[rkward] rkward: Add online help search to workspace browser and script editor. Simplify function reference search code.

Thomas Friedrichsmeier thomas.friedrichsmeier at ruhr-uni-bochum.de
Wed Mar 9 12:06:50 UTC 2016


Git commit 7a003a2a299371ba9ce465c3cec58b0b5efb44b7 by Thomas Friedrichsmeier.
Committed on 09/03/2016 at 12:05.
Pushed by tfry into branch 'master'.

Add online help search to workspace browser and script editor. Simplify function reference search code.

M  +1    -1    rkward/misc/CMakeLists.txt
M  +27   -6    rkward/misc/rkstandardactions.cpp
M  +1    -1    rkward/misc/rkstandardactions.h
M  +1    -6    rkward/rkconsole.cpp
M  +0    -2    rkward/rkconsole.h
M  +2    -10   rkward/windows/rkcommandeditorwindow.cpp
M  +0    -4    rkward/windows/rkcommandeditorwindow.h
M  +5    -3    rkward/windows/robjectbrowser.cpp
M  +6    -3    rkward/windows/robjectbrowser.h

http://commits.kde.org/rkward/7a003a2a299371ba9ce465c3cec58b0b5efb44b7

diff --git a/rkward/misc/CMakeLists.txt b/rkward/misc/CMakeLists.txt
index d3847e9..c18ffa7 100644
--- a/rkward/misc/CMakeLists.txt
+++ b/rkward/misc/CMakeLists.txt
@@ -34,7 +34,7 @@ SET(misc_STAT_SRCS
 QT4_AUTOMOC(${misc_STAT_SRCS})
 # Urghs. QT4_AUTOMOC scans only the .h-file for Q_OBJECT macros. Let's hope this will be better with KF5
 QT4_GENERATE_MOC (rkaccordiontable.cpp ${CMAKE_CURRENT_BINARY_DIR}/rkaccordiontablemodel_moc.cpp)
-QT4_GENERATE_MOC (rkstandardactions.cpp ${CMAKE_CURRENT_BINARY_DIR}/rksearchonlinehelpaction_moc.cpp)
+QT4_GENERATE_MOC (rkstandardactions.cpp ${CMAKE_CURRENT_BINARY_DIR}/rkstandardactions_moc.cpp)
 
 ADD_LIBRARY(misc STATIC ${misc_STAT_SRCS})
 
diff --git a/rkward/misc/rkstandardactions.cpp b/rkward/misc/rkstandardactions.cpp
index 685415b..663e8f5 100644
--- a/rkward/misc/rkstandardactions.cpp
+++ b/rkward/misc/rkstandardactions.cpp
@@ -2,7 +2,7 @@
                           rkstandardactions  -  description
                              -------------------
     begin                : Sun Nov 18 2007
-    copyright            : (C) 2007-2013 by Thomas Friedrichsmeier
+    copyright            : (C) 2007-2016 by Thomas Friedrichsmeier
     email                : thomas.friedrichsmeier at kdemail.net
  ***************************************************************************/
 
@@ -25,6 +25,7 @@
 #include "rkspecialactions.h"
 #include "../windows/rkmdiwindow.h"
 #include "../windows/rkcommandeditorwindow.h"
+#include "../windows/rkhelpsearchwindow.h"
 
 #include "../debug.h"
 
@@ -72,12 +73,32 @@ KAction* RKStandardActions::runAll (RKMDIWindow *window, const QObject *receiver
 	return ret;
 }
 
-KAction* RKStandardActions::functionHelp (RKMDIWindow *window, const QObject *receiver, const char *member) {
+class RKSearchRHelpAction : public KAction {
+	Q_OBJECT
+public:
+	RKSearchRHelpAction (QObject *parent, RKScriptContextProvider *context_provider) : KAction (parent) {
+		RK_TRACE (MISC);
+		provider = context_provider;
+		setText (i18n ("&Function reference"));
+		setShortcut (Qt::Key_F2);
+		connect (this, SIGNAL (triggered(bool)), this, SLOT (doSearch()));
+	};
+public slots:
+	void doSearch () {
+		RK_TRACE (MISC);
+		QString symbol, package;
+		provider->currentHelpContext (&symbol, &package);
+		RKHelpSearchWindow::mainHelpSearch ()->getFunctionHelp (symbol, package);
+	};
+private:
+	RKScriptContextProvider *provider;
+};
+
+KAction* RKStandardActions::functionHelp (RKMDIWindow *window, RKScriptContextProvider *context_provider) {
 	RK_TRACE (MISC);
 
-	KAction* ret = window->standardActionCollection ()->addAction ("function_reference", receiver, member);
-	ret->setText (i18n ("&Function reference"));
-	ret->setShortcut (Qt::Key_F2);
+	KAction* ret = new RKSearchRHelpAction (window, context_provider);
+	window->standardActionCollection ()->addAction ("function_reference", ret);
 	return ret;
 }
 
@@ -115,4 +136,4 @@ KAction* RKStandardActions::onlineHelp (RKMDIWindow *window, RKScriptContextProv
 	return ret;
 }
 
-#include "rksearchonlinehelpaction_moc.cpp"
+#include "rkstandardactions_moc.cpp"
diff --git a/rkward/misc/rkstandardactions.h b/rkward/misc/rkstandardactions.h
index 50e0157..9571404 100644
--- a/rkward/misc/rkstandardactions.h
+++ b/rkward/misc/rkstandardactions.h
@@ -36,7 +36,7 @@ namespace RKStandardActions {
 	KAction* runCurrent (RKMDIWindow *window, const QObject *receiver=0, const char *member=0, bool current_or_line=false);
 	KAction* runAll (RKMDIWindow *window, const QObject *receiver=0, const char *member=0);
 
-	KAction* functionHelp (RKMDIWindow *window, const QObject *receiver=0, const char *member=0);
+	KAction* functionHelp (RKMDIWindow *window, RKScriptContextProvider *context_provider);
 /** Search for current symbol / selection, online. Note that you will not have to connect this action to any slot to work. It does everything by itself.
  *  It will query the given context_provider for context. */
 	KAction* onlineHelp (RKMDIWindow *window, RKScriptContextProvider *context_provider);
diff --git a/rkward/rkconsole.cpp b/rkward/rkconsole.cpp
index 49d4d1a..17b8434 100644
--- a/rkward/rkconsole.cpp
+++ b/rkward/rkconsole.cpp
@@ -880,11 +880,6 @@ void RKConsole::copyLinesToOutput () {
 	RKCommandHighlighter::copyLinesToOutput (view, RKCommandHighlighter::RInteractiveSession);
 }
 
-void RKConsole::showContextHelp () {
-	RK_TRACE (APP);
-	RKHelpSearchWindow::mainHelpSearch ()->getContextHelp (currentEditingLine (), currentCursorPositionInCommand ());
-}
-
 void RKConsole::currentHelpContext (QString* symbol, QString* package) {
 	RK_TRACE (APP);
 	Q_UNUSED (package);
@@ -902,7 +897,7 @@ void RKConsole::initializeActions (KActionCollection *ac) {
 #	define REAL_CMD_KEY Qt::MetaModifier
 #endif
 	RKStandardActions::copyLinesToOutput (this, this, SLOT (copyLinesToOutput()));
-	RKStandardActions::functionHelp (this, this, SLOT(showContextHelp()));
+	RKStandardActions::functionHelp (this, this);
 	RKStandardActions::onlineHelp (this, this);
 	run_selection_action = RKStandardActions::runCurrent (this, this, SLOT (runSelection()));
 
diff --git a/rkward/rkconsole.h b/rkward/rkconsole.h
index a5a21d4..500715a 100644
--- a/rkward/rkconsole.h
+++ b/rkward/rkconsole.h
@@ -158,8 +158,6 @@ public slots:
 	void literalCopy ();
 /** Clear the view, and add a prompt at the top. */
 	void clear ();
-/** show context help on the current word */
-	void showContextHelp ();
 /** Cancels the current command, if any, and clears the command buffer(s) */
 	void resetConsole ();
 	void runSelection ();
diff --git a/rkward/windows/rkcommandeditorwindow.cpp b/rkward/windows/rkcommandeditorwindow.cpp
index f7b5afc..e31982b 100644
--- a/rkward/windows/rkcommandeditorwindow.cpp
+++ b/rkward/windows/rkcommandeditorwindow.cpp
@@ -218,7 +218,8 @@ void RKCommandEditorWindow::initializeActions (KActionCollection* ac) {
 	action->setText (i18n ("Insert line break and run"));
 	action->setShortcuts (KShortcut (Qt::AltModifier + Qt::Key_Return, Qt::AltModifier + Qt::Key_Enter));
 
-	action_help_function = RKStandardActions::functionHelp (this, this, SLOT (showHelp()));
+	RKStandardActions::functionHelp (this, this);
+	RKStandardActions::onlineHelp (this, this);
 
 	actionmenu_run_block = new KActionMenu (i18n ("Run block"), this);
 	actionmenu_run_block->setDelayed (false);	// KDE4: TODO does not work correctly in the tool bar.
@@ -580,15 +581,6 @@ void RKCommandEditorWindow::updateCaption (KTextEditor::Document*) {
 	RKWardMainWindow::getMain ()->addScriptUrl (url ());
 }
 
-void RKCommandEditorWindow::showHelp () {
-	RK_TRACE (COMMANDEDITOR);
-
-	KTextEditor::Cursor c = m_view->cursorPosition();
-	QString line = m_doc->line(c.line ()) + ' ';
-
-	RKHelpSearchWindow::mainHelpSearch ()->getContextHelp (line, c.column());
-}
-
 void RKCommandEditorWindow::currentHelpContext (QString *symbol, QString *package) {
 	RK_TRACE (COMMANDEDITOR);
 	Q_UNUSED (package);
diff --git a/rkward/windows/rkcommandeditorwindow.h b/rkward/windows/rkcommandeditorwindow.h
index cb18ac7..fcb17a0 100644
--- a/rkward/windows/rkcommandeditorwindow.h
+++ b/rkward/windows/rkcommandeditorwindow.h
@@ -208,8 +208,6 @@ public slots:
 	void tryCompletion ();
 	void setPopupMenu ();
 	void focusIn (KTextEditor::View *);
-/** Show help about the current word. */
-	void showHelp ();
 /** run the currently selected command(s) or line */
 	void runCurrent ();
 /** run the entire script */
@@ -294,8 +292,6 @@ private:
 
 	KAction* action_setwd_to_script;
 
-	KAction* action_help_function;
-
 	KUrl previous_autosave_url;
 	QTimer* autosave_timer;
 
diff --git a/rkward/windows/robjectbrowser.cpp b/rkward/windows/robjectbrowser.cpp
index 345caeb..5643a45 100644
--- a/rkward/windows/robjectbrowser.cpp
+++ b/rkward/windows/robjectbrowser.cpp
@@ -115,7 +115,8 @@ RObjectBrowserInternal::RObjectBrowserInternal (QWidget *parent, RObjectBrowser
 	update_button = new QPushButton (i18n ("Update"), this);
 	vbox->addWidget (update_button);
 
-	actions.insert (Help, RKStandardActions::functionHelp (browser, this, SLOT(popupHelp())));
+	actions.insert (Help, RKStandardActions::functionHelp (browser, this));
+	actions.insert (SearchOnline, RKStandardActions::onlineHelp (browser, this));
 	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));
@@ -164,12 +165,13 @@ void RObjectBrowserInternal::updateButtonClicked () {
 	RObjectList::getObjectList ()->updateFromR (0);
 }
 
-void RObjectBrowserInternal::popupHelp () {
+void RObjectBrowserInternal::currentHelpContext (QString* symbol, QString* package) {
 	RK_TRACE (APP);
 
 	RObject *object = list_view->menuObject ();
 	if (!object) return;
-	RKHelpSearchWindow::mainHelpSearch ()->getFunctionHelp (object->getShortName (), object->isInGlobalEnv () ? QString () : object->toplevelEnvironment ()->packageName ());
+	*symbol = object->getShortName ();
+	*package = object->isInGlobalEnv () ? QString () : object->toplevelEnvironment ()->packageName ();
 }
 
 void RObjectBrowserInternal::popupEdit () {
diff --git a/rkward/windows/robjectbrowser.h b/rkward/windows/robjectbrowser.h
index 2f038f7..2fec0bf 100644
--- a/rkward/windows/robjectbrowser.h
+++ b/rkward/windows/robjectbrowser.h
@@ -22,6 +22,8 @@
 #include <QModelIndex>
 #include <QFocusEvent>
 
+#include "rkcommandeditorwindow.h"
+
 class RKObjectListView;
 class RKObjectListViewSettings;
 class QPushButton;
@@ -59,7 +61,7 @@ Provides most of the functionality of RObjectBrowser
 
 @author Thomas Friedrichsmeier
 */
-class RObjectBrowserInternal : public QWidget {
+class RObjectBrowserInternal : public QWidget, public RKScriptContextProvider {
 Q_OBJECT
 public:
 	explicit RObjectBrowserInternal (QWidget *parent, RObjectBrowser *browser);
@@ -67,8 +69,7 @@ public:
 private slots:
 	void updateButtonClicked ();
 	void contextMenuCallback (RObject *object, bool *suppress);
-	
-	void popupHelp ();
+
 	void popupEdit ();
 	void popupCopy ();
 /** essentially like popupCopy, but does not ask for a name */
@@ -82,9 +83,11 @@ private slots:
 protected:
 /** reimplemnented from QWidget to make show the globalenv object when activated (other than by mouse click) */
 	void focusInEvent (QFocusEvent *e);
+	void currentHelpContext (QString *symbol, QString *package); // KF5 TODO: override
 private:
 	enum PopupActions {
 		Help=0,
+		SearchOnline,
 		Edit,
 		View,
 		Rename,



More information about the rkward-tracker mailing list