From fb7ac450d9ebd662f0a4d234924d967e4556f4f8 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 22 Dec 2020 02:29:27 +0000 Subject: [PATCH] Read-only dialogs for symbols in legacy libraries. Fixes https://gitlab.com/kicad/code/kicad/issues/5211 --- .../dialogs/dialog_lib_edit_draw_item.cpp | 12 ++++- .../dialogs/dialog_lib_edit_pin_table.cpp | 11 +++++ eeschema/dialogs/dialog_lib_edit_text.cpp | 11 ++++- .../dialogs/dialog_lib_symbol_properties.cpp | 11 ++++- eeschema/symbol_editor/symbol_edit_frame.cpp | 47 ++++++------------- .../symbol_editor/symbol_library_manager.cpp | 1 - .../symbol_editor/symbol_library_manager.h | 23 --------- .../symbol_tree_synchronizing_adapter.cpp | 24 +++++----- .../tools/symbol_editor_drawing_tools.cpp | 2 - 9 files changed, 69 insertions(+), 73 deletions(-) diff --git a/eeschema/dialogs/dialog_lib_edit_draw_item.cpp b/eeschema/dialogs/dialog_lib_edit_draw_item.cpp index a98d01dca7..b9f0d8e591 100644 --- a/eeschema/dialogs/dialog_lib_edit_draw_item.cpp +++ b/eeschema/dialogs/dialog_lib_edit_draw_item.cpp @@ -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 SetFocus(); - m_sdbSizerOK->SetDefault(); + + if( aParent->IsSymbolFromLegacyLibrary() ) + { + m_sdbSizerCancel->SetDefault(); + m_sdbSizerOK->SetLabel( _( "Read Only" ) ); + m_sdbSizerOK->Enable( false ); + } + else + { + m_sdbSizerOK->SetDefault(); + } // Now all widgets have the size fixed, call FinishDialogSettings finishDialogSettings(); diff --git a/eeschema/dialogs/dialog_lib_edit_pin_table.cpp b/eeschema/dialogs/dialog_lib_edit_pin_table.cpp index 8c18498d6e..1fd4184664 100644 --- a/eeschema/dialogs/dialog_lib_edit_pin_table.cpp +++ b/eeschema/dialogs/dialog_lib_edit_pin_table.cpp @@ -449,6 +449,17 @@ DIALOG_LIB_EDIT_PIN_TABLE::DIALOG_LIB_EDIT_PIN_TABLE( SYMBOL_EDIT_FRAME* parent, GetSizer()->SetSizeHints(this); Centre(); + if( parent->IsSymbolFromLegacyLibrary() ) + { + m_ButtonsCancel->SetDefault(); + m_ButtonsOK->SetLabel( _( "Read Only" ) ); + m_ButtonsOK->Enable( false ); + } + else + { + m_ButtonsOK->SetDefault(); + } + m_ButtonsOK->SetDefault(); m_initialized = true; m_modified = false; diff --git a/eeschema/dialogs/dialog_lib_edit_text.cpp b/eeschema/dialogs/dialog_lib_edit_text.cpp index 7efc6e669d..09949d4276 100644 --- a/eeschema/dialogs/dialog_lib_edit_text.cpp +++ b/eeschema/dialogs/dialog_lib_edit_text.cpp @@ -52,7 +52,16 @@ DIALOG_LIB_EDIT_TEXT::DIALOG_LIB_EDIT_TEXT( SYMBOL_EDIT_FRAME* aParent, LIB_TEXT SetInitialFocus( m_TextCtrl ); m_StyledTextCtrl->Show( false ); - m_sdbSizerButtonsOK->SetDefault(); + if( aParent->IsSymbolFromLegacyLibrary() ) + { + m_sdbSizerButtonsCancel->SetDefault(); + m_sdbSizerButtonsOK->SetLabel( _( "Read Only" ) ); + m_sdbSizerButtonsOK->Enable( false ); + } + else + { + m_sdbSizerButtonsOK->SetDefault(); + } // Now all widgets have the size fixed, call FinishDialogSettings finishDialogSettings(); diff --git a/eeschema/dialogs/dialog_lib_symbol_properties.cpp b/eeschema/dialogs/dialog_lib_symbol_properties.cpp index 7815ce3b48..f5fbecf919 100644 --- a/eeschema/dialogs/dialog_lib_symbol_properties.cpp +++ b/eeschema/dialogs/dialog_lib_symbol_properties.cpp @@ -86,7 +86,16 @@ DIALOG_LIB_SYMBOL_PROPERTIES::DIALOG_LIB_SYMBOL_PROPERTIES( SYMBOL_EDIT_FRAME* a m_deleteFilterButton->SetBitmap( KiBitmap( trash_xpm ) ); m_editFilterButton->SetBitmap( KiBitmap( small_edit_xpm ) ); - m_stdSizerButtonOK->SetDefault(); + if( aParent->IsSymbolFromLegacyLibrary() ) + { + m_stdSizerButtonCancel->SetDefault(); + m_stdSizerButtonOK->SetLabel( _( "Read Only" ) ); + m_stdSizerButtonOK->Enable( false ); + } + else + { + m_stdSizerButtonOK->SetDefault(); + } #ifndef KICAD_SPICE m_spiceFieldsButton->Hide(); diff --git a/eeschema/symbol_editor/symbol_edit_frame.cpp b/eeschema/symbol_editor/symbol_edit_frame.cpp index c88d5acaab..14e701a155 100644 --- a/eeschema/symbol_editor/symbol_edit_frame.cpp +++ b/eeschema/symbol_editor/symbol_edit_frame.cpp @@ -327,10 +327,11 @@ void SYMBOL_EDIT_FRAME::setupUIConditions() return m_my_part; }; - auto haveRootSymbolCond = + auto isEditableCond = [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 = @@ -384,17 +385,17 @@ void SYMBOL_EDIT_FRAME::setupUIConditions() CHECK( cond.CanvasType( EDA_DRAW_PANEL_GAL::GAL_TYPE_CAIRO ) ) ); mgr->SetConditions( ACTIONS::cut, - ENABLE( haveRootSymbolCond && SELECTION_CONDITIONS::NotEmpty ) ); + ENABLE( isEditableCond && SELECTION_CONDITIONS::NotEmpty ) ); mgr->SetConditions( ACTIONS::copy, - ENABLE( haveRootSymbolCond && SELECTION_CONDITIONS::NotEmpty ) ); + ENABLE( haveSymbolCond && SELECTION_CONDITIONS::NotEmpty ) ); mgr->SetConditions( ACTIONS::paste, - ENABLE( haveRootSymbolCond && SELECTION_CONDITIONS::Idle ) ); + ENABLE( isEditableCond && SELECTION_CONDITIONS::Idle ) ); mgr->SetConditions( ACTIONS::doDelete, - ENABLE( haveRootSymbolCond && SELECTION_CONDITIONS::NotEmpty ) ); + ENABLE( isEditableCond && SELECTION_CONDITIONS::NotEmpty ) ); mgr->SetConditions( ACTIONS::duplicate, - ENABLE( haveRootSymbolCond && SELECTION_CONDITIONS::NotEmpty ) ); + ENABLE( isEditableCond && SELECTION_CONDITIONS::NotEmpty ) ); mgr->SetConditions( ACTIONS::selectAll, - ENABLE( haveRootSymbolCond ) ); + ENABLE( haveSymbolCond ) ); mgr->SetConditions( 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::showComponentTree, CHECK( showCompTreeCond ) ); - auto isEditableCond = - [this] ( const SELECTION& ) - { - // Only root symbols are editable - return m_my_part && m_my_part->IsRoot(); - }; - auto demorganCond = [this] ( const SELECTION& ) { @@ -461,8 +455,8 @@ void SYMBOL_EDIT_FRAME::setupUIConditions() mgr->SetConditions( EE_ACTIONS::showDatasheet, ENABLE( haveDatasheetCond ) ); mgr->SetConditions( EE_ACTIONS::symbolProperties, ENABLE( haveSymbolCond ) ); - mgr->SetConditions( EE_ACTIONS::runERC, ENABLE( isEditableCond) ); - mgr->SetConditions( EE_ACTIONS::pinTable, ENABLE( isEditableCond) ); + mgr->SetConditions( EE_ACTIONS::runERC, ENABLE( haveSymbolCond ) ); + mgr->SetConditions( EE_ACTIONS::pinTable, ENABLE( haveSymbolCond ) ); mgr->SetConditions( EE_ACTIONS::showDeMorganStandard, 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( EE_ACTIONS::placeSymbolPin, EDIT_TOOL( EE_ACTIONS::placeSymbolPin ) ); mgr->SetConditions( EE_ACTIONS::placeSymbolText, EDIT_TOOL( EE_ACTIONS::placeSymbolText ) ); - mgr->SetConditions( EE_ACTIONS::drawSymbolRectangle, - EDIT_TOOL( EE_ACTIONS::drawSymbolRectangle ) ); - mgr->SetConditions( EE_ACTIONS::drawSymbolCircle, - EDIT_TOOL( EE_ACTIONS::drawSymbolCircle ) ); + mgr->SetConditions( EE_ACTIONS::drawSymbolRectangle, EDIT_TOOL( EE_ACTIONS::drawSymbolRectangle ) ); + mgr->SetConditions( EE_ACTIONS::drawSymbolCircle, EDIT_TOOL( EE_ACTIONS::drawSymbolCircle ) ); mgr->SetConditions( EE_ACTIONS::drawSymbolArc, EDIT_TOOL( EE_ACTIONS::drawSymbolArc ) ); mgr->SetConditions( EE_ACTIONS::drawSymbolLines, EDIT_TOOL( EE_ACTIONS::drawSymbolLines ) ); - mgr->SetConditions( EE_ACTIONS::placeSymbolAnchor, - EDIT_TOOL( EE_ACTIONS::placeSymbolAnchor ) ); + mgr->SetConditions( EE_ACTIONS::placeSymbolAnchor, EDIT_TOOL( EE_ACTIONS::placeSymbolAnchor ) ); 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 ENABLE @@ -673,8 +664,6 @@ wxString SYMBOL_EDIT_FRAME::SetCurLib( const wxString& aLibNickname ) else Prj().SetRString( PROJECT::SCH_LIBEDIT_CUR_LIB, aLibNickname ); - m_libMgr->SetCurrentLib( aLibNickname ); - return old; } @@ -689,15 +678,9 @@ void SYMBOL_EDIT_FRAME::SetCurPart( LIB_PART* aPart, bool aUpdateZoom ) // select the current component in the tree widget if( !IsSymbolFromSchematic() && m_my_part ) - { m_treePane->GetLibTree()->SelectLibId( m_my_part->GetLibId() ); - } else - { m_treePane->GetLibTree()->Unselect(); - m_libMgr->SetCurrentLib( wxEmptyString ); - m_libMgr->SetCurrentPart( wxEmptyString ); - } wxString partName = m_my_part ? m_my_part->GetName() : wxString(); bool isAlias = !IsSymbolFromSchematic() && m_my_part && m_my_part->IsAlias(); diff --git a/eeschema/symbol_editor/symbol_library_manager.cpp b/eeschema/symbol_editor/symbol_library_manager.cpp index ea85a48906..caf9ddd5c0 100644 --- a/eeschema/symbol_editor/symbol_library_manager.cpp +++ b/eeschema/symbol_editor/symbol_library_manager.cpp @@ -439,7 +439,6 @@ bool SYMBOL_LIBRARY_MANAGER::UpdatePartAfterRename( LIB_PART* aPart, const wxStr wxCHECK( partBuf, false ); libBuf.UpdateBuffer( partBuf, aPart ); - SetCurrentPart( aPart->GetName() ); m_frame.SyncLibraries( false ); return true; diff --git a/eeschema/symbol_editor/symbol_library_manager.h b/eeschema/symbol_editor/symbol_library_manager.h index 35e859d412..4e54d1456c 100644 --- a/eeschema/symbol_editor/symbol_library_manager.h +++ b/eeschema/symbol_editor/symbol_library_manager.h @@ -278,26 +278,6 @@ public: */ wxObjectDataPtr& 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 ); /** @@ -480,9 +460,6 @@ private: LIB_LOGGER m_logger; int m_syncHash; ///< Symbol lib table hash value from last synchronization - wxString m_currentLib; ///< Currently modified part - wxString m_currentPart; ///< Currently modified library - wxObjectDataPtr m_adapter; }; diff --git a/eeschema/symbol_tree_synchronizing_adapter.cpp b/eeschema/symbol_tree_synchronizing_adapter.cpp index 846a7ef093..e556720006 100644 --- a/eeschema/symbol_tree_synchronizing_adapter.cpp +++ b/eeschema/symbol_tree_synchronizing_adapter.cpp @@ -280,25 +280,26 @@ bool SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetAttr( wxDataViewItem const& aItem, un if( aCol != 0 ) return false; + LIB_PART* curPart = m_frame->GetCurPart(); + switch( node->m_Type ) { case LIB_TREE_NODE::LIB: // mark modified libs with bold font 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__ - // 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.... - if( node->m_Name == m_libMgr->GetCurrentLib() ) + // 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.... aAttr.SetColour( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT ) ); #else - // mark the current library with background color - if( node->m_Name == m_libMgr->GetCurrentLib() ) - { aAttr.SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT ) ); aAttr.SetColour( wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOXHIGHLIGHTTEXT ) ); - } #endif + } break; case LIB_TREE_NODE::LIBID: @@ -308,19 +309,18 @@ bool SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetAttr( wxDataViewItem const& aItem, un // mark aliases with italic font aAttr.SetItalic( !node->m_IsRoot ); + // mark the current part with background color + if( curPart && curPart->GetLibId() == node->m_LibId ) + { #ifdef __WXGTK__ // 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.... - if( node->m_LibId == m_libMgr->GetCurrentLibId() ) aAttr.SetColour( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT ) ); #else - // mark the current part with background color - if( node->m_LibId == m_libMgr->GetCurrentLibId() ) - { aAttr.SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT ) ); aAttr.SetColour( wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOXHIGHLIGHTTEXT ) ); - } #endif + } break; default: diff --git a/eeschema/tools/symbol_editor_drawing_tools.cpp b/eeschema/tools/symbol_editor_drawing_tools.cpp index ca2ba52012..f9aac62a9e 100644 --- a/eeschema/tools/symbol_editor_drawing_tools.cpp +++ b/eeschema/tools/symbol_editor_drawing_tools.cpp @@ -26,7 +26,6 @@ #include #include #include -#include #include #include #include @@ -41,7 +40,6 @@ #include #include #include -#include "ee_point_editor.h" static void* g_lastPinWeakPtr;