// --------------------------------------------------------------------------------------------------------------------
//
// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
//
//
// Interaction logic for VideoView.xaml
//
// --------------------------------------------------------------------------------------------------------------------
namespace HandBrakeWPF.Views
{
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using HandBrakeWPF.Services.Queue.Model;
using HandBrakeWPF.ViewModels;
///
/// Interaction logic for VideoView
///
public partial class QueueView : Window
{
private QueueTask mouseActiveQueueTask;
///
/// Initializes a new instance of the class.
///
public QueueView()
{
this.InitializeComponent();
}
private void ContextMenu_OnOpened(object sender, RoutedEventArgs e)
{
ContextMenu menu = sender as ContextMenu;
this.mouseActiveQueueTask = null;
if (menu != null)
{
Point p = Mouse.GetPosition(this);
HitTestResult result = VisualTreeHelper.HitTest(this, p);
if (result != null)
{
ListBoxItem listBoxItem = FindParent(result.VisualHit);
if (listBoxItem != null)
{
this.mouseActiveQueueTask = listBoxItem.DataContext as QueueTask;
}
}
}
this.openSourceDir.IsEnabled = this.mouseActiveQueueTask != null;
this.openDestDir.IsEnabled = this.mouseActiveQueueTask != null;
}
private static T FindParent(DependencyObject from) where T : class
{
DependencyObject parent = VisualTreeHelper.GetParent(from);
T result = null;
if (parent is T)
{
result = parent as T;
}
else if (parent != null)
{
result = FindParent(parent);
}
return result;
}
private void OpenSourceDir_OnClick(object sender, RoutedEventArgs e)
{
((QueueViewModel)this.DataContext).OpenSourceDirectory(this.mouseActiveQueueTask);
}
private void OpenDestDir_OnClick(object sender, RoutedEventArgs e)
{
((QueueViewModel)this.DataContext).OpenDestinationDirectory(this.mouseActiveQueueTask);
}
}
}