Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow users to paste text into the annotations tool #524

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, "pasteTextFromClipboard", pasteTextFromClipboard, 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(pasteTextFromClipboard, 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(pasteTextFromClipboard, 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, "pasteTextFromClipboard", pasteTextFromClipboard, 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(pasteTextFromClipboard, Pointer) {
const StringType* stype = static_cast<const StringType*>(NODE_THIS.type());
std::string s = RvApp()->pasteTextFromClipboard(); // 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);

/*
chxmberland marked this conversation as resolved.
Show resolved Hide resolved
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
12 changes: 12 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 @@ -1451,6 +1454,15 @@ RvApplication::putUrlOnClipboard(string url, string title, bool doEncode)
#endif
}

std::string
RvApplication::pasteTextFromClipboard()
{
QString text;
QClipboard *clipboard = QApplication::clipboard();
text = clipboard->text(QClipboard::Clipboard);
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(pasteTextFromClipboard, 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 pasteTextFromClipboard ();
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"
pasteTextFromClipboard "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
20 changes: 20 additions & 0 deletions src/plugins/rv-packages/annotate/annotate_mode.mu
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,25 @@ class: AnnotateMinorMode : MinorMode
populateAnnotationList();
}

method: pasteTextFromClipboard (void; Event event)
{
// Getting text directly from the users clipboard
let text = commands.pasteTextFromClipboard();

if (text == "") {
print("WARNING: Clipboard is empty");

} else {
_textPlacementMode = true;
_textBuffer.pop_back();

for (int i = 0; i < text.size(); i++)
_textBuffer.push_back(text[i]);

setText(_textBuffer);
}
}

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

method: pointerLocation ((string, Point); Event event)
Expand Down Expand Up @@ -2152,6 +2171,7 @@ class: AnnotateMinorMode : MinorMode
("key-down--alt--backspace", backwardsKillWord, ""),
("key-down--shift--backspace", backwardsKillWord, ""),
("key-down--control--backspace", backwardsKillWord, ""),
("key-down--meta--v", pasteTextFromClipboard, ""), // Paste from clipboard
("key-down--meta--a", killLine, ""),
("key-down--alt--a", killLine, ""),
("key-down--space", insertChar, ""),
Expand Down