26#include <wx/clipbrd.h>
27#include <wx/listbox.h>
46 m_parent( aParent ), m_listBox( aListBox )
67 Connect( EDA_EVT_LISTBOX_DUPLICATE,
83 Disconnect( EDA_EVT_LISTBOX_DUPLICATE,
90 for(
const auto& [
id,
string] : aItems )
99 wxArrayInt selections;
102 std::sort( selections.begin(), selections.end() );
104 for(
int ii = selections.GetCount() - 1; ii >= 0; ii-- )
110 m_listBox.SetSelection( std::max( 0, selections[0] - 1 ) );
112 wxPostEvent( &
m_listBox, wxCommandEvent( EDA_EVT_LISTBOX_CHANGED ) );
119 wxArrayInt selections;
122 wxArrayString result;
124 for(
size_t ii = 0; ii < selections.GetCount(); ii++ )
125 result.Add(
m_listBox.GetString( selections[ii] ) );
133 wxArrayInt selections;
136 int insertAt = selections.GetCount() > 0 ? selections.back() + 1 :
m_listBox.GetCount();
140 for(
size_t ii = 0; ii < selections.GetCount(); ii++ )
148 wxPostEvent( &
m_listBox, wxCommandEvent( EDA_EVT_LISTBOX_CHANGED ) );
158 for(
const wxString&
filter : filters )
160 result +=
filter + wxT(
"\n" );
163 if( wxTheClipboard->Open() )
165 wxTheClipboard->SetData(
new wxTextDataObject( result ) );
166 wxTheClipboard->Close();
175 if( wxTheClipboard->Open() )
177 wxTextDataObject data;
178 wxTheClipboard->GetData( data );
180 wxString
text = data.GetText();
183 lines = wxSplit(
text,
'\n' );
185 wxTheClipboard->Close();
188 wxArrayInt selections;
190 int insertAt = selections.GetCount() > 0 ? selections.back() + 1 :
m_listBox.GetCount();
192 for( wxString& line : lines )
198 m_listBox.InsertItems( lines, insertAt );
202 for(
size_t ii = insertAt; ii < insertAt + lines.GetCount(); ii++ )
205 wxPostEvent( &
m_listBox, wxCommandEvent( EDA_EVT_LISTBOX_CHANGED ) );
214 size_t select = deleted.GetCount() > 0 ? deleted[0] :
m_listBox.GetCount();
225 const auto mstr = [&](
const MENU_ID& id ) ->
const wxString&
235 mstr(
ID_CUT ) +
"\tCtrl+X",
248 menu.Bind( wxEVT_COMMAND_MENU_SELECTED,
249 [&]( wxCommandEvent& aCmd )
251 switch( aEvent.GetId() )
253 case ID_COPY: listBoxCopy(); break;
254 case ID_PASTE: listBoxPaste(); break;
255 case ID_CUT: listBoxCut(); break;
256 case ID_DELETE: listBoxDeleteSelected(); break;
257 case ID_DUPLICATE: listBoxDuplicateSelected(); break;
258 default: aEvent.Skip();
268 if( aEvent.GetKeyCode() == WXK_DELETE )
274 if( aEvent.ControlDown() )
276 switch( aEvent.GetKeyCode() )
282 default: aEvent.Skip();
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
void OnListBoxCut(wxCommandEvent &aEvent)
void listBoxDuplicateSelected()
Duplicate the selected filters.
void OnListBoxDuplicate(wxCommandEvent &aEvent)
LISTBOX_TRICKS(wxWindow &aWindow, wxListBox &aListBox)
void OnListBoxPaste(wxCommandEvent &aEvent)
void OnListBoxCopy(wxCommandEvent &aEvent)
wxArrayString listBoxGetSelected() const
void OnListBoxDelete(wxCommandEvent &aEvent)
void OnListBoxKeyDown(wxKeyEvent &aEvent)
MENU_ID
These are the ids for the menu.
wxArrayInt listBoxDeleteSelected()
Delete the selected filters.
void SetMenuLabels(const std::map< MENU_ID, wxString > &aItems)
std::map< MENU_ID, wxString > m_menuStrings
void OnListBoxRDown(wxMouseEvent &aEvent)
wxDEFINE_EVENT(EDA_EVT_LISTBOX_COPY, wxCommandEvent)
KICOMMON_API wxMenuItem * AddMenuItem(wxMenu *aMenu, int aId, const wxString &aText, const wxBitmapBundle &aImage, wxItemKind aType=wxITEM_NORMAL)
Create and insert a menu item with an icon into aMenu.
Functions to provide common constants and other functions to assist in making a consistent UI.