SelectAllActivity 30/158030/4
authorPawel Kurowski <p.kurowski2@samsung.com>
Fri, 27 Oct 2017 09:40:06 +0000 (11:40 +0200)
committerPawel Kurowski <p.kurowski2@samsung.com>
Mon, 30 Oct 2017 11:39:45 +0000 (12:39 +0100)
Minor refactor in ClipboardActivity

Change-Id: I351c1809e9ca14de268937293aff78a98d5e5dae

src/ClipboardActivity.cpp
src/MenuBuilder.cpp

index a1caa7c..5069bfa 100644 (file)
@@ -13,36 +13,20 @@ class ClipboardActivity : public UIActivity, private RegisterActivity<DerivedTyp
 public:
        constexpr static const char *activityType = DerivedType::activityType;
 
-       ClipboardActivity() : UIActivity(activityType) {}
+       ClipboardActivity() : UIActivity(activityType), atspi(Singleton<UniversalSwitch>::instance().getAtspi()) {}
 
 protected:
-       bool getAtspiInterfaces()
+       void getAtspiInterfaces()
        {
+               ASSERT(atspi, "Atspi should exist");
+
                if (!uiElement) {
                        ERROR("Process invoked with incorrect UIElement");
-                       markAsCompleted();
-                       return false;
-               }
-
-               atspi = Singleton<UniversalSwitch>::instance().getAtspi();
-               if (!atspi) {
-                       markAsCompleted();
-                       return false;
+                       return;
                }
 
                atspiText = atspi->getTextInterface(uiElement->getObject());
-               if (!atspiText) {
-                       markAsCompleted();
-                       return false;
-               }
-
                atspiEditableText = atspi->getEditableTextInterface(uiElement->getObject());
-               if (!atspiEditableText) {
-                       markAsCompleted();
-                       return false;
-               }
-
-               return true;
        }
 
        std::shared_ptr<Atspi> atspi;
@@ -58,8 +42,7 @@ public:
 
        void process() override
        {
-               if (!getAtspiInterfaces())
-                       return;
+               getAtspiInterfaces();
 
                auto range = atspi->getTextSelection(atspiText);
                if (range)
@@ -76,8 +59,7 @@ public:
 
        void process() override
        {
-               if (!getAtspiInterfaces())
-                       return;
+               getAtspiInterfaces();
 
                auto range = atspi->getTextSelection(atspiText);
                if (range)
@@ -95,8 +77,7 @@ public:
 
        void process() override
        {
-               if (!getAtspiInterfaces())
-                       return;
+               getAtspiInterfaces();
 
                auto caretOffset = atspi->getTextCaretOffset(atspiText);
                if (caretOffset)
@@ -105,3 +86,22 @@ public:
                markAsCompleted();
        }
 };
+
+class SelectAllActivity : public ClipboardActivity<SelectAllActivity>
+{
+public:
+       constexpr static const char *activityType = "SELECT_ALL";
+
+       void process() override
+       {
+               getAtspiInterfaces();
+
+               auto offsetEnd = atspi->countTextCharacters(atspiText);
+               if (offsetEnd) {
+                       auto range = TextRange {0, *offsetEnd};
+                       atspi->setTextSelection(atspiText, range);
+               }
+
+               markAsCompleted();
+       }
+};
index bcae694..2ae255c 100644 (file)
@@ -278,7 +278,8 @@ MenuBuilderImplementation::MenuBuilderImplementation()
                                                                                defaultImg);
        auto selectAll                          =       std::make_shared<MenuItemImplementation>(
                                                                                std::vector<std::string> {"IDS_SELECT_ALL"},
-                                                                               defaultImg);
+                                                                               defaultImg,
+                                                                               "SELECT_ALL");
        auto previous                           =       std::make_shared<VconfIntTypeMenuItem>(
                                                                                std::vector<std::string> { "IDS_PREVIOUS_CHARACTER", "IDS_PREVIOUS_WORD", "IDS_PREVIOUS_LINE", "IDS_PREVIOUS_PARAGRAPH"},
                                                                                defaultImg,