Browse Source

Added Debug Menu

CPKreuz 4 years ago
parent
commit
7ba9143264

+ 23 - 0
PixiEditor/ViewModels/SubViewModels/Main/DebugViewModel.cs

@@ -0,0 +1,23 @@
+using System.Diagnostics;
+using PixiEditor.Helpers;
+
+namespace PixiEditor.ViewModels.SubViewModels.Main
+{
+    public class DebugViewModel : SubViewModel<ViewModelMain>
+    {
+        public RelayCommand BreakCommand { get; set; }
+
+        public DebugViewModel(ViewModelMain owner)
+            : base(owner)
+        {
+            BreakCommand = new RelayCommand(Break, CanBreak);
+        }
+
+        public static void Break(object parameter)
+        {
+            Debugger.Break();
+        }
+
+        public static bool CanBreak(object parameter) => Debugger.IsAttached;
+    }
+}

+ 23 - 1
PixiEditor/ViewModels/ViewModelMain.cs

@@ -59,6 +59,10 @@ namespace PixiEditor.ViewModels
 
 
         public DiscordViewModel DiscordViewModel { get; set; }
         public DiscordViewModel DiscordViewModel { get; set; }
 
 
+#if DEBUG
+        public DebugViewModel DebugSubViewModel { get; set; }
+#endif
+
         public BitmapManager BitmapManager { get; set; }
         public BitmapManager BitmapManager { get; set; }
 
 
         public PixelChangesController ChangesController { get; set; }
         public PixelChangesController ChangesController { get; set; }
@@ -67,6 +71,16 @@ namespace PixiEditor.ViewModels
 
 
         public IPreferences Preferences { get; set; }
         public IPreferences Preferences { get; set; }
 
 
+        public bool IsDebug
+        {
+            get =>
+#if DEBUG
+                true;
+#else
+                false;
+#endif
+        }
+
         public ViewModelMain(IServiceProvider services)
         public ViewModelMain(IServiceProvider services)
         {
         {
             Current = this;
             Current = this;
@@ -98,6 +112,9 @@ namespace PixiEditor.ViewModels
             DocumentSubViewModel = new DocumentViewModel(this);
             DocumentSubViewModel = new DocumentViewModel(this);
             MiscSubViewModel = new MiscViewModel(this);
             MiscSubViewModel = new MiscViewModel(this);
             DiscordViewModel = new DiscordViewModel(this, "764168193685979138");
             DiscordViewModel = new DiscordViewModel(this, "764168193685979138");
+#if DEBUG
+            DebugSubViewModel = new DebugViewModel(this);
+#endif
 
 
             ShortcutController = new ShortcutController
             ShortcutController = new ShortcutController
             {
             {
@@ -147,7 +164,12 @@ namespace PixiEditor.ViewModels
                     new Shortcut(Key.F2, LayersSubViewModel.RenameLayerCommand, BitmapManager.ActiveDocument?.ActiveLayerIndex),
                     new Shortcut(Key.F2, LayersSubViewModel.RenameLayerCommand, BitmapManager.ActiveDocument?.ActiveLayerIndex),
 
 
                     // View
                     // View
-                    new Shortcut(Key.OemTilde, ViewportSubViewModel.ToggleGridLinesCommand, modifier: ModifierKeys.Control)
+                    new Shortcut(Key.OemTilde, ViewportSubViewModel.ToggleGridLinesCommand, modifier: ModifierKeys.Control),
+
+#if DEBUG
+                    // Debug
+                    new Shortcut(Key.End, DebugSubViewModel.BreakCommand, modifier: ModifierKeys.Shift | ModifierKeys.Alt)
+#endif
                 }
                 }
             };
             };
             BitmapManager.PrimaryColor = ColorsSubViewModel.PrimaryColor;
             BitmapManager.PrimaryColor = ColorsSubViewModel.PrimaryColor;

+ 4 - 0
PixiEditor/Views/MainWindow.xaml

@@ -143,6 +143,10 @@
                     <MenuItem Header="Third Party Licenses" Command="{Binding MiscSubViewModel.OpenHyperlinkCommand}"
                     <MenuItem Header="Third Party Licenses" Command="{Binding MiscSubViewModel.OpenHyperlinkCommand}"
                               CommandParameter="https://github.com/PixiEditor/PixiEditor/wiki/Third-party-licenses"/>
                               CommandParameter="https://github.com/PixiEditor/PixiEditor/wiki/Third-party-licenses"/>
                 </MenuItem>
                 </MenuItem>
+                <MenuItem Header="_Debug" Visibility="{Binding IsDebug, Converter={StaticResource BoolToVisibilityConverter}}">
+                    <MenuItem Header="Break" Command="{Binding DebugSubViewModel.BreakCommand}"
+                              InputGestureText="Shift+Alt+End"/>
+                </MenuItem>
             </Menu>
             </Menu>
             <StackPanel DockPanel.Dock="Right" VerticalAlignment="Top" Orientation="Horizontal"
             <StackPanel DockPanel.Dock="Right" VerticalAlignment="Top" Orientation="Horizontal"
                         HorizontalAlignment="Right" WindowChrome.IsHitTestVisibleInChrome="True">
                         HorizontalAlignment="Right" WindowChrome.IsHitTestVisibleInChrome="True">