1 // -------------------------------------------------------------------------------------------------------------------- 2 // <copyright file="MainView.xaml.cs" company="HandBrake Project (http://handbrake.fr)"> 3 // This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. 4 // </copyright> 5 // <summary> 6 // Interaction logic for MainView.xaml 7 // </summary> 8 // -------------------------------------------------------------------------------------------------------------------- 9 10 namespace HandBrakeWPF.Views 11 { 12 using System.Windows; 13 using System.Windows.Controls; 14 using System.Windows.Input; 15 using System.Windows.Media; 16 17 using HandBrakeWPF.Services.Presets.Model; 18 using HandBrakeWPF.ViewModels; 19 using HandBrakeWPF.ViewModels.Interfaces; 20 21 /// <summary> 22 /// Interaction logic for MainView.xaml 23 /// </summary> 24 public partial class MainView : UserControl 25 { 26 /// <summary> 27 /// Initializes a new instance of the <see cref="MainView"/> class. 28 /// </summary> MainView()29 public MainView() 30 { 31 this.InitializeComponent(); 32 } 33 34 /// <summary> 35 /// Add to Queue button context menu handling. 36 /// </summary> 37 /// <param name="sender"> 38 /// The sender. 39 /// </param> 40 /// <param name="e"> 41 /// The e. 42 /// </param> AddToQueue_PreviewMouseDown(object sender, MouseButtonEventArgs e)43 private void AddToQueue_PreviewMouseDown(object sender, MouseButtonEventArgs e) 44 { 45 // If we've clicked the dropdown part of the button, display the context menu below the button. 46 Button button = (sender as Button); 47 if (button != null) 48 { 49 HitTestResult result = VisualTreeHelper.HitTest(button, e.GetPosition(button)); 50 FrameworkElement element = result.VisualHit as FrameworkElement; 51 if (element != null) 52 { 53 if (element.Name == "dropdown" || element.Name == "dropdownArrow") 54 { 55 button.ContextMenu.IsEnabled = true; 56 button.ContextMenu.PlacementTarget = button; 57 button.ContextMenu.Placement = System.Windows.Controls.Primitives.PlacementMode.Bottom; 58 button.ContextMenu.IsOpen = true; 59 return; 60 } 61 } 62 } 63 64 // Otherwise assume it's a main area click and add to queue. 65 ((IMainViewModel)this.DataContext).AddToQueueWithErrorHandling(); 66 } 67 Presets_PreviewMouseDown(object sender, MouseButtonEventArgs e)68 private void Presets_PreviewMouseDown(object sender, MouseButtonEventArgs e) 69 { 70 // If we've clicked the dropdown part of the button, display the context menu below the button. 71 Button button = (sender as Button); 72 if (button != null) 73 { 74 button.ContextMenu.IsEnabled = true; 75 button.ContextMenu.PlacementTarget = button; 76 button.ContextMenu.Placement = System.Windows.Controls.Primitives.PlacementMode.Bottom; 77 button.ContextMenu.IsOpen = true; 78 } 79 } 80 TabControl_OnSelectionChanged(object sender, SelectionChangedEventArgs e)81 private void TabControl_OnSelectionChanged(object sender, SelectionChangedEventArgs e) 82 { 83 if (e.Source is TabControl && e.AddedItems.Count > 0) 84 { 85 TabItem tab = e.AddedItems[0] as TabItem; 86 if (tab != null && Properties.Resources.MainView_SummaryTab.Equals(tab.Header)) 87 { 88 ((MainViewModel)this.DataContext).SummaryViewModel.UpdateDisplayedInfo(); 89 } 90 91 this.tabControl.Focus(); 92 } 93 } 94 MorePresetOptionsButton_OnClick(object sender, RoutedEventArgs e)95 private void MorePresetOptionsButton_OnClick(object sender, RoutedEventArgs e) 96 { 97 var button = sender as FrameworkElement; 98 if (button != null && button.ContextMenu != null) 99 { 100 button.ContextMenu.PlacementTarget = button; 101 button.ContextMenu.Placement = System.Windows.Controls.Primitives.PlacementMode.Bottom; 102 button.ContextMenu.IsOpen = true; 103 } 104 } 105 SelectPreset_OnClick(object sender, RoutedEventArgs e)106 private void SelectPreset_OnClick(object sender, RoutedEventArgs e) 107 { 108 var button = sender as FrameworkElement; 109 if (button != null && button.ContextMenu != null) 110 { 111 button.ContextMenu.PlacementTarget = button; 112 button.ContextMenu.Placement = System.Windows.Controls.Primitives.PlacementMode.Right; 113 button.ContextMenu.IsOpen = true; 114 } 115 } 116 } 117 } 118