-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c1d06f1
commit afae894
Showing
9 changed files
with
185 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using Rampastring.Tools; | ||
using System.Collections.Generic; | ||
using System.Globalization; | ||
using TSMapEditor.Misc; | ||
|
||
namespace TSMapEditor.Settings | ||
{ | ||
public class RecentFiles | ||
{ | ||
public const int MaxEntries = 4; | ||
private const string IniSectionName = "RecentFiles"; | ||
|
||
private List<string> entries = new List<string>(MaxEntries); | ||
|
||
public void PutEntry(string entry) | ||
{ | ||
int existingIndex = entries.IndexOf(entry); | ||
if (existingIndex == 0) | ||
return; | ||
|
||
if (existingIndex > -1) | ||
{ | ||
entries.Swap(0, existingIndex); | ||
} | ||
else | ||
{ | ||
entries.Insert(0, entry); | ||
TrimEntries(); | ||
} | ||
} | ||
|
||
public List<string> GetEntries() => new List<string>(entries); | ||
|
||
private void TrimEntries() | ||
{ | ||
if (entries.Count > MaxEntries) | ||
entries.RemoveRange(MaxEntries, entries.Count - MaxEntries); | ||
} | ||
|
||
public void WriteToIniFile(IniFile iniFile) | ||
{ | ||
iniFile.RemoveSection(IniSectionName); | ||
|
||
if (entries.Count == 0) | ||
return; | ||
|
||
var section = new IniSection(IniSectionName); | ||
for (int i = 0; i < entries.Count; i++) | ||
{ | ||
section.AddKey(i.ToString(CultureInfo.InvariantCulture), entries[i]); | ||
} | ||
iniFile.AddSection(section); | ||
} | ||
|
||
public void ReadFromIniFile(IniFile iniFile) | ||
{ | ||
var keys = iniFile.GetSectionKeys(IniSectionName); | ||
if (keys == null) | ||
return; | ||
|
||
foreach (string key in keys) | ||
{ | ||
string path = iniFile.GetStringValue(IniSectionName, key, string.Empty); | ||
if (!string.IsNullOrWhiteSpace(path)) | ||
entries.Add(path); | ||
} | ||
|
||
TrimEntries(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using Rampastring.XNAUI; | ||
using Rampastring.XNAUI.XNAControls; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Globalization; | ||
using TSMapEditor.Settings; | ||
using TSMapEditor.UI.Windows; | ||
|
||
namespace TSMapEditor.UI | ||
{ | ||
public class RecentFilesPanel : XNAPanel | ||
{ | ||
public RecentFilesPanel(WindowManager windowManager) : base(windowManager) | ||
{ | ||
BackgroundTexture = AssetLoader.CreateTexture(UISettings.ActiveSettings.BackgroundColor, 2, 2); | ||
} | ||
|
||
public EventHandler<FileSelectedEventArgs> FileSelected; | ||
|
||
private List<XNALinkLabel> fileLabels = new List<XNALinkLabel>(); | ||
|
||
public override void Initialize() | ||
{ | ||
Name = nameof(RecentFilesPanel); | ||
|
||
var entries = UserSettings.Instance.RecentFiles.GetEntries(); | ||
|
||
int y = Constants.UIEmptyTopSpace; | ||
|
||
for (int i = 0; i < entries.Count; i++) | ||
{ | ||
string path = entries[i]; // Necessary to define a new local here for the lambda to capture | ||
|
||
var fileLabel = new XNALinkLabel(WindowManager); | ||
fileLabel.Name = nameof(fileLabel) + i.ToString(CultureInfo.InvariantCulture); | ||
fileLabel.X = Constants.UIEmptySideSpace; | ||
fileLabel.Y = y; | ||
fileLabel.Text = (i + 1).ToString(CultureInfo.InvariantCulture) + ") " + string.Join(Environment.NewLine, Renderer.GetFixedTextLines(path, fileLabel.FontIndex, Width - fileLabel.X - Constants.UIEmptySideSpace)); | ||
fileLabel.Tag = entries[i]; | ||
fileLabel.LeftClick += (s, e) => FileSelected?.Invoke(this, new FileSelectedEventArgs(path)); | ||
AddChild(fileLabel); | ||
|
||
y += fileLabel.Height + (Constants.UIVerticalSpacing * 2); | ||
|
||
fileLabels.Add(fileLabel); | ||
} | ||
|
||
base.Initialize(); | ||
} | ||
|
||
public override void Kill() | ||
{ | ||
BackgroundTexture?.Dispose(); | ||
base.Kill(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters