From 53b32006cb77c5b48406c21e0ca8570e9569a3a3 Mon Sep 17 00:00:00 2001 From: morkt Date: Sun, 3 May 2015 22:12:51 +0400 Subject: [PATCH] (MainWindow): various tweaks. - set ImageData default DPI to desktop resolution. - display menubar on ALT keypress when it's hidden. - tweaked filename lookup on keypress logic (search should start from the current position, not from beginning). --- MainWindow.xaml | 1 + MainWindow.xaml.cs | 45 +++++++++++++++++++++++++++++++++------------ 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/MainWindow.xaml b/MainWindow.xaml index 395e9d48..36402d6f 100644 --- a/MainWindow.xaml +++ b/MainWindow.xaml @@ -6,6 +6,7 @@ xmlns:p="clr-namespace:GARbro.GUI.Properties" Title="GARbro" MinHeight="250" ResizeMode="CanResizeWithGrip" Loaded="WindowLoaded" + KeyDown="WindowKeyDown" Top="{Binding Source={x:Static p:Settings.Default}, Path=winTop, Mode=TwoWay}" Left="{Binding Source={x:Static p:Settings.Default}, Path=winLeft, Mode=TwoWay}" Height="{Binding Source={x:Static p:Settings.Default}, Path=winHeight, Mode=TwoWay}" diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index 97de6317..2f0e46aa 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -87,6 +87,7 @@ namespace GARbro.GUI { lv_SetSortMode (Settings.Default.lvSortColumn, Settings.Default.lvSortDirection); Dispatcher.InvokeAsync (WindowRendered, DispatcherPriority.ContextIdle); + ImageData.SetDefaultDpi (Desktop.DpiX, Desktop.DpiY); } void WindowRendered () @@ -96,6 +97,24 @@ namespace GARbro.GUI SetStatusText (guiStrings.MsgReady); } + 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; + } + } + /// /// Save settings when main window is about to close /// @@ -168,7 +187,7 @@ namespace GARbro.GUI get { int i = 1; - return m_recent_files.Select (f => new Tuple (f, string.Format ("_{0} {1}", i++, f))); + return m_recent_files.Select (f => Tuple.Create (f, string.Format ("_{0} {1}", i++, f))); } } @@ -545,20 +564,22 @@ namespace GARbro.GUI if (m_current_input.Mismatch) return; - var items = source.Cast(); - if (1 == m_current_input.Phrase.Length && m_current_input.Phrase[0] == key[0]) - { - // same key repeats, lookup by first letter only - int current = CurrentDirectory.SelectedIndex; - if (current != -1 && current+1 < source.Count) - { - items = items.Skip (current+1).Concat (items.Take (current+1)); - } - } - else + if (!(1 == m_current_input.Phrase.Length && m_current_input.Phrase[0] == key[0])) { m_current_input.Phrase.Append (key); } + int start_index = CurrentDirectory.SelectedIndex; + if (1 == m_current_input.Phrase.Length) + { + // lookup starting from the next item + if (start_index != -1 && start_index+1 < source.Count) + ++start_index; + } + var items = source.Cast(); + if (start_index > 0) + { + items = items.Skip (start_index).Concat (items.Take (start_index)); + } string input = m_current_input.Phrase.ToString(); var matched = items.Where (e => e.Name.StartsWith (input, StringIgnoreCase)).FirstOrDefault(); if (null != matched)