Browse Source

Open dockable implemented

Krzysztof Krysiński 1 year ago
parent
commit
04cf17970e

+ 22 - 0
src/PixiEditor.AvaloniaUI/ViewModels/Dock/LayoutManager.cs

@@ -163,4 +163,26 @@ internal class LayoutManager
             }
         }
     }
+
+    public void ShowDockable(string id)
+    {
+        foreach (var element in ActiveLayout.Root)
+        {
+            if (element is IDockableHost dockableHost)
+            {
+                var dockable = dockableHost.Dockables.FirstOrDefault(x => x.Id == id);
+                if (dockable != null)
+                {
+                    dockableHost.ActiveDockable = dockable;
+                    return;
+                }
+            }
+        }
+
+        IDockable? created = TryCreateDockable(id);
+        if (created != null)
+        {
+            DockContext.Float(created, 0, 0);
+        }
+    }
 }

+ 3 - 16
src/PixiEditor.AvaloniaUI/ViewModels/SubViewModels/WindowViewModel.cs

@@ -182,22 +182,9 @@ internal class WindowViewModel : SubViewModel<ViewModelMain>
         new AboutPopup().Show();
     }
 
-    [Command.Basic("PixiEditor.Window.OpenNavigationWindow", "navigation", "OPEN_NAVIGATION_WINDOW", "OPEN_NAVIGATION_WINDOW")]
-    public static void ShowDockWindow(string id)
+    [Command.Basic("PixiEditor.Window.OpenNavigationWindow", "Navigator", "OPEN_NAVIGATION_WINDOW", "OPEN_NAVIGATION_WINDOW")]
+    public void ShowDockWindow(string id)
     {
-        //TODO: Implement this
-        /*if (MainWindow.Current?.LayoutRoot?.Manager?.Layout == null) return;
-        var anchorables = new List<LayoutAnchorable>(MainWindow.Current.LayoutRoot.Manager.Layout
-            .Descendents()
-            .OfType<LayoutAnchorable>());
-
-        foreach (var la in anchorables)
-        {
-            if (la.ContentId == id)
-            {
-                la.Show();
-                la.IsActive = true;
-            }
-        }*/
+        Owner.LayoutSubViewModel.LayoutManager.ShowDockable(id);
     }
 }

+ 4 - 0
src/PixiEditor.AvaloniaUI/Views/Dock/PaletteViewerDockView.axaml

@@ -5,8 +5,12 @@
              xmlns:palettes="clr-namespace:PixiEditor.AvaloniaUI.Views.Palettes"
              xmlns:cmds="clr-namespace:PixiEditor.AvaloniaUI.Models.Commands.XAML"
              xmlns:converters="clr-namespace:PixiEditor.AvaloniaUI.Helpers.Converters"
+             xmlns:dock="clr-namespace:PixiEditor.AvaloniaUI.ViewModels.Dock"
              mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
              x:Class="PixiEditor.AvaloniaUI.Views.Dock.PaletteViewerDockView">
+    <Design.DataContext>
+        <dock:PaletteViewerDockViewModel />
+    </Design.DataContext>
     <palettes:PaletteViewer
         IsEnabled="{Binding DocumentManagerSubViewModel.ActiveDocument, Converter={x:Static ObjectConverters.IsNotNull}}"
         Colors="{Binding DocumentManagerSubViewModel.ActiveDocument.Palette}"

+ 1 - 2
src/PixiEditor.AvaloniaUI/Views/Palettes/PaletteViewer.axaml.cs

@@ -31,8 +31,7 @@ internal partial class PaletteViewer : UserControl
 {
     public static readonly StyledProperty<ObservableRangeCollection<PaletteColor>> SwatchesProperty =
         AvaloniaProperty.Register<PaletteViewer, ObservableRangeCollection<PaletteColor>>(
-            nameof(Swatches),
-            default(ObservableRangeCollection<PaletteColor>));
+            nameof(Swatches));
 
     public ObservableRangeCollection<PaletteColor> Swatches
     {