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,
|
int OKOrCancelDialog( wxWindow* aParent, const wxString& aWarning, const wxString& aMessage,
|
||||||
const wxString& aDetailedMessage, const wxString& aOKLabel,
|
wxString aDetailedMessage, wxString aOKLabel, wxString aCancelLabel,
|
||||||
const wxString& aCancelLabel, bool* aApplyToAll )
|
bool* aApplyToAll )
|
||||||
{
|
{
|
||||||
wxRichMessageDialog dlg( aParent, aMessage, aWarning,
|
wxRichMessageDialog dlg( aParent, aMessage, aWarning,
|
||||||
wxOK | wxCANCEL | wxOK_DEFAULT | wxICON_WARNING | wxCENTER );
|
wxOK | wxCANCEL | wxOK_DEFAULT | wxICON_WARNING | wxCENTER );
|
||||||
|
|
||||||
|
if( aOKLabel.IsEmpty() )
|
||||||
|
aOKLabel = _( "OK" );
|
||||||
|
|
||||||
|
if( aCancelLabel.IsEmpty() )
|
||||||
|
aCancelLabel = _( "Cancel" );
|
||||||
|
|
||||||
dlg.SetOKCancelLabels( aOKLabel, aCancelLabel );
|
dlg.SetOKCancelLabels( aOKLabel, aCancelLabel );
|
||||||
|
|
||||||
if( !aDetailedMessage.IsEmpty() )
|
if( !aDetailedMessage.IsEmpty() )
|
||||||
dlg.ShowDetailedText( aDetailedMessage );
|
dlg.SetExtendedMessage( aDetailedMessage );
|
||||||
|
|
||||||
if( aApplyToAll )
|
if( aApplyToAll )
|
||||||
dlg.ShowCheckBox( _( "Apply to all" ), true );
|
dlg.ShowCheckBox( _( "Apply to all" ), true );
|
||||||
|
|
|
@ -348,12 +348,10 @@ void SYMBOL_EDIT_FRAME::setupUIConditions()
|
||||||
const wxString& libName = libId.GetLibNickname();
|
const wxString& libName = libId.GetLibNickname();
|
||||||
const wxString& partName = libId.GetLibItemName();
|
const wxString& partName = libId.GetLibItemName();
|
||||||
|
|
||||||
bool readOnly = libName.IsEmpty() || m_libMgr->IsLibraryReadOnly( libName );
|
|
||||||
|
|
||||||
if( partName.IsEmpty() )
|
if( partName.IsEmpty() )
|
||||||
return ( !readOnly && m_libMgr->IsLibraryModified( libName ) );
|
return ( m_libMgr->IsLibraryModified( libName ) );
|
||||||
else
|
else
|
||||||
return ( !readOnly && m_libMgr->IsPartModified( partName, libName ) );
|
return ( m_libMgr->IsPartModified( partName, libName ) );
|
||||||
};
|
};
|
||||||
|
|
||||||
mgr->SetConditions( ACTIONS::saveAll,
|
mgr->SetConditions( ACTIONS::saveAll,
|
||||||
|
|
|
@ -578,15 +578,18 @@ void SYMBOL_EDIT_FRAME::Save()
|
||||||
const wxString& libName = libId.GetLibNickname();
|
const wxString& libName = libId.GetLibNickname();
|
||||||
const wxString& partName = libId.GetLibItemName();
|
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 );
|
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
|
else
|
||||||
{
|
{
|
||||||
// Save a single library.
|
// 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 )
|
bool SYMBOL_EDIT_FRAME::saveAllLibraries( bool aRequireConfirmation )
|
||||||
{
|
{
|
||||||
wxString msg;
|
wxString msg, msg2;
|
||||||
bool doSave = true;
|
bool doSave = true;
|
||||||
int dirtyCount = 0;
|
int dirtyCount = 0;
|
||||||
bool applyToAll = false;
|
bool applyToAll = false;
|
||||||
bool retv = true;
|
bool retv = true;
|
||||||
|
|
||||||
for( const auto& libNickname : m_libMgr->GetLibraryNames() )
|
for( const wxString& libNickname : m_libMgr->GetLibraryNames() )
|
||||||
{
|
{
|
||||||
if( m_libMgr->IsLibraryModified( libNickname ) )
|
if( m_libMgr->IsLibraryModified( libNickname ) )
|
||||||
dirtyCount++;
|
dirtyCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
for( const auto& libNickname : m_libMgr->GetLibraryNames() )
|
for( const wxString& libNickname : m_libMgr->GetLibraryNames() )
|
||||||
{
|
{
|
||||||
if( m_libMgr->IsLibraryModified( libNickname ) )
|
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
|
// If saving under existing name fails then do a Save As..., and if that
|
||||||
// fails then cancel close action.
|
// fails then cancel close action.
|
||||||
if( m_libMgr->IsLibraryReadOnly( libNickname ) )
|
|
||||||
|
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 )
|
||||||
{
|
{
|
||||||
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;
|
retv = false;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_infoBar->Dismiss();
|
||||||
|
m_infoBar->ShowMessageFor( msg + wxS( " " ) + msg2,
|
||||||
|
2000, wxICON_EXCLAMATION );
|
||||||
|
|
||||||
if( saveLibrary( libNickname, false ) )
|
while( m_infoBar->IsShown() )
|
||||||
|
wxSafeYield();
|
||||||
|
|
||||||
|
retv = false;
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if( !saveLibrary( libNickname, true ) )
|
if( !saveLibrary( libNickname, true ) )
|
||||||
retv = false;
|
retv = false;
|
||||||
|
|
|
@ -67,7 +67,7 @@ bool SYMBOL_LIBRARY_MANAGER::HasModifications() const
|
||||||
{
|
{
|
||||||
for( const auto& lib : m_libs )
|
for( const auto& lib : m_libs )
|
||||||
{
|
{
|
||||||
if( lib.second.IsModified() && !IsLibraryReadOnly( lib.first ) )
|
if( lib.second.IsModified() )
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,19 +46,27 @@ bool LIB_CONTROL::Init()
|
||||||
CONDITIONAL_MENU& ctxMenu = m_menu.GetMenu();
|
CONDITIONAL_MENU& ctxMenu = m_menu.GetMenu();
|
||||||
SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
|
SYMBOL_EDIT_FRAME* editFrame = getEditFrame<SYMBOL_EDIT_FRAME>();
|
||||||
|
|
||||||
auto libSelectedCondition = [ editFrame ] ( const SELECTION& aSel ) {
|
auto libSelectedCondition =
|
||||||
|
[ editFrame ]( const SELECTION& aSel )
|
||||||
|
{
|
||||||
LIB_ID sel = editFrame->GetTreeLIBID();
|
LIB_ID sel = editFrame->GetTreeLIBID();
|
||||||
return !sel.GetLibNickname().empty() && sel.GetLibItemName().empty();
|
return !sel.GetLibNickname().empty() && sel.GetLibItemName().empty();
|
||||||
};
|
};
|
||||||
auto pinnedLibSelectedCondition = [ editFrame ] ( const SELECTION& aSel ) {
|
auto pinnedLibSelectedCondition =
|
||||||
|
[ editFrame ]( const SELECTION& aSel )
|
||||||
|
{
|
||||||
LIB_TREE_NODE* current = editFrame->GetCurrentTreeNode();
|
LIB_TREE_NODE* current = editFrame->GetCurrentTreeNode();
|
||||||
return current && current->m_Type == LIB_TREE_NODE::LIB && current->m_Pinned;
|
return current && current->m_Type == LIB_TREE_NODE::LIB && current->m_Pinned;
|
||||||
};
|
};
|
||||||
auto unpinnedLibSelectedCondition = [ editFrame ] (const SELECTION& aSel ) {
|
auto unpinnedLibSelectedCondition =
|
||||||
|
[ editFrame ](const SELECTION& aSel )
|
||||||
|
{
|
||||||
LIB_TREE_NODE* current = editFrame->GetCurrentTreeNode();
|
LIB_TREE_NODE* current = editFrame->GetCurrentTreeNode();
|
||||||
return current && current->m_Type == LIB_TREE_NODE::LIB && !current->m_Pinned;
|
return current && current->m_Type == LIB_TREE_NODE::LIB && !current->m_Pinned;
|
||||||
};
|
};
|
||||||
auto symbolSelectedCondition = [ editFrame ] ( const SELECTION& aSel ) {
|
auto symbolSelectedCondition =
|
||||||
|
[ editFrame ]( const SELECTION& aSel )
|
||||||
|
{
|
||||||
LIB_ID sel = editFrame->GetTreeLIBID();
|
LIB_ID sel = editFrame->GetTreeLIBID();
|
||||||
return !sel.GetLibNickname().empty() && !sel.GetLibItemName().empty();
|
return !sel.GetLibNickname().empty() && !sel.GetLibItemName().empty();
|
||||||
};
|
};
|
||||||
|
|
|
@ -159,8 +159,8 @@ bool IsOK( wxWindow* aParent, const wxString& aMessage );
|
||||||
* @return wxID_OK or wxID_CANCEL depending on the button the user selected.
|
* @return wxID_OK or wxID_CANCEL depending on the button the user selected.
|
||||||
*/
|
*/
|
||||||
int OKOrCancelDialog( wxWindow* aParent, const wxString& aWarning, const wxString& aMessage,
|
int OKOrCancelDialog( wxWindow* aParent, const wxString& aWarning, const wxString& aMessage,
|
||||||
const wxString& aDetailedMessage, const wxString& aOKLabel,
|
wxString aDetailedMessage = wxEmptyString, wxString aOKLabel = wxEmptyString,
|
||||||
const wxString& aCancelLabel, bool* aApplyToAll );
|
wxString aCancelLabel = wxEmptyString, bool* aApplyToAll = nullptr );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue