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

tfry at users.sourceforge.net tfry at users.sourceforge.net
Wed Jun 10 19:46:25 UTC 2009


Revision: 2527
          http://rkward.svn.sourceforge.net/rkward/?rev=2527&view=rev
Author:   tfry
Date:     2009-06-10 19:46:25 +0000 (Wed, 10 Jun 2009)

Log Message:
-----------
Make file.edit and file.show work on windows
Implement askyesnocancel-dialog

Modified Paths:
--------------
    trunk/rkward/rkward/agents/showedittextfileagent.cpp
    trunk/rkward/rkward/rbackend/rembedinternal.cpp
    trunk/rkward/rkward/rbackend/rinterface.cpp
    trunk/rkward/rkward/rbackend/rpackages/rkward/R/public.R
    trunk/rkward/rkward/settings/rksettingsmodulephp.cpp
    trunk/rkward/rkward/settings/rksettingsmoduler.cpp
    trunk/rkward/rkward/settings/rksettingsmoduler.h

Modified: trunk/rkward/rkward/agents/showedittextfileagent.cpp
===================================================================
--- trunk/rkward/rkward/agents/showedittextfileagent.cpp	2009-06-10 19:44:12 UTC (rev 2526)
+++ trunk/rkward/rkward/agents/showedittextfileagent.cpp	2009-06-10 19:46:25 UTC (rev 2527)
@@ -79,40 +79,42 @@
 
 	QStringList files = args->params["files"].toStringList ();
 	QStringList titles = args->params["titles"].toStringList ();
+	QString wtitle = args->params["wtitle"].toString ();
 	int count = files.count ();
 	RK_ASSERT (titles.count () == count);
 
 	QString bad_files_list;
+	bool r_highlighting = false;
+	bool read_only = true;
 	if (args->type == RCallbackArgs::RShowFiles) {
-
 		caption = i18n ("Showing file(s)");
 		message = i18n ("A command running in the R-engine wants you to see one or more file(s). RKWard can not determine, whether it is safe to continue processing R commands, before you have read the file(s) in question.") + message_snip1 + message_snip2;
-
-		for (int n = 0; n < count; ++n) {
-			message.append (files[n]).append (" (\"").append (titles[n]).append ("\")\n");
-
-			bool ok = RKWorkplace::mainWorkplace ()->openScriptEditor (KUrl::fromPath (files[n]), false, true, args->params["wtitle"].toString ());
-
-			if (!ok)  {
-				bad_files_list.append ("- ").append (files[n]).append (" (\"").append (titles[n]).append ("\")\n");
-			}
-		}
 	} else if (args->type == RCallbackArgs::REditFiles) {
 		caption = i18n ("Edit file(s)");
 		message = i18n ("A command running in the R-engine wants you to edit one or more file(s). RKWard can not determine, whether it is safe to continue processing R commands, before you have read/edited (and saved) the file(s) in question.") + message_snip1 + message_snip2;
 
-		for (int n = 0; n < count; ++n) {
-			message.append (files[n]).append (" (\"").append (titles[n]).append ("\")\n");
+		r_highlighting = true;
+		read_only = false;
+	}
 
-			bool ok = RKWorkplace::mainWorkplace ()->openScriptEditor (KUrl::fromPath (files[n]), true, false, QString (titles[n]));
+	for (int n = 0; n < count; ++n) {
+		QString title;
+		if (!titles[n].isEmpty ()) title = titles[n];
+		else if (count > 1) title = files[n];
+		if (!wtitle.isEmpty ()) {
+			if (!title.isEmpty ()) title.prepend (": ");
+			title.prepend (wtitle);
+		}
 
-			if (!ok) {
-				bad_files_list.append ("- ").append (files[n]).append (" (\"").append (titles[n]).append ("\")\n");
-			}
+		message.append (title + "\n");
+
+		bool ok = RKWorkplace::mainWorkplace ()->openScriptEditor (KUrl::fromLocalFile (files[n]), r_highlighting, read_only, title);
+
+		if (!ok)  {
+			bad_files_list.append ("- ").append (title).append (" (").append (files[n]).append (")\n");
 		}
 	}
 
-
 	if (!bad_files_list.isEmpty ()) {
 		message.append (i18n ("\n\nThe following of the above files were not readable and have not been opened:\n\n"));
 		message.append (bad_files_list);

Modified: trunk/rkward/rkward/rbackend/rembedinternal.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rembedinternal.cpp	2009-06-10 19:44:12 UTC (rev 2526)
+++ trunk/rkward/rkward/rbackend/rembedinternal.cpp	2009-06-10 19:46:25 UTC (rev 2527)
@@ -124,6 +124,7 @@
 
 SEXP RKWard_RData_Tag;
 QString *SEXPToStringList (SEXP from_exp, unsigned int *count);
+int *SEXPToIntArray (SEXP from_exp, unsigned int *count);
 
 // ############## R Standard callback overrides BEGIN ####################
 void RSuicide (const char* message) {
@@ -147,7 +148,6 @@
 }
 
 // TODO: currently used on windows, only!
-#warning implement in rinterface.cpp!
 /* FROM R_ext/RStartup.h: "Return value here is expected to be 1 for Yes, -1 for No and 0 for Cancel:
    symbolic constants in graphapp.h" */
 int RAskYesNoCancel (const char* message) {
@@ -266,21 +266,6 @@
 	return ret;
 }
 
-int RShowFiles (int nfile, const char **file, const char **headers, const char *wtitle, Rboolean del, const char *pager) {
-	RK_TRACE (RBACKEND);
-
-	RCallbackArgs args;
-	args.type = RCallbackArgs::RShowFiles;
-	args.params["files"] = QVariant (charPArrayToQStringList (file, nfile));
-	args.params["titles"] = QVariant (charPArrayToQStringList (headers, nfile));
-	args.params["wtitle"] = QVariant (wtitle);
-	args.params["delete"] = QVariant (del);
-	REmbedInternal::this_pointer->handleStandardCallback (&args);
-
-// default implementation seems to returns 1 on success, 0 on failure. see unix/std-sys.c
-	return 1;
-}
-
 int RChooseFile (int isnew, char *buf, int len) {
 	RK_TRACE (RBACKEND);
 
@@ -297,36 +282,49 @@
 	return (qMin (len - 1, localres.size ()));
 }
 
-void REditFilesHelper (QStringList files, QStringList titles, QString name_or_something) {
+/* There are about one million possible entry points to editing / showing files. We try to cover them all, using the
+following bunch of functions (REditFilesHelper() and doShowEditFiles() are helpers, only) */
+
+void REditFilesHelper (QStringList files, QStringList titles, QString wtitle, RCallbackArgs::RCallbackType edit, bool delete_files) {
 	RK_TRACE (RBACKEND);
 
 	RCallbackArgs args;
-	args.type = RCallbackArgs::REditFiles;
+	if (edit == RCallbackArgs::REditFiles) args.type = RCallbackArgs::REditFiles;
+	else {
+		RK_ASSERT (edit == RCallbackArgs::RShowFiles);
+		args.type = RCallbackArgs::RShowFiles;
+		args.params["delete"] = QVariant (delete_files);
+	}
+	// see ?file.show() for what appears to be the intended meaning of these first three parameters
+	// (which seem to be inconsistently named even in R itself...)
 	args.params["files"] = QVariant (files);
 	args.params["titles"] = QVariant (titles);
-	// and whatever the name_or_something from REditFiles is for...
+	args.params["wtitle"] = QVariant (wtitle);
+
 	REmbedInternal::this_pointer->handleStandardCallback (&args);
 }
 
-int REditFiles (int nfile, const char **file, const char **title, const char *editor) {
+int REditFiles (int nfile, const char **file, const char **title, const char *wtitle) {
 	RK_TRACE (RBACKEND);
 
-	REditFilesHelper (charPArrayToQStringList (file, nfile), charPArrayToQStringList (title, nfile), editor);
+	REditFilesHelper (charPArrayToQStringList (file, nfile), charPArrayToQStringList (title, nfile), wtitle, RCallbackArgs::REditFiles, false);
 
 // default implementation seems to return 1 if nfile <= 0, else 1. No idea, what for. see unix/std-sys.c
 	return (nfile <= 0);
 }
 
-SEXP doEditFiles (SEXP files, SEXP titles, SEXP name) {
+SEXP doShowEditFiles (SEXP files, SEXP titles, SEXP wtitle, SEXP del, RCallbackArgs::RCallbackType edit) {
 	RK_TRACE (RBACKEND);
 
 	// this function would be much shorter, if SEXPToStringList would simply return a QStringList...
-	unsigned int files_count, titles_count, name_count;
+	unsigned int files_count, titles_count, wtitle_count, del_count;
 	QString *file_strings = SEXPToStringList (files, &files_count);
 	QString *title_strings = SEXPToStringList (titles, &titles_count);
-	QString *name_strings = SEXPToStringList (name, &name_count);
+	QString *wtitle_strings = SEXPToStringList (wtitle, &wtitle_count);
+	int *del_bools = SEXPToIntArray (del, &del_count);
 
-	RK_ASSERT (name_count <= 1);
+	RK_ASSERT (wtitle_count <= 1);
+	RK_ASSERT (del_count <= 1);
 	RK_ASSERT (files_count == titles_count);
 	RK_ASSERT (files_count >= 1);
 
@@ -338,18 +336,25 @@
 		files_list.append (file_strings[i]);
 		titles_list.append (title_strings[i]);
 	}
-	QString name_string;
-	if (name_count) name_string = name_strings[0];
+	QString wtitle_string;
+	if (wtitle_count) wtitle_string = wtitle_strings[0];
+	bool del_files = false;
+	if (del_count) del_files = (del_bools[0] != 0);
 
-	REditFilesHelper (files_list, titles_list, name_string);
+	REditFilesHelper (files_list, titles_list, wtitle_string, edit, del_files);
 
 	delete [] file_strings;
 	delete [] title_strings;
-	delete [] name_strings;
+	delete [] wtitle_strings;
+	delete [] del_bools;
 
 	return (R_NilValue);
 }
 
+SEXP doEditFiles (SEXP files, SEXP titles, SEXP wtitle) {
+	return (doShowEditFiles (files, titles, wtitle, R_NilValue, RCallbackArgs::REditFiles));
+}
+
 int REditFile (const char *buf) {
 	RK_TRACE (RBACKEND);
 
@@ -360,6 +365,19 @@
 	return REditFiles (1, const_cast<const char**> (&buf), &title, editor);
 }
 
+SEXP doShowFiles (SEXP files, SEXP titles, SEXP wtitle, SEXP delete_files) {
+	return (doShowEditFiles (files, titles, wtitle, delete_files, RCallbackArgs::RShowFiles));
+}
+
+int RShowFiles (int nfile, const char **file, const char **headers, const char *wtitle, Rboolean del, const char */* pager */) {
+	RK_TRACE (RBACKEND);
+
+	REditFilesHelper (charPArrayToQStringList (file, nfile), charPArrayToQStringList (headers, nfile), QString (wtitle), RCallbackArgs::RShowFiles, (bool) del);
+
+// default implementation seems to returns 1 on success, 0 on failure. see unix/std-sys.c
+	return 1;
+}
+
 void RBusy (int busy) {
 	RK_TRACE (RBACKEND);
 
@@ -783,6 +801,7 @@
 		{ "rk.get.structure", (DL_FUNC) &doGetStructure, 4 },
 		{ "rk.copy.no.eval", (DL_FUNC) &doCopyNoEval, 3 },
 		{ "rk.edit.files", (DL_FUNC) &doEditFiles, 3 },
+		{ "rk.show.files", (DL_FUNC) &doShowFiles, 4 },
 		{ 0, 0, 0 }
 	};
 	R_registerRoutines (R_getEmbeddingDllInfo(), NULL, callMethods, NULL, NULL);

Modified: trunk/rkward/rkward/rbackend/rinterface.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rinterface.cpp	2009-06-10 19:44:12 UTC (rev 2526)
+++ trunk/rkward/rkward/rbackend/rinterface.cpp	2009-06-10 19:46:25 UTC (rev 2527)
@@ -419,7 +419,14 @@
 	RCallbackArgs::RCallbackType type = args->type;
 
 	if (type == RCallbackArgs::RShowMessage) {
-		KMessageBox::information (0, args->params["message"].toString (), i18n ("Message from the R backend"));
+		if (args->params.value ("askync").toBool ()) {
+			int res = KMessageBox::questionYesNoCancel (0, args->params["message"].toString (), i18n ("Question from the R backend"));
+			if (res == KMessageBox::Yes) args->params["result"] = "yes";
+			else if (res == KMessageBox::No) args->params["result"] = "no";
+			// else: cancel
+		} else {
+			KMessageBox::information (0, args->params["message"].toString (), i18n ("Message from the R backend"));
+		}
 	} else if (type == RCallbackArgs::RReadLine) {
 		QString result;
 

Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/R/public.R
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/R/public.R	2009-06-10 19:44:12 UTC (rev 2526)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/R/public.R	2009-06-10 19:46:25 UTC (rev 2527)
@@ -317,11 +317,16 @@
 		environment (x) <- env
 		return (x)
 	}
-	.Call ("rk.edit.files", file, title, name)
+	invisible (.Call ("rk.edit.files", file, title, name))
 }
 
+"rk.show.files" <- function (file = file, title = file, wtitle = NULL, delete=FALSE)
+{
+	invisible (.Call ("rk.show.files", as.character (file), as.character (title), as.character (wtitle), delete))
+}
+
 "rk.show.html" <- function (url) {
-	.rk.do.call ("showHTML", as.character (url));
+	invisible (.rk.do.call ("showHTML", as.character (url)));
 }
 
 "rk.call.plugin" <- function (plugin, ..., submit.mode = c ("manual", "auto", "submit")) {
@@ -347,4 +352,6 @@
 			stop (res$message)
 		}
 	}
+
+	invisible (TRUE)
 }

Modified: trunk/rkward/rkward/settings/rksettingsmodulephp.cpp
===================================================================
--- trunk/rkward/rkward/settings/rksettingsmodulephp.cpp	2009-06-10 19:44:12 UTC (rev 2526)
+++ trunk/rkward/rkward/settings/rksettingsmodulephp.cpp	2009-06-10 19:46:25 UTC (rev 2527)
@@ -2,7 +2,7 @@
                           rksettingsmodulephp  -  description
                              -------------------
     begin                : Wed Jul 28 2004
-    copyright            : (C) 2004 by Thomas Friedrichsmeier
+    copyright            : (C) 2004, 2009 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -89,7 +89,12 @@
 	RK_TRACE (SETTINGS);
 
 	KConfigGroup cg = config->group ("PHP Settings");
+#ifdef Q_WS_WIN
+	// on windows, our best hope is that php is in the path
+	php_bin = cg.readEntry ("PHP binary", "php");
+#else
 	php_bin = cg.readEntry ("PHP binary", "/usr/bin/php");
+#endif
 }
 
 #include "rksettingsmodulephp.moc"

Modified: trunk/rkward/rkward/settings/rksettingsmoduler.cpp
===================================================================
--- trunk/rkward/rkward/settings/rksettingsmoduler.cpp	2009-06-10 19:44:12 UTC (rev 2526)
+++ trunk/rkward/rkward/settings/rksettingsmoduler.cpp	2009-06-10 19:46:25 UTC (rev 2527)
@@ -48,6 +48,7 @@
 bool RKSettingsModuleR::options_checkbounds;
 QString RKSettingsModuleR::options_printcmd;
 QString RKSettingsModuleR::options_editor;
+QString RKSettingsModuleR::options_pager;
 // static constants
 QString RKSettingsModuleR::builtin_editor = "<rkward>";
 
@@ -161,6 +162,17 @@
 	connect (editor_input, SIGNAL (editTextChanged (const QString &)), this, SLOT (textChanged (const QString &)));
 	grid->addWidget (editor_input, row, 1);
 
+	grid->addWidget (new QLabel (i18n ("Pager command"), this), ++row, 0);
+	pager_input = new QComboBox (this);
+	pager_input->setEditable (true);
+	pager_input->addItem (builtin_editor);
+	if (options_pager != builtin_editor) {
+		pager_input->addItem (options_pager);
+		pager_input->setCurrentIndex (1);
+	}
+	connect (pager_input, SIGNAL (editTextChanged (const QString &)), this, SLOT (textChanged (const QString &)));
+	grid->addWidget (pager_input, row, 1);
+
 	main_vbox->addStretch ();
 }
 
@@ -208,6 +220,7 @@
 	options_checkbounds = checkbounds_input->itemData (checkbounds_input->currentIndex ()).toBool ();
 	options_printcmd = printcmd_input->text ();
 	options_editor = editor_input->currentText ();
+	options_pager = pager_input->currentText ();
 
 // apply run time options in R
 	QStringList commands = makeRRunTimeOptionCommands ();
@@ -237,6 +250,8 @@
 	list.append ("options (printcmd=\"" + options_printcmd + "\")\n");
 	if (options_editor == builtin_editor) list.append ("options (editor=rk.edit.files)\n");
 	else list.append ("options (editor=\"" + options_editor + "\")\n");
+	if (options_pager == builtin_editor) list.append ("options (pager=rk.show.files)\n");
+	else list.append ("options (pager=\"" + options_pager + "\")\n");
 
 #warning TODO make the following options configurable
 	list.append ("options (device=\"rk.screen.device\")\n");
@@ -270,6 +285,7 @@
 	cg.writeEntry ("check.bounds", options_checkbounds);
 	cg.writeEntry ("printcmd", options_printcmd);
 	cg.writeEntry ("editor", options_editor);
+	cg.writeEntry ("pager", options_pager);
 }
 
 void RKSettingsModuleR::loadSettings (KConfig *config) {
@@ -288,6 +304,7 @@
 	options_checkbounds = cg.readEntry ("check.bounds", false);
 	options_printcmd = cg.readEntry ("printcmd", "kprinter");
 	options_editor = cg.readEntry ("editor", builtin_editor);
+	options_pager = cg.readEntry ("pager", builtin_editor);
 }
 
 //#################################################

Modified: trunk/rkward/rkward/settings/rksettingsmoduler.h
===================================================================
--- trunk/rkward/rkward/settings/rksettingsmoduler.h	2009-06-10 19:44:12 UTC (rev 2526)
+++ trunk/rkward/rkward/settings/rksettingsmoduler.h	2009-06-10 19:46:25 UTC (rev 2527)
@@ -70,6 +70,7 @@
 	QComboBox *checkbounds_input;
 	QLineEdit *printcmd_input;
 	QComboBox *editor_input;
+	QComboBox *pager_input;
 
 	static QString options_outdec;
 	static int options_width;
@@ -83,6 +84,7 @@
 	static bool options_checkbounds;
 	static QString options_printcmd;
 	static QString options_editor;
+	static QString options_pager;
 
 // constants
 	static QString builtin_editor;


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