flabbet преди 4 години
родител
ревизия
07995587df

+ 11 - 0
PixiEditor/Models/Layers/GuidStructureItem.cs

@@ -65,6 +65,17 @@ namespace PixiEditor.Models.Layers
             }
         }
 
+        private bool isRenaming = false;
+
+        public bool IsRenaming
+        {
+            get => isRenaming;
+            set
+            {
+                SetProperty(ref isRenaming, value);
+            }
+        }
+
         public GuidStructureItem(
             string name,
             Guid startLayerGuid,

+ 11 - 0
PixiEditor/Models/Layers/LayerGroup.cs

@@ -82,6 +82,17 @@ namespace PixiEditor.Models.Layers
             }
         }
 
+        private bool isRenaming;
+
+        public bool IsRenaming
+        {
+            get => isRenaming;
+            set
+            {
+                SetProperty(ref isRenaming, value);
+            }
+        }
+
         private void UpdateIsExpandedInDocument(bool value)
         {
             var folder = ViewModelMain.Current.BitmapManager.ActiveDocument.LayerStructure.GetGroupByGuid(GroupGuid);

+ 0 - 1
PixiEditor/Models/Layers/LayerStructure.cs

@@ -173,7 +173,6 @@ namespace PixiEditor.Models.Layers
 
                 if (group.StartLayerGuid != null && group.EndLayerGuid != null)
                 {
-
                     int folderTopIndex = Owner.Layers.IndexOf(Owner.Layers.First(x => x.LayerGuid == group.EndLayerGuid));
                     int folderBottomIndex = Owner.Layers.IndexOf(Owner.Layers.First(x => x.LayerGuid == group.StartLayerGuid));
 

+ 2 - 1
PixiEditor/Models/Layers/StructuredLayerTree.cs

@@ -140,7 +140,8 @@ namespace PixiEditor.Models.Layers
             LayerGroup folder = new (structureItemLayers, subFolders, structureItem.Name,
                 structureItem.GroupGuid, displayIndex, displayIndex + structureItemLayers.Count - 1, structureItem)
             {
-                IsExpanded = structureItem.IsExpanded
+                IsExpanded = structureItem.IsExpanded,
+                IsRenaming = structureItem.IsRenaming
             };
             return folder;
         }

+ 12 - 0
PixiEditor/ViewModels/SubViewModels/Main/LayersViewModel.cs

@@ -20,6 +20,8 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
 
         public RelayCommand RenameLayerCommand { get; set; }
 
+        public RelayCommand RenameGroupCommand { get; set; }
+
         public RelayCommand MoveToBackCommand { get; set; }
 
         public RelayCommand MoveToFrontCommand { get; set; }
@@ -43,9 +45,19 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
             MergeSelectedCommand = new RelayCommand(MergeSelected, CanMergeSelected);
             MergeWithAboveCommand = new RelayCommand(MergeWithAbove, CanMergeWithAbove);
             MergeWithBelowCommand = new RelayCommand(MergeWithBelow, CanMergeWithBelow);
+            RenameGroupCommand = new RelayCommand(RenameGroup);
             Owner.BitmapManager.DocumentChanged += BitmapManager_DocumentChanged;
         }
 
+        public void RenameGroup(object parameter)
+        {
+            if (parameter is Guid guid)
+            {
+                var group = Owner.BitmapManager.ActiveDocument?.LayerStructure.GetGroupByGuid(guid);
+                group.IsRenaming = true;
+            }
+        }
+
         public void NewGroup(object parameter)
         {
             Owner.BitmapManager.ActiveDocument?.LayerStructure.AddNewGroup($"{Owner.BitmapManager.ActiveLayer.Name} Group", Owner.BitmapManager.ActiveLayer.LayerGuid);

+ 13 - 5
PixiEditor/Views/UserControls/LayerGroupControl.xaml

@@ -2,14 +2,14 @@
              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
-             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
-             xmlns:local="clr-namespace:PixiEditor.Views.UserControls" xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:behaviors="clr-namespace:PixiEditor.Helpers.Behaviours" xmlns:userControls="clr-namespace:PixiEditor.Views" xmlns:converters="clr-namespace:PixiEditor.Helpers.Converters"
+             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:behaviors="clr-namespace:PixiEditor.Helpers.Behaviours" xmlns:userControls="clr-namespace:PixiEditor.Views" xmlns:converters="clr-namespace:PixiEditor.Helpers.Converters"
              mc:Ignorable="d" Focusable="True"
              d:DesignHeight="60" d:DesignWidth="250" Name="groupControl">
     <UserControl.Resources>
         <converters:InverseBooleanConverter x:Key="InverseBooleanConverter"/>
     </UserControl.Resources>
-    <Border BorderThickness="0 0 0 0.5" BorderBrush="Gray" MinWidth="60" Focusable="True" >
+    <Border BorderThickness="0 0 0 0.5" BorderBrush="Gray" MinWidth="60" Focusable="True" Tag="{Binding ElementName=groupControl}">
         <i:Interaction.Behaviors>
             <behaviors:ClearFocusOnClickBehavior/>
         </i:Interaction.Behaviors>
@@ -29,13 +29,21 @@
                 <Image Source="/Images/Folder.png" Height="20"/>
                 <StackPanel Grid.Row="1" Orientation="Horizontal" Grid.Column="1" HorizontalAlignment="Left" Margin="5,0,0,0">
                     <userControls:EditableTextBlock
-                    IsEditing="False"
                     FontSize="16"
                     VerticalAlignment="Center"
-                    Text="{Binding GroupName, ElementName=groupControl, Mode=TwoWay}" />
+                    IsEditing="{Binding GroupData.IsRenaming, ElementName=groupControl, Mode=TwoWay}"
+                    Text="{Binding GroupData.Name, ElementName=groupControl, Mode=TwoWay}" />
                 </StackPanel>
             </Grid>
             <Grid DragEnter="Grid_DragEnter" Drop="Grid_Drop_Bottom"  DragLeave="Grid_DragLeave" Grid.Row="2" AllowDrop="{Binding  GroupData.IsExpanded, ElementName=groupControl, Converter={StaticResource InverseBooleanConverter}}" Grid.ColumnSpan="3" Background="Transparent"/>
         </Grid>
+        <Border.ContextMenu>
+            <ContextMenu>
+                <MenuItem Header="Rename"
+                                     Command="{Binding PlacementTarget.Tag.LayersViewModel.RenameGroupCommand, 
+                                            RelativeSource={RelativeSource AncestorType=ContextMenu}}" CommandParameter="{Binding PlacementTarget.Tag.GroupGuid, RelativeSource={RelativeSource AncestorType=ContextMenu}}">
+                </MenuItem>
+            </ContextMenu>
+        </Border.ContextMenu>
     </Border>
 </UserControl>