Browse Source

Added rename via context menu

Frytek 5 years ago
parent
commit
1a4e466164

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

@@ -41,6 +41,19 @@ namespace PixiEditor.Models.Layers
             }
             }
         }
         }
 
 
+        private bool _isRenaming = false;
+
+        public bool IsRenaming
+        {
+            get { return _isRenaming; }
+            set
+            {
+                _isRenaming = value;
+                RaisePropertyChanged("IsRenaming");
+            }
+        }
+
+
         public WriteableBitmap LayerBitmap
         public WriteableBitmap LayerBitmap
         {
         {
             get => _layerBitmap;
             get => _layerBitmap;

+ 7 - 0
PixiEditor/ViewModels/ViewModelMain.cs

@@ -35,6 +35,7 @@ namespace PixiEditor.ViewModels
         public RelayCommand NewLayerCommand { get; set; }
         public RelayCommand NewLayerCommand { get; set; }
         public RelayCommand ReloadImageCommand { get; set; }
         public RelayCommand ReloadImageCommand { get; set; }
         public RelayCommand DeleteLayerCommand { get; set; }
         public RelayCommand DeleteLayerCommand { get; set; }
+        public RelayCommand RenameLayerCommand { get; set; }
         public RelayCommand MoveToBackCommand { get; set; }
         public RelayCommand MoveToBackCommand { get; set; }
         public RelayCommand MoveToFrontCommand { get; set; }
         public RelayCommand MoveToFrontCommand { get; set; }
         public RelayCommand SwapColorsCommand { get; set; }
         public RelayCommand SwapColorsCommand { get; set; }
@@ -155,6 +156,7 @@ namespace PixiEditor.ViewModels
             MoveToFrontCommand = new RelayCommand(MoveLayerToFront, CanMoveToFront);
             MoveToFrontCommand = new RelayCommand(MoveLayerToFront, CanMoveToFront);
             SwapColorsCommand = new RelayCommand(SwapColors);
             SwapColorsCommand = new RelayCommand(SwapColors);
             KeyDownCommand = new RelayCommand(KeyDown);
             KeyDownCommand = new RelayCommand(KeyDown);
+            RenameLayerCommand = new RelayCommand(RenameLayer);
             ToolSet = new List<Tool> { new PixiTools.PenTool(), new PixiTools.FloodFill(), new PixiTools.LineTool(),
             ToolSet = new List<Tool> { new PixiTools.PenTool(), new PixiTools.FloodFill(), new PixiTools.LineTool(),
             new PixiTools.CircleTool(), new PixiTools.RectangleTool(), new PixiTools.EarserTool(), new PixiTools.BrightnessTool() };
             new PixiTools.CircleTool(), new PixiTools.RectangleTool(), new PixiTools.EarserTool(), new PixiTools.BrightnessTool() };
             ShortcutController = new ShortcutController
             ShortcutController = new ShortcutController
@@ -180,6 +182,11 @@ namespace PixiEditor.ViewModels
             ToolSize = 1;
             ToolSize = 1;
         }
         }
 
 
+        public void RenameLayer(object parameter)
+        {
+            BitmapUtility.Layers[(int)parameter].IsRenaming = true;
+        }
+
         public void KeyDown(object parameter)
         public void KeyDown(object parameter)
         {
         {
             ShortcutController.KeyPressed(((KeyEventArgs)parameter).Key);
             ShortcutController.KeyPressed(((KeyEventArgs)parameter).Key);

+ 19 - 7
PixiEditor/Views/EditableTextBlock.xaml.cs

@@ -45,16 +45,26 @@ namespace PixiEditor.Views
 
 
 
 
 
 
-        public RelayCommand EnableEditingCommand
+
+        public bool IsEditing
         {
         {
-            get { return (RelayCommand)GetValue(EnableEditingCommandProperty); }
-            set { SetValue(EnableEditingCommandProperty, value); }
+            get { return (bool)GetValue(EnableEditingProperty); }
+            set { SetValue(EnableEditingProperty, value);}
         }
         }
 
 
-        // Using a DependencyProperty as the backing store for EnableEditingCommand.  This enables animation, styling, binding, etc...
-        public static readonly DependencyProperty EnableEditingCommandProperty =
-            DependencyProperty.Register("EnableEditingCommand", typeof(RelayCommand), typeof(EditableTextBlock), new PropertyMetadata(null));
+        // Using a DependencyProperty as the backing store for EnableEditing.  This enables animation, styling, binding, etc...
+        public static readonly DependencyProperty EnableEditingProperty =
+            DependencyProperty.Register("IsEditing", typeof(bool), typeof(EditableTextBlock), new PropertyMetadata(OnIsEditingChanged));
 
 
+        private static void OnIsEditingChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+        {
+            if((bool)e.NewValue == true)
+            {
+                EditableTextBlock tb = (EditableTextBlock)d;
+                tb.EnableEditing();
+                
+            }
+        }
 
 
 
 
         public string Text
         public string Text
@@ -67,18 +77,20 @@ namespace PixiEditor.Views
         {
         {
             ShortcutController.BlockShortcutExecution = true;
             ShortcutController.BlockShortcutExecution = true;
             TextBlockVisibility = Visibility.Hidden;
             TextBlockVisibility = Visibility.Hidden;
+            IsEditing = true;
         }
         }
 
 
         private void DisableEditing()
         private void DisableEditing()
         {
         {
             TextBlockVisibility = Visibility.Visible;
             TextBlockVisibility = Visibility.Visible;
             ShortcutController.BlockShortcutExecution = false;
             ShortcutController.BlockShortcutExecution = false;
+            IsEditing = false;
         }
         }
 
 
 
 
         private void TextBlock_MouseDown(object sender, MouseButtonEventArgs e)
         private void TextBlock_MouseDown(object sender, MouseButtonEventArgs e)
         {
         {
-            if(e.ClickCount == 2)
+            if (e.ChangedButton == MouseButton.Left)
             {
             {
                 EnableEditing();
                 EnableEditing();
             }
             }

+ 3 - 1
PixiEditor/Views/MainWindow.xaml

@@ -199,6 +199,8 @@
                                                             <Button.ContextMenu>
                                                             <Button.ContextMenu>
                                                                 <ContextMenu>
                                                                 <ContextMenu>
                                                                     <MenuItem Header="Delete" Command="{Binding DeleteLayerCommand, Source={StaticResource ViewModelMain}}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},
                                                                     <MenuItem Header="Delete" Command="{Binding DeleteLayerCommand, Source={StaticResource ViewModelMain}}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},
+                            Path=(ItemsControl.AlternationIndex)}"/>
+                                                                    <MenuItem Header="Rename" Command="{Binding RenameLayerCommand, Source={StaticResource ViewModelMain}}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},
                             Path=(ItemsControl.AlternationIndex)}"/>
                             Path=(ItemsControl.AlternationIndex)}"/>
                                                                     <MenuItem Header="Move to front" Command="{Binding MoveToFrontCommand, Source={StaticResource ViewModelMain}}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},
                                                                     <MenuItem Header="Move to front" Command="{Binding MoveToFrontCommand, Source={StaticResource ViewModelMain}}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},
                             Path=(ItemsControl.AlternationIndex)}"/>
                             Path=(ItemsControl.AlternationIndex)}"/>
@@ -206,7 +208,7 @@
                             Path=(ItemsControl.AlternationIndex)}"/>
                             Path=(ItemsControl.AlternationIndex)}"/>
                                                                 </ContextMenu>
                                                                 </ContextMenu>
                                                             </Button.ContextMenu>
                                                             </Button.ContextMenu>
-                                                            <vws:EditableTextBlock x:Name="layerNameTB" Text="{Binding Name, Mode=TwoWay}">
+                                                            <vws:EditableTextBlock IsEditing="{Binding IsRenaming, Mode=TwoWay}" Text="{Binding Name, Mode=TwoWay}">
                                                             </vws:EditableTextBlock>
                                                             </vws:EditableTextBlock>
                                                         </Button>
                                                         </Button>
                                                     </DockPanel>
                                                     </DockPanel>