2014-07-22 03:26:28 +08:00
|
|
|
|
// Game Resource Browser
|
|
|
|
|
//
|
2015-05-02 03:30:57 +08:00
|
|
|
|
// Copyright (C) 2014-2015 by morkt
|
2014-07-22 03:26:28 +08:00
|
|
|
|
//
|
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
// of this software and associated documentation files (the "Software"), to
|
|
|
|
|
// deal in the Software without restriction, including without limitation the
|
|
|
|
|
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
|
|
|
// sell copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
// furnished to do so, subject to the following conditions:
|
|
|
|
|
//
|
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
|
//
|
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
|
|
|
// IN THE SOFTWARE.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Collections.Generic;
|
2015-08-05 01:02:16 +08:00
|
|
|
|
using System.Collections.Specialized;
|
2014-07-22 03:26:28 +08:00
|
|
|
|
using System.ComponentModel;
|
2015-08-05 01:02:16 +08:00
|
|
|
|
using System.Diagnostics;
|
2014-08-02 22:23:20 +08:00
|
|
|
|
using System.Globalization;
|
2014-07-22 03:26:28 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
2015-08-05 01:02:16 +08:00
|
|
|
|
using System.Text.RegularExpressions;
|
2014-07-22 03:26:28 +08:00
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
using System.Windows.Data;
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
using System.Windows.Threading;
|
|
|
|
|
using Microsoft.VisualBasic.FileIO;
|
|
|
|
|
using GARbro.GUI.Properties;
|
|
|
|
|
using GARbro.GUI.Strings;
|
|
|
|
|
using GameRes;
|
|
|
|
|
using Rnd.Windows;
|
2014-07-31 10:56:30 +08:00
|
|
|
|
using Microsoft.Win32;
|
2014-11-07 06:45:48 +08:00
|
|
|
|
using NAudio.Wave;
|
2014-07-22 03:26:28 +08:00
|
|
|
|
|
|
|
|
|
namespace GARbro.GUI
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Interaction logic for MainWindow.xaml
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class MainWindow : Window
|
|
|
|
|
{
|
|
|
|
|
private App m_app;
|
|
|
|
|
|
|
|
|
|
const StringComparison StringIgnoreCase = StringComparison.CurrentCultureIgnoreCase;
|
|
|
|
|
|
|
|
|
|
public MainWindow()
|
|
|
|
|
{
|
|
|
|
|
m_app = Application.Current as App;
|
|
|
|
|
InitializeComponent();
|
2015-02-15 23:48:16 +08:00
|
|
|
|
if (this.Top < 0) this.Top = 0;
|
|
|
|
|
if (this.Left < 0) this.Left = 0;
|
2014-07-22 03:26:28 +08:00
|
|
|
|
InitDirectoryChangesWatcher();
|
|
|
|
|
InitPreviewPane();
|
|
|
|
|
|
2014-07-30 21:15:16 +08:00
|
|
|
|
if (null == Settings.Default.appRecentFiles)
|
|
|
|
|
Settings.Default.appRecentFiles = new StringCollection();
|
2014-08-02 16:59:01 +08:00
|
|
|
|
m_recent_files = new LinkedList<string> (Settings.Default.appRecentFiles.Cast<string>().Take (MaxRecentFiles));
|
2014-07-31 10:56:30 +08:00
|
|
|
|
RecentFilesMenu.ItemsSource = RecentFiles;
|
2014-07-30 21:15:16 +08:00
|
|
|
|
|
2015-08-12 05:31:56 +08:00
|
|
|
|
FormatCatalog.Instance.ParametersRequest += (s, e) => Dispatcher.Invoke (() => OnParametersRequest (s, e));
|
2014-07-22 03:26:28 +08:00
|
|
|
|
|
|
|
|
|
CurrentDirectory.SizeChanged += (s, e) => {
|
|
|
|
|
if (e.WidthChanged)
|
|
|
|
|
{
|
|
|
|
|
pathLine.MinWidth = e.NewSize.Width-79;
|
2014-08-01 20:37:16 +08:00
|
|
|
|
this.MinWidth = e.NewSize.Width+79;
|
2014-07-22 03:26:28 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
pathLine.EnterKeyDown += acb_OnKeyDown;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WindowLoaded (object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
lv_SetSortMode (Settings.Default.lvSortColumn, Settings.Default.lvSortDirection);
|
|
|
|
|
Dispatcher.InvokeAsync (WindowRendered, DispatcherPriority.ContextIdle);
|
2015-05-04 02:12:51 +08:00
|
|
|
|
ImageData.SetDefaultDpi (Desktop.DpiX, Desktop.DpiY);
|
2014-07-22 03:26:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WindowRendered ()
|
|
|
|
|
{
|
2015-09-20 09:20:42 +08:00
|
|
|
|
DirectoryViewModel vm = null;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
vm = GetNewViewModel (m_app.InitPath);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception X)
|
|
|
|
|
{
|
|
|
|
|
PopupError (X.Message, guiStrings.MsgErrorOpening);
|
|
|
|
|
}
|
|
|
|
|
if (null == vm)
|
|
|
|
|
{
|
|
|
|
|
vm = CreateViewModel (Directory.GetCurrentDirectory(), true);
|
|
|
|
|
}
|
|
|
|
|
ViewModel = vm;
|
2014-07-22 03:26:28 +08:00
|
|
|
|
lv_SelectItem (0);
|
|
|
|
|
SetStatusText (guiStrings.MsgReady);
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-04 02:12:51 +08:00
|
|
|
|
void WindowKeyDown (object sender, KeyEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (MainMenuBar.Visibility != Visibility.Visible && Key.System == e.Key)
|
|
|
|
|
{
|
|
|
|
|
MainMenuBar.Visibility = Visibility.Visible;
|
|
|
|
|
MainMenuBar.IsKeyboardFocusWithinChanged += HideMenuBar;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HideMenuBar (object sender, DependencyPropertyChangedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (!MainMenuBar.IsKeyboardFocusWithin)
|
|
|
|
|
{
|
|
|
|
|
MainMenuBar.IsKeyboardFocusWithinChanged -= HideMenuBar;
|
|
|
|
|
MainMenuBar.Visibility = Visibility.Collapsed;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-22 03:26:28 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Save settings when main window is about to close
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected override void OnClosing (CancelEventArgs e)
|
|
|
|
|
{
|
2015-06-09 00:07:09 +08:00
|
|
|
|
AudioDevice = null;
|
2015-05-12 17:31:27 +08:00
|
|
|
|
CurrentAudio = null;
|
2014-07-22 03:26:28 +08:00
|
|
|
|
SaveSettings();
|
|
|
|
|
base.OnClosing (e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Manually save settings that are not automatically saved by bindings.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void SaveSettings()
|
|
|
|
|
{
|
|
|
|
|
if (null != m_lvSortByColumn)
|
|
|
|
|
{
|
2014-08-02 22:23:20 +08:00
|
|
|
|
Settings.Default.lvSortColumn = SortMode;
|
2014-07-22 03:26:28 +08:00
|
|
|
|
Settings.Default.lvSortDirection = m_lvSortDirection;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
Settings.Default.lvSortColumn = "";
|
2014-07-30 05:09:28 +08:00
|
|
|
|
|
2014-07-30 21:15:16 +08:00
|
|
|
|
Settings.Default.appRecentFiles.Clear();
|
|
|
|
|
foreach (var file in m_recent_files)
|
|
|
|
|
Settings.Default.appRecentFiles.Add (file);
|
|
|
|
|
|
2014-07-30 05:09:28 +08:00
|
|
|
|
string cwd = CurrentPath;
|
|
|
|
|
if (!string.IsNullOrEmpty (cwd))
|
|
|
|
|
{
|
|
|
|
|
if (ViewModel.IsArchive)
|
|
|
|
|
cwd = Path.GetDirectoryName (cwd);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
cwd = Directory.GetCurrentDirectory();
|
|
|
|
|
Settings.Default.appLastDirectory = cwd;
|
2014-07-22 03:26:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Set status line text. Could be called from any thread.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void SetStatusText (string text)
|
|
|
|
|
{
|
|
|
|
|
Dispatcher.Invoke (() => { appStatusText.Text = text; });
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-23 02:35:28 +08:00
|
|
|
|
public void SetResourceText (string text)
|
|
|
|
|
{
|
|
|
|
|
Dispatcher.Invoke (() => { appResourceText.Text = text; });
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-22 03:26:28 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Popup error message box. Could be called from any thread.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void PopupError (string message, string title)
|
|
|
|
|
{
|
|
|
|
|
Dispatcher.Invoke (() => MessageBox.Show (this, message, title, MessageBoxButton.OK, MessageBoxImage.Error));
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-02 16:59:01 +08:00
|
|
|
|
const int MaxRecentFiles = 9;
|
2014-07-31 10:56:30 +08:00
|
|
|
|
LinkedList<string> m_recent_files;
|
2014-07-30 21:15:16 +08:00
|
|
|
|
|
2014-08-01 20:37:16 +08:00
|
|
|
|
// Item1 = file name, Item2 = menu item string
|
2014-07-31 10:56:30 +08:00
|
|
|
|
public IEnumerable<Tuple<string,string>> RecentFiles
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
int i = 1;
|
2015-05-04 02:12:51 +08:00
|
|
|
|
return m_recent_files.Select (f => Tuple.Create (f, string.Format ("_{0} {1}", i++, f)));
|
2014-07-31 10:56:30 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-07-30 21:15:16 +08:00
|
|
|
|
|
|
|
|
|
void PushRecentFile (string file)
|
|
|
|
|
{
|
2014-07-31 10:56:30 +08:00
|
|
|
|
var node = m_recent_files.Find (file);
|
2014-09-08 16:15:13 +08:00
|
|
|
|
if (node != null && node == m_recent_files.First)
|
2014-07-31 10:56:30 +08:00
|
|
|
|
return;
|
|
|
|
|
if (null == node)
|
2014-07-30 21:15:16 +08:00
|
|
|
|
{
|
2014-08-02 22:23:20 +08:00
|
|
|
|
while (MaxRecentFiles <= m_recent_files.Count)
|
2014-07-31 10:56:30 +08:00
|
|
|
|
m_recent_files.RemoveLast();
|
|
|
|
|
m_recent_files.AddFirst (file);
|
2014-07-30 21:15:16 +08:00
|
|
|
|
}
|
2014-07-31 10:56:30 +08:00
|
|
|
|
else
|
2014-07-30 21:15:16 +08:00
|
|
|
|
{
|
2014-07-31 10:56:30 +08:00
|
|
|
|
m_recent_files.Remove (node);
|
|
|
|
|
m_recent_files.AddFirst (node);
|
2014-07-30 21:15:16 +08:00
|
|
|
|
}
|
2014-07-31 10:56:30 +08:00
|
|
|
|
RecentFilesMenu.ItemsSource = RecentFiles;
|
2014-07-30 21:15:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-22 03:26:28 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Set data context of the ListView.
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
2015-05-16 01:19:15 +08:00
|
|
|
|
public DirectoryViewModel ViewModel
|
2014-07-22 03:26:28 +08:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var source = CurrentDirectory.ItemsSource as CollectionView;
|
|
|
|
|
if (null == source)
|
|
|
|
|
return null;
|
|
|
|
|
return source.SourceCollection as DirectoryViewModel;
|
|
|
|
|
}
|
2015-05-16 01:19:15 +08:00
|
|
|
|
private set
|
2014-07-22 03:26:28 +08:00
|
|
|
|
{
|
|
|
|
|
StopWatchDirectoryChanges();
|
|
|
|
|
var cvs = this.Resources["ListViewSource"] as CollectionViewSource;
|
|
|
|
|
cvs.Source = value;
|
2014-07-30 21:15:16 +08:00
|
|
|
|
|
2015-09-01 12:52:47 +08:00
|
|
|
|
// update path textbox
|
|
|
|
|
var path_component = value.Path.Last();
|
|
|
|
|
if (string.IsNullOrEmpty (path_component) && value.Path.Count > 1)
|
|
|
|
|
path_component = value.Path[value.Path.Count-2];
|
|
|
|
|
pathLine.Text = path_component;
|
|
|
|
|
|
|
|
|
|
if (value.IsArchive && value.Path.Count <= 2)
|
2015-08-31 14:48:27 +08:00
|
|
|
|
PushRecentFile (value.Path.First());
|
2014-07-30 21:15:16 +08:00
|
|
|
|
|
2014-08-02 22:23:20 +08:00
|
|
|
|
lv_Sort (SortMode, m_lvSortDirection);
|
2015-08-31 14:48:27 +08:00
|
|
|
|
if (!value.IsArchive && !string.IsNullOrEmpty (value.Path.First()))
|
2014-07-22 03:26:28 +08:00
|
|
|
|
{
|
2015-08-31 14:48:27 +08:00
|
|
|
|
WatchDirectoryChanges (value.Path.First());
|
2014-07-22 03:26:28 +08:00
|
|
|
|
}
|
|
|
|
|
CurrentDirectory.UpdateLayout();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-01 12:52:47 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Save current position and update view model.
|
|
|
|
|
/// </summary>
|
|
|
|
|
void PushViewModel (DirectoryViewModel vm)
|
|
|
|
|
{
|
|
|
|
|
SaveCurrentPosition();
|
|
|
|
|
ViewModel = vm;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-22 03:26:28 +08:00
|
|
|
|
DirectoryViewModel GetNewViewModel (string path)
|
|
|
|
|
{
|
2015-09-01 12:52:47 +08:00
|
|
|
|
if (!string.IsNullOrEmpty (path))
|
|
|
|
|
{
|
|
|
|
|
if (!VFS.IsVirtual)
|
|
|
|
|
path = Path.GetFullPath (path);
|
|
|
|
|
var entry = VFS.FindFile (path);
|
|
|
|
|
if (!(entry is SubDirEntry))
|
|
|
|
|
SetBusyState();
|
|
|
|
|
VFS.ChDir (entry);
|
|
|
|
|
}
|
2015-08-31 14:48:27 +08:00
|
|
|
|
return new DirectoryViewModel (VFS.FullPath, VFS.GetFiles(), VFS.IsVirtual);
|
2014-07-22 03:26:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-27 03:21:21 +08:00
|
|
|
|
private bool m_busy_state = false;
|
|
|
|
|
|
2014-07-22 03:26:28 +08:00
|
|
|
|
public void SetBusyState()
|
|
|
|
|
{
|
2014-07-27 03:21:21 +08:00
|
|
|
|
m_busy_state = true;
|
2014-07-22 03:26:28 +08:00
|
|
|
|
Mouse.OverrideCursor = Cursors.Wait;
|
|
|
|
|
Dispatcher.InvokeAsync (() => {
|
2014-07-27 03:21:21 +08:00
|
|
|
|
m_busy_state = false;
|
2014-07-22 03:26:28 +08:00
|
|
|
|
Mouse.OverrideCursor = null;
|
|
|
|
|
}, DispatcherPriority.ApplicationIdle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Create view model corresponding to <paramref name="path">. Returns null on error.
|
|
|
|
|
/// </summary>
|
|
|
|
|
DirectoryViewModel TryCreateViewModel (string path)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return GetNewViewModel (path);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception X)
|
|
|
|
|
{
|
|
|
|
|
SetStatusText (string.Format ("{0}: {1}", Path.GetFileName (path), X.Message));
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Create view model corresponding to <paramref name="path"> or empty view model if there was
|
|
|
|
|
/// an error accessing path.
|
|
|
|
|
/// </summary>
|
2015-09-20 09:20:42 +08:00
|
|
|
|
DirectoryViewModel CreateViewModel (string path, bool suppress_warning = false)
|
2014-07-22 03:26:28 +08:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return GetNewViewModel (path);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception X)
|
|
|
|
|
{
|
2015-09-20 09:20:42 +08:00
|
|
|
|
if (!suppress_warning)
|
|
|
|
|
PopupError (X.Message, guiStrings.MsgErrorOpening);
|
2015-08-31 14:48:27 +08:00
|
|
|
|
return new DirectoryViewModel (new string[] { "" }, new Entry[0], false);
|
2014-07-22 03:26:28 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region Refresh view on filesystem changes
|
|
|
|
|
|
|
|
|
|
private FileSystemWatcher m_watcher = new FileSystemWatcher();
|
|
|
|
|
|
|
|
|
|
void InitDirectoryChangesWatcher ()
|
|
|
|
|
{
|
|
|
|
|
m_watcher.NotifyFilter = NotifyFilters.Size | NotifyFilters.FileName | NotifyFilters.DirectoryName;
|
|
|
|
|
m_watcher.Changed += InvokeRefreshView;
|
|
|
|
|
m_watcher.Created += InvokeRefreshView;
|
|
|
|
|
m_watcher.Deleted += InvokeRefreshView;
|
|
|
|
|
m_watcher.Renamed += InvokeRefreshView;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WatchDirectoryChanges (string path)
|
|
|
|
|
{
|
|
|
|
|
m_watcher.Path = path;
|
|
|
|
|
m_watcher.EnableRaisingEvents = true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-22 14:16:11 +08:00
|
|
|
|
public void StopWatchDirectoryChanges()
|
2014-07-22 03:26:28 +08:00
|
|
|
|
{
|
|
|
|
|
m_watcher.EnableRaisingEvents = false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-22 14:16:11 +08:00
|
|
|
|
public void ResumeWatchDirectoryChanges ()
|
2014-07-29 11:12:10 +08:00
|
|
|
|
{
|
2015-08-31 14:48:27 +08:00
|
|
|
|
m_watcher.EnableRaisingEvents = !ViewModel.IsArchive;
|
2014-07-29 11:12:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-22 03:26:28 +08:00
|
|
|
|
private void InvokeRefreshView (object source, FileSystemEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var watcher = source as FileSystemWatcher;
|
2015-08-31 14:48:27 +08:00
|
|
|
|
var vm = ViewModel;
|
|
|
|
|
if (!vm.IsArchive && vm.Path.First() == watcher.Path)
|
2014-07-22 03:26:28 +08:00
|
|
|
|
{
|
|
|
|
|
watcher.EnableRaisingEvents = false;
|
2015-06-17 21:34:59 +08:00
|
|
|
|
Dispatcher.Invoke (RefreshView);
|
2014-07-22 03:26:28 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Select specified item within CurrentDirectory and bring it into a view.
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
|
|
void lv_SelectItem (EntryViewModel item)
|
|
|
|
|
{
|
|
|
|
|
if (item != null)
|
|
|
|
|
{
|
|
|
|
|
CurrentDirectory.SelectedItem = item;
|
|
|
|
|
CurrentDirectory.ScrollIntoView (item);
|
|
|
|
|
var lvi = (ListViewItem)CurrentDirectory.ItemContainerGenerator.ContainerFromItem (item);
|
|
|
|
|
if (lvi != null)
|
|
|
|
|
lvi.Focus();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void lv_SelectItem (int index)
|
|
|
|
|
{
|
|
|
|
|
CurrentDirectory.SelectedIndex = index;
|
|
|
|
|
CurrentDirectory.ScrollIntoView (CurrentDirectory.SelectedItem);
|
|
|
|
|
var lvi = (ListViewItem)CurrentDirectory.ItemContainerGenerator.ContainerFromIndex (index);
|
|
|
|
|
if (lvi != null)
|
|
|
|
|
lvi.Focus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void lv_SelectItem (string name)
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty (name))
|
|
|
|
|
lv_SelectItem (ViewModel.Find (name));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void lv_Focus ()
|
|
|
|
|
{
|
|
|
|
|
if (CurrentDirectory.SelectedIndex != -1)
|
|
|
|
|
{
|
|
|
|
|
var item = CurrentDirectory.SelectedItem;
|
|
|
|
|
var lvi = CurrentDirectory.ItemContainerGenerator.ContainerFromItem (item) as ListViewItem;
|
|
|
|
|
if (lvi != null)
|
|
|
|
|
{
|
|
|
|
|
lvi.Focus();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
CurrentDirectory.Focus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void lvi_Selected (object sender, RoutedEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
var lvi = sender as ListViewItem;
|
|
|
|
|
if (lvi == null)
|
|
|
|
|
return;
|
|
|
|
|
var entry = lvi.Content as EntryViewModel;
|
|
|
|
|
if (entry == null)
|
|
|
|
|
return;
|
|
|
|
|
PreviewEntry (entry.Source);
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-04 02:45:59 +08:00
|
|
|
|
EntryViewModel m_last_selected = null;
|
|
|
|
|
|
|
|
|
|
void lv_SelectionChanged (object sender, SelectionChangedEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
var lv = sender as ListView;
|
|
|
|
|
if (null == lv)
|
|
|
|
|
return;
|
|
|
|
|
var item = lv.SelectedItem as EntryViewModel;
|
|
|
|
|
if (item != null && m_last_selected != item)
|
|
|
|
|
{
|
|
|
|
|
m_last_selected = item;
|
|
|
|
|
PreviewEntry (item.Source);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-22 03:26:28 +08:00
|
|
|
|
void lvi_DoubleClick (object sender, MouseButtonEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
var lvi = sender as ListViewItem;
|
|
|
|
|
if (Commands.OpenItem.CanExecute (null, lvi))
|
|
|
|
|
{
|
|
|
|
|
Commands.OpenItem.Execute (null, lvi);
|
|
|
|
|
args.Handled = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Get currently selected item from ListView widget.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private ListViewItem lv_GetCurrentContainer ()
|
|
|
|
|
{
|
|
|
|
|
int current = CurrentDirectory.SelectedIndex;
|
|
|
|
|
if (-1 == current)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
return CurrentDirectory.ItemContainerGenerator.ContainerFromIndex (current) as ListViewItem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GridViewColumnHeader m_lvSortByColumn = null;
|
|
|
|
|
ListSortDirection m_lvSortDirection = ListSortDirection.Ascending;
|
|
|
|
|
|
2014-08-02 22:23:20 +08:00
|
|
|
|
public string SortMode
|
|
|
|
|
{
|
|
|
|
|
get { return GetValue (SortModeProperty) as string; }
|
|
|
|
|
private set { SetValue (SortModeProperty, value); }
|
2014-07-22 03:26:28 +08:00
|
|
|
|
}
|
2014-08-02 22:23:20 +08:00
|
|
|
|
|
|
|
|
|
public static readonly DependencyProperty SortModeProperty =
|
|
|
|
|
DependencyProperty.RegisterAttached ("SortMode", typeof(string), typeof(MainWindow), new UIPropertyMetadata());
|
2014-07-22 03:26:28 +08:00
|
|
|
|
|
|
|
|
|
void lv_SetSortMode (string sortBy, ListSortDirection direction)
|
|
|
|
|
{
|
|
|
|
|
m_lvSortByColumn = null;
|
|
|
|
|
GridView view = CurrentDirectory.View as GridView;
|
|
|
|
|
foreach (var column in view.Columns)
|
|
|
|
|
{
|
|
|
|
|
var header = column.Header as GridViewColumnHeader;
|
|
|
|
|
if (null != header && !string.IsNullOrEmpty (sortBy) && sortBy.Equals (header.Tag))
|
|
|
|
|
{
|
|
|
|
|
if (ListSortDirection.Ascending == direction)
|
|
|
|
|
column.HeaderTemplate = Resources["SortArrowUp"] as DataTemplate;
|
|
|
|
|
else
|
|
|
|
|
column.HeaderTemplate = Resources["SortArrowDown"] as DataTemplate;
|
|
|
|
|
m_lvSortByColumn = header;
|
|
|
|
|
m_lvSortDirection = direction;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
column.HeaderTemplate = Resources["SortArrowNone"] as DataTemplate;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-08-02 22:23:20 +08:00
|
|
|
|
SortMode = sortBy;
|
2014-07-22 03:26:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void lv_Sort (string sortBy, ListSortDirection direction)
|
|
|
|
|
{
|
|
|
|
|
var dataView = CollectionViewSource.GetDefaultView (CurrentDirectory.ItemsSource) as ListCollectionView;
|
|
|
|
|
dataView.CustomSort = new FileSystemComparer (sortBy, direction);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sort Listview by columns
|
|
|
|
|
/// </summary>
|
|
|
|
|
void lv_ColumnHeaderClicked (object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var headerClicked = e.OriginalSource as GridViewColumnHeader;
|
|
|
|
|
|
|
|
|
|
if (null == headerClicked)
|
|
|
|
|
return;
|
|
|
|
|
if (headerClicked.Role == GridViewColumnHeaderRole.Padding)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
ListSortDirection direction;
|
|
|
|
|
if (headerClicked != m_lvSortByColumn)
|
|
|
|
|
direction = ListSortDirection.Ascending;
|
|
|
|
|
else if (m_lvSortDirection == ListSortDirection.Ascending)
|
|
|
|
|
direction = ListSortDirection.Descending;
|
|
|
|
|
else
|
|
|
|
|
direction = ListSortDirection.Ascending;
|
|
|
|
|
|
|
|
|
|
string sortBy = headerClicked.Tag.ToString();
|
|
|
|
|
lv_Sort (sortBy, direction);
|
2014-08-02 22:23:20 +08:00
|
|
|
|
SortMode = sortBy;
|
2014-07-22 03:26:28 +08:00
|
|
|
|
|
|
|
|
|
// Remove arrow from previously sorted header
|
|
|
|
|
if (m_lvSortByColumn != null && m_lvSortByColumn != headerClicked)
|
|
|
|
|
{
|
|
|
|
|
m_lvSortByColumn.Column.HeaderTemplate = Resources["SortArrowNone"] as DataTemplate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ListSortDirection.Ascending == direction)
|
|
|
|
|
{
|
|
|
|
|
headerClicked.Column.HeaderTemplate = Resources["SortArrowUp"] as DataTemplate;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
headerClicked.Column.HeaderTemplate = Resources["SortArrowDown"] as DataTemplate;
|
|
|
|
|
}
|
|
|
|
|
m_lvSortByColumn = headerClicked;
|
|
|
|
|
m_lvSortDirection = direction;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Handle "Sort By" commands.
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
|
|
private void SortByExec (object sender, ExecutedRoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
string sort_by = e.Parameter as string;
|
|
|
|
|
lv_Sort (sort_by, ListSortDirection.Ascending);
|
|
|
|
|
lv_SetSortMode (sort_by, ListSortDirection.Ascending);
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-23 11:35:05 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Handle "Set file type" commands.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void SetFileTypeExec (object sender, ExecutedRoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var selected = CurrentDirectory.SelectedItems.Cast<EntryViewModel>().Where (x => !x.IsDirectory);
|
|
|
|
|
if (!selected.Any())
|
|
|
|
|
return;
|
|
|
|
|
string type = e.Parameter as string;
|
|
|
|
|
foreach (var entry in selected)
|
|
|
|
|
{
|
|
|
|
|
entry.Type = type;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-22 03:26:28 +08:00
|
|
|
|
/// <summary>
|
2014-08-02 22:23:20 +08:00
|
|
|
|
/// Event handler for keys pressed in the directory view pane
|
2014-07-22 03:26:28 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
|
|
private void lv_TextInput (object sender, TextCompositionEventArgs e)
|
|
|
|
|
{
|
2014-08-02 22:23:20 +08:00
|
|
|
|
LookupItem (e.Text, e.Timestamp);
|
2014-07-22 03:26:28 +08:00
|
|
|
|
e.Handled = true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-02 22:23:20 +08:00
|
|
|
|
class InputData
|
|
|
|
|
{
|
|
|
|
|
public int LastTime = 0;
|
|
|
|
|
public StringBuilder Phrase = new StringBuilder();
|
|
|
|
|
public bool Mismatch = false;
|
2014-08-03 14:50:03 +08:00
|
|
|
|
|
|
|
|
|
public void Reset ()
|
|
|
|
|
{
|
|
|
|
|
Phrase.Clear ();
|
|
|
|
|
Mismatch = false;
|
|
|
|
|
}
|
2014-08-02 22:23:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const int TextLookupTimeout = 1000; // milliseconds
|
|
|
|
|
|
|
|
|
|
InputData m_current_input = new InputData();
|
|
|
|
|
|
2014-07-22 03:26:28 +08:00
|
|
|
|
/// <summary>
|
2014-08-02 22:23:20 +08:00
|
|
|
|
/// Lookup item in listview pane by first letters of name.
|
2014-07-22 03:26:28 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
2014-08-02 22:23:20 +08:00
|
|
|
|
private void LookupItem (string key, int timestamp)
|
2014-07-22 03:26:28 +08:00
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty (key))
|
|
|
|
|
return;
|
|
|
|
|
var source = CurrentDirectory.ItemsSource as CollectionView;
|
|
|
|
|
if (source == null)
|
|
|
|
|
return;
|
|
|
|
|
|
2014-08-02 22:23:20 +08:00
|
|
|
|
if (timestamp - m_current_input.LastTime > TextLookupTimeout)
|
|
|
|
|
{
|
2014-08-03 14:50:03 +08:00
|
|
|
|
m_current_input.Reset();
|
2014-08-02 22:23:20 +08:00
|
|
|
|
}
|
|
|
|
|
m_current_input.LastTime = timestamp;
|
|
|
|
|
if (m_current_input.Mismatch)
|
|
|
|
|
return;
|
2014-07-22 03:26:28 +08:00
|
|
|
|
|
2015-05-04 02:12:51 +08:00
|
|
|
|
if (!(1 == m_current_input.Phrase.Length && m_current_input.Phrase[0] == key[0]))
|
2014-07-22 03:26:28 +08:00
|
|
|
|
{
|
2015-05-04 02:12:51 +08:00
|
|
|
|
m_current_input.Phrase.Append (key);
|
2014-07-22 03:26:28 +08:00
|
|
|
|
}
|
2015-05-04 02:12:51 +08:00
|
|
|
|
int start_index = CurrentDirectory.SelectedIndex;
|
|
|
|
|
if (1 == m_current_input.Phrase.Length)
|
2014-08-02 22:23:20 +08:00
|
|
|
|
{
|
2015-05-04 02:12:51 +08:00
|
|
|
|
// lookup starting from the next item
|
|
|
|
|
if (start_index != -1 && start_index+1 < source.Count)
|
|
|
|
|
++start_index;
|
|
|
|
|
}
|
|
|
|
|
var items = source.Cast<EntryViewModel>();
|
|
|
|
|
if (start_index > 0)
|
|
|
|
|
{
|
|
|
|
|
items = items.Skip (start_index).Concat (items.Take (start_index));
|
2014-08-02 22:23:20 +08:00
|
|
|
|
}
|
|
|
|
|
string input = m_current_input.Phrase.ToString();
|
2015-04-28 06:48:12 +08:00
|
|
|
|
var matched = items.Where (e => e.Name.StartsWith (input, StringIgnoreCase)).FirstOrDefault();
|
2014-08-02 22:23:20 +08:00
|
|
|
|
if (null != matched)
|
|
|
|
|
lv_SelectItem (matched);
|
|
|
|
|
else
|
|
|
|
|
m_current_input.Mismatch = true;
|
2014-07-22 03:26:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void acb_OnKeyDown (object sender, KeyEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.Key != Key.Return)
|
|
|
|
|
return;
|
|
|
|
|
string path = (sender as AutoCompleteBox).Text;
|
|
|
|
|
if (string.IsNullOrEmpty (path))
|
|
|
|
|
return;
|
|
|
|
|
try
|
|
|
|
|
{
|
2015-09-01 12:52:47 +08:00
|
|
|
|
PushViewModel (GetNewViewModel (path));
|
2014-07-22 03:26:28 +08:00
|
|
|
|
lv_Focus();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception X)
|
|
|
|
|
{
|
|
|
|
|
PopupError (X.Message, guiStrings.MsgErrorOpening);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region Navigation history implementation
|
|
|
|
|
|
2015-08-31 14:48:27 +08:00
|
|
|
|
internal string CurrentPath { get { return ViewModel.Path.First(); } }
|
2014-07-22 03:26:28 +08:00
|
|
|
|
|
|
|
|
|
HistoryStack<DirectoryPosition> m_history = new HistoryStack<DirectoryPosition>();
|
|
|
|
|
|
2014-07-29 11:12:10 +08:00
|
|
|
|
public DirectoryPosition GetCurrentPosition ()
|
2014-07-22 03:26:28 +08:00
|
|
|
|
{
|
|
|
|
|
var evm = CurrentDirectory.SelectedItem as EntryViewModel;
|
|
|
|
|
return new DirectoryPosition (ViewModel, evm);
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-29 11:12:10 +08:00
|
|
|
|
public bool SetCurrentPosition (DirectoryPosition pos)
|
2014-07-22 03:26:28 +08:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2015-08-31 14:48:27 +08:00
|
|
|
|
VFS.FullPath = pos.Path;
|
|
|
|
|
var vm = TryCreateViewModel (pos.Path.Last());
|
|
|
|
|
if (null == vm)
|
|
|
|
|
return false;
|
2014-07-22 03:26:28 +08:00
|
|
|
|
ViewModel = vm;
|
|
|
|
|
if (null != pos.Item)
|
2014-07-27 10:06:50 +08:00
|
|
|
|
lv_SelectItem (pos.Item);
|
2014-07-22 03:26:28 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception X)
|
|
|
|
|
{
|
|
|
|
|
SetStatusText (X.Message);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-29 11:12:10 +08:00
|
|
|
|
public void SaveCurrentPosition ()
|
2014-07-22 03:26:28 +08:00
|
|
|
|
{
|
|
|
|
|
m_history.Push (GetCurrentPosition());
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-15 01:42:27 +08:00
|
|
|
|
public void ChangePosition (DirectoryPosition new_pos)
|
|
|
|
|
{
|
|
|
|
|
var current = GetCurrentPosition();
|
2015-08-31 14:48:27 +08:00
|
|
|
|
if (!current.Path.SequenceEqual (new_pos.Path))
|
2014-08-15 01:42:27 +08:00
|
|
|
|
SaveCurrentPosition();
|
|
|
|
|
SetCurrentPosition (new_pos);
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-22 03:26:28 +08:00
|
|
|
|
private void GoBackExec (object sender, ExecutedRoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
DirectoryPosition current = m_history.Undo (GetCurrentPosition());
|
|
|
|
|
if (current != null)
|
|
|
|
|
SetCurrentPosition (current);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void GoForwardExec (object sender, ExecutedRoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
DirectoryPosition current = m_history.Redo (GetCurrentPosition());
|
|
|
|
|
if (current != null)
|
|
|
|
|
SetCurrentPosition (current);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CanExecuteGoBack (object sender, CanExecuteRoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
e.CanExecute = m_history.CanUndo();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CanExecuteGoForward (object sender, CanExecuteRoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
e.CanExecute = m_history.CanRedo();
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
2014-07-31 10:56:30 +08:00
|
|
|
|
private void OpenFileExec (object control, ExecutedRoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var dlg = new OpenFileDialog {
|
|
|
|
|
CheckFileExists = true,
|
|
|
|
|
CheckPathExists = true,
|
|
|
|
|
Multiselect = false,
|
|
|
|
|
Title = guiStrings.TextChooseArchive,
|
|
|
|
|
};
|
|
|
|
|
if (!dlg.ShowDialog (this).Value)
|
|
|
|
|
return;
|
|
|
|
|
OpenFile (dlg.FileName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OpenFile (string filename)
|
|
|
|
|
{
|
|
|
|
|
if (filename == CurrentPath)
|
|
|
|
|
return;
|
|
|
|
|
try
|
|
|
|
|
{
|
2015-09-01 12:52:47 +08:00
|
|
|
|
PushViewModel (GetNewViewModel (filename));
|
2015-08-31 14:48:27 +08:00
|
|
|
|
if (null != VFS.CurrentArchive)
|
|
|
|
|
SetStatusText (VFS.CurrentArchive.Description);
|
2014-07-31 10:56:30 +08:00
|
|
|
|
lv_SelectItem (0);
|
|
|
|
|
}
|
2014-08-02 16:59:01 +08:00
|
|
|
|
catch (OperationCanceledException X)
|
|
|
|
|
{
|
|
|
|
|
SetStatusText (X.Message);
|
|
|
|
|
}
|
2014-07-31 10:56:30 +08:00
|
|
|
|
catch (Exception X)
|
|
|
|
|
{
|
|
|
|
|
PopupError (string.Format("{0}:\n{1}", filename, X.Message), guiStrings.MsgErrorOpening);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OpenRecentExec (object control, ExecutedRoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
string filename = e.Parameter as string;
|
|
|
|
|
if (string.IsNullOrEmpty (filename))
|
|
|
|
|
return;
|
|
|
|
|
OpenFile (filename);
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-22 03:26:28 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Open file/directory.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void OpenItemExec (object control, ExecutedRoutedEventArgs e)
|
|
|
|
|
{
|
2014-08-02 05:06:04 +08:00
|
|
|
|
EntryViewModel entry = null;
|
|
|
|
|
var lvi = e.OriginalSource as ListViewItem;
|
|
|
|
|
if (lvi != null)
|
|
|
|
|
entry = lvi.Content as EntryViewModel;
|
2014-07-22 03:26:28 +08:00
|
|
|
|
if (null == entry)
|
2014-08-02 05:06:04 +08:00
|
|
|
|
entry = CurrentDirectory.SelectedItem as EntryViewModel;
|
2014-07-22 03:26:28 +08:00
|
|
|
|
if (null == entry)
|
|
|
|
|
return;
|
2014-11-07 06:45:48 +08:00
|
|
|
|
if ("audio" == entry.Type)
|
|
|
|
|
{
|
|
|
|
|
PlayFile (entry.Source);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-09-01 12:52:47 +08:00
|
|
|
|
OpenDirectoryEntry (ViewModel, entry);
|
2014-07-22 03:26:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OpenDirectoryEntry (DirectoryViewModel vm, EntryViewModel entry)
|
|
|
|
|
{
|
2015-09-01 12:52:47 +08:00
|
|
|
|
string old_dir = null == vm ? "" : vm.Path.Last();
|
2015-08-31 14:48:27 +08:00
|
|
|
|
string new_dir = entry.Source.Name;
|
2015-09-01 12:52:47 +08:00
|
|
|
|
if (".." == new_dir)
|
|
|
|
|
{
|
|
|
|
|
if (null != vm && !vm.IsArchive)
|
|
|
|
|
new_dir = Path.Combine (old_dir, entry.Name);
|
|
|
|
|
if (vm.Path.Count > 1 && string.IsNullOrEmpty (old_dir))
|
|
|
|
|
old_dir = vm.Path[vm.Path.Count-2];
|
|
|
|
|
}
|
2014-07-22 03:26:28 +08:00
|
|
|
|
Trace.WriteLine (new_dir, "OpenDirectoryEntry");
|
2015-08-31 14:48:27 +08:00
|
|
|
|
int old_fs_count = VFS.Count;
|
2014-07-22 03:26:28 +08:00
|
|
|
|
vm = TryCreateViewModel (new_dir);
|
|
|
|
|
if (null == vm)
|
|
|
|
|
return;
|
2015-09-01 12:52:47 +08:00
|
|
|
|
|
|
|
|
|
PushViewModel (vm);
|
2015-08-31 14:48:27 +08:00
|
|
|
|
if (VFS.Count > old_fs_count && null != VFS.CurrentArchive)
|
|
|
|
|
SetStatusText (string.Format ("{0}: {1}", VFS.CurrentArchive.Description,
|
|
|
|
|
Localization.Format ("MsgFiles", VFS.CurrentArchive.Dir.Count())));
|
2014-07-22 03:26:28 +08:00
|
|
|
|
else
|
|
|
|
|
SetStatusText ("");
|
2015-08-31 14:48:27 +08:00
|
|
|
|
|
|
|
|
|
if (".." == entry.Name)
|
2014-07-22 03:26:28 +08:00
|
|
|
|
lv_SelectItem (Path.GetFileName (old_dir));
|
|
|
|
|
else
|
|
|
|
|
lv_SelectItem (0);
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-09 00:07:09 +08:00
|
|
|
|
WaveOutEvent m_audio_device;
|
|
|
|
|
WaveOutEvent AudioDevice
|
2015-05-12 17:31:27 +08:00
|
|
|
|
{
|
2015-06-09 00:07:09 +08:00
|
|
|
|
get { return m_audio_device; }
|
2015-05-12 17:31:27 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
2015-06-09 00:07:09 +08:00
|
|
|
|
if (m_audio_device != null)
|
|
|
|
|
m_audio_device.Dispose();
|
|
|
|
|
m_audio_device = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WaveStream m_audio_input;
|
|
|
|
|
WaveStream CurrentAudio
|
|
|
|
|
{
|
|
|
|
|
get { return m_audio_input; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (m_audio_input != null)
|
|
|
|
|
m_audio_input.Dispose();
|
|
|
|
|
m_audio_input = value;
|
2015-05-12 17:31:27 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-11-07 06:45:48 +08:00
|
|
|
|
|
|
|
|
|
private void PlayFile (Entry entry)
|
|
|
|
|
{
|
2015-06-09 00:07:09 +08:00
|
|
|
|
SoundInput sound = null;
|
2014-11-07 06:45:48 +08:00
|
|
|
|
try
|
|
|
|
|
{
|
2015-05-29 18:55:45 +08:00
|
|
|
|
SetBusyState();
|
2015-09-01 12:52:47 +08:00
|
|
|
|
using (var input = VFS.OpenStream (entry))
|
2014-11-07 06:45:48 +08:00
|
|
|
|
{
|
2014-11-07 21:13:02 +08:00
|
|
|
|
FormatCatalog.Instance.LastError = null;
|
2015-06-09 00:07:09 +08:00
|
|
|
|
sound = AudioFormat.Read (input);
|
2014-11-07 06:45:48 +08:00
|
|
|
|
if (null == sound)
|
2014-11-07 21:13:02 +08:00
|
|
|
|
{
|
|
|
|
|
if (null != FormatCatalog.Instance.LastError)
|
|
|
|
|
throw FormatCatalog.Instance.LastError;
|
2014-11-07 06:45:48 +08:00
|
|
|
|
return;
|
2014-11-07 21:13:02 +08:00
|
|
|
|
}
|
2014-11-07 06:45:48 +08:00
|
|
|
|
|
2015-06-09 00:07:09 +08:00
|
|
|
|
if (AudioDevice != null)
|
2014-11-07 06:45:48 +08:00
|
|
|
|
{
|
2015-06-09 00:07:09 +08:00
|
|
|
|
AudioDevice.PlaybackStopped -= OnPlaybackStopped;
|
|
|
|
|
AudioDevice = null;
|
2014-11-07 06:45:48 +08:00
|
|
|
|
}
|
2015-06-09 00:07:09 +08:00
|
|
|
|
CurrentAudio = new WaveStreamImpl (sound);
|
|
|
|
|
AudioDevice = new WaveOutEvent();
|
|
|
|
|
AudioDevice.Init (CurrentAudio);
|
|
|
|
|
AudioDevice.PlaybackStopped += OnPlaybackStopped;
|
|
|
|
|
AudioDevice.Play();
|
|
|
|
|
var fmt = CurrentAudio.WaveFormat;
|
2015-06-09 06:38:08 +08:00
|
|
|
|
SetResourceText (string.Format ("Playing {0} / {3} / {2}bps / {1}Hz", entry.Name,
|
|
|
|
|
fmt.SampleRate, sound.SourceBitrate / 1000,
|
|
|
|
|
CurrentAudio.TotalTime.ToString ("m':'ss")));
|
2014-11-07 06:45:48 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception X)
|
|
|
|
|
{
|
|
|
|
|
SetStatusText (X.Message);
|
2015-06-09 00:07:09 +08:00
|
|
|
|
if (null != sound)
|
|
|
|
|
sound.Dispose();
|
2014-11-07 06:45:48 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnPlaybackStopped (object sender, StoppedEventArgs e)
|
|
|
|
|
{
|
2015-04-23 02:35:28 +08:00
|
|
|
|
SetResourceText ("");
|
2015-06-09 00:07:09 +08:00
|
|
|
|
CurrentAudio = null;
|
2014-11-07 06:45:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-22 03:26:28 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Launch specified file.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void SystemOpen (string file)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Process.Start (file);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception X)
|
|
|
|
|
{
|
|
|
|
|
SetStatusText (X.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Refresh current view.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void RefreshExec (object sender, ExecutedRoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
RefreshView();
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-22 14:16:11 +08:00
|
|
|
|
public void RefreshView ()
|
2014-07-22 03:26:28 +08:00
|
|
|
|
{
|
2015-08-31 14:48:27 +08:00
|
|
|
|
VFS.Flush();
|
2014-07-22 03:26:28 +08:00
|
|
|
|
var pos = GetCurrentPosition();
|
|
|
|
|
SetCurrentPosition (pos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Open current file in Explorer.
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
|
|
private void ExploreItemExec (object sender, ExecutedRoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var entry = CurrentDirectory.SelectedItem as EntryViewModel;
|
|
|
|
|
if (entry != null && !ViewModel.IsArchive)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string name = Path.Combine (CurrentPath, entry.Name);
|
|
|
|
|
Process.Start ("explorer.exe", "/select,"+name);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception X)
|
|
|
|
|
{
|
|
|
|
|
// ignore
|
|
|
|
|
Trace.WriteLine (X.Message, "explorer.exe");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Delete item from both media library and disk drive.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void DeleteItemExec (object sender, ExecutedRoutedEventArgs e)
|
|
|
|
|
{
|
2014-08-02 05:06:04 +08:00
|
|
|
|
var items = CurrentDirectory.SelectedItems.Cast<EntryViewModel>().Where (f => !f.IsDirectory);
|
|
|
|
|
if (!items.Any())
|
2014-07-22 03:26:28 +08:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
this.IsEnabled = false;
|
|
|
|
|
try
|
|
|
|
|
{
|
2015-08-31 14:48:27 +08:00
|
|
|
|
VFS.Flush();
|
2015-06-09 00:07:09 +08:00
|
|
|
|
ResetPreviewPane();
|
2014-08-02 05:06:04 +08:00
|
|
|
|
if (!items.Skip (1).Any()) // items.Count() == 1
|
|
|
|
|
{
|
|
|
|
|
string item_name = Path.Combine (CurrentPath, items.First().Name);
|
|
|
|
|
Trace.WriteLine (item_name, "DeleteItemExec");
|
|
|
|
|
FileSystem.DeleteFile (item_name, UIOption.AllDialogs, RecycleOption.SendToRecycleBin);
|
|
|
|
|
DeleteItem (lv_GetCurrentContainer());
|
|
|
|
|
SetStatusText (string.Format(guiStrings.MsgDeletedItem, item_name));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int count = 0;
|
|
|
|
|
StopWatchDirectoryChanges ();
|
|
|
|
|
try
|
|
|
|
|
{
|
2014-08-08 18:08:49 +08:00
|
|
|
|
var file_list = items.Select (entry => Path.Combine (CurrentPath, entry.Name));
|
|
|
|
|
GARbro.Shell.File.Delete (file_list);
|
|
|
|
|
count = file_list.Count();
|
2014-08-02 05:06:04 +08:00
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
ResumeWatchDirectoryChanges();
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
RefreshView();
|
|
|
|
|
SetStatusText (Localization.Format ("MsgDeletedItems", count));
|
|
|
|
|
}
|
2014-07-22 03:26:28 +08:00
|
|
|
|
}
|
|
|
|
|
catch (OperationCanceledException)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
catch (Exception X)
|
|
|
|
|
{
|
|
|
|
|
SetStatusText (X.Message);
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
this.IsEnabled = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Delete item at the specified position within ListView, correctly adjusting current
|
|
|
|
|
/// position.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void DeleteItem (ListViewItem item)
|
|
|
|
|
{
|
|
|
|
|
int i = CurrentDirectory.SelectedIndex;
|
|
|
|
|
int next = -1;
|
|
|
|
|
if (i+1 < CurrentDirectory.Items.Count)
|
|
|
|
|
next = i + 1;
|
|
|
|
|
else if (i > 0)
|
|
|
|
|
next = i - 1;
|
|
|
|
|
|
|
|
|
|
if (next != -1)
|
|
|
|
|
CurrentDirectory.SelectedIndex = next;
|
|
|
|
|
|
|
|
|
|
var entry = item.Content as EntryViewModel;
|
|
|
|
|
if (entry != null)
|
|
|
|
|
{
|
|
|
|
|
ViewModel.Remove (entry);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Rename selected item.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void RenameItemExec(object sender, ExecutedRoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
RenameElement (lv_GetCurrentContainer());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Rename item contained within specified framework control.
|
|
|
|
|
/// </summary>
|
|
|
|
|
void RenameElement (ListViewItem item)
|
|
|
|
|
{
|
|
|
|
|
if (item == null)
|
|
|
|
|
return;
|
|
|
|
|
/*
|
|
|
|
|
TextBlock block = FindByName (item, "item_Text") as TextBlock;
|
|
|
|
|
TextBox box = FindSibling (block, "item_Input") as TextBox;
|
|
|
|
|
|
|
|
|
|
if (block == null || box == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
IsRenameActive = true;
|
|
|
|
|
|
|
|
|
|
block.Visibility = Visibility.Collapsed;
|
|
|
|
|
box.Text = block.Text;
|
|
|
|
|
box.Visibility = Visibility.Visible;
|
|
|
|
|
box.Select (0, box.Text.Length);
|
|
|
|
|
box.Focus();
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-04 02:45:59 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Select files matching mask.
|
|
|
|
|
/// </summary>
|
|
|
|
|
void AddSelectionExec (object sender, ExecutedRoutedEventArgs e)
|
|
|
|
|
{
|
2015-08-11 11:09:21 +08:00
|
|
|
|
try
|
2015-08-04 02:45:59 +08:00
|
|
|
|
{
|
2015-08-11 11:09:21 +08:00
|
|
|
|
var ext_list = new SortedSet<string>();
|
|
|
|
|
foreach (var entry in ViewModel)
|
2015-08-04 02:45:59 +08:00
|
|
|
|
{
|
2015-08-11 11:09:21 +08:00
|
|
|
|
var ext = Path.GetExtension (entry.Name).ToLowerInvariant();
|
|
|
|
|
if (!string.IsNullOrEmpty (ext))
|
|
|
|
|
ext_list.Add (ext);
|
2015-08-04 02:45:59 +08:00
|
|
|
|
}
|
2015-08-11 11:09:21 +08:00
|
|
|
|
var selection = new EnterMaskDialog (ext_list.Select (ext => "*"+ext));
|
|
|
|
|
selection.Owner = this;
|
|
|
|
|
var result = selection.ShowDialog();
|
|
|
|
|
if (!result.Value)
|
|
|
|
|
return;
|
|
|
|
|
if ("*.*" == selection.Mask.Text)
|
|
|
|
|
{
|
|
|
|
|
CurrentDirectory.SelectAll();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var mask = Regex.Escape (selection.Mask.Text).Replace (@"\*", ".*").Replace (@"\?", ".");
|
|
|
|
|
var glob = new Regex ("^"+mask+"$", RegexOptions.IgnoreCase);
|
|
|
|
|
var matching = ViewModel.Where (entry => glob.IsMatch (entry.Name));
|
|
|
|
|
if (!matching.Any())
|
|
|
|
|
{
|
|
|
|
|
SetStatusText (string.Format (guiStrings.MsgNoMatching, selection.Mask.Text));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
int count = 0;
|
|
|
|
|
foreach (var item in matching)
|
|
|
|
|
{
|
|
|
|
|
if (!CurrentDirectory.SelectedItems.Contains (item))
|
|
|
|
|
{
|
|
|
|
|
CurrentDirectory.SelectedItems.Add (item);
|
|
|
|
|
++count;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (count != 0)
|
|
|
|
|
SetStatusText (Localization.Format ("MsgSelectedFiles", count));
|
|
|
|
|
}
|
|
|
|
|
catch (Exception X)
|
|
|
|
|
{
|
|
|
|
|
SetStatusText (X.Message);
|
2015-08-04 02:45:59 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SelectAllExec (object sender, ExecutedRoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
CurrentDirectory.SelectAll();
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-22 03:26:28 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Handle "Exit" command.
|
|
|
|
|
/// </summary>
|
|
|
|
|
void ExitExec (object sender, ExecutedRoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Application.Current.Shutdown();
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-31 10:56:30 +08:00
|
|
|
|
private void AboutExec (object sender, ExecutedRoutedEventArgs e)
|
2014-07-22 03:26:28 +08:00
|
|
|
|
{
|
|
|
|
|
var about = new AboutBox();
|
|
|
|
|
about.Owner = this;
|
|
|
|
|
about.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CanExecuteAlways (object sender, CanExecuteRoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
e.CanExecute = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CanExecuteControlCommand (object sender, CanExecuteRoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Control target = e.Source as Control;
|
|
|
|
|
e.CanExecute = target != null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CanExecuteOnSelected (object sender, CanExecuteRoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
e.CanExecute = CurrentDirectory.SelectedIndex != -1;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-14 13:05:09 +08:00
|
|
|
|
private void CanExecuteConvertMedia (object sender, CanExecuteRoutedEventArgs e)
|
2015-06-01 16:59:14 +08:00
|
|
|
|
{
|
2015-06-14 13:05:09 +08:00
|
|
|
|
if (CurrentDirectory.SelectedItems.Count >= 1)
|
2015-06-01 16:59:14 +08:00
|
|
|
|
{
|
|
|
|
|
e.CanExecute = !ViewModel.IsArchive;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-22 14:16:11 +08:00
|
|
|
|
private void CanExecuteOnImage (object sender, CanExecuteRoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var entry = CurrentDirectory.SelectedItem as EntryViewModel;
|
|
|
|
|
e.CanExecute = !ViewModel.IsArchive && entry != null && entry.Type == "image";
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-22 03:26:28 +08:00
|
|
|
|
private void CanExecuteInArchive (object sender, CanExecuteRoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
e.CanExecute = ViewModel.IsArchive && CurrentDirectory.SelectedIndex != -1;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-24 09:43:20 +08:00
|
|
|
|
private void CanExecuteCreateArchive (object sender, CanExecuteRoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
e.CanExecute = !ViewModel.IsArchive && CurrentDirectory.SelectedItems.Count > 0;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-22 03:26:28 +08:00
|
|
|
|
private void CanExecuteInDirectory (object sender, CanExecuteRoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
e.CanExecute = !ViewModel.IsArchive;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-29 11:12:10 +08:00
|
|
|
|
private void CanExecuteExtract (object sender, CanExecuteRoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (ViewModel.IsArchive)
|
|
|
|
|
{
|
|
|
|
|
e.CanExecute = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else if (CurrentDirectory.SelectedIndex != -1)
|
|
|
|
|
{
|
|
|
|
|
var entry = CurrentDirectory.SelectedItem as EntryViewModel;
|
|
|
|
|
if (entry != null && !entry.IsDirectory)
|
|
|
|
|
{
|
|
|
|
|
e.CanExecute = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
e.CanExecute = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CanExecuteOnPhysicalFile (object sender, CanExecuteRoutedEventArgs e)
|
2014-07-22 03:26:28 +08:00
|
|
|
|
{
|
|
|
|
|
if (!ViewModel.IsArchive && CurrentDirectory.SelectedIndex != -1)
|
|
|
|
|
{
|
|
|
|
|
var entry = CurrentDirectory.SelectedItem as EntryViewModel;
|
|
|
|
|
if (entry != null && !entry.IsDirectory)
|
|
|
|
|
{
|
|
|
|
|
e.CanExecute = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
e.CanExecute = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnParametersRequest (object sender, ParametersRequestEventArgs e)
|
|
|
|
|
{
|
2015-08-12 05:31:56 +08:00
|
|
|
|
var format = sender as IResource;
|
2014-07-27 11:39:58 +08:00
|
|
|
|
if (null != format)
|
|
|
|
|
{
|
|
|
|
|
var control = format.GetAccessWidget() as UIElement;
|
|
|
|
|
if (null != control)
|
|
|
|
|
{
|
|
|
|
|
bool busy_state = m_busy_state;
|
|
|
|
|
var param_dialog = new ArcParametersDialog (control, e.Notice);
|
|
|
|
|
param_dialog.Owner = this;
|
|
|
|
|
e.InputResult = param_dialog.ShowDialog() ?? false;
|
|
|
|
|
if (e.InputResult)
|
|
|
|
|
e.Options = format.GetOptions (control);
|
|
|
|
|
if (busy_state)
|
|
|
|
|
SetBusyState();
|
|
|
|
|
}
|
2014-07-22 03:26:28 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-08-02 05:06:04 +08:00
|
|
|
|
|
|
|
|
|
private void CanExecuteFitWindow (object sender, CanExecuteRoutedEventArgs e)
|
|
|
|
|
{
|
2015-05-12 17:31:27 +08:00
|
|
|
|
e.CanExecute = ImageCanvas.Source != null;
|
2014-08-02 05:06:04 +08:00
|
|
|
|
}
|
2014-08-02 16:59:01 +08:00
|
|
|
|
|
|
|
|
|
private void HideStatusBarExec (object sender, ExecutedRoutedEventArgs e)
|
|
|
|
|
{
|
2014-08-03 14:50:03 +08:00
|
|
|
|
ToggleVisibility (AppStatusBar);
|
2014-08-02 16:59:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void HideMenuBarExec (object sender, ExecutedRoutedEventArgs e)
|
|
|
|
|
{
|
2014-08-03 14:50:03 +08:00
|
|
|
|
ToggleVisibility (MainMenuBar);
|
2014-08-02 16:59:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void HideToolBarExec (object sender, ExecutedRoutedEventArgs e)
|
|
|
|
|
{
|
2014-08-03 14:50:03 +08:00
|
|
|
|
ToggleVisibility (MainToolBar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void ToggleVisibility (UIElement item)
|
|
|
|
|
{
|
|
|
|
|
var status = item.Visibility;
|
2014-08-02 16:59:01 +08:00
|
|
|
|
if (Visibility.Visible == status)
|
2014-08-03 14:50:03 +08:00
|
|
|
|
item.Visibility = Visibility.Collapsed;
|
2014-08-02 16:59:01 +08:00
|
|
|
|
else
|
2014-08-03 14:50:03 +08:00
|
|
|
|
item.Visibility = Visibility.Visible;
|
2014-08-02 16:59:01 +08:00
|
|
|
|
}
|
2014-07-22 03:26:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-02 22:23:20 +08:00
|
|
|
|
public class SortModeToBooleanConverter : IValueConverter
|
|
|
|
|
{
|
|
|
|
|
public object Convert (object value, Type targetType, object parameter, CultureInfo culture)
|
|
|
|
|
{
|
|
|
|
|
string actual_mode = value as string;
|
|
|
|
|
string check_mode = parameter as string;
|
|
|
|
|
if (string.IsNullOrEmpty (check_mode))
|
|
|
|
|
return string.IsNullOrEmpty (actual_mode);
|
|
|
|
|
return check_mode.Equals (actual_mode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public object ConvertBack (object value, Type targetType, object parameter, CultureInfo culture)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-24 09:43:20 +08:00
|
|
|
|
public class BooleanToCollapsedVisibilityConverter : IValueConverter
|
|
|
|
|
{
|
|
|
|
|
#region IValueConverter Members
|
|
|
|
|
|
|
|
|
|
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
|
|
|
|
{
|
|
|
|
|
//reverse conversion (false=>Visible, true=>collapsed) on any given parameter
|
|
|
|
|
bool input = (null == parameter) ? (bool)value : !((bool)value);
|
|
|
|
|
return (input) ? Visibility.Visible : Visibility.Collapsed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-22 03:26:28 +08:00
|
|
|
|
public static class Commands
|
|
|
|
|
{
|
|
|
|
|
public static readonly RoutedCommand OpenItem = new RoutedCommand();
|
2014-07-31 10:56:30 +08:00
|
|
|
|
public static readonly RoutedCommand OpenFile = new RoutedCommand();
|
|
|
|
|
public static readonly RoutedCommand OpenRecent = new RoutedCommand();
|
2014-07-22 03:26:28 +08:00
|
|
|
|
public static readonly RoutedCommand ExtractItem = new RoutedCommand();
|
2014-07-24 09:43:20 +08:00
|
|
|
|
public static readonly RoutedCommand CreateArchive = new RoutedCommand();
|
2014-07-22 03:26:28 +08:00
|
|
|
|
public static readonly RoutedCommand SortBy = new RoutedCommand();
|
|
|
|
|
public static readonly RoutedCommand Exit = new RoutedCommand();
|
2014-07-31 10:56:30 +08:00
|
|
|
|
public static readonly RoutedCommand About = new RoutedCommand();
|
2014-07-22 03:26:28 +08:00
|
|
|
|
public static readonly RoutedCommand GoBack = new RoutedCommand();
|
|
|
|
|
public static readonly RoutedCommand GoForward = new RoutedCommand();
|
|
|
|
|
public static readonly RoutedCommand DeleteItem = new RoutedCommand();
|
|
|
|
|
public static readonly RoutedCommand RenameItem = new RoutedCommand();
|
|
|
|
|
public static readonly RoutedCommand ExploreItem = new RoutedCommand();
|
2015-06-14 13:05:09 +08:00
|
|
|
|
public static readonly RoutedCommand ConvertMedia = new RoutedCommand();
|
2014-07-22 03:26:28 +08:00
|
|
|
|
public static readonly RoutedCommand Refresh = new RoutedCommand();
|
|
|
|
|
public static readonly RoutedCommand Browse = new RoutedCommand();
|
2014-08-02 05:06:04 +08:00
|
|
|
|
public static readonly RoutedCommand FitWindow = new RoutedCommand();
|
2014-08-02 16:59:01 +08:00
|
|
|
|
public static readonly RoutedCommand HideStatusBar = new RoutedCommand();
|
|
|
|
|
public static readonly RoutedCommand HideMenuBar = new RoutedCommand();
|
|
|
|
|
public static readonly RoutedCommand HideToolBar = new RoutedCommand();
|
2015-08-04 02:45:59 +08:00
|
|
|
|
public static readonly RoutedCommand AddSelection = new RoutedCommand();
|
|
|
|
|
public static readonly RoutedCommand SelectAll = new RoutedCommand();
|
2015-08-23 11:35:05 +08:00
|
|
|
|
public static readonly RoutedCommand SetFileType = new RoutedCommand();
|
2014-07-22 03:26:28 +08:00
|
|
|
|
}
|
|
|
|
|
}
|