added recent files list.

This commit is contained in:
morkt 2014-07-30 17:15:16 +04:00
parent da8bdc3274
commit 49096a02c5
4 changed files with 64 additions and 15 deletions

View File

@ -83,7 +83,20 @@
</ContextMenu> </ContextMenu>
</Window.Resources> </Window.Resources>
<DockPanel LastChildFill="True"> <DockPanel LastChildFill="True">
<Menu x:Name="MainMenuBar" DockPanel.Dock="Top" IsMainMenu="True" Visibility="Collapsed"/> <Menu x:Name="MainMenuBar" DockPanel.Dock="Top" IsMainMenu="True" Visibility="Collapsed">
<MenuItem Header="File">
<MenuItem Header="Open..."/>
<MenuItem Header="Recent files" ItemsSource="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:MainWindow}, Path=RecentFiles, Mode=OneWay}">
<MenuItem.ItemContainerStyle>
<Style TargetType="MenuItem">
<Setter Property="Header" Value="{Binding}"/>
</Style>
</MenuItem.ItemContainerStyle>
</MenuItem>
<Separator/>
<MenuItem Header="Exit" Command="{x:Static local:Commands.Exit}" InputGestureText="Ctrl+Q"/>
</MenuItem>
</Menu>
<DockPanel Background="{Binding Path=Background, ElementName=MainMenuBar}" x:Name="MainToolBar" <DockPanel Background="{Binding Path=Background, ElementName=MainMenuBar}" x:Name="MainToolBar"
HorizontalAlignment="Stretch" DockPanel.Dock="Top"> HorizontalAlignment="Stretch" DockPanel.Dock="Top">
<DockPanel.Resources> <DockPanel.Resources>
@ -138,7 +151,7 @@
</Button> </Button>
<TextBlock Visibility="Hidden"/> <TextBlock Visibility="Hidden"/>
</DockPanel> </DockPanel>
<StatusBar DockPanel.Dock="Bottom"> <StatusBar DockPanel.Dock="Bottom" x:Name="AppStatusBar">
<StatusBarItem> <StatusBarItem>
<TextBlock x:Name="appStatusText"/> <TextBlock x:Name="appStatusText"/>
</StatusBarItem> </StatusBarItem>

View File

@ -40,6 +40,8 @@ using GARbro.GUI.Properties;
using GARbro.GUI.Strings; using GARbro.GUI.Strings;
using GameRes; using GameRes;
using Rnd.Windows; using Rnd.Windows;
using System.Collections.Specialized;
using System.Collections.ObjectModel;
namespace GARbro.GUI namespace GARbro.GUI
{ {
@ -59,6 +61,10 @@ namespace GARbro.GUI
InitDirectoryChangesWatcher(); InitDirectoryChangesWatcher();
InitPreviewPane(); InitPreviewPane();
if (null == Settings.Default.appRecentFiles)
Settings.Default.appRecentFiles = new StringCollection();
m_recent_files = new ObservableCollection<string> (Settings.Default.appRecentFiles.Cast<string>());
FormatCatalog.Instance.ParametersRequest += OnParametersRequest; FormatCatalog.Instance.ParametersRequest += OnParametersRequest;
CurrentDirectory.SizeChanged += (s, e) => { CurrentDirectory.SizeChanged += (s, e) => {
@ -106,6 +112,10 @@ namespace GARbro.GUI
else else
Settings.Default.lvSortColumn = ""; Settings.Default.lvSortColumn = "";
Settings.Default.appRecentFiles.Clear();
foreach (var file in m_recent_files)
Settings.Default.appRecentFiles.Add (file);
string cwd = CurrentPath; string cwd = CurrentPath;
if (!string.IsNullOrEmpty (cwd)) if (!string.IsNullOrEmpty (cwd))
{ {
@ -133,6 +143,27 @@ namespace GARbro.GUI
Dispatcher.Invoke (() => MessageBox.Show (this, message, title, MessageBoxButton.OK, MessageBoxImage.Error)); Dispatcher.Invoke (() => MessageBox.Show (this, message, title, MessageBoxButton.OK, MessageBoxImage.Error));
} }
const int MaxRecentFiles = 10;
ObservableCollection<string> m_recent_files;
public ObservableCollection<string> 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);
}
}
/// <summary> /// <summary>
/// Set data context of the ListView. /// Set data context of the ListView.
/// </summary> /// </summary>
@ -152,6 +183,10 @@ namespace GARbro.GUI
var cvs = this.Resources["ListViewSource"] as CollectionViewSource; var cvs = this.Resources["ListViewSource"] as CollectionViewSource;
cvs.Source = value; cvs.Source = value;
pathLine.Text = value.Path; pathLine.Text = value.Path;
if (value.IsArchive)
PushRecentFile (value.Path);
if (m_lvSortByColumn != null) if (m_lvSortByColumn != null)
lv_Sort (m_lvSortByColumn.Tag.ToString(), m_lvSortDirection); lv_Sort (m_lvSortByColumn.Tag.ToString(), m_lvSortDirection);
else else
@ -385,19 +420,6 @@ namespace GARbro.GUI
{ {
var dataView = CollectionViewSource.GetDefaultView (CurrentDirectory.ItemsSource) as ListCollectionView; var dataView = CollectionViewSource.GetDefaultView (CurrentDirectory.ItemsSource) as ListCollectionView;
dataView.CustomSort = new FileSystemComparer (sortBy, direction); 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));
}
}
*/
} }
/// <summary> /// <summary>

View File

@ -238,5 +238,16 @@ namespace GARbro.GUI.Properties {
this["appArchiveFormat"] = value; 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;
}
}
} }
} }

View File

@ -56,5 +56,8 @@
<Setting Name="appArchiveFormat" Type="System.String" Scope="User"> <Setting Name="appArchiveFormat" Type="System.String" Scope="User">
<Value Profile="(Default)" /> <Value Profile="(Default)" />
</Setting> </Setting>
<Setting Name="appRecentFiles" Type="System.Collections.Specialized.StringCollection" Scope="User">
<Value Profile="(Default)" />
</Setting>
</Settings> </Settings>
</SettingsFile> </SettingsFile>