From f9895848087e834ceda4aace670046165702b340 Mon Sep 17 00:00:00 2001 From: Oskar Chodowicz Date: Wed, 17 Jul 2019 11:48:17 +0200 Subject: [PATCH] Small fixes this patch introduce these changes: 1. use actions in modal presenter what allows to disable buttons 2. set focus on entry in modal view Change-Id: I71c29a17daf20bfc6880514af442616b2d71daed --- .../AlreadyMappedSwitchModalPresenter.cpp | 7 +++- src/presenter/EntryNameModalPresenter.cpp | 19 +++++----- src/presenter/EntryNameModalPresenter.hpp | 1 + src/presenter/ModalPresenter.cpp | 20 ---------- src/presenter/ModalPresenter.hpp | 8 ---- src/presenter/NoSwitchesModalPresenter.cpp | 7 ++-- src/presenter/RemoveSwitchesModalPresenter.cpp | 8 ++-- src/ui/Widget.cpp | 5 +++ src/ui/Widget.hpp | 1 + src/view/ModalView.cpp | 44 ++++++++++++++-------- 10 files changed, 58 insertions(+), 62 deletions(-) diff --git a/src/presenter/AlreadyMappedSwitchModalPresenter.cpp b/src/presenter/AlreadyMappedSwitchModalPresenter.cpp index 1d0c337..0f7d7b3 100644 --- a/src/presenter/AlreadyMappedSwitchModalPresenter.cpp +++ b/src/presenter/AlreadyMappedSwitchModalPresenter.cpp @@ -1,8 +1,13 @@ #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("doneAction", "IDS_ACCS_UNIVERSAL_SWITCH_OK", [](auto action) { + Singleton::instance().popModal(); + })); } diff --git a/src/presenter/EntryNameModalPresenter.cpp b/src/presenter/EntryNameModalPresenter.cpp index 0ecec72..ce9b755 100644 --- a/src/presenter/EntryNameModalPresenter.cpp +++ b/src/presenter/EntryNameModalPresenter.cpp @@ -7,14 +7,15 @@ EntryNameModalPresenter::EntryNameModalPresenter(std::string switchId) { setTitle("IDS_ACCS_UNIVERSAL_SWITCH_ADD_SWITCH"); - entryAction_ = addAction(std::make_unique("modalEntry", "IDS_ACCS_UNIVERSAL_SWITCH_ADD_SWITCH_NAME", std::function{})); - doneText_ = "IDS_ACCS_UNIVERSAL_SWITCH_SAVE"; - cancelText_ = "IDS_ACCS_UNIVERSAL_SWITCH_CANCEL"; - doneCb_ = [this, switchId]() { + entryAction_ = addAction(std::make_unique("modalEntry", "IDS_ACCS_UNIVERSAL_SWITCH_ADD_SWITCH_NAME", [this](auto action) { + doneAction_->enabled_ = !entryAction_->title_.value().empty(); + })); + + addAction(std::make_unique("cancelAction", "IDS_ACCS_UNIVERSAL_SWITCH_CANCEL", std::function{})); + doneAction_ = addAction(std::make_unique("doneAction", "IDS_ACCS_UNIVERSAL_SWITCH_SAVE", [this, switchId](auto action) { auto switchUserName = this->entryAction_->title_.value(); - if (!switchUserName.empty()) { - Singleton::instance().popModal(); - Singleton::instance().push(std::make_unique(switchId, switchUserName, ChangeType::ADD, 2)); - } - }; + Singleton::instance().popModal(); + Singleton::instance().push(std::make_unique(switchId, switchUserName, ChangeType::ADD, 2)); + }, + false)); } \ No newline at end of file diff --git a/src/presenter/EntryNameModalPresenter.hpp b/src/presenter/EntryNameModalPresenter.hpp index 05999f7..a6a089f 100644 --- a/src/presenter/EntryNameModalPresenter.hpp +++ b/src/presenter/EntryNameModalPresenter.hpp @@ -10,6 +10,7 @@ class EntryNameModalPresenter : public ModalPresenter private: Action *entryAction_ = nullptr; + Action *doneAction_ = nullptr; }; #endif \ No newline at end of file diff --git a/src/presenter/ModalPresenter.cpp b/src/presenter/ModalPresenter.cpp index 351142d..02cef08 100644 --- a/src/presenter/ModalPresenter.cpp +++ b/src/presenter/ModalPresenter.cpp @@ -1,26 +1,6 @@ #include "ModalPresenter.hpp" -std::function ModalPresenter::getDoneCb() -{ - return doneCb_; -} - -std::function 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 diff --git a/src/presenter/ModalPresenter.hpp b/src/presenter/ModalPresenter.hpp index 852eea8..f306e00 100644 --- a/src/presenter/ModalPresenter.hpp +++ b/src/presenter/ModalPresenter.hpp @@ -6,20 +6,12 @@ class ModalPresenter : public Presenter { public: - std::function getDoneCb(); - std::function getCancelCb(); std::string getText(); - std::string getDoneText(); - std::string getCancelText(); protected: using Presenter::Presenter; - std::function doneCb_; - std::function cancelCb_; std::string text_; - std::string doneText_; - std::string cancelText_; }; #endif \ No newline at end of file diff --git a/src/presenter/NoSwitchesModalPresenter.cpp b/src/presenter/NoSwitchesModalPresenter.cpp index 40ac5a8..0831f5f 100644 --- a/src/presenter/NoSwitchesModalPresenter.cpp +++ b/src/presenter/NoSwitchesModalPresenter.cpp @@ -8,10 +8,9 @@ NoSwitchesModalPresenter::NoSwitchesModalPresenter() 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("cancelAction", "IDS_ACCS_UNIVERSAL_SWITCH_CANCEL", std::function{})); + addAction(std::make_unique("doneAction", "IDS_ACCS_UNIVERSAL_SWITCH_POPUP_ADD", [this](auto action) { Singleton::instance().popModal(); Singleton::instance().push(std::make_unique()); - }; + })); } \ No newline at end of file diff --git a/src/presenter/RemoveSwitchesModalPresenter.cpp b/src/presenter/RemoveSwitchesModalPresenter.cpp index 8bbc19f..d0ce44f 100644 --- a/src/presenter/RemoveSwitchesModalPresenter.cpp +++ b/src/presenter/RemoveSwitchesModalPresenter.cpp @@ -13,12 +13,10 @@ RemoveSwitchesModalPresenter::RemoveSwitchesModalPresenter(std::vector("cancelAction", "IDS_ST_BUTTON_CANCEL", std::function{})); + addAction(std::make_unique("doneAction", "IDS_ACCS_DELETE", [this](auto action) { model_.removeSwitches(switchesToRemove_); Singleton::instance().popModal(); Singleton::instance().pop(); - }; + })); } \ No newline at end of file diff --git a/src/ui/Widget.cpp b/src/ui/Widget.cpp index b806122..ee2a28f 100644 --- a/src/ui/Widget.cpp +++ b/src/ui/Widget.cpp @@ -123,6 +123,11 @@ void Widget::emitSignal(const std::string &signal) 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()); diff --git a/src/ui/Widget.hpp b/src/ui/Widget.hpp index 53b0bf6..0003a33 100644 --- a/src/ui/Widget.hpp +++ b/src/ui/Widget.hpp @@ -48,6 +48,7 @@ class Widget 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(); diff --git a/src/view/ModalView.cpp b/src/view/ModalView.cpp index 8877051..08a6be7 100644 --- a/src/view/ModalView.cpp +++ b/src/view/ModalView.cpp @@ -33,40 +33,54 @@ ModalView::ModalView(const NavigationContext &context, ModalPresenter *presenter }); 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::instance().popModal(); + auto cancelAction = presenter_->getAction("cancelAction"); + if (cancelAction) { + auto c = cancelAction->onInvoke_; + if (c) { + c(cancelAction); + return; + } + } + Singleton::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