소스 검색

Merge pull request #345 from PixiEditor/ui-fixes

UI Fixes
Krzysztof Krysiński 3 년 전
부모
커밋
4bbc30694b

+ 4 - 4
PixiEditor/ViewModels/SubViewModels/Main/DiscordViewModel.cs

@@ -1,8 +1,8 @@
-using System;
-using DiscordRPC;
+using DiscordRPC;
 using PixiEditor.Helpers.Extensions;
 using PixiEditor.Models.DataHolders;
 using PixiEditor.Models.UserPreferences;
+using System;
 
 namespace PixiEditor.ViewModels.SubViewModels.Main
 {
@@ -158,7 +158,7 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
                 Assets = new Assets
                 {
                     LargeImageKey = "editorlogo",
-                    LargeImageText = "You discovered PixiEditor's logo",
+                    LargeImageText = "You've discovered PixiEditor's logo",
                     SmallImageKey = "github",
                     SmallImageText = "Download PixiEditor on GitHub (github.com/PixiEditor/PixiEditor)!"
                 },
@@ -210,4 +210,4 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
             Enabled = false;
         }
     }
-}
+}

+ 64 - 26
PixiEditor/ViewModels/SubViewModels/Main/LayersViewModel.cs

@@ -1,7 +1,6 @@
 using PixiEditor.Helpers;
 using PixiEditor.Models.Controllers;
 using PixiEditor.Models.Layers;
-using PixiEditor.Models.Undo;
 using PixiEditor.Views.UserControls.Layers;
 using System;
 using System.Linq;
@@ -48,7 +47,7 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
             NewLayerCommand = new RelayCommand(NewLayer, CanCreateNewLayer);
             NewGroupCommand = new RelayCommand(NewGroup, CanCreateNewLayer);
             CreateGroupFromActiveLayersCommand = new RelayCommand(CreateGroupFromActiveLayers, CanCreateGroupFromSelected);
-            DeleteLayersCommand = new RelayCommand(DeleteLayer, CanDeleteLayer);
+            DeleteLayersCommand = new RelayCommand(DeleteActiveLayers, CanDeleteActiveLayers);
             DuplicateLayerCommand = new RelayCommand(DuplicateLayer, CanDuplicateLayer);
             MoveToBackCommand = new RelayCommand(MoveLayerToBack, CanMoveToBack);
             MoveToFrontCommand = new RelayCommand(MoveLayerToFront, CanMoveToFront);
@@ -57,7 +56,7 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
             MergeWithAboveCommand = new RelayCommand(MergeWithAbove, CanMergeWithAbove);
             MergeWithBelowCommand = new RelayCommand(MergeWithBelow, CanMergeWithBelow);
             RenameGroupCommand = new RelayCommand(RenameGroup);
-            DeleteGroupCommand = new RelayCommand(DeleteGroup);
+            DeleteGroupCommand = new RelayCommand(DeleteGroup, CanDeleteGroup);
             DeleteSelectedCommand = new RelayCommand(DeleteSelected, CanDeleteSelected);
             Owner.BitmapManager.DocumentChanged += BitmapManager_DocumentChanged;
         }
@@ -73,22 +72,37 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
 
         public bool CanDeleteSelected(object parameter)
         {
-            return (
-                (
-                    parameter is not null and (Layer or LayerGroup)) || (Owner.BitmapManager?.ActiveDocument?.ActiveLayer != null)
-                )
-                && Owner.BitmapManager.ActiveDocument != null;
+            bool paramIsLayerOrGroup = parameter is not null and (Layer or LayerGroup);
+            bool activeLayerExists = Owner.BitmapManager?.ActiveDocument?.ActiveLayer != null;
+            bool activeDocumentExists = Owner.BitmapManager.ActiveDocument != null;
+            bool allGood = (paramIsLayerOrGroup || activeLayerExists) && activeDocumentExists;
+            if (!allGood)
+                return false;
+
+            if (parameter is Layer or LayerStructureItemContainer)
+            {
+                return CanDeleteActiveLayers(null);
+            }
+            else if (parameter is LayerGroup group)
+            {
+                return CanDeleteGroup(group.GuidValue);
+            }
+            else if (parameter is LayerGroupControl groupControl)
+            {
+                return CanDeleteGroup(groupControl.GroupGuid);
+            }
+            else if (Owner.BitmapManager.ActiveDocument.ActiveLayer != null)
+            {
+                return CanDeleteActiveLayers(null);
+            }
+            return false;
         }
 
         public void DeleteSelected(object parameter)
         {
-            if (parameter is Layer layer)
-            {
-                DeleteLayer(Owner.BitmapManager.ActiveDocument.Layers.IndexOf(layer));
-            }
-            else if (parameter is LayerStructureItemContainer container)
+            if (parameter is Layer or LayerStructureItemContainer)
             {
-                DeleteLayer(Owner.BitmapManager.ActiveDocument.Layers.IndexOf(container.Layer));
+                DeleteActiveLayers(null);
             }
             else if (parameter is LayerGroup group)
             {
@@ -100,14 +114,35 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
             }
             else if (Owner.BitmapManager.ActiveDocument.ActiveLayer != null)
             {
-                DeleteLayer(Owner.BitmapManager.ActiveDocument.Layers.IndexOf(Owner.BitmapManager.ActiveDocument.ActiveLayer));
+                DeleteActiveLayers(null);
             }
         }
 
+        public bool CanDeleteGroup(object parameter)
+        {
+            if (parameter is not Guid guid)
+                return false;
+
+            var document = Owner.BitmapManager.ActiveDocument;
+            if (document == null)
+                return false;
+
+            var group = document.LayerStructure.GetGroupByGuid(guid);
+            if (group == null)
+                return false;
+
+            return document.LayerStructure.GetGroupLayers(group).Count < document.Layers.Count;
+        }
+
         public void DeleteGroup(object parameter)
         {
             if (parameter is Guid guid)
             {
+                foreach (var layer in Owner.BitmapManager.ActiveDocument?.Layers)
+                {
+                    layer.IsActive = false;
+                }
+
                 var group = Owner.BitmapManager.ActiveDocument?.LayerStructure.GetGroupByGuid(guid);
                 var layers = Owner.BitmapManager.ActiveDocument?.LayerStructure.GetGroupLayers(group);
                 foreach (var layer in layers)
@@ -224,15 +259,18 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
             }
         }
 
-        public void DeleteLayer(object parameter)
+        public void DeleteActiveLayers(object unusedParameter)
         {
             var doc = Owner.BitmapManager.ActiveDocument;
             doc.RemoveActiveLayers();
         }
 
-        public bool CanDeleteLayer(object property)
+        public bool CanDeleteActiveLayers(object unusedParam)
         {
-            return Owner.BitmapManager.ActiveDocument != null && Owner.BitmapManager.ActiveDocument.Layers.Count > 1;
+            if (Owner.BitmapManager.ActiveDocument == null)
+                return false;
+            int activeLayerCount = Owner.BitmapManager.ActiveDocument.Layers.Where(layer => layer.IsActive).Count();
+            return Owner.BitmapManager.ActiveDocument.Layers.Count > activeLayerCount;
         }
 
         public void DuplicateLayer(object parameter)
@@ -247,17 +285,17 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
 
         public void RenameLayer(object parameter)
         {
-          if (Owner.BitmapManager.ActiveDocument == null)
-            return;
+            if (Owner.BitmapManager.ActiveDocument == null)
+                return;
 
-          int? index = (int?)parameter;
+            int? index = (int?)parameter;
 
-          if (index == null)
-          {
-            index = Owner.BitmapManager.ActiveDocument.Layers.IndexOf(Owner.BitmapManager.ActiveDocument.ActiveLayer);
-          }
+            if (index == null)
+            {
+                index = Owner.BitmapManager.ActiveDocument.Layers.IndexOf(Owner.BitmapManager.ActiveDocument.ActiveLayer);
+            }
 
-          Owner.BitmapManager.ActiveDocument.Layers[(int)index].IsRenaming = true;
+            Owner.BitmapManager.ActiveDocument.Layers[(int)index].IsRenaming = true;
         }
 
         public bool CanRenameLayer(object parameter)

+ 4 - 3
PixiEditor/Views/Dialogs/CrashReportDialog.xaml

@@ -9,8 +9,9 @@
         mc:Ignorable="d"
         Background="{StaticResource AccentColor}" Foreground="White"
         Title="PixiEditor has crashed!" WindowStyle="None"
-        MinWidth="450" MinHeight="195"
-        Width="480" Height="180">
+        MinWidth="480" MinHeight="195"
+        WindowStartupLocation="CenterScreen"
+        Width="480" Height="195">
 
     <WindowChrome.WindowChrome>
         <WindowChrome CaptionHeight="32" GlassFrameThickness="0.1"
@@ -34,7 +35,7 @@
                     <StackPanel Margin="7" VerticalAlignment="Center">
                         <TextBlock Text="{Binding DocumentCount, StringFormat={}{0} file(s) can be recovered}"
                        d:Text="2 file(s) can be recovered"/>
-                        <TextBlock TextWrapping="Wrap">You can help the developers fixing this bug by sending a crash report that was generated</TextBlock>
+                        <TextBlock TextWrapping="Wrap">You can help the developers fix this bug by sending a crash report that was generated (you will still be able to recover the files).</TextBlock>
                     </StackPanel>
                 </Grid>
 

+ 1 - 1
PixiEditor/Views/Dialogs/DialogTitleBar.xaml

@@ -19,7 +19,7 @@
             FontSize="15" 
             Margin="5,0,0,0" 
             Grid.Column="0" Grid.ColumnSpan="2"/>
-        <Button Grid.Column="1" HorizontalAlignment="Right" Style="{StaticResource CloseButtonStyle}"
+        <Button Grid.Column="1" HorizontalAlignment="Right" Style="{StaticResource CloseButtonStyle}" IsCancel="True"
                     WindowChrome.IsHitTestVisibleInChrome="True" ToolTip="Close"
                     Command="{Binding ElementName=uc, Path=CloseCommand}" />
     </Grid>

+ 5 - 3
PixiEditor/Views/Dialogs/SendCrashReportWindow.xaml

@@ -8,7 +8,9 @@
         Background="{StaticResource AccentColor}" Foreground="White"
         Title="Send crash report"
         WindowStyle="None"
-        Height="170" Width="340">
+        WindowStartupLocation="CenterScreen"
+        MinHeight="195" MinWidth="340"
+        Height="195" Width="340">
     <Window.Resources>
         <Style TargetType="TextBlock">
             <Setter Property="HorizontalAlignment" Value="Center"/>
@@ -36,13 +38,13 @@
             <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
                 <Button Width="140" Click="OpenInExplorer">Open in Explorer</Button>
             </StackPanel>
-            <TextBlock TextAlignment="Center">You can report your crash report here:</TextBlock>
+            <TextBlock TextAlignment="Center">You can send your crash report using:</TextBlock>
             <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
                 <Button Click="OpenHyperlink" Tag="github">GitHub</Button>
                 <Button Click="OpenHyperlink" Tag="discord">Discord</Button>
                 <Button Click="OpenHyperlink" Tag="email">E-Mail</Button>
             </StackPanel>
-            <TextBlock TextWrapping="Wrap" FontSize="8">The report might contain the doucments that were opened when the crash happened</TextBlock>
+            <TextBlock TextWrapping="Wrap" TextAlignment="Center">The report contains the documents that were opened when the crash happened, feel free to review it before sending.</TextBlock>
         </StackPanel>
     </StackPanel>
 </Window>

+ 5 - 6
PixiEditor/Views/UserControls/SizeInput.xaml.cs

@@ -1,5 +1,4 @@
 using PixiEditor.Models.Enums;
-using System;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Input;
@@ -50,7 +49,7 @@ namespace PixiEditor.Views
             get => (bool)GetValue(BehaveLikeSmallEmbeddedFieldProperty);
             set => SetValue(BehaveLikeSmallEmbeddedFieldProperty, value);
         }
-                
+
         public void FocusAndSelect()
         {
             textBox.Focus();
@@ -59,8 +58,6 @@ namespace PixiEditor.Views
 
         private void Border_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
         {
-            if (!textBox.IsFocused)
-                textBox.Focus();
             Point pos = Mouse.GetPosition(textBox);
             int charIndex = textBox.GetCharacterIndexFromPoint(pos, true);
             var charRect = textBox.GetRectFromCharacterIndex(charIndex);
@@ -70,12 +67,14 @@ namespace PixiEditor.Views
             else
                 textBox.CaretIndex = charIndex;
             e.Handled = true;
+            if (!textBox.IsFocused)
+                textBox.Focus();
         }
 
         public SizeUnit Unit
         {
-          get => (SizeUnit)GetValue(UnitProperty);
-          set => SetValue(UnitProperty, value);
+            get => (SizeUnit)GetValue(UnitProperty);
+            set => SetValue(UnitProperty, value);
         }
 
         private static void InputSizeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)

+ 1 - 1
PixiEditor/Views/UserControls/SizePicker.xaml.cs

@@ -90,7 +90,7 @@ namespace PixiEditor.Views
 
         public void FocusWidthPicker()
         {
-            PercentageSizePicker.FocusAndSelect();
+            WidthPicker.FocusAndSelect();
         }
 
         private void AfterLoaded(object parameter)

+ 3 - 2
PixiEditor/Views/UserControls/SmallColorPicker.xaml

@@ -38,10 +38,11 @@
                 <RowDefinition Height="25"/>
             </Grid.RowDefinitions>
             <colorpicker:SquarePicker Grid.ColumnSpan="2" Grid.RowSpan="2" Margin="3"
-                                ColorState="{Binding ColorState, Mode=TwoWay, ElementName=uc}"
+                                x:Name="mainPicker"
+                                ColorState="{Binding ColorState, Mode=TwoWay, ElementName=uc, Delay=50}"
                                 PickerType="{Binding ElementName=colorSpaceComboBox, Path=SelectedIndex, Converter={conv:IntToPickerTypeConverter}}"/>
             <colorpicker:ColorDisplay Grid.Row="1" Grid.RowSpan="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="3,0,0,0"
-                                ColorState="{Binding ColorState, Mode=TwoWay, ElementName=uc}" 
+                                ColorState="{Binding ColorState, Mode=TwoWay, ElementName=mainPicker}" 
                                 SecondColorState="{Binding SecondColorState, Mode=TwoWay, ElementName=uc}"/>
             <ComboBox Grid.Row="1" Grid.RowSpan="2" Grid.Column="2" Width="50" Height="20" HorizontalAlignment="Right" 
                 VerticalAlignment="Bottom" x:Name="colorSpaceComboBox" Margin="0,0,80,0">