Browse Source

Merge pull request #160 from PixiEditor/debuggerDisplays

Added Debugging Tools
Krzysztof Krysiński 4 years ago
parent
commit
43642b207c

+ 2 - 0
PixiEditor/Models/Controllers/BitmapManager.cs

@@ -1,6 +1,7 @@
 using System;
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
+using System.Diagnostics;
 using System.Linq;
 using System.Windows;
 using System.Windows.Input;
@@ -18,6 +19,7 @@ using PixiEditor.Models.Tools.ToolSettings.Settings;
 
 namespace PixiEditor.Models.Controllers
 {
+    [DebuggerDisplay("{Documents.Count} Document(s)")]
     public class BitmapManager : NotifyableObject
     {
         private Document activeDocument;

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

@@ -1,5 +1,6 @@
 using System;
 using System.Collections.Generic;
+using System.Diagnostics;
 using System.Linq;
 using System.Reflection;
 using PixiEditor.Models.Undo;
@@ -7,6 +8,7 @@ using PixiEditor.ViewModels;
 
 namespace PixiEditor.Models.Controllers
 {
+    [DebuggerDisplay("{UndoStack.Count} undo steps, {RedoStack.Count} redo step(s)")]
     public class UndoManager
     {
         private bool lastChangeWasUndo;

+ 2 - 0
PixiEditor/Models/DataHolders/Document/Document.cs

@@ -1,6 +1,7 @@
 using System;
 using System.Buffers;
 using System.Collections.ObjectModel;
+using System.Diagnostics;
 using System.IO;
 using System.Linq;
 using System.Threading;
@@ -20,6 +21,7 @@ using PixiEditor.ViewModels;
 
 namespace PixiEditor.Models.DataHolders
 {
+    [DebuggerDisplay("'{Name, nq}' {width}x{height} {Layers.Count} Layer(s)")]
     public partial class Document : NotifyableObject
     {
         private int height;

+ 2 - 0
PixiEditor/Models/Layers/Layer.cs

@@ -1,5 +1,6 @@
 using System;
 using System.Collections.Generic;
+using System.Diagnostics;
 using System.Linq;
 using System.Windows;
 using System.Windows.Media;
@@ -12,6 +13,7 @@ using PixiEditor.ViewModels;
 
 namespace PixiEditor.Models.Layers
 {
+    [DebuggerDisplay("'{name,nq}' {width}x{height}")]
     public class Layer : BasicLayer
     {
         private const int SizeOfArgb = 4;

+ 1 - 1
PixiEditor/Models/Tools/Tools/PenTool.cs

@@ -92,7 +92,7 @@ namespace PixiEditor.Models.Tools.Tools
                 return changes;
             }
 
-            changedPixelsindex += changedPixelsindex >= 2 ? 0 : 1;
+            changedPixelsindex += changedPixelsindex >= 2 ? (byte)0 : (byte)1;
 
             var result = BitmapPixelChanges.FromSingleColoredArray(GetThickShape(latestPixels, toolSize), color);
 

+ 2 - 0
PixiEditor/Models/UserPreferences/PreferencesSettings.cs

@@ -1,11 +1,13 @@
 using System;
 using System.Collections.Generic;
+using System.Diagnostics;
 using System.IO;
 using Newtonsoft.Json;
 using PixiEditor.ViewModels;
 
 namespace PixiEditor.Models.UserPreferences
 {
+    [DebuggerDisplay("{Preferences.Count + LocalPreferences.Count} Preference(s)")]
     public class PreferencesSettings : IPreferences
     {
         public static IPreferences Current => ViewModelMain.Current.Preferences;

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

@@ -0,0 +1,13 @@
+using System.Diagnostics;
+using PixiEditor.Helpers;
+
+namespace PixiEditor.ViewModels.SubViewModels.Main
+{
+    public class DebugViewModel : SubViewModel<ViewModelMain>
+    {
+        public DebugViewModel(ViewModelMain owner)
+            : base(owner)
+        {
+        }
+    }
+}

+ 18 - 1
PixiEditor/ViewModels/ViewModelMain.cs

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

+ 3 - 0
PixiEditor/Views/MainWindow.xaml

@@ -143,6 +143,9 @@
                     <MenuItem Header="Third Party Licenses" Command="{Binding MiscSubViewModel.OpenHyperlinkCommand}"
                               CommandParameter="https://github.com/PixiEditor/PixiEditor/wiki/Third-party-licenses"/>
                 </MenuItem>
+                <MenuItem Header="_Debug" Visibility="{Binding IsDebug, Converter={StaticResource BoolToVisibilityConverter}}">
+                    <MenuItem Header="Such empty here..." IsEnabled="False"/>
+                </MenuItem>
             </Menu>
             <StackPanel DockPanel.Dock="Right" VerticalAlignment="Top" Orientation="Horizontal"
                         HorizontalAlignment="Right" WindowChrome.IsHitTestVisibleInChrome="True">