Skip to content

Commit

Permalink
Allow users to paste from clipboard into RV annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
chxmberland committed Jul 29, 2024
1 parent d15e8b1 commit 5256b0b
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 21 deletions.
2 changes: 1 addition & 1 deletion rvcmds.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down
9 changes: 9 additions & 0 deletions src/bin/imgtools/rvio/UICommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/bin/imgtools/rvio/UICommands.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
29 changes: 10 additions & 19 deletions src/lib/app/RvCommon/MuUICommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -2038,6 +2042,12 @@ NODE_IMPLEMENTATION(sessionFromUrl, void)
RvApp()->sessionFromUrl(url->c_str());
}

NODE_IMPLEMENTATION(getTextFromClipboard, Pointer) {
const StringType* stype = static_cast<const StringType*>(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)
{
Expand All @@ -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<QUrl> 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)
Expand Down
23 changes: 23 additions & 0 deletions src/lib/app/RvCommon/RvApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
#include <QtWidgets/QDesktopWidget>
#include <QtWidgets/QGridLayout>
#include <QtWidgets/QTextEdit>
#include <QApplication>
#include <QClipboard>
#include <QString>

#ifndef PLATFORM_WINDOWS
extern char **environ;
Expand Down Expand Up @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions src/lib/app/RvCommon/RvCommon/MuUICommands.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/lib/app/RvCommon/RvCommon/RvApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class RvApplication : public QObject, public RvConsoleApplication
static void parseURL (const char *s, std::vector<char *> &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);
Expand Down
1 change: 1 addition & 0 deletions src/lib/app/mu_rvui/commands.mud
Original file line number Diff line number Diff line change
Expand Up @@ -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 "-"
Expand Down
14 changes: 13 additions & 1 deletion src/plugins/rv-packages/annotate/annotate_mode.mu
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,11 @@ class: AnnotateMinorMode : MinorMode
populateAnnotationList();
}

method: getTextFromClipboard(string;)
{

}

//----------------------------------------------------------------------

method: pointerLocation ((string, Point); Event event)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,), ""),
Expand Down

0 comments on commit 5256b0b

Please sign in to comment.