mirror of
https://github.com/KDE/konsole.git
synced 2026-06-11 23:45:09 -04:00
Remember last 'Save Output As' directory
This will save current session's last 'Save Output As' directory as well as saving it so next Konsole startup will remember it. Original code by Tao Guo <guotao945@gmail.com> with additions by myself. BUG: 403103 FIXED-IN: 19.08.0 Differential Revision: https://phabricator.kde.org/D18352
This commit is contained in:
@@ -26,12 +26,17 @@
|
||||
|
||||
#include <KMessageBox>
|
||||
#include <KLocalizedString>
|
||||
#include <KSharedConfig>
|
||||
#include <KConfig>
|
||||
#include <KConfigGroup>
|
||||
|
||||
#include "SessionManager.h"
|
||||
#include "Emulation.h"
|
||||
|
||||
namespace Konsole {
|
||||
|
||||
QString SaveHistoryTask::_saveDialogRecentURL;
|
||||
|
||||
SaveHistoryTask::SaveHistoryTask(QObject* parent)
|
||||
: SessionTask(parent)
|
||||
{
|
||||
@@ -45,9 +50,7 @@ void SaveHistoryTask::execute()
|
||||
// three then providing a URL for each one will be tedious
|
||||
|
||||
// TODO - show a warning ( preferably passive ) if saving the history output fails
|
||||
QFileDialog* dialog = new QFileDialog(QApplication::activeWindow(),
|
||||
QString(),
|
||||
QDir::homePath());
|
||||
QFileDialog* dialog = new QFileDialog(QApplication::activeWindow());
|
||||
dialog->setAcceptMode(QFileDialog::AcceptSave);
|
||||
|
||||
QStringList mimeTypes {
|
||||
@@ -56,6 +59,20 @@ void SaveHistoryTask::execute()
|
||||
};
|
||||
dialog->setMimeTypeFilters(mimeTypes);
|
||||
|
||||
KSharedConfigPtr konsoleConfig = KSharedConfig::openConfig();
|
||||
auto group = konsoleConfig->group("SaveHistory Settings");
|
||||
|
||||
if (_saveDialogRecentURL.isEmpty()) {
|
||||
const auto list = group.readPathEntry("Recent URLs", QStringList());
|
||||
if (list.isEmpty()) {
|
||||
dialog->setDirectory(QDir::homePath());
|
||||
} else {
|
||||
dialog->setDirectoryUrl(QUrl(list.at(0)));
|
||||
}
|
||||
} else {
|
||||
dialog->setDirectoryUrl(QUrl(_saveDialogRecentURL));
|
||||
}
|
||||
|
||||
// iterate over each session in the task and display a dialog to allow the user to choose where
|
||||
// to save that session's history.
|
||||
// then start a KIO job to transfer the data from the history to the chosen URL
|
||||
@@ -76,6 +93,10 @@ void SaveHistoryTask::execute()
|
||||
continue;
|
||||
}
|
||||
|
||||
// Save selected URL for next time
|
||||
_saveDialogRecentURL = url.adjusted(QUrl::RemoveFilename|QUrl::StripTrailingSlash).toString();
|
||||
group.writePathEntry("Recent URLs", _saveDialogRecentURL);
|
||||
|
||||
KIO::TransferJob* job = KIO::put(url,
|
||||
-1, // no special permissions
|
||||
// overwrite existing files
|
||||
|
||||
Reference in New Issue
Block a user