Right-click context menus for COMPONENT_TREE widget
This commit is contained in:
parent
42220579df
commit
3288a5f8b8
|
@ -133,6 +133,7 @@ CMP_TREE_NODE_LIB_ID::CMP_TREE_NODE_LIB_ID( CMP_TREE_NODE* aParent, LIB_ALIAS* a
|
||||||
|
|
||||||
Type = LIBID;
|
Type = LIBID;
|
||||||
Parent = aParent;
|
Parent = aParent;
|
||||||
|
Type = ALIAS;
|
||||||
Name = aAlias->GetName();
|
Name = aAlias->GetName();
|
||||||
Desc = aAlias->GetDescription();
|
Desc = aAlias->GetDescription();
|
||||||
|
|
||||||
|
|
|
@ -261,6 +261,13 @@ int CMP_TREE_MODEL_ADAPTER::GetUnitFor( const wxDataViewItem& aSelection ) const
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
CMP_TREE_NODE::TYPE CMP_TREE_MODEL_ADAPTER::GetTypeFor( const wxDataViewItem& aSelection ) const
|
||||||
|
{
|
||||||
|
auto node = ToNode( aSelection );
|
||||||
|
return node ? node->Type : CMP_TREE_NODE::INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int CMP_TREE_MODEL_ADAPTER::GetComponentsCount() const
|
int CMP_TREE_MODEL_ADAPTER::GetComponentsCount() const
|
||||||
{
|
{
|
||||||
int n = 0;
|
int n = 0;
|
||||||
|
|
|
@ -225,6 +225,16 @@ public:
|
||||||
*/
|
*/
|
||||||
int GetUnitFor( const wxDataViewItem& aSelection ) const;
|
int GetUnitFor( const wxDataViewItem& aSelection ) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return node type for the given item.
|
||||||
|
*
|
||||||
|
* @param aSelection item from the wxDataViewCtrl
|
||||||
|
* (see wxDataViewCtrl::GetSelection())
|
||||||
|
*
|
||||||
|
* @return Type of the selected node, might be INVALID.
|
||||||
|
*/
|
||||||
|
CMP_TREE_NODE::TYPE GetTypeFor( const wxDataViewItem& aSelection ) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the number of components loaded in the tree.
|
* Return the number of components loaded in the tree.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -43,6 +43,9 @@ COMPONENT_TREE::COMPONENT_TREE( wxWindow* aParent, SYMBOL_LIB_TABLE* aSymLibTabl
|
||||||
m_query_ctrl( nullptr ),
|
m_query_ctrl( nullptr ),
|
||||||
m_details_ctrl( nullptr )
|
m_details_ctrl( nullptr )
|
||||||
{
|
{
|
||||||
|
// create space for context menu pointers, INVALID is the max value
|
||||||
|
m_menus.resize( CMP_TREE_NODE::TYPE::INVALID + 1 );
|
||||||
|
|
||||||
auto sizer = new wxBoxSizer( wxVERTICAL );
|
auto sizer = new wxBoxSizer( wxVERTICAL );
|
||||||
|
|
||||||
// Search text control
|
// Search text control
|
||||||
|
@ -89,6 +92,7 @@ COMPONENT_TREE::COMPONENT_TREE( wxWindow* aParent, SYMBOL_LIB_TABLE* aSymLibTabl
|
||||||
|
|
||||||
m_tree_ctrl->Bind( wxEVT_DATAVIEW_ITEM_ACTIVATED, &COMPONENT_TREE::onTreeActivate, 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_tree_ctrl->Bind( wxEVT_DATAVIEW_SELECTION_CHANGED, &COMPONENT_TREE::onTreeSelect, this );
|
||||||
|
m_tree_ctrl->Bind( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, &COMPONENT_TREE::onContextMenu, this );
|
||||||
|
|
||||||
Bind( COMPONENT_PRESELECTED, &COMPONENT_TREE::onPreselect, this );
|
Bind( COMPONENT_PRESELECTED, &COMPONENT_TREE::onPreselect, this );
|
||||||
|
|
||||||
|
@ -236,5 +240,19 @@ void COMPONENT_TREE::onPreselect( wxCommandEvent& aEvent )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void COMPONENT_TREE::onContextMenu( wxDataViewEvent& aEvent )
|
||||||
|
{
|
||||||
|
auto const sel = m_tree_ctrl->GetSelection();
|
||||||
|
auto type = sel.IsOk() ? m_adapter->GetTypeFor( sel ) : CMP_TREE_NODE::INVALID;
|
||||||
|
|
||||||
|
if( m_menus[type] )
|
||||||
|
{
|
||||||
|
m_menuActive = true;
|
||||||
|
PopupMenu( m_menus[type].get() );
|
||||||
|
m_menuActive = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
wxDEFINE_EVENT( COMPONENT_PRESELECTED, wxCommandEvent );
|
wxDEFINE_EVENT( COMPONENT_PRESELECTED, wxCommandEvent );
|
||||||
wxDEFINE_EVENT( COMPONENT_SELECTED, wxCommandEvent );
|
wxDEFINE_EVENT( COMPONENT_SELECTED, wxCommandEvent );
|
||||||
|
|
|
@ -60,6 +60,25 @@ public:
|
||||||
*/
|
*/
|
||||||
LIB_ID GetSelectedLibId( int* aUnit = nullptr ) const;
|
LIB_ID GetSelectedLibId( int* aUnit = nullptr ) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Associates a right click context menu for a specific node type.
|
||||||
|
* @param aType is the node type to have a menu associated.
|
||||||
|
* @param aMenu is the associated menu.
|
||||||
|
*/
|
||||||
|
void SetMenu( CMP_TREE_NODE::TYPE aType, std::unique_ptr<wxMenu> aMenu )
|
||||||
|
{
|
||||||
|
m_menus[aType] = std::move( aMenu );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the status of right-click context menu.
|
||||||
|
* @return True in case a right-click context menu is active.
|
||||||
|
*/
|
||||||
|
bool IsMenuActive() const
|
||||||
|
{
|
||||||
|
return m_menuActive;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
* If a wxDataViewitem is valid, select it and post a selection event.
|
* If a wxDataViewitem is valid, select it and post a selection event.
|
||||||
|
@ -86,12 +105,20 @@ protected:
|
||||||
|
|
||||||
void onDetailsLink( wxHtmlLinkEvent& aEvent );
|
void onDetailsLink( wxHtmlLinkEvent& aEvent );
|
||||||
void onPreselect( wxCommandEvent& aEvent );
|
void onPreselect( wxCommandEvent& aEvent );
|
||||||
|
void onContextMenu( wxDataViewEvent& aEvent );
|
||||||
|
|
||||||
SYMBOL_LIB_TABLE* m_sym_lib_table;
|
SYMBOL_LIB_TABLE* m_sym_lib_table;
|
||||||
CMP_TREE_MODEL_ADAPTER::PTR m_adapter;
|
CMP_TREE_MODEL_ADAPTER::PTR m_adapter;
|
||||||
|
|
||||||
wxTextCtrl* m_query_ctrl;
|
wxTextCtrl* m_query_ctrl;
|
||||||
wxDataViewCtrl* m_tree_ctrl;
|
wxDataViewCtrl* m_tree_ctrl;
|
||||||
wxHtmlWindow* m_details_ctrl;
|
wxHtmlWindow* m_details_ctrl;
|
||||||
|
|
||||||
|
///> Right click context menus for each tree level
|
||||||
|
std::vector<std::unique_ptr<wxMenu>> m_menus;
|
||||||
|
|
||||||
|
///> Flag indicating whether a right-click context menu is active
|
||||||
|
bool m_menuActive;
|
||||||
};
|
};
|
||||||
|
|
||||||
///> Custom event sent when a new component is preselected
|
///> Custom event sent when a new component is preselected
|
||||||
|
|
Loading…
Reference in New Issue