KiCad PCB EDA Suite
Loading...
Searching...
No Matches
lib_table_grid_tricks.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2017-2023 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
21#include "lib_table_grid.h"
22
23
25 GRID_TRICKS( aGrid )
26{
27}
28
29
30void LIB_TABLE_GRID_TRICKS::showPopupMenu( wxMenu& menu, wxGridEvent& aEvent )
31{
33 _( "Edit options..." ),
34 _( "Edit options for this library entry" ) );
35
36 menu.AppendSeparator();
37
38 bool showActivate = false;
39 bool showDeactivate = false;
40 bool showSetVisible = false;
41 bool showUnsetVisible = false;
42 LIB_TABLE_GRID* tbl = static_cast<LIB_TABLE_GRID*>( m_grid->GetTable() );
43
44 // Ensure selection parameters are up to date
46
47 for( int row = m_sel_row_start; row < m_sel_row_start + m_sel_row_count; ++row )
48 {
49 if( tbl->GetValueAsBool( row, 0 ) )
50 showDeactivate = true;
51 else
52 showActivate = true;
53
54 if( tbl->GetValueAsBool( row, 1 ) )
55 showUnsetVisible = true;
56 else
57 showSetVisible = true;
58
59 if( showActivate && showDeactivate && showSetVisible && showUnsetVisible )
60 break;
61 }
62
63 if( showActivate )
64 menu.Append( LIB_TABLE_GRID_TRICKS_ACTIVATE_SELECTED, _( "Activate selected" ) );
65
66 if( showDeactivate )
67 menu.Append( LIB_TABLE_GRID_TRICKS_DEACTIVATE_SELECTED, _( "Deactivate selected" ) );
68
70 {
71 if( showSetVisible )
72 menu.Append( LIB_TABLE_GRID_TRICKS_SET_VISIBLE, _( "Set visible flag" ) );
73
74 if( showUnsetVisible )
75 menu.Append( LIB_TABLE_GRID_TRICKS_UNSET_VISIBLE, _( "Unset visible flag" ) );
76 }
77
78 bool showSettings = false;
79
81 {
82 showSettings = true;
84 wxString::Format( _( "Library settings for %s..." ),
85 tbl->GetValue( m_sel_row_start, 2 ) ) );
86 }
87
88 if( showActivate || showDeactivate || showSetVisible || showUnsetVisible || showSettings )
89 menu.AppendSeparator();
90
91 GRID_TRICKS::showPopupMenu( menu, aEvent );
92}
93
94
95void LIB_TABLE_GRID_TRICKS::doPopupSelection( wxCommandEvent& event )
96{
97 int menu_id = event.GetId();
98 LIB_TABLE_GRID* tbl = (LIB_TABLE_GRID*) m_grid->GetTable();
99
101 {
102 optionsEditor( m_grid->GetGridCursorRow() );
103 }
106 {
107 bool selected_state = menu_id == LIB_TABLE_GRID_TRICKS_ACTIVATE_SELECTED;
108
109 for( int row = m_sel_row_start; row < m_sel_row_start + m_sel_row_count; ++row )
110 tbl->SetValueAsBool( row, 0, selected_state );
111
112 // Ensure the new state (on/off) of the widgets is immediately shown:
113 m_grid->Refresh();
114 }
115 else if( menu_id == LIB_TABLE_GRID_TRICKS_SET_VISIBLE
117 {
118 bool selected_state = menu_id == LIB_TABLE_GRID_TRICKS_SET_VISIBLE;
119
120 for( int row = m_sel_row_start; row < m_sel_row_start + m_sel_row_count; ++row )
121 tbl->SetValueAsBool( row, 1, selected_state );
122
123 // Ensure the new state (on/off) of the widgets is immediately shown:
124 m_grid->Refresh();
125 }
126 else if( menu_id == LIB_TABLE_GRID_TRICKS_LIBRARY_SETTINGS )
127 {
128 LIB_TABLE_ROW* row = tbl->At( m_sel_row_start );
129 row->Refresh();
130 row->ShowSettingsDialog( m_grid->GetParent() );
131 }
132 else
133 {
135 }
136}
137
138
140{
141 if( aEvent.GetCol() == COL_OPTIONS )
142 {
143 optionsEditor( aEvent.GetRow() );
144 return true;
145 }
146
147 return false;
148}
149
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
Definition: grid_tricks.h:61
void getSelectedArea()
Puts the selected area into a sensible rectangle of m_sel_{row,col}_{start,count} above.
virtual void doPopupSelection(wxCommandEvent &event)
virtual void showPopupMenu(wxMenu &menu, wxGridEvent &aEvent)
int m_sel_row_start
Definition: grid_tricks.h:129
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:125
int m_sel_row_count
Definition: grid_tricks.h:131
bool handleDoubleClick(wxGridEvent &aEvent) override
LIB_TABLE_GRID_TRICKS(WX_GRID *aGrid)
virtual void optionsEditor(int aRow)=0
virtual bool supportsVisibilityColumn()
void doPopupSelection(wxCommandEvent &event) override
void showPopupMenu(wxMenu &menu, wxGridEvent &aEvent) override
This abstract base class mixes any object derived from LIB_TABLE into wxGridTableBase so the result c...
void SetValueAsBool(int aRow, int aCol, bool aValue) override
wxString GetValue(int aRow, int aCol) override
LIB_TABLE_ROW * At(size_t aIndex)
bool GetValueAsBool(int aRow, int aCol) override
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE.
virtual void ShowSettingsDialog(wxWindow *aParent) const
virtual bool Refresh()
virtual bool SupportsSettingsDialog() const
#define _(s)
@ COL_OPTIONS