diff options
Diffstat (limited to 'win/CS/HandBrakeWPF/Views')
-rw-r--r-- | win/CS/HandBrakeWPF/Views/OptionsView.xaml | 2 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/Views/ShellView.xaml.cs | 80 |
2 files changed, 80 insertions, 2 deletions
diff --git a/win/CS/HandBrakeWPF/Views/OptionsView.xaml b/win/CS/HandBrakeWPF/Views/OptionsView.xaml index 99d857bdc..389a80791 100644 --- a/win/CS/HandBrakeWPF/Views/OptionsView.xaml +++ b/win/CS/HandBrakeWPF/Views/OptionsView.xaml @@ -290,7 +290,7 @@ <StackPanel Orientation="Vertical" Grid.Column="1" Margin="20,0,0,0">
<CheckBox Content="Prevent the system from sleeping while encoding" IsChecked="{Binding PreventSleep}" />
- <CheckBox Content="Minimize to system tray (Requires Restart)" Visibility="Collapsed" IsChecked="{Binding MinimiseToTray}" />
+ <CheckBox Content="Minimize to system tray (Requires Restart)" IsChecked="{Binding MinimiseToTray}" />
<CheckBox Content="Display status messages from tray icon (balloon popups)" Visibility="Collapsed" IsChecked="{Binding DisplayStatusMessagesTrayIcon}" />
<CheckBox Content="Disable built-in preset update notification" IsChecked="{Binding DisablePresetUpdateCheckNotification}" />
<CheckBox Content="Always clear completed queue items after an encode completes" IsChecked="{Binding ClearQueueOnEncodeCompleted}" />
diff --git a/win/CS/HandBrakeWPF/Views/ShellView.xaml.cs b/win/CS/HandBrakeWPF/Views/ShellView.xaml.cs index 8a086ea09..b1eff7ddd 100644 --- a/win/CS/HandBrakeWPF/Views/ShellView.xaml.cs +++ b/win/CS/HandBrakeWPF/Views/ShellView.xaml.cs @@ -9,26 +9,58 @@ namespace HandBrakeWPF.Views
{
+ using System;
+ using System.IO;
using System.Windows;
+ using System.Windows.Forms;
using System.Windows.Input;
+ using System.Windows.Resources;
+ using Caliburn.Micro;
+
+ using HandBrake.ApplicationServices.Services.Interfaces;
using HandBrake.ApplicationServices.Utilities;
using HandBrakeWPF.Commands;
using HandBrakeWPF.ViewModels.Interfaces;
+ using Application = System.Windows.Application;
+
/// <summary>
/// Interaction logic for ShellView.xaml
/// </summary>
- public partial class ShellView : Window
+ public partial class ShellView
{
/// <summary>
+ /// The my notify icon.
+ /// </summary>
+ private readonly System.Windows.Forms.NotifyIcon notifyIcon;
+
+ /// <summary>
/// Initializes a new instance of the <see cref="ShellView"/> class.
/// </summary>
public ShellView()
{
this.InitializeComponent();
+ IUserSettingService userSettingService = IoC.Get<IUserSettingService>();
+ bool minimiseToTray = userSettingService.GetUserSetting<bool>(UserSettingConstants.MainWindowMinimize);
+
+ if (minimiseToTray)
+ {
+ this.notifyIcon = new System.Windows.Forms.NotifyIcon();
+ this.notifyIcon.ContextMenu = new ContextMenu(new[] { new MenuItem("Restore", NotifyIconClick) });
+
+ StreamResourceInfo streamResourceInfo = Application.GetResourceStream(new Uri("pack://application:,,,/handbrakepineapple.ico"));
+ if (streamResourceInfo != null)
+ {
+ Stream iconStream = streamResourceInfo.Stream;
+ this.notifyIcon.Icon = new System.Drawing.Icon(iconStream);
+ }
+ this.notifyIcon.DoubleClick += this.NotifyIconClick;
+ this.StateChanged += this.ShellViewStateChanged;
+ }
+
// Start Encode (Ctrl+S)
// Stop Encode (Ctrl+K)
// Open Log Window (Ctrl+L)
@@ -53,6 +85,47 @@ namespace HandBrakeWPF.Views }
/// <summary>
+ /// The notify icon_ click.
+ /// </summary>
+ /// <param name="sender">
+ /// The sender.
+ /// </param>
+ /// <param name="e">
+ /// The e.
+ /// </param>
+ private void NotifyIconClick(object sender, EventArgs e)
+ {
+ this.WindowState = WindowState.Normal;
+ }
+
+ /// <summary>
+ /// The shell view state changed.
+ /// </summary>
+ /// <param name="sender">
+ /// The sender.
+ /// </param>
+ /// <param name="e">
+ /// The e.
+ /// </param>
+ private void ShellViewStateChanged(object sender, EventArgs e)
+ {
+ if (this.notifyIcon != null)
+ {
+ if (this.WindowState == WindowState.Minimized)
+ {
+ this.ShowInTaskbar = false;
+ notifyIcon.Visible = true;
+ // notifyIcon.ShowBalloonTip(5000, "HandBrake", "Application Minimised", ToolTipIcon.Info);
+ }
+ else if (this.WindowState == WindowState.Normal)
+ {
+ notifyIcon.Visible = false;
+ this.ShowInTaskbar = true;
+ }
+ }
+ }
+
+ /// <summary>
/// Check with the user before closing.
/// </summary>
/// <param name="e">
@@ -71,6 +144,11 @@ namespace HandBrakeWPF.Views }
}
+ if (this.notifyIcon != null)
+ {
+ this.notifyIcon.Visible = false;
+ }
+
base.OnClosing(e);
}
}
|