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{
26}
27
28
29void LIB_TABLE_GRID_TRICKS::showPopupMenu( wxMenu& menu, wxGridEvent& aEvent )
30{
32 _( "Edit options..." ),
33 _( "Edit options for this library entry" ) );
34
35 menu.AppendSeparator();
36
37 bool showActivate = false;
38 bool showDeactivate = false;
39 bool showSetVisible = false;
40 bool showUnsetVisible = false;
41 LIB_TABLE_GRID* tbl = static_cast<LIB_TABLE_GRID*>( m_grid->GetTable() );
42
43 // Ensure selection parameters are up to date
45
46 for( int row = m_sel_row_start; row < m_sel_row_start + m_sel_row_count; ++row )
47 {
48 if( tbl->GetValueAsBool( row, 0 ) )
49 showDeactivate = true;
50 else
51 showActivate = true;
52
53 if( tbl->GetValueAsBool( row, 1 ) )
54 showUnsetVisible = true;
55 else
56 showSetVisible = true;
57
58 if( showActivate && showDeactivate && showSetVisible && showUnsetVisible )
59 break;
60 }
61
62 if( showActivate )
63 menu.Append( LIB_TABLE_GRID_TRICKS_ACTIVATE_SELECTED, _( "Activate selected" ) );
64
65 if( showDeactivate )
66 menu.Append( LIB_TABLE_GRID_TRICKS_DEACTIVATE_SELECTED, _( "Deactivate selected" ) );
67
68 if( showSetVisible )
69 menu.Append( LIB_TABLE_GRID_TRICKS_SET_VISIBLE, _( "Set visible flag" ) );
70
71 if( showUnsetVisible )
72 menu.Append( LIB_TABLE_GRID_TRICKS_UNSET_VISIBLE, _( "Unset visible flag" ) );
73
74 bool showSettings = false;
75
77 {
78 showSettings = true;
80 wxString::Format( _( "Library settings for %s..." ),
81 tbl->GetValue( m_sel_row_start, 2 ) ) );
82 }
83
84 if( showActivate || showDeactivate || showSetVisible || showUnsetVisible || showSettings )
85 menu.AppendSeparator();
86
87 GRID_TRICKS::showPopupMenu( menu, aEvent );
88}
89
90
91void LIB_TABLE_GRID_TRICKS::doPopupSelection( wxCommandEvent& event )
92{
93 int menu_id = event.GetId();
94 LIB_TABLE_GRID* tbl = (LIB_TABLE_GRID*) m_grid->GetTable();
95
97 {
98 optionsEditor( m_grid->GetGridCursorRow() );
99 }
102 {
103 bool selected_state = menu_id == LIB_TABLE_GRID_TRICKS_ACTIVATE_SELECTED;
104
105 for( int row = m_sel_row_start; row < m_sel_row_start + m_sel_row_count; ++row )
106 tbl->SetValueAsBool( row, 0, selected_state );
107
108 // Ensure the new state (on/off) of the widgets is immediately shown:
109 m_grid->Refresh();
110 }
111 else if( menu_id == LIB_TABLE_GRID_TRICKS_SET_VISIBLE
113 {
114 bool selected_state = menu_id == LIB_TABLE_GRID_TRICKS_SET_VISIBLE;
115
116 for( int row = m_sel_row_start; row < m_sel_row_start + m_sel_row_count; ++row )
117 tbl->SetValueAsBool( row, 1, selected_state );
118
119 // Ensure the new state (on/off) of the widgets is immediately shown:
120 m_grid->Refresh();
121 }
122 else if( menu_id == LIB_TABLE_GRID_TRICKS_LIBRARY_SETTINGS )
123 {
124 LIB_TABLE_ROW* row = tbl->At( m_sel_row_start );
125 row->Refresh();
126 row->ShowSettingsDialog( m_grid->GetParent() );
127 }
128 else
129 {
131 }
132}
133
134
136{
137 if( aEvent.GetCol() == COL_OPTIONS )
138 {
139 optionsEditor( aEvent.GetRow() );
140 return true;
141 }
142
143 return false;
144}
145
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
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