Read-only dialogs for symbols in legacy libraries.

Fixes https://gitlab.com/kicad/code/kicad/issues/5211
This commit is contained in:
Jeff Young 2020-12-22 02:29:27 +00:00
parent ad1ee40441
commit fb7ac450d9
9 changed files with 69 additions and 73 deletions

View File

@ -43,7 +43,17 @@ DIALOG_LIB_EDIT_DRAW_ITEM::DIALOG_LIB_EDIT_DRAW_ITEM( SYMBOL_EDIT_FRAME* aParent
// Required under wxGTK if we want to dismiss the dialog with the ESC key // Required under wxGTK if we want to dismiss the dialog with the ESC key
SetFocus(); SetFocus();
if( aParent->IsSymbolFromLegacyLibrary() )
{
m_sdbSizerCancel->SetDefault();
m_sdbSizerOK->SetLabel( _( "Read Only" ) );
m_sdbSizerOK->Enable( false );
}
else
{
m_sdbSizerOK->SetDefault(); m_sdbSizerOK->SetDefault();
}
// Now all widgets have the size fixed, call FinishDialogSettings // Now all widgets have the size fixed, call FinishDialogSettings
finishDialogSettings(); finishDialogSettings();

View File

@ -449,6 +449,17 @@ DIALOG_LIB_EDIT_PIN_TABLE::DIALOG_LIB_EDIT_PIN_TABLE( SYMBOL_EDIT_FRAME* parent,
GetSizer()->SetSizeHints(this); GetSizer()->SetSizeHints(this);
Centre(); Centre();
if( parent->IsSymbolFromLegacyLibrary() )
{
m_ButtonsCancel->SetDefault();
m_ButtonsOK->SetLabel( _( "Read Only" ) );
m_ButtonsOK->Enable( false );
}
else
{
m_ButtonsOK->SetDefault();
}
m_ButtonsOK->SetDefault(); m_ButtonsOK->SetDefault();
m_initialized = true; m_initialized = true;
m_modified = false; m_modified = false;

View File

@ -52,7 +52,16 @@ DIALOG_LIB_EDIT_TEXT::DIALOG_LIB_EDIT_TEXT( SYMBOL_EDIT_FRAME* aParent, LIB_TEXT
SetInitialFocus( m_TextCtrl ); SetInitialFocus( m_TextCtrl );
m_StyledTextCtrl->Show( false ); m_StyledTextCtrl->Show( false );
if( aParent->IsSymbolFromLegacyLibrary() )
{
m_sdbSizerButtonsCancel->SetDefault();
m_sdbSizerButtonsOK->SetLabel( _( "Read Only" ) );
m_sdbSizerButtonsOK->Enable( false );
}
else
{
m_sdbSizerButtonsOK->SetDefault(); m_sdbSizerButtonsOK->SetDefault();
}
// Now all widgets have the size fixed, call FinishDialogSettings // Now all widgets have the size fixed, call FinishDialogSettings
finishDialogSettings(); finishDialogSettings();

View File

@ -86,7 +86,16 @@ DIALOG_LIB_SYMBOL_PROPERTIES::DIALOG_LIB_SYMBOL_PROPERTIES( SYMBOL_EDIT_FRAME* a
m_deleteFilterButton->SetBitmap( KiBitmap( trash_xpm ) ); m_deleteFilterButton->SetBitmap( KiBitmap( trash_xpm ) );
m_editFilterButton->SetBitmap( KiBitmap( small_edit_xpm ) ); m_editFilterButton->SetBitmap( KiBitmap( small_edit_xpm ) );
if( aParent->IsSymbolFromLegacyLibrary() )
{
m_stdSizerButtonCancel->SetDefault();
m_stdSizerButtonOK->SetLabel( _( "Read Only" ) );
m_stdSizerButtonOK->Enable( false );
}
else
{
m_stdSizerButtonOK->SetDefault(); m_stdSizerButtonOK->SetDefault();
}
#ifndef KICAD_SPICE #ifndef KICAD_SPICE
m_spiceFieldsButton->Hide(); m_spiceFieldsButton->Hide();

View File

@ -327,10 +327,11 @@ void SYMBOL_EDIT_FRAME::setupUIConditions()
return m_my_part; return m_my_part;
}; };
auto haveRootSymbolCond = auto isEditableCond =
[this] ( const SELECTION& ) [this] ( const SELECTION& )
{ {
return m_my_part && m_my_part->IsRoot(); // Only root symbols are editable
return m_my_part && m_my_part->IsRoot() && !IsSymbolFromLegacyLibrary();
}; };
auto libMgrModifiedCond = auto libMgrModifiedCond =
@ -384,17 +385,17 @@ void SYMBOL_EDIT_FRAME::setupUIConditions()
CHECK( cond.CanvasType( EDA_DRAW_PANEL_GAL::GAL_TYPE_CAIRO ) ) ); CHECK( cond.CanvasType( EDA_DRAW_PANEL_GAL::GAL_TYPE_CAIRO ) ) );
mgr->SetConditions( ACTIONS::cut, mgr->SetConditions( ACTIONS::cut,
ENABLE( haveRootSymbolCond && SELECTION_CONDITIONS::NotEmpty ) ); ENABLE( isEditableCond && SELECTION_CONDITIONS::NotEmpty ) );
mgr->SetConditions( ACTIONS::copy, mgr->SetConditions( ACTIONS::copy,
ENABLE( haveRootSymbolCond && SELECTION_CONDITIONS::NotEmpty ) ); ENABLE( haveSymbolCond && SELECTION_CONDITIONS::NotEmpty ) );
mgr->SetConditions( ACTIONS::paste, mgr->SetConditions( ACTIONS::paste,
ENABLE( haveRootSymbolCond && SELECTION_CONDITIONS::Idle ) ); ENABLE( isEditableCond && SELECTION_CONDITIONS::Idle ) );
mgr->SetConditions( ACTIONS::doDelete, mgr->SetConditions( ACTIONS::doDelete,
ENABLE( haveRootSymbolCond && SELECTION_CONDITIONS::NotEmpty ) ); ENABLE( isEditableCond && SELECTION_CONDITIONS::NotEmpty ) );
mgr->SetConditions( ACTIONS::duplicate, mgr->SetConditions( ACTIONS::duplicate,
ENABLE( haveRootSymbolCond && SELECTION_CONDITIONS::NotEmpty ) ); ENABLE( isEditableCond && SELECTION_CONDITIONS::NotEmpty ) );
mgr->SetConditions( ACTIONS::selectAll, mgr->SetConditions( ACTIONS::selectAll,
ENABLE( haveRootSymbolCond ) ); ENABLE( haveSymbolCond ) );
mgr->SetConditions( ACTIONS::zoomTool, mgr->SetConditions( ACTIONS::zoomTool,
CHECK( cond.CurrentTool( ACTIONS::zoomTool ) ) ); CHECK( cond.CurrentTool( ACTIONS::zoomTool ) ) );
@ -416,13 +417,6 @@ void SYMBOL_EDIT_FRAME::setupUIConditions()
mgr->SetConditions( EE_ACTIONS::showElectricalTypes, CHECK( pinTypeCond ) ); mgr->SetConditions( EE_ACTIONS::showElectricalTypes, CHECK( pinTypeCond ) );
mgr->SetConditions( EE_ACTIONS::showComponentTree, CHECK( showCompTreeCond ) ); mgr->SetConditions( EE_ACTIONS::showComponentTree, CHECK( showCompTreeCond ) );
auto isEditableCond =
[this] ( const SELECTION& )
{
// Only root symbols are editable
return m_my_part && m_my_part->IsRoot();
};
auto demorganCond = auto demorganCond =
[this] ( const SELECTION& ) [this] ( const SELECTION& )
{ {
@ -461,8 +455,8 @@ void SYMBOL_EDIT_FRAME::setupUIConditions()
mgr->SetConditions( EE_ACTIONS::showDatasheet, ENABLE( haveDatasheetCond ) ); mgr->SetConditions( EE_ACTIONS::showDatasheet, ENABLE( haveDatasheetCond ) );
mgr->SetConditions( EE_ACTIONS::symbolProperties, ENABLE( haveSymbolCond ) ); mgr->SetConditions( EE_ACTIONS::symbolProperties, ENABLE( haveSymbolCond ) );
mgr->SetConditions( EE_ACTIONS::runERC, ENABLE( isEditableCond) ); mgr->SetConditions( EE_ACTIONS::runERC, ENABLE( haveSymbolCond ) );
mgr->SetConditions( EE_ACTIONS::pinTable, ENABLE( isEditableCond) ); mgr->SetConditions( EE_ACTIONS::pinTable, ENABLE( haveSymbolCond ) );
mgr->SetConditions( EE_ACTIONS::showDeMorganStandard, mgr->SetConditions( EE_ACTIONS::showDeMorganStandard,
ACTION_CONDITIONS().Enable( demorganCond ).Check( demorganStandardCond ) ); ACTION_CONDITIONS().Enable( demorganCond ).Check( demorganStandardCond ) );
@ -477,17 +471,14 @@ void SYMBOL_EDIT_FRAME::setupUIConditions()
mgr->SetConditions( ACTIONS::deleteTool, EDIT_TOOL( ACTIONS::deleteTool ) ); mgr->SetConditions( ACTIONS::deleteTool, EDIT_TOOL( ACTIONS::deleteTool ) );
mgr->SetConditions( EE_ACTIONS::placeSymbolPin, EDIT_TOOL( EE_ACTIONS::placeSymbolPin ) ); mgr->SetConditions( EE_ACTIONS::placeSymbolPin, EDIT_TOOL( EE_ACTIONS::placeSymbolPin ) );
mgr->SetConditions( EE_ACTIONS::placeSymbolText, EDIT_TOOL( EE_ACTIONS::placeSymbolText ) ); mgr->SetConditions( EE_ACTIONS::placeSymbolText, EDIT_TOOL( EE_ACTIONS::placeSymbolText ) );
mgr->SetConditions( EE_ACTIONS::drawSymbolRectangle, mgr->SetConditions( EE_ACTIONS::drawSymbolRectangle, EDIT_TOOL( EE_ACTIONS::drawSymbolRectangle ) );
EDIT_TOOL( EE_ACTIONS::drawSymbolRectangle ) ); mgr->SetConditions( EE_ACTIONS::drawSymbolCircle, EDIT_TOOL( EE_ACTIONS::drawSymbolCircle ) );
mgr->SetConditions( EE_ACTIONS::drawSymbolCircle,
EDIT_TOOL( EE_ACTIONS::drawSymbolCircle ) );
mgr->SetConditions( EE_ACTIONS::drawSymbolArc, EDIT_TOOL( EE_ACTIONS::drawSymbolArc ) ); mgr->SetConditions( EE_ACTIONS::drawSymbolArc, EDIT_TOOL( EE_ACTIONS::drawSymbolArc ) );
mgr->SetConditions( EE_ACTIONS::drawSymbolLines, EDIT_TOOL( EE_ACTIONS::drawSymbolLines ) ); mgr->SetConditions( EE_ACTIONS::drawSymbolLines, EDIT_TOOL( EE_ACTIONS::drawSymbolLines ) );
mgr->SetConditions( EE_ACTIONS::placeSymbolAnchor, mgr->SetConditions( EE_ACTIONS::placeSymbolAnchor, EDIT_TOOL( EE_ACTIONS::placeSymbolAnchor ) );
EDIT_TOOL( EE_ACTIONS::placeSymbolAnchor ) );
RegisterUIUpdateHandler( ID_LIBEDIT_IMPORT_BODY_BUTT, ENABLE( isEditableCond ) ); RegisterUIUpdateHandler( ID_LIBEDIT_IMPORT_BODY_BUTT, ENABLE( isEditableCond ) );
RegisterUIUpdateHandler( ID_LIBEDIT_EXPORT_BODY_BUTT, ENABLE( isEditableCond ) ); RegisterUIUpdateHandler( ID_LIBEDIT_EXPORT_BODY_BUTT, ENABLE( haveSymbolCond ) );
#undef CHECK #undef CHECK
#undef ENABLE #undef ENABLE
@ -673,8 +664,6 @@ wxString SYMBOL_EDIT_FRAME::SetCurLib( const wxString& aLibNickname )
else else
Prj().SetRString( PROJECT::SCH_LIBEDIT_CUR_LIB, aLibNickname ); Prj().SetRString( PROJECT::SCH_LIBEDIT_CUR_LIB, aLibNickname );
m_libMgr->SetCurrentLib( aLibNickname );
return old; return old;
} }
@ -689,15 +678,9 @@ void SYMBOL_EDIT_FRAME::SetCurPart( LIB_PART* aPart, bool aUpdateZoom )
// select the current component in the tree widget // select the current component in the tree widget
if( !IsSymbolFromSchematic() && m_my_part ) if( !IsSymbolFromSchematic() && m_my_part )
{
m_treePane->GetLibTree()->SelectLibId( m_my_part->GetLibId() ); m_treePane->GetLibTree()->SelectLibId( m_my_part->GetLibId() );
}
else else
{
m_treePane->GetLibTree()->Unselect(); m_treePane->GetLibTree()->Unselect();
m_libMgr->SetCurrentLib( wxEmptyString );
m_libMgr->SetCurrentPart( wxEmptyString );
}
wxString partName = m_my_part ? m_my_part->GetName() : wxString(); wxString partName = m_my_part ? m_my_part->GetName() : wxString();
bool isAlias = !IsSymbolFromSchematic() && m_my_part && m_my_part->IsAlias(); bool isAlias = !IsSymbolFromSchematic() && m_my_part && m_my_part->IsAlias();

View File

@ -439,7 +439,6 @@ bool SYMBOL_LIBRARY_MANAGER::UpdatePartAfterRename( LIB_PART* aPart, const wxStr
wxCHECK( partBuf, false ); wxCHECK( partBuf, false );
libBuf.UpdateBuffer( partBuf, aPart ); libBuf.UpdateBuffer( partBuf, aPart );
SetCurrentPart( aPart->GetName() );
m_frame.SyncLibraries( false ); m_frame.SyncLibraries( false );
return true; return true;

View File

@ -278,26 +278,6 @@ public:
*/ */
wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>& GetAdapter() { return m_adapter; } wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>& GetAdapter() { return m_adapter; }
/**
* Returns the currently modified library name.
*/
const wxString& GetCurrentLib() const { return m_currentLib; }
void SetCurrentLib( const wxString& aLibrary ) { m_currentLib = aLibrary; }
/**
* Returns the currently modified part name.
*/
const wxString& GetCurrentPart() const { return m_currentPart; }
void SetCurrentPart( const wxString& aPart ) { m_currentPart = aPart; }
/**
* Returns the current library and part name as LIB_ID.
*/
LIB_ID GetCurrentLibId() const
{
return LIB_ID( m_currentLib, m_currentPart );
}
void GetRootSymbolNames( const wxString& aLibName, wxArrayString& aRootSymbolNames ); void GetRootSymbolNames( const wxString& aLibName, wxArrayString& aRootSymbolNames );
/** /**
@ -480,9 +460,6 @@ private:
LIB_LOGGER m_logger; LIB_LOGGER m_logger;
int m_syncHash; ///< Symbol lib table hash value from last synchronization int m_syncHash; ///< Symbol lib table hash value from last synchronization
wxString m_currentLib; ///< Currently modified part
wxString m_currentPart; ///< Currently modified library
wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER> m_adapter; wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER> m_adapter;
}; };

View File

@ -280,25 +280,26 @@ bool SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetAttr( wxDataViewItem const& aItem, un
if( aCol != 0 ) if( aCol != 0 )
return false; return false;
LIB_PART* curPart = m_frame->GetCurPart();
switch( node->m_Type ) switch( node->m_Type )
{ {
case LIB_TREE_NODE::LIB: case LIB_TREE_NODE::LIB:
// mark modified libs with bold font // mark modified libs with bold font
aAttr.SetBold( m_libMgr->IsLibraryModified( node->m_Name ) ); aAttr.SetBold( m_libMgr->IsLibraryModified( node->m_Name ) );
// mark the current library with background color
if( curPart && curPart->GetLibId().GetLibNickname() == node->m_LibId.GetLibNickname() )
{
#ifdef __WXGTK__ #ifdef __WXGTK__
// The native wxGTK+ impl ignores background colour, so set the text colour instead. // The native wxGTK+ impl ignores background colour, so set the text colour instead.
// This works reasonably well in dark themes, and quite poorly in light ones.... // This works reasonably well in dark themes, and quite poorly in light ones....
if( node->m_Name == m_libMgr->GetCurrentLib() )
aAttr.SetColour( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT ) ); aAttr.SetColour( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT ) );
#else #else
// mark the current library with background color
if( node->m_Name == m_libMgr->GetCurrentLib() )
{
aAttr.SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT ) ); aAttr.SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT ) );
aAttr.SetColour( wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOXHIGHLIGHTTEXT ) ); aAttr.SetColour( wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOXHIGHLIGHTTEXT ) );
}
#endif #endif
}
break; break;
case LIB_TREE_NODE::LIBID: case LIB_TREE_NODE::LIBID:
@ -308,19 +309,18 @@ bool SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetAttr( wxDataViewItem const& aItem, un
// mark aliases with italic font // mark aliases with italic font
aAttr.SetItalic( !node->m_IsRoot ); aAttr.SetItalic( !node->m_IsRoot );
// mark the current part with background color
if( curPart && curPart->GetLibId() == node->m_LibId )
{
#ifdef __WXGTK__ #ifdef __WXGTK__
// The native wxGTK+ impl ignores background colour, so set the text colour instead. // The native wxGTK+ impl ignores background colour, so set the text colour instead.
// This works reasonably well in dark themes, and quite poorly in light ones.... // This works reasonably well in dark themes, and quite poorly in light ones....
if( node->m_LibId == m_libMgr->GetCurrentLibId() )
aAttr.SetColour( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT ) ); aAttr.SetColour( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT ) );
#else #else
// mark the current part with background color
if( node->m_LibId == m_libMgr->GetCurrentLibId() )
{
aAttr.SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT ) ); aAttr.SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT ) );
aAttr.SetColour( wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOXHIGHLIGHTTEXT ) ); aAttr.SetColour( wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOXHIGHLIGHTTEXT ) );
}
#endif #endif
}
break; break;
default: default:

View File

@ -26,7 +26,6 @@
#include <symbol_edit_frame.h> #include <symbol_edit_frame.h>
#include <view/view_controls.h> #include <view/view_controls.h>
#include <tool/tool_manager.h> #include <tool/tool_manager.h>
#include <tools/ee_selection_tool.h>
#include <tools/symbol_editor_drawing_tools.h> #include <tools/symbol_editor_drawing_tools.h>
#include <tools/symbol_editor_pin_tool.h> #include <tools/symbol_editor_pin_tool.h>
#include <class_libentry.h> #include <class_libentry.h>
@ -41,7 +40,6 @@
#include <symbol_editor/symbol_editor_settings.h> #include <symbol_editor/symbol_editor_settings.h>
#include <settings/settings_manager.h> #include <settings/settings_manager.h>
#include <kicad_string.h> #include <kicad_string.h>
#include "ee_point_editor.h"
static void* g_lastPinWeakPtr; static void* g_lastPinWeakPtr;