Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More options to manage recent files #369

Merged
merged 3 commits into from
Oct 9, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 27 additions & 10 deletions AnnoDesigner.Core/Helper/RecentFilesHelper.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO.Abstractions;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AnnoDesigner.Core.Models;

namespace AnnoDesigner.Core.Helper
Expand All @@ -17,27 +14,39 @@ public class RecentFilesHelper : IRecentFilesHelper

private readonly IRecentFilesSerializer _serializer;
private readonly IFileSystem _fileSystem;
private int _maximumItemCount;

public RecentFilesHelper(IRecentFilesSerializer serializerToUse, IFileSystem fileSystemToUse)
public RecentFilesHelper(IRecentFilesSerializer serializerToUse, IFileSystem fileSystemToUse, int maxItemCount = 10)
{
_serializer = serializerToUse ?? throw new ArgumentNullException(nameof(serializerToUse));
_fileSystem = fileSystemToUse ?? throw new ArgumentNullException(nameof(fileSystemToUse));

RecentFiles = new List<RecentFile>();
MaximumItemCount = 10;

_maximumItemCount = maxItemCount;
Load();
}

public List<RecentFile> RecentFiles { get; private set; }

/// <summary>
/// Gets or sets the maximum item count.
/// <para />
/// The default value is <c>10</c>.
/// Gets or sets the maximum item count.
/// </summary>
/// <remarks>The default value is <c>10</c>.</remarks>
/// <value>The maximum item count.</value>
public int MaximumItemCount { get; set; }
public int MaximumItemCount
{
get { return _maximumItemCount; }
set
{
if (_maximumItemCount != value)
{
_maximumItemCount = value;
EnsureMaxiumItemCount();
Save();
Updated?.Invoke(this, EventArgs.Empty);
}
}
}

private void Load()
{
Expand Down Expand Up @@ -125,5 +134,13 @@ private void RemoveNonExistingFiles(List<RecentFile> loadedFiles)
}
}
}

public void ClearRecentFiles()
{
RecentFiles.Clear();

Save();
Updated?.Invoke(this, EventArgs.Empty);
}
}
}
1 change: 1 addition & 0 deletions AnnoDesigner.Core/Models/IAppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public interface IAppSettings
bool UpdateSupportsPrerelease { get; set; }
string HotkeyMappings { get; set; }
string RecentFiles { get; set; }
int MaxRecentFiles { get; set; }
string ColorGridLines { get; set; }
string ColorObjectBorderLines { get; set; }
bool UseZoomToPoint { get; set; }
Expand Down
5 changes: 5 additions & 0 deletions AnnoDesigner.Core/Models/IRecentFilesHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,10 @@ public interface IRecentFilesHelper
/// <param name="fileToRemove">The file.</param>
/// <exception cref="ArgumentNullException">The <paramref name="fileToRemove"/> is <c>null</c>.</exception>
void RemoveFile(RecentFile fileToRemove);

/// <summary>
/// Clears the list of recently used files.
/// </summary>
void ClearRecentFiles();
}
}
2 changes: 1 addition & 1 deletion AnnoDesigner/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ private async void Application_Startup(object sender, StartupEventArgs e)

var recentFilesSerializer = new RecentFilesAppSettingsSerializer(_appSettings);

IRecentFilesHelper recentFilesHelper = new RecentFilesHelper(recentFilesSerializer, _fileSystem);
IRecentFilesHelper recentFilesHelper = new RecentFilesHelper(recentFilesSerializer, _fileSystem, _appSettings.MaxRecentFiles);
ITreeLocalizationLoader treeLocalizationLoader = new TreeLocalizationLoader(_fileSystem);

var mainVM = new MainViewModel(_commons, _appSettings, recentFilesHelper, _messageBoxService, _updateHelper, _localizationHelper, _fileSystem, treeLocalizationLoader: treeLocalizationLoader);
Expand Down
5 changes: 5 additions & 0 deletions AnnoDesigner/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,10 @@ public static class Constants
/// Used to prevent endless loop on updates.
/// </summary>
public const string Argument_Ask_For_Admin = "-askAdmin";

/// <summary>
/// The default number for maximum recent files saved.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a better comment here should The default number of recent files to show?
And the property - DefaultRecentFilesToShow?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DefaultRecentFilesToShow sounds to me like a list of default files, in the meaning of a list of file paths.
Also the value could be changed so it isn't really a default value.

/// </summary>
public const int MaxRecentFiles = 10;
}
}
38 changes: 31 additions & 7 deletions AnnoDesigner/Localization/Localization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public static void Init(ICommons commons)
["ViewLicenses"] = "View open source licenses",
["ExternalLinkConfirmationMessage"] = "This will open a new tab in your default web browser. Continue?",
["ExternalLinkMessageTitle"] = "Opening an external link",
["RecentFiles"] = "Recent files",
["RecentFiles"] = "Recent Files",
["UpdatePreferencesVersionInformation"] = "Version Information",
["UpdatePreferencesSettings"] = "Settings",
["UpdatePreferencesCheckPreRelease"] = "Check for pre-releases",
Expand Down Expand Up @@ -246,7 +246,11 @@ public static void Init(ICommons commons)
["UnsavedChangedBeforeCrash"] = "Program crashed but there are unsaved changes",
["ColorPresetsVersion"] = "Color Presets Version",
["TreeLocalizationVersion"] = "Tree Localization Version",
["ShowHarborBlockedArea"] = "Show Harbor Areas"
["ShowHarborBlockedArea"] = "Show Harbor Areas",
["ShowPanorama"] = "Show Panorama",
["GeneralPreferencesRecentFilesSettings"] = "Recent Files Settings",
["GeneralPreferencesMaxRecentFiles"] = "Maximum Recent Files",
["Clear"] = "Clear"
},
["ger"] = new Dictionary<string, string>()
{
Expand Down Expand Up @@ -440,7 +444,11 @@ public static void Init(ICommons commons)
["UnsavedChangedBeforeCrash"] = "Die Anwendung ist abgestürzt, aber es gibt nicht gespeicherte Änderungen.",
["ColorPresetsVersion"] = "Farbvorlagenversion",
["TreeLocalizationVersion"] = "Übersetzungsversion",
["ShowHarborBlockedArea"] = "Hafengebiete anzeigen"
["ShowHarborBlockedArea"] = "Hafengebiete anzeigen",
["ShowPanorama"] = "Panorama zeigen",
["GeneralPreferencesRecentFilesSettings"] = "Zuletzt geöffnete Dateien",
["GeneralPreferencesMaxRecentFiles"] = "maximale Anzahl Dateien",
["Clear"] = "Leeren"
},
["fra"] = new Dictionary<string, string>()
{
Expand Down Expand Up @@ -634,7 +642,11 @@ public static void Init(ICommons commons)
["UnsavedChangedBeforeCrash"] = "Le programme a planté mais il y a des modifications non sauvegardées.",
["ColorPresetsVersion"] = "Version des préréglages de couleur",
["TreeLocalizationVersion"] = "Version de la localisation de l'arbre",
["ShowHarborBlockedArea"] = "Afficher les zones portuaires"
["ShowHarborBlockedArea"] = "Afficher les zones portuaires",
["ShowPanorama"] = "Montrer panorama",
["GeneralPreferencesRecentFilesSettings"] = "Fichiers récents",
["GeneralPreferencesMaxRecentFiles"] = "Nombre maximal de fichiers",
["Clear"] = "Supprimer"
},
["esp"] = new Dictionary<string, string>()
{
Expand Down Expand Up @@ -828,7 +840,11 @@ public static void Init(ICommons commons)
["UnsavedChangedBeforeCrash"] = "El programa se ha interrumpido pero hay cambios no guardados",
["ColorPresetsVersion"] = "Versión de preajustes de color",
["TreeLocalizationVersion"] = "Versión de localización del árbol",
["ShowHarborBlockedArea"] = "Mostrar zonas portuarias"
["ShowHarborBlockedArea"] = "Mostrar zonas portuarias",
["ShowPanorama"] = "Mostrar panorama",
["GeneralPreferencesRecentFilesSettings"] = "Archivos recientes",
["GeneralPreferencesMaxRecentFiles"] = "Número máximo de archivos",
["Clear"] = "Eliminar"
},
["pol"] = new Dictionary<string, string>()
{
Expand Down Expand Up @@ -1022,7 +1038,11 @@ public static void Init(ICommons commons)
["UnsavedChangedBeforeCrash"] = "Program zawiesił się, ale są niezapisane zmiany",
["ColorPresetsVersion"] = "Presety kolorów Wersja",
["TreeLocalizationVersion"] = "Wersja lokalizacji drzewa",
["ShowHarborBlockedArea"] = "Pokaż obszary portowe"
["ShowHarborBlockedArea"] = "Pokaż obszary portowe",
["ShowPanorama"] = "Pokaż panoramę",
["GeneralPreferencesRecentFilesSettings"] = "Ostatnie akta",
["GeneralPreferencesMaxRecentFiles"] = "Maksymalna liczba plików",
["Clear"] = "Skreślić"
},
["rus"] = new Dictionary<string, string>()
{
Expand Down Expand Up @@ -1216,7 +1236,11 @@ public static void Init(ICommons commons)
["UnsavedChangedBeforeCrash"] = "Программа аварийно завершена, но есть несохраненные изменения",
["ColorPresetsVersion"] = "Версия предустановок цвета",
["TreeLocalizationVersion"] = "Версия локализации деревьев",
["ShowHarborBlockedArea"] = "Показать районы гавани"
["ShowHarborBlockedArea"] = "Показать районы гавани",
["ShowPanorama"] = "Показать панораму",
["GeneralPreferencesRecentFilesSettings"] = "Последние Файлы",
["GeneralPreferencesMaxRecentFiles"] = "Максимальное количество файлов",
["Clear"] = "Удалить"
},
};

Expand Down
6 changes: 6 additions & 0 deletions AnnoDesigner/Models/AppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,12 @@ public string RecentFiles
set => Settings.Default.RecentFiles = value;
}

public int MaxRecentFiles
{
get => Settings.Default.MaxRecentFiles;
set => Settings.Default.MaxRecentFiles = value;
}

public string ColorGridLines
{
get => Settings.Default.ColorGridLines;
Expand Down
53 changes: 51 additions & 2 deletions AnnoDesigner/PreferencesPages/GeneralSettingsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,17 @@
<TextBlock Grid.Column="0"
Text="{l:Localize GeneralPreferencesZoomSensitivity, StringFormat='{}{0}:'}" />
<Slider Grid.Column="1"
Margin="10,0,0,0"
Name="ZoomSlider"
Value="{Binding ZoomSensitivityPercentage}"
Maximum="{x:Static annoDesigner:Constants.ZoomSensitivitySliderMaximum}"
Minimum="1"
Width="150"
Width="140"
TickFrequency="1"
IsSnapToTickEnabled="True"
TickPlacement="None" />
<TextBlock Grid.Column="2"
Margin="5,0,0,0"
Margin="10,0,0,0"
Text="{Binding ElementName=ZoomSlider, Path=Value, StringFormat='{}{0}%'}" />
<Button Grid.Column="3"
Content="{l:Localize Default}"
Expand All @@ -169,6 +170,54 @@
Content="{l:Localize GeneralPreferencesHideInfluenceOnSelection}" />

</StackPanel>

<!--#endregion-->

<!--#region Recent files Settings -->

<TextBlock Text="{l:Localize GeneralPreferencesRecentFilesSettings}"
FontSize="14"
Margin="0,10,0,10" />

<Grid Margin="20,0,0,10">
<Grid.ColumnDefinitions>
<ColumnDefinition MinWidth="180"
Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<TextBlock Grid.Column="0"
Text="{l:Localize GeneralPreferencesMaxRecentFiles, StringFormat='\{0\}:', Mode=OneWay}" />

<xctk:IntegerUpDown Grid.Column="1"
Margin="10,0,0,0"
Height="22"
IsEnabled="True"
Width="70"
DefaultValue="10"
DisplayDefaultValueOnEmptyText="True"
Increment="1"
Minimum="1"
Maximum="100"
TabIndex="0"
Value="{Binding MaxRecentFiles}" />

<Button Grid.Column="2"
Content="{l:Localize Default}"
Command="{Binding ResetMaxRecentFilesCommand}"
Padding="5,2"
Margin="20,0,0,0" />
<Button Grid.Column="3"
Content="{l:Localize Clear}"
Command="{Binding ClearRecentFilesCommand}"
Padding="5,2"
Margin="50,0,0,0" />

</Grid>

<!--#endregion-->

</StackPanel>
</Page>
12 changes: 12 additions & 0 deletions AnnoDesigner/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions AnnoDesigner/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,8 @@
<Setting Name="ShowHarborBlockedArea" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="MaxRecentFiles" Type="System.Int32" Scope="User">
<Value Profile="(Default)">10</Value>
</Setting>
</Settings>
</SettingsFile>
Loading