diff --git a/GoToWindow/App.config b/GoToWindow/App.config
index 288b1a2..d572bfe 100644
--- a/GoToWindow/App.config
+++ b/GoToWindow/App.config
@@ -16,6 +16,9 @@
5B+09:2
+
+ False
+
diff --git a/GoToWindow/App.xaml.cs b/GoToWindow/App.xaml.cs
index ab6fc72..d11beca 100644
--- a/GoToWindow/App.xaml.cs
+++ b/GoToWindow/App.xaml.cs
@@ -137,7 +137,7 @@ private void Application_Deactivated(object sender, EventArgs e)
Log.Debug("Application deactivated.");
if (_context != null)
- _context.Hide();
+ _context.Hide(false);
}
private void Application_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
diff --git a/GoToWindow/GoToWindowContext.cs b/GoToWindow/GoToWindowContext.cs
index 2413e64..ea63856 100644
--- a/GoToWindow/GoToWindowContext.cs
+++ b/GoToWindow/GoToWindowContext.cs
@@ -5,6 +5,7 @@
using System.Windows.Interop;
using System.Windows.Threading;
using GoToWindow.Api;
+using GoToWindow.Properties;
using GoToWindow.ViewModels;
using GoToWindow.Windows;
using log4net;
@@ -18,7 +19,7 @@ public interface IGoToWindowContext : IDisposable
IGoToWindowPluginsContainer PluginsContainer { get; }
void Init();
void Show();
- void Hide();
+ void Hide(bool requested);
void EnableKeyboardHook(KeyboardShortcut shortcut);
void ShowSettings();
void UpdateAvailable(string version);
@@ -129,13 +130,16 @@ private void SetAvailableWindowSize(double screenWidth, double screenHeight)
}
}
- public void Hide()
+ public void Hide(bool requested)
{
- Hide(false);
+ Hide(false, requested);
}
- public void Hide(bool hideIfPending)
+ public void Hide(bool hideIfPending, bool requested)
{
+ if (!requested && Settings.Default.KeepOpenOnLostFocus)
+ return;
+
lock (_lock)
{
if (_state == GoToWindowState.Showing)
@@ -256,7 +260,7 @@ private bool HideWindowIfNotForeground()
Log.DebugFormat("Window does not have focus when initialization is complete. Current foreground window is {0} (Process '{1}')", foregroundWindow.HWnd, foregroundWindow.ProcessName);
#endif
- Hide();
+ Hide(false);
return true;
}
@@ -276,9 +280,9 @@ private void HandleShortcut()
Application.Current.Dispatcher.InvokeAsync(Show, DispatcherPriority.Normal);
}
- private void _mainViewModel_Hide(object sender, EventArgs e)
+ private void _mainViewModel_Hide(object sender, CloseEventArgs e)
{
- Hide();
+ Hide(false, e.Requested);
}
public void Dispose()
diff --git a/GoToWindow/Properties/Settings.Designer.cs b/GoToWindow/Properties/Settings.Designer.cs
index c612d23..7a123b6 100644
--- a/GoToWindow/Properties/Settings.Designer.cs
+++ b/GoToWindow/Properties/Settings.Designer.cs
@@ -12,7 +12,7 @@ namespace GoToWindow.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
- [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0")]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
@@ -57,5 +57,17 @@ public string OpenShortcut {
this["OpenShortcut"] = value;
}
}
+
+ [global::System.Configuration.UserScopedSettingAttribute()]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Configuration.DefaultSettingValueAttribute("False")]
+ public bool KeepOpenOnLostFocus {
+ get {
+ return ((bool)(this["KeepOpenOnLostFocus"]));
+ }
+ set {
+ this["KeepOpenOnLostFocus"] = value;
+ }
+ }
}
}
diff --git a/GoToWindow/Properties/Settings.settings b/GoToWindow/Properties/Settings.settings
index 4469bd1..ca1c952 100644
--- a/GoToWindow/Properties/Settings.settings
+++ b/GoToWindow/Properties/Settings.settings
@@ -11,5 +11,8 @@
5B+09:2
+
+ False
+
\ No newline at end of file
diff --git a/GoToWindow/ViewModels/MainViewModel.cs b/GoToWindow/ViewModels/MainViewModel.cs
index 952f133..3d9b5f7 100644
--- a/GoToWindow/ViewModels/MainViewModel.cs
+++ b/GoToWindow/ViewModels/MainViewModel.cs
@@ -87,7 +87,7 @@ public bool UpdateAvailable
public ICommand GoToWindowEntryShortcut { get; private set; }
- public event EventHandler Close;
+ public event CloseEventHandler Close;
public MainViewModel()
{
@@ -140,10 +140,10 @@ public void Empty()
IsRowIndexVisible = false;
}
- public void AskClose()
+ public void AskClose(bool requested)
{
if (Close != null)
- Close(this, new EventArgs());
+ Close(this, new CloseEventArgs(requested));
}
private ISearchResult GetEntryAt(int index)
@@ -162,7 +162,19 @@ private ISearchResult GetEntryAt(int index)
private void GoToWindowEntryShortcutCommand_Executed(object sender, EventArgs e)
{
if (Close != null)
- Close(this, new EventArgs());
+ Close(this, new CloseEventArgs(true));
}
}
+
+ public delegate void CloseEventHandler(object sender, CloseEventArgs args);
+
+ public class CloseEventArgs : EventArgs
+ {
+ public bool Requested { get; private set; }
+
+ public CloseEventArgs(bool requested)
+ {
+ Requested = requested;
+ }
+ }
}
diff --git a/GoToWindow/ViewModels/SettingsViewModel.cs b/GoToWindow/ViewModels/SettingsViewModel.cs
index c1c9847..2f6e255 100644
--- a/GoToWindow/ViewModels/SettingsViewModel.cs
+++ b/GoToWindow/ViewModels/SettingsViewModel.cs
@@ -41,6 +41,7 @@ public SettingsViewModel(IGoToWindowContext context)
}
public bool WindowListSingleClick { get; set; }
+ public bool KeepOpenOnLostFocus { get; set; }
public bool NoElevatedPrivilegesWarning { get; set; }
public string Version { get; set; }
public List Plugins { get; protected set; }
@@ -151,6 +152,7 @@ public void Load()
{
// Settings
WindowListSingleClick = Settings.Default.WindowListSingleClick;
+ KeepOpenOnLostFocus = Settings.Default.KeepOpenOnLostFocus;
// Shortcut
var shortcut = KeyboardShortcut.FromString(Settings.Default.OpenShortcut);
@@ -190,6 +192,7 @@ public void Apply()
// Settings
Settings.Default.WindowListSingleClick = WindowListSingleClick;
+ Settings.Default.KeepOpenOnLostFocus = KeepOpenOnLostFocus;
// Plugins
var disabledPlugins = new StringCollection();
diff --git a/GoToWindow/Windows/MainWindow.xaml.cs b/GoToWindow/Windows/MainWindow.xaml.cs
index 4a42577..eb99549 100644
--- a/GoToWindow/Windows/MainWindow.xaml.cs
+++ b/GoToWindow/Windows/MainWindow.xaml.cs
@@ -64,7 +64,7 @@ private void FocusSelectedWindowItem()
windowEntry.Select();
- ViewModel.AskClose();
+ ViewModel.AskClose(true);
}
private void SearchTextBox_TextChanged(object sender, TextChangedEventArgs e)
@@ -185,7 +185,7 @@ private void WindowsListView_PreviewKeyDown(object sender, KeyEventArgs e)
private void ClearSearchButton_Click(object sender, RoutedEventArgs e)
{
- ViewModel.AskClose();
+ ViewModel.AskClose(true);
}
private void Window_Activated(object sender, EventArgs e)
@@ -196,7 +196,7 @@ private void Window_Activated(object sender, EventArgs e)
private void Window_Deactivated(object sender, EventArgs e)
{
Log.Debug("Window deactivated.");
- ViewModel.AskClose();
+ ViewModel.AskClose(false);
}
private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
@@ -205,7 +205,7 @@ private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
ViewModel.IsRowIndexVisible = true;
if (e.Key == Key.Escape)
- ViewModel.AskClose();
+ ViewModel.AskClose(true);
}
private void Window_PreviewKeyUp(object sender, KeyEventArgs e)
diff --git a/GoToWindow/Windows/SettingsWindow.xaml b/GoToWindow/Windows/SettingsWindow.xaml
index 4c3c530..8188c1d 100644
--- a/GoToWindow/Windows/SettingsWindow.xaml
+++ b/GoToWindow/Windows/SettingsWindow.xaml
@@ -121,6 +121,7 @@
+