From 6733101c6f5d9a36fed3d8133581146ffac8dab1 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 10 Apr 2017 16:43:25 +0200 Subject: [PATCH] Flags to select additional widgets for COMPONENT_TREE --- eeschema/widgets/component_tree.cpp | 83 ++++++++++++++++++----------- eeschema/widgets/component_tree.h | 8 ++- 2 files changed, 57 insertions(+), 34 deletions(-) diff --git a/eeschema/widgets/component_tree.cpp b/eeschema/widgets/component_tree.cpp index 82ac8cdaac..aaec051b46 100644 --- a/eeschema/widgets/component_tree.cpp +++ b/eeschema/widgets/component_tree.cpp @@ -32,44 +32,57 @@ #include #include -COMPONENT_TREE::COMPONENT_TREE( wxWindow* aParent, CMP_TREE_MODEL_ADAPTER::PTR& aAdapter ) - : wxPanel( aParent ), m_adapter( aAdapter ) +COMPONENT_TREE::COMPONENT_TREE( wxWindow* aParent, + CMP_TREE_MODEL_ADAPTER::PTR& aAdapter, WIDGETS aWidgets ) + : wxPanel( aParent ), m_adapter( aAdapter ), m_query_ctrl( nullptr ), m_details_ctrl( nullptr ) { auto sizer = new wxBoxSizer( wxVERTICAL ); - auto search_sizer = new wxBoxSizer( wxHORIZONTAL ); - m_query_ctrl = new wxTextCtrl( - this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER ); + // Search text control + if( aWidgets & SEARCH ) + { + auto search_sizer = new wxBoxSizer( wxHORIZONTAL ); + m_query_ctrl = new wxTextCtrl( + this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER ); + +// Additional visual cue for GTK, which hides the placeholder text on focus +#ifdef __WXGTK__ + search_sizer->Add( new wxStaticBitmap( this, wxID_ANY, + wxArtProvider::GetBitmap( wxART_FIND, wxART_FRAME_ICON ) ), + 0, wxALIGN_CENTER | wxALL, 5 ); +#endif + + search_sizer->Add( m_query_ctrl, 1, wxALIGN_CENTER | wxALL | wxEXPAND, 5 ); + sizer->Add( search_sizer, 0, wxEXPAND, 5 ); + + m_query_ctrl->Bind( wxEVT_TEXT, &COMPONENT_TREE::onQueryText, this ); + m_query_ctrl->Bind( wxEVT_TEXT_ENTER, &COMPONENT_TREE::onQueryEnter, this ); + m_query_ctrl->Bind( wxEVT_CHAR_HOOK, &COMPONENT_TREE::onQueryCharHook, this ); + } + + // Component tree m_tree_ctrl = new wxDataViewCtrl( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxDV_SINGLE ); m_adapter->AttachTo( m_tree_ctrl ); - m_details_ctrl = new wxHtmlWindow( this, wxID_ANY, wxDefaultPosition, wxSize( 320, 240 ), - wxHW_SCROLLBAR_AUTO | wxSUNKEN_BORDER ); - -// Additional visual cue for GTK, which hides the placeholder text on focus -#ifdef __WXGTK__ - search_sizer->Add( new wxStaticBitmap( this, wxID_ANY, - wxArtProvider::GetBitmap( wxART_FIND, wxART_FRAME_ICON ) ), - 0, wxALIGN_CENTER | wxALL, 5 ); -#endif - - search_sizer->Add( m_query_ctrl, 1, wxALIGN_CENTER | wxALL | wxEXPAND, 5 ); - - sizer->Add( search_sizer, 0, wxEXPAND, 5 ); sizer->Add( m_tree_ctrl, 1, wxALL | wxEXPAND, 5 ); - sizer->Add( m_details_ctrl, 1, wxALL | wxEXPAND, 5 ); + + // Description panel + if( aWidgets & DETAILS ) + { + m_details_ctrl = new wxHtmlWindow( this, wxID_ANY, wxDefaultPosition, wxSize( 320, 240 ), + wxHW_SCROLLBAR_AUTO | wxSUNKEN_BORDER ); + + sizer->Add( m_details_ctrl, 1, wxALL | wxEXPAND, 5 ); + m_details_ctrl->Bind( wxEVT_HTML_LINK_CLICKED, &COMPONENT_TREE::onDetailsLink, this ); + } SetSizer( sizer ); Bind( wxEVT_INIT_DIALOG, &COMPONENT_TREE::onInitDialog, this ); - m_query_ctrl->Bind( wxEVT_TEXT, &COMPONENT_TREE::onQueryText, this ); - m_query_ctrl->Bind( wxEVT_TEXT_ENTER, &COMPONENT_TREE::onQueryEnter, this ); - m_query_ctrl->Bind( wxEVT_CHAR_HOOK, &COMPONENT_TREE::onQueryCharHook, this ); m_tree_ctrl->Bind( wxEVT_DATAVIEW_ITEM_ACTIVATED, &COMPONENT_TREE::onTreeActivate, this ); m_tree_ctrl->Bind( wxEVT_DATAVIEW_SELECTION_CHANGED, &COMPONENT_TREE::onTreeSelect, this ); - m_details_ctrl->Bind( wxEVT_HTML_LINK_CLICKED, &COMPONENT_TREE::onDetailsLink, this ); Layout(); sizer->Fit( this ); @@ -124,9 +137,12 @@ void COMPONENT_TREE::onInitDialog( wxInitDialogEvent& aEvent ) { // If wxTextCtrl::SetHint() is called before binding wxEVT_TEXT, the event // handler will intermittently fire. - m_query_ctrl->SetHint( _( "Search" ) ); - m_query_ctrl->SetFocus(); - m_query_ctrl->SetValue( wxEmptyString ); + if( m_query_ctrl ) + { + m_query_ctrl->SetHint( _( "Search" ) ); + m_query_ctrl->SetFocus(); + m_query_ctrl->SetValue( wxEmptyString ); + } // There may be a part preselected in the model. Make sure it is displayed. postSelectEvent(); @@ -169,13 +185,16 @@ void COMPONENT_TREE::onQueryCharHook( wxKeyEvent& aKeyStroke ) void COMPONENT_TREE::onTreeSelect( wxDataViewEvent& aEvent ) { - int unit = 0; - LIB_ALIAS* alias = GetSelectedAlias( &unit ); + if( m_details_ctrl ) + { + int unit = 0; + LIB_ALIAS* alias = GetSelectedAlias( &unit ); - if( alias ) - m_details_ctrl->SetPage( GenerateAliasInfo( alias, unit ) ); - else - m_details_ctrl->SetPage( wxEmptyString ); + if( alias ) + m_details_ctrl->SetPage( GenerateAliasInfo( alias, unit ) ); + else + m_details_ctrl->SetPage( wxEmptyString ); + } aEvent.Skip(); } diff --git a/eeschema/widgets/component_tree.h b/eeschema/widgets/component_tree.h index 706fd1d87f..69c9709444 100644 --- a/eeschema/widgets/component_tree.h +++ b/eeschema/widgets/component_tree.h @@ -35,12 +35,16 @@ class wxHtmlWindow; class wxHtmlLinkEvent; /** - * Widget displaying a tree of components with a search text control and description. + * Widget displaying a tree of components with optional search text control and description panel. */ class COMPONENT_TREE : public wxPanel { public: - COMPONENT_TREE( wxWindow* aParent, CMP_TREE_MODEL_ADAPTER::PTR& aAdapter ); + ///> Flags to select extra widgets + enum WIDGETS { NONE = 0x00, SEARCH = 0x01, DETAILS = 0x02, ALL = 0xFF }; + + COMPONENT_TREE( wxWindow* aParent, + CMP_TREE_MODEL_ADAPTER::PTR& aAdapter, WIDGETS aWidgets = ALL ); /** * For multi-unit components, if the user selects the component itself