[rkward-cvs] rkward/rkward/agents showedittextfileagent.cpp,1.1,1.2 showedittextfileagent.h,1.1,1.2

Thomas Friedrichsmeier tfry at users.sourceforge.net
Wed Sep 14 12:06:04 UTC 2005


Update of /cvsroot/rkward/rkward/rkward/agents
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28436/agents

Modified Files:
	showedittextfileagent.cpp showedittextfileagent.h 
Log Message:
Implemented R_EditFile and R_ShowFile. Not pretty yet, but working. Some more code cleanups

Index: showedittextfileagent.h
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/agents/showedittextfileagent.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** showedittextfileagent.h	13 Sep 2005 16:08:34 -0000	1.1
--- showedittextfileagent.h	14 Sep 2005 12:06:01 -0000	1.2
***************
*** 22,25 ****
--- 22,26 ----
  
  struct RCallbackArgs;
+ class ShowEditTextFileDialog;
  
  /** The purpose of this agent is to display text files for showing and/or editing on request of the R backend. Technically speaking, it gets invoked, whenever the standard R callbacks (ptr_)R_ShowFiles, (ptr_)R_EditFiles, or (ptr_)R_EditFile are called. While the task of simply opening such files for display/editing is rather simple, there is one slightly more difficult issue involved (and hence this class to handle it): In standard R, all these calls are blocking further processing, until the user has closed the shown/edited files. In some cases this may be necessary (for instance if R wants to use with the edited files immediately), in some cases this is an unneccessary nuisance (such as when R simply wants to display a help page or some other purely informational text).
***************
*** 34,38 ****
  	Q_OBJECT
  public:
! 	ShowEditTextFileAgent (QObject *parent = 0);
  
  /** destructor */
--- 35,42 ----
  	Q_OBJECT
  public:
! /** constructor. Do not use directly. Use the static showEditFiles () instead.
! @param args The corresponding RCallbackArgs-record
! @param text Text to display in the dialog. */
! 	ShowEditTextFileAgent (RCallbackArgs *args, const QString &text, const QString &caption);
  
  /** destructor */
***************
*** 41,45 ****
  /** This gets called by RInterface, in order to show/edit the files in question. The RCallbackArgs-struct is passed in raw form, and only this function sorts
  out, what exactly needs to be done. Note that this is a static member. It will take care of creating/deleting an agent on its own. */
! 	static showEditFiles (RCallbackArgs *args);
  };
  
--- 45,70 ----
  /** This gets called by RInterface, in order to show/edit the files in question. The RCallbackArgs-struct is passed in raw form, and only this function sorts
  out, what exactly needs to be done. Note that this is a static member. It will take care of creating/deleting an agent on its own. */
! 	static void showEditFiles (RCallbackArgs *args);
! public slots:
! /** this slot gets called, when the user presses the done button (or closes the notification dialog). Resumes processing in the backend, deletes the agent */
! 	void done ();
! private:
! 	RCallbackArgs *args;
! 	ShowEditTextFileDialog *dialog;
! };
! 
! #include <kdialogbase.h>
! 
! /** Mini helper class of ShowEditTextFileAgent. Do not use outside of ShowEditTextFileAgent. 
! 
! TODO: might be renamed / reused as a more generic non-modal information dialog */
! 
! class ShowEditTextFileDialog : public KDialogBase {
! 	public:
! /** constructor
! @param text: Text to display in the dialog */
! 	ShowEditTextFileDialog (const QString &text, const QString &caption);
! /** destructor */
! 	~ShowEditTextFileDialog ();
  };
  

Index: showedittextfileagent.cpp
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/agents/showedittextfileagent.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** showedittextfileagent.cpp	13 Sep 2005 16:08:34 -0000	1.1
--- showedittextfileagent.cpp	14 Sep 2005 12:06:01 -0000	1.2
***************
*** 18,31 ****
  #include "showedittextfileagent.h"
  
! ShowEditTextFileAgent::ShowEditTextFileAgent(QObject *parent, const char *name)
!  : QObject(parent, name)
! {
  }
  
  
! ShowEditTextFileAgent::~ShowEditTextFileAgent()
! {
  }
  
  
  #include "showedittextfileagent.moc"
--- 18,142 ----
  #include "showedittextfileagent.h"
  
! #include <kdialogbase.h>
! #include <klocale.h>
! 
! #include <qlabel.h>
! #include <qlayout.h>
! #include <qfile.h>
! 
! #include "../windows/rkcommandeditorwindow.h"
! #include "../rbackend/rinterface.h"
! #include "../rbackend/rembedinternal.h"
! #include "../rkglobals.h"
! #include "../rkward.h"
! 
! #include "../debug.h"
! 
! ShowEditTextFileAgent::ShowEditTextFileAgent (RCallbackArgs *args, const QString &text, const QString &caption) : QObject (RKGlobals::rkApp ()) {
! 	RK_TRACE (APP);
! 
! 	ShowEditTextFileAgent::args = args;
! 
! 	dialog = new ShowEditTextFileDialog (text, caption);
! 	connect (dialog, SIGNAL (finished ()), this, SLOT (done ()));
! 
! 	dialog->show ();
  }
  
  
! ShowEditTextFileAgent::~ShowEditTextFileAgent () {
! 	RK_TRACE (APP);
  }
  
+ // static
+ void ShowEditTextFileAgent::showEditFiles (RCallbackArgs *args) {
+ 	RK_TRACE (APP);
+ 	if (!args) return;
+ 
+ 	QString caption;
+ 	QString message;
+ 	QString message_snip1 = i18n (" For that reason processing has been stopped for now. Press the \"Done\"-button, or close this dialog once you think it is safe to resume.\n\n");
+ 	QString message_snip2 = i18n ("The file(s) have been opened in text-windows. The following is a list of the file(s) in question:\n\n");
+ 
+ 	QString bad_files_list;
+ 	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 < args->int_a; ++n) {
+ 			message.append (args->chars_a[n]).append (" (\"").append (args->chars_b[n]).append ("\")\n");
+ 
+ 			RKCommandEditorWindow *window = new RKCommandEditorWindow (0, false);
+ 			bool ok = window->openURL (KURL (args->chars_a[n]), false, true);
+ 
+ 			if (ok) {
+ 				if (qstrlen (*(args->chars_c))) window->setTabCaption (*(args->chars_c));
+ 				RKGlobals::rkApp ()->addWindow (window);
+ 			} else {
+ 				delete (window);
+ 				bad_files_list.append ("- ").append (args->chars_a[n]).append (" (\"").append (args->chars_b[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 < args->int_a; ++n) {
+ 			message.append (args->chars_a[n]).append (" (\"").append (args->chars_b[n]).append ("\")\n");
+ 
+ 			RKCommandEditorWindow *window = new RKCommandEditorWindow (0, false);
+ 			bool ok = window->openURL (KURL (args->chars_a[n]), true, false);
+ 
+ 			if (ok) {
+ 				if (qstrlen (args->chars_b[n])) window->setTabCaption (args->chars_b[n]);
+ 				RKGlobals::rkApp ()->addWindow (window);
+ 			} else {
+ 				delete (window);
+ 				bad_files_list.append ("- ").append (args->chars_a[n]).append (" (\"").append (args->chars_b[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);
+ 	}
+ 
+ 	ShowEditTextFileAgent* agent = new ShowEditTextFileAgent (args, message, caption);
+ }
+ 
+ void ShowEditTextFileAgent::done () {
+ 	RK_TRACE (APP);
+ 	delete dialog;
+ 
+ 	// int_c in RShowFiles means files are to be deleted
+ 	if ((args->type == RCallbackArgs::RShowFiles) && args->int_c) {
+ 		for (int n = 0; n < args->int_a; ++n) {
+ 			QFile (QString (args->chars_a[n])).remove ();
+ 		}
+ 	}
+ 
+ 	args->done = true;
+ 
+ 	deleteLater ();
+ }
+ 
+ ///################# END ShowEditTextFileAgent ##################
+ ///################# BEGIN ShowEditTextFileDialog #################
+ 
+ ShowEditTextFileDialog::ShowEditTextFileDialog (const QString &text, const QString &caption) : KDialogBase ((QWidget*) 0, 0, false, caption, KDialogBase::Ok, KDialogBase::Ok) {
+ 	QWidget *page = new QWidget (this);
+ 	setMainWidget (page);
+ 	QVBoxLayout *layout = new QVBoxLayout (page, 0, spacingHint ());
+ 	QLabel *label = new QLabel (text, page);
+ 	label->setAlignment (Qt::WordBreak | Qt::AlignAuto | Qt::AlignVCenter | Qt::ExpandTabs);
+ 	layout->addWidget (label);
+ 
+ 	setButtonOK (KGuiItem (i18n ("Done")));
+ }
+ 
+ ShowEditTextFileDialog::~ShowEditTextFileDialog () {
+ }
  
  #include "showedittextfileagent.moc"





More information about the rkward-tracker mailing list