[rkward-cvs] SF.net SVN: rkward:[3433] trunk/rkward
tfry at users.sourceforge.net
tfry at users.sourceforge.net
Sun Feb 13 12:56:37 UTC 2011
Revision: 3433
http://rkward.svn.sourceforge.net/rkward/?rev=3433&view=rev
Author: tfry
Date: 2011-02-13 12:56:37 +0000 (Sun, 13 Feb 2011)
Log Message:
-----------
Try to be smart about moved workspaces.
First tries to load scripts from their previous absolute path. If they do not exist, there, check whether scripts exist at an adjusted path.
Modified Paths:
--------------
trunk/rkward/ChangeLog
trunk/rkward/rkward/dataeditor/rkeditor.cpp
trunk/rkward/rkward/dataeditor/rkeditor.h
trunk/rkward/rkward/rkward.cpp
trunk/rkward/rkward/windows/rkcommandeditorwindow.cpp
trunk/rkward/rkward/windows/rkcommandeditorwindow.h
trunk/rkward/rkward/windows/rkhtmlwindow.cpp
trunk/rkward/rkward/windows/rkhtmlwindow.h
trunk/rkward/rkward/windows/rkmdiwindow.h
trunk/rkward/rkward/windows/rkwindowcatcher.h
trunk/rkward/rkward/windows/rkworkplace.cpp
trunk/rkward/rkward/windows/rkworkplace.h
Modified: trunk/rkward/ChangeLog
===================================================================
--- trunk/rkward/ChangeLog 2011-02-09 17:52:29 UTC (rev 3432)
+++ trunk/rkward/ChangeLog 2011-02-13 12:56:37 UTC (rev 3433)
@@ -1,4 +1,5 @@
--- Version 0.5.5 - XXX-XX-2011
+- RKWard now tries to detect, when a workspace has been moved to a new directory, and adjust the paths restored script editor windows, accordingly
- Fixed: Potential crashes when changing length of a data.frame that is currently opened for editing from R code
- All pages in the package installation dialog now support sorting and keyboard search
- Fixed: Converting from factor to string in the data editor set values to numeric, internally
Modified: trunk/rkward/rkward/dataeditor/rkeditor.cpp
===================================================================
--- trunk/rkward/rkward/dataeditor/rkeditor.cpp 2011-02-09 17:52:29 UTC (rev 3432)
+++ trunk/rkward/rkward/dataeditor/rkeditor.cpp 2011-02-13 12:56:37 UTC (rev 3433)
@@ -27,11 +27,4 @@
// getObject ()->setObjectOpened (this, false);
}
-QString RKEditor::getDescription () {
- RK_TRACE (EDITOR);
- RK_ASSERT (getObject ());
-
- return ("data:" + getObject ()->getFullName ());
-}
-
#include "rkeditor.moc"
Modified: trunk/rkward/rkward/dataeditor/rkeditor.h
===================================================================
--- trunk/rkward/rkward/dataeditor/rkeditor.h 2011-02-09 17:52:29 UTC (rev 3432)
+++ trunk/rkward/rkward/dataeditor/rkeditor.h 2011-02-13 12:56:37 UTC (rev 3433)
@@ -51,7 +51,6 @@
/** Tells the editor to restore the given object in the R-workspace from its copy of the data */
virtual void restoreObject (RObject *object) = 0;
- QString getDescription ();
bool isModified () { return false; };
protected:
RObject *object;
Modified: trunk/rkward/rkward/rkward.cpp
===================================================================
--- trunk/rkward/rkward/rkward.cpp 2011-02-09 17:52:29 UTC (rev 3432)
+++ trunk/rkward/rkward/rkward.cpp 2011-02-13 12:56:37 UTC (rev 3433)
@@ -255,7 +255,7 @@
}
if (RKSettingsModuleGeneral::workplaceSaveMode () == RKSettingsModuleGeneral::SaveWorkplaceWithSession) {
- RKWorkplace::mainWorkplace ()->restoreWorkplace (RKSettingsModuleGeneral::getSavedWorkplace (KGlobal::config ().data ()));
+ RKWorkplace::mainWorkplace ()->restoreWorkplace (RKSettingsModuleGeneral::getSavedWorkplace (KGlobal::config ().data ()).split ('\n'));
}
if (RKSettingsModuleGeneral::showHelpOnStartup ()) {
@@ -508,7 +508,7 @@
slotSetStatusBarText (i18n ("Exiting..."));
saveOptions ();
if (RKSettingsModuleGeneral::workplaceSaveMode () == RKSettingsModuleGeneral::SaveWorkplaceWithSession) {
- RKSettingsModuleGeneral::setSavedWorkplace (RKWorkplace::mainWorkplace ()->makeWorkplaceDescription ("\n", false), KGlobal::config ().data ());
+ RKSettingsModuleGeneral::setSavedWorkplace (RKWorkplace::mainWorkplace ()->makeWorkplaceDescription ().join ("\n"), KGlobal::config ().data ());
}
// if (!RObjectList::getGlobalEnv ()->isEmpty ()) {
Modified: trunk/rkward/rkward/windows/rkcommandeditorwindow.cpp
===================================================================
--- trunk/rkward/rkward/windows/rkcommandeditorwindow.cpp 2011-02-09 17:52:29 UTC (rev 3432)
+++ trunk/rkward/rkward/windows/rkcommandeditorwindow.cpp 2011-02-13 12:56:37 UTC (rev 3433)
@@ -293,12 +293,6 @@
}
}
-QString RKCommandEditorWindow::getDescription () {
- RK_TRACE (COMMANDEDITOR);
-
- return ("script:" + m_doc->url ().url ());
-}
-
void RKCommandEditorWindow::closeEvent (QCloseEvent *e) {
if (isModified ()) {
int status = KMessageBox::warningYesNo (this, i18n ("The document \"%1\" has been modified. Close it anyway?", windowTitle ()), i18n ("File not saved"));
Modified: trunk/rkward/rkward/windows/rkcommandeditorwindow.h
===================================================================
--- trunk/rkward/rkward/windows/rkcommandeditorwindow.h 2011-02-09 17:52:29 UTC (rev 3432)
+++ trunk/rkward/rkward/windows/rkcommandeditorwindow.h 2011-02-13 12:56:37 UTC (rev 3433)
@@ -154,8 +154,6 @@
/** copy current selection. Wrapper for use by external classes */
void copy ();
- QString getDescription ();
-
/** reimplemented from RKMDIWindow to return full path of file (if any) */
QString fullCaption ();
Modified: trunk/rkward/rkward/windows/rkhtmlwindow.cpp
===================================================================
--- trunk/rkward/rkward/windows/rkhtmlwindow.cpp 2011-02-09 17:52:29 UTC (rev 3432)
+++ trunk/rkward/rkward/windows/rkhtmlwindow.cpp 2011-02-13 12:56:37 UTC (rev 3433)
@@ -97,16 +97,10 @@
RKCommonFunctions::removeContainers (khtmlpart, QString ("tools,security,extraToolBar,saveBackground,saveFrame,printFrame,kget_menu").split (','), true);
}
-QString RKHTMLWindow::getDescription () {
+KUrl RKHTMLWindow::restorableUrl () {
RK_TRACE (APP);
- if (window_mode == HTMLOutputWindow) {
- return ("output:" + current_url.url ());
-
- } else {
- QString fixed_url = current_url.url ().replace (RKSettingsModuleR::helpBaseUrl(), "rkward://RHELPBASE");
- return ("help:" + fixed_url);
- }
+ return (current_url.url ().replace (RKSettingsModuleR::helpBaseUrl(), "rkward://RHELPBASE"));
}
bool RKHTMLWindow::isModified () {
Modified: trunk/rkward/rkward/windows/rkhtmlwindow.h
===================================================================
--- trunk/rkward/rkward/windows/rkhtmlwindow.h 2011-02-09 17:52:29 UTC (rev 3432)
+++ trunk/rkward/rkward/windows/rkhtmlwindow.h 2011-02-13 12:56:37 UTC (rev 3433)
@@ -2,7 +2,7 @@
rkhtmlwindow - description
-------------------
begin : Wed Oct 12 2005
- copyright : (C) 2005, 2006, 2007, 2009 by Thomas Friedrichsmeier
+ copyright : (C) 2005, 2006, 2007, 2009, 2011 by Thomas Friedrichsmeier
email : tfry at users.sourceforge.net
***************************************************************************/
@@ -61,10 +61,11 @@
/** initialize all actions */
void initActions ();
- QString getDescription ();
bool isModified ();
/** Return current url */
KUrl url ();
+/** Return current url in a restorable way, i.e. for help pages, abstract the session specific part of the path */
+ KUrl restorableUrl ();
void doGotoAnchor (const QString &anchor_name);
WindowMode mode () { return window_mode; };
Modified: trunk/rkward/rkward/windows/rkmdiwindow.h
===================================================================
--- trunk/rkward/rkward/windows/rkmdiwindow.h 2011-02-09 17:52:29 UTC (rev 3432)
+++ trunk/rkward/rkward/windows/rkmdiwindow.h 2011-02-13 12:56:37 UTC (rev 3433)
@@ -82,9 +82,6 @@
virtual QString shortCaption ();
/** @returns The corresponding KPart for this window */
KParts::Part *getPart () { return part; };
-/** This is used in RKWorkplace::saveWorkplace () to save the info about the workplace. Make sure to add corresponding code to RKWorkplace::restoreWorkplace (), so your window(s) get restored when loading a Workspace
- at returns An internal descriptive string. */
- virtual QString getDescription () { return QString (); };
/** Is this window attached (or detached)?
@returns true if attached, false if detached */
bool isAttached () const { return (state == Attached); };
Modified: trunk/rkward/rkward/windows/rkwindowcatcher.h
===================================================================
--- trunk/rkward/rkward/windows/rkwindowcatcher.h 2011-02-09 17:52:29 UTC (rev 3432)
+++ trunk/rkward/rkward/windows/rkwindowcatcher.h 2011-02-13 12:56:37 UTC (rev 3433)
@@ -106,8 +106,6 @@
RKCaughtX11Window (WId window_to_embed, int device_number);
/** dtor */
~RKCaughtX11Window ();
-/** TODO */
- QString getDescription () { return "x11:unimplemented"; };
/** TODO? */
bool isModified () { return false; };
Modified: trunk/rkward/rkward/windows/rkworkplace.cpp
===================================================================
--- trunk/rkward/rkward/windows/rkworkplace.cpp 2011-02-09 17:52:29 UTC (rev 3432)
+++ trunk/rkward/rkward/windows/rkworkplace.cpp 2011-02-13 12:56:37 UTC (rev 3433)
@@ -2,7 +2,7 @@
rkworkplace - description
-------------------
begin : Thu Sep 21 2006
- copyright : (C) 2006, 2007, 2009, 2010 by Thomas Friedrichsmeier
+ copyright : (C) 2006, 2007, 2009, 2010, 2011 by Thomas Friedrichsmeier
email : tfry at users.sourceforge.net
***************************************************************************/
@@ -28,6 +28,8 @@
#include <krun.h>
#include <kmimetype.h>
+#include <QFileInfo>
+
#include "detachedwindowcontainer.h"
#include "rkcommandeditorwindow.h"
#include "rkhtmlwindow.h"
@@ -483,23 +485,33 @@
return (ret);
}
-QString RKWorkplace::makeWorkplaceDescription (const QString &sep, bool quote) {
+QStringList RKWorkplace::makeWorkplaceDescription () {
RK_TRACE (APP);
+ QStringList workplace_description;
+
+ // first, save the base directory of the workplace. This allows us to cope better with moved workspaces while restoring.
+ KUrl base_url = RObjectList::getObjectList ()->getWorkspaceURL ();
+ base_url.setPath (base_url.directory ());
+ if (base_url.isLocalFile () && base_url.hasPath ()) workplace_description.append ("base:" + base_url.url ());
+
// window order in the workplace view may have changed with respect to our list. Thus we first generate a properly sorted list
RKWorkplaceObjectList list = getObjectList (RKMDIWindow::DocumentWindow, RKMDIWindow::Detached);
for (int i=0; i < wview->count (); ++i) {
list.append (static_cast<RKMDIWindow*> (wview->widget (i)));
}
-
- QString workplace_description;
- bool first = true;
foreach (RKMDIWindow *win, list) {
- if (first) first = false;
- else workplace_description.append (sep);
-
- if (!quote) workplace_description.append (win->getDescription ());
- else workplace_description.append (RObject::rQuote (win->getDescription ()));
+ QString desc;
+ if (win->isType (RKMDIWindow::DataEditorWindow)) {
+ desc = "data:" + static_cast<RKEditor*> (win)->getObject ()->getFullName ();
+ } else if (win->isType (RKMDIWindow::CommandEditorWindow)) {
+ desc = "script:" + static_cast<RKCommandEditorWindow*> (win)->url ().url ();
+ } else if (win->isType (RKMDIWindow::OutputWindow)) {
+ desc = "output:" + static_cast<RKHTMLWindow*> (win)->url ().url ();
+ } else if (win->isType (RKMDIWindow::HelpWindow)) {
+ desc = "help:" + static_cast<RKHTMLWindow*> (win)->restorableUrl ().url ();
+ }
+ if (!desc.isEmpty ()) workplace_description.append (desc);
}
return workplace_description;
}
@@ -508,9 +520,11 @@
RK_TRACE (APP);
if (RKSettingsModuleGeneral::workplaceSaveMode () != RKSettingsModuleGeneral::SaveWorkplaceWithWorkspace) return;
- QString workplace_description = ".rk.workplace.save <- c (" + makeWorkplaceDescription (", ", true) + ')';
+ QStringList workplace_description = makeWorkplaceDescription ();
+ for (int i=0; i < workplace_description.size (); ++i) workplace_description[i] = RObject::rQuote (workplace_description[i]);
+ QString command = ".rk.workplace.save <- c (" + workplace_description.join (", ") + ')';
- RKGlobals::rInterface ()->issueCommand (workplace_description, RCommand::App | RCommand::Sync, i18n ("Save Workplace layout"), 0, 0, chain);
+ RKGlobals::rInterface ()->issueCommand (command, RCommand::App | RCommand::Sync, i18n ("Save Workplace layout"), 0, 0, chain);
}
void RKWorkplace::restoreWorkplace (RCommandChain *chain) {
@@ -520,12 +534,52 @@
RKGlobals::rInterface ()->issueCommand (".rk.workplace.save", RCommand::App | RCommand::Sync | RCommand::GetStringVector, i18n ("Restore Workplace layout"), this, RESTORE_WORKPLACE_COMMAND, chain);
}
-void RKWorkplace::restoreWorkplace (const QString &description) {
+KUrl checkAdjustRestoredUrl (const QString &_url, const QString old_base) {
+ KUrl url (_url);
+
+ if (old_base.isEmpty ()) return (url);
+ KUrl new_base_url = RObjectList::getObjectList ()->getWorkspaceURL ();
+ new_base_url.setPath (new_base_url.directory ());
+ if (new_base_url.isEmpty ()) return (url);
+ KUrl old_base_url (old_base);
+ if (old_base_url == new_base_url) return (url);
+
+ // TODO: Should we also care about non-local files? In theory: yes, but stat'ing remote files for existence can take a long time.
+ if (!(old_base_url.isLocalFile () && new_base_url.isLocalFile () && url.isLocalFile ())) return (url);
+
+ // if the file exists, unadjusted, return it.
+ if (QFileInfo (url.toLocalFile ()).exists ()) return (url);
+
+ // check whether a file exists for the adjusted url
+ KUrl relative = KUrl::fromLocalFile (new_base_url.path () + '/' + KUrl::relativePath (old_base_url.path (), url.path ()));
+ relative.cleanPath ();
+ if (QFileInfo (relative.toLocalFile ()).exists ()) return (relative);
+ return (url);
+}
+
+void RKWorkplace::restoreWorkplace (const QStringList &description) {
RK_TRACE (APP);
- QStringList list = description.split ("\n");
- for (QStringList::const_iterator it = list.constBegin (); it != list.constEnd (); ++it) {
- restoreWorkplaceItem (*it);
+ QString base;
+ for (int i = 0; i < description.size (); ++i) {
+ QString type = description[i].section (QChar (':'), 0, 0);
+ QString specification = description[i].section (QChar (':'), 1);
+
+ if (type == "base") {
+ RK_ASSERT (i == 0);
+ base = specification;
+ } else if (type == "data") {
+ RObject *object = RObjectList::getObjectList ()->findObject (specification);
+ if (object) editObject (object);
+ } else if (type == "script") {
+ openScriptEditor (checkAdjustRestoredUrl (specification, base));
+ } else if (type == "output") {
+ openOutputWindow (checkAdjustRestoredUrl (specification, base));
+ } else if (type == "help") {
+ openHelpWindow (checkAdjustRestoredUrl (specification, base), true);
+ } else {
+ RK_ASSERT (false);
+ }
}
}
@@ -540,32 +594,9 @@
RK_TRACE (APP);
RK_ASSERT (command->getFlags () == RESTORE_WORKPLACE_COMMAND);
- for (unsigned int i = 0; i < command->getDataLength (); ++i) {
- restoreWorkplaceItem (command->getStringVector ()[i]);
- }
+ restoreWorkplace (command->getStringVector ());
}
-void RKWorkplace::restoreWorkplaceItem (const QString &desc) {
- RK_TRACE (APP);
-
- QString type = desc.section (QChar (':'), 0, 0);
- QString specification = desc.section (QChar (':'), 1);
-
- if (type == "data") {
- RObject *object = RObjectList::getObjectList ()->findObject (specification);
- if (object) editObject (object);
- } else if (type == "script") {
- openScriptEditor (specification);
- } else if (type == "output") {
- openOutputWindow (specification);
- } else if (type == "help") {
- openHelpWindow (specification, true);
- } else {
- RK_ASSERT (false);
- }
-}
-
-
///////////////////////// END RKWorkplace ////////////////////////////
///////////////////// BEGIN RKMDIWindowHistory ///////////////////////
Modified: trunk/rkward/rkward/windows/rkworkplace.h
===================================================================
--- trunk/rkward/rkward/windows/rkworkplace.h 2011-02-09 17:52:29 UTC (rev 3432)
+++ trunk/rkward/rkward/windows/rkworkplace.h 2011-02-13 12:56:37 UTC (rev 3433)
@@ -145,13 +145,13 @@
void restoreWorkplace (RCommandChain *chain=0);
/** Like the other restoreWorkplace (), but takes the description as a parameter rather than reading from the R workspace. To be used, when RKSettingsModuleGeneral::workplaceSaveMode () == RKSettingsModuleGeneral::SaveWorkplaceWithSeesion
@param description workplace description */
- void restoreWorkplace (const QString &description);
+ void restoreWorkplace (const QStringList &description);
/** Clear the description as set by saveWorkplace () from the R backend. Simply removes the internal object. Since the description is only needed while the workplace is being saved / restored, this should be called shortly after saveWorkplace () and restoreWorkplace ()
Has no effect, if RKSettingsModuleGeneral::workplaceSaveMode () != RKSettingsModuleGeneral::SaveWorkplaceWithWorkspace
@param cahin command chain to place the command in */
void clearWorkplaceDescription (RCommandChain *chain=0);
- QString makeWorkplaceDescription (const QString &sep, bool quote);
+ QStringList makeWorkplaceDescription ();
/** In the current design there is only ever one workplace. Use this static function to reference it.
@returns a pointer to the workplace */
@@ -179,7 +179,6 @@
/** a window was removed. Try to activate some other window. */
void windowRemoved ();
- void restoreWorkplaceItem (const QString &desc);
RKMDIWindowHistory *history;
QSplitter *horiz_splitter;
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