[rkward] rkward: Work in progress: Add "search online" context action (to R Console, for now).

Thomas Friedrichsmeier thomas.friedrichsmeier at ruhr-uni-bochum.de
Tue Mar 8 19:20:29 UTC 2016


Git commit 6d109f0404ca447271ce4470917e4e2d32f3720f by Thomas Friedrichsmeier.
Committed on 08/03/2016 at 19:19.
Pushed by tfry into branch 'master'.

Work in progress: Add "search online" context action (to R Console, for now).

TODO:
- Also add to script editor, workspace browser
- Change "Function Reference"-action to be autonomous, too.

M  +1    -0    rkward/misc/CMakeLists.txt
M  +37   -0    rkward/misc/rkstandardactions.cpp
M  +5    -1    rkward/misc/rkstandardactions.h
M  +9    -1    rkward/rkconsole.cpp
M  +1    -1    rkward/rkconsole.h
M  +10   -0    rkward/windows/rkcommandeditorwindow.cpp
M  +8    -2    rkward/windows/rkcommandeditorwindow.h
M  +2    -0    rkward/windows/rkstandardactions.rc

http://commits.kde.org/rkward/6d109f0404ca447271ce4470917e4e2d32f3720f

diff --git a/rkward/misc/CMakeLists.txt b/rkward/misc/CMakeLists.txt
index 2e70517..d3847e9 100644
--- a/rkward/misc/CMakeLists.txt
+++ b/rkward/misc/CMakeLists.txt
@@ -34,6 +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)
 
 ADD_LIBRARY(misc STATIC ${misc_STAT_SRCS})
 
diff --git a/rkward/misc/rkstandardactions.cpp b/rkward/misc/rkstandardactions.cpp
index f613598..685415b 100644
--- a/rkward/misc/rkstandardactions.cpp
+++ b/rkward/misc/rkstandardactions.cpp
@@ -24,6 +24,7 @@
 #include "rkstandardicons.h"
 #include "rkspecialactions.h"
 #include "../windows/rkmdiwindow.h"
+#include "../windows/rkcommandeditorwindow.h"
 
 #include "../debug.h"
 
@@ -79,3 +80,39 @@ KAction* RKStandardActions::functionHelp (RKMDIWindow *window, const QObject *re
 	ret->setShortcut (Qt::Key_F2);
 	return ret;
 }
+
+#include <kurifilter.h>
+#include <ktoolinvocation.h>
+
+class RKSearchOnlineHelpAction : public KAction {
+	Q_OBJECT
+public:
+	RKSearchOnlineHelpAction (QObject *parent, RKScriptContextProvider *context_provider) : KAction (parent) {
+		RK_TRACE (MISC);
+		provider = context_provider;
+		setText (i18n ("Search Online"));
+		connect (this, SIGNAL (triggered(bool)), this, SLOT (doSearch()));
+	};
+public slots:
+	void doSearch () {
+		RK_TRACE (MISC);
+		QString symbol, package;
+		provider->currentHelpContext (&symbol, &package);
+		KUriFilterData data (symbol + " " + package + " R");
+		KUriFilter::self ()->filterSearchUri (data, KUriFilter::NormalTextFilter);
+		KToolInvocation::invokeBrowser (data.uri ().url ());
+	};
+private:
+	RKScriptContextProvider *provider;
+};
+
+KAction* RKStandardActions::onlineHelp (RKMDIWindow *window, RKScriptContextProvider *context_provider) {
+	RK_TRACE (MISC);
+
+	// KF5 TODO: Add / replace with submenu to select search provider -> KUriFilterSearchProviderActions
+	KAction* ret = new RKSearchOnlineHelpAction (window, context_provider);
+	window->standardActionCollection ()->addAction ("search_online", ret);
+	return ret;
+}
+
+#include "rksearchonlinehelpaction_moc.cpp"
diff --git a/rkward/misc/rkstandardactions.h b/rkward/misc/rkstandardactions.h
index 8702bc5..50e0157 100644
--- a/rkward/misc/rkstandardactions.h
+++ b/rkward/misc/rkstandardactions.h
@@ -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
  ***************************************************************************/
 
@@ -22,6 +22,7 @@ class KAction;
 class QString;
 class QObject;
 class RKMDIWindow;
+class RKScriptContextProvider;
 
 /** This namespace provides functions to generate some standard actions, i.e. actions which are needed at more than one place.
 
@@ -36,6 +37,9 @@ namespace RKStandardActions {
 	KAction* runAll (RKMDIWindow *window, const QObject *receiver=0, const char *member=0);
 
 	KAction* functionHelp (RKMDIWindow *window, const QObject *receiver=0, const char *member=0);
+/** 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);
 };
 
 #endif
diff --git a/rkward/rkconsole.cpp b/rkward/rkconsole.cpp
index 553f29a..49d4d1a 100644
--- a/rkward/rkconsole.cpp
+++ b/rkward/rkconsole.cpp
@@ -885,6 +885,13 @@ void RKConsole::showContextHelp () {
 	RKHelpSearchWindow::mainHelpSearch ()->getContextHelp (currentEditingLine (), currentCursorPositionInCommand ());
 }
 
+void RKConsole::currentHelpContext (QString* symbol, QString* package) {
+	RK_TRACE (APP);
+	Q_UNUSED (package);
+
+	*symbol = RKCommonFunctions::getCurrentSymbol (currentEditingLine (), currentCursorPositionInCommand ());
+}
+
 void RKConsole::initializeActions (KActionCollection *ac) {
 	RK_TRACE (APP);
 #ifdef Q_WS_MAC
@@ -895,7 +902,8 @@ void RKConsole::initializeActions (KActionCollection *ac) {
 #	define REAL_CMD_KEY Qt::MetaModifier
 #endif
 	RKStandardActions::copyLinesToOutput (this, this, SLOT (copyLinesToOutput()));
-	context_help_action = RKStandardActions::functionHelp (this, this, SLOT(showContextHelp()));
+	RKStandardActions::functionHelp (this, this, SLOT(showContextHelp()));
+	RKStandardActions::onlineHelp (this, this);
 	run_selection_action = RKStandardActions::runCurrent (this, this, SLOT (runSelection()));
 
 	interrupt_command_action = ac->addAction ("interrupt", this, SLOT (resetConsole()));
diff --git a/rkward/rkconsole.h b/rkward/rkconsole.h
index 5b7d02b..a5a21d4 100644
--- a/rkward/rkconsole.h
+++ b/rkward/rkconsole.h
@@ -62,6 +62,7 @@ public:
 	int currentCursorPositionInCommand ();
 	void doTabCompletion ();
 	QString provideContext (int line_rev);
+	void currentHelpContext (QString *symbol, QString *package);  // KF5 TODO: override keyword
 
 	static RKConsole *mainConsole () { return main_console; };
 	static void setMainConsole (RKConsole *console) { main_console = console; };
@@ -135,7 +136,6 @@ friend class RKConsolePart;
 
 	bool tab_key_pressed_before;
 
-	KAction* context_help_action;
 	KAction* run_selection_action;
 	KAction* interrupt_command_action;
 	KAction* copy_commands_action;
diff --git a/rkward/windows/rkcommandeditorwindow.cpp b/rkward/windows/rkcommandeditorwindow.cpp
index 4c0fb3e..f7b5afc 100644
--- a/rkward/windows/rkcommandeditorwindow.cpp
+++ b/rkward/windows/rkcommandeditorwindow.cpp
@@ -589,6 +589,16 @@ void RKCommandEditorWindow::showHelp () {
 	RKHelpSearchWindow::mainHelpSearch ()->getContextHelp (line, c.column());
 }
 
+void RKCommandEditorWindow::currentHelpContext (QString *symbol, QString *package) {
+	RK_TRACE (COMMANDEDITOR);
+	Q_UNUSED (package);
+
+	KTextEditor::Cursor c = m_view->cursorPosition();
+	QString line = m_doc->line(c.line ()) + ' ';
+
+	*symbol = RKCommonFunctions::getCurrentSymbol (line, c.column ());
+}
+
 void RKCommandEditorWindow::tryCompletionProxy (KTextEditor::Document*) {
 	if (RKSettingsModuleCommandEditor::completionEnabled ()) {
 		if (cc_iface && cc_iface->isCompletionActive ()) {
diff --git a/rkward/windows/rkcommandeditorwindow.h b/rkward/windows/rkcommandeditorwindow.h
index eda6667..cb18ac7 100644
--- a/rkward/windows/rkcommandeditorwindow.h
+++ b/rkward/windows/rkcommandeditorwindow.h
@@ -2,7 +2,7 @@
                           rkcommandeditorwindow  -  description
                              -------------------
     begin                : Mon Aug 30 2004
-    copyright            : (C) 2004-2014 by Thomas Friedrichsmeier
+    copyright            : (C) 2004-2016 by Thomas Friedrichsmeier
     email                : thomas.friedrichsmeier at kdemail.net
  ***************************************************************************/
 
@@ -68,7 +68,12 @@ public:
 	/** to be implemented in subclasses. Provide some context, i.e. text *preceding* the cursor position (probably a line, but you may provide chunks in arbitrary size). If line_rev is 0, provide the line, the cursor is in. If line_rev is greater than 0, provide context before that.
 	@param context Place the context here
 	@returns a chunk of context. A null QString(), if no context was available. */
-	virtual QString provideContext (int line_rev) = 0;
+	virtual QString provideContext (int line_rev) {
+		Q_UNUSED (line_rev);
+		return QString ();
+	};
+	/** to be implemented in subclasses. Provide current context for help searches (based on current selection / current cursor position). If not package information is known, leave that empty. */
+	virtual void currentHelpContext (QString *symbol, QString *package) = 0;
 };
 
 class RObject;
@@ -190,6 +195,7 @@ public:
 	KUrl url ();
 
 	QString provideContext (int line_rev);
+	void currentHelpContext (QString* symbol, QString* package);  // KF5 TODO: add override keyword
 	QString currentCompletionWord () const;
 
 	void highlightLine (int linenum);
diff --git a/rkward/windows/rkstandardactions.rc b/rkward/windows/rkstandardactions.rc
index dd85c54..accdacc 100644
--- a/rkward/windows/rkstandardactions.rc
+++ b/rkward/windows/rkstandardactions.rc
@@ -40,6 +40,7 @@
 			<Action name="run_all" group="run_actions_merge"/>
 		</Menu>
 		<Action name="function_reference" group="ktexteditor_popup_merge2"/>
+		<Action name="search_online" group="ktexteditor_popup_merge2"/>
 		<Separator group="ktexteditor_popup_merge2"/>
 		<Action name="window_configure" group="ktexteditor_popup_merge2"/>
 	</Menu>
@@ -48,6 +49,7 @@
 		<Action name="paste_special" group="rkconsole_context_merge_paste"/>
 		<Action name="run_current" group="rkconsole_context_merge1"/>
 		<Action name="function_reference" group="rkconsole_context_merge2"/>
+		<Action name="search_online" group="ktexteditor_context_merge2"/>
 		<Separator/>
 		<Action name="window_configure"/>
 	</Menu>



More information about the rkward-tracker mailing list