1
0
mirror of https://github.com/fadden/6502bench.git synced 2024-10-02 21:54:31 +00:00

Add change discard confirmation to project properties editor

It's too easy to hit Escape after making a bunch of changes, so
now we ask for confirmation.

(Might make sense to make this strictly an Esc guard, and not
pester the user if they actually hit the Cancel button or close
box.  I'm not convinced though; Esc+Enter isn't terrible.)
This commit is contained in:
Andy McFadden 2019-11-04 17:39:59 -08:00
parent 6411df7ff9
commit 6a8d6950e5
3 changed files with 17 additions and 2 deletions

View File

@ -25,7 +25,7 @@ limitations under the License.
Title="Edit Project Properties"
Width="640" Height="400" ResizeMode="NoResize"
ShowInTaskbar="False" WindowStartupLocation="CenterOwner"
Loaded="Window_Loaded">
Loaded="Window_Loaded" Closing="Window_Closing">
<Window.Resources>
<!-- don't center the column headers -->
@ -33,6 +33,9 @@ limitations under the License.
<Setter Property="HorizontalContentAlignment" Value="Left" />
</Style>
<system:String x:Key="str_ConfirmDiscardChanges">Some changes have not been applied. Discard them?</system:String>
<system:String x:Key="str_ConfirmDiscardChangesCaption">Discard Changes?</system:String>
<!-- strings for combo boxes -->
<system:String x:Key="str_6502">MOS 6502</system:String>
<system:String x:Key="str_65C02">WDC W65C02S</system:String>

View File

@ -149,6 +149,18 @@ namespace SourceGen.WpfGui {
UpdateControls();
}
private void Window_Closing(object sender, CancelEventArgs e) {
if (IsDirty) {
string msg = (string)FindResource("str_ConfirmDiscardChanges");
string caption = (string)FindResource("str_ConfirmDiscardChangesCaption");
MessageBoxResult result = MessageBox.Show(msg, caption, MessageBoxButton.OKCancel,
MessageBoxImage.Question);
if (result == MessageBoxResult.Cancel) {
e.Cancel = true;
}
}
}
private void ApplyButton_Click(object sender, RoutedEventArgs e) {
NewProps = new ProjectProperties(mWorkProps);
IsDirty = false;
@ -160,6 +172,7 @@ namespace SourceGen.WpfGui {
// insufficient. Might be best to just let the UndoableChange stuff figure out
// that nothing changed.
NewProps = new ProjectProperties(mWorkProps);
IsDirty = false;
DialogResult = true;
//GridView view = (GridView)projectSymbolsListView.View;

View File

@ -341,7 +341,6 @@ namespace SourceGen.WpfGui {
}
if (!mMainCtrl.WindowClosing()) {
e.Cancel = true;
return;
}
}