Browse Source

Added shortcut hint to apply transform button and changed enter key representation to ↵

CPKreuz 2 years ago
parent
commit
ca12b80574

+ 20 - 2
src/PixiEditor/Helpers/Converters/NotNullToVisibilityConverter.cs

@@ -12,13 +12,31 @@ internal class NotNullToVisibilityConverter
 
 
     public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
     public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
     {
     {
-        bool isNull = value is not null;
+        bool isNull = IsDefaultValue(value);
 
 
         if (Inverted)
         if (Inverted)
         {
         {
             isNull = !isNull;
             isNull = !isNull;
         }
         }
 
 
-        return isNull ? Visibility.Visible : Visibility.Collapsed;
+        return isNull ? Visibility.Collapsed : Visibility.Visible;
+    }
+    
+    bool IsDefaultValue(object obj)
+    {
+        if (obj is null)
+        {
+            return true;
+        }
+        
+        var type = obj.GetType();
+
+        if (type.IsValueType)
+        {
+            object defaultValue = Activator.CreateInstance(type);
+            return obj.Equals(defaultValue);
+        }
+
+        return false;
     }
     }
 }
 }

+ 1 - 1
src/PixiEditor/Helpers/InputKeyHelpers.cs

@@ -25,7 +25,7 @@ internal static class InputKeyHelpers
         >= Key.NumPad0 and <= Key.Divide => $"Num {GetMappedKey(key, forceInvariant)}",
         >= Key.NumPad0 and <= Key.Divide => $"Num {GetMappedKey(key, forceInvariant)}",
         Key.Space => nameof(Key.Space),
         Key.Space => nameof(Key.Space),
         Key.Tab => nameof(Key.Tab),
         Key.Tab => nameof(Key.Tab),
-        Key.Return => "Enter",
+        Key.Return => "",
         Key.Back => "Backspace",
         Key.Back => "Backspace",
         Key.Escape => "Esc",
         Key.Escape => "Esc",
         _ => GetMappedKey(key, forceInvariant),
         _ => GetMappedKey(key, forceInvariant),

+ 1 - 1
src/PixiEditor/Models/Commands/XAML/ContextMenu.cs

@@ -36,7 +36,7 @@ internal class ContextMenu : System.Windows.Controls.ContextMenu
         var command = CommandController.Current.Commands[value];
         var command = CommandController.Current.Commands[value];
 
 
         item.Command = Command.GetICommand(command, false);
         item.Command = Command.GetICommand(command, false);
-        item.SetBinding(MenuItem.InputGestureTextProperty, ShortcutBinding.GetBinding(command));
+        item.SetBinding(MenuItem.InputGestureTextProperty, ShortcutBinding.GetBinding(command, null));
     }
     }
 
 
     private static void HandleDesignMode(MenuItem item, string name)
     private static void HandleDesignMode(MenuItem item, string name)

+ 1 - 1
src/PixiEditor/Models/Commands/XAML/Menu.cs

@@ -54,7 +54,7 @@ internal class Menu : System.Windows.Controls.Menu
 
 
         item.Command = Command.GetICommand(command, false);
         item.Command = Command.GetICommand(command, false);
         item.Icon = icon;
         item.Icon = icon;
-        item.SetBinding(MenuItem.InputGestureTextProperty, ShortcutBinding.GetBinding(command));
+        item.SetBinding(MenuItem.InputGestureTextProperty, ShortcutBinding.GetBinding(command, null));
     }
     }
 
 
     private static void HandleDesignMode(MenuItem item, string name)
     private static void HandleDesignMode(MenuItem item, string name)

+ 6 - 3
src/PixiEditor/Models/Commands/XAML/ShortcutBinding.cs

@@ -12,6 +12,8 @@ internal class ShortcutBinding : MarkupExtension
 
 
     public string Name { get; set; }
     public string Name { get; set; }
 
 
+    public IValueConverter Converter { get; set; }
+    
     public ShortcutBinding() { }
     public ShortcutBinding() { }
 
 
     public ShortcutBinding(string name) => Name = name;
     public ShortcutBinding(string name) => Name = name;
@@ -25,14 +27,15 @@ internal class ShortcutBinding : MarkupExtension
         }
         }
 
 
         commandController ??= ViewModelMain.Current.CommandController;
         commandController ??= ViewModelMain.Current.CommandController;
-        return GetBinding(commandController.Commands[Name]).ProvideValue(serviceProvider);
+        return GetBinding(commandController.Commands[Name], Converter).ProvideValue(serviceProvider);
     }
     }
 
 
-    public static Binding GetBinding(ActualCommand command) => new Binding
+    public static Binding GetBinding(ActualCommand command, IValueConverter converter) => new Binding
     {
     {
         Source = command,
         Source = command,
         Path = new("Shortcut"),
         Path = new("Shortcut"),
         Mode = BindingMode.OneWay,
         Mode = BindingMode.OneWay,
-        StringFormat = ""
+        StringFormat = "",
+        Converter = converter
     };
     };
 }
 }

+ 11 - 5
src/PixiEditor/Views/UserControls/Viewport.xaml

@@ -404,13 +404,13 @@
         </zoombox:Zoombox>
         </zoombox:Zoombox>
         <Button 
         <Button 
             Panel.ZIndex="99999"
             Panel.ZIndex="99999"
-            DockPanel.Dock="Bottom" 
-            Width="140" 
-            Height="28" 
-            Margin="5" 
+            DockPanel.Dock="Bottom"
+            Margin="5"
+            Padding="8,5,5,5"
             VerticalAlignment="Bottom" 
             VerticalAlignment="Bottom" 
+            HorizontalAlignment="Center"
             Style="{StaticResource GrayRoundButton}"
             Style="{StaticResource GrayRoundButton}"
-            Command="{cmds:Command PixiEditor.Tools.ApplyTransform}" views:Translator.Key="APPLY_TRANSFORM">
+            Command="{cmds:Command PixiEditor.Tools.ApplyTransform}">
             <Button.Visibility>
             <Button.Visibility>
                 <MultiBinding Converter="{converters:BoolOrToVisibilityConverter}">
                 <MultiBinding Converter="{converters:BoolOrToVisibilityConverter}">
                     <MultiBinding.Bindings>
                     <MultiBinding.Bindings>
@@ -419,6 +419,12 @@
                     </MultiBinding.Bindings>
                     </MultiBinding.Bindings>
                 </MultiBinding>
                 </MultiBinding>
             </Button.Visibility>
             </Button.Visibility>
+            <StackPanel Orientation="Horizontal">
+                <TextBlock views:Translator.Key="APPLY_TRANSFORM" VerticalAlignment="Center" Margin="0,0,5,0" />
+                <Border Padding="10,3" CornerRadius="5" Background="{StaticResource AccentColor}" Visibility="{cmds:ShortcutBinding PixiEditor.Tools.ApplyTransform, Converter={converters:NotNullToVisibilityConverter}}">
+                    <TextBlock Text="{cmds:ShortcutBinding PixiEditor.Tools.ApplyTransform}" />
+                </Border>
+            </StackPanel>
         </Button>
         </Button>
     </Grid>
     </Grid>
 </UserControl>
 </UserControl>