diff --git a/source/Axiom/Axiom/Controls/Configure.cs b/source/Axiom/Axiom/Controls/Configure.cs index f6f2a5c..8da5af4 100644 --- a/source/Axiom/Axiom/Controls/Configure.cs +++ b/source/Axiom/Axiom/Controls/Configure.cs @@ -30,6 +30,7 @@ You should have received a copy of the GNU General Public License using ViewModel; using Axiom; using System.Collections.ObjectModel; +using System.Threading.Tasks; // Disable XML Comment warnings #pragma warning disable 1591 @@ -243,10 +244,8 @@ public static void WriteAxiomConf(string directory, ConfigFile.conf = new ConfigFile(Path.Combine(directory, filename)); // Write each action in the list - foreach (Action Write in actionsToWrite) - { - Write(); - } + foreach (var t in actionsToWrite) + t(); } // Error catch diff --git a/source/Axiom/Axiom/CropWindow.xaml b/source/Axiom/Axiom/CropWindow.xaml index 01c98fa..bc853c7 100644 --- a/source/Axiom/Axiom/CropWindow.xaml +++ b/source/Axiom/Axiom/CropWindow.xaml @@ -61,7 +61,7 @@ VerticalAlignment="Top" Width="60" Style="{DynamicResource TextBoxStyle}" - KeyDown="tbxVideo_Crop_X_KeyDown" + TextInput="Allow_Only_Numbers" ToolTipService.ShowOnDisabled="True" ToolTip="Position of Crop from Left" /> @@ -82,7 +82,7 @@ VerticalAlignment="Top" Width="60" Style="{DynamicResource TextBoxStyle}" - KeyDown="tbxVideo_Crop_Y_KeyDown" + TextInput="Allow_Only_Numbers" ToolTipService.ShowOnDisabled="True" ToolTip="Position of Crop from Top" /> @@ -103,7 +103,7 @@ VerticalAlignment="Top" Width="60" Style="{DynamicResource TextBoxStyle}" - KeyDown="tbxVideo_Crop_Width_KeyDown" + TextInput="Allow_Only_Numbers" ToolTipService.ShowOnDisabled="True" ToolTip="Width of Cropped Area" /> @@ -124,7 +124,7 @@ VerticalAlignment="Top" Width="60" Style="{DynamicResource TextBoxStyle}" - KeyDown="tbxVideo_Crop_Height_KeyDown" + TextInput="Allow_Only_Numbers" ToolTipService.ShowOnDisabled="True" ToolTip="Height of Cropped Area" /> diff --git a/source/Axiom/Axiom/CropWindow.xaml.cs b/source/Axiom/Axiom/CropWindow.xaml.cs index 3f0bf1d..351e3d2 100644 --- a/source/Axiom/Axiom/CropWindow.xaml.cs +++ b/source/Axiom/Axiom/CropWindow.xaml.cs @@ -22,7 +22,9 @@ You should have received a copy of the GNU General Public License using System; using System.Collections.Generic; using System.Linq; +using System.Text.RegularExpressions; using System.Windows; +using System.Windows.Controls; using System.Windows.Input; using ViewModel; // Disable XML Comment warnings @@ -46,7 +48,6 @@ public partial class CropWindow : Window public static string cropY { get; set; } public static string crop { get; set; } // Combined Width, Height, X, Y - public CropWindow(MainWindow mainwindow) { InitializeComponent(); @@ -70,55 +71,25 @@ private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs this.Close(); } - /// - /// Crop Width - /// - private void tbxVideo_Crop_Width_KeyDown(object sender, KeyEventArgs e) - { - // Only allow Numbers or Backspace - if (!(e.Key >= Key.D0 && e.Key <= Key.D9) && e.Key != Key.Back) - { - e.Handled = true; - } - } + private static readonly Regex numsOnlyRegex = new Regex(@"\d+"); /// - /// Crop Height + /// Allow Only Numbers /// - private void tbxVideo_Crop_Height_KeyDown(object sender, KeyEventArgs e) + public void Allow_Only_Numbers(object sender, TextCompositionEventArgs e) { - // Only allow Numbers or Backspace - if (!(e.Key >= Key.D0 && e.Key <= Key.D9) && e.Key != Key.Back) + var textBox = e.Source as TextBox; + if (textBox != null) { - e.Handled = true; - } - } + var finalText = (textBox.SelectedText.Length > 0 + ? textBox.Text.Replace(textBox.SelectedText, "") + : textBox.Text) + + e.Text; - /// - /// Crop X - /// - private void tbxVideo_Crop_X_KeyDown(object sender, KeyEventArgs e) - { - // Only allow Numbers or Backspace - if (!(e.Key >= Key.D0 && e.Key <= Key.D9) && e.Key != Key.Back) - { - e.Handled = true; - } - } - - /// - /// Crop Y - /// - private void tbxVideo_Crop_Y_KeyDown(object sender, KeyEventArgs e) - { - // Only allow Numbers or Backspace - if (!(e.Key >= Key.D0 && e.Key <= Key.D9) && e.Key != Key.Back) - { - e.Handled = true; + e.Handled = !numsOnlyRegex.IsMatch(finalText); } } - /// /// SET Button /// diff --git a/source/Axiom/Axiom/MainWindow.xaml b/source/Axiom/Axiom/MainWindow.xaml index fca08bb..b7164e0 100644 --- a/source/Axiom/Axiom/MainWindow.xaml +++ b/source/Axiom/Axiom/MainWindow.xaml @@ -674,7 +674,7 @@ Margin="1,3,0,0" Grid.Column="2" Grid.Row="4" - KeyDown="tbxCutStartHours_KeyDown" + PreviewTextInput="Allow_Only_Two_Numbers" GotFocus="tbxCutStartHours_GotFocus" LostFocus="tbxCutStartHours_LostFocus" Panel.ZIndex="2" /> @@ -712,7 +712,7 @@ Grid.Row="4" Padding="1,1,0,0" Margin="22,3,0,0" - KeyDown="tbxCutStartMinutes_KeyDown" + PreviewTextInput="Allow_Only_Two_Numbers" GotFocus="tbxCutStartMinutes_GotFocus" LostFocus="tbxCutStartMinutes_LostFocus" Panel.ZIndex="2" /> @@ -750,7 +750,7 @@ Grid.Row="4" Padding="1,1,0,0" Margin="43,3,0,0" - KeyDown="tbxCutStartSeconds_KeyDown" + PreviewTextInput="Allow_Only_Two_Numbers" GotFocus="tbxCutStartSeconds_GotFocus" LostFocus="tbxCutStartSeconds_LostFocus" Panel.ZIndex="2" /> @@ -787,7 +787,7 @@ Grid.Row="4" Padding="1,1,0,0" Margin="64,3,0,0" - KeyDown="tbxCutStartMilliseconds_KeyDown" + PreviewTextInput="Allow_Only_Three_Numbers" GotFocus="tbxCutStartMilliseconds_GotFocus" LostFocus="tbxCutStartMilliseconds_LostFocus" Panel.ZIndex="2" /> @@ -839,7 +839,7 @@ Margin="1,3,0,0" Grid.Column="2" Grid.Row="5" - KeyDown="tbxCutEndHours_KeyDown" + PreviewTextInput="Allow_Only_Two_Numbers" GotFocus="tbxCutEndHours_GotFocus" LostFocus="tbxCutEndHours_LostFocus" Panel.ZIndex="2" /> @@ -876,7 +876,7 @@ Grid.Row="5" Padding="1,1,0,0" Margin="22,3,0,0" - KeyDown="tbxCutEndMinutes_KeyDown" + PreviewTextInput="Allow_Only_Two_Numbers" GotFocus="tbxCutEndMinutes_GotFocus" LostFocus="tbxCutEndMinutes_LostFocus" Panel.ZIndex="2" /> @@ -913,7 +913,7 @@ Grid.Row="5" Padding="1,1,0,0" Margin="43,3,0,0" - KeyDown="tbxCutEndSeconds_KeyDown" + PreviewTextInput="Allow_Only_Two_Numbers" GotFocus="tbxCutEndSeconds_GotFocus" LostFocus="tbxCutEndSeconds_LostFocus" Panel.ZIndex="2" /> @@ -949,7 +949,7 @@ Grid.Row="5" Padding="1,1,0,0" Margin="64,3,0,0" - KeyDown="tbxCutEndMilliseconds_KeyDown" + PreviewTextInput="Allow_Only_Three_Numbers" GotFocus="tbxCutEndMilliseconds_GotFocus" LostFocus="tbxCutEndMilliseconds_LostFocus" Panel.ZIndex="2" /> @@ -993,7 +993,7 @@ MaxLines="1" VerticalAlignment="Top" Width="50" - KeyDown="tbxFrameStart_KeyDown" + PreviewTextInput="Allow_Only_Numbers" GotFocus="tbxFrameStart_GotFocus" LostFocus="tbxFrameStart_LostFocus" ToolTipService.InitialShowDelay="500" @@ -1015,7 +1015,7 @@ MaxLines="1" VerticalAlignment="Top" Width="50" - KeyDown="tbxFrameEnd_KeyDown" + PreviewTextInput="Allow_Only_Numbers" GotFocus="tbxFrameEnd_GotFocus" LostFocus="tbxFrameEnd_LostFocus" ToolTipService.InitialShowDelay="500" @@ -1477,7 +1477,7 @@ TextWrapping="NoWrap" VerticalAlignment="Top" Width="30" - KeyDown="tbxVideo_CRF_KeyDown" + PreviewTextInput="Allow_Only_Numbers" MaxLines="1" MaxLength="2" ToolTipService.InitialShowDelay="500" @@ -1724,7 +1724,7 @@ Grid.Row="5" Grid.Column="2" Margin="0,2,0,0" - SelectionChanged="cboVideo_PixelFormat_SelectionChanged" Height="22" /> + Height="22" />