SHARE
TWEET

Untitled

a guest Jun 19th, 2017 58 in 8 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. From a97825bd4191b5f64d8f954f6941acd8d7bbb5db Mon Sep 17 00:00:00 2001
  2. From: Maciej Suminski <maciej.suminski@cern.ch>
  3. Date: Mon, 10 Apr 2017 16:43:25 +0200
  4. Subject: [PATCH 2/2] Flags to select additional widgets for COMPONENT_TREE
  5.  
  6. ---
  7.  eeschema/widgets/component_tree.cpp | 79 +++++++++++++++++++++++--------------
  8.  eeschema/widgets/component_tree.h   |  8 +++-
  9.  2 files changed, 55 insertions(+), 32 deletions(-)
  10.  
  11. diff --git a/eeschema/widgets/component_tree.cpp b/eeschema/widgets/component_tree.cpp
  12. index 82ac8cdaa..aaec051b4 100644
  13. --- a/eeschema/widgets/component_tree.cpp
  14. +++ b/eeschema/widgets/component_tree.cpp
  15. @@ -32,44 +32,57 @@
  16.  #include <wx/statbmp.h>
  17.  #include <wx/html/htmlwin.h>
  18.  
  19. -COMPONENT_TREE::COMPONENT_TREE( wxWindow* aParent, CMP_TREE_MODEL_ADAPTER::PTR& aAdapter )
  20. -    : wxPanel( aParent ), m_adapter( aAdapter )
  21. +COMPONENT_TREE::COMPONENT_TREE( wxWindow* aParent,
  22. +        CMP_TREE_MODEL_ADAPTER::PTR& aAdapter, WIDGETS aWidgets )
  23. +    : wxPanel( aParent ), m_adapter( aAdapter ), m_query_ctrl( nullptr ), m_details_ctrl( nullptr )
  24.  {
  25.      auto sizer = new wxBoxSizer( wxVERTICAL );
  26. -    auto search_sizer = new wxBoxSizer( wxHORIZONTAL );
  27.  
  28. -    m_query_ctrl = new wxTextCtrl(
  29. -            this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER );
  30. -
  31. -    m_tree_ctrl =
  32. -            new wxDataViewCtrl( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxDV_SINGLE );
  33. -    m_adapter->AttachTo( m_tree_ctrl );
  34. +    // Search text control
  35. +    if( aWidgets & SEARCH )
  36. +    {
  37. +        auto search_sizer = new wxBoxSizer( wxHORIZONTAL );
  38.  
  39. -    m_details_ctrl = new wxHtmlWindow( this, wxID_ANY, wxDefaultPosition, wxSize( 320, 240 ),
  40. -            wxHW_SCROLLBAR_AUTO | wxSUNKEN_BORDER );
  41. +        m_query_ctrl = new wxTextCtrl(
  42. +                this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER );
  43.  
  44.  // Additional visual cue for GTK, which hides the placeholder text on focus
  45.  #ifdef __WXGTK__
  46. -    search_sizer->Add( new wxStaticBitmap( this, wxID_ANY,
  47. -                               wxArtProvider::GetBitmap( wxART_FIND, wxART_FRAME_ICON ) ),
  48. -            0, wxALIGN_CENTER | wxALL, 5 );
  49. +        search_sizer->Add( new wxStaticBitmap( this, wxID_ANY,
  50. +                                wxArtProvider::GetBitmap( wxART_FIND, wxART_FRAME_ICON ) ),
  51. +                0, wxALIGN_CENTER | wxALL, 5 );
  52.  #endif
  53.  
  54. -    search_sizer->Add( m_query_ctrl, 1, wxALIGN_CENTER | wxALL | wxEXPAND, 5 );
  55. +        search_sizer->Add( m_query_ctrl, 1, wxALIGN_CENTER | wxALL | wxEXPAND, 5 );
  56. +        sizer->Add( search_sizer, 0, wxEXPAND, 5 );
  57. +
  58. +        m_query_ctrl->Bind( wxEVT_TEXT, &COMPONENT_TREE::onQueryText, this );
  59. +        m_query_ctrl->Bind( wxEVT_TEXT_ENTER, &COMPONENT_TREE::onQueryEnter, this );
  60. +        m_query_ctrl->Bind( wxEVT_CHAR_HOOK, &COMPONENT_TREE::onQueryCharHook, this );
  61. +    }
  62. +
  63. +    // Component tree
  64. +    m_tree_ctrl =
  65. +            new wxDataViewCtrl( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxDV_SINGLE );
  66. +    m_adapter->AttachTo( m_tree_ctrl );
  67.  
  68. -    sizer->Add( search_sizer, 0, wxEXPAND, 5 );
  69.      sizer->Add( m_tree_ctrl, 1, wxALL | wxEXPAND, 5 );
  70. -    sizer->Add( m_details_ctrl, 1, wxALL | wxEXPAND, 5 );
  71. +
  72. +    // Description panel
  73. +    if( aWidgets & DETAILS )
  74. +    {
  75. +        m_details_ctrl = new wxHtmlWindow( this, wxID_ANY, wxDefaultPosition, wxSize( 320, 240 ),
  76. +                wxHW_SCROLLBAR_AUTO | wxSUNKEN_BORDER );
  77. +
  78. +        sizer->Add( m_details_ctrl, 1, wxALL | wxEXPAND, 5 );
  79. +        m_details_ctrl->Bind( wxEVT_HTML_LINK_CLICKED, &COMPONENT_TREE::onDetailsLink, this );
  80. +    }
  81.  
  82.      SetSizer( sizer );
  83.  
  84.      Bind( wxEVT_INIT_DIALOG, &COMPONENT_TREE::onInitDialog, this );
  85. -    m_query_ctrl->Bind( wxEVT_TEXT, &COMPONENT_TREE::onQueryText, this );
  86. -    m_query_ctrl->Bind( wxEVT_TEXT_ENTER, &COMPONENT_TREE::onQueryEnter, this );
  87. -    m_query_ctrl->Bind( wxEVT_CHAR_HOOK, &COMPONENT_TREE::onQueryCharHook, this );
  88.      m_tree_ctrl->Bind( wxEVT_DATAVIEW_ITEM_ACTIVATED, &COMPONENT_TREE::onTreeActivate, this );
  89.      m_tree_ctrl->Bind( wxEVT_DATAVIEW_SELECTION_CHANGED, &COMPONENT_TREE::onTreeSelect, this );
  90. -    m_details_ctrl->Bind( wxEVT_HTML_LINK_CLICKED, &COMPONENT_TREE::onDetailsLink, this );
  91.  
  92.      Layout();
  93.      sizer->Fit( this );
  94. @@ -124,9 +137,12 @@ void COMPONENT_TREE::onInitDialog( wxInitDialogEvent& aEvent )
  95.  {
  96.      // If wxTextCtrl::SetHint() is called before binding wxEVT_TEXT, the event
  97.      // handler will intermittently fire.
  98. -    m_query_ctrl->SetHint( _( "Search" ) );
  99. -    m_query_ctrl->SetFocus();
  100. -    m_query_ctrl->SetValue( wxEmptyString );
  101. +    if( m_query_ctrl )
  102. +    {
  103. +        m_query_ctrl->SetHint( _( "Search" ) );
  104. +        m_query_ctrl->SetFocus();
  105. +        m_query_ctrl->SetValue( wxEmptyString );
  106. +    }
  107.  
  108.      // There may be a part preselected in the model. Make sure it is displayed.
  109.      postSelectEvent();
  110. @@ -169,13 +185,16 @@ void COMPONENT_TREE::onQueryCharHook( wxKeyEvent& aKeyStroke )
  111.  
  112.  void COMPONENT_TREE::onTreeSelect( wxDataViewEvent& aEvent )
  113.  {
  114. -    int unit = 0;
  115. -    LIB_ALIAS* alias = GetSelectedAlias( &unit );
  116. +    if( m_details_ctrl )
  117. +    {
  118. +        int unit = 0;
  119. +        LIB_ALIAS* alias = GetSelectedAlias( &unit );
  120.  
  121. -    if( alias )
  122. -        m_details_ctrl->SetPage( GenerateAliasInfo( alias, unit ) );
  123. -    else
  124. -        m_details_ctrl->SetPage( wxEmptyString );
  125. +        if( alias )
  126. +            m_details_ctrl->SetPage( GenerateAliasInfo( alias, unit ) );
  127. +        else
  128. +            m_details_ctrl->SetPage( wxEmptyString );
  129. +    }
  130.  
  131.      aEvent.Skip();
  132.  }
  133. diff --git a/eeschema/widgets/component_tree.h b/eeschema/widgets/component_tree.h
  134. index 706fd1d87..69c970944 100644
  135. --- a/eeschema/widgets/component_tree.h
  136. +++ b/eeschema/widgets/component_tree.h
  137. @@ -35,12 +35,16 @@ class wxHtmlWindow;
  138.  class wxHtmlLinkEvent;
  139.  
  140.  /**
  141. - * Widget displaying a tree of components with a search text control and description.
  142. + * Widget displaying a tree of components with optional search text control and description panel.
  143.   */
  144.  class COMPONENT_TREE : public wxPanel
  145.  {
  146.  public:
  147. -    COMPONENT_TREE( wxWindow* aParent, CMP_TREE_MODEL_ADAPTER::PTR& aAdapter );
  148. +    ///> Flags to select extra widgets
  149. +    enum WIDGETS { NONE = 0x00, SEARCH = 0x01, DETAILS = 0x02, ALL = 0xFF };
  150. +
  151. +    COMPONENT_TREE( wxWindow* aParent,
  152. +            CMP_TREE_MODEL_ADAPTER::PTR& aAdapter, WIDGETS aWidgets = ALL );
  153.  
  154.      /**
  155.       * For multi-unit components, if the user selects the component itself
  156. --
  157. 2.12.0
RAW Paste Data
Pastebin PRO Summer Special!
Get 40% OFF on Pastebin PRO accounts!
Top