Browse Source

Implement debug mode settings, add a button that opens the crash reports directory

Equbuxu 3 years ago
parent
commit
6de8292a65

+ 13 - 0
PixiEditor/Styles/LabelStyles.xaml

@@ -13,6 +13,19 @@
         <Setter Property="FontWeight" Value="DemiBold"/>
     </Style>
 
+    <Style x:Key="SettingsLink" TargetType="Hyperlink" BasedOn="{StaticResource {x:Type Hyperlink}}">
+        <Setter Property="Foreground" Value="LightGray"/>
+        <Style.Triggers>
+            <Trigger Property="IsMouseOver" Value="True">
+                <Setter Property="Foreground" Value="White"/>
+                <Setter Property="TextDecorations" Value="Underline"/>
+            </Trigger>
+            <Trigger Property="IsMouseOver" Value="False">
+                <Setter Property="TextDecorations" Value="None"/>
+            </Trigger>
+        </Style.Triggers>
+    </Style>
+
     <Style x:Key="SettingsText" TargetType="Label" BasedOn="{StaticResource BaseLabel}">
         <Setter Property="FontSize" Value="12"/>
         <Setter Property="Padding" Value="0"/>

+ 12 - 2
PixiEditor/ViewModels/SubViewModels/Main/DebugViewModel.cs

@@ -15,7 +15,12 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
 
         public bool IsDebugModeEnabled { get; set; }
 
-        public bool UseDebug { get; set; }
+        private bool useDebug;
+        public bool UseDebug
+        {
+            get => useDebug;
+            set => SetProperty(ref useDebug, value);
+        }
 
         public DebugViewModel(ViewModelMain owner, IPreferences preferences)
             : base(owner)
@@ -28,6 +33,7 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
         [Command.Debug("PixiEditor.Debug.OpenTempDirectory", "%Temp%/PixiEditor", "Open Temp Directory", "Open Temp Directory")]
         [Command.Debug("PixiEditor.Debug.OpenLocalAppDataDirectory", "%LocalAppData%/PixiEditor", "Open Local AppData Directory", "Open Local AppData Directory")]
         [Command.Debug("PixiEditor.Debug.OpenRoamingAppDataDirectory", "%AppData%/PixiEditor", "Open Roaming AppData Directory", "Open Roaming AppData Directory")]
+        [Command.Debug("PixiEditor.Debug.OpenCrashReportsDirectory", "%LocalAppData%/PixiEditor/crash_logs", "Open Crash Reports Directory", "Open Crash Reports Directory")]
         public static void OpenFolder(string path)
         {
             ProcessHelpers.ShellExecuteEV(path);
@@ -66,6 +72,10 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
         [Conditional("DEBUG")]
         private void SetDebug() => IsDebugBuild = true;
 
-        private void UpdateDebugMode(bool setting) => UseDebug = IsDebugBuild || IsDebugModeEnabled;
+        private void UpdateDebugMode(bool setting)
+        {
+            IsDebugModeEnabled = setting;
+            UseDebug = IsDebugBuild || IsDebugModeEnabled;
+        }
     }
 }

+ 8 - 7
PixiEditor/ViewModels/SubViewModels/UserPreferences/Settings/GeneralSettings.cs

@@ -1,10 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace PixiEditor.ViewModels.SubViewModels.UserPreferences.Settings
+namespace PixiEditor.ViewModels.SubViewModels.UserPreferences.Settings
 {
     public class GeneralSettings : SettingsGroup
     {
@@ -15,5 +9,12 @@ namespace PixiEditor.ViewModels.SubViewModels.UserPreferences.Settings
             get => imagePreviewInTaskbar;
             set => RaiseAndUpdatePreference(ref imagePreviewInTaskbar, value);
         }
+
+        private bool isDebugModeEnabled = GetPreference(nameof(IsDebugModeEnabled), false);
+        public bool IsDebugModeEnabled
+        {
+            get => isDebugModeEnabled;
+            set => RaiseAndUpdatePreference(ref isDebugModeEnabled, value);
+        }
     }
 }

+ 12 - 0
PixiEditor/Views/Dialogs/SettingsWindow.xaml

@@ -82,6 +82,9 @@
                     <RowDefinition Height="{Binding RelativeSource={RelativeSource AncestorType=Grid}, Path=Tag}"/>
                     <RowDefinition Height="{Binding RelativeSource={RelativeSource AncestorType=Grid}, Path=Tag}"/>
                     <RowDefinition Height="{Binding RelativeSource={RelativeSource AncestorType=Grid}, Path=Tag}"/>
+                    <RowDefinition Height="{Binding RelativeSource={RelativeSource AncestorType=Grid}, Path=Tag}"/>
+                    <RowDefinition Height="{Binding RelativeSource={RelativeSource AncestorType=Grid}, Path=Tag}"/>
+                    <RowDefinition Height="{Binding RelativeSource={RelativeSource AncestorType=Grid}, Path=Tag}"/>
                 </Grid.RowDefinitions>
 
                 <Label Grid.Row="0" Grid.ColumnSpan="2" Style="{StaticResource SettingsHeader}">Misc</Label>
@@ -127,6 +130,15 @@
                     Width="110" Height="22" HorizontalAlignment="Left"
                     ItemsSource="{Binding SettingsSubViewModel.Update.UpdateChannels}"
                     SelectedValue="{Binding SettingsSubViewModel.Update.UpdateChannelName}"/>
+
+                <Label Grid.Row="12" Grid.ColumnSpan="2" Style="{StaticResource SettingsHeader}">Debug</Label>
+                <CheckBox Grid.Row="13" Grid.Column="1" VerticalAlignment="Center"
+                    IsChecked="{Binding SettingsSubViewModel.General.IsDebugModeEnabled}">Enable Debug Mode</CheckBox>
+                <Label Grid.Row="14" Grid.Column="1" Style="{StaticResource SettingsText}" VerticalAlignment="Center">
+                    <Hyperlink Command="{cmds:Command PixiEditor.Debug.OpenCrashReportsDirectory}" Style="{StaticResource SettingsLink}">
+                        Open Crash Reports Directory
+                    </Hyperlink>
+                </Label>
             </Grid>
 
             <StackPanel Visibility="{Binding SelectedItem, ElementName=pages, Converter={converters:EqualityBoolToVisibilityConverter},

+ 4 - 1
PixiEditor/Views/MainWindow.xaml

@@ -318,6 +318,9 @@
                         <MenuItem
                             Header="Open _Install Location"
                             cmds:Menu.Command="PixiEditor.Debug.OpenInstallDirectory" />
+                        <MenuItem
+                            Header="Open Crash Reports Location"
+                            cmds:Menu.Command="PixiEditor.Debug.OpenCrashReportsDirectory" />
                         <Separator />
                         <MenuItem
                             Header="_Crash"
@@ -790,4 +793,4 @@
             Height="700"
             MaxWidth="920" />
     </Grid>
-</Window>
+</Window>

+ 4 - 0
PixiEditor/Views/UserControls/CommandSearch/CommandSearchControlHelper.cs

@@ -15,6 +15,10 @@ internal static class CommandSearchControlHelper
 {
     public static (List<SearchResult> results, List<string> warnings) ConstructSearchResults(string query)
     {
+        // avoid xaml designer error
+        if (ViewModelMain.Current is null)
+            return (new(), new());
+
         List<SearchResult> newResults = new();
         List<string> warnings = new();