From 1fae5640fafcc3a4613eba99dcbb56f3e98430ae Mon Sep 17 00:00:00 2001 From: sr55 Date: Sun, 30 Oct 2011 21:53:10 +0000 Subject: WinGui: (WPF) Further work on the new Options window. Just UI/Cosmetic code to finish now. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4330 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- win/CS/HandBrakeWPF/HandBrakeWPF.csproj | 5 + win/CS/HandBrakeWPF/Helpers/ListBoxHelper.cs | 93 ++++++++++++ win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs | 166 ++++++++++++++------- win/CS/HandBrakeWPF/Views/Images/arrow_down.png | Bin 0 -> 625 bytes win/CS/HandBrakeWPF/Views/Images/arrow_left.png | Bin 0 -> 654 bytes win/CS/HandBrakeWPF/Views/Images/arrow_right.png | Bin 0 -> 793 bytes win/CS/HandBrakeWPF/Views/Images/arrow_up.png | Bin 0 -> 669 bytes win/CS/HandBrakeWPF/Views/OptionsView.xaml | 24 ++- 8 files changed, 228 insertions(+), 60 deletions(-) create mode 100644 win/CS/HandBrakeWPF/Helpers/ListBoxHelper.cs create mode 100644 win/CS/HandBrakeWPF/Views/Images/arrow_down.png create mode 100644 win/CS/HandBrakeWPF/Views/Images/arrow_left.png create mode 100644 win/CS/HandBrakeWPF/Views/Images/arrow_right.png create mode 100644 win/CS/HandBrakeWPF/Views/Images/arrow_up.png (limited to 'win') diff --git a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj index f94cf2a28..c600cd1a4 100644 --- a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj +++ b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj @@ -75,6 +75,7 @@ Designer + @@ -231,6 +232,10 @@ Always + + + + diff --git a/win/CS/HandBrakeWPF/Helpers/ListBoxHelper.cs b/win/CS/HandBrakeWPF/Helpers/ListBoxHelper.cs new file mode 100644 index 000000000..ee24b3bbe --- /dev/null +++ b/win/CS/HandBrakeWPF/Helpers/ListBoxHelper.cs @@ -0,0 +1,93 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// A Helper for the ListBox control to provide SelectedItems functionality. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeWPF.Helpers +{ + using System.Collections; + using System.Windows; + using System.Windows.Controls; + + /// + /// A Helper for the ListBox control to provide SelectedItems functionality. + /// + public class ListBoxHelper + { + /// + /// SelectedItems Attached Dependency Property + /// + public static readonly DependencyProperty SelectedItemsProperty = + DependencyProperty.RegisterAttached("SelectedItems", typeof(IList), typeof(ListBoxHelper), new FrameworkPropertyMetadata(null, OnSelectedItemsChanged)); + + /// + /// Gets the SelectedItems property. This dependency property + /// indicates .... + /// + /// + /// The item. + /// + /// + /// The get selected items. + /// + public static IList GetSelectedItems(DependencyObject item) + { + return (IList)item.GetValue(SelectedItemsProperty); + } + + /// + /// Sets the SelectedItems property. This dependency property + /// indicates .... + /// + /// + /// The item. + /// + /// + /// The value. + /// + public static void SetSelectedItems(DependencyObject item, IList value) + { + item.SetValue(SelectedItemsProperty, value); + } + + /// + /// Handles changes to the SelectedItems property. + /// + /// + /// The item. + /// + /// + /// The DependencyPropertyChangedEventArgs. + /// + private static void OnSelectedItemsChanged(DependencyObject item, DependencyPropertyChangedEventArgs e) + { + ListBox listBox = item as ListBox; + if (listBox != null) + { + ResetSelectedItems(listBox); + listBox.SelectionChanged += delegate { ResetSelectedItems(listBox); }; + } + } + + /// + /// Reset Selected Items + /// + /// + /// The list box. + /// + private static void ResetSelectedItems(ListBox listBox) + { + IList selectedItems = GetSelectedItems(listBox); + selectedItems.Clear(); + if (listBox.SelectedItems != null) + { + foreach (var item in listBox.SelectedItems) + selectedItems.Add(item); + } + } + } +} diff --git a/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs index 68a4ecf5d..9af9590f3 100644 --- a/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs @@ -674,6 +674,40 @@ namespace HandBrakeWPF.ViewModels #region Audio and Subtitles + /// + /// Gets or sets preferredLanguages. + /// + public BindingList PreferredLanguages + { + get + { + return this.preferredLanguages; + } + + set + { + this.preferredLanguages = value; + this.NotifyOfPropertyChange("preferredLanguages"); + } + } + + /// + /// Gets or sets SelectedPreferreedLangauge. + /// + public string SelectedPreferredLangauge + { + get + { + return this.selectedPreferredLangauge; + } + + set + { + this.selectedPreferredLangauge = value; + this.NotifyOfPropertyChange("SelectedPreferreedLangauge"); + } + } + /// /// Gets or sets AvailableLanguages. /// @@ -691,6 +725,32 @@ namespace HandBrakeWPF.ViewModels } } + /// + /// Gets or sets SelectedLangauges. + /// + public BindingList SelectedLangauges + { + get + { + return this.selectedLangauges; + } + set + { + this.selectedLangauges = value; + this.NotifyOfPropertyChange("SelectedLangauges"); + } + } + + /// + /// Gets or sets SelectedLangauges. + /// + public BindingList SelectedAvailableToMove { get; set; } + + /// + /// Gets or sets SelectedLangauges. + /// + public BindingList SelectedLangaugesToMove { get; set; } + /// /// Gets or sets AddAudioModeOptions. /// @@ -793,55 +853,6 @@ namespace HandBrakeWPF.ViewModels } } - /// - /// Gets or sets preferredLanguages. - /// - public BindingList PreferredLanguages - { - get - { - return this.preferredLanguages; - } - - set - { - this.preferredLanguages = value; - this.NotifyOfPropertyChange("preferredLanguages"); - } - } - - /// - /// Gets or sets SelectedLangauges. - /// - public BindingList SelectedLangauges - { - get - { - return this.selectedLangauges; - } - set - { - this.selectedLangauges = value; - this.NotifyOfPropertyChange("SelectedLangauges"); - } - } - - /// - /// Gets or sets SelectedPreferreedLangauge. - /// - public string SelectedPreferredLangauge - { - get - { - return this.selectedPreferredLangauge; - } - - set - { - this.selectedPreferredLangauge = value; - this.NotifyOfPropertyChange("SelectedPreferreedLangauge"); - } - } #endregion #region System and Logging @@ -1297,6 +1308,9 @@ namespace HandBrakeWPF.ViewModels // Audio and Subtitles Tab // ############################# + this.SelectedAvailableToMove = new BindingList(); + this.SelectedLangaugesToMove = new BindingList(); + IDictionary langList = LanguageUtilities.MapLanguages(); foreach (string selectedItem in this.userSettingService.GetUserSetting(UserSettingConstants.SelectedLanguages)) @@ -1447,7 +1461,15 @@ namespace HandBrakeWPF.ViewModels /// public void LanguageMoveLeft() { - // TODO + if (this.AvailableLanguages.Count > 0) + { + List copiedList = SelectedAvailableToMove.ToList(); + foreach (string item in copiedList) + { + this.AvailableLanguages.Remove(item); + this.SelectedLangauges.Add(item); + } + } } /// @@ -1455,7 +1477,15 @@ namespace HandBrakeWPF.ViewModels /// public void LanguageMoveRight() { - // TODO + if (this.SelectedLangauges.Count > 0) + { + List copiedList = SelectedLangaugesToMove.ToList(); + foreach (string item in copiedList) + { + this.SelectedLangauges.Remove(item); + this.AvailableLanguages.Add(item); + } + } } /// @@ -1463,6 +1493,11 @@ namespace HandBrakeWPF.ViewModels /// public void LanguageClearAll() { + foreach (string item in this.SelectedLangauges) + { + this.AvailableLanguages.Add(item); + } + this.SelectedLangauges.Clear(); } @@ -1471,7 +1506,19 @@ namespace HandBrakeWPF.ViewModels /// public void LanguageMoveUp() { - // TODO + List langauges = this.SelectedLangauges.ToList(); + foreach (string item in langauges) + { + if (this.SelectedLangaugesToMove.Contains(item)) + { + int index = this.SelectedLangauges.IndexOf(item); + if (index != 0) + { + this.SelectedLangauges.Remove(item); + this.SelectedLangauges.Insert(index - 1, item); + } + } + } } /// @@ -1479,7 +1526,20 @@ namespace HandBrakeWPF.ViewModels /// public void LanguageMoveDown() { - // TODO + List langauges = this.SelectedLangauges.ToList(); + int count = this.SelectedLangauges.Count; + foreach (string item in langauges) + { + if (this.SelectedLangaugesToMove.Contains(item)) + { + int index = this.SelectedLangauges.IndexOf(item); + if ((index + 1) != count) + { + this.SelectedLangauges.Remove(item); + this.SelectedLangauges.Insert(index + 1, item); + } + } + } } /// diff --git a/win/CS/HandBrakeWPF/Views/Images/arrow_down.png b/win/CS/HandBrakeWPF/Views/Images/arrow_down.png new file mode 100644 index 000000000..9a8de4f4a Binary files /dev/null and b/win/CS/HandBrakeWPF/Views/Images/arrow_down.png differ diff --git a/win/CS/HandBrakeWPF/Views/Images/arrow_left.png b/win/CS/HandBrakeWPF/Views/Images/arrow_left.png new file mode 100644 index 000000000..713030f29 Binary files /dev/null and b/win/CS/HandBrakeWPF/Views/Images/arrow_left.png differ diff --git a/win/CS/HandBrakeWPF/Views/Images/arrow_right.png b/win/CS/HandBrakeWPF/Views/Images/arrow_right.png new file mode 100644 index 000000000..a270c5479 Binary files /dev/null and b/win/CS/HandBrakeWPF/Views/Images/arrow_right.png differ diff --git a/win/CS/HandBrakeWPF/Views/Images/arrow_up.png b/win/CS/HandBrakeWPF/Views/Images/arrow_up.png new file mode 100644 index 000000000..530daed53 Binary files /dev/null and b/win/CS/HandBrakeWPF/Views/Images/arrow_up.png differ diff --git a/win/CS/HandBrakeWPF/Views/OptionsView.xaml b/win/CS/HandBrakeWPF/Views/OptionsView.xaml index 8f3d155bd..36df30219 100644 --- a/win/CS/HandBrakeWPF/Views/OptionsView.xaml +++ b/win/CS/HandBrakeWPF/Views/OptionsView.xaml @@ -1,7 +1,7 @@  + xmlns:Helpers="clr-namespace:HandBrakeWPF.Helpers" Title="OptionsView" MinWidth="620" MinHeight="550" Width="620" Height="550">