Browse Source

PixiEditorPopup wip

Krzysztof Krysiński 1 year ago
parent
commit
cf3c1015d5

+ 1 - 0
src/PixiEditor.AvaloniaUI/App.axaml

@@ -16,6 +16,7 @@
         <StyleInclude Source="/Styles/PixiEditor.Animators.axaml"/>
         <StyleInclude Source="/Styles/PixiEditor.Handles.axaml"/>
         <StyleInclude Source="/Styles/PixiEditor.Layers.axaml"/>
+        <StyleInclude Source="/Styles/PixiEditorPopupTemplate.axaml"/>
     </Application.Styles>
 
 </Application>

+ 30 - 0
src/PixiEditor.AvaloniaUI/Styles/PixiEditorPopupTemplate.axaml

@@ -0,0 +1,30 @@
+<Styles xmlns="https://github.com/avaloniaui"
+        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+        xmlns:controls="using:PixiEditor.AvaloniaUI.Views.Dialogs"
+        xmlns:behaviours="clr-namespace:PixiEditor.AvaloniaUI.Helpers.Behaviours">
+    <Design.PreviewWith>
+        <controls:PixiEditorPopup Width="400" Height="400" SizeToContent="Manual"/>
+    </Design.PreviewWith>
+
+    <Style Selector="controls|PixiEditorPopup">
+        <Setter Property="Background" Value="Transparent" />
+        <Setter Property="WindowStartupLocation" Value="CenterOwner"/>
+        <Setter Property="TransparencyLevelHint" Value="Transparent"/>
+        <Setter Property="SystemDecorations" Value="None"/>
+        <Setter Property="ShowInTaskbar" Value="False"/>
+        <Setter Property="Template">
+            <ControlTemplate>
+                <Grid Background="{DynamicResource ThemeBackgroundBrush1}" Focusable="True" RowDefinitions="40, *">
+                    <Interaction.Behaviors>
+                        <behaviours:ClearFocusOnClickBehavior/>
+                    </Interaction.Behaviors>
+
+                    <controls:DialogTitleBar DockPanel.Dock="Top"
+                                            TitleKey="{TemplateBinding Title}"/>
+
+                    <ContentPresenter Grid.Row="1" DockPanel.Dock="Bottom" Content="{TemplateBinding Content}" />
+                </Grid>
+            </ControlTemplate>
+        </Setter>
+    </Style>
+</Styles>

+ 13 - 43
src/PixiEditor.AvaloniaUI/Views/Dialogs/NewFilePopup.axaml

@@ -2,59 +2,29 @@
         x:ClassModifier="internal"
         xmlns="https://github.com/avaloniaui"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
-        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
-        xmlns:local="clr-namespace:PixiEditor.Views"
-        xmlns:vm="clr-namespace:PixiEditor.ViewModels"
-        xmlns:userControls="clr-namespace:PixiEditor.Views.UserControls"
-        xmlns:helpers="clr-namespace:PixiEditor.Helpers"
         xmlns:ui="clr-namespace:PixiEditor.Extensions.UI;assembly=PixiEditor.Extensions"
-        xmlns:subViewModels="clr-namespace:PixiEditor.AvaloniaUI.ViewModels.SubViewModels"
-        xmlns:markupExtensions="clr-namespace:PixiEditor.AvaloniaUI.Helpers.MarkupExtensions"
-        xmlns:behaviours="clr-namespace:PixiEditor.AvaloniaUI.Helpers.Behaviours"
         xmlns:dialogs="clr-namespace:PixiEditor.AvaloniaUI.Views.Dialogs"
-        xmlns:viewModels="clr-namespace:PixiEditor.AvaloniaUI.ViewModels"
         xmlns:input="clr-namespace:PixiEditor.AvaloniaUI.Views.Input"
         xmlns:system="clr-namespace:System;assembly=System.Runtime"
-        ShowInTaskbar="False"
-        SystemDecorations="None"
-        WindowStartupLocation="CenterScreen" 
-        MinHeight="250" Height="250"
-        SizeToContent="Width"
-        Name="newFilePopup" 
+        Width="300" Height="250"
+        SizeToContent="Height"
+        Name="popup"
         BorderBrush="Black" BorderThickness="1"
-        FlowDirection="{markupExtensions:Localization FlowDirection}"
-        ui:Translator.Key="CREATE_NEW_IMAGE">
-    <!--<WindowChrome.WindowChrome>
-        <WindowChrome CaptionHeight="32"  GlassFrameThickness="0.1"
-                      ResizeBorderThickness="{x:Static SystemParameters.WindowResizeBorderThickness}" />
-    </WindowChrome.WindowChrome>
-
-    <Window.CommandBindings>
-        <CommandBinding Command="{x:Static SystemCommands.CloseWindowCommand}" CanExecute="CommandBinding_CanExecute"
-                        Executed="CommandBinding_Executed_Close" />
-    </Window.CommandBindings>-->
-
+        Title="CREATE_NEW_IMAGE">
     <DockPanel Background="{DynamicResource ThemeBackgroundBrush1}" Focusable="True">
-        <Interaction.Behaviors>
-            <behaviours:ClearFocusOnClickBehavior/>
-        </Interaction.Behaviors>
-
-        <dialogs:DialogTitleBar DockPanel.Dock="Top"
-            TitleKey="CREATE_NEW_IMAGE" CloseCommand="{Binding DataContext.CancelCommand, ElementName=newFilePopup}"  />
-
         <Button DockPanel.Dock="Bottom" Margin="0,15,0,15" HorizontalAlignment="Center"
                 IsDefault="True" ui:Translator.Key="CREATE" x:Name="createButton"
                 Classes="DarkRoundButton"
-                Command="{Binding Path=DataContext.SetResultAndCloseCommand, ElementName=newFilePopup}">
-                <Button.CommandParameter>
-                    <system:Boolean>True</system:Boolean>
-                </Button.CommandParameter>
-            </Button>
+                Command="{Binding Path=DataContext.SetResultAndCloseCommand, ElementName=popup}">
+            <Button.CommandParameter>
+                <system:Boolean>True</system:Boolean>
+            </Button.CommandParameter>
+        </Button>
 
         <input:SizePicker HorizontalAlignment="Center" MinWidth="230" Height="125" Margin="15,30,15,0"
-                              PreserveAspectRatio="False"
-                              ChosenHeight="{Binding FileHeight, Mode=TwoWay, ElementName=newFilePopup}"
-                              ChosenWidth="{Binding FileWidth, Mode=TwoWay, ElementName=newFilePopup}" 
-                              x:Name="sizePicker"/>
+                          PreserveAspectRatio="False"
+                          ChosenHeight="{Binding FileHeight, Mode=TwoWay, ElementName=popup}"
+                          ChosenWidth="{Binding FileWidth, Mode=TwoWay, ElementName=popup}"
+                          x:Name="sizePicker"/>
     </DockPanel>
 </Window>

+ 1 - 14
src/PixiEditor.AvaloniaUI/Views/Dialogs/NewFilePopup.axaml.cs

@@ -8,7 +8,7 @@ namespace PixiEditor.AvaloniaUI.Views.Dialogs;
 /// <summary>
 ///     Interaction logic for NewFilePopup.xaml.
 /// </summary>
-internal partial class NewFilePopup : Window
+internal partial class NewFilePopup : PixiEditorPopup
 {
     public static readonly StyledProperty<int> FileHeightProperty =
         AvaloniaProperty.Register<NewFilePopup, int>(nameof(FileHeight));
@@ -40,17 +40,4 @@ internal partial class NewFilePopup : Window
         get => (int)GetValue(FileWidthProperty);
         set => SetValue(FileWidthProperty, value);
     }
-
-
-    [RelayCommand]
-    private void SetResultAndClose(bool property)
-    {
-        Close(true);
-    }
-
-    [RelayCommand]
-    private void Cancel()
-    {
-        Close(false);
-    }
 }

+ 24 - 0
src/PixiEditor.AvaloniaUI/Views/Dialogs/PixiEditorPopup.cs

@@ -0,0 +1,24 @@
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Controls.Primitives;
+using Avalonia.Styling;
+using CommunityToolkit.Mvvm.Input;
+
+namespace PixiEditor.AvaloniaUI.Views.Dialogs;
+
+public partial class PixiEditorPopup : Window, IStyleable
+{
+    Type IStyleable.StyleKey => typeof(PixiEditorPopup);
+
+    [RelayCommand]
+    public void SetResultAndCloseCommand()
+    {
+        Close(true);
+    }
+
+    [RelayCommand]
+    public void CloseCommand()
+    {
+        Close(false);
+    }
+}