Explorar o código

Add last few sub view models

flabbet %!s(int64=4) %!d(string=hai) anos
pai
achega
4cc937490b

+ 1 - 1
PixiEditor/Models/Tools/Tools/ColorPickerTool.cs

@@ -17,7 +17,7 @@ namespace PixiEditor.Models.Tools.Tools
 
         public override void Use(Coordinates[] coordinates)
         {
-            ViewModelMain.Current.PrimaryColor = GetColorUnderMouse();
+            ViewModelMain.Current.ColorsSubViewModel.PrimaryColor = GetColorUnderMouse();
         }
 
         public Color GetColorUnderMouse()

+ 82 - 0
PixiEditor/ViewModels/SubViewModels/Main/ColorsViewModel.cs

@@ -0,0 +1,82 @@
+using PixiEditor.Helpers;
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Windows.Media;
+
+namespace PixiEditor.ViewModels.SubViewModels.Main
+{
+    public class ColorsViewModel : SubViewModel<ViewModelMain>
+    {
+        public RelayCommand SwapColorsCommand { get; set; }
+        public RelayCommand SelectColorCommand { get; set; }
+        public RelayCommand RemoveSwatchCommand { get; set; }
+
+        private Color _primaryColor = Colors.Black;
+        public Color PrimaryColor //Primary color, hooked with left mouse button
+        {
+            get => _primaryColor;
+            set
+            {
+                if (_primaryColor != value)
+                {
+                    _primaryColor = value;
+                    Owner.BitmapManager.PrimaryColor = value;
+                    RaisePropertyChanged("PrimaryColor");
+                }
+            }
+        }
+
+        private Color _secondaryColor = Colors.White;
+        public Color SecondaryColor
+        {
+            get => _secondaryColor;
+            set
+            {
+                if (_secondaryColor != value)
+                {
+                    _secondaryColor = value;
+                    RaisePropertyChanged("SecondaryColor");
+                }
+            }
+        }
+
+        public ColorsViewModel(ViewModelMain owner) : base(owner)
+        {
+            SelectColorCommand = new RelayCommand(SelectColor);
+            RemoveSwatchCommand = new RelayCommand(RemoveSwatch);
+            SwapColorsCommand = new RelayCommand(SwapColors);
+        }
+
+        public void SwapColors(object parameter)
+        {
+            var tmp = PrimaryColor;
+            PrimaryColor = SecondaryColor;
+            SecondaryColor = tmp;
+        }
+
+        public void AddSwatch(Color color)
+        {
+            if (!Owner.BitmapManager.ActiveDocument.Swatches.Contains(color))
+            {
+                Owner.BitmapManager.ActiveDocument.Swatches.Add(color);
+            }
+        }
+
+        private void RemoveSwatch(object parameter)
+        {
+            if (!(parameter is Color)) throw new ArgumentException();
+            Color color = (Color)parameter;
+            if (Owner.BitmapManager.ActiveDocument.Swatches.Contains(color))
+            {
+                Owner.BitmapManager.ActiveDocument.Swatches.Remove(color);
+            }
+        }
+
+        private void SelectColor(object parameter)
+        {
+            PrimaryColor = parameter as Color? ?? throw new ArgumentException();
+        }
+
+    }
+}

+ 55 - 0
PixiEditor/ViewModels/SubViewModels/Main/DocumentViewModel.cs

@@ -0,0 +1,55 @@
+using PixiEditor.Helpers;
+using PixiEditor.Models.Dialogs;
+using System.Linq;
+
+namespace PixiEditor.ViewModels.SubViewModels.Main
+{
+    public class DocumentViewModel : SubViewModel<ViewModelMain>
+    {
+        public const string ConfirmationDialogMessage = "Document was modified. Do you want to save changes?";
+        public bool UnsavedDocumentModified { get; set; }
+        public RelayCommand CenterContentCommand { get; set; }
+        public RelayCommand ClipCanvasCommand { get; set; }
+        public RelayCommand DeletePixelsCommand { get; set; }
+        public RelayCommand OpenResizePopupCommand { get; set; }
+
+        public DocumentViewModel(ViewModelMain owner) : base(owner)
+        {
+            CenterContentCommand = new RelayCommand(CenterContent, Owner.DocumentIsNotNull);
+            ClipCanvasCommand = new RelayCommand(ClipCanvas, Owner.DocumentIsNotNull);
+            DeletePixelsCommand = new RelayCommand(DeletePixels, Owner.SelectionSubViewModel.SelectionIsNotEmpty);
+            OpenResizePopupCommand = new RelayCommand(OpenResizePopup, Owner.DocumentIsNotNull);
+        }
+
+        private void DeletePixels(object parameter)
+        {
+            Owner.BitmapManager.BitmapOperations.DeletePixels(new[] { Owner.BitmapManager.ActiveLayer },
+                Owner.SelectionSubViewModel.ActiveSelection.SelectedPoints.ToArray());
+        }
+
+        public void ClipCanvas(object parameter)
+        {
+            Owner.BitmapManager.ActiveDocument?.ClipCanvas();
+        }
+
+        private void OpenResizePopup(object parameter)
+        {
+            bool isCanvasDialog = (string)parameter == "canvas";
+            ResizeDocumentDialog dialog = new ResizeDocumentDialog(Owner.BitmapManager.ActiveDocument.Width,
+                Owner.BitmapManager.ActiveDocument.Height, isCanvasDialog);
+            if (dialog.ShowDialog())
+            {
+                if (isCanvasDialog)
+                    Owner.BitmapManager.ActiveDocument.ResizeCanvas(dialog.Width, dialog.Height, dialog.ResizeAnchor);
+                else
+                    Owner.BitmapManager.ActiveDocument.Resize(dialog.Width, dialog.Height);
+            }
+        }
+
+        private void CenterContent(object property)
+        {
+            Owner.BitmapManager.ActiveDocument.CenterContent();
+        }
+
+    }
+}

+ 5 - 5
PixiEditor/ViewModels/SubViewModels/Main/FileViewModel.cs

@@ -85,9 +85,9 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
 
         private void Open(string path)
         {
-            if (Owner.UnsavedDocumentModified)
+            if (Owner.DocumentSubViewModel.UnsavedDocumentModified)
             {
-                var result = ConfirmationDialog.Show(ViewModelMain.ConfirmationDialogMessage);
+                var result = ConfirmationDialog.Show(DocumentViewModel.ConfirmationDialogMessage);
                 if (result == ConfirmationType.Yes)
                 {
                     SaveDocument(null);
@@ -124,7 +124,7 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
         {
             Owner.BitmapManager.ActiveDocument = Importer.ImportDocument(path);
             Exporter.SaveDocumentPath = path;
-            Owner.UnsavedDocumentModified = false;
+            Owner.DocumentSubViewModel.UnsavedDocumentModified = false;
         }
 
         public void SaveDocument(bool asNew)
@@ -138,12 +138,12 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
             if (paramIsAsNew || Exporter.SaveDocumentPath == null)
             {
                 var saved = Exporter.SaveAsEditableFileWithDialog(Owner.BitmapManager.ActiveDocument, !paramIsAsNew);
-                Owner.UnsavedDocumentModified = Owner.UnsavedDocumentModified && !saved;
+                Owner.DocumentSubViewModel.UnsavedDocumentModified = Owner.DocumentSubViewModel.UnsavedDocumentModified && !saved;
             }
             else
             {
                 Exporter.SaveAsEditableFile(Owner.BitmapManager.ActiveDocument, Exporter.SaveDocumentPath);
-                Owner.UnsavedDocumentModified = false;
+                Owner.DocumentSubViewModel.UnsavedDocumentModified = false;
             }
         }
 

+ 29 - 5
PixiEditor/ViewModels/SubViewModels/Main/IoViewModel.cs

@@ -14,6 +14,30 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
         public RelayCommand KeyDownCommand { get; set; }
         public RelayCommand KeyUpCommand { get; set; }
 
+        private double _mouseXonCanvas;
+
+        private double _mouseYonCanvas;
+
+        public double MouseXOnCanvas //Mouse X coordinate relative to canvas
+        {
+            get => _mouseXonCanvas;
+            set
+            {
+                _mouseXonCanvas = value;
+                RaisePropertyChanged(nameof(MouseXOnCanvas));
+            }
+        }
+
+        public double MouseYOnCanvas //Mouse Y coordinate relative to canvas
+        {
+            get => _mouseYonCanvas;
+            set
+            {
+                _mouseYonCanvas = value;
+                RaisePropertyChanged(nameof(MouseYOnCanvas));
+            }
+        }
+
         private bool _restoreToolOnKeyUp = false;
 
         public IoViewModel(ViewModelMain owner) : base(owner)
@@ -42,10 +66,10 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
             {
                 if (!Owner.BitmapManager.MouseController.IsRecordingChanges)
                 {
-                    bool clickedOnCanvas = Owner.MouseXOnCanvas >= 0 &&
-                        Owner.MouseXOnCanvas <= Owner.BitmapManager.ActiveDocument.Width &&
-                        Owner.MouseYOnCanvas >= 0 && 
-                        Owner.MouseYOnCanvas <= Owner.BitmapManager.ActiveDocument.Height;
+                    bool clickedOnCanvas = MouseXOnCanvas >= 0 &&
+                        MouseXOnCanvas <= Owner.BitmapManager.ActiveDocument.Width &&
+                        MouseYOnCanvas >= 0 && 
+                        MouseYOnCanvas <= Owner.BitmapManager.ActiveDocument.Height;
                     Owner.BitmapManager.MouseController.StartRecordingMouseMovementChanges(clickedOnCanvas);
                     Owner.BitmapManager.MouseController.RecordMouseMovementChange(MousePositionConverter.CurrentCoordinates);
                 }
@@ -65,7 +89,7 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
         /// <param name="parameter"></param>
         private void MouseMove(object parameter)
         {
-            Coordinates cords = new Coordinates((int)Owner.MouseXOnCanvas, (int)Owner.MouseYOnCanvas);
+            Coordinates cords = new Coordinates((int)MouseXOnCanvas, (int)MouseYOnCanvas);
             MousePositionConverter.CurrentCoordinates = cords;
 
 

+ 19 - 0
PixiEditor/ViewModels/SubViewModels/Main/UndoViewModel.cs

@@ -1,6 +1,9 @@
 using PixiEditor.Helpers;
 using PixiEditor.Models.Controllers;
 using PixiEditor.Models.DataHolders;
+using PixiEditor.Models.Tools;
+using System;
+using System.Linq;
 
 namespace PixiEditor.ViewModels.SubViewModels.Main
 {
@@ -27,6 +30,22 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
             RedoCommand = new RelayCommand(Redo, CanRedo);
         }
 
+        public void TriggerNewUndoChange(Tool toolUsed)
+        {
+            if (BitmapManager.IsOperationTool(toolUsed)
+                && ((BitmapOperationTool)toolUsed).UseDefaultUndoMethod)
+            {
+                Tuple<LayerChange, LayerChange>[] changes = Owner.ChangesController.PopChanges();
+                if (changes != null && changes.Length > 0)
+                {
+                    LayerChange[] newValues = changes.Select(x => x.Item1).ToArray();
+                    LayerChange[] oldValues = changes.Select(x => x.Item2).ToArray();
+                    UndoManager.AddUndoChange(new Change("UndoChanges", oldValues, newValues, root: this));
+                    toolUsed.AfterAddedUndo();
+                }
+            }
+        }
+
         /// <summary>
         ///     Undo last action
         /// </summary>

+ 26 - 161
PixiEditor/ViewModels/ViewModelMain.cs

@@ -24,28 +24,14 @@ namespace PixiEditor.ViewModels
 {
     public class ViewModelMain : ViewModelBase
     {
-        public const string ConfirmationDialogMessage = "Document was modified. Do you want to save changes?";
 
         public event EventHandler OnStartupEvent;
 
-        private Color _primaryColor = Colors.Black;
-
-        private Color _secondaryColor = Colors.White;
-
-        public bool UnsavedDocumentModified { get; set; }
-
         public Action CloseAction { get; set; }
 
         public static ViewModelMain Current { get; set; }                         
-        public RelayCommand SwapColorsCommand { get; set; }    
-        public RelayCommand ClipCanvasCommand { get; set; }
-        public RelayCommand DeletePixelsCommand { get; set; }
-        public RelayCommand OpenResizePopupCommand { get; set; }
-        public RelayCommand SelectColorCommand { get; set; }
-        public RelayCommand RemoveSwatchCommand { get; set; }
         public RelayCommand OnStartupCommand { get; set; }
         public RelayCommand CloseWindowCommand { get; set; }
-        public RelayCommand CenterContentCommand { get; set; }
         public RelayCommand OpenHyperlinkCommand { get; set; } 
 
         public FileViewModel FileSubViewModel { get; set; }
@@ -57,58 +43,9 @@ namespace PixiEditor.ViewModels
         public UndoViewModel UndoSubViewModel { get; set; }
         public SelectionViewModel SelectionSubViewModel { get; set; }
         public ViewportViewModel ViewportSubViewModel { get; set; }
-
-
-        private double _mouseXonCanvas;
-
-        private double _mouseYonCanvas;
-
-        public double MouseXOnCanvas //Mouse X coordinate relative to canvas
-        {
-            get => _mouseXonCanvas;
-            set
-            {
-                _mouseXonCanvas = value;
-                RaisePropertyChanged(nameof(MouseXOnCanvas));
-            }
-        }
-
-        public double MouseYOnCanvas //Mouse Y coordinate relative to canvas
-        {
-            get => _mouseYonCanvas;
-            set
-            {
-                _mouseYonCanvas = value;
-                RaisePropertyChanged(nameof(MouseYOnCanvas));
-            }
-        }
-
-        public Color PrimaryColor //Primary color, hooked with left mouse button
-        {
-            get => _primaryColor;
-            set
-            {
-                if (_primaryColor != value)
-                {
-                    _primaryColor = value;
-                    BitmapManager.PrimaryColor = value;
-                    RaisePropertyChanged("PrimaryColor");
-                }
-            }
-        }
-
-        public Color SecondaryColor
-        {
-            get => _secondaryColor;
-            set
-            {
-                if (_secondaryColor != value)
-                {
-                    _secondaryColor = value;
-                    RaisePropertyChanged("SecondaryColor");
-                }
-            }
-        }
+        public ColorsViewModel ColorsSubViewModel { get; set; }
+        public DocumentViewModel DocumentSubViewModel { get; set; }
+       
 
         public BitmapManager BitmapManager { get; set; }
         public PixelChangesController ChangesController { get; set; }
@@ -125,15 +62,8 @@ namespace PixiEditor.ViewModels
             SelectionSubViewModel = new SelectionViewModel(this);
 
             ChangesController = new PixelChangesController();
-            SwapColorsCommand = new RelayCommand(SwapColors);           
-            ClipCanvasCommand = new RelayCommand(ClipCanvas, DocumentIsNotNull);
-            DeletePixelsCommand = new RelayCommand(DeletePixels, SelectionSubViewModel.SelectionIsNotEmpty);
-            OpenResizePopupCommand = new RelayCommand(OpenResizePopup, DocumentIsNotNull);
-            SelectColorCommand = new RelayCommand(SelectColor);
-            RemoveSwatchCommand = new RelayCommand(RemoveSwatch);
             OnStartupCommand = new RelayCommand(OnStartup);
             CloseWindowCommand = new RelayCommand(CloseWindow);
-            CenterContentCommand = new RelayCommand(CenterContent, DocumentIsNotNull);
             OpenHyperlinkCommand = new RelayCommand(OpenHyperlink);
 
             FileSubViewModel = new FileViewModel(this);
@@ -144,6 +74,8 @@ namespace PixiEditor.ViewModels
             ClipboardSubViewModel = new ClipboardViewModel(this);
             UndoSubViewModel = new UndoViewModel(this);
             ViewportSubViewModel = new ViewportViewModel(this);
+            ColorsSubViewModel = new ColorsViewModel(this);
+            DocumentSubViewModel = new DocumentViewModel(this);
 
 
             ShortcutController = new ShortcutController
@@ -168,7 +100,7 @@ namespace PixiEditor.ViewModels
                     new Shortcut(Key.OemOpenBrackets, ToolsSubViewModel.ChangeToolSizeCommand, -1),
                     new Shortcut(Key.OemCloseBrackets, ToolsSubViewModel.ChangeToolSizeCommand, 1),
                     //Editor
-                    new Shortcut(Key.X, SwapColorsCommand),
+                    new Shortcut(Key.X, ColorsSubViewModel.SwapColorsCommand),
                     new Shortcut(Key.Y, UndoSubViewModel.RedoCommand, modifier: ModifierKeys.Control),
                     new Shortcut(Key.Z,  UndoSubViewModel.UndoCommand, modifier: ModifierKeys.Control),
                     new Shortcut(Key.D, SelectionSubViewModel.DeselectCommand, modifier: ModifierKeys.Control),
@@ -177,9 +109,9 @@ namespace PixiEditor.ViewModels
                     new Shortcut(Key.V, ClipboardSubViewModel.PasteCommand, modifier: ModifierKeys.Control),
                     new Shortcut(Key.J, ClipboardSubViewModel.DuplicateCommand, modifier: ModifierKeys.Control),
                     new Shortcut(Key.X, ClipboardSubViewModel.CutCommand, modifier: ModifierKeys.Control),
-                    new Shortcut(Key.Delete, DeletePixelsCommand),
-                    new Shortcut(Key.I, OpenResizePopupCommand, modifier: ModifierKeys.Control | ModifierKeys.Shift),
-                    new Shortcut(Key.C, OpenResizePopupCommand, "canvas", ModifierKeys.Control | ModifierKeys.Shift),
+                    new Shortcut(Key.Delete, DocumentSubViewModel.DeletePixelsCommand),
+                    new Shortcut(Key.I, DocumentSubViewModel.OpenResizePopupCommand, modifier: ModifierKeys.Control | ModifierKeys.Shift),
+                    new Shortcut(Key.C, DocumentSubViewModel.OpenResizePopupCommand, "canvas", ModifierKeys.Control | ModifierKeys.Shift),
                     new Shortcut(Key.F11, SystemCommands.MaximizeWindowCommand),
                     //File
                     new Shortcut(Key.O, FileSubViewModel.OpenFileCommand, modifier: ModifierKeys.Control),
@@ -191,7 +123,7 @@ namespace PixiEditor.ViewModels
                 }
             };
             UndoManager.SetMainRoot(this);
-            BitmapManager.PrimaryColor = PrimaryColor;
+            BitmapManager.PrimaryColor = ColorsSubViewModel.PrimaryColor;
             Current = this;
         }        
 
@@ -207,11 +139,6 @@ namespace PixiEditor.ViewModels
             Process.Start(processInfo);
         }
 
-        private void CenterContent(object property)
-        {
-            BitmapManager.ActiveDocument.CenterContent();
-        }
-
         private void CloseWindow(object property)
         {
             if (!(property is CancelEventArgs)) throw new ArgumentException();
@@ -219,16 +146,19 @@ namespace PixiEditor.ViewModels
             ((CancelEventArgs) property).Cancel = true;
 
             ConfirmationType result = ConfirmationType.No;
-            if (UnsavedDocumentModified)
+            if (DocumentSubViewModel.UnsavedDocumentModified)
             {
-                result = ConfirmationDialog.Show(ConfirmationDialogMessage);
+                result = ConfirmationDialog.Show(DocumentViewModel.ConfirmationDialogMessage);
                 if (result == ConfirmationType.Yes) 
                 {
                     FileSubViewModel.SaveDocument(false); 
                 }
             }
 
-            if (result != ConfirmationType.Canceled) ((CancelEventArgs) property).Cancel = false;
+            if (result != ConfirmationType.Canceled)
+            {
+                ((CancelEventArgs)property).Cancel = false;
+            }
         }
 
         private void OnStartup(object parameter)
@@ -239,59 +169,15 @@ namespace PixiEditor.ViewModels
         private void BitmapManager_DocumentChanged(object sender, DocumentChangedEventArgs e)
         {
             e.NewDocument.DocumentSizeChanged += ActiveDocument_DocumentSizeChanged;
-        }
-    
-
-        private void RemoveSwatch(object parameter)
-        {
-            if (!(parameter is Color)) throw new ArgumentException();
-            Color color = (Color) parameter;
-            if (BitmapManager.ActiveDocument.Swatches.Contains(color))
-                BitmapManager.ActiveDocument.Swatches.Remove(color);
-        }
-
-        private void SelectColor(object parameter)
-        {
-            PrimaryColor = parameter as Color? ?? throw new ArgumentException();
-        }
+        }           
 
         private void ActiveDocument_DocumentSizeChanged(object sender, DocumentSizeChangedEventArgs e)
         {
             SelectionSubViewModel.ActiveSelection = new Selection(Array.Empty<Coordinates>());
             ViewportSubViewModel.CenterViewport();
-            UnsavedDocumentModified = true;
-        }
-
-        public void AddSwatch(Color color)
-        {
-            if (!BitmapManager.ActiveDocument.Swatches.Contains(color))
-                BitmapManager.ActiveDocument.Swatches.Add(color);
-        }
-
-        private void OpenResizePopup(object parameter)
-        {
-            bool isCanvasDialog = (string) parameter == "canvas";
-            ResizeDocumentDialog dialog = new ResizeDocumentDialog(BitmapManager.ActiveDocument.Width,
-                BitmapManager.ActiveDocument.Height, isCanvasDialog);
-            if (dialog.ShowDialog())
-            {
-                if (isCanvasDialog)
-                    BitmapManager.ActiveDocument.ResizeCanvas(dialog.Width, dialog.Height, dialog.ResizeAnchor);
-                else
-                    BitmapManager.ActiveDocument.Resize(dialog.Width, dialog.Height);
-            }
-        }
-
-        private void DeletePixels(object parameter)
-        {
-            BitmapManager.BitmapOperations.DeletePixels(new[] {BitmapManager.ActiveLayer},
-                SelectionSubViewModel.ActiveSelection.SelectedPoints.ToArray());
-        }
-
-        public void ClipCanvas(object parameter)
-        {
-            BitmapManager.ActiveDocument?.ClipCanvas();
+            DocumentSubViewModel.UnsavedDocumentModified = true;
         }        
+              
 
         public bool DocumentIsNotNull(object property)
         {
@@ -300,40 +186,19 @@ namespace PixiEditor.ViewModels
 
         private void MouseController_StoppedRecordingChanges(object sender, EventArgs e)
         {
-           TriggerNewUndoChange(BitmapManager.SelectedTool);
-        }
-
-        public void TriggerNewUndoChange(Tool toolUsed)
-        {
-            if (BitmapManager.IsOperationTool(toolUsed)
-                && ((BitmapOperationTool) toolUsed).UseDefaultUndoMethod)
-            {
-                Tuple<LayerChange, LayerChange>[] changes = ChangesController.PopChanges();
-                if (changes != null && changes.Length > 0)
-                {
-                    LayerChange[] newValues = changes.Select(x => x.Item1).ToArray();
-                    LayerChange[] oldValues = changes.Select(x => x.Item2).ToArray();
-                    UndoManager.AddUndoChange(new Change("UndoChanges", oldValues, newValues, root: UndoSubViewModel));
-                    toolUsed.AfterAddedUndo();
-                }
-            }
+           UndoSubViewModel.TriggerNewUndoChange(BitmapManager.SelectedTool);
         }
 
         private void BitmapUtility_BitmapChanged(object sender, BitmapChangedEventArgs e)
         {
             ChangesController.AddChanges(new LayerChange(e.PixelsChanged, e.ChangedLayerIndex),
                 new LayerChange(e.OldPixelsValues, e.ChangedLayerIndex));
-            UnsavedDocumentModified = true;
+            DocumentSubViewModel.UnsavedDocumentModified = true;
             if (BitmapManager.IsOperationTool())
-                AddSwatch(PrimaryColor);
-        }
-
-        public void SwapColors(object parameter)
-        {
-            var tmp = PrimaryColor;
-            PrimaryColor = SecondaryColor;
-            SecondaryColor = tmp;
-        }             
+            {
+                ColorsSubViewModel.AddSwatch(ColorsSubViewModel.PrimaryColor);
+            }
+        }            
 
         /// <summary>
         ///     Resets most variables and controller, so new documents can be handled.
@@ -346,7 +211,7 @@ namespace PixiEditor.ViewModels
             SelectionSubViewModel.ActiveSelection = new Selection(Array.Empty<Coordinates>());
             ViewportSubViewModel.CenterViewport();
             Exporter.SaveDocumentPath = null;
-            UnsavedDocumentModified = false;
+            DocumentSubViewModel.UnsavedDocumentModified = false;
         }
     }
 }

+ 13 - 13
PixiEditor/Views/MainWindow.xaml

@@ -94,7 +94,7 @@
                     <MenuItem Header="_Paste" Command="{Binding ClipboardSubViewModel.PasteCommand}" InputGestureText="Ctrl+V" />
                     <MenuItem Header="_Duplicate" Command="{Binding ClipboardSubViewModel.DuplicateCommand}" InputGestureText="Ctrl+J" />
                     <Separator />
-                    <MenuItem Header="_Delete Selected" Command="{Binding DeletePixelsCommand}"
+                    <MenuItem Header="_Delete Selected" Command="{Binding DocumentSubViewModel.DeletePixelsCommand}"
                               InputGestureText="Delete" />
                 </MenuItem>
                 <MenuItem Header="_Select">
@@ -102,13 +102,13 @@
                     <MenuItem Header="_Deselect" Command="{Binding SelectionSubViewModel.DeselectCommand}" InputGestureText="Ctrl+D" />
                 </MenuItem>
                 <MenuItem Header="_Document">
-                    <MenuItem Header="Resize Document..." Command="{Binding OpenResizePopupCommand}"
+                    <MenuItem Header="Resize Document..." Command="{Binding DocumentSubViewModel.OpenResizePopupCommand}"
                               InputGestureText="Ctrl+Shift+I" />
-                    <MenuItem Header="Resize Canvas..." Command="{Binding OpenResizePopupCommand}"
+                    <MenuItem Header="Resize Canvas..." Command="{Binding DocumentSubViewModel.OpenResizePopupCommand}"
                               CommandParameter="canvas" InputGestureText="Ctrl+Shift+C" />
-                    <MenuItem Header="Clip Canvas" Command="{Binding ClipCanvasCommand}" />
+                    <MenuItem Header="Clip Canvas" Command="{Binding DocumentSubViewModel.ClipCanvasCommand}" />
                     <Separator/>
-                    <MenuItem Header="Center Content" Command="{Binding CenterContentCommand}" />
+                    <MenuItem Header="Center Content" Command="{Binding DocumentSubViewModel.CenterContentCommand}" />
                 </MenuItem>
                 <MenuItem Header="_Help">
                     <MenuItem Header="Documentation" Command="{Binding OpenHyperlinkCommand}"
@@ -177,8 +177,8 @@
                     </i:Interaction.Triggers>
                     <i:Interaction.Behaviors>
                         <behaviors:MouseBehaviour RelativeTo="{Binding ElementName=DrawingPanel, Path=Item}"
-                                                  MouseX="{Binding MouseXOnCanvas, Mode=OneWayToSource}"
-                                                  MouseY="{Binding MouseYOnCanvas, Mode=OneWayToSource}" />
+                                                  MouseX="{Binding IoSubViewModel.MouseXOnCanvas, Mode=OneWayToSource}"
+                                                  MouseY="{Binding IoSubViewModel.MouseYOnCanvas, Mode=OneWayToSource}" />
                     </i:Interaction.Behaviors>
                     <vws:MainDrawingPanel.Item>
                         <Canvas Width="{Binding BitmapManager.ActiveDocument.Width}"
@@ -249,8 +249,8 @@
             </Grid.RowDefinitions>
             <StackPanel Grid.Row="2" Orientation="Vertical" ZIndex="15">
             </StackPanel>
-            <colorpicker:StandardColorPicker Grid.Row="0" SelectedColor="{Binding PrimaryColor, Mode=TwoWay}"
-                             SecondaryColor="{Binding SecondaryColor, Mode=TwoWay}" />
+            <colorpicker:StandardColorPicker Grid.Row="0" SelectedColor="{Binding ColorsSubViewModel.PrimaryColor, Mode=TwoWay}"
+                             SecondaryColor="{Binding ColorsSubViewModel.SecondaryColor, Mode=TwoWay}" />
             <avalondock:DockingManager Foreground="White" Background="{StaticResource AccentColor}" BorderThickness="0"
                                        Grid.Row="1">
                 <avalondock:LayoutRoot x:Name="LayoutRoot">
@@ -358,14 +358,14 @@
                                                         <i:EventTrigger EventName="MouseDown">
                                                             <i:InvokeCommandAction
                                                                 Command="{Binding
-                                                                    RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.SelectColorCommand}"
+                                                                    RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.ColorsSubViewModel.SelectColorCommand}"
                                                                 CommandParameter="{Binding}" />
                                                         </i:EventTrigger>
                                                     </i:Interaction.Triggers>
                                                     <Grid.ContextMenu>
                                                         <ContextMenu>
                                                             <MenuItem Header="Remove" Foreground="White"
-                                                                      Command="{Binding RemoveSwatchCommand, Source={StaticResource ViewModelMain}}"
+                                                                      Command="{Binding ColorsSubViewModel.RemoveSwatchCommand, Source={StaticResource ViewModelMain}}"
                                                                       CommandParameter="{Binding}" />
                                                         </ContextMenu>
                                                     </Grid.ContextMenu>
@@ -386,9 +386,9 @@
         <DockPanel Grid.Row="3" Grid.Column="1">
             <StackPanel DockPanel.Dock="Right" Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Center">
                 <TextBlock Text="X:" Foreground="White" FontSize="16"/>
-                <TextBlock Margin="4,0,10,0" Text="{Binding MouseXOnCanvas, Converter={StaticResource DoubleToIntConverter}}" Foreground="White" FontSize="16"/>
+                <TextBlock Margin="4,0,10,0" Text="{Binding IoSubViewModel.MouseXOnCanvas, Converter={StaticResource DoubleToIntConverter}}" Foreground="White" FontSize="16"/>
                 <TextBlock Text="Y:" Foreground="White" FontSize="16"/>
-                <TextBlock Margin="4,0,10,0" Text="{Binding MouseYOnCanvas, Converter={StaticResource DoubleToIntConverter}}" Foreground="White" FontSize="16"/>
+                <TextBlock Margin="4,0,10,0" Text="{Binding IoSubViewModel.MouseYOnCanvas, Converter={StaticResource DoubleToIntConverter}}" Foreground="White" FontSize="16"/>
             </StackPanel>
         </DockPanel>
         <StackPanel Margin="10,0,0,0" VerticalAlignment="Center" Grid.Row="3"