-
Notifications
You must be signed in to change notification settings - Fork 0
/
SelectSourceNameOption.cpp
44 lines (38 loc) · 1.43 KB
/
SelectSourceNameOption.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "SelectSourceNameOption.h"
SelectSourceNameOption::SelectSourceNameOption(const std::string& name, std::shared_ptr<Communicator> communicator) :
Option(name, communicator)
{
sourceName = nullptr;
}
void SelectSourceNameOption::connectNotifiers(std::shared_ptr<OneArgNotifier<std::string>> formatChangedNotifier, std::shared_ptr<OneArgNotifier<std::string>> sourceNameChangedNotifier)
{
formatChangedNotifier->notified += [this](auto format) {this->onFormatChanged(); };
sourceNameChangedNotifier->notified += [this](auto name) {this->onSourceNameChanged(name); };
this->sourceNameChangedNotifier = sourceNameChangedNotifier;
}
void SelectSourceNameOption::execute()
{
displayText("Give source image name.");
std::string imageName = handleInput();
auto sourceName = std::shared_ptr<std::string>(new std::string(imageName));
sourceNameChangedNotifier->notifyListeners(sourceName);
}
std::string SelectSourceNameOption::getDescription()
{
if (sourceName != nullptr)
{
return "Select source image name, current name: " + *sourceName;
}
else
{
return "Select source image name, current name: undefined";
}
}
void SelectSourceNameOption::onFormatChanged(std::shared_ptr<std::string> newFormat)
{
sourceNameChangedNotifier->notifyListeners(nullptr);
}
void SelectSourceNameOption::onSourceNameChanged(std::shared_ptr<std::string> newSourceName)
{
sourceName = newSourceName;
}