diff --git a/common/confirm.cpp b/common/confirm.cpp index ef72a0f2df..5f2d3fa739 100644 --- a/common/confirm.cpp +++ b/common/confirm.cpp @@ -213,15 +213,22 @@ bool HandleUnsavedChanges( wxWindow* aParent, const wxString& aMessage, int OKOrCancelDialog( wxWindow* aParent, const wxString& aWarning, const wxString& aMessage, - const wxString& aDetailedMessage, const wxString& aOKLabel, - const wxString& aCancelLabel, bool* aApplyToAll ) + wxString aDetailedMessage, wxString aOKLabel, wxString aCancelLabel, + bool* aApplyToAll ) { wxRichMessageDialog dlg( aParent, aMessage, aWarning, wxOK | wxCANCEL | wxOK_DEFAULT | wxICON_WARNING | wxCENTER ); + + if( aOKLabel.IsEmpty() ) + aOKLabel = _( "OK" ); + + if( aCancelLabel.IsEmpty() ) + aCancelLabel = _( "Cancel" ); + dlg.SetOKCancelLabels( aOKLabel, aCancelLabel ); if( !aDetailedMessage.IsEmpty() ) - dlg.ShowDetailedText( aDetailedMessage ); + dlg.SetExtendedMessage( aDetailedMessage ); if( aApplyToAll ) dlg.ShowCheckBox( _( "Apply to all" ), true ); diff --git a/eeschema/symbol_editor/symbol_edit_frame.cpp b/eeschema/symbol_editor/symbol_edit_frame.cpp index fcaa5c7bc3..8f9c6c139b 100644 --- a/eeschema/symbol_editor/symbol_edit_frame.cpp +++ b/eeschema/symbol_editor/symbol_edit_frame.cpp @@ -348,12 +348,10 @@ void SYMBOL_EDIT_FRAME::setupUIConditions() const wxString& libName = libId.GetLibNickname(); const wxString& partName = libId.GetLibItemName(); - bool readOnly = libName.IsEmpty() || m_libMgr->IsLibraryReadOnly( libName ); - if( partName.IsEmpty() ) - return ( !readOnly && m_libMgr->IsLibraryModified( libName ) ); + return ( m_libMgr->IsLibraryModified( libName ) ); else - return ( !readOnly && m_libMgr->IsPartModified( partName, libName ) ); + return ( m_libMgr->IsPartModified( partName, libName ) ); }; mgr->SetConditions( ACTIONS::saveAll, diff --git a/eeschema/symbol_editor/symbol_editor.cpp b/eeschema/symbol_editor/symbol_editor.cpp index b681f0c409..8d2b05d4f3 100644 --- a/eeschema/symbol_editor/symbol_editor.cpp +++ b/eeschema/symbol_editor/symbol_editor.cpp @@ -574,19 +574,22 @@ void SYMBOL_EDIT_FRAME::CreateNewPart() void SYMBOL_EDIT_FRAME::Save() { - LIB_ID libId = getTargetLibId(); + LIB_ID libId = getTargetLibId(); const wxString& libName = libId.GetLibNickname(); const wxString& partName = libId.GetLibItemName(); - if( partName.IsEmpty() ) + if( !libName.IsEmpty() && m_libMgr->IsLibraryReadOnly( libName ) ) + { + wxString msg = wxString::Format( _( "Symbol library '%s' is not writeable." ), libName ); + wxString msg2 = _( "You must save to a different location." ); + + if( OKOrCancelDialog( this, _( "Warning" ), msg, msg2 ) == wxID_OK ) + saveLibrary( libName, true ); + } + else if( partName.IsEmpty() ) { saveLibrary( libName, false ); } - else if( !libName.IsEmpty() && m_libMgr->IsLibraryReadOnly( libName ) ) - { - // Force a "Save As..." if the modified library is read only. - saveLibrary( libName, true ); - } else { // Save a single library. @@ -1079,19 +1082,19 @@ bool SYMBOL_EDIT_FRAME::saveLibrary( const wxString& aLibrary, bool aNewFile ) bool SYMBOL_EDIT_FRAME::saveAllLibraries( bool aRequireConfirmation ) { - wxString msg; - bool doSave = true; - int dirtyCount = 0; - bool applyToAll = false; - bool retv = true; + wxString msg, msg2; + bool doSave = true; + int dirtyCount = 0; + bool applyToAll = false; + bool retv = true; - for( const auto& libNickname : m_libMgr->GetLibraryNames() ) + for( const wxString& libNickname : m_libMgr->GetLibraryNames() ) { if( m_libMgr->IsLibraryModified( libNickname ) ) dirtyCount++; } - for( const auto& libNickname : m_libMgr->GetLibraryNames() ) + for( const wxString& libNickname : m_libMgr->GetLibraryNames() ) { if( m_libMgr->IsLibraryModified( libNickname ) ) { @@ -1112,18 +1115,38 @@ bool SYMBOL_EDIT_FRAME::saveAllLibraries( bool aRequireConfirmation ) { // If saving under existing name fails then do a Save As..., and if that // fails then cancel close action. - if( m_libMgr->IsLibraryReadOnly( libNickname ) ) - { - m_infoBar->Dismiss(); - msg.Printf( _( "Library \"%s\" is read only and must be saved as a " - "different library." ), libNickname ); - m_infoBar->ShowMessageFor( msg, 3000, wxICON_EXCLAMATION ); - retv = false; - continue; - } - if( saveLibrary( libNickname, false ) ) - continue; + if( !m_libMgr->IsLibraryReadOnly( libNickname ) ) + { + if( saveLibrary( libNickname, false ) ) + continue; + } + else + { + msg.Printf( _( "Symbol library '%s' is not writeable." ), libNickname ); + msg2 = _( "You must save to a different location." ); + + if( dirtyCount == 1 ) + { + if( OKOrCancelDialog( this, _( "Warning" ), msg, msg2 ) != wxID_OK ) + { + retv = false; + continue; + } + } + else + { + m_infoBar->Dismiss(); + m_infoBar->ShowMessageFor( msg + wxS( " " ) + msg2, + 2000, wxICON_EXCLAMATION ); + + while( m_infoBar->IsShown() ) + wxSafeYield(); + + retv = false; + continue; + } + } if( !saveLibrary( libNickname, true ) ) retv = false; diff --git a/eeschema/symbol_editor/symbol_library_manager.cpp b/eeschema/symbol_editor/symbol_library_manager.cpp index 535817fd89..b9b82ba484 100644 --- a/eeschema/symbol_editor/symbol_library_manager.cpp +++ b/eeschema/symbol_editor/symbol_library_manager.cpp @@ -67,7 +67,7 @@ bool SYMBOL_LIBRARY_MANAGER::HasModifications() const { for( const auto& lib : m_libs ) { - if( lib.second.IsModified() && !IsLibraryReadOnly( lib.first ) ) + if( lib.second.IsModified() ) return true; } diff --git a/eeschema/tools/lib_control.cpp b/eeschema/tools/lib_control.cpp index 8a9ba52741..6ccf772623 100644 --- a/eeschema/tools/lib_control.cpp +++ b/eeschema/tools/lib_control.cpp @@ -46,22 +46,30 @@ bool LIB_CONTROL::Init() CONDITIONAL_MENU& ctxMenu = m_menu.GetMenu(); SYMBOL_EDIT_FRAME* editFrame = getEditFrame(); - auto libSelectedCondition = [ editFrame ] ( const SELECTION& aSel ) { - LIB_ID sel = editFrame->GetTreeLIBID(); - return !sel.GetLibNickname().empty() && sel.GetLibItemName().empty(); - }; - auto pinnedLibSelectedCondition = [ editFrame ] ( const SELECTION& aSel ) { - LIB_TREE_NODE* current = editFrame->GetCurrentTreeNode(); - return current && current->m_Type == LIB_TREE_NODE::LIB && current->m_Pinned; - }; - auto unpinnedLibSelectedCondition = [ editFrame ] (const SELECTION& aSel ) { - LIB_TREE_NODE* current = editFrame->GetCurrentTreeNode(); - return current && current->m_Type == LIB_TREE_NODE::LIB && !current->m_Pinned; - }; - auto symbolSelectedCondition = [ editFrame ] ( const SELECTION& aSel ) { - LIB_ID sel = editFrame->GetTreeLIBID(); - return !sel.GetLibNickname().empty() && !sel.GetLibItemName().empty(); - }; + auto libSelectedCondition = + [ editFrame ]( const SELECTION& aSel ) + { + LIB_ID sel = editFrame->GetTreeLIBID(); + return !sel.GetLibNickname().empty() && sel.GetLibItemName().empty(); + }; + auto pinnedLibSelectedCondition = + [ editFrame ]( const SELECTION& aSel ) + { + LIB_TREE_NODE* current = editFrame->GetCurrentTreeNode(); + return current && current->m_Type == LIB_TREE_NODE::LIB && current->m_Pinned; + }; + auto unpinnedLibSelectedCondition = + [ editFrame ](const SELECTION& aSel ) + { + LIB_TREE_NODE* current = editFrame->GetCurrentTreeNode(); + return current && current->m_Type == LIB_TREE_NODE::LIB && !current->m_Pinned; + }; + auto symbolSelectedCondition = + [ editFrame ]( const SELECTION& aSel ) + { + LIB_ID sel = editFrame->GetTreeLIBID(); + return !sel.GetLibNickname().empty() && !sel.GetLibItemName().empty(); + }; ctxMenu.AddItem( ACTIONS::pinLibrary, unpinnedLibSelectedCondition ); ctxMenu.AddItem( ACTIONS::unpinLibrary, pinnedLibSelectedCondition ); diff --git a/include/confirm.h b/include/confirm.h index bcb48711f9..85e9bd4448 100644 --- a/include/confirm.h +++ b/include/confirm.h @@ -159,8 +159,8 @@ bool IsOK( wxWindow* aParent, const wxString& aMessage ); * @return wxID_OK or wxID_CANCEL depending on the button the user selected. */ int OKOrCancelDialog( wxWindow* aParent, const wxString& aWarning, const wxString& aMessage, - const wxString& aDetailedMessage, const wxString& aOKLabel, - const wxString& aCancelLabel, bool* aApplyToAll ); + wxString aDetailedMessage = wxEmptyString, wxString aOKLabel = wxEmptyString, + wxString aCancelLabel = wxEmptyString, bool* aApplyToAll = nullptr );