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

Commit 9f16660

Browse files
committed
added Reopen Last File feature
1 parent 5571623 commit 9f16660

File tree

10 files changed

+48
-17
lines changed

10 files changed

+48
-17
lines changed

Interop/HotkeyControl.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public class HotkeyControl
1111
{ "New", "Ctrl+N" },
1212
{ "NewTemplate", "Ctrl+Shift+N" },
1313
{ "Open", "Ctrl+O" },
14+
{ "ReopenLastClosedTab", "Ctrl+Shift+T" },
1415
{ "Save", "Ctrl+S" },
1516
{ "SaveAll", "Ctrl+Shift+S" },
1617
{ "SaveAs", "Ctrl+Alt+S" },

Interop/TranslationProvider.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ private void FillToEnglishDefaults()
367367
language.Add("EnableRPCFile", "Show current file");
368368
language.Add("TemplateExists", "Template name already exists");
369369
language.Add("IllegalCharacters", "Illegal characters");
370+
language.Add("ReopenLastClosedTab", "Reopen the last closed tab");
370371
}
371372
}
372373
}

Program.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ public static class Program
3030
public static Config[] Configs;
3131
public static int SelectedConfig;
3232
public static string SelectedTemplatePath;
33-
33+
public static Stack<string> RecentFilesStack = new();
3434
public static UpdateInfo UpdateStatus;
35-
3635
public static bool RCCKMade;
3736
public static DiscordRpcClient DiscordClient = new(Constants.DiscordRPCAppID);
3837
public static Timestamps DiscordTime = Timestamps.Now;

UI/Components/DASMElement/DASMElement.xaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,7 @@ private void Treeview__SelectedItemChanged(object sender, RoutedPropertyChangedE
923923
public void Close()
924924
{
925925
Program.MainWindow.DASMReferences.Remove(this);
926+
Program.RecentFilesStack.Push(FilePath);
926927
Program.MainWindow.UpdateWindowTitle();
927928
}
928929

UI/Components/EditorElement/EditorElement.xaml.cs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -747,30 +747,28 @@ public async void Close(bool ForcedToSave = false, bool CheckSavings = true)
747747
fileWatcher = null;
748748
}
749749

750-
if (CheckSavings)
750+
if (CheckSavings && _NeedsSave)
751751
{
752-
if (_NeedsSave)
752+
if (ForcedToSave)
753753
{
754-
if (ForcedToSave)
754+
Save();
755+
}
756+
else
757+
{
758+
var title = $"{Program.Translations.GetLanguage("SavingFile")} '" + Parent.Title.Trim('*') +
759+
"'";
760+
var Result = await Program.MainWindow.ShowMessageAsync(title, "",
761+
MessageDialogStyle.AffirmativeAndNegative, Program.MainWindow.MetroDialogOptions);
762+
if (Result == MessageDialogResult.Affirmative)
755763
{
756764
Save();
757765
}
758-
else
759-
{
760-
var title = $"{Program.Translations.GetLanguage("SavingFile")} '" + Parent.Title.Trim('*') +
761-
"'";
762-
var Result = await Program.MainWindow.ShowMessageAsync(title, "",
763-
MessageDialogStyle.AffirmativeAndNegative, Program.MainWindow.MetroDialogOptions);
764-
if (Result == MessageDialogResult.Affirmative)
765-
{
766-
Save();
767-
}
768-
}
769766
}
770767
}
771768

772769
Program.MainWindow.EditorsReferences.Remove(this);
773-
770+
Program.MainWindow.MenuI_ReopenLastClosedTab.IsEnabled = true;
771+
Program.RecentFilesStack.Push(FullFilePath);
774772
Parent = null; //to prevent a ring depency which disables the GC from work
775773
Program.MainWindow.UpdateWindowTitle();
776774
}

UI/MainWindow/MainWindow.xaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,12 @@
9898
<Grid x:Name="MainWindowCommands">
9999
<Menu>
100100
<MenuItem x:Name="MenuI_File" Header="File" SubmenuOpened="FileMenu_Open">
101+
101102
<MenuItem x:Name="MenuI_New" Header="New" Click="Menu_New"/>
102103
<MenuItem x:Name="MenuI_NewTemplate" Header="New From Template" Click="Menu_NewFromTemplate"/>
104+
105+
<Separator/>
106+
103107
<MenuItem x:Name="MenuI_Open" Header="Open" Click="Menu_Open"/>
104108
<MenuItem x:Name="MenuI_Recent" Header="Recent files">
105109
<MenuItem.ContextMenu>
@@ -108,13 +112,19 @@
108112
</ContextMenu>
109113
</MenuItem.ContextMenu>
110114
</MenuItem>
115+
<MenuItem x:Name="MenuI_ReopenLastClosedTab" Header="Reopen last tab" Click="Menu_ReopenLastClosedTab"/>
116+
111117
<Separator />
118+
112119
<MenuItem x:Name="MenuI_Save" Header="Save" Click="Menu_Save"/>
113120
<MenuItem x:Name="MenuI_SaveAll" Header="Save All" Click="Menu_SaveAll"/>
114121
<MenuItem x:Name="MenuI_SaveAs" Header="Save As" Click="Menu_SaveAs"/>
122+
115123
<Separator />
124+
116125
<MenuItem x:Name="MenuI_Close" Header="Close" Click="Menu_Close"/>
117126
<MenuItem x:Name="MenuI_CloseAll" Header="Close All" Click="Menu_CloseAll"/>
127+
118128
</MenuItem>
119129

120130
<MenuItem x:Name="MenuI_Edit" Header="Edit" SubmenuOpened="EditMenu_Open">

UI/MainWindow/MainWindow.xaml.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ public MainWindow(SplashScreen sc)
127127
LoadCommandsDictionary();
128128
LoadRecentsList();
129129

130+
MenuI_ReopenLastClosedTab.IsEnabled = false;
131+
130132
UpdateOBFileButton();
131133

132134
SearchCooldownTimer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(300) };

UI/MainWindow/MainWindowCommands.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,5 +517,17 @@ private void Command_OpenSPDef()
517517
};
518518
spDefinitionWindow.ShowDialog();
519519
}
520+
/// <summary>
521+
/// Re-opens the last closed tab
522+
/// </summary>
523+
private void Command_ReopenLastClosedTab()
524+
{
525+
if (Program.RecentFilesStack.Count > 0)
526+
{
527+
TryLoadSourceFile(Program.RecentFilesStack.Pop(), out _, true, false, true);
528+
}
529+
530+
MenuI_ReopenLastClosedTab.IsEnabled = Program.RecentFilesStack.Count > 0;
531+
}
520532
}
521533
}

UI/MainWindow/MainWindowInputHandler.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ private void LoadCommandsDictionary()
6565
{ "New", Command_New },
6666
{ "NewTemplate", Command_NewFromTemplate },
6767
{ "Open", Command_Open },
68+
{ "ReopenLastClosedTab", Command_ReopenLastClosedTab },
6869
{ "Save", Command_Save },
6970
{ "SaveAll", Command_SaveAll },
7071
{ "SaveAs", Command_SaveAs },

UI/MainWindow/MainWindowMenuHandler.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ private void Menu_ClearRecent(object sender, RoutedEventArgs e)
4444
MenuI_Recent.IsEnabled = false;
4545
}
4646

47+
private void Menu_ReopenLastClosedTab(object sender, RoutedEventArgs e)
48+
{
49+
Command_ReopenLastClosedTab();
50+
}
51+
4752
private void Menu_New(object sender, RoutedEventArgs e)
4853
{
4954
Command_New();
@@ -411,6 +416,7 @@ private MenuItem BuildRecentFileItem(string file)
411416
TryLoadSourceFile(fInfo.FullName, out _, true, false, true);
412417
};
413418

419+
// Return the MenuItem
414420
return mi;
415421
}
416422
#endregion

0 commit comments

Comments
 (0)