[rkward-cvs] SF.net SVN: rkward:[2478] trunk/rkward

tfry at users.sourceforge.net tfry at users.sourceforge.net
Wed May 13 21:39:09 UTC 2009


Revision: 2478
          http://rkward.svn.sourceforge.net/rkward/?rev=2478&view=rev
Author:   tfry
Date:     2009-05-13 21:39:09 +0000 (Wed, 13 May 2009)

Log Message:
-----------
Make file.edit() work again (unfinished)

Modified Paths:
--------------
    trunk/rkward/ChangeLog
    trunk/rkward/rkward/agents/showedittextfileagent.cpp
    trunk/rkward/rkward/rbackend/rembedinternal.cpp
    trunk/rkward/rkward/rbackend/rpackages/rkward/R/public.R

Modified: trunk/rkward/ChangeLog
===================================================================
--- trunk/rkward/ChangeLog	2009-05-13 16:32:13 UTC (rev 2477)
+++ trunk/rkward/ChangeLog	2009-05-13 21:39:09 UTC (rev 2478)
@@ -1,3 +1,4 @@
+- Fixed: Make built-in editor work again for file.edit ()	TODO: set options("editor")
 - (Almost) all plugins now write a header to the output window		TODO: work in progress; which ones should not?
 - Add makeHeaderCode convenience function for use inside plugins	TODO: document
 - Adjust some icons

Modified: trunk/rkward/rkward/agents/showedittextfileagent.cpp
===================================================================
--- trunk/rkward/rkward/agents/showedittextfileagent.cpp	2009-05-13 16:32:13 UTC (rev 2477)
+++ trunk/rkward/rkward/agents/showedittextfileagent.cpp	2009-05-13 21:39:09 UTC (rev 2478)
@@ -2,7 +2,7 @@
                           showedittextfileagent  -  description
                              -------------------
     begin                : Tue Sep 13 2005
-    copyright            : (C) 2005 by Thomas Friedrichsmeier
+    copyright            : (C) 2005, 2009 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -85,7 +85,7 @@
 		for (int n = 0; n < args->int_a; ++n) {
 			message.append (args->chars_a[n]).append (" (\"").append (args->chars_b[n]).append ("\")\n");
 
-			bool ok = RKWorkplace::mainWorkplace ()->openScriptEditor (KUrl (args->chars_a[n]), false, true, QString (*(args->chars_c)));
+			bool ok = RKWorkplace::mainWorkplace ()->openScriptEditor (KUrl::fromPath (args->chars_a[n]), false, true, QString (*(args->chars_c)));
 
 			if (!ok)  {
 				bad_files_list.append ("- ").append (args->chars_a[n]).append (" (\"").append (args->chars_b[n]).append ("\")\n");
@@ -98,7 +98,7 @@
 		for (int n = 0; n < args->int_a; ++n) {
 			message.append (args->chars_a[n]).append (" (\"").append (args->chars_b[n]).append ("\")\n");
 
-			bool ok = RKWorkplace::mainWorkplace ()->openScriptEditor (KUrl (args->chars_a[n]), true, false, QString (args->chars_b[n]));
+			bool ok = RKWorkplace::mainWorkplace ()->openScriptEditor (KUrl::fromPath (args->chars_a[n]), true, false, QString (args->chars_b[n]));
 
 			if (!ok) {
 				bad_files_list.append ("- ").append (args->chars_a[n]).append (" (\"").append (args->chars_b[n]).append ("\")\n");

Modified: trunk/rkward/rkward/rbackend/rembedinternal.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rembedinternal.cpp	2009-05-13 16:32:13 UTC (rev 2477)
+++ trunk/rkward/rkward/rbackend/rembedinternal.cpp	2009-05-13 21:39:09 UTC (rev 2478)
@@ -156,6 +156,7 @@
 #endif
 
 SEXP RKWard_RData_Tag;
+QString *SEXPToStringList (SEXP from_exp, unsigned int *count);
 
 // ############## R Standard callback overrides BEGIN ####################
 #ifdef R_2_7
@@ -354,6 +355,36 @@
 	return (nfile <= 0);
 }
 
+SEXP doEditFiles (SEXP files, SEXP titles, SEXP name) {
+	unsigned int files_count, titles_count, name_count;
+	QString *file_strings = SEXPToStringList (files, &files_count);
+	QString *title_strings = SEXPToStringList (titles, &titles_count);
+	QString *name_strings = SEXPToStringList (name, &name_count);
+
+	RK_ASSERT (name_count <= 1);
+	RK_ASSERT (files_count == titles_count);
+	RK_ASSERT (files_count >= 1);
+
+	files_count = titles_count = qMin (files_count, titles_count);
+
+	char **file_chars = new char*[files_count];
+	char **title_chars = new char*[files_count];
+	for (unsigned int i = 0; i < files_count; ++i) {
+		file_chars[i] = file_strings[i].toLocal8Bit ().data ();
+		title_chars[i] = title_strings[i].toLocal8Bit ().data ();
+	}
+	char *name_char;
+	if (name_count > 0) name_char = name_strings[0].toLocal8Bit ().data ();
+	else {
+		name_char = new char[1];
+		name_char[0] = '\0';
+	}
+
+	REditFiles (files_count, const_cast<const char**> (file_chars), const_cast<const char**> (title_chars), name_char);
+// TODO: fix memory leak!
+	return (R_NilValue);
+}
+
 #ifdef R_2_7
 int REditFile (const char *buf) {
 #else
@@ -422,6 +453,7 @@
 	ptr_R_CleanUp = RCleanUp;			// unfortunately, it seems, we can't safely cancel quitting anymore, here!
 	ptr_R_ShowFiles = RShowFiles;
 	ptr_R_ChooseFile = RChooseFile;
+// TODO: R devels disabled this for some reason. We set it anyway...
 	ptr_R_EditFile = REditFile;
 //	ptr_R_EditFiles = REditFiles;		// undefined reference
 
@@ -685,7 +717,7 @@
 	unsigned int count;
 	QString *strings = SEXPToStringList (call, &count);
 	QStringList list;
-	for (int i = 0; i < count; ++i) {
+	for (unsigned int i = 0; i < count; ++i) {
 		list.append (strings[i]);
 	}
 	REmbedInternal::this_pointer->handleSubstackCall (list);
@@ -796,6 +828,7 @@
 		{ "rk.update.locale", (DL_FUNC) &doUpdateLocale, 0 },
 		{ "rk.get.structure", (DL_FUNC) &doGetStructure, 4 },
 		{ "rk.copy.no.eval", (DL_FUNC) &doCopyNoEval, 3 },
+		{ "rk.edit.files", (DL_FUNC) &doEditFiles, 3 },
 		{ 0, 0, 0 }
 	};
 	R_registerRoutines (info, NULL, callMethods, NULL, NULL);

Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/R/public.R
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/R/public.R	2009-05-13 16:32:13 UTC (rev 2477)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/R/public.R	2009-05-13 21:39:09 UTC (rev 2478)
@@ -304,3 +304,18 @@
 
 	x
 }
+
+"rk.edit.files" <- function (file = file, title = file, name = NULL)
+{
+	if (!is.character (file)) {
+		nfile = tempfile()
+		env = environment (file)
+		dput (file, file=nfile)
+		file = nfile
+		.Call("rk.edit.files", file, title, name)
+		x <- dget (file)
+		environment (x) <- env
+		return (x)
+	}
+	.Call ("rk.edit.files", file, title, name)
+}


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the rkward-tracker mailing list