Fix OSX button order issue in Unsaved Changes dialog.

Also changes the presentation of the string when the checkbox appears
so that the "Changes will be lost" warning isn't hidden by the turndown.
This last part may require conditional compilation as it's undocumented.

Lastly, regularizes the Unsaved Changes strings between the apps.
This commit is contained in:
Jeff Young 2019-06-17 16:59:39 +01:00
parent 8085899d0a
commit 4eab89d9ef
13 changed files with 53 additions and 37 deletions

View File

@ -152,21 +152,25 @@ long KIDIALOG::getStyle( KD_TYPE aType )
} }
int UnsavedChangesDialog( wxWindow* parent, const wxString& aMessage, bool* aApplyToAll ) int UnsavedChangesDialog( wxWindow* parent, wxString aMessage, bool* aApplyToAll )
{ {
static bool s_apply_to_all = false;
wxRichMessageDialog dlg( parent, aMessage, wxEmptyString, wxRichMessageDialog dlg( parent, aMessage, wxEmptyString,
wxYES_NO | wxCANCEL | wxYES_DEFAULT | wxICON_WARNING | wxCENTER ); wxYES_NO | wxCANCEL | wxYES_DEFAULT | wxICON_WARNING | wxCENTER );
dlg.ShowDetailedText( _( "If you don't save, all your changes will be permanently lost." ) ); dlg.SetExtendedMessage( _( "If you don't save, all your changes will be permanently lost." ) );
dlg.SetYesNoLabels( wxMessageDialog::ButtonLabel( _( "Save" ) ), dlg.SetYesNoLabels( _( "Save" ), _( "Discard Changes" ) );
wxMessageDialog::ButtonLabel( _( "Discard Changes" ) ) );
if( aApplyToAll ) if( aApplyToAll )
dlg.ShowCheckBox( _( "Apply to all" ), true ); dlg.ShowCheckBox( _( "Apply to all" ), s_apply_to_all );
int ret = dlg.ShowModal(); int ret = dlg.ShowModal();
if( aApplyToAll ) if( aApplyToAll )
{
*aApplyToAll = dlg.IsCheckBoxChecked(); *aApplyToAll = dlg.IsCheckBoxChecked();
s_apply_to_all = dlg.IsCheckBoxChecked();
}
// Returns wxID_YES, wxID_NO, or wxID_CANCEL // Returns wxID_YES, wxID_NO, or wxID_CANCEL
return ret; return ret;
@ -175,14 +179,18 @@ int UnsavedChangesDialog( wxWindow* parent, const wxString& aMessage, bool* aApp
int UnsavedChangesDialog( wxWindow* parent, const wxString& aMessage ) int UnsavedChangesDialog( wxWindow* parent, const wxString& aMessage )
{ {
#ifdef __APPLE__
// wxWidgets gets the button order wrong on Mac so use the other dialog.
return UnsavedChangesDialog( parent, aMessage, nullptr );
#else
wxMessageDialog dlg( parent, aMessage, wxEmptyString, wxMessageDialog dlg( parent, aMessage, wxEmptyString,
wxYES_NO | wxCANCEL | wxYES_DEFAULT | wxICON_WARNING | wxCENTER ); wxYES_NO | wxCANCEL | wxYES_DEFAULT | wxICON_WARNING | wxCENTER );
dlg.SetExtendedMessage( _( "If you don't save, all your changes will be permanently lost." ) ); dlg.SetExtendedMessage( _( "If you don't save, all your changes will be permanently lost." ) );
dlg.SetYesNoLabels( wxMessageDialog::ButtonLabel( _( "Save" ) ), dlg.SetYesNoLabels( _( "Save" ), _( "Discard Changes" ) );
wxMessageDialog::ButtonLabel( _( "Discard Changes" ) ) );
// Returns wxID_YES, wxID_NO, or wxID_CANCEL // Returns wxID_YES, wxID_NO, or wxID_CANCEL
return dlg.ShowModal(); return dlg.ShowModal();
#endif
} }
@ -191,8 +199,7 @@ bool ConfirmRevertDialog( wxWindow* parent, const wxString& aMessage )
wxMessageDialog dlg( parent, aMessage, wxEmptyString, wxMessageDialog dlg( parent, aMessage, wxEmptyString,
wxOK | wxCANCEL | wxOK_DEFAULT | wxICON_WARNING | wxCENTER ); wxOK | wxCANCEL | wxOK_DEFAULT | wxICON_WARNING | wxCENTER );
dlg.SetExtendedMessage( _( "Your current changes will be permanently lost." ) ); dlg.SetExtendedMessage( _( "Your current changes will be permanently lost." ) );
dlg.SetOKCancelLabels( wxMessageDialog::ButtonLabel( _( "Revert" ) ), dlg.SetOKCancelLabels( _( "Revert" ), _( "Cancel" ) );
wxMessageDialog::ButtonLabel( _( "Cancel" ) ) );
return dlg.ShowModal() == wxID_OK; return dlg.ShowModal() == wxID_OK;
} }
@ -217,8 +224,7 @@ int OKOrCancelDialog( wxWindow* aParent, const wxString& aWarning, const wxStrin
wxRichMessageDialog dlg( aParent, aMessage, wxEmptyString, wxRichMessageDialog dlg( aParent, aMessage, wxEmptyString,
wxOK | wxCANCEL | wxOK_DEFAULT | wxICON_WARNING | wxCENTER ); wxOK | wxCANCEL | wxOK_DEFAULT | wxICON_WARNING | wxCENTER );
dlg.ShowDetailedText( _( "If you don't save, all your changes will be permanently lost." ) ); dlg.ShowDetailedText( _( "If you don't save, all your changes will be permanently lost." ) );
dlg.SetOKCancelLabels( wxMessageDialog::ButtonLabel( aOKLabel ), dlg.SetOKCancelLabels( aOKLabel, aCancelLabel );
wxMessageDialog::ButtonLabel( aCancelLabel ) );
if( aApplyToAll ) if( aApplyToAll )
dlg.ShowCheckBox( _( "Apply to all" ), true ); dlg.ShowCheckBox( _( "Apply to all" ), true );
@ -241,7 +247,8 @@ void DisplayError( wxWindow* parent, const wxString& text, int displaytime )
int icon = displaytime > 0 ? wxICON_INFORMATION : wxICON_ERROR; int icon = displaytime > 0 ? wxICON_INFORMATION : wxICON_ERROR;
dialog = new wxMessageDialog( parent, text, _( "Warning" ), dialog = new wxMessageDialog( parent, text, _( "Warning" ),
wxOK | wxCENTRE | wxRESIZE_BORDER | icon | wxSTAY_ON_TOP ); wxOK | wxCENTRE | wxRESIZE_BORDER |
icon | wxSTAY_ON_TOP );
dialog->ShowModal(); dialog->ShowModal();
dialog->Destroy(); dialog->Destroy();

View File

@ -274,7 +274,7 @@ void CVPCB_MAINFRAME::OnCloseWindow( wxCloseEvent& Event )
if( m_modified ) if( m_modified )
{ {
if( !HandleUnsavedChanges( this, _( "Symbol to Footprint links have been modified. " if( !HandleUnsavedChanges( this, _( "Symbol to Footprint links have been modified. "
"Save before exit?" ), "Save changes?" ),
[&]()->bool { return SaveFootprintAssociation( false ); } ) ) [&]()->bool { return SaveFootprintAssociation( false ); } ) )
{ {
Event.Veto(); Event.Veto();

View File

@ -907,7 +907,8 @@ bool SCH_EDIT_FRAME::AskToSaveChanges()
{ {
if( screen->IsModify() ) if( screen->IsModify() )
{ {
if( !HandleUnsavedChanges( this, _( "The current schematic has been modified. Save changes?" ), if( !HandleUnsavedChanges( this, _( "The current schematic has been modified. "
"Save changes?" ),
[&]()->bool { return SaveProject(); } ) ) [&]()->bool { return SaveProject(); } ) )
{ {
return false; return false;

View File

@ -148,7 +148,8 @@ bool LIB_EDIT_FRAME::LoadComponentAndSelectLib( const LIB_ID& aLibId, int aUnit,
if( GetScreen()->IsModify() && GetCurPart() ) if( GetScreen()->IsModify() && GetCurPart() )
{ {
if( !HandleUnsavedChanges( this, _( "The current symbol has been modified. Save changes?" ), if( !HandleUnsavedChanges( this, _( "The current symbol has been modified. "
"Save changes?" ),
[&]()->bool { return saveCurrentPart(); } ) ) [&]()->bool { return saveCurrentPart(); } ) )
{ {
return false; return false;

View File

@ -517,10 +517,10 @@ void SCH_EDIT_FRAME::OnCloseWindow( wxCloseEvent& aEvent )
if( sheetList.IsModified() ) if( sheetList.IsModified() )
{ {
wxString fileName = Prj().AbsolutePath( g_RootSheet->GetScreen()->GetFileName() ); wxFileName fileName = g_RootSheet->GetScreen()->GetFileName();
wxString msg = _( "Save changes to\n\"%s\"\nbefore closing?" ); wxString msg = _( "Save changes to \"%s\" before closing?" );
if( !HandleUnsavedChanges( this, wxString::Format( msg, fileName ), if( !HandleUnsavedChanges( this, wxString::Format( msg, fileName.GetFullName() ),
[&]()->bool { return SaveProject(); } ) ) [&]()->bool { return SaveProject(); } ) )
{ {
aEvent.Veto(); aEvent.Veto();

View File

@ -154,9 +154,8 @@ wxString SCH_SHEET_PATH::Path() const
s = wxT( "/" ); // This is the root path s = wxT( "/" ); // This is the root path
// start at 1 to avoid the root sheet, // Start at 1 to avoid the root sheet, which does not need to be added to the path.
// which does not need to be added to the path // It's timestamp changes anyway.
// it's timestamp changes anyway.
for( unsigned i = 1; i < size(); i++ ) for( unsigned i = 1; i < size(); i++ )
{ {
t.Printf( _( "%8.8lX/" ), (long unsigned) at( i )->GetTimeStamp() ); t.Printf( _( "%8.8lX/" ), (long unsigned) at( i )->GetTimeStamp() );
@ -171,13 +170,14 @@ wxString SCH_SHEET_PATH::PathHumanReadable() const
{ {
wxString s; wxString s;
if( size() == 1 )
return _( "<root sheet>" );
s = wxT( "/" ); s = wxT( "/" );
// start at 1 to avoid the root sheet, as above. // Start at 1 to avoid the root sheet, as above.
for( unsigned i = 1; i < size(); i++ ) for( unsigned i = 1; i < size(); i++ )
{
s = s + at( i )->GetName() + wxT( "/" ); s = s + at( i )->GetName() + wxT( "/" );
}
return s; return s;
} }

View File

@ -95,7 +95,7 @@ bool HandleUnsavedChanges( wxWindow* aParent, const wxString& aMessage,
* written back to the bool. * written back to the bool.
* @return wxID_YES, wxID_CANCEL, wxID_NO. * @return wxID_YES, wxID_CANCEL, wxID_NO.
*/ */
int UnsavedChangesDialog( wxWindow* aParent, const wxString& aMessage, bool* aApplyToAll ); int UnsavedChangesDialog( wxWindow* aParent, wxString aMessage, bool* aApplyToAll );
int UnsavedChangesDialog( wxWindow* aParent, const wxString& aMessage ); int UnsavedChangesDialog( wxWindow* aParent, const wxString& aMessage );

View File

@ -57,8 +57,8 @@ void PL_EDITOR_FRAME::OnFileHistory( wxCommandEvent& event )
{ {
if( GetScreen()->IsModify() ) if( GetScreen()->IsModify() )
{ {
if( !HandleUnsavedChanges( this, if( !HandleUnsavedChanges( this, _( "The current page layout has been modified. "
_( "The current page layout has been modified. Save changes?" ), "Save changes?" ),
[&]()->bool { return saveCurrentPageLayout(); } ) ) [&]()->bool { return saveCurrentPageLayout(); } ) )
{ {
return; return;
@ -92,7 +92,8 @@ void PL_EDITOR_FRAME::Files_io( wxCommandEvent& event )
if( ( id == wxID_NEW || id == wxID_OPEN ) && GetScreen()->IsModify() ) if( ( id == wxID_NEW || id == wxID_OPEN ) && GetScreen()->IsModify() )
{ {
if( !HandleUnsavedChanges( this, _( "The current page layout has been modified. Save changes?" ), if( !HandleUnsavedChanges( this, _( "The current page layout has been modified. "
"Save changes?" ),
[&]()->bool { return saveCurrentPageLayout(); } ) ) [&]()->bool { return saveCurrentPageLayout(); } ) )
{ {
return; return;

View File

@ -241,8 +241,10 @@ void PL_EDITOR_FRAME::OnCloseWindow( wxCloseEvent& Event )
{ {
if( GetScreen()->IsModify() ) if( GetScreen()->IsModify() )
{ {
if( !HandleUnsavedChanges( this, wxFileName filename = GetCurrFileName();
_( "The current page layout has been modified. Save changes?" ), wxString msg = _( "Save changes to \"%s\" before closing?" );
if( !HandleUnsavedChanges( this, wxString::Format( msg, filename.GetFullName() ),
[&]()->bool { return saveCurrentPageLayout(); } ) ) [&]()->bool { return saveCurrentPageLayout(); } ) )
{ {
Event.Veto(); Event.Veto();

View File

@ -451,7 +451,10 @@ void FOOTPRINT_EDIT_FRAME::OnCloseWindow( wxCloseEvent& Event )
{ {
if( GetScreen()->IsModify() && GetBoard()->GetFirstModule() ) if( GetScreen()->IsModify() && GetBoard()->GetFirstModule() )
{ {
if( !HandleUnsavedChanges( this, _( "Save changes to footprint before closing?" ), wxString footprintName = GetBoard()->GetFirstModule()->GetFPID().GetLibItemName();
wxString msg = _( "Save changes to \"%s\" before closing? " );
if( !HandleUnsavedChanges( this, wxString::Format( msg, footprintName ),
[&]() -> bool { return SaveFootprint( GetBoard()->GetFirstModule() ); } ) ) [&]() -> bool { return SaveFootprint( GetBoard()->GetFirstModule() ); } ) )
{ {
Event.Veto(); Event.Veto();

View File

@ -206,8 +206,8 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
if( GetScreen()->IsModify() && !GetBoard()->IsEmpty() ) if( GetScreen()->IsModify() && !GetBoard()->IsEmpty() )
{ {
if( !HandleUnsavedChanges( this, if( !HandleUnsavedChanges( this, _( "The current footprint has been modified. "
_( "The current footprint has been modified. Save changes?" ), "Save changes?" ),
[&]() -> bool { [&]() -> bool {
return SaveFootprint( GetBoard()->GetFirstModule() ); return SaveFootprint( GetBoard()->GetFirstModule() );
} ) ) } ) )

View File

@ -104,8 +104,8 @@ bool FOOTPRINT_EDIT_FRAME::Clear_Pcb( bool aQuery )
{ {
wxSafeYield( this, true ); // Allow frame to come to front before showing warning. wxSafeYield( this, true ); // Allow frame to come to front before showing warning.
if( !HandleUnsavedChanges( this, if( !HandleUnsavedChanges( this, _( "The current footprint has been modified. "
_( "The current footprint has been modified. Save changes?" ), "Save changes?" ),
[&]() -> bool { return SaveFootprint( GetBoard()->Modules().front() ); } ) ) [&]() -> bool { return SaveFootprint( GetBoard()->Modules().front() ); } ) )
{ {
return false; return false;

View File

@ -463,9 +463,10 @@ void PCB_EDIT_FRAME::OnCloseWindow( wxCloseEvent& Event )
{ {
if( GetScreen()->IsModify() && !GetBoard()->IsEmpty() ) if( GetScreen()->IsModify() && !GetBoard()->IsEmpty() )
{ {
wxString msg = _( "Save changes to\n\"%s\"\nbefore closing?" ); wxFileName fileName = GetBoard()->GetFileName();
wxString msg = _( "Save changes to \"%s\" before closing?" );
if( !HandleUnsavedChanges( this, wxString::Format( msg, GetBoard()->GetFileName() ), if( !HandleUnsavedChanges( this, wxString::Format( msg, fileName.GetFullName() ),
[&]()->bool { return Files_io_from_id( ID_SAVE_BOARD ); } ) ) [&]()->bool { return Files_io_from_id( ID_SAVE_BOARD ); } ) )
{ {
Event.Veto(); Event.Veto();