Browse Source

Added file extension icons

CPKreuz 4 years ago
parent
commit
559c6f805e

+ 44 - 0
PixiEditor/Helpers/Converters/FileExtensionToImageSourceConverter.cs

@@ -0,0 +1,44 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Data;
+
+namespace PixiEditor.Helpers.Converters
+{
+    public class FileExtensionToImageSourceConverter : IValueConverter
+    {
+        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+        {
+            string extension = (string)value;
+
+            if (extension == ".pixi")
+            {
+                return Join("PixiFile.png", parameter);
+            }
+            else if (extension == ".png")
+            {
+                return Join("PngFile.png", parameter);
+            }
+            else if (extension == ".jpg" || extension == ".jpeg")
+            {
+                return Join("JpgFile.png", parameter);
+            }
+
+            return Join("UnknownFile.png", parameter);
+        }
+
+        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+        {
+            throw new NotImplementedException();
+        }
+
+        private string Join(string path, object parameter)
+        {
+            return Path.Join((string)parameter, "Images", path);
+        }
+    }
+}

BIN
PixiEditor/Images/JpgFile.png


BIN
PixiEditor/Images/PixiFile.png


BIN
PixiEditor/Images/PixiParserLogo.png


BIN
PixiEditor/Images/PngFile.png


BIN
PixiEditor/Images/UnknownFile.png


+ 44 - 5
PixiEditor/Models/DataHolders/RecentlyOpenedDocument.cs

@@ -13,6 +13,8 @@ namespace PixiEditor.Models.DataHolders
     [DebuggerDisplay("{FilePath}")]
     public class RecentlyOpenedDocument : NotifyableObject
     {
+        private bool corrupt;
+
         private string filePath;
 
         private WriteableBitmap previewBitmap;
@@ -24,11 +26,27 @@ namespace PixiEditor.Models.DataHolders
             {
                 SetProperty(ref filePath, value);
                 RaisePropertyChanged(nameof(FileName));
+                RaisePropertyChanged(nameof(FileExtension));
                 PreviewBitmap = null;
             }
         }
 
-        public string FileName => Path.GetFileName(filePath);
+        public bool Corrupt { get => corrupt; set => SetProperty(ref corrupt, value); }
+
+        public string FileName => Path.GetFileNameWithoutExtension(filePath);
+
+        public string FileExtension
+        {
+            get
+            {
+                if (Corrupt)
+                {
+                    return "Corrupt";
+                }
+
+                return Path.GetExtension(filePath).ToLower();
+            }
+        }
 
         [DebuggerBrowsable(DebuggerBrowsableState.Never)]
         public WriteableBitmap PreviewBitmap
@@ -52,18 +70,39 @@ namespace PixiEditor.Models.DataHolders
 
         private WriteableBitmap LoadPreviewBitmap()
         {
-            if (FilePath.EndsWith(".pixi"))
+            if (FileExtension == ".pixi")
             {
-                SerializableDocument serializableDocument = PixiParser.Deserialize(filePath);
+                SerializableDocument serializableDocument = null;
+
+                try
+                {
+                    serializableDocument = PixiParser.Deserialize(filePath);
+                }
+                catch
+                {
+                    corrupt = true;
+                    return null;
+                }
 
                 return BitmapUtils.GeneratePreviewBitmap(serializableDocument.Layers, serializableDocument.Width, serializableDocument.Height, 80, 50);
             }
-            else
+            else if (FileExtension == ".png" || FileExtension == ".jpg" || FileExtension == ".jpeg")
             {
-                WriteableBitmap bitmap = Importer.ImportImage(FilePath);
+                WriteableBitmap bitmap = null;
+
+                try
+                {
+                    bitmap = Importer.ImportImage(FilePath);
+                }
+                catch
+                {
+                    corrupt = true;
+                }
 
                 return bitmap;
             }
+
+            return null;
         }
     }
 }

+ 10 - 0
PixiEditor/PixiEditor.csproj

@@ -37,11 +37,16 @@
     <None Remove="Images\AnchorDot.png" />
     <None Remove="Images\Eye-off.png" />
     <None Remove="Images\Eye.png" />
+    <None Remove="Images\JpgFile.png" />
     <None Remove="Images\MoveImage.png" />
     <None Remove="Images\MoveViewportImage.png" />
     <None Remove="Images\PixiBotLogo.png" />
     <None Remove="Images\PixiEditorLogo.png" />
+    <None Remove="Images\PixiFile.png" />
+    <None Remove="Images\PixiParserLogo.png" />
+    <None Remove="Images\PngFile.png" />
     <None Remove="Images\SelectImage.png" />
+    <None Remove="Images\UnknownFile.png" />
     <None Remove="Images\ZoomImage.png" />
     <None Include="..\icon.ico">
       <Pack>True</Pack>
@@ -76,6 +81,7 @@
     <Resource Include="Images\BrightnessImage.png" />
     <Resource Include="Images\Eye-off.png" />
     <Resource Include="Images\Eye.png" />
+    <Resource Include="Images\JpgFile.png" />
     <Resource Include="Images\LineImage.png" />
     <Resource Include="Images\MoveImage.png" />
     <Resource Include="Images\MoveViewportImage.png" />
@@ -83,9 +89,13 @@
     <Resource Include="Images\ColorPickerImage.png" />
     <Resource Include="Images\PixiBotLogo.png" />
     <Resource Include="Images\PixiEditorLogo.png" />
+    <Resource Include="Images\PixiFile.png" />
+    <Resource Include="Images\PixiParserLogo.png" />
+    <Resource Include="Images\PngFile.png" />
     <Resource Include="Images\RectangleImage.png" />
     <Resource Include="Images\SelectImage.png" />
     <Resource Include="Images\transparentbg.png" />
+    <Resource Include="Images\UnknownFile.png" />
     <Resource Include="Images\ZoomImage.png" />
   </ItemGroup>
   <ItemGroup>

+ 11 - 0
PixiEditor/ViewModels/SubViewModels/Main/FileViewModel.cs

@@ -34,6 +34,8 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
 
         public RelayCommand OpenRecentCommand { get; set; }
 
+        public RelayCommand RemoveRecentlyOpenedCommand { get; set; }
+
         public bool HasRecent
         {
             get => hasRecent;
@@ -54,6 +56,7 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
             OpenFileCommand = new RelayCommand(Open);
             ExportFileCommand = new RelayCommand(ExportFile, CanSave);
             OpenRecentCommand = new RelayCommand(OpenRecent);
+            RemoveRecentlyOpenedCommand = new RelayCommand(RemoveRecentlyOpened);
             Owner.OnStartupEvent += Owner_OnStartupEvent;
             RecentlyOpened = new RecentlyOpenedCollection(GetRecentlyOpenedDocuments());
 
@@ -88,6 +91,14 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
             Open((string)parameter);
         }
 
+        public void RemoveRecentlyOpened(object parameter)
+        {
+            if (RecentlyOpened.Contains((string)parameter))
+            {
+                RecentlyOpened.Remove((string)parameter);
+            }
+        }
+
         /// <summary>
         ///     Generates new Layer and sets it as active one.
         /// </summary>

+ 21 - 9
PixiEditor/Views/Dialogs/HelloTherePopup.xaml

@@ -6,11 +6,12 @@
         xmlns:dataHolders="clr-namespace:PixiEditor.Models.DataHolders" xmlns:converters="clr-namespace:PixiEditor.Helpers.Converters"
         xmlns:sys="clr-namespace:System;assembly=System.Runtime"
         mc:Ignorable="d"
-        Title="Hello there!" Height="615" Width="625"
+        Title="Hello there!" Height="651" Width="651"
         WindowStyle="None" WindowStartupLocation="CenterScreen">
 
     <Window.Resources>
         <converters:EqualityBoolToVisibilityConverter x:Key="EqualBoolToVisibilty"/>
+        <converters:FileExtensionToImageSourceConverter x:Key="FileExtensionToImageSource"/>
 
         <Style TargetType="TextBlock">
             <Setter Property="Foreground" Value="White"/>
@@ -85,15 +86,26 @@
                     <ItemsControl ItemsSource="{Binding RecentlyOpened}">
                         <ItemsControl.ItemTemplate>
                             <DataTemplate DataType="{x:Type dataHolders:RecentlyOpenedDocument}">
-                                <StackPanel Margin="8,5,8,0" ToolTip="{Binding FilePath}">
-                                    <Button Style="{StaticResource DarkRoundButton}" Margin="0,10,0,0" HorizontalAlignment="Center"
-                                            Width="90" Height="90"
-                                            Command="{Binding DataContext.OpenRecentCommand, RelativeSource={RelativeSource AncestorType=WrapPanel}}" CommandParameter="{Binding FilePath}">
-                                        <Image Source="{Binding PreviewBitmap}" Margin="20"/>
-                                    </Button>
+                                <Grid>
+                                    <StackPanel Margin="8,5,8,0" ToolTip="{Binding FilePath}">
+                                        <Button Margin="0,10,0,0" HorizontalAlignment="Center"
+                                                Width="100" Height="100"
+                                                Command="{Binding DataContext.OpenRecentCommand, RelativeSource={RelativeSource AncestorType=WrapPanel}}"
+                                                CommandParameter="{Binding FilePath}"
+                                                Style="{StaticResource DarkRoundButton}">
+                                            <Image Source="{Binding PreviewBitmap}" Margin="20"/>
+                                        </Button>
 
-                                    <TextBlock Text="{Binding FileName}" Width="100" TextAlignment="Center" TextTrimming="CharacterEllipsis" FontSize="18" Margin="10,2,10,2" HorizontalAlignment="Center" Foreground="White"/>
-                                </StackPanel>
+                                        <TextBlock Text="{Binding FileName}" Width="110" TextAlignment="Center" TextTrimming="CharacterEllipsis"
+                                                   FontSize="18" Margin="10,10,10,2" HorizontalAlignment="Center" Foreground="White"/>
+                                    </StackPanel>
+                                    <Image Source="{Binding FileExtension, Converter={StaticResource FileExtensionToImageSource}, ConverterParameter=../..}" Width="33"
+                                           ToolTip="{Binding FileExtension}">
+                                        <Image.RenderTransform>
+                                            <TranslateTransform X="38" Y="23"/>
+                                        </Image.RenderTransform>
+                                    </Image>
+                                </Grid>
                             </DataTemplate>
                         </ItemsControl.ItemTemplate>
                         <ItemsControl.ItemsPanel>

+ 2 - 2
PixiEditor/Views/Dialogs/HelloTherePopup.xaml.cs

@@ -63,8 +63,8 @@ namespace PixiEditor.Views.Dialogs
             }
             else if (RecentlyOpened.Count < 7)
             {
-                Height = 612;
-                Width = 506;
+                Height = 656;
+                Width = 545;
             }
         }