Debian Codegraph @

plugins/dm.gui/GuiSelector.h

raw
1 #pragma once
2
3 #include "wxutil/Icon.h"
4 #include "wxutil/dialog/DialogBase.h"
5 #include "wxutil/dataview/VFSTreePopulator.h"
6 #include "wxutil/dataview/TreeView.h"
7
8 class wxNotebook;
9 class wxBookCtrlEvent;
10
11 namespace ui
12 {
13
14 // Forward decl.
15 class ReadableEditorDialog;
16
17 ///////////////////////////// XDataSelector:
18 // Selector-Dialog for TwoSided and OneSided readable guis. Switching the pages of the notebook
19 // also toggles the according editing mode on the ReadableEditorDialog (TwoSided or OneSided).
20 // Selecting a gui definition updates the guiView for previewing.
21 class GuiSelector :
22 public wxutil::DialogBase,
23 public wxutil::VFSTreePopulator::Visitor
24 {
25 public:
26 // Treestore enum
27 struct GuiTreeModelColumns :
28 public wxutil::TreeModel::ColumnRecord
29 {
30 GuiTreeModelColumns() :
31 name(add(wxutil::TreeModel::Column::IconText)),
32 fullName(add(wxutil::TreeModel::Column::String)),
33 isFolder(add(wxutil::TreeModel::Column::Boolean))
34 {}
35
36 wxutil::TreeModel::Column name;
37 wxutil::TreeModel::Column fullName;
38 wxutil::TreeModel::Column isFolder;
39 };
40
41 private:
42 // Reference to the calling ReadableEditorDialog
43 ReadableEditorDialog* _editorDialog;
44
45 // The name that was picked.
46 std::string _name;
47
48 // The notebook holding the tabs for one-sided and two-sided readables.
49 wxNotebook* _notebook;
50
51 GuiTreeModelColumns _columns;
52 wxutil::TreeModel::Ptr _oneSidedStore;
53 wxutil::TreeModel::Ptr _twoSidedStore;
54
55 wxutil::TreeView* _oneSidedView;
56 wxutil::TreeView* _twoSidedView;
57
58 wxutil::Icon _guiIcon;
59 wxutil::Icon _folderIcon;
60
61 public:
62 // Starts the GuiSelector and returns the name of the selected GUI or an empty string if the user canceled.
63 // The dialog shows the twoSided treeview if twoSided is true.
64 static std::string Run(bool twoSided, ReadableEditorDialog* editorDialog);
65
66 void visit(wxutil::TreeModel& store, wxutil::TreeModel::Row& row,
67 const std::string& path, bool isExplicit);
68
69 // Disconnect all events when the dialog is destroyed
70 virtual bool Destroy() override;
71
72 private:
73 GuiSelector(bool twoSided, ReadableEditorDialog* editorDialog);
74
75 void fillTrees();
76
77 void populateWindow();
78
79 void onSelectionChanged(wxDataViewEvent& ev);
80 void onPageSwitch(wxBookCtrlEvent& ev);
81 };
82
83 } // namespace