From bc11832f9fceb28cc7df9c334471091fabd0399f Mon Sep 17 00:00:00 2001 From: Stone_Red <56473591+Stone-Red-Code@users.noreply.github.com> Date: Fri, 29 Nov 2024 18:40:00 +0100 Subject: [PATCH] Add right click actions to tray icon --- src/DesktopMagic/MainWindow.xaml.cs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/DesktopMagic/MainWindow.xaml.cs b/src/DesktopMagic/MainWindow.xaml.cs index fc1036d..e6ff4da 100644 --- a/src/DesktopMagic/MainWindow.xaml.cs +++ b/src/DesktopMagic/MainWindow.xaml.cs @@ -53,10 +53,21 @@ namespace DesktopMagic try { Stream iconStream = Application.GetResourceStream(new Uri("pack://application:,,,/DesktopMagic;component/icon.ico")).Stream; - notifyIcon.Click += TaskbarIcon_TrayLeftClick; + notifyIcon.MouseClick += NotifyIcon_MouseClick; notifyIcon.Visible = true; notifyIcon.Text = App.AppName; notifyIcon.Icon = new System.Drawing.Icon(iconStream); + notifyIcon.ContextMenuStrip = new System.Windows.Forms.ContextMenuStrip() + { + Items = + { + new System.Windows.Forms.ToolStripMenuItem("Open", null, (s, e) => RestoreWindow()), + new System.Windows.Forms.ToolStripMenuItem("Toggle Edit Mode", null, (s, e) => { EditCheckBox.IsChecked = !EditCheckBox.IsChecked; EditCheckBox_Click(null, null); }), + new System.Windows.Forms.ToolStripMenuItem("Plugin Manager", null, (s, e) => PluginManagerButton_Click(null!, null!)), + new System.Windows.Forms.ToolStripMenuItem("GitHub", null, (s, e) => GitHubButton_Click(null!, null!)), + new System.Windows.Forms.ToolStripMenuItem("Exit", null, (s, e) => Close()), + } + }; InitializeComponent(); @@ -569,6 +580,7 @@ namespace DesktopMagic } EditCheckBox.IsChecked = false; + EditCheckBox_Click(null, null); blockWindowsClosing = true; Windows.Clear(); WindowNames.Clear(); @@ -634,9 +646,12 @@ namespace DesktopMagic LoadLayout(false); } - private void TaskbarIcon_TrayLeftClick(object? sender, EventArgs e) + private void NotifyIcon_MouseClick(object? sender, System.Windows.Forms.MouseEventArgs e) { - RestoreWindow(); + if (e.Button == System.Windows.Forms.MouseButtons.Left) + { + RestoreWindow(); + } } private void GitHubButton_Click(object sender, RoutedEventArgs e)