Skip to content

Commit 5256b0b

Browse files
committed
Allow users to paste from clipboard into RV annotations
1 parent d15e8b1 commit 5256b0b

File tree

9 files changed

+60
-21
lines changed

9 files changed

+60
-21
lines changed

rvcmds.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ RV_BUILD_PARALLELISM="${RV_BUILD_PARALLELISM:-$(python3 -c 'import os; print(os.
7979

8080
# ALIASES: Basic commands
8181

82-
alias rvsetup="SETUPTOOLS_USE_DISTUTILS=${SETUPTOOLS_USE_DISTUTILS} python3 -m pip install --user --upgrade -r ${RV_HOME}/requirements.txt"
82+
alias rvsetup="SETUPTOOLS_USE_DISTUTILS=${SETUPTOOLS_USE_DISTUTILS} python3 -m pip install --user --upgrade -r ${RV_HOME}/requirements.txt --break-system-packages"
8383
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}"
8484
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}"
8585
alias rvbuildt="cmake --build ${RV_BUILD} --config Release -v --parallel=${RV_BUILD_PARALLELISM} --target "

src/bin/imgtools/rvio/UICommands.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,10 @@ void initUICommands(MuLangContext* context)
279279
new Param(c, "doEncode", "bool", Value(true)),
280280
End),
281281

282+
new Function(c, "getTextFromClipboard", getTextFromClipboard, None,
283+
Return, "string",
284+
End),
285+
282286
new Function(c, "myNetworkPort", myNetworkPort, None,
283287
Return, "int",
284288
End),
@@ -466,6 +470,11 @@ NODE_DECLARATION(putUrlOnClipboard, void)
466470
{
467471
}
468472

473+
NODE_DECLARAION(getTextFromClipboard, Mu::Pointer)
474+
{
475+
NODE_RETURN(0); // Will represent a string
476+
}
477+
469478
NODE_DECLARATION(myNetworkPort, int)
470479
{
471480
NODE_RETURN(0);

src/bin/imgtools/rvio/UICommands.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ NODE_DECLARATION(httpGet, void);
5050
NODE_DECLARATION(httpPost, void);
5151
NODE_DECLARATION(sessionFromUrl, void);
5252
NODE_DECLARATION(putUrlOnClipboard, void);
53+
NODE_DECLARATION(getTextFromClipboard, Mu::Pointer);
5354
NODE_DECLARATION(myNetworkPort, int);
5455
NODE_DECLARATION(encodePassword, Mu::Pointer);
5556
NODE_DECLARATION(decodePassword, Mu::Pointer);

src/lib/app/RvCommon/MuUICommands.cpp

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,10 @@ void initUICommands()
491491
new Param(c, "doEncode", "bool", Value(true)),
492492
End),
493493

494+
new Function(c, "getTextFromClipboard", getTextFromClipboard, None,
495+
Return, "string",
496+
End),
497+
494498
new Function(c, "myNetworkPort", myNetworkPort, None,
495499
Return, "int",
496500
End),
@@ -2038,6 +2042,12 @@ NODE_IMPLEMENTATION(sessionFromUrl, void)
20382042
RvApp()->sessionFromUrl(url->c_str());
20392043
}
20402044

2045+
NODE_IMPLEMENTATION(getTextFromClipboard, Pointer) {
2046+
const StringType* stype = static_cast<const StringType*>(NODE_THIS.type());
2047+
std::string s = RvApp()->getTextFromClipboard(); // Getting text from the clipboard
2048+
Mu::Pointer p = stype->allocate(s.c_str());
2049+
NODE_RETURN(p);
2050+
}
20412051

20422052
NODE_IMPLEMENTATION(putUrlOnClipboard, void)
20432053
{
@@ -2050,25 +2060,6 @@ NODE_IMPLEMENTATION(putUrlOnClipboard, void)
20502060
RvApp()->putUrlOnClipboard(url->c_str(),
20512061
title->c_str(),
20522062
doEncode);
2053-
2054-
/*
2055-
NO WORKY
2056-
2057-
QUrl qurl;
2058-
qurl.setScheme("rvlink");
2059-
qurl.setUrl (url->c_str(), QUrl::TolerantMode);
2060-
cerr << "made QUrl from '" << url->c_str() << "', valid " << qurl.isValid() << endl;
2061-
QList<QUrl> qlist;
2062-
qlist.append (qurl);
2063-
2064-
// XXX memory leak, but a tiny one.
2065-
QMimeData *qmd = new QMimeData();
2066-
2067-
qmd->setUrls(qlist);
2068-
qmd->setText(url->c_str());
2069-
2070-
QApplication::clipboard()->setMimeData(qmd);
2071-
*/
20722063
}
20732064

20742065
NODE_IMPLEMENTATION(myNetworkPort, int)

src/lib/app/RvCommon/RvApplication.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@
5151
#include <QtWidgets/QDesktopWidget>
5252
#include <QtWidgets/QGridLayout>
5353
#include <QtWidgets/QTextEdit>
54+
#include <QApplication>
55+
#include <QClipboard>
56+
#include <QString>
5457

5558
#ifndef PLATFORM_WINDOWS
5659
extern char **environ;
@@ -1446,6 +1449,26 @@ RvApplication::putUrlOnClipboard(string url, string title, bool doEncode)
14461449
#endif
14471450
}
14481451

1452+
std::string
1453+
RvApplication::getTextFromClipboard()
1454+
{
1455+
QString text;
1456+
QClipboard *clipboard = QApplication::clipboard();
1457+
1458+
#if defined(PLATFORM_DARWIN)
1459+
text = clipboard->text(QClipboard::Clipboard);
1460+
#elif defined(PLATFORM_WINDOWS)
1461+
text = clipboard->text(QClipboard::Clipboard);
1462+
#else
1463+
text = clipboard->text(QClipboard::Selection);
1464+
if (text.isEmpty()) {
1465+
text = clipboard->text(QClipboard::Clipboard);
1466+
}
1467+
#endif
1468+
1469+
return text.toUtf8().constData();
1470+
}
1471+
14491472
void
14501473
RvApplication::initializeQSettings(string altPath)
14511474
{

src/lib/app/RvCommon/RvCommon/MuUICommands.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ NODE_DECLARATION(httpPutString, void);
6161
NODE_DECLARATION(httpPutData, void);
6262
NODE_DECLARATION(sessionFromUrl, void);
6363
NODE_DECLARATION(putUrlOnClipboard, void);
64+
NODE_DECLARATION(getTextFromClipboard, Mu::Pointer);
6465
NODE_DECLARATION(myNetworkPort, int);
6566
NODE_DECLARATION(myNetworkHost, Mu::Pointer);
6667
NODE_DECLARATION(encodePassword, Mu::Pointer);

src/lib/app/RvCommon/RvCommon/RvApplication.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ class RvApplication : public QObject, public RvConsoleApplication
100100
static void parseURL (const char *s, std::vector<char *> &av);
101101
static void sessionFromUrl (std::string url);
102102
static void putUrlOnClipboard (std::string url, std::string title, bool doEncode=true);
103+
static std::string getTextFromClipboard ();
103104
static std::string encodeCommandLineURL (int argc, char *argv[]);
104105
static std::string bakeCommandLineURL (int argc, char *argv[]);
105106
static void initializeQSettings (std::string altPath);

src/lib/app/mu_rvui/commands.mud

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1727,6 +1727,7 @@ networkAccessManager "Returns Qt network access manager object"
17271727
//javascriptMuExport "Export Mu eval() call as a javascript Object in the given WebFrame"
17281728
sessionFromUrl "Create a session from a (possibly baked) rvlink URL"
17291729
putUrlOnClipboard "Copy a URL on the system clipboard"
1730+
getTextFromClipboard "Get the text sitting in your clipboard"
17301731
myNetworkPort "Returns the currently set port number for networking"
17311732
myNetworkHost "Returns the name of the host RV is running on for purposes of networking"
17321733
encodePassword "-"

src/plugins/rv-packages/annotate/annotate_mode.mu

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,11 @@ class: AnnotateMinorMode : MinorMode
622622
populateAnnotationList();
623623
}
624624

625+
method: getTextFromClipboard(string;)
626+
{
627+
628+
}
629+
625630
//----------------------------------------------------------------------
626631

627632
method: pointerLocation ((string, Point); Event event)
@@ -1105,6 +1110,12 @@ class: AnnotateMinorMode : MinorMode
11051110
_toolSliderLabel.setText(if d.sliderName eq nil then "Opacity" else d.sliderName);
11061111
}
11071112

1113+
method: getClipboard(string;)
1114+
{
1115+
print("DEBUG: Getting clipboard from Mu file");
1116+
commands.getTextFromClipboard();
1117+
}
1118+
11081119
method: locationChangedSlot (void; Qt.DockWidgetArea area)
11091120
{
11101121
_dockArea = area;
@@ -2154,7 +2165,8 @@ class: AnnotateMinorMode : MinorMode
21542165
("key-down--control--backspace", backwardsKillWord, ""),
21552166
("key-down--meta--a", killLine, ""),
21562167
("key-down--alt--a", killLine, ""),
2157-
("key-down--space", insertChar, ""),
2168+
// ("key-down--space", insertChar, ""),
2169+
("key-down--space", getClipboard, ""),
21582170
("key-down--enter", insertNL, ""),
21592171
("key-down--control--enter", commitText(false,), ""),
21602172
("key-down--meta--enter", commitText(false,), ""),

0 commit comments

Comments
 (0)