Permalink
Browse files

Added System Tray Context Menu.

Added failsafe for settings load failures.
  • Loading branch information...
Elestriel
Elestriel committed Jan 10, 2017
1 parent 83d0c19 commit a6ada0788f673bb0068e185876ee7e3e0bf90b0f
Showing with 41 additions and 6 deletions.
  1. +10 −0 TaskbarTool/MainWindow.xaml
  2. +29 −4 TaskbarTool/MainWindow.xaml.cs
  3. +2 −2 TaskbarTool/Properties/AssemblyInfo.cs
@@ -11,6 +11,16 @@
MinHeight="160" MinWidth="370"
Icon="Resources/Mushroom1UP.ico"
ContentRendered="Window_ContentRendered" Closing="Window_Closing">
<Window.Resources>
<!-- Tray Icon ContextMenu -->
<ContextMenu x:Key="TrayContextMenu">
<ContextMenu.Items>
<MenuItem x:Name="SysTrayStartStopButton" Header="Pause/Resume" Click="StartStopButton_Click"/>
<Separator/>
<MenuItem x:Name="SysTrayQuitButton" Header="Quit" IsEnabled="True" Click="CloseMainWindow"/>
</ContextMenu.Items>
</ContextMenu>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
@@ -6,6 +6,7 @@
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace TaskbarTool
@@ -81,17 +82,21 @@ public WinCompatTrData(WindowCompositionAttribute attribute, IntPtr data, int si
static bool RunTask = false;
static AccentPolicy accentPolicy = new AccentPolicy();
static System.Windows.Forms.NotifyIcon SysTrayIcon;
ContextMenu SysTrayContextMenu;
#endregion Declarations
#region Initializations
public MainWindow()
{
InitializeComponent();
SysTrayContextMenu = this.FindResource("TrayContextMenu") as ContextMenu;
SysTrayIcon = new System.Windows.Forms.NotifyIcon();
Stream iconStream = Application.GetResourceStream(new Uri("pack://application:,,,/TaskbarTool;component/Resources/Mushroom1UP.ico")).Stream;
Stream iconStream = Application.GetResourceStream(new Uri("Resources/Mushroom1UP.ico", UriKind.Relative)).Stream;
SysTrayIcon.Icon = new System.Drawing.Icon(iconStream);
SysTrayIcon.Visible = true;
SysTrayIcon.MouseClick += SysTrayIcon_MouseClick;
SysTrayIcon.DoubleClick +=
delegate (object sender, EventArgs args)
{
@@ -111,6 +116,7 @@ protected override void OnStateChanged(EventArgs e)
private void PopulateComboBoxes()
{
AccentStateComboBox.ItemsSource = Enum.GetValues(typeof(AccentState)).Cast<AccentState>();
AccentStateComboBox.SelectedIndex = 0;
}
private void LoadSettings()
@@ -123,8 +129,11 @@ private void LoadSettings()
}
catch (Exception ex)
{
Console.WriteLine("Error loading settings.");
Console.WriteLine(ex.Message);
AccentStateComboBox.SelectedIndex = 0;
GradientColorPicker.SelectedColor = Color.FromArgb(127, 64, 127, 255);
ColorizeBlurCheckBox.IsChecked = true;
MessageBox.Show(ex.Message, "Error loading settings.");
}
}
@@ -156,6 +165,11 @@ private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs
SysTrayIcon.Dispose();
SaveSettings();
}
private void CloseMainWindow(object sender, RoutedEventArgs e)
{
this.Close();
}
#endregion Destructors
#region Functions
@@ -216,7 +230,7 @@ private void StartStopButton_Click(object sender, RoutedEventArgs e)
}
}
private void AccentStateComboBox_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
private void AccentStateComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
accentPolicy.AccentState = (AccentState)AccentStateComboBox.SelectedItem;
}
@@ -232,6 +246,17 @@ private void ColorizeBlurCheckBox_Changed(object sender, RoutedEventArgs e)
if (ColorizeBlurCheckBox.IsChecked == true) { accentPolicy.AccentFlags = 2; }
else { accentPolicy.AccentFlags = 0; }
}
private void SysTrayIcon_MouseClick(object sender, EventArgs e)
{
System.Windows.Forms.MouseEventArgs me = (System.Windows.Forms.MouseEventArgs)e;
if (me.Button == System.Windows.Forms.MouseButtons.Right)
{
SysTrayContextMenu.PlacementTarget = sender as Button;
SysTrayContextMenu.IsOpen = true;
this.Activate();
}
}
#endregion Control Handles
}
}
@@ -51,5 +51,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.1")]
[assembly: AssemblyFileVersion("1.0.1")]
[assembly: AssemblyVersion("1.0.2")]
[assembly: AssemblyFileVersion("1.0.2")]

0 comments on commit a6ada07

Please sign in to comment.