From 4eab89d9eff9a7abb183f56fff554f5aed9a67e5 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Mon, 17 Jun 2019 16:59:39 +0100 Subject: [PATCH] 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. --- common/confirm.cpp | 31 ++++++++++++++++----------- cvpcb/cvpcb_mainframe.cpp | 2 +- eeschema/files-io.cpp | 3 ++- eeschema/libedit/libedit.cpp | 3 ++- eeschema/sch_edit_frame.cpp | 6 +++--- eeschema/sch_sheet_path.cpp | 12 +++++------ include/confirm.h | 2 +- pagelayout_editor/files.cpp | 7 +++--- pagelayout_editor/pl_editor_frame.cpp | 6 ++++-- pcbnew/footprint_edit_frame.cpp | 5 ++++- pcbnew/footprint_editor_utils.cpp | 4 ++-- pcbnew/initpcb.cpp | 4 ++-- pcbnew/pcb_edit_frame.cpp | 5 +++-- 13 files changed, 53 insertions(+), 37 deletions(-) diff --git a/common/confirm.cpp b/common/confirm.cpp index 9c9f2d9992..fbb038b4d0 100644 --- a/common/confirm.cpp +++ b/common/confirm.cpp @@ -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, wxYES_NO | wxCANCEL | wxYES_DEFAULT | wxICON_WARNING | wxCENTER ); - dlg.ShowDetailedText( _( "If you don't save, all your changes will be permanently lost." ) ); - dlg.SetYesNoLabels( wxMessageDialog::ButtonLabel( _( "Save" ) ), - wxMessageDialog::ButtonLabel( _( "Discard Changes" ) ) ); + dlg.SetExtendedMessage( _( "If you don't save, all your changes will be permanently lost." ) ); + dlg.SetYesNoLabels( _( "Save" ), _( "Discard Changes" ) ); if( aApplyToAll ) - dlg.ShowCheckBox( _( "Apply to all" ), true ); + dlg.ShowCheckBox( _( "Apply to all" ), s_apply_to_all ); int ret = dlg.ShowModal(); if( aApplyToAll ) + { *aApplyToAll = dlg.IsCheckBoxChecked(); + s_apply_to_all = dlg.IsCheckBoxChecked(); + } // Returns wxID_YES, wxID_NO, or wxID_CANCEL return ret; @@ -175,14 +179,18 @@ int UnsavedChangesDialog( wxWindow* parent, const wxString& aMessage, bool* aApp 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, wxYES_NO | wxCANCEL | wxYES_DEFAULT | wxICON_WARNING | wxCENTER ); dlg.SetExtendedMessage( _( "If you don't save, all your changes will be permanently lost." ) ); - dlg.SetYesNoLabels( wxMessageDialog::ButtonLabel( _( "Save" ) ), - wxMessageDialog::ButtonLabel( _( "Discard Changes" ) ) ); + dlg.SetYesNoLabels( _( "Save" ), _( "Discard Changes" ) ); // Returns wxID_YES, wxID_NO, or wxID_CANCEL return dlg.ShowModal(); +#endif } @@ -191,8 +199,7 @@ bool ConfirmRevertDialog( wxWindow* parent, const wxString& aMessage ) wxMessageDialog dlg( parent, aMessage, wxEmptyString, wxOK | wxCANCEL | wxOK_DEFAULT | wxICON_WARNING | wxCENTER ); dlg.SetExtendedMessage( _( "Your current changes will be permanently lost." ) ); - dlg.SetOKCancelLabels( wxMessageDialog::ButtonLabel( _( "Revert" ) ), - wxMessageDialog::ButtonLabel( _( "Cancel" ) ) ); + dlg.SetOKCancelLabels( _( "Revert" ), _( "Cancel" ) ); return dlg.ShowModal() == wxID_OK; } @@ -217,8 +224,7 @@ int OKOrCancelDialog( wxWindow* aParent, const wxString& aWarning, const wxStrin wxRichMessageDialog dlg( aParent, aMessage, wxEmptyString, wxOK | wxCANCEL | wxOK_DEFAULT | wxICON_WARNING | wxCENTER ); dlg.ShowDetailedText( _( "If you don't save, all your changes will be permanently lost." ) ); - dlg.SetOKCancelLabels( wxMessageDialog::ButtonLabel( aOKLabel ), - wxMessageDialog::ButtonLabel( aCancelLabel ) ); + dlg.SetOKCancelLabels( aOKLabel, aCancelLabel ); if( aApplyToAll ) 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; 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->Destroy(); diff --git a/cvpcb/cvpcb_mainframe.cpp b/cvpcb/cvpcb_mainframe.cpp index acdff63e0e..3b3576d193 100644 --- a/cvpcb/cvpcb_mainframe.cpp +++ b/cvpcb/cvpcb_mainframe.cpp @@ -274,7 +274,7 @@ void CVPCB_MAINFRAME::OnCloseWindow( wxCloseEvent& Event ) if( m_modified ) { if( !HandleUnsavedChanges( this, _( "Symbol to Footprint links have been modified. " - "Save before exit?" ), + "Save changes?" ), [&]()->bool { return SaveFootprintAssociation( false ); } ) ) { Event.Veto(); diff --git a/eeschema/files-io.cpp b/eeschema/files-io.cpp index 64be90fcb6..48d57eaf96 100644 --- a/eeschema/files-io.cpp +++ b/eeschema/files-io.cpp @@ -907,7 +907,8 @@ bool SCH_EDIT_FRAME::AskToSaveChanges() { 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(); } ) ) { return false; diff --git a/eeschema/libedit/libedit.cpp b/eeschema/libedit/libedit.cpp index 4e0b4ad403..d8df3717c3 100644 --- a/eeschema/libedit/libedit.cpp +++ b/eeschema/libedit/libedit.cpp @@ -148,7 +148,8 @@ bool LIB_EDIT_FRAME::LoadComponentAndSelectLib( const LIB_ID& aLibId, int aUnit, 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(); } ) ) { return false; diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index 026be726ca..24b01a64c3 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -517,10 +517,10 @@ void SCH_EDIT_FRAME::OnCloseWindow( wxCloseEvent& aEvent ) if( sheetList.IsModified() ) { - wxString fileName = Prj().AbsolutePath( g_RootSheet->GetScreen()->GetFileName() ); - wxString msg = _( "Save changes to\n\"%s\"\nbefore closing?" ); + wxFileName fileName = g_RootSheet->GetScreen()->GetFileName(); + 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(); } ) ) { aEvent.Veto(); diff --git a/eeschema/sch_sheet_path.cpp b/eeschema/sch_sheet_path.cpp index e176ff0bc1..4f0afbea6b 100644 --- a/eeschema/sch_sheet_path.cpp +++ b/eeschema/sch_sheet_path.cpp @@ -154,9 +154,8 @@ wxString SCH_SHEET_PATH::Path() const s = wxT( "/" ); // This is the root path - // start at 1 to avoid the root sheet, - // which does not need to be added to the path - // it's timestamp changes anyway. + // Start at 1 to avoid the root sheet, which does not need to be added to the path. + // It's timestamp changes anyway. for( unsigned i = 1; i < size(); i++ ) { t.Printf( _( "%8.8lX/" ), (long unsigned) at( i )->GetTimeStamp() ); @@ -171,13 +170,14 @@ wxString SCH_SHEET_PATH::PathHumanReadable() const { wxString s; + if( size() == 1 ) + return _( "" ); + 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++ ) - { s = s + at( i )->GetName() + wxT( "/" ); - } return s; } diff --git a/include/confirm.h b/include/confirm.h index 430e48a26d..9b2dbe1ca0 100644 --- a/include/confirm.h +++ b/include/confirm.h @@ -95,7 +95,7 @@ bool HandleUnsavedChanges( wxWindow* aParent, const wxString& aMessage, * written back to the bool. * @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 ); diff --git a/pagelayout_editor/files.cpp b/pagelayout_editor/files.cpp index 0415a99435..c47f7e138a 100644 --- a/pagelayout_editor/files.cpp +++ b/pagelayout_editor/files.cpp @@ -57,8 +57,8 @@ void PL_EDITOR_FRAME::OnFileHistory( wxCommandEvent& event ) { if( 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(); } ) ) { return; @@ -92,7 +92,8 @@ void PL_EDITOR_FRAME::Files_io( wxCommandEvent& event ) 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(); } ) ) { return; diff --git a/pagelayout_editor/pl_editor_frame.cpp b/pagelayout_editor/pl_editor_frame.cpp index 217ac383c9..010ab94588 100644 --- a/pagelayout_editor/pl_editor_frame.cpp +++ b/pagelayout_editor/pl_editor_frame.cpp @@ -241,8 +241,10 @@ void PL_EDITOR_FRAME::OnCloseWindow( wxCloseEvent& Event ) { if( GetScreen()->IsModify() ) { - if( !HandleUnsavedChanges( this, - _( "The current page layout has been modified. Save changes?" ), + wxFileName filename = GetCurrFileName(); + wxString msg = _( "Save changes to \"%s\" before closing?" ); + + if( !HandleUnsavedChanges( this, wxString::Format( msg, filename.GetFullName() ), [&]()->bool { return saveCurrentPageLayout(); } ) ) { Event.Veto(); diff --git a/pcbnew/footprint_edit_frame.cpp b/pcbnew/footprint_edit_frame.cpp index af0aa9393d..ec9d48fd32 100644 --- a/pcbnew/footprint_edit_frame.cpp +++ b/pcbnew/footprint_edit_frame.cpp @@ -451,7 +451,10 @@ void FOOTPRINT_EDIT_FRAME::OnCloseWindow( wxCloseEvent& Event ) { 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() ); } ) ) { Event.Veto(); diff --git a/pcbnew/footprint_editor_utils.cpp b/pcbnew/footprint_editor_utils.cpp index bdb0d6fb3c..0e77c05ae9 100644 --- a/pcbnew/footprint_editor_utils.cpp +++ b/pcbnew/footprint_editor_utils.cpp @@ -206,8 +206,8 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) if( GetScreen()->IsModify() && !GetBoard()->IsEmpty() ) { - if( !HandleUnsavedChanges( this, - _( "The current footprint has been modified. Save changes?" ), + if( !HandleUnsavedChanges( this, _( "The current footprint has been modified. " + "Save changes?" ), [&]() -> bool { return SaveFootprint( GetBoard()->GetFirstModule() ); } ) ) diff --git a/pcbnew/initpcb.cpp b/pcbnew/initpcb.cpp index 7685463b10..f3ec088a18 100644 --- a/pcbnew/initpcb.cpp +++ b/pcbnew/initpcb.cpp @@ -104,8 +104,8 @@ bool FOOTPRINT_EDIT_FRAME::Clear_Pcb( bool aQuery ) { wxSafeYield( this, true ); // Allow frame to come to front before showing warning. - if( !HandleUnsavedChanges( this, - _( "The current footprint has been modified. Save changes?" ), + if( !HandleUnsavedChanges( this, _( "The current footprint has been modified. " + "Save changes?" ), [&]() -> bool { return SaveFootprint( GetBoard()->Modules().front() ); } ) ) { return false; diff --git a/pcbnew/pcb_edit_frame.cpp b/pcbnew/pcb_edit_frame.cpp index 624b32c69e..03b891b16f 100644 --- a/pcbnew/pcb_edit_frame.cpp +++ b/pcbnew/pcb_edit_frame.cpp @@ -463,9 +463,10 @@ void PCB_EDIT_FRAME::OnCloseWindow( wxCloseEvent& Event ) { 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 ); } ) ) { Event.Veto();