Browse Source

Disable recent if there is no recent and move newly opened higher up

CPKreuz 4 years ago
parent
commit
d5e823dba7

+ 7 - 0
PixiEditor/Models/DataHolders/Document/Document.IO.cs

@@ -58,6 +58,11 @@ namespace PixiEditor.Models.DataHolders
             {
                 recentlyOpened.Insert(0, newPath);
             }
+            else
+            {
+                int index = recentlyOpened.IndexOf(newPath);
+                recentlyOpened.Move(index, 0);
+            }
 
             if (recentlyOpened.Count > 5)
             {
@@ -68,6 +73,8 @@ namespace PixiEditor.Models.DataHolders
             }
 
             UserPreferences.PreferencesSettings.UpdateLocalPreference("RecentlyOpened", recentlyOpened);
+
+            XamlAccesibleViewModel.FileSubViewModel.HasRecent = true;
         }
     }
 }

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

@@ -21,6 +21,8 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
 {
     public class FileViewModel : SubViewModel<ViewModelMain>
     {
+        private bool hasRecent;
+
         public RelayCommand OpenNewFilePopupCommand { get; set; }
 
         public RelayCommand SaveDocumentCommand { get; set; }
@@ -31,6 +33,16 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
 
         public RelayCommand OpenRecentCommand { get; set; }
 
+        public bool HasRecent
+        {
+            get => hasRecent;
+            set
+            {
+                hasRecent = value;
+                RaisePropertyChanged(nameof(HasRecent));
+            }
+        }
+
         public ObservableCollection<string> RecentlyOpened { get; set; } = new ObservableCollection<string>();
 
         public FileViewModel(ViewModelMain owner)
@@ -43,6 +55,11 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
             OpenRecentCommand = new RelayCommand(OpenRecent);
             Owner.OnStartupEvent += Owner_OnStartupEvent;
             RecentlyOpened = new ObservableCollection<string>(PreferencesSettings.GetLocalPreference<JArray>(nameof(RecentlyOpened), new JArray()).ToObject<string[]>());
+
+            if (RecentlyOpened.Count > 0)
+            {
+                HasRecent = true;
+            }
         }
 
         public void OpenRecent(object parameter)

+ 1 - 1
PixiEditor/Views/MainWindow.xaml

@@ -83,7 +83,7 @@
                 <MenuItem Header="_File">
                     <MenuItem InputGestureText="CTRL+N" Header="_New" Command="{Binding FileSubViewModel.OpenNewFilePopupCommand}" />
                     <MenuItem Header="_Open" InputGestureText="Ctrl+O" Command="{Binding FileSubViewModel.OpenFileCommand}" />
-                    <MenuItem Header="_Recent" ItemsSource="{Binding FileSubViewModel.RecentlyOpened}" x:Name="recentItemMenu">
+                    <MenuItem Header="_Recent" ItemsSource="{Binding FileSubViewModel.RecentlyOpened}" x:Name="recentItemMenu" IsEnabled="{Binding FileSubViewModel.HasRecent}">
                         <MenuItem.ItemContainerStyle>
                             <Style TargetType="MenuItem">
                                 <Setter Property="Command" Value="{Binding ElementName=recentItemMenu, Path=DataContext.FileSubViewModel.OpenRecentCommand}"/>