SPH
RunSelectDialog.cpp
Go to the documentation of this file.
2 #include <wx/button.h>
3 #include <wx/checkbox.h>
4 #include <wx/listctrl.h>
5 #include <wx/msgdlg.h>
6 #include <wx/sizer.h>
7 #include <wx/stattext.h>
8 
10 
12  : wxDialog(parent, wxID_ANY, "Select run", wxDefaultPosition, wxSize(800, 500))
13  , nodes(std::move(nodes)) {
14 
15  wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
16  sizer->Add(new wxStaticText(this, wxID_ANY, "Select run:"));
17  const int listHeight = this->GetClientSize().y - 70;
18  wxListCtrl* list = new wxListCtrl(
19  this, wxID_ANY, wxDefaultPosition, wxSize(800, listHeight), wxLC_REPORT | wxLC_SINGLE_SEL);
20  const int columnWidth = list->GetSize().x / 2 - 5;
21  list->AppendColumn("Name");
22  list->AppendColumn("Type");
23  list->SetColumnWidth(0, columnWidth);
24  list->SetColumnWidth(1, columnWidth);
25  int index = 0;
26  for (auto& node : this->nodes) {
27  wxListItem item;
28  item.SetId(index);
29  item.SetText(node->instanceName());
30  item.SetColumn(0);
31  list->InsertItem(item);
32 
33  list->SetItem(index, 1, node->className());
34 
35  ++index;
36  }
37  list->Bind(wxEVT_LIST_ITEM_ACTIVATED, [this](wxListEvent& evt) { select(evt.GetIndex()); });
38  sizer->Add(list);
39  rememberBox = new wxCheckBox(this, wxID_ANY, "Remember choice");
40  sizer->Add(rememberBox);
41 
42  wxBoxSizer* buttonSizer = new wxBoxSizer(wxHORIZONTAL);
43  wxButton* runButton = new wxButton(this, wxID_ANY, "Run");
44  runButton->Bind(wxEVT_BUTTON, [this, list](wxCommandEvent& UNUSED(evt)) {
45  int item = list->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
46  if (item == -1) {
47  wxMessageBox("No run selected", "No run", wxOK | wxCENTRE);
48  return;
49  }
50  select(item);
51  });
52  wxButton* cancelButton = new wxButton(this, wxID_ANY, "Cancel");
53  cancelButton->Bind(wxEVT_BUTTON, [this](wxCommandEvent& UNUSED(evt)) { this->EndModal(wxID_CANCEL); });
54  buttonSizer->Add(runButton);
55  buttonSizer->Add(cancelButton);
56  sizer->Add(buttonSizer, 0, wxALIGN_RIGHT);
57 
58  this->SetSizer(sizer);
59 }
60 
62 
64  return rememberBox->GetValue();
65 }
66 
67 void RunSelectDialog::select(const int index) {
68  selected = nodes[index];
69  this->EndModal(wxID_OK);
70 }
71 
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
#define UNUSED(x)
Definition: Object.h:37
#define NAMESPACE_SPH_END
Definition: Object.h:12
Generic dynamically allocated resizable storage.
Definition: Array.h:43
bool remember() const
RunSelectDialog(wxWindow *parent, Array< SharedPtr< JobNode >> &&nodes)
Overload of std::swap for Sph::Array.
Definition: Array.h:578