flabbet 4 years ago
parent
commit
bc04ced3f2

+ 25 - 0
PixiEditor/Helpers/UI/UniversalTextBox.cs

@@ -0,0 +1,25 @@
+using System.Windows.Controls;
+using PixiEditor.Models.Controllers.Shortcuts;
+
+namespace PixiEditor.Helpers.UI
+{
+    public class UniversalTextBox : TextBox
+    {
+        public UniversalTextBox()
+            : base()
+        {
+            GotFocus += UniversalTextBox_GotFocus;
+            LostFocus += UniversalTextBox_LostFocus;
+        }
+
+        private void UniversalTextBox_GotFocus(object sender, System.Windows.RoutedEventArgs e)
+        {
+            ShortcutController.BlockShortcutExecution = true;
+        }
+
+        private void UniversalTextBox_LostFocus(object sender, System.Windows.RoutedEventArgs e)
+        {
+            ShortcutController.BlockShortcutExecution = false;
+        }
+    }
+}

+ 17 - 8
PixiEditor/Views/UserControls/EditableTextBlock.xaml.cs

@@ -7,19 +7,24 @@ using PixiEditor.Models.Controllers.Shortcuts;
 namespace PixiEditor.Views
 namespace PixiEditor.Views
 {
 {
     /// <summary>
     /// <summary>
-    ///     Interaction logic for EditableTextBlock.xaml
+    ///     Interaction logic for EditableTextBlock.xaml.
     /// </summary>
     /// </summary>
     public partial class EditableTextBlock : UserControl
     public partial class EditableTextBlock : UserControl
     {
     {
         // Using a DependencyProperty as the backing store for TextBlockVisibility.  This enables animation, styling, binding, etc...
         // Using a DependencyProperty as the backing store for TextBlockVisibility.  This enables animation, styling, binding, etc...
         public static readonly DependencyProperty TextBlockVisibilityProperty =
         public static readonly DependencyProperty TextBlockVisibilityProperty =
-            DependencyProperty.Register("TextBlockVisibility", typeof(Visibility), typeof(EditableTextBlock),
+            DependencyProperty.Register(
+                "TextBlockVisibility",
+                typeof(Visibility),
+                typeof(EditableTextBlock),
                 new PropertyMetadata(Visibility.Visible));
                 new PropertyMetadata(Visibility.Visible));
 
 
-
         // Using a DependencyProperty as the backing store for Text.  This enables animation, styling, binding, etc...
         // Using a DependencyProperty as the backing store for Text.  This enables animation, styling, binding, etc...
         public static readonly DependencyProperty TextProperty =
         public static readonly DependencyProperty TextProperty =
-            DependencyProperty.Register("Text", typeof(string), typeof(EditableTextBlock),
+            DependencyProperty.Register(
+                "Text",
+                typeof(string),
+                typeof(EditableTextBlock),
                 new PropertyMetadata(default(string)));
                 new PropertyMetadata(default(string)));
 
 
         // Using a DependencyProperty as the backing store for EnableEditing.  This enables animation, styling, binding, etc...
         // Using a DependencyProperty as the backing store for EnableEditing.  This enables animation, styling, binding, etc...
@@ -38,14 +43,12 @@ namespace PixiEditor.Views
             set => SetValue(TextBlockVisibilityProperty, value);
             set => SetValue(TextBlockVisibilityProperty, value);
         }
         }
 
 
-
         public bool IsEditing
         public bool IsEditing
         {
         {
             get => (bool) GetValue(EnableEditingProperty);
             get => (bool) GetValue(EnableEditingProperty);
             set => SetValue(EnableEditingProperty, value);
             set => SetValue(EnableEditingProperty, value);
         }
         }
 
 
-
         public string Text
         public string Text
         {
         {
             get => (string) GetValue(TextProperty);
             get => (string) GetValue(TextProperty);
@@ -80,12 +83,18 @@ namespace PixiEditor.Views
 
 
         private void TextBlock_MouseDown(object sender, MouseButtonEventArgs e)
         private void TextBlock_MouseDown(object sender, MouseButtonEventArgs e)
         {
         {
-            if (e.ChangedButton == MouseButton.Left && e.ClickCount == 2) EnableEditing();
+            if (e.ChangedButton == MouseButton.Left && e.ClickCount == 2)
+            {
+                EnableEditing();
+            }
         }
         }
 
 
         private void TextBox_KeyDown(object sender, KeyEventArgs e)
         private void TextBox_KeyDown(object sender, KeyEventArgs e)
         {
         {
-            if (e.Key == Key.Enter) DisableEditing();
+            if (e.Key == Key.Enter)
+            {
+                DisableEditing();
+            }
         }
         }
 
 
         private void TextBox_LostFocus(object sender, RoutedEventArgs e)
         private void TextBox_LostFocus(object sender, RoutedEventArgs e)

+ 2 - 2
PixiEditor/Views/UserControls/NumberInput.xaml

@@ -10,11 +10,11 @@
              mc:Ignorable="d"
              mc:Ignorable="d"
              d:DesignHeight="20" d:DesignWidth="40" x:Name="numberInput">
              d:DesignHeight="20" d:DesignWidth="40" x:Name="numberInput">
     <Grid>
     <Grid>
-        <TextBox TextAlignment="Center" Style="{StaticResource DarkTextBoxStyle}"
+        <ui:UniversalTextBox TextAlignment="Center" Style="{StaticResource DarkTextBoxStyle}"
                  PreviewTextInput="TextBox_PreviewTextInput" Text="{Binding ElementName=numberInput, Path=Value}">
                  PreviewTextInput="TextBox_PreviewTextInput" Text="{Binding ElementName=numberInput, Path=Value}">
             <i:Interaction.Behaviors>
             <i:Interaction.Behaviors>
                 <behaviours:TextBoxFocusBehavior />
                 <behaviours:TextBoxFocusBehavior />
             </i:Interaction.Behaviors>
             </i:Interaction.Behaviors>
-        </TextBox>
+        </ui:UniversalTextBox>
     </Grid>
     </Grid>
 </UserControl>
 </UserControl>

+ 14 - 5
PixiEditor/Views/UserControls/NumberInput.xaml.cs

@@ -1,4 +1,5 @@
-using System;
+using PixiEditor.Models.Controllers.Shortcuts;
+using System;
 using System.Text.RegularExpressions;
 using System.Text.RegularExpressions;
 using System.Windows;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Controls;
@@ -13,20 +14,28 @@ namespace PixiEditor.Views
     {
     {
         // Using a DependencyProperty as the backing store for Value.  This enables animation, styling, binding, etc...
         // Using a DependencyProperty as the backing store for Value.  This enables animation, styling, binding, etc...
         public static readonly DependencyProperty ValueProperty =
         public static readonly DependencyProperty ValueProperty =
-            DependencyProperty.Register("Value", typeof(float), typeof(NumberInput),
+            DependencyProperty.Register(
+                "Value",
+                typeof(float),
+                typeof(NumberInput),
                 new PropertyMetadata(0f, OnValueChanged));
                 new PropertyMetadata(0f, OnValueChanged));
 
 
         // Using a DependencyProperty as the backing store for Min.  This enables animation, styling, binding, etc...
         // Using a DependencyProperty as the backing store for Min.  This enables animation, styling, binding, etc...
         public static readonly DependencyProperty MinProperty =
         public static readonly DependencyProperty MinProperty =
-            DependencyProperty.Register("Min", typeof(float), typeof(NumberInput),
+            DependencyProperty.Register(
+                "Min",
+                typeof(float),
+                typeof(NumberInput),
                 new PropertyMetadata(float.NegativeInfinity));
                 new PropertyMetadata(float.NegativeInfinity));
 
 
         // Using a DependencyProperty as the backing store for Max.  This enables animation, styling, binding, etc...
         // Using a DependencyProperty as the backing store for Max.  This enables animation, styling, binding, etc...
         public static readonly DependencyProperty MaxProperty =
         public static readonly DependencyProperty MaxProperty =
-            DependencyProperty.Register("Max", typeof(float), typeof(NumberInput),
+            DependencyProperty.Register(
+                "Max",
+                typeof(float), 
+                typeof(NumberInput),
                 new PropertyMetadata(float.PositiveInfinity));
                 new PropertyMetadata(float.PositiveInfinity));
 
 
-
         public NumberInput()
         public NumberInput()
         {
         {
             InitializeComponent();
             InitializeComponent();

+ 5 - 5
PixiEditor/Views/UserControls/SizeInput.xaml

@@ -3,19 +3,19 @@
              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
-             xmlns:local="clr-namespace:PixiEditor.Views"
              xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
              xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
              xmlns:behaviors="clr-namespace:PixiEditor.Helpers.Behaviours"
              xmlns:behaviors="clr-namespace:PixiEditor.Helpers.Behaviours"
              xmlns:converters="clr-namespace:PixiEditor.Helpers"
              xmlns:converters="clr-namespace:PixiEditor.Helpers"
              xmlns:validators="clr-namespace:PixiEditor.Helpers.Validators"
              xmlns:validators="clr-namespace:PixiEditor.Helpers.Validators"
+             xmlns:ui="clr-namespace:PixiEditor.Helpers.UI"
              mc:Ignorable="d"
              mc:Ignorable="d"
              d:DesignHeight="30" d:DesignWidth="160" Name="uc" LayoutUpdated="UserControlLayoutUpdated">
              d:DesignHeight="30" d:DesignWidth="160" Name="uc" LayoutUpdated="UserControlLayoutUpdated">
     <UserControl.Resources>
     <UserControl.Resources>
         <converters:ToolSizeToIntConverter x:Key="ToolSizeToIntConverter" />
         <converters:ToolSizeToIntConverter x:Key="ToolSizeToIntConverter" />
     </UserControl.Resources>
     </UserControl.Resources>
-    <TextBox IsEnabled="{Binding IsEnabled, ElementName=uc}" HorizontalContentAlignment="Center"
+    <ui:UniversalTextBox IsEnabled="{Binding IsEnabled, ElementName=uc}" HorizontalContentAlignment="Center"
              Style="{StaticResource DarkTextBoxStyle}" FontSize="16" MaxLength="4">
              Style="{StaticResource DarkTextBoxStyle}" FontSize="16" MaxLength="4">
-        <TextBox.Text>
+        <ui:UniversalTextBox.Text>
             <Binding ElementName="uc"
             <Binding ElementName="uc"
                      Path="Size" Mode="TwoWay"
                      Path="Size" Mode="TwoWay"
                      Converter="{StaticResource ToolSizeToIntConverter}">
                      Converter="{StaticResource ToolSizeToIntConverter}">
@@ -23,9 +23,9 @@
                     <validators:SizeValidationRule ValidatesOnTargetUpdated="True" />
                     <validators:SizeValidationRule ValidatesOnTargetUpdated="True" />
                 </Binding.ValidationRules>
                 </Binding.ValidationRules>
             </Binding>
             </Binding>
-        </TextBox.Text>
+        </ui:UniversalTextBox.Text>
         <i:Interaction.Behaviors>
         <i:Interaction.Behaviors>
             <behaviors:TextBoxFocusBehavior FillSize="True" />
             <behaviors:TextBoxFocusBehavior FillSize="True" />
         </i:Interaction.Behaviors>
         </i:Interaction.Behaviors>
-    </TextBox>
+    </ui:UniversalTextBox>
 </UserControl>
 </UserControl>