[rkward/frameworks] rkward: Keep track of last used locations without kfiledialog.
Thomas Friedrichsmeier
thomas.friedrichsmeier at ruhr-uni-bochum.de
Sat Nov 28 14:53:19 UTC 2015
Git commit f97ec426c333fcd5a76b41b0c695ec21c21891e6 by Thomas Friedrichsmeier.
Committed on 27/11/2015 at 19:49.
Pushed by tfry into branch 'frameworks'.
Keep track of last used locations without kfiledialog.
M +3 -1 rkward/rkconsole.cpp
M +4 -18 rkward/rkward.cpp
M +23 -0 rkward/settings/rksettingsmodulegeneral.cpp
M +7 -0 rkward/settings/rksettingsmodulegeneral.h
http://commits.kde.org/rkward/f97ec426c333fcd5a76b41b0c695ec21c21891e6
diff --git a/rkward/rkconsole.cpp b/rkward/rkconsole.cpp
index b505424..38f6972 100644
--- a/rkward/rkconsole.cpp
+++ b/rkward/rkconsole.cpp
@@ -56,6 +56,7 @@
#include "rbackend/rcommand.h"
#include "settings/rksettings.h"
#include "settings/rksettingsmoduleconsole.h"
+#include "settings/rksettingsmodulegeneral.h"
#include "misc/rkcommonfunctions.h"
#include "misc/rkstandardicons.h"
#include "misc/rkstandardactions.h"
@@ -813,8 +814,9 @@ void RKConsole::userLoadHistory (const QUrl &_url) {
QUrl url = _url;
if (url.isEmpty ()) {
- url = QFileDialog::getOpenFileUrl (this, i18n ("Select command history file to load"), QUrl (), i18n ("R history files (*.Rhistory);;All files (*)"));
+ url = QFileDialog::getOpenFileUrl (this, i18n ("Select command history file to load"), RKSettingsModuleGeneral::lastUsedUrlFor ("rscripts"), i18n ("R history files (*.Rhistory);;All files (*)"));
if (url.isEmpty ()) return;
+ RKSettingsModuleGeneral::updateLastUsedUrl ("rscripts", url.adjusted (QUrl::RemoveFilename));
}
QString tempfile;
diff --git a/rkward/rkward.cpp b/rkward/rkward.cpp
index 79e1bde..9fef045 100644
--- a/rkward/rkward.cpp
+++ b/rkward/rkward.cpp
@@ -777,17 +777,10 @@ void RKWardMainWindow::askOpenWorkspace (const QUrl &url) {
slotSetStatusBarText(i18n("Opening workspace..."));
QUrl lurl = url;
if (lurl.isEmpty ()) {
-#ifdef Q_OS_WIN
- // getOpenUrl(QUrl("kfiledialog:///<rfiles>"), ...) causes a hang on windows (KDElibs 4.2.3).
-# ifdef __GNUC__
-# warning Track this bug down and/or report it
-# endif
- lurl = KFileDialog::getOpenUrl (QUrl (), i18n("%1|R Workspace Files (%1)\n*|All files", RKSettingsModuleGeneral::workspaceFilenameFilter ()), this, i18n("Select workspace to open..."));
-#else
- lurl = KFileDialog::getOpenUrl (QUrl("kfiledialog:///<rfiles>"), i18n("%1|R Workspace Files (%1)\n*|All files", RKSettingsModuleGeneral::workspaceFilenameFilter ()), this, i18n("Select workspace to open..."));
-#endif
+ lurl = QFileDialog::getOpenFileUrl (this, i18n("Select workspace to open..."), RKSettingsModuleGeneral::lastUsedUrlFor ("workspaces"), i18n ("R Workspace Files (%1);;All files (*)", RKSettingsModuleGeneral::workspaceFilenameFilter ()));
}
if (!lurl.isEmpty ()) {
+ RKSettingsModuleGeneral::updateLastUsedUrl ("workspaces", lurl.adjusted (QUrl::RemoveFilename));
openWorkspace (lurl);
}
slotSetStatusReady ();
@@ -914,16 +907,9 @@ void RKWardMainWindow::slotOpenCommandEditor () {
RK_TRACE (APP);
KEncodingFileDialog::Result res;
-#ifdef Q_OS_WIN
- // getOpenUrls(QUrl("kfiledialog:///<rfiles>"), ...) causes a hang on windows (KDElibs 4.2.3).
-# ifdef __GNUC__
-# warning Track this bug down and/or report it
-# endif
- res = KEncodingFileDialog::getOpenUrlsAndEncoding (QString (), QUrl (), QString ("%1|R Script Files (%1)\n*|All Files (*)").arg (RKSettingsModuleCommandEditor::scriptFileFilter ()), this, i18n ("Open script file(s)"));
-#else
- res = KEncodingFileDialog::getOpenUrlsAndEncoding (QString (), QUrl ("kfiledialog:///<rfiles>"), QString ("%1|R Script Files (%1)\n*|All Files (*)").arg (RKSettingsModuleCommandEditor::scriptFileFilter ()), this, i18n ("Open script file(s)"));
-#endif
+ res = KEncodingFileDialog::getOpenUrlsAndEncoding (QString (), RKSettingsModuleGeneral::lastUsedUrlFor ("rscripts"), QString ("%1|R Script Files (%1)\n*|All Files (*)").arg (RKSettingsModuleCommandEditor::scriptFileFilter ()), this, i18n ("Open script file(s)"));
for (int i = 0; i < res.URLs.size (); ++i) {
+ if (i == 0) RKSettingsModuleGeneral::updateLastUsedUrl ("rscripts", res.URLs[i].adjusted (QUrl::RemoveFilename));
slotOpenCommandEditor (res.URLs[i], res.encoding);
}
};
diff --git a/rkward/settings/rksettingsmodulegeneral.cpp b/rkward/settings/rksettingsmodulegeneral.cpp
index 42ead79..75ff1fd 100644
--- a/rkward/settings/rksettingsmodulegeneral.cpp
+++ b/rkward/settings/rksettingsmodulegeneral.cpp
@@ -54,6 +54,7 @@ QString RKSettingsModuleGeneral::initial_dir_specification;
bool RKSettingsModuleGeneral::rkward_version_changed;
bool RKSettingsModuleGeneral::installation_moved = false;
QString RKSettingsModuleGeneral::previous_rkward_data_dir;
+QUrl RKSettingsModuleGeneral::generic_filedialog_start_url;
RKSettingsModuleGeneral::RKSettingsModuleGeneral (RKSettings *gui, QWidget *parent) : RKSettingsModule (gui, parent) {
RK_TRACE (SETTINGS);
@@ -174,6 +175,28 @@ QString RKSettingsModuleGeneral::initialWorkingDirectory () {
return initial_dir_specification;
}
+QUrl RKSettingsModuleGeneral::lastUsedUrlFor (const QString& thing) {
+ RK_TRACE (SETTINGS);
+
+ if (thing.isEmpty ()) {
+ if (generic_filedialog_start_url.isEmpty ()) return QUrl::fromLocalFile (QDir::currentPath ());
+ return generic_filedialog_start_url;
+ }
+ KConfigGroup cg (KSharedConfig::openConfig (), "FileDialogUrls");
+ return (cg.readEntry (thing, QUrl ()));
+}
+
+void RKSettingsModuleGeneral::updateLastUsedUrl (const QString& thing, const QUrl& new_path) {
+ RK_TRACE (SETTINGS);
+
+ if (thing.isEmpty ()) {
+ generic_filedialog_start_url = new_path;
+ } else {
+ KConfigGroup cg (KSharedConfig::openConfig (), "FileDialogUrls");
+ cg.writeEntry (thing, new_path);
+ }
+}
+
void RKSettingsModuleGeneral::settingChanged () {
RK_TRACE (SETTINGS);
int dummy = initial_dir_chooser->itemData (initial_dir_chooser->currentIndex ()).toInt ();
diff --git a/rkward/settings/rksettingsmodulegeneral.h b/rkward/settings/rksettingsmodulegeneral.h
index eaff3f3..f8e3952 100644
--- a/rkward/settings/rksettingsmodulegeneral.h
+++ b/rkward/settings/rksettingsmodulegeneral.h
@@ -78,6 +78,12 @@ public:
static RKMDIFocusPolicy mdiFocusPolicy () { return mdi_focus_policy; }
static QString workspaceFilenameFilter () { return ("*.RData *.RDA"); };
static QString initialWorkingDirectory ();
+/** get the url last used for @param thing, where thing is simply a key string.
+ Urls are saved and restored across sessions, _except_ for the empty key, which will keep track of the last used
+ "generic" url within a session (and defaults to the current working directory, while not set). */
+ static QUrl lastUsedUrlFor (const QString& thing);
+/** update the url used for @param thing, @see lastUsedUrlFor(). */
+ static void updateLastUsedUrl (const QString& thing, const QUrl& new_path);
/** if the installation-path of KDE seems to have moved since the last startup, *and* the given path is relative to the
* KDE data path, adjust the given path (probably loaded from config), accordingly. @See RKCommonFunctions::getRKWardDataDir()
* TODO: similar, but not quite identical functionality in rkworkplace.cpp checkAdjustRestoredUrl(). Might be mergeable. */
@@ -129,6 +135,7 @@ private:
static bool rkward_version_changed;
static QString previous_rkward_data_dir;
static bool installation_moved;
+ static QUrl generic_filedialog_start_url;
};
#endif
More information about the rkward-tracker
mailing list