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

Commit 5748746

Browse files
committed
polishing new closing options for files
1 parent 9ddf33b commit 5748746

File tree

4 files changed

+13
-47
lines changed

4 files changed

+13
-47
lines changed

UI/Components/EditorElement/EditorElement.xaml.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public partial class EditorElement : UserControl
4646
private bool WantFoldingUpdate;
4747
public bool IsTemplateEditor = false;
4848
private bool Closed = false;
49+
public bool ClosingPromptOpened = false;
4950

5051
public string FullFilePath
5152
{
@@ -740,10 +741,12 @@ public async void Close(bool ForcedToSave = false, bool CheckSavings = true)
740741
}
741742
else
742743
{
744+
ClosingPromptOpened = true;
743745
var result = await Program.MainWindow.ShowMessageAsync(
744746
$"Do you want to save changes to '{Parent.Title.Substring(1)}'?",
745747
"Your changes will be lost if you don't save them",
746748
MessageDialogStyle.AffirmativeAndNegativeAndSingleAuxiliary, Program.MainWindow.ClosingDialogOptions);
749+
ClosingPromptOpened = false;
747750
switch (result)
748751
{
749752
case MessageDialogResult.Affirmative:
@@ -774,7 +777,7 @@ public async void Close(bool ForcedToSave = false, bool CheckSavings = true)
774777

775778
Parent = null;
776779

777-
Program.MainWindow.EditorsReferences.Remove(this);
780+
Program.MainWindow.EditorReferences.Remove(this);
778781
Program.MainWindow.MenuI_ReopenLastClosedTab.IsEnabled = true;
779782
Program.RecentFilesStack.Push(FullFilePath);
780783
Program.MainWindow.UpdateWindowTitle();

UI/MainWindow/MainWindow.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public partial class MainWindow
3131
#region Variables
3232
private readonly Storyboard BlendOverEffect;
3333
private readonly Storyboard DisableServerAnim;
34-
public readonly List<EditorElement> EditorsReferences = new();
34+
public readonly List<EditorElement> EditorReferences = new();
3535
public readonly List<DASMElement> DASMReferences = new();
3636
private readonly Storyboard EnableServerAnim;
3737
public readonly List<MenuItem> MenuItems;
@@ -416,7 +416,7 @@ private void AddEditorElement(FileInfo fInfo, string editorTitle, bool SelectMe,
416416
layoutDocument.ToolTip = fInfo.FullName;
417417
editor = new EditorElement(fInfo.FullName) { Parent = layoutDocument };
418418
layoutDocument.Content = editor;
419-
EditorsReferences.Add(editor);
419+
EditorReferences.Add(editor);
420420
DockingPane.Children.Add(layoutDocument);
421421
AddNewRecentFile(fInfo);
422422
if (SelectMe)

UI/MainWindow/MainWindowCommands.cs

Lines changed: 5 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public DASMElement GetCurrentDASMElement()
6868
/// <returns></returns>
6969
public EditorElement[] GetAllEditorElements()
7070
{
71-
return EditorsReferences.Count < 1 ? null : EditorsReferences.ToArray();
71+
return EditorReferences.Count < 1 ? null : EditorReferences.ToArray();
7272
}
7373

7474
/// <summary>
@@ -338,7 +338,7 @@ private void Command_Close()
338338
try
339339
{
340340
var ee = GetCurrentEditorElement();
341-
if (ee == null || ee.IsTemplateEditor)
341+
if (ee == null || ee.IsTemplateEditor || ee.ClosingPromptOpened)
342342
{
343343
return;
344344
}
@@ -359,50 +359,13 @@ private async void Command_CloseAll()
359359
try
360360
{
361361
var editors = GetAllEditorElements();
362-
if (editors == null || GetCurrentEditorElement().IsTemplateEditor)
362+
363+
if (editors == null || GetCurrentEditorElement().IsTemplateEditor || editors.Length == 0 || editors.Any(x => x.ClosingPromptOpened))
363364
{
364365
return;
365366
}
366367

367-
if (editors.Length > 0)
368-
{
369-
var UnsavedEditorsExisting = false;
370-
foreach (var editor in editors)
371-
{
372-
UnsavedEditorsExisting |= editor.NeedsSave;
373-
}
374-
375-
var ForceSave = false;
376-
if (UnsavedEditorsExisting)
377-
{
378-
var str = new StringBuilder();
379-
for (var i = 0; i < editors.Length; ++i)
380-
{
381-
if (i == 0)
382-
{
383-
str.Append(editors[i].Parent.Title.Trim('*'));
384-
}
385-
else
386-
{
387-
str.AppendLine(editors[i].Parent.Title.Trim('*'));
388-
}
389-
}
390-
391-
var result = await this.ShowMessageAsync(Program.Translations.Get("SaveFollow"),
392-
str.ToString(), MessageDialogStyle.AffirmativeAndNegative, MetroDialogOptions);
393-
if (result == MessageDialogResult.Affirmative)
394-
{
395-
ForceSave = true;
396-
}
397-
}
398-
399-
foreach (var editor in editors)
400-
{
401-
DockingPane.RemoveChild(editor.Parent);
402-
editor.Close(ForceSave, ForceSave);
403-
}
404-
}
405-
UpdateOBFileButton();
368+
editors.ToList().ForEach(x => x.Close());
406369
}
407370
catch (Exception ex)
408371
{

UI/Windows/NewFileWindow.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public NewFileWindow()
100100
ParseTemplateFile();
101101
Language_Translate();
102102
PreviewBox.Parent = new LayoutDocument();
103-
Program.MainWindow.EditorsReferences.Add(PreviewBox);
103+
Program.MainWindow.EditorReferences.Add(PreviewBox);
104104
if (Program.OptionsObject.Program_AccentColor != "Red" || Program.OptionsObject.Program_Theme != "BaseDark")
105105
{
106106
ThemeManager.ChangeAppStyle(this, ThemeManager.GetAccent(Program.OptionsObject.Program_AccentColor),
@@ -279,7 +279,7 @@ private void NewFileWind_KeyDown(object sender, KeyEventArgs e)
279279

280280
private void NewFileWind_Closing(object sender, CancelEventArgs e)
281281
{
282-
Program.MainWindow.EditorsReferences.Remove(PreviewBox);
282+
Program.MainWindow.EditorReferences.Remove(PreviewBox);
283283
}
284284

285285
#endregion

0 commit comments

Comments
 (0)