[rkward] /: Allow to reference current script file name in plugins (untested)

Thomas Friedrichsmeier null at kde.org
Sat Sep 29 15:48:47 BST 2018


Git commit f605ff01d8429d7f4b548e15e81f5cc4f6339b76 by Thomas Friedrichsmeier.
Committed on 29/09/2018 at 14:47.
Pushed by tfry into branch 'master'.

Allow to reference current script file name in plugins (untested)

M  +1    -0    ChangeLog
M  +3    -2    doc/rkwardplugins/index.docbook
M  +8    -2    rkward/plugin/rkstandardcomponent.cpp
M  +2    -1    rkward/windows/rkcommandeditorwindow.cpp

https://commits.kde.org/rkward/f605ff01d8429d7f4b548e15e81f5cc4f6339b76

diff --git a/ChangeLog b/ChangeLog
index f794e6ff..13fa1374 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,5 @@
 --- Version 0.7.1 - UNRELEASED
+- Allow to reference current script file in plugins      TODO: Test this
 - Add various live-preview options for R scripts, including a preview of R markdown rendering
 - Make it possible to "link" to specific settings pages from the internal documentation
 - Slighlty less confusing output in case a package is installed from require(), such as in many plugins
diff --git a/doc/rkwardplugins/index.docbook b/doc/rkwardplugins/index.docbook
index 39c04bd1..516bfe45 100644
--- a/doc/rkwardplugins/index.docbook
+++ b/doc/rkwardplugins/index.docbook
@@ -1702,9 +1702,10 @@ This chapter contains information on some topics that are useful only to certain
 </sect1>
 
 <sect1 id="current_object">
-<title>Referencing the current object</title>
+<title>Referencing the current object or current file</title>
 	<para>
-		For many plugins it is desirable to work on the <quote>current</quote> object. For instance a <quote>sort</quote> plugin could pre-select the data.frame that is currently being edited for sorting. The name of the current object is available to plugins as a pre-defined property called <parameter>current_object</parameter>. You can connect to this property in the usual way. If no object is current, the property equates to an empty string.
+		For many plugins it is desirable to work on the <quote>current</quote> object. For instance a <quote>sort</quote> plugin could pre-select the data.frame that is currently being edited for sorting. The name of the current object is available to plugins as a pre-defined property called <parameter>current_object</parameter>. You can connect to this property in the usual way. If no object is current, the property equates to an empty string. Similarly, the url of the current script file
+		is accessible as a pre-defined property called <parameter>current_filename</parameter>. That property is empty if no script file is currently being edited, or the script file has not been saved, yet.
 	</para>
 	<para>
 		Currently the <parameter>current_object</parameter> can only be of class <function>data.frame</function>, but please do not rely on this, since this will be extended to other types of data in the future. If you are interested in <function>data.frame</function> objects, only, connect to the <parameter>current_dataframe</parameter> property, instead. Alternatively, you can enforce type requirements by using appropriate constraints on your <command><varslot></command>s, or by using <link linkend="logic_scripted">GUI logic scripting</link>.
diff --git a/rkward/plugin/rkstandardcomponent.cpp b/rkward/plugin/rkstandardcomponent.cpp
index 89538c00..95d05d06 100644
--- a/rkward/plugin/rkstandardcomponent.cpp
+++ b/rkward/plugin/rkstandardcomponent.cpp
@@ -2,7 +2,7 @@
                           rkstandardcomponent  -  description
                              -------------------
     begin                : Sun Feb 19 2006
-    copyright            : (C) 2006-2016 by Thomas Friedrichsmeier
+    copyright            : (C) 2006-2018 by Thomas Friedrichsmeier
     email                : thomas.friedrichsmeier at kdemail.net
  ***************************************************************************/
 
@@ -80,13 +80,19 @@ RKStandardComponent::RKStandardComponent (RKComponent *parent_component, QWidget
 
 	RKComponentPropertyRObjects *current_object_property = new RKComponentPropertyRObjects (this, false);
 	RKComponentPropertyRObjects *current_dataframe_property = new RKComponentPropertyRObjects (this, false);
+	RKComponentPropertyBase *current_filename_property = new RKComponentPropertyBase (this, false);
 	current_object_property->setInternal (true);
 	current_dataframe_property->setInternal (true);
+	current_filename_property->setInternal (false);
 	RKMDIWindow *w = RKWorkplace::mainWorkplace ()->activeWindow (RKMDIWindow::AnyWindowState);
-	if (w) current_object_property->setValue (w->globalContextProperty ("current_object"));
+	if (w) {
+		current_object_property->setValue (w->globalContextProperty ("current_object"));
+		current_filename_property->setValue (w->globalContextProperty ("current_filename"));
+	}
 	if (current_object_property->objectValue () && current_object_property->objectValue ()->isDataFrame ()) current_dataframe_property->setObjectValue (current_object_property->objectValue ());
 	addChild ("current_object", current_object_property);
 	addChild ("current_dataframe", current_dataframe_property);
+	addChild ("current_filename", current_filename_property);
 
 	// open the main description file for parsing
 	XMLHelper* xml = getXmlHelper ();
diff --git a/rkward/windows/rkcommandeditorwindow.cpp b/rkward/windows/rkcommandeditorwindow.cpp
index e0d29772..b924a0d8 100644
--- a/rkward/windows/rkcommandeditorwindow.cpp
+++ b/rkward/windows/rkcommandeditorwindow.cpp
@@ -208,7 +208,8 @@ RKCommandEditorWindow::RKCommandEditorWindow (QWidget *parent, const QUrl _url,
 	preview_widget->hide ();
 	layout->addWidget(preview_splitter);
 
-	connect (m_doc, &KTextEditor::Document::documentUrlChanged, this, &RKCommandEditorWindow::updateCaption);
+	setGlobalContextProperty ("current_filename", m_doc->url ().url ());
+	connect (m_doc, &KTextEditor::Document::documentUrlChanged, [this]() { updateCaption(); setGlobalContextProperty ("current_filename", m_doc->url ().url ()); });
 	connect (m_doc, &KTextEditor::Document::modifiedChanged, this, &RKCommandEditorWindow::updateCaption);                // of course most of the time this causes a redundant call to updateCaption. Not if a modification is undone, however.
 #ifdef __GNUC__
 #warning remove this in favor of KTextEditor::Document::restore()



More information about the rkward-tracker mailing list