From d354c217d7fd3a7440384c61dd32c890b0d740f3 Mon Sep 17 00:00:00 2001 From: VisualLinux Date: Mon, 8 May 2017 17:08:03 +0200 Subject: [PATCH 1/3] Preferences view opens only once The program now checks, if the preferences view window is open, and if it is, it sets the focus to the window. --- src/Carnac/CarnacTrayIcon.cs | 13 ++++++++++++- src/Carnac/UI/PreferencesView.xaml | 3 ++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Carnac/CarnacTrayIcon.cs b/src/Carnac/CarnacTrayIcon.cs index 4dcfa5dc..d8ee90e4 100644 --- a/src/Carnac/CarnacTrayIcon.cs +++ b/src/Carnac/CarnacTrayIcon.cs @@ -2,6 +2,8 @@ using System.Drawing; using System.Reflection; using System.Windows.Forms; +using System.Linq; +using System.Windows; using Application = System.Windows.Application; namespace Carnac @@ -39,7 +41,16 @@ public CarnacTrayIcon() void NotifyIconClick(object sender, MouseEventArgs mouseEventArgs) { if (mouseEventArgs.Button == MouseButtons.Left) - OpenPreferences(); + if (Application.Current.Windows.Cast().Any(x=>x.Name=="PreferencesViewWindow")) + { + Application.Current.Windows.Cast() + .Where(x => x.Name == "PreferencesViewWindow") + .ToArray()[0].Activate(); //We have only one window, so the array has only one element + } + else + { + OpenPreferences(); + } } public void Dispose() diff --git a/src/Carnac/UI/PreferencesView.xaml b/src/Carnac/UI/PreferencesView.xaml index 2c303198..bcbcecac 100644 --- a/src/Carnac/UI/PreferencesView.xaml +++ b/src/Carnac/UI/PreferencesView.xaml @@ -11,7 +11,8 @@ Foreground="{DynamicResource BlackBrush}" d:DataContext="{d:DesignInstance ui:PreferencesViewModel}" mc:Ignorable="d" ShowTitleBar="False" ShowMinButton="False" ShowMaxRestoreButton="False" - SaveWindowPosition="True" utilities:DesignTimeHelper.Background="Black"> + SaveWindowPosition="True" utilities:DesignTimeHelper.Background="Black" + Name="PreferencesViewWindow"> From 812fc2b177690f5b9c5cbb5cb348240ae5b72d70 Mon Sep 17 00:00:00 2001 From: VisualLinux Date: Tue, 9 May 2017 11:30:34 +0200 Subject: [PATCH 2/3] Made code more readable --- src/Carnac/CarnacTrayIcon.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Carnac/CarnacTrayIcon.cs b/src/Carnac/CarnacTrayIcon.cs index d8ee90e4..b1e7b862 100644 --- a/src/Carnac/CarnacTrayIcon.cs +++ b/src/Carnac/CarnacTrayIcon.cs @@ -41,11 +41,10 @@ public CarnacTrayIcon() void NotifyIconClick(object sender, MouseEventArgs mouseEventArgs) { if (mouseEventArgs.Button == MouseButtons.Left) - if (Application.Current.Windows.Cast().Any(x=>x.Name=="PreferencesViewWindow")) + var preferencesWindow = Application.Current.Windows.Cast().FirstOrDefault(x => x.Name == "PreferencesViewWindow"); + if (preferencesWindow != null) { - Application.Current.Windows.Cast() - .Where(x => x.Name == "PreferencesViewWindow") - .ToArray()[0].Activate(); //We have only one window, so the array has only one element + preferencesWindow.Activate(); } else { From e4d9c34dbb7d1e8825bf846099a51cb1038444e6 Mon Sep 17 00:00:00 2001 From: VisualLinux Date: Tue, 9 May 2017 14:12:00 +0200 Subject: [PATCH 3/3] Solved compile error --- src/Carnac/CarnacTrayIcon.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Carnac/CarnacTrayIcon.cs b/src/Carnac/CarnacTrayIcon.cs index b1e7b862..cf776940 100644 --- a/src/Carnac/CarnacTrayIcon.cs +++ b/src/Carnac/CarnacTrayIcon.cs @@ -41,6 +41,7 @@ public CarnacTrayIcon() void NotifyIconClick(object sender, MouseEventArgs mouseEventArgs) { if (mouseEventArgs.Button == MouseButtons.Left) + { var preferencesWindow = Application.Current.Windows.Cast().FirstOrDefault(x => x.Name == "PreferencesViewWindow"); if (preferencesWindow != null) { @@ -50,6 +51,7 @@ void NotifyIconClick(object sender, MouseEventArgs mouseEventArgs) { OpenPreferences(); } + } } public void Dispose()