Browse Source

Improved document picker

Krzysztof Krysiński 3 weeks ago
parent
commit
ea9e7297b3

+ 11 - 0
src/PixiEditor/Helpers/Converters/EmptyStringConverter.cs

@@ -0,0 +1,11 @@
+using System.Globalization;
+
+namespace PixiEditor.Helpers.Converters;
+
+internal class EmptyStringConverter : SingleInstanceConverter<NotEmptyStringConverter>
+{
+    public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+    {
+        return string.IsNullOrEmpty(value as string);
+    }
+}

+ 16 - 0
src/PixiEditor/Helpers/Converters/FilePathToFileNameConverter.cs

@@ -0,0 +1,16 @@
+using System.Globalization;
+
+namespace PixiEditor.Helpers.Converters;
+
+internal class FilePathToFileNameConverter : SingleInstanceConverter<FilePathToFileNameConverter>
+{
+    public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+    {
+        if (value is string path)
+        {
+            return System.IO.Path.GetFileName(path);
+        }
+
+        return value!;
+    }
+}

+ 12 - 1
src/PixiEditor/Views/Nodes/Properties/DocumentReferencePropertyView.axaml

@@ -9,12 +9,23 @@
                              xmlns:input="clr-namespace:PixiEditor.Views.Input"
                              xmlns:settings="clr-namespace:PixiEditor.Views.Tools.ToolSettings.Settings"
                              xmlns:blackboard="clr-namespace:PixiEditor.ViewModels.Document.Blackboard"
+                             xmlns:properties1="clr-namespace:PixiEditor.ViewModels.Nodes.Properties"
                              mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
                              x:Class="PixiEditor.Views.Nodes.Properties.DocumentReferencePropertyView">
+    <Design.DataContext>
+        <properties1:DocumentReferencePropertyViewModel />
+    </Design.DataContext>
     <StackPanel Orientation="Horizontal"
                 HorizontalAlignment="{Binding IsInput, Converter={converters:BoolToValueConverter FalseValue='Right', TrueValue='Stretch'}}">
         <TextBlock localization:Translator.TooltipKey="{Binding DisplayName}" VerticalAlignment="Center"
                    localization:Translator.Key="{Binding DisplayName}" />
-        <Button Command="{Binding PickGraphFileCommand}" localization:Translator.Key="SELECT"/>
+        <Button Command="{Binding PickGraphFileCommand}"
+                MaxWidth="100"
+                Margin="5, 0, 0, 0">
+            <Panel>
+                <TextBlock FontSize="12" localization:Translator.Key="SELECT" IsVisible="{Binding Value.OriginalFilePath, Converter={converters:EmptyStringConverter}}" />
+                <TextBlock TextTrimming="CharacterEllipsis" FontSize="12" Text="{Binding Value.OriginalFilePath, Converter={converters:FilePathToFileNameConverter}}"/>
+            </Panel>
+        </Button>
     </StackPanel>
 </properties:NodePropertyView>