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

Commit 534946c

Browse files
committed
fixes #108
1 parent f58ffab commit 534946c

File tree

3 files changed

+53
-36
lines changed

3 files changed

+53
-36
lines changed

UI/Components/EditorElement/EditorElement.xaml.cs

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.ComponentModel;
34
using System.Diagnostics;
45
using System.IO;
56
using System.Linq;
@@ -44,6 +45,7 @@ public partial class EditorElement : UserControl
4445
private bool SelectionIsHighlited;
4546
private bool WantFoldingUpdate;
4647
public bool IsTemplateEditor = false;
48+
private bool Closed = false;
4749

4850
public string FullFilePath
4951
{
@@ -208,6 +210,12 @@ private void Editor_Loaded(object sender, RoutedEventArgs e)
208210
ParseIncludes(sender, e);
209211
}
210212

213+
public void Editor_TabClosed(object sender, CancelEventArgs e)
214+
{
215+
e.Cancel = true;
216+
Close();
217+
}
218+
211219
private async void TextArea_MouseDown(object sender, MouseButtonEventArgs e)
212220
{
213221
if (!Keyboard.IsKeyDown(Key.LeftCtrl) || IsTemplateEditor)
@@ -269,8 +277,8 @@ private void FileWatcher_Changed(object sender, FileSystemEventArgs e)
269277
}
270278
catch (Exception)
271279
{
272-
// ignored
273-
}
280+
// ignored
281+
}
274282

275283
Thread.Sleep(
276284
100); //dont include System.Threading in the using directives, cause its onlyused once and the Timer class will double
@@ -341,7 +349,7 @@ private void Caret_PositionChanged(object sender, EventArgs e)
341349
StatusLine_Column.Text = $"{Program.Translations.Get("ColAbb")} {editor.TextArea.Caret.Column}";
342350
StatusLine_Line.Text = $"{Program.Translations.Get("LnAbb")} {editor.TextArea.Caret.Line}";
343351
#if DEBUG
344-
StatusLine_Offset.Text = $"Off {editor.TextArea.Caret.Offset}";
352+
StatusLine_Offset.Text = $"Off {editor.TextArea.Caret.Offset}";
345353
#endif
346354
EvaluateIntelliSense();
347355

@@ -687,8 +695,8 @@ private void ParseIncludes(object sender, EventArgs e)
687695
var acNodes = smDef.ProduceACNodes();
688696
var isNodes = smDef.ProduceISNodes();
689697

690-
// Lags the hell out when typing a lot.
691-
ce.editor.SyntaxHighlighting = new AeonEditorHighlighting(smDef);
698+
// Lags the hell out when typing a lot.
699+
ce.editor.SyntaxHighlighting = new AeonEditorHighlighting(smDef);
692700

693701
foreach (var el in ee)
694702
{
@@ -724,33 +732,44 @@ public void UpdateFontSize(double size, bool updateLineHeight = true)
724732

725733
public async void Close(bool ForcedToSave = false, bool CheckSavings = true)
726734
{
727-
regularyTimer.Stop();
728-
regularyTimer.Close();
729-
730-
if (fileWatcher != null)
731-
{
732-
fileWatcher.EnableRaisingEvents = false;
733-
fileWatcher.Dispose();
734-
fileWatcher = null;
735-
}
736-
737-
if (CheckSavings && _NeedsSave)
735+
if (CheckSavings && _NeedsSave && !Closed)
738736
{
739737
if (ForcedToSave)
740738
{
741739
Save();
742740
}
743741
else
744742
{
745-
var title = $"{Program.Translations.Get("SavingFile")} '" + Parent.Title.Trim('*') +
746-
"'";
747-
var Result = await Program.MainWindow.ShowMessageAsync(title, "",
748-
MessageDialogStyle.AffirmativeAndNegative, Program.MainWindow.MetroDialogOptions);
749-
if (Result == MessageDialogResult.Affirmative)
743+
var result = await Program.MainWindow.ShowMessageAsync(
744+
$"Do you want to save changes to '{Parent.Title.Substring(1)}'?",
745+
"Your changes will be lost if you don't save them",
746+
MessageDialogStyle.AffirmativeAndNegativeAndSingleAuxiliary, Program.MainWindow.ClosingDialogOptions);
747+
switch (result)
750748
{
751-
Save();
749+
case MessageDialogResult.Affirmative:
750+
Closed = true;
751+
Save();
752+
break;
753+
case MessageDialogResult.Negative:
754+
Closed = true;
755+
break;
756+
case MessageDialogResult.FirstAuxiliary:
757+
return;
752758
}
753759
}
760+
761+
}
762+
Program.MainWindow.DockingPane.RemoveChild(Parent);
763+
Program.MainWindow.UpdateOBFileButton();
764+
765+
regularyTimer.Stop();
766+
regularyTimer.Close();
767+
768+
if (fileWatcher != null)
769+
{
770+
fileWatcher.EnableRaisingEvents = false;
771+
fileWatcher.Dispose();
772+
fileWatcher = null;
754773
}
755774

756775
Parent = null;

UI/MainWindow/MainWindow.xaml.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@ public partial class MainWindow
5454
Program.Translations.Get("CompileAll"),
5555
Program.Translations.Get("CompileCurrent")
5656
};
57+
58+
public MetroDialogSettings ClosingDialogOptions = new()
59+
{
60+
AffirmativeButtonText = Program.Translations.Get("Yes"),
61+
NegativeButtonText = Program.Translations.Get("No"),
62+
FirstAuxiliaryButtonText = Program.Translations.Get("Cancel"),
63+
AnimateHide = false,
64+
AnimateShow = false,
65+
DefaultButtonFocus = MessageDialogResult.Affirmative
66+
};
5767
#endregion
5868

5969
#region Constructors
@@ -231,23 +241,12 @@ private async void MetroWindow_Closing(object sender, CancelEventArgs e)
231241
// Cancel closing to handle it manually
232242
e.Cancel = true;
233243

234-
// Build dialog buttons
235-
var closeMetroDialogOptions = new MetroDialogSettings()
236-
{
237-
AffirmativeButtonText = Program.Translations.Get("Yes"),
238-
NegativeButtonText = Program.Translations.Get("No"),
239-
FirstAuxiliaryButtonText = Program.Translations.Get("Cancel"),
240-
AnimateHide = false,
241-
AnimateShow = false,
242-
DefaultButtonFocus = MessageDialogResult.Affirmative
243-
};
244-
245244
// Build list of unsaved files to show
246245
var sb = new StringBuilder();
247246
editors.Where(x => x.NeedsSave).ToList().ForEach(y => sb.AppendLine($" - {y.Parent.Title.Substring(1)}"));
248247

249248
var result = await this.ShowMessageAsync("Save all files?", $"Unsaved files:\n{sb}",
250-
MessageDialogStyle.AffirmativeAndNegativeAndSingleAuxiliary, closeMetroDialogOptions);
249+
MessageDialogStyle.AffirmativeAndNegativeAndSingleAuxiliary, ClosingDialogOptions);
251250

252251
switch (result)
253252
{
@@ -427,6 +426,7 @@ private void AddEditorElement(FileInfo fInfo, string editorTitle, bool SelectMe,
427426
EditorToFocus = editor;
428427
SelectDocumentTimer.Start();
429428
}
429+
layoutDocument.Closing += editor.Editor_TabClosed;
430430
}
431431

432432
/// <summary>

UI/MainWindow/MainWindowCommands.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,7 @@ private void Command_Close()
343343
return;
344344
}
345345

346-
DockingPane.RemoveChild(ee.Parent);
347346
ee.Close();
348-
UpdateOBFileButton();
349347
}
350348
catch (Exception ex)
351349
{

0 commit comments

Comments
 (0)