26#include <wx/clipbrd.h>
27#include <wx/listbox.h>
46 m_parent( aParent ), m_listBox( aListBox )
88 for(
const auto& [
id,
string] : aItems )
97 wxArrayInt selections;
100 std::sort( selections.begin(), selections.end() );
102 for(
int ii = selections.GetCount() - 1; ii >= 0; ii-- )
107 m_listBox.SetSelection( std::max( 0, selections[0] - 1 ) );
109 wxPostEvent( &
m_listBox, wxCommandEvent( EDA_EVT_LISTBOX_CHANGED ) );
116 wxArrayInt selections;
119 wxArrayString result;
120 for(
size_t ii = 0; ii < selections.GetCount(); ii++ )
121 result.Add(
m_listBox.GetString( selections[ii] ) );
129 wxArrayInt selections;
132 int insertAt = selections.GetCount() > 0 ? selections.back() + 1 :
m_listBox.GetCount();
136 for(
size_t ii = 0; ii < selections.GetCount(); ii++ )
144 wxPostEvent( &
m_listBox, wxCommandEvent( EDA_EVT_LISTBOX_CHANGED ) );
153 for(
const wxString&
filter : filters )
155 result +=
filter + wxT(
"\n" );
158 if( wxTheClipboard->Open() )
160 wxTheClipboard->SetData(
new wxTextDataObject( result ) );
161 wxTheClipboard->Close();
169 if( wxTheClipboard->Open() )
171 wxTextDataObject data;
172 wxTheClipboard->GetData( data );
174 wxString
text = data.GetText();
177 lines = wxSplit(
text,
'\n' );
179 wxTheClipboard->Close();
182 wxArrayInt selections;
184 int insertAt = selections.GetCount() > 0 ? selections.back() + 1 :
m_listBox.GetCount();
186 for( wxString& line : lines )
192 m_listBox.InsertItems( lines, insertAt );
195 for(
size_t ii = insertAt; ii < insertAt + lines.GetCount(); ii++ )
198 wxPostEvent( &
m_listBox, wxCommandEvent( EDA_EVT_LISTBOX_CHANGED ) );
207 size_t select = deleted.GetCount() > 0 ? deleted[0] :
m_listBox.GetCount();
218 const auto mstr = [&](
const MENU_ID& id )
228 mstr(
ID_CUT ) +
"\tCtrl+X",
241 menu.Bind( wxEVT_COMMAND_MENU_SELECTED,
242 [&]( wxCommandEvent& aCmd )
244 switch( aEvent.GetId() )
246 case ID_COPY: listBoxCopy(); break;
247 case ID_PASTE: listBoxPaste(); break;
248 case ID_CUT: listBoxCut(); break;
249 case ID_DELETE: listBoxDeleteSelected(); break;
250 case ID_DUPLICATE: listBoxDuplicateSelected(); break;
251 default: aEvent.Skip();
261 if( aEvent.GetKeyCode() == WXK_DELETE )
267 if( aEvent.ControlDown() )
269 switch( aEvent.GetKeyCode() )
275 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.