diff options
author | sr55 <[email protected]> | 2012-07-13 21:28:03 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2012-07-13 21:28:03 +0000 |
commit | 2425840702b5e319165384f73a51874349ee6d84 (patch) | |
tree | 2e4868e7839f841a8127e2275577b7f797e15677 /win/CS | |
parent | 252b183a32348050bbf9c23f3d70e9723db9271a (diff) |
WinGui: Improve the code behind the taskbar source menu. Note, The Disc insert detection still isn't in place, so it will only show the initial available drives, it won't detect disc changes yet.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4828 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/CS')
-rw-r--r-- | win/CS/HandBrakeWPF/Commands/SourceMenuCommand.cs | 86 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/HandBrakeWPF.csproj | 3 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/Model/SourceMenuItem.cs | 54 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs | 204 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/Views/MainView.xaml | 28 |
5 files changed, 250 insertions, 125 deletions
diff --git a/win/CS/HandBrakeWPF/Commands/SourceMenuCommand.cs b/win/CS/HandBrakeWPF/Commands/SourceMenuCommand.cs new file mode 100644 index 000000000..661ef7fe3 --- /dev/null +++ b/win/CS/HandBrakeWPF/Commands/SourceMenuCommand.cs @@ -0,0 +1,86 @@ +// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="SourceMenuCommand.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 SourceMenuCommand type.
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrakeWPF.Commands
+{
+ using System;
+ using System.Windows.Input;
+
+ /// <summary>
+ /// The source menu command.
+ /// </summary>
+ public class SourceMenuCommand : ICommand
+ {
+ #region Constants and Fields
+
+ /// <summary>
+ /// The execute action.
+ /// </summary>
+ private readonly Action executeAction;
+
+ #endregion
+
+ #region Constructors and Destructors
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="SourceMenuCommand"/> class.
+ /// </summary>
+ /// <param name="executeAction">
+ /// The execute action.
+ /// </param>
+ public SourceMenuCommand(Action executeAction)
+ {
+ this.executeAction = executeAction;
+ }
+
+ #endregion
+
+ #region Events
+
+ /// <summary>
+ /// The can execute changed.
+ /// </summary>
+ public event EventHandler CanExecuteChanged;
+
+ #endregion
+
+ #region Implemented Interfaces
+
+ #region ICommand
+
+ /// <summary>
+ /// The can execute.
+ /// </summary>
+ /// <param name="parameter">
+ /// The parameter.
+ /// </param>
+ /// <returns>
+ /// The System.Boolean.
+ /// </returns>
+ public bool CanExecute(object parameter)
+ {
+ return true;
+ }
+
+ /// <summary>
+ /// The execute.
+ /// </summary>
+ /// <param name="parameter">
+ /// The parameter.
+ /// </param>
+ public void Execute(object parameter)
+ {
+ this.executeAction();
+ }
+
+ #endregion
+
+ #endregion
+ }
+}
\ No newline at end of file diff --git a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj index 2a10df83a..e6c2fba7f 100644 --- a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj +++ b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj @@ -94,6 +94,7 @@ <Reference Include="System" />
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.Drawing" />
+ <Reference Include="System.Management" />
<Reference Include="System.Windows.Interactivity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\libraries\caliburn\System.Windows.Interactivity.dll</HintPath>
</Reference>
@@ -112,6 +113,7 @@ </ApplicationDefinition>
<Compile Include="AttachedProperties\MenuItemExtensions.cs" />
<Compile Include="Commands\ProcessShortcutCommand.cs" />
+ <Compile Include="Commands\SourceMenuCommand.cs" />
<Compile Include="Controls\Loading.xaml.cs">
<DependentUpon>Loading.xaml</DependentUpon>
</Compile>
@@ -126,6 +128,7 @@ <Compile Include="Converters\Subtitles\SubtitlesQueueDisplayConverter.cs" />
<Compile Include="Converters\Video\VideoEncoderConverter.cs" />
<Compile Include="Model\ShellWindow.cs" />
+ <Compile Include="Model\SourceMenuItem.cs" />
<Compile Include="Model\UpdateCheckInformation.cs" />
<Compile Include="Model\DownloadStatus.cs" />
<Compile Include="Services\Interfaces\IUpdateService.cs" />
diff --git a/win/CS/HandBrakeWPF/Model/SourceMenuItem.cs b/win/CS/HandBrakeWPF/Model/SourceMenuItem.cs new file mode 100644 index 000000000..b0c4a9766 --- /dev/null +++ b/win/CS/HandBrakeWPF/Model/SourceMenuItem.cs @@ -0,0 +1,54 @@ +// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="SourceMenuItem.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 SourceMenuItem type.
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrakeWPF.Model
+{
+ using System.Collections.ObjectModel;
+ using System.Windows.Controls;
+ using System.Windows.Input;
+
+ /// <summary>
+ /// The source menu item.
+ /// </summary>
+ public class SourceMenuItem
+ {
+ /// <summary>
+ /// Initializes a new instance of the <see cref="SourceMenuItem"/> class.
+ /// </summary>
+ public SourceMenuItem()
+ {
+ this.Children = new ObservableCollection<SourceMenuItem>();
+ }
+
+ /// <summary>
+ /// Gets or sets the text.
+ /// </summary>
+ public string Text { get; set; }
+
+ /// <summary>
+ /// Gets or sets the command.
+ /// </summary>
+ public ICommand Command { get; set; }
+
+ /// <summary>
+ /// Gets or sets the image.
+ /// </summary>
+ public Image Image { get; set; }
+
+ /// <summary>
+ /// Gets or sets the children.
+ /// </summary>
+ public ObservableCollection<SourceMenuItem> Children { get; set; }
+
+ /// <summary>
+ /// Gets or sets the tag.
+ /// </summary>
+ public object Tag { get; set; }
+ }
+}
diff --git a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs index 36a1a0e11..d9bc80b3f 100644 --- a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs @@ -16,8 +16,8 @@ namespace HandBrakeWPF.ViewModels using System.Diagnostics;
using System.IO;
using System.Linq;
+ using System.Threading;
using System.Windows;
- using System.Windows.Controls;
using System.Windows.Media.Imaging;
using Caliburn.Micro;
@@ -29,14 +29,14 @@ namespace HandBrakeWPF.ViewModels using HandBrake.ApplicationServices.Services.Interfaces;
using HandBrake.ApplicationServices.Utilities;
+ using HandBrakeWPF.Commands;
using HandBrakeWPF.Helpers;
using HandBrakeWPF.Model;
+ using HandBrakeWPF.Services.Interfaces;
using HandBrakeWPF.ViewModels.Interfaces;
using Ookii.Dialogs.Wpf;
- using HandBrakeWPF.Services.Interfaces;
-
using Image = System.Windows.Controls.Image;
/// <summary>
@@ -152,6 +152,10 @@ namespace HandBrakeWPF.ViewModels /// </summary>
private EncodeTask queueEditTask;
+ /// <summary>
+ /// The Source Menu Backing Field
+ /// </summary>
+ private IEnumerable<SourceMenuItem> sourceMenu;
#endregion
/// <summary>
@@ -187,7 +191,7 @@ namespace HandBrakeWPF.ViewModels IErrorService errorService, IShellViewModel shellViewModel, IUpdateService updateService)
{
GeneralUtilities.SetInstanceId();
-
+
this.scanService = scanService;
this.encodeService = encodeService;
@@ -316,70 +320,18 @@ namespace HandBrakeWPF.ViewModels }
/// <summary>
- /// Gets SourceToolbarMenu.
+ /// Gets or sets the source menu.
/// </summary>
- public IEnumerable<MenuItem> SourceToolbarMenu
+ public IEnumerable<SourceMenuItem> SourceMenu
{
get
{
- // TODO - Find a cleaner way of implementing this
-
- BindingList<MenuItem> menuItems = new BindingList<MenuItem>();
-
- // Folder Menu Item
- MenuItem folderMenuItem = new MenuItem
- {
- Icon = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/HandBrake;component/Views/Images/folder.png")), Width = 16, Height = 16 },
- Header = new TextBlock { Text = "Open Folder", Margin = new Thickness(8, 0, 0, 0), VerticalAlignment = VerticalAlignment.Center }
- };
- folderMenuItem.Click += this.folderMenuItem_Click;
- menuItems.Add(folderMenuItem);
-
- // File Menu Item
- MenuItem fileMenuItem = new MenuItem
- {
- Icon = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/HandBrake;component/Views/Images/Movies.png")), Width = 16, Height = 16 },
- Header = new TextBlock { Text = "Open File", Margin = new Thickness(8, 0, 0, 0), VerticalAlignment = VerticalAlignment.Center }
- };
- fileMenuItem.Click += this.fileMenuItem_Click;
- menuItems.Add(fileMenuItem);
-
- // File Menu Item
- MenuItem titleSpecific = new MenuItem { Header = new TextBlock { Text = "Title Specific Scan", Margin = new Thickness(8, 0, 0, 0), VerticalAlignment = VerticalAlignment.Center } };
-
- MenuItem titleSpecificFolder = new MenuItem
- {
- Icon = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/HandBrake;component/Views/Images/folder.png")), Width = 16, Height = 16 },
- Header = new TextBlock { Text = "Open Folder", Margin = new Thickness(8, 0, 0, 0), VerticalAlignment = VerticalAlignment.Center }
- };
- MenuItem titleSpecificFile = new MenuItem
- {
- Icon = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/HandBrake;component/Views/Images/Movies.png")), Width = 16, Height = 16 },
- Header = new TextBlock { Text = "Open File", Margin = new Thickness(8, 0, 0, 0), VerticalAlignment = VerticalAlignment.Center }
- };
- titleSpecificFolder.Click += this.titleSpecificFolder_Click;
- titleSpecificFile.Click += this.titleSpecificFile_Click;
-
- titleSpecific.Items.Add(titleSpecificFolder);
- titleSpecific.Items.Add(titleSpecificFile);
-
- menuItems.Add(titleSpecific);
-
- // Drives
- foreach (DriveInformation item in GeneralUtilities.GetDrives())
- {
- MenuItem driveMenuItem = new MenuItem
- {
- Icon = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/HandBrake;component/Views/Images/disc_small.png")), Width = 16, Height = 16 },
- Header = new TextBlock { Text = string.Format("{0} ({1})", item.RootDirectory, item.VolumeLabel), Margin = new Thickness(8, 0, 0, 0), VerticalAlignment = VerticalAlignment.Center },
- Tag = item
- };
- driveMenuItem.Click += this.driveMenuItem_Click;
- menuItems.Add(driveMenuItem);
- }
-
-
- return menuItems;
+ return this.sourceMenu;
+ }
+ set
+ {
+ this.sourceMenu = value;
+ this.NotifyOfPropertyChange(() => SourceMenu);
}
}
@@ -841,6 +793,9 @@ namespace HandBrakeWPF.ViewModels QueueRecoveryHelper.RecoverQueue(this.queueProcessor, this.errorService);
this.SelectedPreset = this.presetService.DefaultPreset;
+
+ // Populate the Source menu with drives.
+ this.SourceMenu = this.GenerateSourceMenu();
}
/// <summary>
@@ -1418,7 +1373,7 @@ namespace HandBrakeWPF.ViewModels this.SubtitleViewModel.UpdateTask(this.CurrentTask);
this.ChaptersViewModel.UpdateTask(this.CurrentTask);
this.AdvancedViewModel.UpdateTask(this.CurrentTask);
-
+
// Cleanup
this.ShowStatusWindow = false;
});
@@ -1557,7 +1512,7 @@ namespace HandBrakeWPF.ViewModels if (information.NewVersionAvailable)
{
MessageBox.Show("A New Version is available. Goto Tools Menu > Options to Install or visit http://handbrake.fr for details.", "Update Available", MessageBoxButton.OK, MessageBoxImage.Information);
- }
+ }
else
{
MessageBox.Show("There is no new updates at this time.", "No Update Available", MessageBoxButton.OK, MessageBoxImage.Information);
@@ -1699,77 +1654,84 @@ namespace HandBrakeWPF.ViewModels }
/// <summary>
- /// Drive Scan
+ /// The process drive.
/// </summary>
- /// <param name="sender">
- /// The sender.
- /// </param>
- /// <param name="e">
- /// The RoutedEventArgs.
+ /// <param name="item">
+ /// The item.
/// </param>
- private void driveMenuItem_Click(object sender, RoutedEventArgs e)
+ private void ProcessDrive(object item)
{
- MenuItem item = e.OriginalSource as MenuItem;
if (item != null)
{
- this.StartScan(((DriveInformation)item.Tag).RootDirectory, 0);
+ this.StartScan(((DriveInformation)item).RootDirectory, 0);
}
}
/// <summary>
- /// File Scan
+ /// The generate source menu.
/// </summary>
- /// <param name="sender">
- /// The sender.
- /// </param>
- /// <param name="e">
- /// The RoutedEventArgs.
- /// </param>
- private void fileMenuItem_Click(object sender, RoutedEventArgs e)
- {
- this.FileScan();
- }
-
- /// <summary>
- /// Folder Scan
- /// </summary>
- /// <param name="sender">
- /// The sender.
- /// </param>
- /// <param name="e">
- /// The RoutedEventArgs.
- /// </param>
- private void folderMenuItem_Click(object sender, RoutedEventArgs e)
- {
- this.FolderScan();
- }
+ /// <returns>
+ /// The System.Collections.Generic.IEnumerable`1[T -> HandBrakeWPF.Model.SourceMenuItem].
+ /// </returns>
+ private IEnumerable<SourceMenuItem> GenerateSourceMenu()
+ {
+ List<SourceMenuItem> menuItems = new List<SourceMenuItem>();
+
+ SourceMenuItem folderScan = new SourceMenuItem
+ {
+ Image = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/HandBrake;component/Views/Images/folder.png")), Width = 16, Height = 16 },
+ Text = "Open Folder",
+ Command = new SourceMenuCommand(this.FolderScan)
+ };
+ SourceMenuItem fileScan = new SourceMenuItem
+ {
+ Image = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/HandBrake;component/Views/Images/Movies.png")), Width = 16, Height = 16 },
+ Text = "Open File",
+ Command = new SourceMenuCommand(this.FileScan)
+ };
+
+ SourceMenuItem titleSpecific = new SourceMenuItem { Text = "Title Specific Scan" };
+ SourceMenuItem folderScanTitle = new SourceMenuItem
+ {
+ Image = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/HandBrake;component/Views/Images/folder.png")), Width = 16, Height = 16 },
+ Text = "Open Folder",
+ Command = new SourceMenuCommand(this.FolderScanTitleSpecific)
+ };
+ SourceMenuItem fileScanTitle = new SourceMenuItem
+ {
+ Image = new Image { Source = new BitmapImage(new Uri("pack://application:,,,/HandBrake;component/Views/Images/Movies.png")), Width = 16, Height = 16 },
+ Text = "Open File",
+ Command = new SourceMenuCommand(this.FileScanTitleSpecific)
+ };
+ titleSpecific.Children.Add(folderScanTitle);
+ titleSpecific.Children.Add(fileScanTitle);
+
+ menuItems.Add(folderScan);
+ menuItems.Add(fileScan);
+ menuItems.Add(titleSpecific);
+
+ // Drives
+ menuItems.AddRange(
+ 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(() => this.ProcessDrive(driveInformation)),
+ Tag = item
+ });
- /// <summary>
- /// Title Specific Scan for File
- /// </summary>
- /// <param name="sender">
- /// The sender.
- /// </param>
- /// <param name="e">
- /// The e.
- /// </param>
- private void titleSpecificFile_Click(object sender, RoutedEventArgs e)
- {
- this.FileScanTitleSpecific();
+ return menuItems;
}
/// <summary>
- /// Title Specific Scan for folder
+ /// The drive tray changed.
/// </summary>
- /// <param name="sender">
- /// The sender.
- /// </param>
- /// <param name="e">
- /// The e.
- /// </param>
- private void titleSpecificFolder_Click(object sender, RoutedEventArgs e)
+ private void DriveTrayChanged()
{
- this.FolderScanTitleSpecific();
+ Caliburn.Micro.Execute.OnUIThread(() => this.SourceMenu = this.GenerateSourceMenu());
}
#endregion
diff --git a/win/CS/HandBrakeWPF/Views/MainView.xaml b/win/CS/HandBrakeWPF/Views/MainView.xaml index 9efcf6dd7..7b78e50e3 100644 --- a/win/CS/HandBrakeWPF/Views/MainView.xaml +++ b/win/CS/HandBrakeWPF/Views/MainView.xaml @@ -5,7 +5,8 @@ xmlns:Converters="clr-namespace:HandBrakeWPF.Converters"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:Micro="clr-namespace:Caliburn.Micro;assembly=Caliburn.Micro"
- xmlns:behaviours="clr-namespace:HandBrakeWPF.Helpers" AllowDrop="True"
+ xmlns:behaviours="clr-namespace:HandBrakeWPF.Helpers" xmlns:Model="clr-namespace:HandBrakeWPF.Model"
+ AllowDrop="True"
Background="#FFF0F0F0"
FontSize="11"
Micro:Message.Attach="[Event Loaded] = [Action Load]"
@@ -41,7 +42,6 @@ <Setter Property="Padding" Value="5,5" />
</Style>
-
<CollectionViewSource x:Key="presetsCvs" Source="{Binding Presets}">
<CollectionViewSource.GroupDescriptions>
<PropertyGroupDescription PropertyName="Category" />
@@ -87,6 +87,7 @@ </Style>
<Converters:BooleanToVisibilityConverter x:Key="boolToVisConverter" />
+
</UserControl.Resources>
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
@@ -158,7 +159,7 @@ ToolBarTray.IsLocked="True"
>
<Menu Background="Transparent">
- <MenuItem ItemsSource="{Binding SourceToolbarMenu}">
+ <MenuItem ItemsSource="{Binding SourceMenu}">
<MenuItem.Header>
<StackPanel Orientation="Horizontal">
<Image Width="32"
@@ -171,6 +172,25 @@ />
</StackPanel>
</MenuItem.Header>
+ <MenuItem.ItemContainerStyle>
+ <Style TargetType="{x:Type MenuItem}">
+ <Setter Property="Header" Value="{Binding Text}" />
+ <Setter Property="MenuItem.Command" Value="{Binding Command}"/>
+ <Setter Property="MenuItem.CommandParameter" Value="123"/>
+ <Setter Property="ItemsSource" Value="{Binding Children}" />
+ <Setter Property="Icon" Value="{Binding Image}" />
+ </Style>
+ </MenuItem.ItemContainerStyle>
+ <!--<HierarchicalDataTemplate DataType="{x:Type Model:SourceMenuItem}"
+ ItemsSource="{Binding Path=Children}">
+ <HierarchicalDataTemplate.ItemContainerStyle>
+ <Style TargetType="MenuItem">
+ <Setter Property="Command" Value="{Binding Command}" />
+ <Setter Property="Icon" Value="{Binding Image}" />
+ </Style>
+ </HierarchicalDataTemplate.ItemContainerStyle>
+ <TextBlock Text="{Binding Text}" />
+ </HierarchicalDataTemplate>-->
</MenuItem>
</Menu>
@@ -530,7 +550,7 @@ SelectedItem="{Binding SelectedPreset, Mode=TwoWay}" BorderThickness="0,0,0,1"
BorderBrush="LightGray"
>
-
+
<ListBox.GroupStyle>
<GroupStyle ContainerStyle="{StaticResource ContainerStyle}"/>
</ListBox.GroupStyle>
|