Debian Codegraph @

plugins/dm.objectives/ce/ReadablePageReachedComponentEditor.cpp

raw
1 #include "ReadablePageReachedComponentEditor.h"
2 #include "../SpecifierType.h"
3 #include "../Component.h"
4
5 #include "i18n.h"
6 #include "string/convert.h"
7
8 #include <wx/stattext.h>
9 #include <wx/spinctrl.h>
10
11 namespace objectives
12 {
13
14 namespace ce
15 {
16
17 // Registration helper, will register this editor in the factory
18 ReadablePageReachedComponentEditor::RegHelper ReadablePageReachedComponentEditor::regHelper;
19
20 // Constructor
21 ReadablePageReachedComponentEditor::ReadablePageReachedComponentEditor(wxWindow* parent, Component& component) :
22 ComponentEditorBase(parent),
23 _component(&component),
24 _readableSpec(new SpecifierEditCombo(_panel, getChangeCallback(), SpecifierType::SET_READABLE()))
25 {
26 _pageNum = new wxSpinCtrl(_panel, wxID_ANY);
27 _pageNum->SetValue(1);
28 _pageNum->SetRange(0, 65535);
29 _pageNum->Bind(wxEVT_SPINCTRL, [&] (wxSpinEvent& ev) { writeToComponent(); });
30
31 wxStaticText* label = new wxStaticText(_panel, wxID_ANY, _("Readable:"));
32 label->SetFont(label->GetFont().Bold());
33
34 _panel->GetSizer()->Add(label, 0, wxBOTTOM | wxEXPAND, 6);
35 _panel->GetSizer()->Add(_readableSpec, 0, wxBOTTOM | wxEXPAND, 6);
36
37 _panel->GetSizer()->Add(new wxStaticText(_panel, wxID_ANY, _("Page Number:")), 0, wxBOTTOM, 6);
38 _panel->GetSizer()->Add(_pageNum, 0, wxBOTTOM | wxEXPAND, 6);
39
40 // Populate the SpecifierEditCombo with the first specifier
41 _readableSpec->setSpecifier(
42 component.getSpecifier(Specifier::FIRST_SPECIFIER)
43 );
44
45 // Initialise the spin button with the value from the first component argument
46 _pageNum->SetValue(string::convert<int>(component.getArgument(0)));
47 }
48
49 // Write to component
50 void ReadablePageReachedComponentEditor::writeToComponent() const
51 {
52 if (!_active) return; // still under construction
53
54 assert(_component);
55
56 _component->setSpecifier(
57 Specifier::FIRST_SPECIFIER, _readableSpec->getSpecifier()
58 );
59
60 _component->clearArguments();
61 _component->setArgument(0, string::to_string(_pageNum->GetValue()));
62 }
63
64 } // namespace ce
65
66 } // namespace objectives