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

Commit

Permalink
fixes #108
Browse files Browse the repository at this point in the history
  • Loading branch information
maxijabase committed Dec 7, 2021
1 parent f58ffab commit 534946c
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 36 deletions.
63 changes: 41 additions & 22 deletions UI/Components/EditorElement/EditorElement.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -44,6 +45,7 @@ public partial class EditorElement : UserControl
private bool SelectionIsHighlited;
private bool WantFoldingUpdate;
public bool IsTemplateEditor = false;
private bool Closed = false;

public string FullFilePath
{
Expand Down Expand Up @@ -208,6 +210,12 @@ private void Editor_Loaded(object sender, RoutedEventArgs e)
ParseIncludes(sender, e);
}

public void Editor_TabClosed(object sender, CancelEventArgs e)
{
e.Cancel = true;
Close();
}

private async void TextArea_MouseDown(object sender, MouseButtonEventArgs e)
{
if (!Keyboard.IsKeyDown(Key.LeftCtrl) || IsTemplateEditor)
Expand Down Expand Up @@ -269,8 +277,8 @@ private void FileWatcher_Changed(object sender, FileSystemEventArgs e)
}
catch (Exception)
{
// ignored
}
// ignored
}
Thread.Sleep(
100); //dont include System.Threading in the using directives, cause its onlyused once and the Timer class will double
Expand Down Expand Up @@ -341,7 +349,7 @@ private void Caret_PositionChanged(object sender, EventArgs e)
StatusLine_Column.Text = $"{Program.Translations.Get("ColAbb")} {editor.TextArea.Caret.Column}";
StatusLine_Line.Text = $"{Program.Translations.Get("LnAbb")} {editor.TextArea.Caret.Line}";
#if DEBUG
StatusLine_Offset.Text = $"Off {editor.TextArea.Caret.Offset}";
StatusLine_Offset.Text = $"Off {editor.TextArea.Caret.Offset}";
#endif
EvaluateIntelliSense();

Expand Down Expand Up @@ -687,8 +695,8 @@ private void ParseIncludes(object sender, EventArgs e)
var acNodes = smDef.ProduceACNodes();
var isNodes = smDef.ProduceISNodes();
// Lags the hell out when typing a lot.
ce.editor.SyntaxHighlighting = new AeonEditorHighlighting(smDef);
// Lags the hell out when typing a lot.
ce.editor.SyntaxHighlighting = new AeonEditorHighlighting(smDef);
foreach (var el in ee)
{
Expand Down Expand Up @@ -724,33 +732,44 @@ public void UpdateFontSize(double size, bool updateLineHeight = true)

public async void Close(bool ForcedToSave = false, bool CheckSavings = true)
{
regularyTimer.Stop();
regularyTimer.Close();

if (fileWatcher != null)
{
fileWatcher.EnableRaisingEvents = false;
fileWatcher.Dispose();
fileWatcher = null;
}

if (CheckSavings && _NeedsSave)
if (CheckSavings && _NeedsSave && !Closed)
{
if (ForcedToSave)
{
Save();
}
else
{
var title = $"{Program.Translations.Get("SavingFile")} '" + Parent.Title.Trim('*') +
"'";
var Result = await Program.MainWindow.ShowMessageAsync(title, "",
MessageDialogStyle.AffirmativeAndNegative, Program.MainWindow.MetroDialogOptions);
if (Result == MessageDialogResult.Affirmative)
var result = await Program.MainWindow.ShowMessageAsync(
$"Do you want to save changes to '{Parent.Title.Substring(1)}'?",
"Your changes will be lost if you don't save them",
MessageDialogStyle.AffirmativeAndNegativeAndSingleAuxiliary, Program.MainWindow.ClosingDialogOptions);
switch (result)
{
Save();
case MessageDialogResult.Affirmative:
Closed = true;
Save();
break;
case MessageDialogResult.Negative:
Closed = true;
break;
case MessageDialogResult.FirstAuxiliary:
return;
}
}

}
Program.MainWindow.DockingPane.RemoveChild(Parent);
Program.MainWindow.UpdateOBFileButton();

regularyTimer.Stop();
regularyTimer.Close();

if (fileWatcher != null)
{
fileWatcher.EnableRaisingEvents = false;
fileWatcher.Dispose();
fileWatcher = null;
}

Parent = null;
Expand Down
24 changes: 12 additions & 12 deletions UI/MainWindow/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ public partial class MainWindow
Program.Translations.Get("CompileAll"),
Program.Translations.Get("CompileCurrent")
};

public MetroDialogSettings ClosingDialogOptions = new()
{
AffirmativeButtonText = Program.Translations.Get("Yes"),
NegativeButtonText = Program.Translations.Get("No"),
FirstAuxiliaryButtonText = Program.Translations.Get("Cancel"),
AnimateHide = false,
AnimateShow = false,
DefaultButtonFocus = MessageDialogResult.Affirmative
};
#endregion

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

// Build dialog buttons
var closeMetroDialogOptions = new MetroDialogSettings()
{
AffirmativeButtonText = Program.Translations.Get("Yes"),
NegativeButtonText = Program.Translations.Get("No"),
FirstAuxiliaryButtonText = Program.Translations.Get("Cancel"),
AnimateHide = false,
AnimateShow = false,
DefaultButtonFocus = MessageDialogResult.Affirmative
};

// Build list of unsaved files to show
var sb = new StringBuilder();
editors.Where(x => x.NeedsSave).ToList().ForEach(y => sb.AppendLine($" - {y.Parent.Title.Substring(1)}"));

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

switch (result)
{
Expand Down Expand Up @@ -427,6 +426,7 @@ private void AddEditorElement(FileInfo fInfo, string editorTitle, bool SelectMe,
EditorToFocus = editor;
SelectDocumentTimer.Start();
}
layoutDocument.Closing += editor.Editor_TabClosed;
}

/// <summary>
Expand Down
2 changes: 0 additions & 2 deletions UI/MainWindow/MainWindowCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,7 @@ private void Command_Close()
return;
}

DockingPane.RemoveChild(ee.Parent);
ee.Close();
UpdateOBFileButton();
}
catch (Exception ex)
{
Expand Down

0 comments on commit 534946c

Please sign in to comment.