From dee77873baee3c54902d8b4b8f7f9a47ca2289c2 Mon Sep 17 00:00:00 2001 From: Justin Aquadro Date: Sun, 2 Sep 2012 19:15:37 -0400 Subject: [PATCH] Recent files and directories lists preserved accross sessions. --- MainForm.Designer.cs | 26 ++++++++++++ MainForm.cs | 73 ++++++++++++++++++++++++++++++++- MainForm.resx | 60 +++++++++++++-------------- Model/RegionFileDataNode.cs | 20 +++++++++ NBTExplorer.csproj | 9 ++++ Properties/Settings.Designer.cs | 48 ++++++++++++++++++++++ Properties/Settings.settings | 12 ++++++ app.config | 2 + 8 files changed, 218 insertions(+), 32 deletions(-) create mode 100644 Properties/Settings.Designer.cs create mode 100644 Properties/Settings.settings diff --git a/MainForm.Designer.cs b/MainForm.Designer.cs index 1bee627..1d3fd1d 100644 --- a/MainForm.Designer.cs +++ b/MainForm.Designer.cs @@ -86,6 +86,9 @@ this.ContentPanel = new System.Windows.Forms.ToolStripContentPanel(); this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); this.testToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this._menuItemRecentFiles = new System.Windows.Forms.ToolStripMenuItem(); + this._menuItemRecentFolders = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripSeparator8 = new System.Windows.Forms.ToolStripSeparator(); this.menuStrip1.SuspendLayout(); this.toolStrip1.SuspendLayout(); this.contextMenuStrip1.SuspendLayout(); @@ -113,6 +116,9 @@ this.toolStripSeparator3, this._menuItemSave, this.toolStripSeparator4, + this._menuItemRecentFiles, + this._menuItemRecentFolders, + this.toolStripSeparator8, this._menuItemExit}); this.fileToolStripMenuItem.Name = "fileToolStripMenuItem"; this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20); @@ -605,6 +611,23 @@ this.testToolStripMenuItem.Size = new System.Drawing.Size(96, 22); this.testToolStripMenuItem.Text = "Test"; // + // _menuItemRecentFiles + // + this._menuItemRecentFiles.Name = "_menuItemRecentFiles"; + this._menuItemRecentFiles.Size = new System.Drawing.Size(223, 22); + this._menuItemRecentFiles.Text = "Recent Files"; + // + // _menuItemRecentFolders + // + this._menuItemRecentFolders.Name = "_menuItemRecentFolders"; + this._menuItemRecentFolders.Size = new System.Drawing.Size(223, 22); + this._menuItemRecentFolders.Text = "Recent Folders"; + // + // toolStripSeparator8 + // + this.toolStripSeparator8.Name = "toolStripSeparator8"; + this.toolStripSeparator8.Size = new System.Drawing.Size(220, 6); + // // MainForm // this.AllowDrop = true; @@ -687,6 +710,9 @@ private System.Windows.Forms.ToolStripSeparator toolStripSeparator6; private System.Windows.Forms.ContextMenuStrip contextMenuStrip1; private System.Windows.Forms.ToolStripMenuItem testToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem _menuItemRecentFiles; + private System.Windows.Forms.ToolStripMenuItem _menuItemRecentFolders; + private System.Windows.Forms.ToolStripSeparator toolStripSeparator8; } } diff --git a/MainForm.cs b/MainForm.cs index c8626a7..348946a 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -7,6 +7,8 @@ using System.Windows.Forms; using NBTExplorer.Forms; using NBTExplorer.Model; using Substrate.Nbt; +using NBTExplorer.Properties; +using System.Collections.Specialized; namespace NBTExplorer { @@ -95,6 +97,8 @@ namespace NBTExplorer else { OpenMinecraftDirectory(); } + + UpdateOpenMenu(); } private void InitializeIconRegistry () @@ -119,7 +123,7 @@ namespace NBTExplorer _iconRegistry.Register(typeof(TagIntArrayDataNode), 14); } - public void OpenFile () + private void OpenFile () { OpenFileDialog ofd = new OpenFileDialog(); ofd.RestoreDirectory = true; @@ -146,7 +150,7 @@ namespace NBTExplorer UpdateUI(); } - public void OpenPaths (string[] paths) + private void OpenPaths (string[] paths) { _nodeTree.Nodes.Clear(); @@ -154,10 +158,14 @@ namespace NBTExplorer if (Directory.Exists(path)) { DirectoryDataNode node = new DirectoryDataNode(path); _nodeTree.Nodes.Add(CreateUnexpandedNode(node)); + + AddPathToHistory(Settings.Default.RecentDirectories, path); } else if (File.Exists(path)) { NbtFileDataNode node = NbtFileDataNode.TryCreateFrom(path); _nodeTree.Nodes.Add(CreateUnexpandedNode(node)); + + AddPathToHistory(Settings.Default.RecentFiles, path); } } @@ -166,6 +174,7 @@ namespace NBTExplorer } UpdateUI(); + UpdateOpenMenu(); } private void OpenMinecraftDirectory () @@ -658,10 +667,60 @@ namespace NBTExplorer _menuItemFindNext.Enabled = _searchState != null; } + private void UpdateOpenMenu () + { + try { + if (Settings.Default.RecentDirectories == null) + Settings.Default.RecentDirectories = new StringCollection(); + if (Settings.Default.RecentFiles == null) + Settings.Default.RecentFiles = new StringCollection(); + } + catch { + return; + } + + _menuItemRecentFolders.DropDown = BuildRecentEntriesDropDown(Settings.Default.RecentDirectories); + _menuItemRecentFiles.DropDown = BuildRecentEntriesDropDown(Settings.Default.RecentFiles); + } + + private ToolStripDropDown BuildRecentEntriesDropDown (StringCollection list) + { + if (list == null || list.Count == 0) + return new ToolStripDropDown(); + + ToolStripDropDown menu = new ToolStripDropDown(); + foreach (string entry in list) { + ToolStripMenuItem item = new ToolStripMenuItem("&" + (menu.Items.Count + 1) + " " + entry); + item.Tag = entry; + item.Click += _menuItemRecentPaths_Click; + + menu.Items.Add(item); + } + + return menu; + } + + private void AddPathToHistory (StringCollection list, string entry) + { + foreach (string item in list) { + if (item == entry) { + list.Remove(item); + break; + } + } + + while (list.Count >= 5) + list.RemoveAt(list.Count - 1); + + list.Insert(0, entry); + } + #region Event Handlers private void MainForm_Closing (object sender, CancelEventArgs e) { + Settings.Default.RecentFiles = Settings.Default.RecentFiles; + Settings.Default.Save(); if (!ConfirmExit()) e.Cancel = true; } @@ -844,6 +903,7 @@ namespace NBTExplorer private void _menuItemExit_Click (object sender, EventArgs e) { + Settings.Default.Save(); Close(); } @@ -892,6 +952,15 @@ namespace NBTExplorer new About().ShowDialog(); } + private void _menuItemRecentPaths_Click (object sender, EventArgs e) + { + ToolStripMenuItem item = sender as ToolStripMenuItem; + if (item == null || !(item.Tag is string)) + return; + + OpenPaths(new string[] { item.Tag as string }); + } + #endregion #endregion diff --git a/MainForm.resx b/MainForm.resx index 8f89107..f77388b 100644 --- a/MainForm.resx +++ b/MainForm.resx @@ -112,15 +112,15 @@ 2.0 - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + 17, 17 - + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 @@ -335,7 +335,7 @@ QtiJ+A2+oxJO8d3MEAAAAABJRU5ErkJggg== - + 237, 17 @@ -343,7 +343,7 @@ AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0 ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAADQ - MwAAAk1TRnQBSQFMAgEBEAEAARABAQEQAQEBEAEAARABAAT/ARkBAAj/AUIBTQE2BwABNgMAASgDAAFA + MwAAAk1TRnQBSQFMAgEBEAEAARgBAQEYAQEBEAEAARABAAT/ARkBAAj/AUIBTQE2BwABNgMAASgDAAFA AwABUAMAAQEBAAEYBgABPP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AB4AA/wD+SH4A/kD/AMAA/0D+SH4 A/kD/TkAA/8D/AP5EvgD+QP7A/4GAAGWAakBvAFcAYQBrgFcAYQBr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PI7N3Mfoc0AVv/Rx0N4UO9jM8ZPgqBhvSE7Y3EHqxwKtOzm8RFAcsT3u1kgE6 - iGGIYfh/2Hdq4Y7iRPNcr2bgN3SrJ86cZttBAAAAAElFTkSuQmCC + YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAJQSURBVDhPhVJdaJJRGFbRLhSnOGQU3dQggroTYjoQTQ3X + KMX/zc/l0qWJ/z9JZtgocdBdEWNdBEFBF9vNGI3ASpK6iEV2EQxGQfRD0W0X0S6ezvvht32tUR88nPe8 + z/M+5/3ecyQS0SeVSmcZFmkV5yn+F7elZaKlarUKtVrd3mlAOeJIs5Pj94y4qtfrX9ntdtDKcFsQUizm + SPuXCUsuN5tNlEol5HIl6HS6nhjEVasXkM3mqYvl3QxWGo0GIhEOXm8YBoMB+XyeB8XExWIxeDwBMljZ + zWC1Xq9jcnICJpOJLxLD4XAgGo3C5fKSweofBixxXavVrtP/C0UulwupVIoHxZS32238SlqqEU+/XavV + 2L9n4fP5YDSaoNFoNsTw+/3IZDKIx+MMSepi+6bYplMulzE1xbFT7Bgf90OlUr1nVzdCoLhSqbAZnMXY + mBNOp5sMOuIOuoVCAeHwBKxWKxN4oFQqPwgCiovFIpvBGdguPYBtpkUGXbHBi2w2i1AoALPZDIfDBblc + /kkQUJzL5fgbMl3rMDzD0GhoQ2zwMp1OY3o6ys8gGOSgUCi+kOBIs7ewN7f4a3T2MYxX2jh2+RHmPwMH + k0s/jjZfc8Ir7FksFthsx7dugZ36jcjhi921Gx+B1Fsg8mYbpXWAOKGLd4lEAhzHsStzs4cUgkwm+06k + 7vTcwmDg5ubh8/dxKHkPwzN3MfIc0AVv/Rx0t/gO9jM8ZPgqBhvSE7Y3EPoxz6tOzm0SFAcsT/u1kgE6 + iGGIYd//sOfU/B3Fida5fs3Ab3OLJ81GwikSAAAAAElFTkSuQmCC - + 347, 17 diff --git a/Model/RegionFileDataNode.cs b/Model/RegionFileDataNode.cs index b22562a..cfc0215 100644 --- a/Model/RegionFileDataNode.cs +++ b/Model/RegionFileDataNode.cs @@ -62,4 +62,24 @@ namespace NBTExplorer.Model Nodes.Clear(); } } + + public class RegionFile256 : RegionFile + { + private const int _sectorBytes = 256; + private static byte[] _emptySector = new byte[_sectorBytes]; + + public RegionFile256 (string path) + : base(path) + { } + + protected override int SectorBytes + { + get { return _sectorBytes; } + } + + protected override byte[] EmptySector + { + get { return _emptySector; } + } + } } diff --git a/NBTExplorer.csproj b/NBTExplorer.csproj index 0b26b23..734b01d 100644 --- a/NBTExplorer.csproj +++ b/NBTExplorer.csproj @@ -161,6 +161,11 @@ + + True + True + Settings.settings + @@ -230,6 +235,10 @@ + + SettingsSingleFileGenerator + Settings.Designer.cs + diff --git a/Properties/Settings.Designer.cs b/Properties/Settings.Designer.cs new file mode 100644 index 0000000..029c8a1 --- /dev/null +++ b/Properties/Settings.Designer.cs @@ -0,0 +1,48 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.269 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace NBTExplorer.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + + [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; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + public global::System.Collections.Specialized.StringCollection RecentDirectories { + get { + return ((global::System.Collections.Specialized.StringCollection)(this["RecentDirectories"])); + } + set { + this["RecentDirectories"] = value; + } + } + } +} diff --git a/Properties/Settings.settings b/Properties/Settings.settings new file mode 100644 index 0000000..86f5808 --- /dev/null +++ b/Properties/Settings.settings @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/app.config b/app.config index a5b20d3..0a7adb0 100644 --- a/app.config +++ b/app.config @@ -1,5 +1,7 @@ + +