diff options
author | sr55 <[email protected]> | 2013-05-26 16:11:55 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2013-05-26 16:11:55 +0000 |
commit | bb402730363d0a2192015f5062f9fda409bf743e (patch) | |
tree | 9b1b2ba85af0659c3d1410fa0cc3bd4dc30c9388 /win/CS/HandBrakeWPF/AttachedProperties/DriveMenu.cs | |
parent | ab11d3012d39eaa0991edbd069c602241d63905c (diff) |
WinGui: Add an attached property to the source menu to handle drive detection rather than relying on callbacks from the OS.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@5517 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/CS/HandBrakeWPF/AttachedProperties/DriveMenu.cs')
-rw-r--r-- | win/CS/HandBrakeWPF/AttachedProperties/DriveMenu.cs | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/win/CS/HandBrakeWPF/AttachedProperties/DriveMenu.cs b/win/CS/HandBrakeWPF/AttachedProperties/DriveMenu.cs new file mode 100644 index 000000000..1149b579e --- /dev/null +++ b/win/CS/HandBrakeWPF/AttachedProperties/DriveMenu.cs @@ -0,0 +1,127 @@ +// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="DriveMenu.cs" company="HandBrake Project (http://handbrake.fr)">
+// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
+// </copyright>
+// <summary>
+// The drive menu.
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrakeWPF.AttachedProperties
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Windows;
+ using System.Windows.Controls;
+ using System.Windows.Media.Imaging;
+
+ using HandBrake.ApplicationServices.Utilities;
+
+ using HandBrakeWPF.Commands;
+ using HandBrakeWPF.Model;
+ using HandBrakeWPF.ViewModels;
+
+ /// <summary>
+ /// The drive menu.
+ /// </summary>
+ public class DriveMenu
+ {
+ /// <summary>
+ /// The show available drives property.
+ /// </summary>
+ public static readonly DependencyProperty ShowAvailableDrivesProperty = DependencyProperty.RegisterAttached(
+ "ShowAvailableDrives",
+ typeof(Boolean),
+ typeof(DriveMenu),
+ new PropertyMetadata(false, OnShowAvailableDrivesChanged));
+
+ /// <summary>
+ /// The get show available drives.
+ /// </summary>
+ /// <param name="element">
+ /// The element.
+ /// </param>
+ /// <returns>
+ /// The <see cref="bool"/>.
+ /// </returns>
+ public static Boolean GetShowAvailableDrives(MenuItem element)
+ {
+ bool result;
+ return bool.TryParse(element.GetValue(ShowAvailableDrivesProperty).ToString(), out result) && result;
+ }
+
+ /// <summary>
+ /// The set show available drives.
+ /// </summary>
+ /// <param name="element">
+ /// The element.
+ /// </param>
+ /// <param name="value">
+ /// The value.
+ /// </param>
+ public static void SetShowAvailableDrives(MenuItem element, Boolean value)
+ {
+ element.SetValue(ShowAvailableDrivesProperty, value);
+ }
+
+ /// <summary>
+ /// The on show available drives changed.
+ /// </summary>
+ /// <param name="d">
+ /// The d.
+ /// </param>
+ /// <param name="e">
+ /// The e.
+ /// </param>
+ private static void OnShowAvailableDrivesChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+ {
+ Menu menu = d as Menu;
+ if (menu != null)
+ {
+ menu.PreviewMouseDown -= MenuMouseDown;
+ menu.PreviewMouseDown += MenuMouseDown;
+ }
+ }
+
+ /// <summary>
+ /// The menu_ mouse down.
+ /// </summary>
+ /// <param name="sender">
+ /// The sender.
+ /// </param>
+ /// <param name="e">
+ /// The e.
+ /// </param>
+ private static void MenuMouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
+ {
+ Menu menu = sender as Menu;
+ if (menu != null)
+ {
+ MainViewModel mvm = menu.DataContext as MainViewModel;
+ if (mvm != null)
+ {
+ List<SourceMenuItem> remove = mvm.SourceMenu.Where(s => s.IsDrive).ToList();
+ foreach (var item in remove)
+ {
+ mvm.SourceMenu.Remove(item);
+ }
+
+ foreach (SourceMenuItem menuItem in from item in GeneralUtilities.GetDrives()
+ let driveInformation = item
+ select new SourceMenuItem
+ {
+ Image = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/HandBrake;component/Views/Images/disc_small.png")), Width = 16, Height = 16 },
+ Text = string.Format("{0} ({1})", item.RootDirectory, item.VolumeLabel),
+ Command = new SourceMenuCommand(() => mvm.ProcessDrive(driveInformation)),
+ Tag = item,
+ IsDrive = true
+ })
+ {
+ mvm.SourceMenu.Add(menuItem);
+ }
+ }
+ }
+ }
+ }
+}
|