From 5256b0be1293323c1a9171002db9892427ee28c5 Mon Sep 17 00:00:00 2001 From: Ben Chamberland Date: Mon, 29 Jul 2024 15:35:06 -0400 Subject: [PATCH] Allow users to paste from clipboard into RV annotations --- rvcmds.sh | 2 +- src/bin/imgtools/rvio/UICommands.cpp | 9 ++++++ src/bin/imgtools/rvio/UICommands.h | 1 + src/lib/app/RvCommon/MuUICommands.cpp | 29 +++++++------------ src/lib/app/RvCommon/RvApplication.cpp | 23 +++++++++++++++ src/lib/app/RvCommon/RvCommon/MuUICommands.h | 1 + src/lib/app/RvCommon/RvCommon/RvApplication.h | 1 + src/lib/app/mu_rvui/commands.mud | 1 + .../rv-packages/annotate/annotate_mode.mu | 14 ++++++++- 9 files changed, 60 insertions(+), 21 deletions(-) diff --git a/rvcmds.sh b/rvcmds.sh index 31bf21b3a..df8dda9d1 100755 --- a/rvcmds.sh +++ b/rvcmds.sh @@ -79,7 +79,7 @@ RV_BUILD_PARALLELISM="${RV_BUILD_PARALLELISM:-$(python3 -c 'import os; print(os. # ALIASES: Basic commands -alias rvsetup="SETUPTOOLS_USE_DISTUTILS=${SETUPTOOLS_USE_DISTUTILS} python3 -m pip install --user --upgrade -r ${RV_HOME}/requirements.txt" +alias rvsetup="SETUPTOOLS_USE_DISTUTILS=${SETUPTOOLS_USE_DISTUTILS} python3 -m pip install --user --upgrade -r ${RV_HOME}/requirements.txt --break-system-packages" alias rvcfg="cmake -B ${RV_BUILD} -G \"${CMAKE_GENERATOR}\" ${CMAKE_WIN_ARCH} -DCMAKE_BUILD_TYPE=Release -DRV_DEPS_QT5_LOCATION=${QT_HOME} -DRV_DEPS_WIN_PERL_ROOT=${WIN_PERL}" alias rvcfgd="cmake -B ${RV_BUILD} -G \"${CMAKE_GENERATOR}\" ${CMAKE_WIN_ARCH} -DCMAKE_BUILD_TYPE=Debug -DRV_DEPS_QT5_LOCATION=${QT_HOME} -DRV_DEPS_WIN_PERL_ROOT=${WIN_PERL}" alias rvbuildt="cmake --build ${RV_BUILD} --config Release -v --parallel=${RV_BUILD_PARALLELISM} --target " diff --git a/src/bin/imgtools/rvio/UICommands.cpp b/src/bin/imgtools/rvio/UICommands.cpp index 22a26bdf8..6a6dca92d 100644 --- a/src/bin/imgtools/rvio/UICommands.cpp +++ b/src/bin/imgtools/rvio/UICommands.cpp @@ -279,6 +279,10 @@ void initUICommands(MuLangContext* context) new Param(c, "doEncode", "bool", Value(true)), End), + new Function(c, "getTextFromClipboard", getTextFromClipboard, None, + Return, "string", + End), + new Function(c, "myNetworkPort", myNetworkPort, None, Return, "int", End), @@ -466,6 +470,11 @@ NODE_DECLARATION(putUrlOnClipboard, void) { } +NODE_DECLARAION(getTextFromClipboard, Mu::Pointer) +{ + NODE_RETURN(0); // Will represent a string +} + NODE_DECLARATION(myNetworkPort, int) { NODE_RETURN(0); diff --git a/src/bin/imgtools/rvio/UICommands.h b/src/bin/imgtools/rvio/UICommands.h index 9c232186a..0a74fc40e 100644 --- a/src/bin/imgtools/rvio/UICommands.h +++ b/src/bin/imgtools/rvio/UICommands.h @@ -50,6 +50,7 @@ NODE_DECLARATION(httpGet, void); NODE_DECLARATION(httpPost, void); NODE_DECLARATION(sessionFromUrl, void); NODE_DECLARATION(putUrlOnClipboard, void); +NODE_DECLARATION(getTextFromClipboard, Mu::Pointer); NODE_DECLARATION(myNetworkPort, int); NODE_DECLARATION(encodePassword, Mu::Pointer); NODE_DECLARATION(decodePassword, Mu::Pointer); diff --git a/src/lib/app/RvCommon/MuUICommands.cpp b/src/lib/app/RvCommon/MuUICommands.cpp index f2ec081ad..4d39d45b7 100644 --- a/src/lib/app/RvCommon/MuUICommands.cpp +++ b/src/lib/app/RvCommon/MuUICommands.cpp @@ -491,6 +491,10 @@ void initUICommands() new Param(c, "doEncode", "bool", Value(true)), End), + new Function(c, "getTextFromClipboard", getTextFromClipboard, None, + Return, "string", + End), + new Function(c, "myNetworkPort", myNetworkPort, None, Return, "int", End), @@ -2038,6 +2042,12 @@ NODE_IMPLEMENTATION(sessionFromUrl, void) RvApp()->sessionFromUrl(url->c_str()); } +NODE_IMPLEMENTATION(getTextFromClipboard, Pointer) { + const StringType* stype = static_cast(NODE_THIS.type()); + std::string s = RvApp()->getTextFromClipboard(); // Getting text from the clipboard + Mu::Pointer p = stype->allocate(s.c_str()); + NODE_RETURN(p); +} NODE_IMPLEMENTATION(putUrlOnClipboard, void) { @@ -2050,25 +2060,6 @@ NODE_IMPLEMENTATION(putUrlOnClipboard, void) RvApp()->putUrlOnClipboard(url->c_str(), title->c_str(), doEncode); - - /* - NO WORKY - - QUrl qurl; - qurl.setScheme("rvlink"); - qurl.setUrl (url->c_str(), QUrl::TolerantMode); - cerr << "made QUrl from '" << url->c_str() << "', valid " << qurl.isValid() << endl; - QList qlist; - qlist.append (qurl); - - // XXX memory leak, but a tiny one. - QMimeData *qmd = new QMimeData(); - - qmd->setUrls(qlist); - qmd->setText(url->c_str()); - - QApplication::clipboard()->setMimeData(qmd); - */ } NODE_IMPLEMENTATION(myNetworkPort, int) diff --git a/src/lib/app/RvCommon/RvApplication.cpp b/src/lib/app/RvCommon/RvApplication.cpp index 126b4464b..ef059efdc 100644 --- a/src/lib/app/RvCommon/RvApplication.cpp +++ b/src/lib/app/RvCommon/RvApplication.cpp @@ -51,6 +51,9 @@ #include #include #include +#include +#include +#include #ifndef PLATFORM_WINDOWS extern char **environ; @@ -1446,6 +1449,26 @@ RvApplication::putUrlOnClipboard(string url, string title, bool doEncode) #endif } +std::string +RvApplication::getTextFromClipboard() +{ + QString text; + QClipboard *clipboard = QApplication::clipboard(); + + #if defined(PLATFORM_DARWIN) + text = clipboard->text(QClipboard::Clipboard); + #elif defined(PLATFORM_WINDOWS) + text = clipboard->text(QClipboard::Clipboard); + #else + text = clipboard->text(QClipboard::Selection); + if (text.isEmpty()) { + text = clipboard->text(QClipboard::Clipboard); + } + #endif + + return text.toUtf8().constData(); +} + void RvApplication::initializeQSettings(string altPath) { diff --git a/src/lib/app/RvCommon/RvCommon/MuUICommands.h b/src/lib/app/RvCommon/RvCommon/MuUICommands.h index 33dce9457..cfa66bb89 100644 --- a/src/lib/app/RvCommon/RvCommon/MuUICommands.h +++ b/src/lib/app/RvCommon/RvCommon/MuUICommands.h @@ -61,6 +61,7 @@ NODE_DECLARATION(httpPutString, void); NODE_DECLARATION(httpPutData, void); NODE_DECLARATION(sessionFromUrl, void); NODE_DECLARATION(putUrlOnClipboard, void); +NODE_DECLARATION(getTextFromClipboard, Mu::Pointer); NODE_DECLARATION(myNetworkPort, int); NODE_DECLARATION(myNetworkHost, Mu::Pointer); NODE_DECLARATION(encodePassword, Mu::Pointer); diff --git a/src/lib/app/RvCommon/RvCommon/RvApplication.h b/src/lib/app/RvCommon/RvCommon/RvApplication.h index c35f8c794..7cce889ee 100644 --- a/src/lib/app/RvCommon/RvCommon/RvApplication.h +++ b/src/lib/app/RvCommon/RvCommon/RvApplication.h @@ -100,6 +100,7 @@ class RvApplication : public QObject, public RvConsoleApplication static void parseURL (const char *s, std::vector &av); static void sessionFromUrl (std::string url); static void putUrlOnClipboard (std::string url, std::string title, bool doEncode=true); + static std::string getTextFromClipboard (); static std::string encodeCommandLineURL (int argc, char *argv[]); static std::string bakeCommandLineURL (int argc, char *argv[]); static void initializeQSettings (std::string altPath); diff --git a/src/lib/app/mu_rvui/commands.mud b/src/lib/app/mu_rvui/commands.mud index fc3a06b98..bd2623b38 100644 --- a/src/lib/app/mu_rvui/commands.mud +++ b/src/lib/app/mu_rvui/commands.mud @@ -1727,6 +1727,7 @@ networkAccessManager "Returns Qt network access manager object" //javascriptMuExport "Export Mu eval() call as a javascript Object in the given WebFrame" sessionFromUrl "Create a session from a (possibly baked) rvlink URL" putUrlOnClipboard "Copy a URL on the system clipboard" +getTextFromClipboard "Get the text sitting in your clipboard" myNetworkPort "Returns the currently set port number for networking" myNetworkHost "Returns the name of the host RV is running on for purposes of networking" encodePassword "-" diff --git a/src/plugins/rv-packages/annotate/annotate_mode.mu b/src/plugins/rv-packages/annotate/annotate_mode.mu index b2757d310..4f67efbb5 100644 --- a/src/plugins/rv-packages/annotate/annotate_mode.mu +++ b/src/plugins/rv-packages/annotate/annotate_mode.mu @@ -622,6 +622,11 @@ class: AnnotateMinorMode : MinorMode populateAnnotationList(); } + method: getTextFromClipboard(string;) + { + + } + //---------------------------------------------------------------------- method: pointerLocation ((string, Point); Event event) @@ -1105,6 +1110,12 @@ class: AnnotateMinorMode : MinorMode _toolSliderLabel.setText(if d.sliderName eq nil then "Opacity" else d.sliderName); } + method: getClipboard(string;) + { + print("DEBUG: Getting clipboard from Mu file"); + commands.getTextFromClipboard(); + } + method: locationChangedSlot (void; Qt.DockWidgetArea area) { _dockArea = area; @@ -2154,7 +2165,8 @@ class: AnnotateMinorMode : MinorMode ("key-down--control--backspace", backwardsKillWord, ""), ("key-down--meta--a", killLine, ""), ("key-down--alt--a", killLine, ""), - ("key-down--space", insertChar, ""), + // ("key-down--space", insertChar, ""), + ("key-down--space", getClipboard, ""), ("key-down--enter", insertNL, ""), ("key-down--control--enter", commitText(false,), ""), ("key-down--meta--enter", commitText(false,), ""),