summaryrefslogtreecommitdiffstats
path: root/win/CS/HandBrakeWPF/AttachedProperties
diff options
context:
space:
mode:
authorsr55 <[email protected]>2012-05-26 02:29:13 +0000
committersr55 <[email protected]>2012-05-26 02:29:13 +0000
commitcdcf2526b9b85befc27a29431f71c917b59a6f9d (patch)
treef0b370a5bd21a6fa29eade50396d7302d2bb6f30 /win/CS/HandBrakeWPF/AttachedProperties
parent39c79db9e18a6e3c13c8d6818474e8fe74dba2cc (diff)
WinGui: Improvements and fixes to the Queue Window. Added WhenDone option. Fixed an issue where the progress counter would not display if you started an encode before opening the queue window.
Updated the Options Window to keep settings displayed up to date. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4698 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/CS/HandBrakeWPF/AttachedProperties')
-rw-r--r--win/CS/HandBrakeWPF/AttachedProperties/MenuItemExtensions.cs145
1 files changed, 145 insertions, 0 deletions
diff --git a/win/CS/HandBrakeWPF/AttachedProperties/MenuItemExtensions.cs b/win/CS/HandBrakeWPF/AttachedProperties/MenuItemExtensions.cs
new file mode 100644
index 000000000..e08cf59c6
--- /dev/null
+++ b/win/CS/HandBrakeWPF/AttachedProperties/MenuItemExtensions.cs
@@ -0,0 +1,145 @@
+// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="MenuItemExtensions.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>
+// Defines the MenuItemExtensions type.
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrakeWPF.AttachedProperties
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Windows;
+ using System.Windows.Controls;
+
+ /// <summary>
+ /// The menu item extensions.
+ /// </summary>
+ public class MenuItemExtensions : DependencyObject
+ {
+ #region Constants and Fields
+
+ /// <summary>
+ /// The group name property.
+ /// </summary>
+ public static readonly DependencyProperty GroupNameProperty = DependencyProperty.RegisterAttached(
+ "GroupName",
+ typeof(string),
+ typeof(MenuItemExtensions),
+ new PropertyMetadata(String.Empty, OnGroupNameChanged));
+
+ /// <summary>
+ /// The element to group names.
+ /// </summary>
+ public static Dictionary<MenuItem, String> ElementToGroupNames = new Dictionary<MenuItem, String>();
+
+ #endregion
+
+ #region Public Methods
+
+ /// <summary>
+ /// The get group name.
+ /// </summary>
+ /// <param name="element">
+ /// The element.
+ /// </param>
+ /// <returns>
+ /// The group name as a string.
+ /// </returns>
+ public static string GetGroupName(MenuItem element)
+ {
+ return element.GetValue(GroupNameProperty).ToString();
+ }
+
+ /// <summary>
+ /// The set group name.
+ /// </summary>
+ /// <param name="element">
+ /// The element.
+ /// </param>
+ /// <param name="value">
+ /// The value.
+ /// </param>
+ public static void SetGroupName(MenuItem element, string value)
+ {
+ element.SetValue(GroupNameProperty, value);
+ }
+
+ #endregion
+
+ #region Methods
+
+ /// <summary>
+ /// The menu item checked.
+ /// </summary>
+ /// <param name="sender">
+ /// The sender.
+ /// </param>
+ /// <param name="e">
+ /// The e.
+ /// </param>
+ private static void MenuItemChecked(object sender, RoutedEventArgs e)
+ {
+ var menuItem = e.OriginalSource as MenuItem;
+ foreach (var item in ElementToGroupNames)
+ {
+ if (item.Key != menuItem && item.Value == GetGroupName(menuItem))
+ {
+ item.Key.IsChecked = false;
+ }
+ }
+ }
+
+ /// <summary>
+ /// The on group name changed.
+ /// </summary>
+ /// <param name="d">
+ /// The d.
+ /// </param>
+ /// <param name="e">
+ /// The e.
+ /// </param>
+ private static void OnGroupNameChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+ {
+ MenuItem menuItem = d as MenuItem;
+
+ if (menuItem != null)
+ {
+ string newGroupName = e.NewValue.ToString();
+ string oldGroupName = e.OldValue.ToString();
+ if (string.IsNullOrEmpty(newGroupName))
+ {
+ RemoveCheckboxFromGrouping(menuItem);
+ }
+ else
+ {
+ if (newGroupName != oldGroupName)
+ {
+ if (!string.IsNullOrEmpty(oldGroupName))
+ {
+ RemoveCheckboxFromGrouping(menuItem);
+ }
+ ElementToGroupNames.Add(menuItem, e.NewValue.ToString());
+ menuItem.Checked += MenuItemChecked;
+ }
+ }
+ }
+ }
+
+ /// <summary>
+ /// The remove checkbox from grouping.
+ /// </summary>
+ /// <param name="checkBox">
+ /// The check box.
+ /// </param>
+ private static void RemoveCheckboxFromGrouping(MenuItem checkBox)
+ {
+ ElementToGroupNames.Remove(checkBox);
+ checkBox.Checked -= MenuItemChecked;
+ }
+
+ #endregion
+ }
+} \ No newline at end of file