Debian Codegraph @

plugins/script/interfaces/DialogInterface.h

raw
1 #pragma once
2
3 #include "iscript.h"
4 #include "iscriptinterface.h"
5 #include "ui/idialogmanager.h"
6
7 namespace script
8 {
9
10 // Wrapper class around IDialog
11 class ScriptDialog
12 {
13 ui::IDialogPtr _dialog;
14 public:
15 ScriptDialog(const ui::IDialogPtr& dialog) :
16 _dialog(dialog)
17 {}
18
19 void setTitle(const std::string& title)
20 {
21 if (_dialog != NULL) _dialog->setTitle(title);
22 }
23
24 ui::IDialog::Result run()
25 {
26 return (_dialog != NULL) ? _dialog->run() : ui::IDialog::RESULT_CANCELLED;
27 }
28
29 ui::IDialog::Handle addLabel(const std::string& text)
30 {
31 return (_dialog != NULL) ? _dialog->addLabel(text) : ui::INVALID_HANDLE;
32 }
33
34 ui::IDialog::Handle addComboBox(const std::string& label, const ui::IDialog::ComboBoxOptions& options)
35 {
36 return (_dialog != NULL) ? _dialog->addComboBox(label, options) : ui::INVALID_HANDLE;
37 }
38
39 ui::IDialog::Handle addEntryBox(const std::string& label)
40 {
41 return (_dialog != NULL) ? _dialog->addEntryBox(label) : ui::INVALID_HANDLE;
42 }
43
44 ui::IDialog::Handle addPathEntry(const std::string& label, bool foldersOnly = false)
45 {
46 return (_dialog != NULL) ? _dialog->addPathEntry(label, foldersOnly) : ui::INVALID_HANDLE;
47 }
48
49 ui::IDialog::Handle addSpinButton(const std::string& label, double min, double max, double step, unsigned int digits)
50 {
51 return (_dialog != NULL) ? _dialog->addSpinButton(label, min, max, step, digits) : ui::INVALID_HANDLE;
52 }
53
54 ui::IDialog::Handle addCheckbox(const std::string& label)
55 {
56 return (_dialog != NULL) ? _dialog->addCheckbox(label) : ui::INVALID_HANDLE;
57 }
58
59 void setElementValue(const ui::IDialog::Handle& handle, const std::string& value)
60 {
61 if (_dialog != NULL) _dialog->setElementValue(handle, value);
62 }
63
64 std::string getElementValue(const ui::IDialog::Handle& handle)
65 {
66 return (_dialog != NULL) ? _dialog->getElementValue(handle) : "";
67 }
68 };
69
70 /**
71 * greebo: This class provides the script interface for the DialogManager class (UIManager module).
72 */
73 class DialogManagerInterface :
74 public IScriptInterface
75 {
76 public:
77 ScriptDialog createDialog(const std::string& title);
78 ScriptDialog createMessageBox(const std::string& title, const std::string& text, ui::IDialog::MessageType type);
79
80 // IScriptInterface implementation
81 void registerInterface(py::module& scope, py::dict& globals) override;
82 };
83
84 } // namespace script