Browse Source

Cosmetic templates changes

Krzysztof Krysiński 2 years ago
parent
commit
3ede78b3b1

+ 1 - 3
src/PixiEditor/Models/Dialogs/CustomDialog.cs

@@ -1,6 +1,4 @@
-using PixiEditor.Helpers;
-
-namespace PixiEditor.Models.Dialogs;
+namespace PixiEditor.Models.Dialogs;
 
 internal abstract class CustomDialog : NotifyableObject
 {

+ 32 - 0
src/PixiEditor/Models/Dialogs/OptionDialog.cs

@@ -0,0 +1,32 @@
+using PixiEditor.Models.Enums;
+using PixiEditor.Views.Dialogs;
+
+namespace PixiEditor.Models.Dialogs;
+
+internal static class OptionDialog
+{
+    public static OptionResult Show(string message, string title, string option1Text, string option2Text)
+    {
+        ConfirmationPopup popup = new ConfirmationPopup
+        {
+            Title = title,
+            Body = message,
+            ShowInTaskbar = false,
+            FirstOptionText = option1Text,
+            SecondOptionText = option2Text,
+        };
+        if (popup.ShowDialog().GetValueOrDefault())
+        {
+            return popup.Result ? OptionResult.Option1 : OptionResult.Option2;
+        }
+
+        return OptionResult.Canceled;
+    }
+}
+
+public enum OptionResult
+{
+    Option1,
+    Option2,
+    Canceled
+}

+ 0 - 2
src/PixiEditor/Styles/ThemeStyle.xaml

@@ -97,9 +97,7 @@
     <Style TargetType="Button" x:Key="DarkRoundButton" BasedOn="{StaticResource BaseDarkButton}">
         <Setter Property="OverridesDefaultStyle" Value="True" />
         <Setter Property="Background" Value="#303030" />
-        <Setter Property="Focusable" Value="False" />
         <Setter Property="Height" Value="28"/>
-        <Setter Property="Width" Value="70"/>
         <Setter Property="Template">
             <Setter.Value>
                 <ControlTemplate TargetType="Button">

+ 8 - 1
src/PixiEditor/ViewModels/SettingsWindowViewModel.cs

@@ -120,7 +120,14 @@ internal class SettingsWindowViewModel : ViewModelBase
     [Command.Internal("PixiEditor.Shortcuts.OpenTemplatePopup")]
     public static void OpenTemplatePopup()
     {
-        new ImportShortcutTemplatePopup().ShowDialog();
+        ImportShortcutTemplatePopup popup = new ImportShortcutTemplatePopup();
+        var settingsWindow = Application.Current.Windows.OfType<SettingsWindow>().FirstOrDefault();
+        if(settingsWindow is not null)
+        {
+            popup.Owner = settingsWindow;
+        }
+        
+        popup.ShowDialog();
     }
 
     public SettingsWindowViewModel()

+ 4 - 4
src/PixiEditor/Views/Dialogs/ConfirmationPopup.xaml

@@ -28,16 +28,16 @@
 
         <StackPanel DockPanel.Dock="Bottom" Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Center"
                     Margin="0,0,10,15">
-            <Button Margin="10,0,10,0" Width="70" IsDefault="True"
+            <Button Margin="10,0,10,0" MinWidth="70" IsDefault="True" Padding="5 0"
                     Command="{Binding Path=DataContext.SetResultAndCloseCommand, ElementName=popup}"
-                    Style="{StaticResource DarkRoundButton}" Content="Yes">
+                    Style="{StaticResource DarkRoundButton}" Content="{Binding ElementName=popup, Path=FirstOptionText}">
                 <Button.CommandParameter>
                     <system:Boolean>True</system:Boolean>
                 </Button.CommandParameter>
             </Button>
-            <Button Width="70"
+            <Button MinWidth="70" Padding="5 0"
                     Command="{Binding Path=DataContext.SetResultAndCloseCommand, ElementName=popup}"
-                    Style="{StaticResource DarkRoundButton}" Content="No">
+                    Style="{StaticResource DarkRoundButton}" Content="{Binding ElementName=popup, Path=SecondOptionText}">
                 <Button.CommandParameter>
                     <system:Boolean>False</system:Boolean>
                 </Button.CommandParameter>

+ 18 - 0
src/PixiEditor/Views/Dialogs/ConfirmationPopup.xaml.cs

@@ -15,6 +15,24 @@ internal partial class ConfirmationPopup : Window
     public static readonly DependencyProperty BodyProperty =
         DependencyProperty.Register(nameof(Body), typeof(string), typeof(ConfirmationPopup), new PropertyMetadata(""));
 
+    public static readonly DependencyProperty FirstOptionTextProperty = DependencyProperty.Register(
+        nameof(FirstOptionText), typeof(string), typeof(ConfirmationPopup), new PropertyMetadata("Yes"));
+
+    public string FirstOptionText
+    {
+        get { return (string)GetValue(FirstOptionTextProperty); }
+        set { SetValue(FirstOptionTextProperty, value); }
+    }
+
+    public static readonly DependencyProperty SecondOptionTextProperty = DependencyProperty.Register(
+        nameof(SecondOptionText), typeof(string), typeof(ConfirmationPopup), new PropertyMetadata("No"));
+
+    public string SecondOptionText
+    {
+        get { return (string)GetValue(SecondOptionTextProperty); }
+        set { SetValue(SecondOptionTextProperty, value); }
+    }
+    
     public ConfirmationPopup()
     {
         InitializeComponent();

+ 1 - 0
src/PixiEditor/Views/Dialogs/ImportShortcutTemplatePopup.xaml

@@ -9,6 +9,7 @@
         xmlns:userControls="clr-namespace:PixiEditor.Views.UserControls"
         mc:Ignorable="d"
         Title="Import from template" Foreground="White"
+        WindowStartupLocation="CenterOwner"
         MinWidth="580"
         SizeToContent="WidthAndHeight" WindowStyle="None"
         Background="{StaticResource AccentColor}"

+ 33 - 8
src/PixiEditor/Views/Dialogs/ImportShortcutTemplatePopup.xaml.cs

@@ -1,7 +1,5 @@
-using System.IO;
-using System.Windows;
+using System.Windows;
 using System.Windows.Input;
-using Microsoft.Win32;
 using PixiEditor.Models.Commands;
 using PixiEditor.Models.Commands.Attributes.Commands;
 using PixiEditor.Models.Commands.Templates;
@@ -77,19 +75,46 @@ internal partial class ImportShortcutTemplatePopup : Window
     {
         ShortcutsTemplateCard card = (ShortcutsTemplateCard)sender;
         ShortcutProvider provider = card.DataContext as ShortcutProvider;
-        
-        ImportFromProvider(provider);
+
+        if (ImportFromProvider(provider))
+        {
+            Close();
+        }
     }
 
-    private void ImportFromProvider(ShortcutProvider provider)
+    /// <summary>
+    ///     Imports shortcuts from a provider. If provider has installation available, then user will be asked to choose between installation and defaults.
+    /// </summary>
+    /// <param name="provider">Shortcut provider.</param>
+    /// <returns>True if imported shortcuts.</returns>
+    private bool ImportFromProvider(ShortcutProvider provider)
     {
         if (provider.ProvidesFromInstallation && provider.HasInstallationPresent)
         {
-            ImportInstallation(provider);
+            var result = OptionDialog.Show(
+                $"We've detected, that you have {provider.Name} installed. Do you want to import shortcuts from it?",
+                "Import from installation",
+                "Import from installation",
+                "Use defaults");
+
+            if (result == OptionResult.Option1)
+            {
+                ImportInstallation(provider);
+            }
+            else if (result == OptionResult.Option2)
+            {
+                ImportDefaults(provider);
+            }
+            
+            return result != OptionResult.Canceled;
         }
-        else if (provider.HasDefaultShortcuts)
+        
+        if (provider.HasDefaultShortcuts)
         {
             ImportDefaults(provider);
+            return true;
         }
+        
+        return false;
     }
 }

+ 1 - 1
src/PixiEditor/Views/Dialogs/SettingsWindow.xaml

@@ -205,7 +205,7 @@
                     <Button Command="{cmds:Command PixiEditor.Shortcuts.Import}"
                             Content="Import"/>
                     <Button Command="{cmds:Command PixiEditor.Shortcuts.OpenTemplatePopup}"
-                            Content="Import from..."/>
+                            Content="Shortcut Templates"/>
                     <Button Command="{cmds:Command PixiEditor.Shortcuts.Reset}"
                             Content="Reset all"/>
                 </StackPanel>