Refactoring
This commit is contained in:
parent
915924c291
commit
633b13316f
@ -11,13 +11,18 @@ public partial class LoaderStart : UserControl
|
|||||||
this.InitializeComponent();
|
this.InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
private RegistryKey I18NCommanderKey => Registry.CurrentUser.OpenSubKey("Software", RegistryKeyPermissionCheck.ReadWriteSubTree)!.CreateSubKey("I18N Commander", RegistryKeyPermissionCheck.ReadWriteSubTree);
|
private static RegistryKey I18NCommanderKey => Registry.CurrentUser.OpenSubKey("Software", RegistryKeyPermissionCheck.ReadWriteSubTree)!.CreateSubKey("I18N Commander", RegistryKeyPermissionCheck.ReadWriteSubTree);
|
||||||
|
|
||||||
private List<string> RecentProjects
|
#region Recent Projects
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the list of recent projects without any extras e.g. it does not prune the list of projects.
|
||||||
|
/// </summary>
|
||||||
|
private static List<string> RecentProjects
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
using var regKey = this.I18NCommanderKey;
|
using var regKey = LoaderStart.I18NCommanderKey;
|
||||||
var recentProjectsValue = regKey.GetValue("recentProjects");
|
var recentProjectsValue = regKey.GetValue("recentProjects");
|
||||||
return recentProjectsValue switch
|
return recentProjectsValue switch
|
||||||
{
|
{
|
||||||
@ -28,7 +33,7 @@ public partial class LoaderStart : UserControl
|
|||||||
|
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
using var regKey = this.I18NCommanderKey;
|
using var regKey = LoaderStart.I18NCommanderKey;
|
||||||
regKey.SetValue("recentProjects", value, RegistryValueKind.MultiString);
|
regKey.SetValue("recentProjects", value, RegistryValueKind.MultiString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -54,13 +59,13 @@ public partial class LoaderStart : UserControl
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var recentProjects = this.RecentProjects;
|
var recentProjects = LoaderStart.RecentProjects;
|
||||||
this.contextMenuRecentProjects.Items.Clear();
|
this.contextMenuRecentProjects.Items.Clear();
|
||||||
this.contextMenuRecentProjects.Items.Add("Browse for project...", Resources.Icons.icons8_browse_folder_512, (innerSender, args) => this.browseForProject());
|
this.contextMenuRecentProjects.Items.Add("Browse for project...", Resources.Icons.icons8_browse_folder_512, (innerSender, args) => this.BrowseForProject());
|
||||||
foreach (var recentProject in recentProjects)
|
foreach (var recentProject in recentProjects)
|
||||||
{
|
{
|
||||||
var fileInfo = new FileInfo(recentProject);
|
var fileInfo = new FileInfo(recentProject);
|
||||||
var item = this.contextMenuRecentProjects.Items.Add($"{fileInfo.Directory.GetDirectories().Last()}/{fileInfo.Name}", Resources.Icons.icons8_document_512, (innerSender, args) => this.openRecentProject(innerSender));
|
var item = this.contextMenuRecentProjects.Items.Add($"{fileInfo.Directory.GetDirectories().Last()}/{fileInfo.Name}", Resources.Icons.icons8_document_512, (innerSender, args) => this.OpenRecentProject(innerSender));
|
||||||
item.Tag = recentProject;
|
item.Tag = recentProject;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,24 +83,27 @@ public partial class LoaderStart : UserControl
|
|||||||
|
|
||||||
// TODO: Open the project
|
// TODO: Open the project
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void BrowseForProject()
|
||||||
|
{
|
||||||
|
// TODO: Browse for project
|
||||||
// TODO: Handle cancel event
|
// TODO: Handle cancel event
|
||||||
|
|
||||||
// TODO: Apply chosen project's path
|
// TODO: Apply chosen project's path
|
||||||
LoaderStart.UpdateRecentProjectsWithPruning(string.Empty);
|
LoaderStart.UpdateRecentProjectsWithPruning(string.Empty);
|
||||||
|
|
||||||
|
// TODO: Open the project
|
||||||
}
|
}
|
||||||
|
|
||||||
private void openRecentProject(object? sender)
|
private void OpenRecentProject(object? sender)
|
||||||
{
|
{
|
||||||
if(sender is null)
|
if (sender is not ToolStripItem item)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (sender is ToolStripItem item)
|
var path = (item.Tag as string)!;
|
||||||
{
|
|
||||||
var path = (item.Tag as string)!;
|
|
||||||
LoaderStart.UpdateRecentProjectsWithPruning(path);
|
LoaderStart.UpdateRecentProjectsWithPruning(path);
|
||||||
|
|
||||||
// TODO: Open the project
|
// TODO: Open the project
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void contextMenuRecentProjects_Closing(object sender, ToolStripDropDownClosingEventArgs e)
|
private void contextMenuRecentProjects_Closing(object sender, ToolStripDropDownClosingEventArgs e)
|
||||||
|
Loading…
Reference in New Issue
Block a user