From 1cadb432eea31f4416fdec89c5f0a68e849ab5d9 Mon Sep 17 00:00:00 2001
From: miku-666 <74728189+NessieHax@users.noreply.github.com>
Date: Sat, 30 Mar 2024 02:20:05 +0100
Subject: [PATCH] MainForm - Add Recently open file menu item
---
PCK-Studio/MainForm.Designer.cs | 34 ++++++++++++-
PCK-Studio/MainForm.cs | 58 +++++++++++++++++++---
PCK-Studio/MainForm.resx | 48 ++++++++++++++++++
PCK-Studio/Properties/Settings.Designer.cs | 13 ++++-
PCK-Studio/Properties/Settings.settings | 3 ++
5 files changed, 148 insertions(+), 8 deletions(-)
diff --git a/PCK-Studio/MainForm.Designer.cs b/PCK-Studio/MainForm.Designer.cs
index 9dceb0cb..96210730 100644
--- a/PCK-Studio/MainForm.Designer.cs
+++ b/PCK-Studio/MainForm.Designer.cs
@@ -32,6 +32,8 @@
System.Windows.Forms.PictureBox logoPictureBox;
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
+ System.Windows.Forms.ToolStripSeparator toolStripSeparator2;
+ System.Windows.Forms.ToolStripSeparator toolStripSeparator4;
this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator();
this.contextMenuPCKEntries = new System.Windows.Forms.ContextMenuStrip(this.components);
this.createToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
@@ -142,8 +144,12 @@
this.imageList = new System.Windows.Forms.ImageList(this.components);
this.previewPictureBox = new PckStudio.ToolboxItems.InterpolationPictureBox();
this.LittleEndianCheckBox = new MetroFramework.Controls.MetroCheckBox();
+ this.recentlyOpenToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
logoPictureBox = new System.Windows.Forms.PictureBox();
toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
+ toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
+ toolStripSeparator4 = new System.Windows.Forms.ToolStripSeparator();
((System.ComponentModel.ISupportInitialize)(logoPictureBox)).BeginInit();
this.contextMenuPCKEntries.SuspendLayout();
this.menuStrip.SuspendLayout();
@@ -474,7 +480,11 @@
this.packSettingsToolStripMenuItem,
this.saveToolStripMenuItem1,
this.saveToolStripMenuItem,
- this.closeToolStripMenuItem});
+ this.closeToolStripMenuItem,
+ toolStripSeparator2,
+ this.recentlyOpenToolStripMenuItem,
+ toolStripSeparator4,
+ this.exitToolStripMenuItem});
this.fileToolStripMenuItem.ForeColor = System.Drawing.Color.Silver;
this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
resources.ApplyResources(this.fileToolStripMenuItem, "fileToolStripMenuItem");
@@ -1064,6 +1074,26 @@
this.LittleEndianCheckBox.Theme = MetroFramework.MetroThemeStyle.Dark;
this.LittleEndianCheckBox.UseSelectable = true;
//
+ // recentlyOpenToolStripMenuItem
+ //
+ this.recentlyOpenToolStripMenuItem.Name = "recentlyOpenToolStripMenuItem";
+ resources.ApplyResources(this.recentlyOpenToolStripMenuItem, "recentlyOpenToolStripMenuItem");
+ //
+ // toolStripSeparator2
+ //
+ toolStripSeparator2.Name = "toolStripSeparator2";
+ resources.ApplyResources(toolStripSeparator2, "toolStripSeparator2");
+ //
+ // exitToolStripMenuItem
+ //
+ this.exitToolStripMenuItem.Name = "exitToolStripMenuItem";
+ resources.ApplyResources(this.exitToolStripMenuItem, "exitToolStripMenuItem");
+ //
+ // toolStripSeparator4
+ //
+ toolStripSeparator4.Name = "toolStripSeparator4";
+ resources.ApplyResources(toolStripSeparator4, "toolStripSeparator4");
+ //
// MainForm
//
this.ApplyImageInvert = true;
@@ -1212,6 +1242,8 @@
private System.Windows.Forms.ToolStripMenuItem moveDownToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem joinDevelopmentDiscordToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem trelloBoardToolStripMenuItem;
+ private System.Windows.Forms.ToolStripMenuItem recentlyOpenToolStripMenuItem;
+ private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem;
}
}
diff --git a/PCK-Studio/MainForm.cs b/PCK-Studio/MainForm.cs
index 4e8951f7..0e3430ab 100644
--- a/PCK-Studio/MainForm.cs
+++ b/PCK-Studio/MainForm.cs
@@ -30,14 +30,15 @@ using PckStudio.Extensions;
using PckStudio.Popups;
using PckStudio.Classes.Utils;
using PckStudio.Helper;
-using PCKStudio_Updater;
+using System.Text.RegularExpressions;
namespace PckStudio
{
public partial class MainForm : MetroFramework.Forms.MetroForm
{
private PckManager PckManager = null;
- string saveLocation = string.Empty;
+ string saveLocation;
+
PckFile currentPCK = null;
bool __modified = false;
@@ -189,16 +190,59 @@ namespace PckStudio
imageList.Images.Add(Resources.BEHAVIOURS_ICON); // Icon for Behaviour files (behaviours.bin)
imageList.Images.Add(Resources.ENTITY_MATERIALS_ICON); // Icon for Entity Material files (entityMaterials.bin)
+ LoadRecentFileList();
+
isSelectingTab = true;
tabControl.SelectTab(0);
isSelectingTab = false;
UpdateRichPresence();
- if (saveLocation != String.Empty) LoadPckFromFile(saveLocation);
+ if (!string.IsNullOrWhiteSpace(saveLocation))
+ LoadPckFromFile(saveLocation);
}
- private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
+ private void LoadRecentFileList()
+ {
+ Settings.Default.RecentFiles ??= new System.Collections.Specialized.StringCollection();
+ recentlyOpenToolStripMenuItem.DropDownItems.Clear();
+ for (int i = 0; i < Settings.Default.RecentFiles.Count && i < 5; i++)
+ {
+ string filepath = Settings.Default.RecentFiles[i];
+ if (!string.IsNullOrWhiteSpace(filepath))
+ {
+ string displayFilepath = Regex.Replace(filepath, @"([A-Z]{1}\:\\[Uu]sers\\)([^\\]*\\)(.*)", "~\\$3");
+ var item = recentlyOpenToolStripMenuItem.DropDownItems.Add(displayFilepath, null, HandleOpenFile);
+ item.Tag = filepath;
+ }
+ }
+ }
+
+ private void HandleOpenFile(object sender, EventArgs e)
+ {
+ if (((ToolStripMenuItem)sender).Tag is string filepath && File.Exists(filepath))
+ LoadPckFromFile(filepath);
+ }
+
+ private void SaveToRecentFiles(string filepath)
+ {
+ if (filepath is null || string.IsNullOrWhiteSpace(filepath))
+ return;
+ if (Settings.Default.RecentFiles.Contains(filepath))
+ Settings.Default.RecentFiles.Remove(filepath);
+ Settings.Default.RecentFiles.Insert(0, filepath);
+ if (Settings.Default.RecentFiles.Count > 5)
+ {
+ for (int i = 5; i < Settings.Default.RecentFiles.Count; i++)
+ {
+ Settings.Default.RecentFiles.RemoveAt(i);
+ }
+ }
+ Settings.Default.Save();
+ LoadRecentFileList();
+ }
+
+ private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
PckManager?.Close();
checkSaveState();
@@ -221,7 +265,8 @@ namespace PckStudio
{
isTemplateFile = false;
saveLocation = filePath;
- var reader = new PckFileReader(LittleEndianCheckBox.Checked ? OMI.Endianness.LittleEndian : OMI.Endianness.BigEndian);
+ SaveToRecentFiles(filePath);
+ var reader = new PckFileReader(LittleEndianCheckBox.Checked ? OMI.Endianness.LittleEndian : OMI.Endianness.BigEndian);
try
{
PckFile pck = reader.FromFile(filePath);
@@ -732,7 +777,8 @@ namespace PckStudio
{
Save(saveFileDialog.FileName);
saveLocation = saveFileDialog.FileName;
- pckFileLabel.Text = Path.GetFileName(saveLocation);
+ SaveToRecentFiles(saveFileDialog.FileName);
+ pckFileLabel.Text = Path.GetFileName(saveLocation);
isTemplateFile = false;
}
}
diff --git a/PCK-Studio/MainForm.resx b/PCK-Studio/MainForm.resx
index 365bcd92..45a6c015 100644
--- a/PCK-Studio/MainForm.resx
+++ b/PCK-Studio/MainForm.resx
@@ -1322,6 +1322,30 @@
False
+
+ False
+
+
+ 183, 6
+
+
+ 186, 22
+
+
+ Recently open
+
+
+ False
+
+
+ 183, 6
+
+
+ 186, 22
+
+
+ Exit
+
37, 20
@@ -7700,6 +7724,30 @@
System.Windows.Forms.ImageList, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+ recentlyOpenToolStripMenuItem
+
+
+ System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ toolStripSeparator2
+
+
+ System.Windows.Forms.ToolStripSeparator, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ exitToolStripMenuItem
+
+
+ System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ toolStripSeparator4
+
+
+ System.Windows.Forms.ToolStripSeparator, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
MainForm
diff --git a/PCK-Studio/Properties/Settings.Designer.cs b/PCK-Studio/Properties/Settings.Designer.cs
index 95fa109d..8acf7cc9 100644
--- a/PCK-Studio/Properties/Settings.Designer.cs
+++ b/PCK-Studio/Properties/Settings.Designer.cs
@@ -12,7 +12,7 @@ namespace PckStudio.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
- [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.7.0.0")]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.9.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
@@ -115,5 +115,16 @@ namespace PckStudio.Properties {
this["UseComboBoxForGRFParameter"] = value;
}
}
+
+ [global::System.Configuration.UserScopedSettingAttribute()]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ public global::System.Collections.Specialized.StringCollection RecentFiles {
+ get {
+ return ((global::System.Collections.Specialized.StringCollection)(this["RecentFiles"]));
+ }
+ set {
+ this["RecentFiles"] = value;
+ }
+ }
}
}
diff --git a/PCK-Studio/Properties/Settings.settings b/PCK-Studio/Properties/Settings.settings
index 2e32328f..1003231b 100644
--- a/PCK-Studio/Properties/Settings.settings
+++ b/PCK-Studio/Properties/Settings.settings
@@ -26,5 +26,8 @@
False
+
+
+
\ No newline at end of file