#include "AlreadyMappedSwitchModalPresenter.hpp"
+#include "AppContext.hpp"
+#include "Singleton.hpp"
+
AlreadyMappedSwitchModalPresenter::AlreadyMappedSwitchModalPresenter()
{
setTitle("IDS_ACCS_UNIVERSAL_SWITCH_UNABLE_TO_ADD");
text_ = "IDS_ACCS_UNIVERSAL_SWITCH_ALREADY_ADDED";
- cancelText_ = "IDS_ACCS_UNIVERSAL_SWITCH_OK";
+ addAction(std::make_unique<Action>("doneAction", "IDS_ACCS_UNIVERSAL_SWITCH_OK", [](auto action) {
+ Singleton<AppContext>::instance().popModal();
+ }));
}
EntryNameModalPresenter::EntryNameModalPresenter(std::string switchId)
{
setTitle("IDS_ACCS_UNIVERSAL_SWITCH_ADD_SWITCH");
- entryAction_ = addAction(std::make_unique<Action>("modalEntry", "IDS_ACCS_UNIVERSAL_SWITCH_ADD_SWITCH_NAME", std::function<void(Action *)>{}));
- doneText_ = "IDS_ACCS_UNIVERSAL_SWITCH_SAVE";
- cancelText_ = "IDS_ACCS_UNIVERSAL_SWITCH_CANCEL";
- doneCb_ = [this, switchId]() {
+ entryAction_ = addAction(std::make_unique<Action>("modalEntry", "IDS_ACCS_UNIVERSAL_SWITCH_ADD_SWITCH_NAME", [this](auto action) {
+ doneAction_->enabled_ = !entryAction_->title_.value().empty();
+ }));
+
+ addAction(std::make_unique<Action>("cancelAction", "IDS_ACCS_UNIVERSAL_SWITCH_CANCEL", std::function<void(Action *)>{}));
+ doneAction_ = addAction(std::make_unique<Action>("doneAction", "IDS_ACCS_UNIVERSAL_SWITCH_SAVE", [this, switchId](auto action) {
auto switchUserName = this->entryAction_->title_.value();
- if (!switchUserName.empty()) {
- Singleton<AppContext>::instance().popModal();
- Singleton<AppContext>::instance().push(std::make_unique<SelectActionPagePresenter>(switchId, switchUserName, ChangeType::ADD, 2));
- }
- };
+ Singleton<AppContext>::instance().popModal();
+ Singleton<AppContext>::instance().push(std::make_unique<SelectActionPagePresenter>(switchId, switchUserName, ChangeType::ADD, 2));
+ },
+ false));
}
\ No newline at end of file
private:
Action *entryAction_ = nullptr;
+ Action *doneAction_ = nullptr;
};
#endif
\ No newline at end of file
#include "ModalPresenter.hpp"
-std::function<void()> ModalPresenter::getDoneCb()
-{
- return doneCb_;
-}
-
-std::function<void()> ModalPresenter::getCancelCb()
-{
- return cancelCb_;
-}
-
std::string ModalPresenter::getText()
{
return text_;
-}
-
-std::string ModalPresenter::getDoneText()
-{
- return doneText_;
-}
-
-std::string ModalPresenter::getCancelText()
-{
- return cancelText_;
}
\ No newline at end of file
class ModalPresenter : public Presenter
{
public:
- std::function<void()> getDoneCb();
- std::function<void()> getCancelCb();
std::string getText();
- std::string getDoneText();
- std::string getCancelText();
protected:
using Presenter::Presenter;
- std::function<void()> doneCb_;
- std::function<void()> cancelCb_;
std::string text_;
- std::string doneText_;
- std::string cancelText_;
};
#endif
\ No newline at end of file
setTitle("IDS_ACCS_UNIVERSAL_SWITCH_NO_SWITCHES_TITLE");
text_ = "IDS_ACCS_UNIVERSAL_SWITCH_NO_SWITCHES_TEXT";
- cancelText_ = "IDS_ACCS_UNIVERSAL_SWITCH_CANCEL";
- doneText_ = "IDS_ACCS_UNIVERSAL_SWITCH_POPUP_ADD";
- doneCb_ = [this]() {
+ addAction(std::make_unique<Action>("cancelAction", "IDS_ACCS_UNIVERSAL_SWITCH_CANCEL", std::function<void(Action *)>{}));
+ addAction(std::make_unique<Action>("doneAction", "IDS_ACCS_UNIVERSAL_SWITCH_POPUP_ADD", [this](auto action) {
Singleton<AppContext>::instance().popModal();
Singleton<AppContext>::instance().push(std::make_unique<AddSwitchPagePresenter>());
- };
+ }));
}
\ No newline at end of file
text_ = std::to_string(switchesToRemove_.size()) + " " + TranslatedString{"IDS_ACCS_UNIVERSAL_SWITCH_DELETE_SWITCHES_DESC"}.str();
}
- doneText_ = "IDS_ACCS_DELETE";
- cancelText_ = "IDS_ST_BUTTON_CANCEL";
-
- doneCb_ = [this]() {
+ addAction(std::make_unique<Action>("cancelAction", "IDS_ST_BUTTON_CANCEL", std::function<void(Action *)>{}));
+ addAction(std::make_unique<Action>("doneAction", "IDS_ACCS_DELETE", [this](auto action) {
model_.removeSwitches(switchesToRemove_);
Singleton<AppContext>::instance().popModal();
Singleton<AppContext>::instance().pop();
- };
+ }));
}
\ No newline at end of file
elm_object_signal_emit(uniqueObj_.get(), signal.c_str(), "");
}
+void Widget::setFocus(bool focus)
+{
+ elm_object_focus_set(uniqueObj_.get(), focus ? EINA_TRUE : EINA_FALSE);
+}
+
void Widget::show()
{
evas_object_show(uniqueObj_.get());
void setPartContent(const std::string &part, Widget *content);
void setHomogeneousDimensions();
void setPropagateEvents(bool prop);
+ void setFocus(bool focus);
void disable(bool disable);
void emitSignal(const std::string &signal);
void show();
});
layout_->setPartContent(PRT_ACCESSORY_POPUP_ENTRY, entry_);
popup_->setContent(layout_);
+ entry_->show();
+ entry_->setFocus(true);
} else {
if (!text.empty())
popup_->setText(text);
}
auto removeCb = [this]() {
- auto c = presenter_->getCancelCb();
- if (c)
- c();
- else
- Singleton<AppContext>::instance().popModal();
+ auto cancelAction = presenter_->getAction("cancelAction");
+ if (cancelAction) {
+ auto c = cancelAction->onInvoke_;
+ if (c) {
+ c(cancelAction);
+ return;
+ }
+ }
+ Singleton<AppContext>::instance().popModal();
};
popup_->setEextEventCallback(EEXT_CALLBACK_BACK, removeCb);
popup_->setEvasSmartCallback("dismissed", removeCb);
popup_->setEvasSmartCallback("block,clicked", removeCb);
- auto cancelText = presenter_->getCancelText();
- if (!cancelText.empty()) {
- auto cancelBtn = Widget::make<Button>(popup_, removeCb, cancelText, "bottom");
+ auto cancelAction = presenter_->getAction("cancelAction");
+ if (cancelAction) {
+ auto cancelBtn = Widget::make<Button>(popup_, removeCb, cancelAction->title_.value(), "bottom");
popup_->setPartContent("button1", cancelBtn);
+ cancelBtn->disable(!cancelAction->enabled_.value());
+ cancelAction->enabled_.attach([cancelBtn](auto value) {
+ cancelBtn->disable(!value);
+ });
}
- auto doneText = presenter_->getDoneText();
- if (!doneText.empty()) {
- auto doneBtn = Widget::make<Button>(popup_, [this]() {
- auto c = presenter_->getDoneCb();
+ auto doneAction = presenter_->getAction("doneAction");
+ if (doneAction) {
+ auto doneBtn = Widget::make<Button>(popup_, [doneAction]() {
+ auto c = doneAction->onInvoke_;
if (c)
- c();
+ c(doneAction);
else
Singleton<AppContext>::instance().popModal();
},
- doneText,
+ doneAction->title_.value(),
"bottom");
- popup_->setPartContent(cancelText.empty() ? "button1" : "button2", doneBtn);
+ popup_->setPartContent(cancelAction ? "button2" : "button1", doneBtn);
+ doneBtn->disable(!doneAction->enabled_.value());
+ doneAction->enabled_.attach([doneBtn](auto value) {
+ doneBtn->disable(!value);
+ });
}
}