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

tfry at users.sourceforge.net tfry at users.sourceforge.net
Wed Jan 26 18:19:34 UTC 2011


Revision: 3393
          http://rkward.svn.sourceforge.net/rkward/?rev=3393&view=rev
Author:   tfry
Date:     2011-01-26 18:19:34 +0000 (Wed, 26 Jan 2011)

Log Message:
-----------
Now that '--restore' is no longer the default, provide an option to re-enable the old behavior.

Modified Paths:
--------------
    trunk/rkward/ChangeLog
    trunk/rkward/rkward/dialogs/startupdialog.cpp
    trunk/rkward/rkward/dialogs/startupdialog.h
    trunk/rkward/rkward/rkward.cpp
    trunk/rkward/rkward/settings/rksettingsmodulegeneral.cpp

Modified: trunk/rkward/ChangeLog
===================================================================
--- trunk/rkward/ChangeLog	2011-01-26 18:16:31 UTC (rev 3392)
+++ trunk/rkward/ChangeLog	2011-01-26 18:19:34 UTC (rev 3393)
@@ -1,3 +1,4 @@
+- Do not load .RData file from current directory by default (configurable)
 - Fixed: On Windows, a wrong locale for LC_NUMERIC would be applied, resulting in malfunction of pdf() and postscript()
 - Fixed: Did not use system configured background color in data editor
 - Fixed: New columns would be always be added to the right, instead of to the left, in the data editor

Modified: trunk/rkward/rkward/dialogs/startupdialog.cpp
===================================================================
--- trunk/rkward/rkward/dialogs/startupdialog.cpp	2011-01-26 18:16:31 UTC (rev 3392)
+++ trunk/rkward/rkward/dialogs/startupdialog.cpp	2011-01-26 18:19:34 UTC (rev 3393)
@@ -2,7 +2,7 @@
                           startupdialog  -  description
                              -------------------
     begin                : Thu Aug 26 2004
-    copyright            : (C) 2004 by Thomas Friedrichsmeier
+    copyright            : (C) 2004, 2011 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -26,6 +26,7 @@
 #include <qpixmap.h>
 #include <QHBoxLayout>
 #include <QVBoxLayout>
+#include <QFileInfo>
 
 #include <klocale.h>
 #include <kvbox.h>
@@ -53,12 +54,19 @@
 
 	choser = new QButtonGroup (this);
 	QGroupBox* choser_box = new QGroupBox (vbox);
-	QVBoxLayout*choser_layout = new QVBoxLayout(choser_box);
+	QVBoxLayout* choser_layout = new QVBoxLayout(choser_box);
 
 	choser_layout->addWidget (empty_workspace_button = new QRadioButton (i18n ("Start with an empty workspace"), choser_box));
 	choser->addButton (empty_workspace_button);
 	choser_layout->addWidget (empty_table_button = new QRadioButton (i18n ("Start with an empty table"), choser_box));
 	choser->addButton (empty_table_button);
+	KUrl rdata_file = getRestoreFile ();
+	choser_layout->addWidget (restore_workspace_button = new QRadioButton (choser_box));
+	choser->addButton (restore_workspace_button);
+	if (rdata_file.isEmpty ()) {
+		restore_workspace_button->setEnabled (false);
+		restore_workspace_button->setText (i18n ("Load workspace from current directory"));
+	} else restore_workspace_button->setText (i18n ("Load workspace from current directory:\n%1", rdata_file.toLocalFile ()));
 	choser_layout->addWidget (open_button = new QRadioButton (i18n ("Load an existing workspace:"), choser_box));
 	choser->addButton (open_button);
 	connect (open_button, SIGNAL (toggled (bool)), this, SLOT (openButtonSelected (bool)));
@@ -88,6 +96,9 @@
 		result->result = EmptyWorkspace;
 	} else if (empty_table_button->isChecked ()) {
 		result->result = EmptyTable;
+	} else if (restore_workspace_button->isChecked ()) {
+		result->result = RestoreFromWD;
+		result->open_url = getRestoreFile ();
 	} else if (open_button->isChecked ()) {
 		QListWidgetItem *item = file_list->currentItem ();
 		if (item == chose_file_item) {
@@ -157,22 +168,36 @@
 	KDialog::showEvent (event);
 }
 
+// static
+KUrl StartupDialog::getRestoreFile () {
+	RK_TRACE (DIALOGS);
+
+	QFileInfo rdata_file (".RData");
+	if (rdata_file.exists ()) return KUrl::fromLocalFile (rdata_file.absoluteFilePath ());
+
+	return KUrl ();
+}
+
 //static
-StartupDialog::StartupDialogResult *StartupDialog::getStartupAction (QWidget *parent, KRecentFilesAction *recent_files) {
+StartupDialog::StartupDialogResult StartupDialog::getStartupAction (QWidget *parent, KRecentFilesAction *recent_files) {
 	RK_TRACE (DIALOGS);
 
-	StartupDialogResult *result = new StartupDialogResult;
-	result->result = RKSettingsModuleGeneral::startupAction ();
+	StartupDialogResult result;
+	result.result = RKSettingsModuleGeneral::startupAction ();
 
-	if (result->result != NoSavedSetting) {
+	if (result.result == RestoreFromWD) {
+		result.open_url = getRestoreFile ();
+		if (result.open_url.isEmpty ()) result.result = NoSavedSetting;
+	}
+	if (result.result != NoSavedSetting) {
 		return result;
 	}
 
-	StartupDialog *dialog = new StartupDialog (parent, result, recent_files);
+	StartupDialog *dialog = new StartupDialog (parent, &result, recent_files);
 	dialog->exec ();
 	delete dialog;
 	
-	RK_DO (qDebug ("startup-dialog result: %d, url: %s", result->result, result->open_url.fileName ().toLatin1 ().data ()), DIALOGS, DL_DEBUG);
+	RK_DO (qDebug ("startup-dialog result: %d, url: %s", result.result, qPrintable (result.open_url.url ())), DIALOGS, DL_DEBUG);
 	
 	return result;
 }

Modified: trunk/rkward/rkward/dialogs/startupdialog.h
===================================================================
--- trunk/rkward/rkward/dialogs/startupdialog.h	2011-01-26 18:16:31 UTC (rev 3392)
+++ trunk/rkward/rkward/dialogs/startupdialog.h	2011-01-26 18:19:34 UTC (rev 3393)
@@ -2,7 +2,7 @@
                           startupdialog  -  description
                              -------------------
     begin                : Thu Aug 26 2004
-    copyright            : (C) 2004 by Thomas Friedrichsmeier
+    copyright            : (C) 2004, 2011 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -38,11 +38,12 @@
 public:
 	/** enum to hold result of StartupDialog. WARNING: do not change the numeric values! They are saved as user settings in the config (@see RKSettingsModuleGeneral). */
 	enum Result {
-		EmptyWorkspace=0,	/**< start with an empty workspace */
+		EmptyWorkspace=0,			/**< start with an empty workspace */
 		EmptyTable=1,				/**< start with an empty table */
 		ChoseFile=2,				/**< chose file to open */
-		NoSavedSetting=3,		/**< not acutally returned as a result. Used in RKSettingsModuleGeneral. This is saved, if user wants to be asked on every startup */
-		OpenFile=4					/**< open a recent file (already specified) */
+		NoSavedSetting=3,			/**< not acutally returned as a result. Used in RKSettingsModuleGeneral. This is saved, if user wants to be asked on every startup */
+		OpenFile=4,					/**< open a recent file (already specified) */
+		RestoreFromWD=5				/**< load workspace from current directory, if available (R option --restore). */
 	};
 	struct StartupDialogResult {
 		Result result;
@@ -53,7 +54,8 @@
 
 	~StartupDialog();
 	
-	static StartupDialogResult *getStartupAction (QWidget *parent, KRecentFilesAction *recent_files);
+	static StartupDialogResult getStartupAction (QWidget *parent, KRecentFilesAction *recent_files);
+	static KUrl getRestoreFile ();
 public slots:
 	void accept ();
 	void reject ();
@@ -66,6 +68,7 @@
 private:
 	QRadioButton *empty_workspace_button;
 	QRadioButton *empty_table_button;
+	QRadioButton *restore_workspace_button;
 	QRadioButton *open_button;
 	QCheckBox *remember_box;
 	

Modified: trunk/rkward/rkward/rkward.cpp
===================================================================
--- trunk/rkward/rkward/rkward.cpp	2011-01-26 18:16:31 UTC (rev 3392)
+++ trunk/rkward/rkward/rkward.cpp	2011-01-26 18:19:34 UTC (rev 3393)
@@ -2,7 +2,7 @@
                           rkward.cpp  -  description
                              -------------------
     begin                : Tue Oct 29 20:06:08 CET 2002
-    copyright            : (C) 2002, 2005, 2006, 2007, 2008, 2009, 2010 by Thomas Friedrichsmeier 
+    copyright            : (C) 2002, 2005, 2006, 2007, 2008, 2009, 2011 by Thomas Friedrichsmeier 
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -235,20 +235,23 @@
 	setUpdatesEnabled (true);
 	show ();
 
-	if (!open_url.isEmpty()) {
-		openWorkspace (open_url);
-	} else {
-		StartupDialog::StartupDialogResult *result = StartupDialog::getStartupAction (this, fileOpenRecentWorkspace);
-		if (result->result == StartupDialog::EmptyWorkspace) {
-		} else if (result->result == StartupDialog::OpenFile) {
-			openWorkspace (result->open_url);
-		} else if (result->result == StartupDialog::ChoseFile) {
-			slotFileOpenWorkspace ();
-		} else if (result->result == StartupDialog::EmptyTable) {
-			RKWorkplace::mainWorkplace ()->editNewDataFrame (i18n ("my.data"));
+//	bool recovered = RKRecoverDialog::checkRecoverCrashedWorkspace ();
+//	if (!recovered) {
+		if (!open_url.isEmpty()) {
+			openWorkspace (open_url);
+		} else {
+			StartupDialog::StartupDialogResult result = StartupDialog::getStartupAction (this, fileOpenRecentWorkspace);
+			if (!result.open_url.isEmpty ()) {
+				openWorkspace (result.open_url);
+			} else {
+				if (result.result == StartupDialog::ChoseFile) {
+					slotFileOpenWorkspace ();
+				} else if (result.result == StartupDialog::EmptyTable) {
+					RKWorkplace::mainWorkplace ()->editNewDataFrame (i18n ("my.data"));
+				}
+			}
 		}
-		delete result;
-	}
+//	}
 
 	if (RKSettingsModuleGeneral::workplaceSaveMode () == RKSettingsModuleGeneral::SaveWorkplaceWithSession) {
 		RKWorkplace::mainWorkplace ()->restoreWorkplace (RKSettingsModuleGeneral::getSavedWorkplace (KGlobal::config ().data ()));

Modified: trunk/rkward/rkward/settings/rksettingsmodulegeneral.cpp
===================================================================
--- trunk/rkward/rkward/settings/rksettingsmodulegeneral.cpp	2011-01-26 18:16:31 UTC (rev 3392)
+++ trunk/rkward/rkward/settings/rksettingsmodulegeneral.cpp	2011-01-26 18:19:34 UTC (rev 3393)
@@ -2,7 +2,7 @@
                           rksettingsmodulegeneral  -  description
                              -------------------
     begin                : Fri Jul 30 2004
-    copyright            : (C) 2004, 2007, 2008, 2010 by Thomas Friedrichsmeier
+    copyright            : (C) 2004, 2007, 2008, 2011 by Thomas Friedrichsmeier
     email                : tfry at users.sourceforge.net
  ***************************************************************************/
 
@@ -64,11 +64,12 @@
 	main_vbox->addWidget (new QLabel (i18n ("Startup Action (*)"), this));
 	startup_action_choser = new QComboBox (this);
 	startup_action_choser->setEditable (false);
-	startup_action_choser->insertItem (StartupDialog::EmptyWorkspace, i18n ("Start with an empty workspace"));
-	startup_action_choser->insertItem (StartupDialog::EmptyTable, i18n ("Start with an empty table"));
-	startup_action_choser->insertItem (StartupDialog::ChoseFile, i18n ("Ask for a file to open"));
-	startup_action_choser->insertItem (StartupDialog::NoSavedSetting, i18n ("Show selection dialog (default)"));
-	startup_action_choser->setCurrentIndex (startup_action);
+	startup_action_choser->addItem (i18n ("Start with an empty workspace"), (int) StartupDialog::EmptyWorkspace);
+	startup_action_choser->addItem (i18n ("Load .RData-file from current directory, if available (R option '--restore')"), (int) StartupDialog::RestoreFromWD);
+	startup_action_choser->addItem (i18n ("Start with an empty table"), (int) StartupDialog::EmptyTable);
+	startup_action_choser->addItem (i18n ("Ask for a file to open"), (int) StartupDialog::ChoseFile);
+	startup_action_choser->addItem (i18n ("Show selection dialog (default)"), (int) StartupDialog::NoSavedSetting);
+	startup_action_choser->setCurrentIndex (startup_action_choser->findData (startup_action));
 	connect (startup_action_choser, SIGNAL (activated (int)), this, SLOT (boxChanged (int)));
 	main_vbox->addWidget (startup_action_choser);
 
@@ -153,7 +154,7 @@
 void RKSettingsModuleGeneral::applyChanges () {
 	RK_TRACE (SETTINGS);
 	new_files_path = files_choser->getLocation ();
-	startup_action = static_cast<StartupDialog::Result> (startup_action_choser->currentIndex ());
+	startup_action = static_cast<StartupDialog::Result> (startup_action_choser->itemData (startup_action_choser->currentIndex ()).toInt ());
 	show_help_on_startup = show_help_on_startup_box->isChecked ();
 	workplace_save_mode = static_cast<WorkplaceSaveMode> (workplace_save_chooser->checkedId ());
 	warn_size_object_edit = warn_size_object_edit_box->intValue ();


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