Repository navigation
AppleScript support - #3355
AppleScript support#3355
Conversation
| static MainWindow *instance; | ||
|
|
||
| public: | ||
| static MainWindow *getInstance(); |
There was a problem hiding this comment.
I'm not a fan of this. Why not have ScriptCommand.mm accept a MainWindow as part of its constructor? Or if that's not possible for some reason, have a method that it can call to 'bind' to a window instance.
There was a problem hiding this comment.
I am not sure if it is possible to dynamically initialize NSScriptCommand, akaik, it is usually initialized automatically by the application. This implementation just mirrors desktop-mac's:
There was a problem hiding this comment.
Perhaps the evaluateRScriptCommand class could gain a function e.g. - initialize(MainWindow* window) that gets called by the MainWindow class when appropriate? And that could take care of setting the MainWindow instance so that it can be used.
| /* | ||
| * ScriptCommand.h | ||
| * | ||
| * Copyright (C) 2009-17 by RStudio, Inc. |
| #include <boost/algorithm/string/replace.hpp> | ||
|
|
||
|
|
||
| std::string jsEscape(std::string str) |
There was a problem hiding this comment.
We have a couple escape helpers here: do any of them suffice?
rstudio/src/cpp/core/include/core/StringUtils.hpp
Lines 91 to 95 in f5ba8af
| { | ||
| rCmd = jsEscape(rCmd); | ||
| std::string js = "window.desktopHooks.evaluateRCmd(\"" + rCmd + "\")"; | ||
| rstudio::desktop::MainWindow::getInstance()->webPage()->runJavaScript(QString::fromUtf8(js.c_str())); |
There was a problem hiding this comment.
nit: there is a QString::fromStdString() method that you might consider using here
|
I have added a class |
|
Great! Just to double-check: does this work as expected when there are multiple RStudio windows open (e.g. if you have multiple main windows; perhaps with different projects open)? |
|
it will always send to the newest instance. In order to support multiple instances, we will need communications between the sessions. I may be able to work on it in the future if you could point me to the correct files to look at. |
|
a quick search reveals that a new window created as a separated instance: .Thus there are no communications between them. We will need a session manager in order to achieve the support of multiple sessions. |
|
I think it's okay if we just send to the newest RStudio instance. You might even want to set things up so that commands are sent to the most recently focused RStudio window. |
@kevinushey unfortunately it is not possible without a session manager. Ideally, there should be only one instance and a new session is opened in the same instance, like how Safari works. |
|
@kevinushey I hope the RStudio team would consider merging this into v1.2 release as AppleScript was already supported v1.1. |
|
Yes, we will take this for v1.2. Thanks again for the PR! |
|
Awesome. |
Not the most beautiful way to do it, but it works.
close #3354