[rkward-cvs] [rkward] /: Allow opening any file that matches text/plain.

Thomas Friedrichsmeier thomas.friedrichsmeier at ruhr-uni-bochum.de
Sat Nov 29 12:27:01 UTC 2014


Git commit 655f24dc1d21dd31034e9c1befd8a720e0b2d208 by Thomas Friedrichsmeier.
Committed on 29/11/2014 at 12:25.
Pushed by tfry into branch 'master'.

Allow opening any file that matches text/plain.
Use correct highlighting for .pluginmap, .rkh, and .inc (guessing XML highlighting for the latter).

M  +1    -0    ChangeLog
M  +16   -4    rkward/windows/rkcommandeditorwindow.cpp
M  +3    -2    rkward/windows/rkcommandeditorwindow.h
M  +2    -1    rkward/windows/rkworkplace.cpp

http://commits.kde.org/rkward/655f24dc1d21dd31034e9c1befd8a720e0b2d208

diff --git a/ChangeLog b/ChangeLog
index bdf1735..0226b30 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,4 @@
+- Allow opening RKWard's plugin files (with correct highlighting), and other text files
 - More robust control over placement of plugins within a menu
   - TODO: document, discuss
 - Fix several issues of excessive printing of digits in plugins' output
diff --git a/rkward/windows/rkcommandeditorwindow.cpp b/rkward/windows/rkcommandeditorwindow.cpp
index 524372a..c9c50c9 100644
--- a/rkward/windows/rkcommandeditorwindow.cpp
+++ b/rkward/windows/rkcommandeditorwindow.cpp
@@ -380,7 +380,7 @@ bool RKCommandEditorWindow::openURL (const KUrl url, const QString& encoding, bo
 				/* HACK: What the...?! Somehow, at least on longer R scripts, stored Mode="Normal" in combination with R Highlighting
 				 * causes code folding to fail (KDE 4.8.4, https://sourceforge.net/tracker/?func=detail&atid=459007&aid=3564769&group_id=50231).
 				 * Forcing Mode == Highlighting appears to help. */
-				conf.writeEntry ("Mode", conf.readEntry ("Highlighting", "Normal"));
+				if (use_r_highlighting) conf.writeEntry ("Mode", conf.readEntry ("Highlighting", "Normal"));
 				iface->readSessionConfig (conf);
 			}
 			iface = qobject_cast<KTextEditor::SessionConfigInterface*> (m_view);
@@ -389,8 +389,9 @@ bool RKCommandEditorWindow::openURL (const KUrl url, const QString& encoding, bo
 				iface->readSessionConfig (conf);
 			}
 		}
-
 		if (use_r_highlighting) RKCommandHighlighter::setHighlighting (m_doc, RKCommandHighlighter::RScript);
+		else RKCommandHighlighter::setHighlighting (m_doc, RKCommandHighlighter::Automatic);
+
 		setReadOnly (read_only);
 
 		updateCaption ();
@@ -1255,8 +1256,19 @@ QString RKCommandHighlighter::commandToHTML (const QString r_command, Highlighti
 void RKCommandHighlighter::setHighlighting (KTextEditor::Document *doc, HighlightingMode mode) {
 	RK_TRACE (COMMANDEDITOR);
 
-	QString mode_string = "R Script";
-	if (mode == RInteractiveSession) mode_string = "R interactive session";
+	QString mode_string;
+	if (mode == RScript) mode_string = "R Script";
+	else if (mode == RInteractiveSession) mode_string = "R interactive session";
+	else {
+		QString fn = doc->url ().fileName ().toLower ();
+		if (fn.endsWith (".pluginmap") || fn.endsWith (".rkh") || fn.endsWith (".xml") || fn.endsWith (".inc")) {
+			mode_string = "XML";
+		} else if (fn.endsWith (".js")) {
+			mode_string = "JavaScript";
+		} else {
+			return;
+		}
+	}
 	if (!(doc->setHighlightingMode (mode_string) && doc->setMode (mode_string))) RK_DEBUG (COMMANDEDITOR, DL_ERROR, "R syntax highlighting definition ('%s')not found!", qPrintable (mode_string));
 }
 
diff --git a/rkward/windows/rkcommandeditorwindow.h b/rkward/windows/rkcommandeditorwindow.h
index 3a6d715..22dae82 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-2013 by Thomas Friedrichsmeier
+    copyright            : (C) 2004-2014 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -302,7 +302,8 @@ class RKCommandHighlighter {
 public:
 	enum HighlightingMode {
 		RInteractiveSession,
-		RScript
+		RScript,
+		Automatic
 	};
 	static void copyLinesToOutput (KTextEditor::View *view, HighlightingMode mode);
 	static void setHighlighting (KTextEditor::Document *doc, HighlightingMode mode);
diff --git a/rkward/windows/rkworkplace.cpp b/rkward/windows/rkworkplace.cpp
index a328ea9..8530ad3 100644
--- a/rkward/windows/rkworkplace.cpp
+++ b/rkward/windows/rkworkplace.cpp
@@ -267,9 +267,10 @@ bool RKWorkplace::openAnyUrl (const KUrl &url, const QString &known_mimetype, bo
 			RKWardMainWindow::getMain ()->askOpenWorkspace (url);
 			return true;	// TODO
 		}
-		if (mimetype->name ().startsWith ("text")) {
+		if (mimetype->is ("text/plain")) {
 			return (openScriptEditor (url, QString (), RKSettingsModuleCommandEditor::matchesScriptFileFilter (url.fileName())));
 		}
+		RK_DEBUG (APP, DL_INFO, "Don't know how to handle mimetype %s.", qPrintable (mimetype->name ()));
 	}
 
 	if (KMessageBox::questionYesNo (this, i18n ("The url you are trying to open ('%1') is not a local file or the filetype is not supported by RKWard. Do you want to open the url in the default application?", url.prettyUrl ()), i18n ("Open in default application?")) != KMessageBox::Yes) {




More information about the rkward-tracker mailing list