[rkward] rkward: Make Workspace tool window use the standard "Function Help"-Action.
Thomas Friedrichsmeier
thomas.friedrichsmeier at ruhr-uni-bochum.de
Tue Mar 8 14:03:02 UTC 2016
Git commit 379d764abee3a702280ee91cb5722effeb7bd993 by Thomas Friedrichsmeier.
Committed on 08/03/2016 at 14:00.
Pushed by tfry into branch 'master'.
Make Workspace tool window use the standard "Function Help"-Action.
For that, make sure to look up function in the correct package (falling back to all packages, if not found).
In passing, remove some support for really antique versions of R (minimum now is 2.10.0).
M +10 -4 rkward/core/robject.cpp
M +4 -1 rkward/core/robject.h
M +1 -1 rkward/rbackend/FindR.cmake
M +10 -8 rkward/rbackend/rpackages/rkward/R/internal_help.R
M +8 -6 rkward/windows/robjectbrowser.cpp
M +2 -2 rkward/windows/robjectbrowser.h
http://commits.kde.org/rkward/379d764abee3a702280ee91cb5722effeb7bd993
diff --git a/rkward/core/robject.cpp b/rkward/core/robject.cpp
index 1c0ca12..c879fd2 100644
--- a/rkward/core/robject.cpp
+++ b/rkward/core/robject.cpp
@@ -2,7 +2,7 @@
robject - description
-------------------
begin : Thu Aug 19 2004
- copyright : (C) 2004-2013 by Thomas Friedrichsmeier
+ copyright : (C) 2004-2016 by Thomas Friedrichsmeier
email : thomas.friedrichsmeier at kdemail.net
***************************************************************************/
@@ -783,7 +783,7 @@ bool RObject::canRemove () const {
return (isInGlobalEnv ());
}
-bool RObject::isInGlobalEnv () const {
+REnvironmentObject* RObject::toplevelEnvironment () const {
RK_TRACE (OBJECTS);
// could be made recursive instead, but likely it's faster like this
@@ -791,11 +791,17 @@ bool RObject::isInGlobalEnv () const {
while (o && (!o->isType (ToplevelEnv))) {
o = o->parent;
}
-
if (!o) {
RK_ASSERT (this == RObjectList::getObjectList ());
- return false;
+ return RObjectList::getGlobalEnv ();
}
+ return static_cast<REnvironmentObject*> (o);
+}
+
+bool RObject::isInGlobalEnv () const {
+ RK_TRACE (OBJECTS);
+
+ RObject* o = toplevelEnvironment ();
if (o->isType (GlobalEnv)) {
if (o != this) return true; // the GlobalEnv is not inside the GlobalEnv!
}
diff --git a/rkward/core/robject.h b/rkward/core/robject.h
index 92308c0..0249622 100644
--- a/rkward/core/robject.h
+++ b/rkward/core/robject.h
@@ -2,7 +2,7 @@
robject - description
-------------------
begin : Thu Aug 19 2004
- copyright : (C) 2004-2013 by Thomas Friedrichsmeier
+ copyright : (C) 2004-2016 by Thomas Friedrichsmeier
email : thomas.friedrichsmeier at kdemail.net
***************************************************************************/
@@ -150,7 +150,10 @@ public:
bool canRead () const;
bool canRename () const;
bool canRemove () const;
+/** returns true, if this object is inside the .GlobalEnv. The .GlobalEnv is not considered to be inside itself. */
bool isInGlobalEnv () const;
+/** returns the toplevel environment that this object is in. May the the same as the object. */
+ REnvironmentObject *toplevelEnvironment () const;
void rename (const QString &new_short_name);
void remove (bool removed_in_workspace);
diff --git a/rkward/rbackend/FindR.cmake b/rkward/rbackend/FindR.cmake
index 867b1bf..aa6bc47 100644
--- a/rkward/rbackend/FindR.cmake
+++ b/rkward/rbackend/FindR.cmake
@@ -19,7 +19,7 @@ EXECUTE_PROCESS(
MESSAGE (STATUS "R architecture is ${R_ARCH}")
# check R version.
-SET (R_MIN_VERSION "2.8.0")
+SET (R_MIN_VERSION "2.10.0")
MESSAGE (STATUS "Checking R version")
EXECUTE_PROCESS(
COMMAND ${R_EXECUTABLE} "--slave" "--no-save" "-e" "cat (paste(R.version$major, R.version$minor, sep='.'))"
diff --git a/rkward/rbackend/rpackages/rkward/R/internal_help.R b/rkward/rbackend/rpackages/rkward/R/internal_help.R
index 84ce113..f4eae65 100644
--- a/rkward/rbackend/rpackages/rkward/R/internal_help.R
+++ b/rkward/rbackend/rpackages/rkward/R/internal_help.R
@@ -23,15 +23,17 @@
# a simple wrapper around help() that makes it easier to detect in code, whether help was found or not.
# used from RKHelpSearchWindow::getFunctionHelp
#' @export
-".rk.getHelp" <- function (...) {
- if (compareVersion (as.character (getRversion()), "2.10.0") >= 0) {
- res <- help (..., help_type="html")
- } else {
- res <- help (..., chmhelp=FALSE, htmlhelp=TRUE)
- }
+".rk.getHelp" <- function (topic, package=NULL, ...) {
+ res <- help (topic, (package), ..., help_type="html")
if (!length (as.character (res))) { # this seems undocumented, but it is what utils:::print.help_files_with_topic checks
- show (res)
- stop ("No help found")
+ if (!is.null (package)) {
+ # if no help found, try once more, without package restriction
+ res <- help (topic, package=NULL, ..., help_type="html")
+ }
+ if (!length (as.character (res))) {
+ show (res)
+ stop ("No help found")
+ }
}
show (res)
invisible (TRUE)
diff --git a/rkward/windows/robjectbrowser.cpp b/rkward/windows/robjectbrowser.cpp
index 1a6d6ee..345caeb 100644
--- a/rkward/windows/robjectbrowser.cpp
+++ b/rkward/windows/robjectbrowser.cpp
@@ -2,7 +2,7 @@
robjectbrowser - description
-------------------
begin : Thu Aug 19 2004
- copyright : (C) 2004 - 2015 by Thomas Friedrichsmeier
+ copyright : (C) 2004 - 2016 by Thomas Friedrichsmeier
email : thomas.friedrichsmeier at kdemail.net
***************************************************************************/
@@ -37,6 +37,7 @@
#include "../misc/rkobjectlistview.h"
#include "../misc/rkdummypart.h"
#include "../misc/rkstandardicons.h"
+#include "../misc/rkstandardactions.h"
#include "rkworkplace.h"
#include "../dataeditor/rkeditor.h"
@@ -93,14 +94,14 @@ void RObjectBrowser::initialize () {
RK_DEBUG (APP, DL_INFO, "creating workspace browser");
- internal = new RObjectBrowserInternal (layout_widget);
+ internal = new RObjectBrowserInternal (layout_widget, this);
setFocusProxy (internal);
setMinimumSize (internal->minimumSize ());
}
///////////////////////// RObjectBrowserInternal /////////////////////////////
-RObjectBrowserInternal::RObjectBrowserInternal (QWidget *parent) : QWidget (parent) {
+RObjectBrowserInternal::RObjectBrowserInternal (QWidget *parent, RObjectBrowser *browser) : QWidget (parent) {
RK_TRACE (APP);
setFocusPolicy (Qt::ClickFocus);
@@ -114,8 +115,7 @@ RObjectBrowserInternal::RObjectBrowserInternal (QWidget *parent) : QWidget (pare
update_button = new QPushButton (i18n ("Update"), this);
vbox->addWidget (update_button);
- actions.insert (Help, new QAction (i18n ("Search Help"), this));
- connect (actions[Help], SIGNAL(triggered(bool)), this, SLOT(popupHelp()));
+ actions.insert (Help, RKStandardActions::functionHelp (browser, this, SLOT(popupHelp())));
actions.insert (Edit, new QAction (i18n ("Edit"), this));
connect (actions[Edit], SIGNAL(triggered(bool)), this, SLOT(popupEdit()));
actions.insert (View, new QAction (i18n ("View"), this));
@@ -167,7 +167,9 @@ void RObjectBrowserInternal::updateButtonClicked () {
void RObjectBrowserInternal::popupHelp () {
RK_TRACE (APP);
- if (list_view->menuObject ()) RKHelpSearchWindow::mainHelpSearch ()->getFunctionHelp (list_view->menuObject ()->getShortName ());
+ RObject *object = list_view->menuObject ();
+ if (!object) return;
+ RKHelpSearchWindow::mainHelpSearch ()->getFunctionHelp (object->getShortName (), object->isInGlobalEnv () ? QString () : object->toplevelEnvironment ()->packageName ());
}
void RObjectBrowserInternal::popupEdit () {
diff --git a/rkward/windows/robjectbrowser.h b/rkward/windows/robjectbrowser.h
index afcadb0..2f038f7 100644
--- a/rkward/windows/robjectbrowser.h
+++ b/rkward/windows/robjectbrowser.h
@@ -2,7 +2,7 @@
robjectbrowser - description
-------------------
begin : Thu Aug 19 2004
- copyright : (C) 2004 - 2015 by Thomas Friedrichsmeier
+ copyright : (C) 2004 - 2016 by Thomas Friedrichsmeier
email : thomas.friedrichsmeier at kdemail.net
***************************************************************************/
@@ -62,7 +62,7 @@ Provides most of the functionality of RObjectBrowser
class RObjectBrowserInternal : public QWidget {
Q_OBJECT
public:
- explicit RObjectBrowserInternal (QWidget *parent);
+ explicit RObjectBrowserInternal (QWidget *parent, RObjectBrowser *browser);
~RObjectBrowserInternal ();
private slots:
void updateButtonClicked ();
More information about the rkward-tracker
mailing list