[rkward/work/kateintegration] rkward: Emit document creation / deletion signals (allows Project plugin to work).

Thomas Friedrichsmeier null at kde.org
Sat Jan 11 22:53:39 GMT 2020


Git commit 56b1597927283e2c3ae42b0737df4b124d649bfc by Thomas Friedrichsmeier.
Committed on 11/01/2020 at 22:51.
Pushed by tfry into branch 'work/kateintegration'.

Emit document creation / deletion signals (allows Project plugin to work).

This required some rework all over the place, as not all our editor windows are to be considered "documents" in that they should be visible to kate plugins.

M  +5    -7    rkward/agents/showedittextfileagent.cpp
M  +1    -1    rkward/plugin/rkstandardcomponentgui.cpp
M  +2    -1    rkward/rkward.cpp
M  +6    -1    rkward/windows/katepluginintegration.cpp
M  +1    -1    rkward/windows/rkcallstackviewer.cpp
M  +34   -11   rkward/windows/rkcommandeditorwindow.cpp
M  +5    -5    rkward/windows/rkcommandeditorwindow.h
M  +5    -5    rkward/windows/rkworkplace.cpp
M  +13   -1    rkward/windows/rkworkplace.h

https://commits.kde.org/rkward/56b1597927283e2c3ae42b0737df4b124d649bfc

diff --git a/rkward/agents/showedittextfileagent.cpp b/rkward/agents/showedittextfileagent.cpp
index 5e3c84dc..f1fdbfba 100644
--- a/rkward/agents/showedittextfileagent.cpp
+++ b/rkward/agents/showedittextfileagent.cpp
@@ -82,13 +82,11 @@ void ShowEditTextFileAgent::showEditFiles (RBackendRequest *request) {
 		display_titles.append (title);
 	}
 
-	bool r_highlighting = false;
-	bool read_only = true;
-	bool delete_files = false;
+	int flags = RKCommandEditorFlags::ReadOnly;
 	if (request->type == RBackendRequest::ShowFiles) {
 		RK_ASSERT (!request->synchronous);
 
-		delete_files = request->params["delete"].toBool ();
+		if (request->params["delete"].toBool ()) flags +=  RKCommandEditorFlags::DeleteOnClose;
 		RKRBackendProtocolFrontend::setRequestCompleted (request);
 
 		if (prompt) {
@@ -101,14 +99,14 @@ void ShowEditTextFileAgent::showEditFiles (RBackendRequest *request) {
 			RKRBackendProtocolFrontend::setRequestCompleted (request);
 		}
 
-		r_highlighting = true;
-		read_only = false;
+		flags += RKCommandEditorFlags::DefaultToRHighlighting;
+		flags -= RKCommandEditorFlags::ReadOnly;
 	} else {
 		RK_ASSERT (false);
 	}
 
 	// do this last, as it may produce error messages, if some of the files could not be opened.
 	for (int n = 0; n < count; ++n) {
-		RKWorkplace::mainWorkplace ()->openScriptEditor (QUrl::fromLocalFile (files[n]), QString (), r_highlighting, read_only, display_titles[n], delete_files);
+		RKWorkplace::mainWorkplace ()->openScriptEditor (QUrl::fromLocalFile (files[n]), QString (), flags, display_titles[n]);
 	}
 }
diff --git a/rkward/plugin/rkstandardcomponentgui.cpp b/rkward/plugin/rkstandardcomponentgui.cpp
index f7307769..f5f071c9 100644
--- a/rkward/plugin/rkstandardcomponentgui.cpp
+++ b/rkward/plugin/rkstandardcomponentgui.cpp
@@ -154,7 +154,7 @@ RKStandardComponentGUI::RKStandardComponentGUI (RKStandardComponent *component,
 	if (!enslaved) {
 		// code display
 		RKXMLGUIPreviewArea *area = addDockedPreview (&code_display_visibility, i18n ("Code Preview"), QString (), true);
-		code_display = new RKCommandEditorWindow (0, QUrl (), QString (), true, false);
+		code_display = new RKCommandEditorWindow (0, QUrl (), QString (), RKCommandEditorFlags::DefaultToRHighlighting);
 		code_display->setReadOnly (true);
 		code_display_visibility.setBoolValue (!enslaved && RKSettingsModulePlugins::showCodeByDefault ());
 		code_display->setParent (area);  // hm, mysterious breakage when adding via constructor. Whatever...
diff --git a/rkward/rkward.cpp b/rkward/rkward.cpp
index bdfe9249..e95d321f 100644
--- a/rkward/rkward.cpp
+++ b/rkward/rkward.cpp
@@ -157,6 +157,7 @@ RKWardMainWindow::RKWardMainWindow () : KParts::MainWindow ((QWidget *)0, (Qt::W
 	insertChildClient (katePluginIntegration ()->mainWindow ());
 	createShellGUI (true);
 	katePluginIntegration ()->loadPlugin ("katesearchplugin");
+	katePluginIntegration ()->loadPlugin ("kateprojectplugin");
 	katePluginIntegration ()->loadPlugin ("katesnippetsplugin");
 	RKXMLGUISyncer::self ()->watchXMLGUIClientUIrc (this);
 
@@ -955,7 +956,7 @@ void RKWardMainWindow::addScriptUrl (const QUrl &url) {
 void RKWardMainWindow::slotOpenCommandEditor (const QUrl &url, const QString &encoding) {
 	RK_TRACE (APP);
 
-	RKWorkplace::mainWorkplace ()->openScriptEditor (url, encoding, url.isEmpty() || RKSettingsModuleCommandEditor::matchesScriptFileFilter (url.fileName()));
+	RKWorkplace::mainWorkplace ()->openScriptEditor (url, encoding);
 }
 
 void RKWardMainWindow::slotOpenCommandEditor () {
diff --git a/rkward/windows/katepluginintegration.cpp b/rkward/windows/katepluginintegration.cpp
index be7dd1a8..79f73179 100644
--- a/rkward/windows/katepluginintegration.cpp
+++ b/rkward/windows/katepluginintegration.cpp
@@ -389,7 +389,7 @@ KTextEditor::View *KatePluginIntegrationWindow::activateView(KTextEditor::Docume
 
 KTextEditor::View *KatePluginIntegrationWindow::openUrl(const QUrl &url, const QString &encoding) {
 	RK_TRACE (APP);
-	RKMDIWindow *w = RKWorkplace::mainWorkplace()->openScriptEditor(url, encoding, RKSettingsModuleCommandEditor::matchesScriptFileFilter(url.fileName()));
+	RKMDIWindow *w = RKWorkplace::mainWorkplace()->openScriptEditor(url, encoding);
 	if (w) return static_cast<RKCommandEditorWindow*>(w)->getView();
 
 	RK_ASSERT(w);  // should not happen
@@ -513,7 +513,12 @@ void KatePluginIntegrationWindow::catchXMLGUIClientsHack(KXMLGUIClient* client)
 }
 
 // TODO: Don't forget to make sure to emit all the signals!
+//       - MainWindow signals
+//       - pluginDeleted
 // TODO: Apply plugin specific hacks as needed (e.g. moving "Tool" menu, removing broken actions)
+// TODO: new RKToplevelWindowGUI should be called after all plugins are loaded (and have registered their tool views). However
+//       that may be a problem, if there is no KXMLGUIFactory around, yet. So, annoyingly, we need to create the GUI, before we
+//       have everything to populate it.
 
 ///  END  KTextEditor::MainWindow interface
 
diff --git a/rkward/windows/rkcallstackviewer.cpp b/rkward/windows/rkcallstackviewer.cpp
index 1a09c169..17e520ad 100644
--- a/rkward/windows/rkcallstackviewer.cpp
+++ b/rkward/windows/rkcallstackviewer.cpp
@@ -110,7 +110,7 @@ RKCallstackViewerWidget::RKCallstackViewerWidget (QWidget *parent) : QWidget (pa
 	frame_info->setWordWrap (true);
 	v_layout->addWidget (frame_info);
 
-	frame_source = new RKCommandEditorWindow (this, QUrl (), QString (), true);
+	frame_source = new RKCommandEditorWindow (this, QUrl (), QString (), RKCommandEditorFlags::DefaultToRHighlighting | RKCommandEditorFlags::ReadOnly);
 	v_layout->addWidget (frame_source);
 
 	updateState ();
diff --git a/rkward/windows/rkcommandeditorwindow.cpp b/rkward/windows/rkcommandeditorwindow.cpp
index bfadd885..d225569d 100644
--- a/rkward/windows/rkcommandeditorwindow.cpp
+++ b/rkward/windows/rkcommandeditorwindow.cpp
@@ -2,7 +2,7 @@
                           rkcommandeditorwindow  -  description
                              -------------------
     begin                : Mon Aug 30 2004
-    copyright            : (C) 2004-2019 by Thomas Friedrichsmeier
+    copyright            : (C) 2004-2020 by Thomas Friedrichsmeier
     email                : thomas.friedrichsmeier at kdemail.net
  ***************************************************************************/
 
@@ -21,6 +21,7 @@
 #include <ktexteditor/editor.h>
 #include <ktexteditor/modificationinterface.h>
 #include <ktexteditor/markinterface.h>
+#include <KTextEditor/Application>
 
 #include <qapplication.h>
 #include <qfile.h>
@@ -88,7 +89,19 @@ RKCommandEditorWindowPart::~RKCommandEditorWindowPart () {
 //static
 QMap<QString, KTextEditor::Document*> RKCommandEditorWindow::unnamed_documents;
 
-RKCommandEditorWindow::RKCommandEditorWindow (QWidget *parent, const QUrl _url, const QString& encoding, bool use_r_highlighting, bool use_codehinting, bool read_only, bool delete_on_close) : RKMDIWindow (parent, RKMDIWindow::CommandEditorWindow) {
+KTextEditor::Document* createDocument(bool with_signals) {
+	if (with_signals) {
+		emit KTextEditor::Editor::instance()->application()->aboutToCreateDocuments();
+	}
+	KTextEditor::Document* ret = KTextEditor::Editor::instance()->createDocument (RKWardMainWindow::getMain ());
+	if (with_signals) {
+		emit KTextEditor::Editor::instance()->application()->documentCreated(ret);
+		emit KTextEditor::Editor::instance()->application()->documentsCreated(QList<KTextEditor::Document*>() << ret);
+	}
+	return ret;
+}
+
+RKCommandEditorWindow::RKCommandEditorWindow (QWidget *parent, const QUrl _url, const QString& encoding, int flags) : RKMDIWindow (parent, RKMDIWindow::CommandEditorWindow) {
 	RK_TRACE (COMMANDEDITOR);
 
 	QString id_header = QStringLiteral ("unnamedscript://");
@@ -99,10 +112,12 @@ RKCommandEditorWindow::RKCommandEditorWindow (QWidget *parent, const QUrl _url,
 	QUrl url = _url;
 	m_doc = 0;
 	preview_dir = 0;
+	visible_to_kateplugins = flags & VisibleToKTextEditorPlugins;
+	bool use_r_highlighting = (flags & ForceRHighlighting) || (url.isEmpty() && (flags & DefaultToRHighlighting)) || RKSettingsModuleCommandEditor::matchesScriptFileFilter (url.fileName ());
 
 	// Lookup of existing text editor documents: First, if no url is given at all, create a new document, and register an id, in case this window will get split, later
 	if (url.isEmpty ()) {
-		m_doc = editor->createDocument (RKWardMainWindow::getMain ());
+		m_doc = createDocument (visible_to_kateplugins);
 		_id = id_header + KRandom::randomString (16).toLower ();
 		RK_ASSERT (!unnamed_documents.contains (_id));
 		unnamed_documents.insert (_id, m_doc);
@@ -111,7 +126,7 @@ RKCommandEditorWindow::RKCommandEditorWindow (QWidget *parent, const QUrl _url,
 		m_doc = unnamed_documents.value (_id);
 		url.clear ();
 		if (!m_doc) {  // can happen while restoring saved workplace.
-			m_doc = editor->createDocument (RKWardMainWindow::getMain ());
+			m_doc = createDocument (visible_to_kateplugins);
 			unnamed_documents.insert (_id, m_doc);
 		}
 	} else {   // regular url given. Try to find an existing document for that url
@@ -126,7 +141,7 @@ RKCommandEditorWindow::RKCommandEditorWindow (QWidget *parent, const QUrl _url,
 		}
 	}
 
-	// if an existing document is re-used, try to honor decoding.
+	// if an existing document is re-used, try to honor encoding.
 	if (m_doc) {
 		if (!encoding.isEmpty () && (m_doc->encoding () != encoding)) {
 			m_doc->setEncoding (encoding);
@@ -136,14 +151,14 @@ RKCommandEditorWindow::RKCommandEditorWindow (QWidget *parent, const QUrl _url,
 
 	// no existing document was found, so create one and load the url
 	if (!m_doc) {
-		m_doc = editor->createDocument (RKWardMainWindow::getMain ()); // The document may have to outlive this window
+		m_doc = createDocument (visible_to_kateplugins); // The document may have to outlive this window
 
 		// encoding must be set *before* loading the file
 		if (!encoding.isEmpty ()) m_doc->setEncoding (encoding);
 		if (!url.isEmpty ()) {
 			if (m_doc->openUrl (url)) {
 				// KF5 TODO: Check which parts of this are still needed in KF5, and which no longer work
-				if (!delete_on_close) {	// don't litter config with temporary files
+				if (!(flags & DeleteOnClose)) {	// don't litter config with temporary files
 					QString p_url = RKWorkplace::mainWorkplace ()->portableUrl (m_doc->url ());
 					KConfigGroup conf (RKWorkplace::mainWorkplace ()->workspaceConfig (), QString ("SkriptDocumentSettings %1").arg (p_url));
 					// HACK: Hmm. KTextEditor::Document's readSessionConfig() simply restores too much. Yes, I want to load bookmarks and stuff.
@@ -162,10 +177,10 @@ RKCommandEditorWindow::RKCommandEditorWindow (QWidget *parent, const QUrl _url,
 		}
 	}
 
-	setReadOnly (read_only);
+	setReadOnly (flags & ReadOnly);
 
-	if (delete_on_close) {
-		if (read_only) {
+	if (flags & DeleteOnClose) {
+		if (flags & ReadOnly) {
 			RKCommandEditorWindow::delete_on_close = url;
 		} else {
 			RK_ASSERT (false);
@@ -227,7 +242,7 @@ RKCommandEditorWindow::RKCommandEditorWindow (QWidget *parent, const QUrl _url,
 	hinter = 0;
 	if (use_r_highlighting) {
 		RKCommandHighlighter::setHighlighting (m_doc, RKCommandHighlighter::RScript);
-		if (use_codehinting) {
+		if (flags & UseCodeHinting) {
 			new RKCompletionManager (m_view);
 			//hinter = new RKFunctionArgHinter (this, m_view);
 		}
@@ -263,7 +278,15 @@ RKCommandEditorWindow::~RKCommandEditorWindow () {
 	delete m_view;
 	QList<KTextEditor::View*> views = m_doc->views ();
 	if (views.isEmpty ()) {
+		if (visible_to_kateplugins) {
+			emit KTextEditor::Editor::instance()->application()->documentWillBeDeleted(m_doc);
+			emit KTextEditor::Editor::instance()->application()->aboutToDeleteDocuments(QList<KTextEditor::Document*>() << m_doc);
+		}
 		delete m_doc;
+		if (visible_to_kateplugins) {
+			emit KTextEditor::Editor::instance()->application()->documentDeleted(m_doc);
+			emit KTextEditor::Editor::instance()->application()->documentsDeleted(QList<KTextEditor::Document*>() << m_doc);
+		}
 		if (!delete_on_close.isEmpty ()) KIO::del (delete_on_close)->start ();
 		unnamed_documents.remove (_id);
 	}
diff --git a/rkward/windows/rkcommandeditorwindow.h b/rkward/windows/rkcommandeditorwindow.h
index 5abc2cfa..21876b55 100644
--- a/rkward/windows/rkcommandeditorwindow.h
+++ b/rkward/windows/rkcommandeditorwindow.h
@@ -29,7 +29,8 @@
 
 #include <QUrl>
 
-#include "../windows/rkmdiwindow.h"
+#include "rkmdiwindow.h"
+#include "rkworkplace.h"
 
 class QEvent;
 class QCloseEvent;
@@ -119,10 +120,8 @@ class RKCommandEditorWindow : public RKMDIWindow, public RKScriptContextProvider
 public:
 /** constructor
 @param encoding encoding to use. If QString (), the default encoding is used.
- at param read_only Open the file in read-only mode
- at param delete_on_close File should be deleted when closing the window. Only respected with read_only=true.
- at param use_r_highlighting Initialize the view to use R syntax highlighting. Use, if you're going to edit an R syntax file */
-	explicit RKCommandEditorWindow (QWidget *parent, const QUrl url, const QString& encoding=QString (), bool use_r_highlighting=true, bool use_codehinting=true, bool read_only=false, bool delete_on_close=false);
+ at param flags @See Combination of RKCommandEditorFlags */
+	explicit RKCommandEditorWindow (QWidget *parent, const QUrl url, const QString& encoding=QString (), int flags=RKCommandEditorFlags::DefaultFlags);
 /** destructor */
 	~RKCommandEditorWindow ();
 /** returns, whether the document was modified since the last save */
@@ -251,6 +250,7 @@ private:
 	QTimer autosave_timer;
 
 	QUrl delete_on_close;
+	bool visible_to_kateplugins;
 
 	QString _id;
 	static QMap<QString, KTextEditor::Document*> unnamed_documents;
diff --git a/rkward/windows/rkworkplace.cpp b/rkward/windows/rkworkplace.cpp
index 03565519..228ef0e6 100644
--- a/rkward/windows/rkworkplace.cpp
+++ b/rkward/windows/rkworkplace.cpp
@@ -421,7 +421,7 @@ bool RKWorkplace::openAnyUrl (const QUrl &url, const QString &known_mimetype, bo
 			return true;	// TODO
 		}
 		if (mimetype.inherits ("text/plain")) {
-			return (openScriptEditor (url, QString (), RKSettingsModuleCommandEditor::matchesScriptFileFilter (url.fileName())));
+			return (openScriptEditor (url, QString ()));
 		}
 		RK_DEBUG (APP, DL_INFO, "Don't know how to handle mimetype %s.", qPrintable (mimetype.name ()));
 	}
@@ -434,7 +434,7 @@ bool RKWorkplace::openAnyUrl (const QUrl &url, const QString &known_mimetype, bo
 	return false;
 }
 
-RKMDIWindow* RKWorkplace::openScriptEditor (const QUrl &url, const QString& encoding, bool use_r_highlighting, bool read_only, const QString &force_caption, bool delete_on_close) {
+RKMDIWindow* RKWorkplace::openScriptEditor (const QUrl &url, const QString& encoding, int flags, const QString &force_caption) {
 	RK_TRACE (APP);
 
 // is this url already opened?
@@ -451,7 +451,7 @@ RKMDIWindow* RKWorkplace::openScriptEditor (const QUrl &url, const QString& enco
 		}
 	}
 
-	RKCommandEditorWindow *editor = new RKCommandEditorWindow (view (), url, encoding, use_r_highlighting, use_r_highlighting, read_only, delete_on_close);
+	RKCommandEditorWindow *editor = new RKCommandEditorWindow (view (), url, encoding, flags);
 
 	if (!force_caption.isEmpty ()) editor->setCaption (force_caption);
 	addWindow (editor);
@@ -853,7 +853,7 @@ RKMDIWindow* restoreDocumentWindowInternal (RKWorkplace* wp, ItemSpecification s
 		if (object) win = wp->editObject (object);
 	} else if (spec.type == "script") {
 		QUrl url = checkAdjustRestoredUrl (spec.specification, base);
-		win = wp->openScriptEditor (url, QString (), RKSettingsModuleCommandEditor::matchesScriptFileFilter (url.fileName()));
+		win = wp->openScriptEditor (url, QString ());
 	} else if (spec.type == "output") {
 		win = wp->openOutputWindow (checkAdjustRestoredUrl (spec.specification, base));
 	} else if (spec.type == "help") {
@@ -964,7 +964,7 @@ void RKWorkplace::splitAndAttachWindow (RKMDIWindow* source) {
 
 	if (source->isType (RKMDIWindow::CommandEditorWindow)) {
 		QUrl url = static_cast<RKCommandEditorWindow*> (source)->url ();
-		openScriptEditor (url, QString (), url.isEmpty () || RKSettingsModuleCommandEditor::matchesScriptFileFilter (url.fileName()));
+		openScriptEditor (url, QString ());
 	} else if (source->isType (RKMDIWindow::HelpWindow)) {
 		openHelpWindow (static_cast<RKHTMLWindow*> (source)->url ());
 	} else if (source->isType (RKMDIWindow::OutputWindow)) {
diff --git a/rkward/windows/rkworkplace.h b/rkward/windows/rkworkplace.h
index bb73c773..c77700f8 100644
--- a/rkward/windows/rkworkplace.h
+++ b/rkward/windows/rkworkplace.h
@@ -68,6 +68,18 @@ private:
 	RKMDIWindowHistoryWidget *getSwitcher (QAction *prev_action, QAction *next_action);
 };
 
+/** Or'able enum of flags to pass the RKCommandEditorWindow c'tor. Logically, these would belong to the RKCommandEditor-class,
+    but are defined, here for technical reasons (trouble including texteditor includes from some places). */
+enum RKCommandEditorFlags {
+	DefaultToRHighlighting = 1, ///< Apply R highlighting, also if the url is empty
+	ForceRHighlighting = 1 << 1,///< Apply R highlighting, even if the url does not match R script extension
+	UseCodeHinting = 1 << 2,    ///< The file is (probably) an editable R script file, and should show code hints
+	ReadOnly = 1 << 3,          ///< Open the file in read-only mode
+	DeleteOnClose = 1 << 4,     ///< The file to show should be deleted when closing the window. Only respected with read_only=true
+	VisibleToKTextEditorPlugins = 1 << 5,
+	DefaultFlags = DefaultToRHighlighting | UseCodeHinting | VisibleToKTextEditorPlugins
+};
+
 /** This class (only one instance will probably be around) keeps track of which windows are opened in the workplace, which are detached, etc. Also it is responsible for creating and manipulating those windows.
 It also provides a QWidget (RKWorkplace::view ()), which actually manages the document windows (only those, so far. I.e. this is a half-replacement for KMdi, which will be gone in KDE 4). Currently layout of the document windows is always tabbed. */
 class RKWorkplace : public QWidget {
@@ -106,7 +118,7 @@ public:
 @param read_only Open the document read only? Default is false, i.e. Read-write
 @param force_caption Usually the caption is determined from the url of the file. If you specify a non-empty string here, that is used instead.
 @returns false if a local url could not be opened, true for all remote urls, and on success */
-	RKMDIWindow* openScriptEditor (const QUrl &url=QUrl (), const QString& encoding=QString (), bool use_r_highlighting=true, bool read_only=false, const QString &force_caption = QString (), bool delete_on_close=false);
+	RKMDIWindow* openScriptEditor (const QUrl &url=QUrl (), const QString& encoding=QString (), int flags = RKCommandEditorFlags::DefaultFlags, const QString &force_caption = QString ());
 /** Opens a new help window, starting at the given url
 @param url URL to open
 @param only_once if true, checks whether any help window already shows this URL. If so, raise it, but do not open a new window. Else show the new window */



More information about the rkward-tracker mailing list