Browse Source

QOL and fixes

CPKreuz 3 years ago
parent
commit
a571cb2b19

+ 7 - 4
PixiEditor/Helpers/Converters/EqualityBoolToVisibilityConverter.cs

@@ -4,14 +4,17 @@ using System.Windows;
 
 
 namespace PixiEditor.Helpers.Converters
 namespace PixiEditor.Helpers.Converters
 {
 {
-    public class EqualityBoolToVisibilityConverter :
-        SingleInstanceConverter<EqualityBoolToVisibilityConverter>
+    public class EqualityBoolToVisibilityConverter : MarkupConverter
     {
     {
+        public bool Invert { get; set; }
+
         public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
         public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
         {
         {
             if (value == null)
             if (value == null)
-                return false;
-            return value.Equals(parameter) ? Visibility.Visible : Visibility.Collapsed;
+                return Invert;
+
+            var parameterValue = System.Convert.ChangeType(parameter, value.GetType());
+            return value.Equals(parameterValue) != Invert ? Visibility.Visible : Visibility.Collapsed;
         }
         }
     }
     }
 }
 }

+ 1 - 1
PixiEditor/Helpers/InputKeyHelpers.cs

@@ -26,7 +26,7 @@ namespace PixiEditor.Helpers
             Key.NumPad9 => "Num9",
             Key.NumPad9 => "Num9",
             Key.Space => nameof(Key.Space),
             Key.Space => nameof(Key.Space),
             Key.Tab => nameof(Key.Tab),
             Key.Tab => nameof(Key.Tab),
-            Key.Back => nameof(Key.Back),
+            Key.Back => "Backspace",
             Key.Escape => "Esc",
             Key.Escape => "Esc",
             _ => GetMappedKey(key, culture),
             _ => GetMappedKey(key, culture),
         };
         };

+ 2 - 2
PixiEditor/Models/Commands/Attributes/Commands/InternalAttribute.cs

@@ -11,7 +11,7 @@
             /// A command that is not shown in the UI
             /// A command that is not shown in the UI
             /// </summary>
             /// </summary>
             public InternalAttribute(string name)
             public InternalAttribute(string name)
-                : base(name, null, null)
+                : base(name, string.Empty, string.Empty)
             {
             {
             }
             }
 
 
@@ -19,7 +19,7 @@
             /// A command that is not shown in the UI
             /// A command that is not shown in the UI
             /// </summary>
             /// </summary>
             public InternalAttribute(string name, object parameter)
             public InternalAttribute(string name, object parameter)
-                : base(name, parameter, null, null)
+                : base(name, parameter, string.Empty, string.Empty)
             {
             {
             }
             }
         }
         }

+ 8 - 0
PixiEditor/Models/Commands/CommandController.cs

@@ -305,6 +305,14 @@ namespace PixiEditor.Models.Commands
         public void ResetShortcuts()
         public void ResetShortcuts()
         {
         {
             Commands.ClearShortcuts();
             Commands.ClearShortcuts();
+
+            foreach (var command in Commands)
+            {
+                Commands.AddShortcut(command, command.DefaultShortcut);
+                command.Shortcut = command.DefaultShortcut;
+            }
+
+            shortcutFile.SaveShortcuts();
         }
         }
     }
     }
 }
 }

+ 1 - 1
PixiEditor/Models/Commands/ShortcutFile.cs

@@ -18,7 +18,7 @@ namespace PixiEditor.Models.Commands
             if (!File.Exists(path))
             if (!File.Exists(path))
             {
             {
                 Directory.CreateDirectory(System.IO.Path.GetDirectoryName(path));
                 Directory.CreateDirectory(System.IO.Path.GetDirectoryName(path));
-                File.Create(Path);
+                File.Create(Path).Dispose();
             }
             }
         }
         }
 
 

+ 1 - 1
PixiEditor/Models/DataHolders/KeyCombination.cs

@@ -18,7 +18,7 @@ namespace PixiEditor.Models.DataHolders
         {
         {
             StringBuilder builder = new();
             StringBuilder builder = new();
 
 
-            foreach (ModifierKeys modifier in Modifiers.GetFlags())
+            foreach (ModifierKeys modifier in Modifiers.GetFlags().OrderByDescending(x => x != ModifierKeys.Alt))
             {
             {
                 if (modifier == ModifierKeys.None) continue;
                 if (modifier == ModifierKeys.None) continue;
 
 

+ 7 - 5
PixiEditor/Styles/ThemeStyle.xaml

@@ -16,7 +16,7 @@
     <Style TargetType="ToggleButton">
     <Style TargetType="ToggleButton">
         <Setter Property="Focusable" Value="False"/>
         <Setter Property="Focusable" Value="False"/>
     </Style>
     </Style>
-    
+
     <Style TargetType="Button" x:Key="BaseDarkButton">
     <Style TargetType="Button" x:Key="BaseDarkButton">
         <Setter Property="Background" Value="#404040" />
         <Setter Property="Background" Value="#404040" />
         <Setter Property="Foreground" Value="White" />
         <Setter Property="Foreground" Value="White" />
@@ -54,12 +54,15 @@
     <Style TargetType="Button" x:Key="DarkRoundButton" BasedOn="{StaticResource BaseDarkButton}">
     <Style TargetType="Button" x:Key="DarkRoundButton" BasedOn="{StaticResource BaseDarkButton}">
         <Setter Property="OverridesDefaultStyle" Value="True" />
         <Setter Property="OverridesDefaultStyle" Value="True" />
         <Setter Property="Background" Value="#303030" />
         <Setter Property="Background" Value="#303030" />
+        <Setter Property="Focusable" Value="False" />
+        <Setter Property="Height" Value="28"/>
+        <Setter Property="Width" Value="70"/>
         <Setter Property="Template">
         <Setter Property="Template">
             <Setter.Value>
             <Setter.Value>
                 <ControlTemplate TargetType="Button">
                 <ControlTemplate TargetType="Button">
                     <Border CornerRadius="4" Background="{TemplateBinding Background}">
                     <Border CornerRadius="4" Background="{TemplateBinding Background}">
                         <ContentPresenter Content="{TemplateBinding Content}" HorizontalAlignment="Center"
                         <ContentPresenter Content="{TemplateBinding Content}" HorizontalAlignment="Center"
-                                          VerticalAlignment="Center" />
+                                          VerticalAlignment="Center" Margin="{TemplateBinding Padding}"/>
                     </Border>
                     </Border>
                     <ControlTemplate.Triggers>
                     <ControlTemplate.Triggers>
                         <Trigger Property="IsEnabled" Value="False">
                         <Trigger Property="IsEnabled" Value="False">
@@ -169,8 +172,7 @@
                 <ControlTemplate TargetType="TextBox">
                 <ControlTemplate TargetType="TextBox">
                     <Border Background="{TemplateBinding Background}"
                     <Border Background="{TemplateBinding Background}"
                             BorderBrush="{TemplateBinding BorderBrush}"
                             BorderBrush="{TemplateBinding BorderBrush}"
-                            BorderThickness="{TemplateBinding BorderThickness}"
-                            Padding="{TemplateBinding Padding}">
+                            BorderThickness="{TemplateBinding BorderThickness}">
                         <ScrollViewer Name="PART_ContentHost"/>
                         <ScrollViewer Name="PART_ContentHost"/>
                     </Border>
                     </Border>
                 </ControlTemplate>
                 </ControlTemplate>
@@ -284,4 +286,4 @@
             </Setter.Value>
             </Setter.Value>
         </Setter>
         </Setter>
     </Style>
     </Style>
-</ResourceDictionary>
+</ResourceDictionary>

+ 12 - 0
PixiEditor/ViewModels/SettingsWindowViewModel.cs

@@ -1,4 +1,6 @@
 using PixiEditor.Models.Commands;
 using PixiEditor.Models.Commands;
+using PixiEditor.Models.Commands.Attributes;
+using PixiEditor.Models.Dialogs;
 using PixiEditor.ViewModels.SubViewModels.UserPreferences;
 using PixiEditor.ViewModels.SubViewModels.UserPreferences;
 using System.Collections.ObjectModel;
 using System.Collections.ObjectModel;
 
 
@@ -22,6 +24,16 @@ namespace PixiEditor.ViewModels
 
 
         public ObservableCollection<CommandGroup> Commands { get; }
         public ObservableCollection<CommandGroup> Commands { get; }
 
 
+        [Models.Commands.Attributes.Command.Internal("PixiEditor.Shortcuts.Reset")]
+        public static void ResetCommand()
+        {
+            var dialog = new OptionsDialog<string>("Are you sure?", "Are you sure you want to reset all shortcuts to their default value?")
+            {
+                { "Yes", x => CommandController.Current.ResetShortcuts() },
+                "Cancel"
+            }.ShowDialog();
+        }
+
         public SettingsWindowViewModel()
         public SettingsWindowViewModel()
         {
         {
             Commands = new(CommandController.Current.CommandGroups);
             Commands = new(CommandController.Current.CommandGroups);

+ 7 - 3
PixiEditor/ViewModels/SubViewModels/Main/DebugViewModel.cs

@@ -43,6 +43,7 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
         public static void Crash() => throw new InvalidOperationException("User requested to crash :c");
         public static void Crash() => throw new InvalidOperationException("User requested to crash :c");
 
 
         [Command.Basic("#DEBUG#PixiEditor.Debug.DeleteUserPreferences", @"%appdata%\PixiEditor\user_preferences.json", "Delete User Preferences (Roaming)", "Delete User Preferences (Roaming AppData)")]
         [Command.Basic("#DEBUG#PixiEditor.Debug.DeleteUserPreferences", @"%appdata%\PixiEditor\user_preferences.json", "Delete User Preferences (Roaming)", "Delete User Preferences (Roaming AppData)")]
+        [Command.Basic("#DEBUG#PixiEditor.Debug.DeleteShortcutFile", @"%appdata%\PixiEditor\shortcuts.json", "Delete Shortcut File (Roaming)", "Delete Shortcut File (Roaming AppData)")]
         [Command.Basic("#DEBUG#PixiEditor.Debug.DeleteEditorData", @"%localappdata%\PixiEditor\editor_data.json", "Delete Editor Data (Local)", "Delete Editor Data (Local AppData)")]
         [Command.Basic("#DEBUG#PixiEditor.Debug.DeleteEditorData", @"%localappdata%\PixiEditor\editor_data.json", "Delete Editor Data (Local)", "Delete Editor Data (Local AppData)")]
         public static void DeleteFile(string path)
         public static void DeleteFile(string path)
         {
         {
@@ -53,10 +54,13 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
                 return;
                 return;
             }
             }
 
 
-            if (ConfirmationDialog.Show($"Are you sure you want to delete {path}?\nThis data will be lost for all installations.\n(Full Path: {file})", "Are you sure?") == Models.Enums.ConfirmationType.Yes)
+            OptionsDialog<string> dialog = new("Are you sure?", $"Are you sure you want to delete {path}?\nThis data will be lost for all installations.\n(Full Path: {file})")
             {
             {
-                File.Delete(file);
-            }
+                { "Yes", x => File.Delete(file) },
+                "Cancel"
+            };
+
+            dialog.ShowDialog();
         }
         }
 
 
         [Conditional("DEBUG")]
         [Conditional("DEBUG")]

+ 19 - 6
PixiEditor/Views/Dialogs/SettingsWindow.xaml

@@ -12,7 +12,8 @@
         xmlns:behaviours="clr-namespace:PixiEditor.Helpers.Behaviours" 
         xmlns:behaviours="clr-namespace:PixiEditor.Helpers.Behaviours" 
         xmlns:usercontrols="clr-namespace:PixiEditor.Views.UserControls"
         xmlns:usercontrols="clr-namespace:PixiEditor.Views.UserControls"
         xmlns:dial="clr-namespace:PixiEditor.Views.Dialogs"
         xmlns:dial="clr-namespace:PixiEditor.Views.Dialogs"
-        xmlns:cmds="clr-namespace:PixiEditor.Models.Commands"
+        xmlns:commands="clr-namespace:PixiEditor.Models.Commands"
+        xmlns:cmds="clr-namespace:PixiEditor.Models.Commands.XAML"
         mc:Ignorable="d"
         mc:Ignorable="d"
         Title="Settings" Name="window" 
         Title="Settings" Name="window" 
         Height="500" Width="640"
         Height="500" Width="640"
@@ -171,24 +172,27 @@
                     <RowDefinition Height="Auto"/>
                     <RowDefinition Height="Auto"/>
                     <RowDefinition/>
                     <RowDefinition/>
                 </Grid.RowDefinitions>
                 </Grid.RowDefinitions>
-                <Grid>
+                <Grid Margin="0,0,0,10">
                     <Grid.ColumnDefinitions>
                     <Grid.ColumnDefinitions>
                         <ColumnDefinition/>
                         <ColumnDefinition/>
                         <ColumnDefinition Width="100"/>
                         <ColumnDefinition Width="100"/>
                     </Grid.ColumnDefinitions>
                     </Grid.ColumnDefinitions>
                     <TextBox Style="{StaticResource DarkTextBoxStyle}"/>
                     <TextBox Style="{StaticResource DarkTextBoxStyle}"/>
                     <Button Grid.Column="1" Style="{StaticResource DarkRoundButton}"
                     <Button Grid.Column="1" Style="{StaticResource DarkRoundButton}"
-                            Content="Reset all" Margin="5,0"/>
+                            Content="Reset all" Height="Auto" Margin="5,0"
+                            FontSize="14" Padding="1"
+                            Command="{cmds:Command PixiEditor.Shortcuts.Reset}"/>
                 </Grid>
                 </Grid>
-                <ScrollViewer Grid.Row="1">
+
+                <ScrollViewer Grid.Row="1" x:Name="commandScroll">
                     <ItemsControl ItemsSource="{Binding Commands}" Foreground="White">
                     <ItemsControl ItemsSource="{Binding Commands}" Foreground="White">
                         <ItemsControl.ItemTemplate>
                         <ItemsControl.ItemTemplate>
-                            <DataTemplate DataType="cmds:CommandGroup">
+                            <DataTemplate DataType="commands:CommandGroup">
                                 <StackPanel Margin="0,0,0,20">
                                 <StackPanel Margin="0,0,0,20">
                                     <TextBlock Text="{Binding Display}" FontSize="22" FontWeight="SemiBold"/>
                                     <TextBlock Text="{Binding Display}" FontSize="22" FontWeight="SemiBold"/>
                                     <ItemsControl ItemsSource="{Binding VisibleCommands}">
                                     <ItemsControl ItemsSource="{Binding VisibleCommands}">
                                         <ItemsControl.ItemTemplate>
                                         <ItemsControl.ItemTemplate>
-                                            <DataTemplate DataType="cmds:Command">
+                                            <DataTemplate DataType="commands:Command">
                                                 <Grid Margin="0,5,5,0">
                                                 <Grid Margin="0,5,5,0">
                                                     <TextBlock Text="{Binding Display}" ToolTip="{Binding Description}"/>
                                                     <TextBlock Text="{Binding Display}" ToolTip="{Binding Description}"/>
                                                     <usercontrols:ShortcutBox Width="120" Command="{Binding}" HorizontalAlignment="Right"/>
                                                     <usercontrols:ShortcutBox Width="120" Command="{Binding}" HorizontalAlignment="Right"/>
@@ -201,6 +205,15 @@
                         </ItemsControl.ItemTemplate>
                         </ItemsControl.ItemTemplate>
                     </ItemsControl>
                     </ItemsControl>
                 </ScrollViewer>
                 </ScrollViewer>
+                
+                <Grid Grid.Row="1" Height="10" VerticalAlignment="Top" Visibility="{Binding VerticalOffset, ElementName=commandScroll, Mode=OneWay, Converter={converters:EqualityBoolToVisibilityConverter Invert=True}, ConverterParameter=0}">
+                    <Grid.Background>
+                        <LinearGradientBrush StartPoint="0, 0" EndPoint="0, 1">
+                            <GradientStop Color="#22000000" Offset="0"/>
+                            <GradientStop Color="#00000000" Offset="1.0"/>
+                        </LinearGradientBrush>
+                    </Grid.Background>
+                </Grid>
             </Grid>
             </Grid>
         </Grid>
         </Grid>
     </DockPanel>
     </DockPanel>

+ 2 - 1
PixiEditor/Views/MainWindow.xaml

@@ -168,6 +168,7 @@
                         <MenuItem Header="_Crash" cmds:Menu.Command="PixiEditor.Debug.Crash" />
                         <MenuItem Header="_Crash" cmds:Menu.Command="PixiEditor.Debug.Crash" />
                         <MenuItem Header="Delete">
                         <MenuItem Header="Delete">
                             <MenuItem Header="User Preferences (Roaming)" cmds:Menu.Command="PixiEditor.Debug.DeleteUserPreferences" />
                             <MenuItem Header="User Preferences (Roaming)" cmds:Menu.Command="PixiEditor.Debug.DeleteUserPreferences" />
+                            <MenuItem Header="Shortcut File (Roaming)" cmds:Menu.Command="PixiEditor.Debug.DeleteShortcutFile" />
                             <MenuItem Header="Editor Data (Local)" cmds:Menu.Command="PixiEditor.Debug.DeleteEditorData" />
                             <MenuItem Header="Editor Data (Local)" cmds:Menu.Command="PixiEditor.Debug.DeleteEditorData" />
                         </MenuItem>
                         </MenuItem>
                     </MenuItem>
                     </MenuItem>
@@ -433,6 +434,6 @@
         </Grid>
         </Grid>
         <usercontrols:CommandSearchControl Visibility="{Binding SearchSubViewModel.SearchWindowOpen, Converter={BoolToVisibilityConverter}, Mode=TwoWay}"
         <usercontrols:CommandSearchControl Visibility="{Binding SearchSubViewModel.SearchWindowOpen, Converter={BoolToVisibilityConverter}, Mode=TwoWay}"
                                            SearchTerm="{Binding SearchSubViewModel.SearchTerm, Mode=TwoWay}"
                                            SearchTerm="{Binding SearchSubViewModel.SearchTerm, Mode=TwoWay}"
-                                           HorizontalAlignment="Center" Height="700"/>
+                                           HorizontalAlignment="Center" Height="700" MaxWidth="920"/>
     </Grid>
     </Grid>
 </Window>
 </Window>

+ 2 - 1
PixiEditor/Views/UserControls/CommandSearchControl.xaml.cs

@@ -93,8 +93,9 @@ namespace PixiEditor.Views.UserControls
                 _viewModel.SelectedResult = _viewModel.Results.IndexOrPrevious(x => x.CanExecute, newIndex);
                 _viewModel.SelectedResult = _viewModel.Results.IndexOrPrevious(x => x.CanExecute, newIndex);
             }
             }
             else if (CommandController.Current.Commands["PixiEditor.Search.Toggle"].Shortcut
             else if (CommandController.Current.Commands["PixiEditor.Search.Toggle"].Shortcut
-                == new KeyCombination(e.Key, Keyboard.Modifiers))
+                == new KeyCombination(e.Key, Keyboard.Modifiers) || e.Key == Key.Escape)
             {
             {
+                FocusManager.SetFocusedElement(FocusManager.GetFocusScope(textBox), null);
                 Keyboard.ClearFocus();
                 Keyboard.ClearFocus();
             }
             }
             else
             else