--- /dev/null
+#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();
+ }
+};
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);