Ver código fonte

Improved CommandDebugPopup

CPKreuz 2 anos atrás
pai
commit
20487f5c3e

+ 30 - 23
src/PixiEditor/Models/Commands/Evaluators/IconEvaluator.cs

@@ -14,39 +14,46 @@ internal class IconEvaluator : Evaluator<ImageSource>
     public override ImageSource CallEvaluate(Command command, object parameter) =>
         base.CallEvaluate(command, parameter ?? command);
 
-    [DebuggerDisplay("IconEvaluator.Default")]
-    private class CommandNameEvaluator : IconEvaluator
+    public static string GetDefaultPath(Command command)
     {
-        public static string[] resources = GetResourceNames();
-
-        public static Dictionary<string, BitmapImage> images = new();
+        string path;
 
-        public override ImageSource CallEvaluate(Command command, object parameter)
+        if (command.IconPath != null)
         {
-            string path;
-
-            if (command.IconPath != null)
+            if (command.IconPath.StartsWith('@'))
             {
-                if (command.IconPath.StartsWith('@'))
-                {
-                    path = command.IconPath[1..];
-                }
-                else
-                {
-                    path = $"Images/{command.IconPath}";
-                }
+                path = command.IconPath[1..];
             }
             else
             {
-                path = $"Images/Commands/{command.InternalName.Replace('.', '/')}.png";
+                path = $"Images/{command.IconPath}";
             }
+        }
+        else
+        {
+            path = $"Images/Commands/{command.InternalName.Replace('.', '/')}.png";
+        }
 
-            path = path.ToLower();
+        path = path.ToLower();
 
-            if (path.StartsWith("/"))
-            {
-                path = path[1..];
-            }
+        if (path.StartsWith("/"))
+        {
+            path = path[1..];
+        }
+
+        return path;
+    }
+
+    [DebuggerDisplay("IconEvaluator.Default")]
+    private class CommandNameEvaluator : IconEvaluator
+    {
+        public static string[] resources = GetResourceNames();
+
+        public static Dictionary<string, BitmapImage> images = new();
+
+        public override ImageSource CallEvaluate(Command command, object parameter)
+        {
+            string path = GetDefaultPath(command);
 
             if (resources.Contains(path))
             {

+ 5 - 1
src/PixiEditor/Views/Dialogs/CommandDebugPopup.xaml

@@ -7,7 +7,7 @@
         xmlns:b="http://schemas.microsoft.com/xaml/behaviors"
         xmlns:behaviours="clr-namespace:PixiEditor.Helpers.Behaviours"
         xmlns:command="clr-namespace:PixiEditor.Models.Commands"
-        xmlns:cmds="clr-namespace:PixiEditor.Models.Commands.Commands" xmlns:usercontrols="clr-namespace:PixiEditor.Views.UserControls" xmlns:converters="clr-namespace:PixiEditor.Helpers.Converters"
+        xmlns:cmds="clr-namespace:PixiEditor.Models.Commands.XAML" xmlns:usercontrols="clr-namespace:PixiEditor.Views.UserControls" xmlns:converters="clr-namespace:PixiEditor.Helpers.Converters"
         WindowStyle="None"
         mc:Ignorable="d"
         x:Name="uc"
@@ -32,6 +32,10 @@
                 <RowDefinition />
             </Grid.RowDefinitions>
 
+            <StackPanel Orientation="Horizontal" Margin="5">
+                <Button Content="Export list" Style="{StaticResource DarkRoundButton}" Command="{cmds:Command PixiEditor.Debug.DumpAllCommands}" Width="100"/>
+            </StackPanel>
+
             <ScrollViewer VerticalScrollBarVisibility="Auto" Grid.Row="1">
                 <ItemsControl ItemsSource="{Binding Commands, ElementName=uc}" Margin="5,0,0,5">
                     <ItemsControl.ItemTemplate>

+ 25 - 15
src/PixiEditor/Views/Dialogs/CommandDebugPopup.xaml.cs

@@ -33,53 +33,61 @@ public partial class CommandDebugPopup : Window
 
         foreach (var command in CommandController.Current.Commands)
         {
-            var comments = new TextBlock();
+            var comments = new TextBlock() { TextWrapping = TextWrapping.Wrap };
 
             var image = command.IconEvaluator.CallEvaluate(command, null);
+            var analysis = AnalyzeCommand(command, image, out int issues);
 
-            foreach (var inline in AnalyzeCommand(command, image))
+            foreach (var inline in analysis)
             {
                 comments.Inlines.Add(inline);
             }
 
-            debugCommands.Add(new CommandDebug(command, comments, image));
+            debugCommands.Add(new CommandDebug(command, comments, image, issues));
         }
 
-        Commands = debugCommands;
+        Commands = debugCommands.OrderByDescending(x => x.Issues).ThenBy(x => x.Command.InternalName).ToArray();
 
         InitializeComponent();
-        //ItemsControl.ItemsSource = CommandController.Current.Commands;
     }
 
-    private IEnumerable<Inline> AnalyzeCommand(Command command, ImageSource image)
+    private List<Inline> AnalyzeCommand(Command command, ImageSource image, out int issues)
     {
+        var inlines = new List<Inline>();
+        issues = 0;
+
         if (image == null && command.IconEvaluator == IconEvaluator.Default)
         {
+            var expected = IconEvaluator.GetDefaultPath(command);
+
             if (string.IsNullOrWhiteSpace(command.IconPath))
             {
-                yield return Info("Default evaluator has not found a image (No icon path provided)");
+                Info($"Default evaluator has not found a image (No icon path provided). Expected at '{expected}'\n");
             }
             else
             {
-                yield return Error("Default evaluator has not found a image at icon path!");
+                Error($"Default evaluator has not found a image at icon path! Expected at '{expected}'.\n");
+                issues++;
             }
         }
 
         if (command.IconEvaluator != IconEvaluator.Default)
         {
-            yield return Info("Uses custom icon evaluator");
+            Info($"Uses custom icon evaluator ({command.IconEvaluator.GetType().Name})\n");
         }
 
         if (!string.IsNullOrWhiteSpace(command.IconPath))
         {
-            yield return Info($"Has custom icon path: '{command.IconPath}'");
+            Info($"Has custom icon path: '{command.IconPath}'\n");
         }
 
-        Run Info(string text) => new Run(text) { Foreground = infoBrush };
+        return inlines;
+
+        void Info(string text) => inlines.Add(new Run(text) { Foreground = infoBrush });
 
-        Run Warning(string text) => new Run(text) { Foreground = warningBrush };
+        void Warning(string text) => inlines.Add(new Run(text) { Foreground = warningBrush });
 
-        Run Error(string text) => new Run(text) { Foreground = errorBrush };
+        void Error(string text) => inlines.Add(new Run(text) { Foreground = errorBrush });
     }
 
     internal class CommandDebug
@@ -90,12 +98,14 @@ public partial class CommandDebugPopup : Window
 
         public ImageSource Image { get; }
 
-        public CommandDebug(Command command, TextBlock comments, ImageSource image)
+        public int Issues { get; }
+
+        public CommandDebug(Command command, TextBlock comments, ImageSource image, int issues)
         {
             Command = command;
             Comments = comments;
             Image = image;
+            Issues = issues;
         }
     }
 }
-

+ 5 - 1
src/PixiEditor/Views/MainWindow.xaml

@@ -323,6 +323,10 @@
                     <MenuItem
                         Header="_Debug"
                         Visibility="{Binding DebugSubViewModel.UseDebug, Converter={StaticResource BoolToVisibilityConverter}}">
+                        <MenuItem
+                            Header="Open Command Debug Window"
+                            cmds:Menu.Command="PixiEditor.Debug.OpenCommandDebugWindow"/>
+                        <Separator/>
                         <MenuItem
                             Header="Open _Local App Data"
                             cmds:Menu.Command="PixiEditor.Debug.OpenLocalAppDataDirectory" />
@@ -336,7 +340,7 @@
                             Header="Open _Install Location"
                             cmds:Menu.Command="PixiEditor.Debug.OpenInstallDirectory" />
                         <MenuItem
-                            Header="Open Crash Reports Location"
+                            Header="Open Crash _Reports Location"
                             cmds:Menu.Command="PixiEditor.Debug.OpenCrashReportsDirectory" />
                         <Separator />
                         <MenuItem