summaryrefslogtreecommitdiffstats
path: root/win/CS/HandBrakeWPF/Commands/ProcessShortcutCommand.cs
blob: 117ea1eb38a982ad8adf3697190be51cc8b540f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ProcessShortcutCommand.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>
//   Keyboard Shortcut Processor
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace HandBrakeWPF.Commands
{
    using System;
    using System.Windows;
    using System.Windows.Input;

    using Caliburn.Micro;

    using HandBrakeWPF.ViewModels.Interfaces;

    /// <summary>
    /// Keyboard Shortcut Processor
    /// </summary>
    public class ProcessShortcutCommand : ICommand
    {
        /// <summary>
        /// The Gesture
        /// </summary>
        private readonly KeyGesture gesture;

        /// <summary>
        /// Initializes a new instance of the <see cref="ProcessShortcutCommand"/> class.
        /// </summary>
        /// <param name="gesture">
        /// The gesture.
        /// </param>
        public ProcessShortcutCommand(KeyGesture gesture)
        {
            this.gesture = gesture;
        }

        /// <summary>
        /// Defines the method to be called when the command is invoked.
        /// </summary>
        /// <param name="parameter">Data used by the command.  If the command does not require data to be passed, this object can be set to null.</param>
        public void Execute(object parameter)
        {
            if (gesture != null)
            {
                IMainViewModel mainViewModel = IoC.Get<IMainViewModel>();
                
                // Start Encode (Ctrl+E)
                if (gesture.Modifiers == ModifierKeys.Control && gesture.Key == Key.E)
                {
                    mainViewModel.StartEncode();
                }

                // Stop Encode (Ctrl+K)
                if (gesture.Modifiers == ModifierKeys.Control && gesture.Key == Key.K)
                {
                    mainViewModel.StopEncode();
                }

                // Open Log Window (Ctrl+L)
                if (gesture.Modifiers == ModifierKeys.Control && gesture.Key == Key.L)
                {
                    mainViewModel.OpenLogWindow();
                }

                // Open Queue Window (Ctrl+Q)
                if (gesture.Modifiers == ModifierKeys.Control && gesture.Key == Key.Q)
                {
                    mainViewModel.OpenQueueWindow();
                }

                // Add to Queue (Ctrl+A)
                if (gesture.Modifiers == ModifierKeys.Control && gesture.Key == Key.A)
                {
                    mainViewModel.AddToQueueWithErrorHandling();
                }

                // Add all to Queue (Alt+A)
                if (gesture.Modifiers == ModifierKeys.Alt && gesture.Key == Key.A)
                {
                    mainViewModel.AddAllToQueue();
                }

                // Add selection to Queue (Control+Shift+A)
                if (gesture.Modifiers == (ModifierKeys.Control | ModifierKeys.Shift) && gesture.Key == Key.A)
                {
                    mainViewModel.AddSelectionToQueue();
                }

                // Scan a File (Alt+O)
                if (gesture.Modifiers == ModifierKeys.Alt && gesture.Key == Key.O)
                {
                    mainViewModel.SelectSourceWindow();
                }

                // Scan a File (Ctrl+O)
                if (gesture.Modifiers == ModifierKeys.Control && gesture.Key == Key.O)
                {
                    mainViewModel.FileScan();
                }

                // Scan a Folder (Ctrl+Shift+O)
                if (gesture.Modifiers == (ModifierKeys.Control | ModifierKeys.Shift) && gesture.Key == Key.O)
                {
                    mainViewModel.FolderScan();
                }

                // Launch Help (F1)
                if (gesture.Key == Key.F1)
                {
                    mainViewModel.LaunchHelp();
                }

                // Browse Destination (Ctrl+S)
                if (gesture.Modifiers == ModifierKeys.Control && gesture.Key == Key.S)
                {
                    mainViewModel.BrowseDestination();
                }

                // Tabs
                if (gesture.Modifiers == ModifierKeys.Control && gesture.Key == Key.D1)
                {
                     mainViewModel.SwitchTab(0);
                }

                if (gesture.Modifiers == ModifierKeys.Control && gesture.Key == Key.D2)
                {
                    mainViewModel.SwitchTab(1);
                }

                if (gesture.Modifiers == ModifierKeys.Control && gesture.Key == Key.D3)
                {
                    mainViewModel.SwitchTab(2);
                }

                if (gesture.Modifiers == ModifierKeys.Control && gesture.Key == Key.D4)
                {
                    mainViewModel.SwitchTab(3);
                }

                if (gesture.Modifiers == ModifierKeys.Control && gesture.Key == Key.D5)
                {
                    mainViewModel.SwitchTab(4);
                }

                if (gesture.Modifiers == ModifierKeys.Control && gesture.Key == Key.D6)
                {
                    mainViewModel.SwitchTab(5);
                }

                if (gesture.Modifiers == ModifierKeys.Control && gesture.Key == Key.D7)
                {
                    mainViewModel.SwitchTab(6);
                }

                if (gesture.Modifiers == (ModifierKeys.Control | ModifierKeys.Shift) && gesture.Key == Key.G)
                {
                    GC.Collect();
                    MessageBox.Show("DEBUG: Garbage Collection Completed");
                }
            }
        }

        /// <summary>
        /// Defines the method that determines whether the command can execute in its current state.
        /// </summary>
        /// <returns>
        /// true if this command can be executed; otherwise, false.
        /// </returns>
        /// <param name="parameter">Data used by the command.  If the command does not require data to be passed, this object can be set to null.</param>
        public bool CanExecute(object parameter)
        {
            return true;
        }

        /// <summary>
        /// Can Execute Changed
        /// </summary>
        public event EventHandler CanExecuteChanged { add { } remove { } }
    }
}