Browse Source

Added workspaces button

Krzysztof Krysiński 3 months ago
parent
commit
0314f4479e

+ 7 - 0
src/PixiEditor/Models/Commands/XAML/Command.cs

@@ -44,6 +44,13 @@ internal class Command : MarkupExtension
             commandController = CommandController.Current; // TODO: Find a better way to get the current CommandController
             commandController = CommandController.Current; // TODO: Find a better way to get the current CommandController
         }
         }
 
 
+        bool contains = commandController.Commands.ContainsKey(Name);
+
+        if (!contains)
+        {
+            return null;
+        }
+
         Commands.Command command = commandController.Commands[Name];
         Commands.Command command = commandController.Commands[Name];
         return GetPixiCommand ? command : GetICommand(command, new CommandBindingSourceInfo(SourceInfoTag), UseProvided);
         return GetPixiCommand ? command : GetICommand(command, new CommandBindingSourceInfo(SourceInfoTag), UseProvided);
     }
     }

+ 27 - 0
src/PixiEditor/Models/Commands/XAML/CommandExists.cs

@@ -0,0 +1,27 @@
+using Avalonia.Controls;
+using Avalonia.Markup.Xaml;
+
+namespace PixiEditor.Models.Commands.XAML;
+
+internal class CommandExists : MarkupExtension
+{
+    public string Name { get; set; }
+
+    public CommandExists() { }
+    public CommandExists(string name) => Name = name;
+
+    public override object ProvideValue(IServiceProvider serviceProvider)
+    {
+        if (Design.IsDesignMode)
+        {
+            return true;
+        }
+
+        if (CommandController.Current.Commands.ContainsKey(Name))
+        {
+            return true;
+        }
+
+        return false;
+    }
+}

+ 10 - 0
src/PixiEditor/ViewModels/Document/DocumentViewModel.cs

@@ -697,6 +697,11 @@ internal partial class DocumentViewModel : PixiObservableObject, IDocument
                 renderOutputName = name.ComputedValue?.ToString();
                 renderOutputName = name.ComputedValue?.ToString();
             }
             }
 
 
+            if (finalSize.ShortestAxis <= 0)
+            {
+                finalSize = SizeBindable;
+            }
+
             return finalSize;
             return finalSize;
         }
         }
 
 
@@ -1311,6 +1316,11 @@ internal partial class DocumentViewModel : PixiObservableObject, IDocument
         if (exportOutput != default)
         if (exportOutput != default)
         {
         {
             size = exportOutput.originalSize;
             size = exportOutput.originalSize;
+
+            if (size.ShortestAxis <= 0)
+            {
+                size = SizeBindable;
+            }
         }
         }
 
 
         return size;
         return size;

+ 2 - 2
src/PixiEditor/ViewModels/SubViewModels/ExtensionsViewModel.cs

@@ -16,7 +16,7 @@ internal class ExtensionsViewModel : SubViewModel<ViewModelMain>
         WindowProvider windowProvider = (WindowProvider)Owner.Services.GetService<IWindowProvider>();
         WindowProvider windowProvider = (WindowProvider)Owner.Services.GetService<IWindowProvider>();
 
 
         RegisterCoreWindows(windowProvider);
         RegisterCoreWindows(windowProvider);
-        Owner.OnStartupEvent += Owner_OnStartupEvent;
+        Owner.OnEarlyStartupEvent += Owner_OnEarlyStartupEvent;
     }
     }
 
 
     private void RegisterCoreWindows(WindowProvider? windowProvider)
     private void RegisterCoreWindows(WindowProvider? windowProvider)
@@ -24,7 +24,7 @@ internal class ExtensionsViewModel : SubViewModel<ViewModelMain>
         windowProvider?.RegisterWindow<PalettesBrowser>();
         windowProvider?.RegisterWindow<PalettesBrowser>();
     }
     }
 
 
-    private void Owner_OnStartupEvent()
+    private void Owner_OnEarlyStartupEvent()
     {
     {
         ExtensionLoader.InitializeExtensions(new ExtensionServices(Owner.Services));
         ExtensionLoader.InitializeExtensions(new ExtensionServices(Owner.Services));
     }
     }

+ 2 - 0
src/PixiEditor/ViewModels/ViewModelMain.cs

@@ -35,6 +35,7 @@ internal partial class ViewModelMain : ViewModelBase, ICommandsHandler
     public IServiceProvider Services { get; private set; }
     public IServiceProvider Services { get; private set; }
 
 
     public event Action OnClose;
     public event Action OnClose;
+    public event Action OnEarlyStartupEvent;
     public event Action OnStartupEvent;
     public event Action OnStartupEvent;
     public FileViewModel FileSubViewModel { get; set; }
     public FileViewModel FileSubViewModel { get; set; }
     public UpdateViewModel UpdateSubViewModel { get; set; }
     public UpdateViewModel UpdateSubViewModel { get; set; }
@@ -176,6 +177,7 @@ internal partial class ViewModelMain : ViewModelBase, ICommandsHandler
 
 
     public void OnStartup()
     public void OnStartup()
     {
     {
+        OnEarlyStartupEvent?.Invoke();
         OnStartupEvent?.Invoke();
         OnStartupEvent?.Invoke();
         MenuBarViewModel.Init(Services, CommandController);
         MenuBarViewModel.Init(Services, CommandController);
     }
     }

+ 7 - 23
src/PixiEditor/Views/Rendering/Scene.cs

@@ -402,7 +402,10 @@ internal class Scene : Zoombox.Zoombox, ICustomHitTest
                 if (prop != null)
                 if (prop != null)
                 {
                 {
                     VecI size = Document.NodeGraph.GetComputedPropertyValue<VecI>(prop);
                     VecI size = Document.NodeGraph.GetComputedPropertyValue<VecI>(prop);
-                    outputSize = size;
+                    if (size.ShortestAxis > 0)
+                    {
+                        outputSize = size;
+                    }
                 }
                 }
             }
             }
         }
         }
@@ -850,40 +853,21 @@ internal class Scene : Zoombox.Zoombox, ICustomHitTest
         if (e.NewValue is DocumentViewModel documentViewModel)
         if (e.NewValue is DocumentViewModel documentViewModel)
         {
         {
             documentViewModel.SizeChanged += scene.DocumentViewModelOnSizeChanged;
             documentViewModel.SizeChanged += scene.DocumentViewModelOnSizeChanged;
-            scene.ContentDimensions = scene.GetRenderOutputSize();
+            scene.ContentDimensions = scene.Document.GetRenderOutputSize(scene.RenderOutput);
         }
         }
     }
     }
 
 
     private void DocumentViewModelOnSizeChanged(object? sender, DocumentSizeChangedEventArgs e)
     private void DocumentViewModelOnSizeChanged(object? sender, DocumentSizeChangedEventArgs e)
     {
     {
-        ContentDimensions = GetRenderOutputSize();
+        ContentDimensions = Document.GetRenderOutputSize(RenderOutput);
     }
     }
 
 
-    private VecI GetRenderOutputSize()
-    {
-        VecI outputSize = Document.SizeBindable;
-
-        if (!string.IsNullOrEmpty(RenderOutput))
-        {
-            if (Document.NodeGraph.CustomRenderOutputs.TryGetValue(RenderOutput, out var node))
-            {
-                var prop = node?.Inputs.FirstOrDefault(x => x.PropertyName == CustomOutputNode.SizePropertyName);
-                if (prop != null)
-                {
-                    VecI size = Document.NodeGraph.GetComputedPropertyValue<VecI>(prop);
-                    outputSize = size;
-                }
-            }
-        }
-
-        return outputSize;
-    }
 
 
     private static void UpdateRenderOutput(Scene scene, AvaloniaPropertyChangedEventArgs e)
     private static void UpdateRenderOutput(Scene scene, AvaloniaPropertyChangedEventArgs e)
     {
     {
         if (e.NewValue is string newValue)
         if (e.NewValue is string newValue)
         {
         {
-            scene.ContentDimensions = scene.GetRenderOutputSize();
+            scene.ContentDimensions = scene.Document.GetRenderOutputSize(newValue);
             scene.CenterContent();
             scene.CenterContent();
         }
         }
     }
     }

+ 15 - 8
src/PixiEditor/Views/Windows/HelloTherePopup.axaml

@@ -70,14 +70,21 @@
                                    Text="{Binding VersionText}" />
                                    Text="{Binding VersionText}" />
                     </StackPanel>
                     </StackPanel>
 
 
-                    <StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Center">
-                        <Button Command="{Binding OpenFileCommand}" MinWidth="150" Margin="10"
-                                ui:Translator.Key="OPEN_FILE" />
-                        <Button Command="{Binding OpenNewFileCommand}" MinWidth="150" Margin="10"
-                                ui:Translator.Key="NEW_FILE" />
-                        <Button Classes="pixi-icon" Content="{DynamicResource icon-paste-as-new-layer}"
-                                Command="{Binding NewFromClipboardCommand}"
-                                ui:Translator.TooltipKey="NEW_FROM_CLIPBOARD" />
+                    <StackPanel Grid.Row="1" Orientation="Vertical" HorizontalAlignment="Center">
+                        <StackPanel Orientation="Horizontal">
+                            <Button Command="{Binding OpenFileCommand}" MinWidth="150" Margin="10"
+                                    ui:Translator.Key="OPEN_FILE" />
+                            <Button Command="{Binding OpenNewFileCommand}" MinWidth="150" Margin="10"
+                                    ui:Translator.Key="NEW_FILE" />
+                            <Button Classes="pixi-icon" Content="{DynamicResource icon-paste-as-new-layer}"
+                                    Command="{Binding NewFromClipboardCommand}"
+                                    ui:Translator.TooltipKey="NEW_FROM_CLIPBOARD" />
+                        </StackPanel>
+                        <Button Command="{xaml:Command Name=PixiEditor.FoundersPack:Workspaces.Browse}"
+                                IsVisible="{xaml:CommandExists Name=PixiEditor.FoundersPack:Workspaces.Browse}"
+                                Name="workspacesButton"
+                                Margin="10, 0, 34, 0"
+                                ui:Translator.Key="PixiEditor.FoundersPack:BROWSE_TEMPLATES"/>
                     </StackPanel>
                     </StackPanel>
 
 
                     <StackPanel Grid.Row="2" HorizontalAlignment="Center" Margin="0,30,0,0">
                     <StackPanel Grid.Row="2" HorizontalAlignment="Center" Margin="0,30,0,0">