Browse Source

Fixed shortcuts with common key

Frytek 5 years ago
parent
commit
3ba6296632

+ 9 - 4
PixiEditor/Models/Controllers/Shortcuts/ShortcutController.cs

@@ -21,11 +21,16 @@ namespace PixiEditor.Models.Controllers
         {
             if (!BlockShortcutExecution)
             {
-                Shortcut shortcut = Shortcuts.Find(x => x.ShortcutKey == key);
-                if (shortcut == null) return;
-                if (Keyboard.Modifiers.HasFlag(shortcut.Modifier))
+                Shortcut[] shortcuts = Shortcuts.FindAll(x => x.ShortcutKey == key).ToArray();
+                if (shortcuts.Length < 1) return;
+                shortcuts = shortcuts.OrderByDescending(x => x.Modifier).ToArray();
+                for (int i = 0; i < shortcuts.Length; i++)
                 {
-                    shortcut.Execute();
+                    if (Keyboard.Modifiers.HasFlag(shortcuts[i].Modifier))
+                    {
+                        shortcuts[i].Execute();
+                        break;
+                    }
                 }
             }
         }

+ 2 - 36
PixiEditor/Models/Controllers/UndoManager.cs

@@ -38,42 +38,7 @@ namespace PixiEditor.Models.Controllers
         {
             MainRoot = root;
         }
-
-        /// <summary>
-        /// Records changes, used to save multiple changes as one
-        /// </summary>
-        /// <param name="property">Record property name.</param>
-        /// <param name="oldValue">Old change value.</param>
-        /// <param name="newValue">New change value.</param>
-        /// <param name="undoDescription">Description of change.</param>
-        public static void RecordChanges(string property, object oldValue, object newValue, string undoDescription = "")
-        {
-            if (_stopRecording == false)
-            {
-                if (_recordedChanges.Count >= 2)
-                {
-                    _recordedChanges.RemoveAt(_recordedChanges.Count - 1);
-                }
-                _recordedChanges.Add(new Change(property, oldValue, newValue, undoDescription));
-
-            }
-        }
-
-        /// <summary>
-        /// Stops recording changes and saves it as one.
-        /// </summary>
-        public static void StopRecording()
-        {
-            _stopRecording = true;
-            if (_recordedChanges.Count > 0)
-            {
-                Change changeToSave = _recordedChanges[0];
-                changeToSave.NewValue = _recordedChanges.Last().OldValue;
-                AddUndoChange(changeToSave);
-                _recordedChanges.Clear();
-            }
-            _stopRecording = false;
-        }
+      
 
         public static void AddUndoChange(Change change)
         {
@@ -84,6 +49,7 @@ namespace PixiEditor.Models.Controllers
             _lastChangeWasUndo = false;
             UndoStack.Push(change);
         }
+
         /// <summary>
         /// Adds property change to UndoStack
         /// </summary>

+ 19 - 18
PixiEditor/Styles/ThemeStyle.xaml

@@ -66,6 +66,25 @@
     </Style>
 
 
+    <Style TargetType="Button" x:Key="ImageButtonStyle">
+        <Setter Property="OverridesDefaultStyle" Value="True"/>
+        <Setter Property="Template">
+            <Setter.Value>
+                <ControlTemplate TargetType="Button">
+                    <Border BorderThickness="0" Opacity="{TemplateBinding Opacity}" Name="brd" Background="{TemplateBinding Background}">
+                        <ContentPresenter/>
+                    </Border>
+                    <ControlTemplate.Triggers>
+                        <Trigger Property="IsMouseOver" Value="True">
+                            <Setter Property="Opacity" TargetName="brd" Value="1"/>
+                        </Trigger>
+                    </ControlTemplate.Triggers>
+                </ControlTemplate>
+            </Setter.Value>
+        </Setter>
+    </Style>
+
+
     <Style TargetType="TextBox" x:Key="DarkTextBoxStyle">
         <Setter Property="Background" Value="#202020"/>
         <Setter Property="BorderThickness" Value="1"/>
@@ -117,23 +136,5 @@
         </Setter>
     </Style>
 
-    <Style TargetType="Button" x:Key="ImageButtonStyle">
-        <Setter Property="OverridesDefaultStyle" Value="True"/>
-        <Setter Property="Template">
-            <Setter.Value>
-                <ControlTemplate TargetType="Button">
-                    <Border BorderThickness="0" Opacity="0.3" Name="brd" Background="{TemplateBinding Background}">
-                        <ContentPresenter/>
-                    </Border>
-                    <ControlTemplate.Triggers>
-                        <Trigger Property="IsMouseOver" Value="True">
-                            <Setter Property="Opacity" TargetName="brd" Value="1"/>
-                        </Trigger>
-                    </ControlTemplate.Triggers>
-                </ControlTemplate>
-            </Setter.Value>
-        </Setter>
-    </Style>
-
 
 </ResourceDictionary>

+ 3 - 1
PixiEditor/ViewModels/ViewModelMain.cs

@@ -167,9 +167,11 @@ namespace PixiEditor.ViewModels
                     new Shortcut(Key.O, OpenFileCommand, null, ModifierKeys.Control),
                     new Shortcut(Key.E, SelectToolCommand, ToolType.Earser),
                     new Shortcut(Key.O, SelectToolCommand, ToolType.ColorPicker),
-                    new Shortcut(Key.C, SelectToolCommand, ToolType.Rectangle),
+                    new Shortcut(Key.R, SelectToolCommand, ToolType.Rectangle),
+                    new Shortcut(Key.C, SelectToolCommand, ToolType.Circle),
                     new Shortcut(Key.L, SelectToolCommand, ToolType.Line),
                     new Shortcut(Key.G, SelectToolCommand, ToolType.Bucket),
+                    new Shortcut(Key.U, SelectToolCommand, ToolType.Brightness),
                     new Shortcut(Key.Y, RedoCommand, null, ModifierKeys.Control),
                     new Shortcut(Key.Z, UndoCommand),
                     new Shortcut(Key.S, UndoCommand, null, ModifierKeys.Control),

+ 2 - 2
PixiEditor/Views/MainWindow.xaml

@@ -147,7 +147,7 @@
                     <ImageBrush ImageSource="/Images/EarserImage.png" Stretch="Uniform"/>
                 </Button.Background>
             </Button>
-            <Button Style="{StaticResource ToolButtonStyle}" Command="{Binding SelectToolCommand, Mode=OneWay}" CommandParameter="Brightness" ToolTip="Makes pixel brighter or darker pixel (U)">
+            <Button Style="{StaticResource ToolButtonStyle}" Opacity="1" Command="{Binding SelectToolCommand, Mode=OneWay}" CommandParameter="Brightness" ToolTip="Makes pixel brighter or darker pixel (U)">
                 <Button.Background>
                     <ImageBrush ImageSource="/Images/LightenImage.png" Stretch="Uniform"/>
                 </Button.Background>
@@ -162,7 +162,7 @@
                     </Rectangle.Fill>
                 </Rectangle>
                 <xctk:ColorPicker Width="70" Panel.ZIndex="2" Height="70" VerticalAlignment="Top" HorizontalAlignment="Left" UsingAlphaChannel="True" AvailableColorsSortingMode="Alphabetical" ShowDropDownButton="False" Background="Transparent" BorderThickness="0" ShowRecentColors="True" SelectedColor="{Binding PrimaryColor, Mode=TwoWay}"></xctk:ColorPicker>
-                <Button ToolTip="Swap colors (X)" Command="{Binding SwapColorsCommand}" Width="25" Height="25" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="0 0 0 3" Style="{StaticResource ImageButtonStyle}">
+                <Button Opacity="0.3" ToolTip="Swap colors (X)" Command="{Binding SwapColorsCommand}" Width="25" Height="25" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="0 0 0 3" Style="{StaticResource ImageButtonStyle}">
                     <Button.Background>
                         <ImageBrush ImageSource="/Images/SwapArrows.png" Stretch="Fill"/>
                     </Button.Background>