Save should be disabled only if the file is up-to-date.
Any other issues (such as locked files) need to produce a dialog with info for the user.
This commit is contained in:
parent
a134567838
commit
412c9c8c4e
|
@ -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 );
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -46,22 +46,30 @@ bool LIB_CONTROL::Init()
|
|||
CONDITIONAL_MENU& ctxMenu = m_menu.GetMenu();
|
||||
SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
|
||||
|
||||
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 );
|
||||
|
|
|
@ -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 );
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue