From 75e206bc09ff7501b2c253a111cd81bfaef3ba6d Mon Sep 17 00:00:00 2001 From: Nina Martin Date: Mon, 29 Jun 2015 18:25:52 -0400 Subject: [PATCH 1/9] * Added CloseProcesses, a multiple window closer. --- Core/AppWindow.cs | 6 +++--- Switcheroo/MainWindow.xaml | 3 +++ Switcheroo/MainWindow.xaml.cs | 30 +++++++++++++++++++++++++++--- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/Core/AppWindow.cs b/Core/AppWindow.cs index 27bf6ae..8b0e81d 100644 --- a/Core/AppWindow.cs +++ b/Core/AppWindow.cs @@ -93,8 +93,8 @@ public AppWindow Owner return new AppWindow(ownerHandle); } } - - public new static IEnumerable AllToplevelWindows + + public new static IEnumerable AllToplevelWindows { get { @@ -186,4 +186,4 @@ private static string GetExecutablePath(int processId) throw new Win32Exception(Marshal.GetLastWin32Error()); } } -} \ No newline at end of file +} diff --git a/Switcheroo/MainWindow.xaml b/Switcheroo/MainWindow.xaml index 38056c7..58775ae 100644 --- a/Switcheroo/MainWindow.xaml +++ b/Switcheroo/MainWindow.xaml @@ -12,6 +12,8 @@ + + diff --git a/Switcheroo/MainWindow.xaml.cs b/Switcheroo/MainWindow.xaml.cs index 793e4f4..151dc6b 100644 --- a/Switcheroo/MainWindow.xaml.cs +++ b/Switcheroo/MainWindow.xaml.cs @@ -56,6 +56,7 @@ public partial class MainWindow : Window public static readonly RoutedUICommand SwitchToWindowCommand = new RoutedUICommand(); public static readonly RoutedUICommand ScrollListDownCommand = new RoutedUICommand(); public static readonly RoutedUICommand ScrollListUpCommand = new RoutedUICommand(); + public static readonly RoutedUICommand CloseProcessesCommand = new RoutedUICommand(); private OptionsWindow _optionsWindow; private AboutWindow _aboutWindow; private AltTabHook _altTabHook; @@ -526,7 +527,7 @@ private void TextChanged(object sender, TextChangedEventArgs args) }; var filterResults = new WindowFilterer().Filter(context, query).ToList(); - + foreach (var filterResult in filterResults) { filterResult.AppWindow.FormattedTitle = @@ -570,7 +571,7 @@ private async void CloseWindow(object sender, ExecutedRoutedEventArgs e) { bool isClosed = await _windowCloser.TryCloseAsync(win); if (isClosed) - RemoveWindow(win); + RemoveWindow(win); } } else @@ -580,6 +581,28 @@ private async void CloseWindow(object sender, ExecutedRoutedEventArgs e) e.Handled = true; } + private async void CloseProcesses(object sender, ExecutedRoutedEventArgs e) + { + if (lb.Items.Count > 0) + { + foreach (AppWindowViewModel win in _filteredWindowList) + { + if (win != null) + { + bool isClosed = await _windowCloser.TryCloseAsync(win); + if(isClosed) + RemoveWindow(win); + } + } + } + else + { + HideWindow(); + } + + e.Handled = true; + } + private void RemoveWindow(AppWindowViewModel window) { int index = _filteredWindowList.IndexOf(window); @@ -688,4 +711,5 @@ private enum InitialFocus PreviousItem } } -} \ No newline at end of file +} + From 271e97297baf98fb038fb15153fd487820f6f02d Mon Sep 17 00:00:00 2001 From: Nina Martin Date: Mon, 29 Jun 2015 18:47:09 -0400 Subject: [PATCH 2/9] * Fixed accidental uncomment --- Switcheroo/MainWindow.xaml.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Switcheroo/MainWindow.xaml.cs b/Switcheroo/MainWindow.xaml.cs index 151dc6b..fc27aea 100644 --- a/Switcheroo/MainWindow.xaml.cs +++ b/Switcheroo/MainWindow.xaml.cs @@ -590,8 +590,8 @@ private async void CloseProcesses(object sender, ExecutedRoutedEventArgs e) if (win != null) { bool isClosed = await _windowCloser.TryCloseAsync(win); - if(isClosed) - RemoveWindow(win); + //if(isClosed) + // RemoveWindow(win); } } } From 7c4b757f7d2025a8b833ecc42962f3d163a1ca7d Mon Sep 17 00:00:00 2001 From: HellBrick Date: Tue, 30 Jun 2015 07:52:10 +0300 Subject: [PATCH 3/9] Extracted TryCloseAndRemoveWindowAsync() --- Switcheroo/MainWindow.xaml.cs | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/Switcheroo/MainWindow.xaml.cs b/Switcheroo/MainWindow.xaml.cs index fc27aea..4471adf 100644 --- a/Switcheroo/MainWindow.xaml.cs +++ b/Switcheroo/MainWindow.xaml.cs @@ -567,12 +567,7 @@ private async void CloseWindow(object sender, ExecutedRoutedEventArgs e) if (lb.Items.Count > 0) { var win = (AppWindowViewModel) lb.SelectedItem; - if (win != null) - { - bool isClosed = await _windowCloser.TryCloseAsync(win); - if (isClosed) - RemoveWindow(win); - } + await TryCloseAndRemoveWindowAsync( win ); } else { @@ -581,18 +576,31 @@ private async void CloseWindow(object sender, ExecutedRoutedEventArgs e) e.Handled = true; } + private async Task TryCloseAndRemoveWindowAsync( AppWindowViewModel win ) + { + if ( win != null ) + { + bool isClosed = await _windowCloser.TryCloseAsync( win ); + if ( isClosed ) + RemoveWindow( win ); + + return isClosed; + } + else + { + // I'm not sure when exactly it happens so I return 'all is good' just in case. + // At least this doesn't mean that the window prevents closing itself. + return true; + } + } + private async void CloseProcesses(object sender, ExecutedRoutedEventArgs e) { if (lb.Items.Count > 0) { foreach (AppWindowViewModel win in _filteredWindowList) { - if (win != null) - { - bool isClosed = await _windowCloser.TryCloseAsync(win); - //if(isClosed) - // RemoveWindow(win); - } + await TryCloseAndRemoveWindowAsync( win ); } } else From 17cb4525701ba7cc9501e8d56f5ebe5060593c13 Mon Sep 17 00:00:00 2001 From: HellBrick Date: Tue, 30 Jun 2015 07:56:26 +0300 Subject: [PATCH 4/9] CloseProcesses() closes the windows concurrently (instead of sequentially) --- Switcheroo/MainWindow.xaml.cs | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/Switcheroo/MainWindow.xaml.cs b/Switcheroo/MainWindow.xaml.cs index 4471adf..0e78333 100644 --- a/Switcheroo/MainWindow.xaml.cs +++ b/Switcheroo/MainWindow.xaml.cs @@ -594,22 +594,27 @@ private async Task TryCloseAndRemoveWindowAsync( AppWindowViewModel win ) } } - private async void CloseProcesses(object sender, ExecutedRoutedEventArgs e) - { - if (lb.Items.Count > 0) - { - foreach (AppWindowViewModel win in _filteredWindowList) - { - await TryCloseAndRemoveWindowAsync( win ); - } - } - else - { - HideWindow(); - } + private async void CloseProcesses( object sender, ExecutedRoutedEventArgs e ) + { + if ( lb.Items.Count > 0 ) + { + var closingTasks = _filteredWindowList + .Select( window => TryCloseAndRemoveWindowAsync( window ) ) + .ToArray(); + + var results = await Task.WhenAll( closingTasks ); + if ( results.All( closedSuccessfully => closedSuccessfully ) ) + { + // TODO: something. Maybe reset the filter text since we've closed all the windows that fit the filter anyway? + } + } + else + { + HideWindow(); + } - e.Handled = true; - } + e.Handled = true; + } private void RemoveWindow(AppWindowViewModel window) { From d6c4ca2ad4fd4b51422ee3f066fafe1e5c249479 Mon Sep 17 00:00:00 2001 From: Nina Martin Date: Mon, 6 Jul 2015 21:09:47 -0400 Subject: [PATCH 5/9] * Commented RemoveWindow to temporarily avoid UnhandledOperationException --- Switcheroo.sln | 8 ++++---- Switcheroo/MainWindow.xaml.cs | 11 +++++++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Switcheroo.sln b/Switcheroo.sln index 655f80b..38c8c08 100644 --- a/Switcheroo.sln +++ b/Switcheroo.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.30723.0 +# Visual Studio 14 +VisualStudioVersion = 14.0.22823.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Switcheroo", "Switcheroo\Switcheroo.csproj", "{B28E183B-0E38-48A8-8A4E-B4AB7B23CE93}" ProjectSection(ProjectDependencies) = postProject @@ -27,8 +27,8 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {B28E183B-0E38-48A8-8A4E-B4AB7B23CE93}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B28E183B-0E38-48A8-8A4E-B4AB7B23CE93}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B28E183B-0E38-48A8-8A4E-B4AB7B23CE93}.Debug|Any CPU.ActiveCfg = Release|Any CPU + {B28E183B-0E38-48A8-8A4E-B4AB7B23CE93}.Debug|Any CPU.Build.0 = Release|Any CPU {B28E183B-0E38-48A8-8A4E-B4AB7B23CE93}.Release|Any CPU.ActiveCfg = Release|Any CPU {B28E183B-0E38-48A8-8A4E-B4AB7B23CE93}.Release|Any CPU.Build.0 = Release|Any CPU {FBD3EC1E-47E2-4D2D-81C9-D6506125A09A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU diff --git a/Switcheroo/MainWindow.xaml.cs b/Switcheroo/MainWindow.xaml.cs index 0e78333..541a9be 100644 --- a/Switcheroo/MainWindow.xaml.cs +++ b/Switcheroo/MainWindow.xaml.cs @@ -550,6 +550,12 @@ private static string GetFormattedTitleFromBestResult(IList matchRe return new XamlHighlighter().Highlight(bestResult.StringParts); } + private void OnSpaceBarPressed(object sender, ExecutedRoutedEventArgs e) + { + Switch(); + e.Handled = true; + } + private void OnEnterPressed(object sender, ExecutedRoutedEventArgs e) { Switch(); @@ -581,9 +587,10 @@ private async Task TryCloseAndRemoveWindowAsync( AppWindowViewModel win ) if ( win != null ) { bool isClosed = await _windowCloser.TryCloseAsync( win ); - if ( isClosed ) + /*if ( isClosed ) RemoveWindow( win ); - + */ + return isClosed; } else From 19c3b542c29e9aee81a400f08e8cba1a3463190b Mon Sep 17 00:00:00 2001 From: HellBrick Date: Tue, 7 Jul 2015 07:55:03 +0300 Subject: [PATCH 6/9] Creating a copy of _filteredWindowList before closing multiple windows to avoid modifying a collection that's being iterated on --- Switcheroo/MainWindow.xaml.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Switcheroo/MainWindow.xaml.cs b/Switcheroo/MainWindow.xaml.cs index 0e78333..33fdfd4 100644 --- a/Switcheroo/MainWindow.xaml.cs +++ b/Switcheroo/MainWindow.xaml.cs @@ -599,6 +599,7 @@ private async void CloseProcesses( object sender, ExecutedRoutedEventArgs e ) if ( lb.Items.Count > 0 ) { var closingTasks = _filteredWindowList + .ToArray() .Select( window => TryCloseAndRemoveWindowAsync( window ) ) .ToArray(); From c5052a9454e6ab34507f9bd7316a400e784e8f9a Mon Sep 17 00:00:00 2001 From: Nina Martin Date: Sat, 11 Jul 2015 15:40:39 -0400 Subject: [PATCH 7/9] Changed close command to Ctrl-Shift-W * --- Switcheroo/MainWindow.xaml | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Switcheroo/MainWindow.xaml b/Switcheroo/MainWindow.xaml index 58775ae..d155017 100644 --- a/Switcheroo/MainWindow.xaml +++ b/Switcheroo/MainWindow.xaml @@ -16,6 +16,8 @@ Executed="CloseProcesses" /> + - + @@ -60,7 +62,14 @@ ctrl+w to close a window - + + + Press esc to dismiss the Switcheroo overlay @@ -109,7 +118,7 @@ - From 4cab08445cdb5ddef2e30dab5e12a41ae5610b44 Mon Sep 17 00:00:00 2001 From: Regin Larsen Date: Tue, 13 Mar 2018 20:00:43 +0100 Subject: [PATCH 8/9] Add confirmation window and combine with current window closer --- Core.UnitTests/Core.UnitTests.csproj | 3 ++ Switcheroo/MainWindow.xaml | 2 +- Switcheroo/MainWindow.xaml.cs | 61 ++++++++++++---------------- 3 files changed, 31 insertions(+), 35 deletions(-) diff --git a/Core.UnitTests/Core.UnitTests.csproj b/Core.UnitTests/Core.UnitTests.csproj index 91afd39..88d1a1d 100644 --- a/Core.UnitTests/Core.UnitTests.csproj +++ b/Core.UnitTests/Core.UnitTests.csproj @@ -54,6 +54,9 @@ Core + + +