From 49096a02c546d9dfbe9cc5638f8f1d06843da965 Mon Sep 17 00:00:00 2001 From: morkt Date: Wed, 30 Jul 2014 17:15:16 +0400 Subject: [PATCH] added recent files list. --- MainWindow.xaml | 17 ++++++++++-- MainWindow.xaml.cs | 48 ++++++++++++++++++++++++--------- Properties/Settings.Designer.cs | 11 ++++++++ Properties/Settings.settings | 3 +++ 4 files changed, 64 insertions(+), 15 deletions(-) diff --git a/MainWindow.xaml b/MainWindow.xaml index 61bf21a0..33c25b11 100644 --- a/MainWindow.xaml +++ b/MainWindow.xaml @@ -83,7 +83,20 @@ - + + + + + + + + + + + + @@ -138,7 +151,7 @@ - + diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index f6ba46e8..d664364a 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -40,6 +40,8 @@ using GARbro.GUI.Properties; using GARbro.GUI.Strings; using GameRes; using Rnd.Windows; +using System.Collections.Specialized; +using System.Collections.ObjectModel; namespace GARbro.GUI { @@ -59,6 +61,10 @@ namespace GARbro.GUI InitDirectoryChangesWatcher(); InitPreviewPane(); + if (null == Settings.Default.appRecentFiles) + Settings.Default.appRecentFiles = new StringCollection(); + m_recent_files = new ObservableCollection (Settings.Default.appRecentFiles.Cast()); + FormatCatalog.Instance.ParametersRequest += OnParametersRequest; CurrentDirectory.SizeChanged += (s, e) => { @@ -106,6 +112,10 @@ namespace GARbro.GUI else Settings.Default.lvSortColumn = ""; + Settings.Default.appRecentFiles.Clear(); + foreach (var file in m_recent_files) + Settings.Default.appRecentFiles.Add (file); + string cwd = CurrentPath; if (!string.IsNullOrEmpty (cwd)) { @@ -133,6 +143,27 @@ namespace GARbro.GUI Dispatcher.Invoke (() => MessageBox.Show (this, message, title, MessageBoxButton.OK, MessageBoxImage.Error)); } + const int MaxRecentFiles = 10; + ObservableCollection m_recent_files; + + public ObservableCollection RecentFiles { get { return m_recent_files; } } + + void PushRecentFile (string file) + { + var found = m_recent_files.IndexOf (file); + if (-1 == found) + { + if (MaxRecentFiles == m_recent_files.Count) + m_recent_files.RemoveAt (0); + m_recent_files.Add (file); + } + else if (found+1 != m_recent_files.Count) + { + m_recent_files.RemoveAt (found); + m_recent_files.Add (file); + } + } + /// /// Set data context of the ListView. /// @@ -152,6 +183,10 @@ namespace GARbro.GUI var cvs = this.Resources["ListViewSource"] as CollectionViewSource; cvs.Source = value; pathLine.Text = value.Path; + + if (value.IsArchive) + PushRecentFile (value.Path); + if (m_lvSortByColumn != null) lv_Sort (m_lvSortByColumn.Tag.ToString(), m_lvSortDirection); else @@ -385,19 +420,6 @@ namespace GARbro.GUI { var dataView = CollectionViewSource.GetDefaultView (CurrentDirectory.ItemsSource) as ListCollectionView; dataView.CustomSort = new FileSystemComparer (sortBy, direction); - /* - using (dataView.DeferRefresh()) - { - dataView.SortDescriptions.Clear(); - dataView.SortDescriptions.Add (new SortDescription ("Priority", ListSortDirection.Ascending)); - if (!string.IsNullOrEmpty (sortBy)) - { - dataView.SortDescriptions.Add (new SortDescription (sortBy, direction)); - if (sortBy != "Name") - dataView.SortDescriptions.Add (new SortDescription ("Name", ListSortDirection.Ascending)); - } - } - */ } /// diff --git a/Properties/Settings.Designer.cs b/Properties/Settings.Designer.cs index f1f5b1ca..67124233 100644 --- a/Properties/Settings.Designer.cs +++ b/Properties/Settings.Designer.cs @@ -238,5 +238,16 @@ namespace GARbro.GUI.Properties { this["appArchiveFormat"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + public global::System.Collections.Specialized.StringCollection appRecentFiles { + get { + return ((global::System.Collections.Specialized.StringCollection)(this["appRecentFiles"])); + } + set { + this["appRecentFiles"] = value; + } + } } } diff --git a/Properties/Settings.settings b/Properties/Settings.settings index 40dff0a2..66fc299a 100644 --- a/Properties/Settings.settings +++ b/Properties/Settings.settings @@ -56,5 +56,8 @@ + + + \ No newline at end of file