From e2bba16738cb230564cfb328ef41429b2aac9823 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Tue, 25 Apr 2017 15:19:40 +0200 Subject: [PATCH] [apps/graph] [apps/sequence] Implement copy paste Change-Id: I7e33e24565b18e771ec530c74fb2a74ade5c3c85 --- apps/sequence/list/list_controller.cpp | 15 +++++++++++++++ apps/sequence/list/list_controller.h | 1 + apps/shared/list_controller.cpp | 12 +++++++++++- apps/shared/list_controller.h | 1 + 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/apps/sequence/list/list_controller.cpp b/apps/sequence/list/list_controller.cpp index 21c18b8f6..cc082c464 100644 --- a/apps/sequence/list/list_controller.cpp +++ b/apps/sequence/list/list_controller.cpp @@ -217,6 +217,21 @@ int ListController::functionIndexForRow(int j) { return sequenceIndex; } +const char * ListController::textForRow(int j) { + Sequence * sequence = (Sequence *)m_functionStore->functionAtIndex(functionIndexForRow(j)); + switch (sequenceDefinitionForRow(j)) { + case 0: + return sequence->text(); + case 1: + return sequence->firstInitialConditionText(); + case 2: + return sequence->secondInitialConditionText(); + default: + assert(false); + return nullptr; + } +} + int ListController::sequenceDefinitionForRow(int j) { if (j < 0) { return j; diff --git a/apps/sequence/list/list_controller.h b/apps/sequence/list/list_controller.h index 8d19eb514..02687369c 100644 --- a/apps/sequence/list/list_controller.h +++ b/apps/sequence/list/list_controller.h @@ -34,6 +34,7 @@ private: void willDisplayTitleCellAtIndex(HighlightCell * cell, int j) override; void willDisplayExpressionCellAtIndex(HighlightCell * cell, int j) override; int functionIndexForRow(int j) override; + const char * textForRow(int j) override; int sequenceDefinitionForRow(int j); void addEmptyFunction() override; void editExpression(Shared::Function * function, Ion::Events::Event event) override; diff --git a/apps/shared/list_controller.cpp b/apps/shared/list_controller.cpp index 80ae2d326..c121b61eb 100644 --- a/apps/shared/list_controller.cpp +++ b/apps/shared/list_controller.cpp @@ -220,7 +220,7 @@ bool ListController::handleEvent(Ion::Events::Event event) { } return true; } - if ((event.hasText() || event == Ion::Events::XNT) + if ((event.hasText() || event == Ion::Events::XNT || event == Ion::Events::Paste) && selectableTableView()->selectedColumn() == 1 && (selectableTableView()->selectedRow() != numberOfRows() - 1 || m_functionStore->numberOfFunctions() == m_functionStore->maxNumberOfFunctions())) { @@ -228,6 +228,11 @@ bool ListController::handleEvent(Ion::Events::Event event) { editExpression(function, event); return true; } + if (event == Ion::Events::Copy && selectableTableView()->selectedColumn() == 1 && + (selectableTableView()->selectedRow() < numberOfRows() - 1 || m_functionStore->numberOfFunctions() == m_functionStore->maxNumberOfFunctions())) { + Clipboard::sharedClipboard()->store(textForRow(selectableTableView()->selectedRow())); + return true; + } return false; } @@ -287,6 +292,11 @@ int ListController::functionIndexForRow(int j) { return j; } +const char * ListController::textForRow(int j) { + Shared::Function * function = m_functionStore->functionAtIndex(functionIndexForRow(j)); + return function->text(); +} + void ListController::addEmptyFunction() { m_functionStore->addEmptyFunction(); selectableTableView()->reloadData(); diff --git a/apps/shared/list_controller.h b/apps/shared/list_controller.h index 48c4d532d..bdb264e0a 100644 --- a/apps/shared/list_controller.h +++ b/apps/shared/list_controller.h @@ -41,6 +41,7 @@ private: static constexpr KDCoordinate k_functionNameWidth = 65; TabViewController * tabController() const; virtual int functionIndexForRow(int j); + virtual const char * textForRow(int j); virtual void addEmptyFunction(); virtual void removeFunctionRow(Function * function); virtual void editExpression(Function * function, Ion::Events::Event event) = 0;