Skip to content

Commit

Permalink
Fix: Issue #78, cancel on C64Studio closing (X) would still shut down
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgRottensteiner committed Jan 14, 2023
1 parent be89039 commit e70c3ad
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 25 deletions.
4 changes: 2 additions & 2 deletions C64Ass/C64Ass.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
<ItemGroup>
<Compile Remove="CompileConfig.cs" />
</ItemGroup>
<PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<PostBuildEvent Condition="'$(OS)' == 'Windows_NT' ">copy "$(TargetDir)C64Ass.exe" "$(SolutionDir)C64StudioRelease\C64Ass"</PostBuildEvent>
<PostBuildEvent Condition="'$(OS)' == 'Unix' ">cp "$(TargetDir)C64Ass.exe" "$(SolutionDir)C64StudioRelease\C64Ass"</PostBuildEvent>
</PropertyGroup>
<PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<PostBuildEvent>if not exist "$(SolutionDir)C64StudioRelease\$(TargetFramework)\C64Ass" md "$(SolutionDir)C64StudioRelease\$(TargetFramework)\C64Ass"
copy "$(TargetDir)C64Ass.exe" "$(SolutionDir)C64StudioRelease\$(TargetFramework)\C64Ass\C64Ass.exe"
copy "$(TargetDir)*.dll" "$(SolutionDir)C64StudioRelease\$(TargetFramework)\C64Ass"
Expand Down
10 changes: 8 additions & 2 deletions C64Studio/Documents/BaseDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -787,13 +787,19 @@ protected override void OnClosed( EventArgs e )
public virtual DialogResult CloseAfterModificationRequest()
{
System.Windows.Forms.DialogResult saveResult = DialogResult.Cancel;

var endButtons = MessageBoxButtons.YesNoCancel;
if ( Core.ShuttingDown )
{
endButtons = MessageBoxButtons.YesNo;
}
if ( string.IsNullOrEmpty( DocumentInfo.DocumentFilename ) )
{
saveResult = System.Windows.Forms.MessageBox.Show( "The unnamed document has been modified. Do you want to save the changes now?", "Save Changes?", MessageBoxButtons.YesNoCancel );
saveResult = System.Windows.Forms.MessageBox.Show( "The unnamed document has been modified. Do you want to save the changes now?", "Save Changes?", endButtons );
}
else
{
saveResult = System.Windows.Forms.MessageBox.Show( "The item " + DocumentInfo.DocumentFilename + " has been modified. Do you want to save the changes now?", "Save Changes?", MessageBoxButtons.YesNoCancel );
saveResult = System.Windows.Forms.MessageBox.Show( "The item " + DocumentInfo.DocumentFilename + " has been modified. Do you want to save the changes now?", "Save Changes?", endButtons );
}
if ( ( saveResult == DialogResult.Cancel )
|| ( saveResult == DialogResult.No ) )
Expand Down
8 changes: 7 additions & 1 deletion C64Studio/Documents/CharsetEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,13 @@ private void closeCharsetProjectToolStripMenuItem_Click( object sender, EventArg
}
if ( Modified )
{
DialogResult doSave = MessageBox.Show( "There are unsaved changes in your character set. Save now?", "Save changes?", MessageBoxButtons.YesNoCancel );
var endButtons = MessageBoxButtons.YesNoCancel;
if ( Core.ShuttingDown )
{
endButtons = MessageBoxButtons.YesNo;
}

DialogResult doSave = MessageBox.Show( "There are unsaved changes in your character set. Save now?", "Save changes?", endButtons );
if ( doSave == DialogResult.Cancel )
{
return;
Expand Down
7 changes: 6 additions & 1 deletion C64Studio/Documents/CharsetScreenEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1481,7 +1481,12 @@ private void closeCharsetProjectToolStripMenuItem_Click( object sender, EventArg
}
if ( Modified )
{
DialogResult doSave = MessageBox.Show( "There are unsaved changes in your character screen project. Save now?", "Save changes?", MessageBoxButtons.YesNoCancel );
var endButtons = MessageBoxButtons.YesNoCancel;
if ( Core.ShuttingDown )
{
endButtons = MessageBoxButtons.YesNo;
}
DialogResult doSave = MessageBox.Show( "There are unsaved changes in your character screen project. Save now?", "Save changes?", endButtons );
if ( doSave == DialogResult.Cancel )
{
return;
Expand Down
7 changes: 6 additions & 1 deletion C64Studio/Documents/GraphicScreenEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,12 @@ private void closeCharsetProjectToolStripMenuItem_Click( object sender, EventArg
}
if ( Modified )
{
DialogResult doSave = MessageBox.Show( "There are unsaved changes in your graphic screen. Save now?", "Save changes?", MessageBoxButtons.YesNoCancel );
var endButtons = MessageBoxButtons.YesNoCancel;
if ( Core.ShuttingDown )
{
endButtons = MessageBoxButtons.YesNo;
}
DialogResult doSave = MessageBox.Show( "There are unsaved changes in your graphic screen. Save now?", "Save changes?", endButtons );
if ( doSave == DialogResult.Cancel )
{
return;
Expand Down
7 changes: 6 additions & 1 deletion C64Studio/Documents/MapEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1430,7 +1430,12 @@ private void closeCharsetProjectToolStripMenuItem_Click( object sender, EventArg
}
if ( Modified )
{
DialogResult doSave = MessageBox.Show( "There are unsaved changes in your map project. Save now?", "Save changes?", MessageBoxButtons.YesNoCancel );
var endButtons = MessageBoxButtons.YesNoCancel;
if ( Core.ShuttingDown )
{
endButtons = MessageBoxButtons.YesNo;
}
DialogResult doSave = MessageBox.Show( "There are unsaved changes in your map project. Save now?", "Save changes?", endButtons );
if ( doSave == DialogResult.Cancel )
{
return;
Expand Down
7 changes: 6 additions & 1 deletion C64Studio/Documents/SpriteEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,12 @@ private void closeCharsetProjectToolStripMenuItem_Click( object sender, EventArg
}
if ( Modified )
{
DialogResult doSave = MessageBox.Show( "There are unsaved changes in your sprite set. Save now?", "Save changes?", MessageBoxButtons.YesNoCancel );
var endButtons = MessageBoxButtons.YesNoCancel;
if ( Core.ShuttingDown )
{
endButtons = MessageBoxButtons.YesNo;
}
DialogResult doSave = MessageBox.Show( "There are unsaved changes in your sprite set. Save now?", "Save changes?", endButtons );
if ( doSave == DialogResult.Cancel )
{
return;
Expand Down
7 changes: 6 additions & 1 deletion C64Studio/Documents/ValueTableEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,12 @@ private void closeCharsetProjectToolStripMenuItem_Click( object sender, EventArg
}
if ( Modified )
{
DialogResult doSave = MessageBox.Show( "There are unsaved changes in your value table project. Save now?", "Save changes?", MessageBoxButtons.YesNoCancel );
var endButtons = MessageBoxButtons.YesNoCancel;
if ( Core.ShuttingDown )
{
endButtons = MessageBoxButtons.YesNo;
}
DialogResult doSave = MessageBox.Show( "There are unsaved changes in your value table project. Save now?", "Save changes?", endButtons );
if ( doSave == DialogResult.Cancel )
{
return;
Expand Down
52 changes: 37 additions & 15 deletions C64Studio/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2997,7 +2997,12 @@ public bool CloseProject( Project ProjectToClose )

if ( changes )
{
DialogResult res = System.Windows.Forms.MessageBox.Show("There are changes in one or more items. Do you want to save them before closing?", "Unsaved changes, save now?", MessageBoxButtons.YesNoCancel);
var endButtons = MessageBoxButtons.YesNoCancel;
if ( StudioCore.ShuttingDown )
{
endButtons = MessageBoxButtons.YesNo;
}
DialogResult res = System.Windows.Forms.MessageBox.Show("There are changes in one or more items. Do you want to save them before closing?", "Unsaved changes, save now?", endButtons );
if ( res == DialogResult.Cancel )
{
return false;
Expand Down Expand Up @@ -5586,33 +5591,50 @@ private void MainForm_FormClosing( object sender, FormClosingEventArgs e )
}

// check ALL projects
List<string> itemsWithChanges = new List<string>();

foreach ( BaseDocument doc in panelMain.Documents )
{
if ( doc.Modified )
{
itemsWithChanges.Add( doc.Name );
}
}

if ( StudioCore.Navigating.Solution != null )
{
foreach ( Project project in StudioCore.Navigating.Solution.Projects )
{
if ( ( project != null )
&& ( project.Modified ) )
if ( project != null )
{
DialogResult result = System.Windows.Forms.MessageBox.Show( "The project " + project.Settings.Name + " has unsaved changes, save now?", "Save Project?", MessageBoxButtons.YesNoCancel );
if ( result == DialogResult.Cancel )
if ( project.Modified )
{
e.Cancel = true;
return;
itemsWithChanges.Add( project.Settings.Name );
}
e.Cancel = false;
if ( result == DialogResult.Yes )
foreach ( var element in project.Elements )
{
project.Save( project.Settings.Filename );
if ( ( element.Document != null )
&& ( element.Document.Modified ) )
{
itemsWithChanges.Add( element.Name );
}
}
}
else
{
e.Cancel = false;
}
}
}
SaveSettings();

if ( itemsWithChanges.Any() )
{
DialogResult result = System.Windows.Forms.MessageBox.Show( "There are unsaved changes, Really shut down?", "Unsaved changes! Shut down?", MessageBoxButtons.YesNo );
if ( result != DialogResult.Yes )
{
e.Cancel = true;
return;
}
}
e.Cancel = false;
StudioCore.ShuttingDown = true;
SaveSettings();
}


Expand Down

0 comments on commit e70c3ad

Please sign in to comment.