Clipboard Activities 65/157865/4
authorPawel Kurowski <p.kurowski2@samsung.com>
Thu, 26 Oct 2017 14:00:11 +0000 (16:00 +0200)
committerPawel Kurowski <p.kurowski2@samsung.com>
Mon, 30 Oct 2017 11:34:08 +0000 (12:34 +0100)
CopyActivity, CutActivity, PasteActivity

Change-Id: I9111b303bdc595dbe7627aed96178bd1f88a71e5

src/ClipboardActivity.cpp [new file with mode: 0644]
src/MenuBuilder.cpp

diff --git a/src/ClipboardActivity.cpp b/src/ClipboardActivity.cpp
new file mode 100644 (file)
index 0000000..37f7155
--- /dev/null
@@ -0,0 +1,102 @@
+#include "UIActivity.hpp"
+#include "ActivityFactory.hpp"
+#include "UniversalSwitchLog.hpp"
+
+#include <memory>
+
+template <typename DerivedType>
+class ClipboardActivity : public UIActivity, private RegisterActivity<DerivedType>
+{
+public:
+       constexpr static const char *activityType = DerivedType::activityType;
+
+       ClipboardActivity() : UIActivity(activityType) {}
+
+protected:
+       bool getAtspiInterfaces()
+       {
+               if (!uiElement || !uiElement->getObject()) {
+                       ERROR("Process invoked with incorrect UIElement");
+                       markAsCompleted();
+                       return false;
+               }
+
+               atspiText.reset(atspi_accessible_get_text_iface(uiElement->getObject().get()), g_object_unref);
+               if (!atspiText) {
+                       ERROR("Get text iface failed");
+                       markAsCompleted();
+                       return false;
+               }
+
+               atspiEditableText.reset(atspi_accessible_get_editable_text_iface(uiElement->getObject().get()), g_object_unref);
+               if (!atspiText) {
+                       ERROR("Get text iface failed");
+                       markAsCompleted();
+                       return false;
+               }
+               return true;
+       }
+
+       std::shared_ptr<AtspiText> atspiText;
+       std::shared_ptr<AtspiEditableText> atspiEditableText;
+};
+
+
+class CopyActivity : public ClipboardActivity<CopyActivity>
+{
+public:
+       constexpr static const char *activityType = "COPY";
+
+       void process() override
+       {
+               if (!getAtspiInterfaces())
+                       return;
+
+               auto range = atspi_text_get_selection(atspiText.get(), 0, nullptr);
+               if (!range)
+                       DEBUG("atspi_text_get_selection failed");
+               else if (!atspi_editable_text_copy_text(atspiEditableText.get(), range->start_offset, range->end_offset, nullptr))
+                       DEBUG("atspi_editable_text_copy_text failed");
+
+               markAsCompleted();
+       }
+};
+
+class CutActivity : public ClipboardActivity<CutActivity>
+{
+public:
+       constexpr static const char *activityType = "CUT";
+
+       void process() override
+       {
+               if (!getAtspiInterfaces())
+                       return;
+
+               auto range = atspi_text_get_selection(atspiText.get(), 0, nullptr);
+               if (!range)
+                       DEBUG("atspi_text_get_selection failed");
+               else if (!atspi_editable_text_cut_text(atspiEditableText.get(), range->start_offset, range->end_offset, nullptr))
+                       DEBUG("atspi_editable_text_cut_text failed");
+
+               markAsCompleted();
+       }
+};
+
+
+class PasteActivity : public ClipboardActivity<PasteActivity>
+{
+public:
+       constexpr static const char *activityType = "PASTE";
+
+       void process() override
+       {
+               if (!getAtspiInterfaces())
+                       return;
+
+               auto caretOffset = atspi_text_get_caret_offset(atspiText.get(), nullptr);
+               if (!atspi_editable_text_paste_text(atspiEditableText.get(), caretOffset, nullptr))
+                       DEBUG("atspi_editable_text_paste_text failed");
+
+               markAsCompleted();
+       }
+};
index dc3afda..bcae694 100644 (file)
@@ -291,13 +291,16 @@ MenuBuilderImplementation::MenuBuilderImplementation()
                                                                                std::string {VCONF_KEY_GRANULARITY_UNIT});
        auto copy                                       =       std::make_shared<MenuItemImplementation>(
                                                                                std::vector<std::string> {"IDS_COPY"},
-                                                                               defaultImg);
+                                                                               defaultImg,
+                                                                               "COPY");
        auto paste                                      =       std::make_shared<MenuItemImplementation>(
                                                                                std::vector<std::string> {"IDS_PASTE"},
-                                                                               defaultImg);
+                                                                               defaultImg,
+                                                                               "PASTE");
        auto cut                                        =       std::make_shared<MenuItemImplementation>(
                                                                                std::vector<std::string> {"IDS_CUT"},
-                                                                               defaultImg);
+                                                                               defaultImg,
+                                                                               "CUT");
        auto touchHold                          =       std::make_shared<MenuItemImplementation>(
                                                                                std::vector<std::string> {"IDS_TOUCH_AND_HOLD"},
                                                                                defaultImg);