Skip to content
This repository was archived by the owner on Sep 11, 2023. It is now read-only.

Commit b6951bc

Browse files
committed
fixed recent files menu not enabling, and limited to 10 items
1 parent d286129 commit b6951bc

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

UI/MainWindow/MainWindow.xaml.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ public bool TryLoadSourceFile(string filePath, out EditorElement outEditor, bool
309309
}
310310
}
311311

312-
AddEditorElement(finalPath, fileInfo.Name, SelectMe, out outEditor);
312+
AddEditorElement(fileInfo, fileInfo.Name, SelectMe, out outEditor);
313313
if (TryOpenIncludes && Program.OptionsObject.Program_OpenCustomIncludes)
314314
{
315315
using var textReader = fileInfo.OpenText();
@@ -374,17 +374,17 @@ public bool TryLoadSourceFile(string filePath, out EditorElement outEditor, bool
374374
/// Adds a new editor element associated with the file to the Docking Manager.
375375
/// </summary>
376376
/// <param name="filePath">The path of the file</param>
377-
/// <param name="name">The title of the tab</param>
377+
/// <param name="editorTitle">The title of the tab</param>
378378
/// <param name="SelectMe">Whether to focus this editor element once created.</param>
379-
private void AddEditorElement(string filePath, string name, bool SelectMe, out EditorElement editor)
379+
private void AddEditorElement(FileInfo fInfo, string editorTitle, bool SelectMe, out EditorElement editor)
380380
{
381-
var layoutDocument = new LayoutDocument { Title = name };
382-
layoutDocument.ToolTip = filePath;
383-
editor = new EditorElement(filePath) { Parent = layoutDocument };
381+
var layoutDocument = new LayoutDocument { Title = editorTitle };
382+
layoutDocument.ToolTip = fInfo.FullName;
383+
editor = new EditorElement(fInfo.FullName) { Parent = layoutDocument };
384384
layoutDocument.Content = editor;
385385
EditorsReferences.Add(editor);
386386
DockingPane.Children.Add(layoutDocument);
387-
AddNewRecentFile(filePath);
387+
AddNewRecentFile(fInfo);
388388
if (SelectMe)
389389
{
390390
layoutDocument.IsSelected = true;
@@ -403,7 +403,7 @@ private void AddDASMElement(FileInfo fileInfo)
403403
layoutDocument.Content = dasmElement;
404404
DockingPane.Children.Add(layoutDocument);
405405
DockingPane.SelectedContentIndex = DockingPane.ChildrenCount - 1;
406-
AddNewRecentFile(fileInfo.FullName);
406+
AddNewRecentFile(fileInfo);
407407
}
408408

409409
/// <summary>

UI/MainWindow/MainWindowCommands.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ private void Command_New()
9898

9999
File.Create(newFilePath).Close();
100100

101-
AddEditorElement(newFilePath, $"New Plugin ({newFileNum}).sp", true, out _);
101+
AddEditorElement(new FileInfo(newFilePath), $"New Plugin ({newFileNum}).sp", true, out _);
102102
RefreshObjectBrowser();
103103
}
104104

UI/MainWindow/MainWindowMenuHandler.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,12 +350,18 @@ private void LoadInputGestureTexts()
350350
}
351351
}
352352

353-
private void AddNewRecentFile(string filePath)
353+
private void AddNewRecentFile(FileInfo fInfo)
354354
{
355-
if (!Program.OptionsObject.RecentFiles.Any(x => x.Equals(filePath)))
355+
if (!Program.OptionsObject.RecentFiles.Any(x => x.Equals(fInfo.FullName)))
356356
{
357-
MenuI_Recent.Items.Insert(0, BuildRecentFileItem(filePath));
358-
Program.OptionsObject.RecentFiles.AddFirst(filePath);
357+
MenuI_Recent.Items.Insert(0, BuildRecentFileItem(fInfo.FullName));
358+
Program.OptionsObject.RecentFiles.AddFirst(fInfo.FullName);
359+
MenuI_Recent.IsEnabled = true;
360+
if (MenuI_Recent.Items.Count > 10)
361+
{
362+
Program.OptionsObject.RecentFiles.RemoveLast();
363+
MenuI_Recent.Items.RemoveAt(10);
364+
}
359365
}
360366
}
361367

0 commit comments

Comments
 (0)