Skip to content

Commit

Permalink
Fixed saving problem when executing scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergiu Marton committed Aug 2, 2018
1 parent 1714b83 commit 67808c9
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions PseudoEditor/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ private void New_Executed(object sender, ExecutedRoutedEventArgs e)
_currentFileName = saveFileDialog.FileName;
File.Create(_currentFileName).Close();
Editor.Load(_currentFileName);
ShowFileName();
_isFileSaved = true;
}
}

Expand All @@ -103,23 +105,35 @@ private void Open_Executed(object sender, ExecutedRoutedEventArgs e)
_currentFileName = dialog.FileName;
Editor.Load(_currentFileName);
ShowFileName();
_isFileSaved = true;
}
}

private void Save_Executed(object sender, ExecutedRoutedEventArgs e)
{
SaveFile();
}

private void SaveAs_Executed(object sender, ExecutedRoutedEventArgs e)
{
SaveFileAs();
}

private void SaveFile()
{
if (_currentFileName == null)
{
SaveAs_Executed(sender, e);
SaveFileAs();
}
else
{
Editor.Save(_currentFileName);
ShowFileName();
_isFileSaved = true;
}
}

private void SaveAs_Executed(object sender, ExecutedRoutedEventArgs e)
private void SaveFileAs()
{
var dialog = new SaveFileDialog
{
Expand All @@ -135,6 +149,7 @@ private void SaveAs_Executed(object sender, ExecutedRoutedEventArgs e)
_currentFileName = dialog.FileName;
Editor.Save(_currentFileName);
ShowFileName();
_isFileSaved = true;
}
}

Expand All @@ -148,6 +163,7 @@ private void Editor_OnTextChanged(object sender, EventArgs e)
if (_currentFileName != null)
{
ShowFileNameChanged();
_isFileSaved = true;
}
}

Expand Down Expand Up @@ -182,7 +198,12 @@ private void ComboBoxFontName_OnLoaded(object sender, RoutedEventArgs e)

private void Execute_Executed(object sender, ExecutedRoutedEventArgs e)
{
var process = Process.Start(InterpreterName, $"{_currentFileName} diagnostics");
SaveFile();

if (_isFileSaved)
{
var process = Process.Start(InterpreterName, $"{_currentFileName} diagnostics");
}
}

private void About_Executed(object sender, ExecutedRoutedEventArgs e)
Expand Down

0 comments on commit 67808c9

Please sign in to comment.