From cca4d364bf5050a264571d68f304090912b6fb9c Mon Sep 17 00:00:00 2001 From: baldurk Date: Thu, 6 Sep 2018 12:30:03 +0100 Subject: [PATCH] Save last capture path per remote host. Closes #1094 --- qrenderdoc/Code/Interface/QRDInterface.h | 2 +- qrenderdoc/Code/Interface/RemoteHost.cpp | 3 ++ qrenderdoc/Code/Interface/RemoteHost.h | 3 ++ qrenderdoc/Code/ReplayManager.h | 2 +- qrenderdoc/Windows/Dialogs/CaptureDialog.cpp | 43 ++++++++++++------- .../Windows/Dialogs/VirtualFileDialog.cpp | 5 ++- .../Windows/Dialogs/VirtualFileDialog.h | 2 +- 7 files changed, 39 insertions(+), 21 deletions(-) diff --git a/qrenderdoc/Code/Interface/QRDInterface.h b/qrenderdoc/Code/Interface/QRDInterface.h index fbd18bcd9..097ee1a7a 100644 --- a/qrenderdoc/Code/Interface/QRDInterface.h +++ b/qrenderdoc/Code/Interface/QRDInterface.h @@ -708,7 +708,7 @@ struct IReplayManager :return: The host connected to, or ``None`` if no connection is active. :rtype: RemoteHost )"); - virtual const RemoteHost *CurrentRemote() = 0; + virtual RemoteHost *CurrentRemote() = 0; DOCUMENT(R"(Retrieves the capture file handle for the currently open file. diff --git a/qrenderdoc/Code/Interface/RemoteHost.cpp b/qrenderdoc/Code/Interface/RemoteHost.cpp index 41b6de197..9c6eb2993 100644 --- a/qrenderdoc/Code/Interface/RemoteHost.cpp +++ b/qrenderdoc/Code/Interface/RemoteHost.cpp @@ -41,6 +41,8 @@ RemoteHost::RemoteHost(const QVariant &var) friendlyName = map[lit("friendlyName")].toString(); if(map.contains(lit("runCommand"))) runCommand = map[lit("runCommand")].toString(); + if(map.contains(lit("lastCapturePath"))) + lastCapturePath = map[lit("lastCapturePath")].toString(); serverRunning = connected = busy = versionMismatch = false; } @@ -51,6 +53,7 @@ RemoteHost::operator QVariant() const map[lit("hostname")] = hostname; map[lit("friendlyName")] = friendlyName; map[lit("runCommand")] = runCommand; + map[lit("lastCapturePath")] = lastCapturePath; return map; } diff --git a/qrenderdoc/Code/Interface/RemoteHost.h b/qrenderdoc/Code/Interface/RemoteHost.h index fe7c38354..dd05db504 100644 --- a/qrenderdoc/Code/Interface/RemoteHost.h +++ b/qrenderdoc/Code/Interface/RemoteHost.h @@ -67,6 +67,9 @@ public: DOCUMENT("The command to run locally to try to launch the server remotely."); rdcstr runCommand; + DOCUMENT("The last folder browser to on this host, to provide a reasonable default path."); + rdcstr lastCapturePath; + DOCUMENT(R"( Returns the name to display for this host in the UI, either :data:`friendlyName` or :data:`hostname` )"); diff --git a/qrenderdoc/Code/ReplayManager.h b/qrenderdoc/Code/ReplayManager.h index 88697c325..390fd4163 100644 --- a/qrenderdoc/Code/ReplayManager.h +++ b/qrenderdoc/Code/ReplayManager.h @@ -86,7 +86,7 @@ public: // work whether local or remote. ICaptureFile *GetCaptureFile() { return m_CaptureFile; } void ReopenCaptureFile(const QString &path); - const RemoteHost *CurrentRemote() { return m_RemoteHost; } + RemoteHost *CurrentRemote() { return m_RemoteHost; } ExecuteResult ExecuteAndInject(const rdcstr &exe, const rdcstr &workingDir, const rdcstr &cmdLine, const rdcarray &env, const rdcstr &capturefile, CaptureOptions opts); diff --git a/qrenderdoc/Windows/Dialogs/CaptureDialog.cpp b/qrenderdoc/Windows/Dialogs/CaptureDialog.cpp index 8f8138370..2add1b8ee 100644 --- a/qrenderdoc/Windows/Dialogs/CaptureDialog.cpp +++ b/qrenderdoc/Windows/Dialogs/CaptureDialog.cpp @@ -575,6 +575,10 @@ void CaptureDialog::on_exePathBrowse_clicked() { initDir = dir.absolutePath(); } + else if(m_Ctx.Replay().CurrentRemote()) + { + initDir = m_Ctx.Replay().CurrentRemote()->lastCapturePath; + } else if(!m_Ctx.Config().LastCapturePath.isEmpty()) { initDir = m_Ctx.Config().LastCapturePath; @@ -584,7 +588,7 @@ void CaptureDialog::on_exePathBrowse_clicked() if(m_Ctx.Replay().CurrentRemote()) { - VirtualFileDialog vfd(m_Ctx, this); + VirtualFileDialog vfd(m_Ctx, initDir, this); RDDialog::show(&vfd); filename = vfd.chosenPath(); } @@ -606,26 +610,31 @@ void CaptureDialog::on_exePathBrowse_clicked() void CaptureDialog::on_workDirBrowse_clicked() { - QString initDir; + QString initDir = ui->workDirPath->text(); - if(QDir(ui->workDirPath->text()).exists()) + if(initDir.isEmpty()) { - initDir = ui->workDirPath->text(); - } - else - { - QDir dir = QFileInfo(ui->exePath->text()).dir(); - if(dir.exists()) - initDir = dir.absolutePath(); - else if(!m_Ctx.Config().LastCapturePath.isEmpty()) - initDir = m_Ctx.Config().LastCapturePath; + if(m_Ctx.Replay().CurrentRemote()) + { + initDir = m_Ctx.Replay().CurrentRemote()->lastCapturePath; + } + else if(!QDir(initDir).exists()) + { + QDir dir = QFileInfo(ui->exePath->text()).dir(); + if(dir.exists()) + initDir = dir.absolutePath(); + else if(!m_Ctx.Config().LastCapturePath.isEmpty()) + initDir = m_Ctx.Config().LastCapturePath; + else + initDir = QString(); + } } QString dir; if(m_Ctx.Replay().CurrentRemote()) { - VirtualFileDialog vfd(m_Ctx, this); + VirtualFileDialog vfd(m_Ctx, initDir, this); vfd.setDirBrowse(); RDDialog::show(&vfd); dir = vfd.chosenPath(); @@ -921,10 +930,12 @@ void CaptureDialog::SetExecutableFilename(const rdcstr &filename) ui->exePath->setText(fn); - if(!m_Ctx.Replay().CurrentRemote()) - { + if(m_Ctx.Replay().CurrentRemote()) + m_Ctx.Replay().CurrentRemote()->lastCapturePath = QFileInfo(fn).absolutePath(); + else m_Ctx.Config().LastCapturePath = QFileInfo(fn).absolutePath(); - } + + m_Ctx.Config().Save(); } void CaptureDialog::SetWorkingDirectory(const rdcstr &dir) diff --git a/qrenderdoc/Windows/Dialogs/VirtualFileDialog.cpp b/qrenderdoc/Windows/Dialogs/VirtualFileDialog.cpp index 76249d8bd..f1671bdc1 100644 --- a/qrenderdoc/Windows/Dialogs/VirtualFileDialog.cpp +++ b/qrenderdoc/Windows/Dialogs/VirtualFileDialog.cpp @@ -550,7 +550,7 @@ protected: } }; -VirtualFileDialog::VirtualFileDialog(ICaptureContext &ctx, QWidget *parent) +VirtualFileDialog::VirtualFileDialog(ICaptureContext &ctx, QString initialDirectory, QWidget *parent) : QDialog(parent), ui(new Ui::VirtualFileDialog) { ui->setupUi(this); @@ -591,7 +591,8 @@ VirtualFileDialog::VirtualFileDialog(ICaptureContext &ctx, QWidget *parent) ui->buttonBox->button(QDialogButtonBox::Ok)->setDefault(false); // switch to home folder and expand it - changeCurrentDir(m_Model->homeFolder()); + changeCurrentDir(initialDirectory.isEmpty() ? m_Model->homeFolder() + : m_Model->indexForPath(initialDirectory)); ui->dirList->expand(m_DirProxy->mapFromSource(currentDir())); QObject::connect(ui->fileList->selectionModel(), &QItemSelectionModel::selectionChanged, this, diff --git a/qrenderdoc/Windows/Dialogs/VirtualFileDialog.h b/qrenderdoc/Windows/Dialogs/VirtualFileDialog.h index c2ca278c4..fe170cced 100644 --- a/qrenderdoc/Windows/Dialogs/VirtualFileDialog.h +++ b/qrenderdoc/Windows/Dialogs/VirtualFileDialog.h @@ -41,7 +41,7 @@ class VirtualFileDialog : public QDialog Q_OBJECT public: - explicit VirtualFileDialog(ICaptureContext &ctx, QWidget *parent = 0); + explicit VirtualFileDialog(ICaptureContext &ctx, QString initialDirectory, QWidget *parent = 0); ~VirtualFileDialog(); QString chosenPath() { return m_ChosenPath; }