|
1 | 1 | using System; |
2 | 2 | using System.Collections.Generic; |
| 3 | +using System.ComponentModel; |
3 | 4 | using System.Diagnostics; |
4 | 5 | using System.IO; |
5 | 6 | using System.Linq; |
@@ -44,6 +45,7 @@ public partial class EditorElement : UserControl |
44 | 45 | private bool SelectionIsHighlited; |
45 | 46 | private bool WantFoldingUpdate; |
46 | 47 | public bool IsTemplateEditor = false; |
| 48 | + private bool Closed = false; |
47 | 49 |
|
48 | 50 | public string FullFilePath |
49 | 51 | { |
@@ -208,6 +210,12 @@ private void Editor_Loaded(object sender, RoutedEventArgs e) |
208 | 210 | ParseIncludes(sender, e); |
209 | 211 | } |
210 | 212 |
|
| 213 | + public void Editor_TabClosed(object sender, CancelEventArgs e) |
| 214 | + { |
| 215 | + e.Cancel = true; |
| 216 | + Close(); |
| 217 | + } |
| 218 | + |
211 | 219 | private async void TextArea_MouseDown(object sender, MouseButtonEventArgs e) |
212 | 220 | { |
213 | 221 | if (!Keyboard.IsKeyDown(Key.LeftCtrl) || IsTemplateEditor) |
@@ -269,8 +277,8 @@ private void FileWatcher_Changed(object sender, FileSystemEventArgs e) |
269 | 277 | } |
270 | 278 | catch (Exception) |
271 | 279 | { |
272 | | - // ignored |
273 | | - } |
| 280 | + // ignored |
| 281 | + } |
274 | 282 |
|
275 | 283 | Thread.Sleep( |
276 | 284 | 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) |
341 | 349 | StatusLine_Column.Text = $"{Program.Translations.Get("ColAbb")} {editor.TextArea.Caret.Column}"; |
342 | 350 | StatusLine_Line.Text = $"{Program.Translations.Get("LnAbb")} {editor.TextArea.Caret.Line}"; |
343 | 351 | #if DEBUG |
344 | | - StatusLine_Offset.Text = $"Off {editor.TextArea.Caret.Offset}"; |
| 352 | + StatusLine_Offset.Text = $"Off {editor.TextArea.Caret.Offset}"; |
345 | 353 | #endif |
346 | 354 | EvaluateIntelliSense(); |
347 | 355 |
|
@@ -687,8 +695,8 @@ private void ParseIncludes(object sender, EventArgs e) |
687 | 695 | var acNodes = smDef.ProduceACNodes(); |
688 | 696 | var isNodes = smDef.ProduceISNodes(); |
689 | 697 |
|
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); |
692 | 700 |
|
693 | 701 | foreach (var el in ee) |
694 | 702 | { |
@@ -724,33 +732,44 @@ public void UpdateFontSize(double size, bool updateLineHeight = true) |
724 | 732 |
|
725 | 733 | public async void Close(bool ForcedToSave = false, bool CheckSavings = true) |
726 | 734 | { |
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) |
738 | 736 | { |
739 | 737 | if (ForcedToSave) |
740 | 738 | { |
741 | 739 | Save(); |
742 | 740 | } |
743 | 741 | else |
744 | 742 | { |
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) |
750 | 748 | { |
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; |
752 | 758 | } |
753 | 759 | } |
| 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; |
754 | 773 | } |
755 | 774 |
|
756 | 775 | Parent = null; |
|
0 commit comments