From e9dda8343fff577071cc79dfcb324a8c3d988acb Mon Sep 17 00:00:00 2001 From: baldurk Date: Thu, 10 Oct 2019 12:19:41 +0100 Subject: [PATCH] When deleting temp files, remove from the recent file list. Closes #1540 * If the UI was launched with a filename as a parameter to open the capture, it will be added to the recent capture file list. Only later (relatively speaking) if we make a capture connection will we realise that it is temporary and potentially delete the file. If we do so, remove the capture from the recent file list. --- qrenderdoc/Code/CaptureContext.cpp | 11 +++++- .../Code/Interface/PersistantConfig.cpp | 38 +++++++++++++------ qrenderdoc/Code/Interface/PersistantConfig.h | 16 ++++++-- qrenderdoc/Code/ReplayManager.cpp | 2 +- .../Code/pyrenderdoc/qrenderdoc_stub.cpp | 6 ++- qrenderdoc/Windows/Dialogs/CaptureDialog.cpp | 4 +- qrenderdoc/Windows/Dialogs/LiveCapture.cpp | 13 ++++++- qrenderdoc/Windows/MainWindow.cpp | 34 +++++++++++++++-- qrenderdoc/Windows/MainWindow.h | 2 + 9 files changed, 100 insertions(+), 26 deletions(-) diff --git a/qrenderdoc/Code/CaptureContext.cpp b/qrenderdoc/Code/CaptureContext.cpp index 1af01d345..efe957456 100644 --- a/qrenderdoc/Code/CaptureContext.cpp +++ b/qrenderdoc/Code/CaptureContext.cpp @@ -809,7 +809,7 @@ void CaptureContext::LoadCaptureThreaded(const QString &captureFile, const Repla if(!temporary) { - AddRecentFile(Config().RecentCaptureFiles, origFilename, 10); + AddRecentFile(Config().RecentCaptureFiles, origFilename); Config().Save(); } @@ -1076,7 +1076,10 @@ void CaptureContext::RecompressCapture() if(tempCap) tempCap->Shutdown(); if(!tempFilename.isEmpty()) + { + m_MainWindow->RemoveRecentCapture(tempFilename); QFile::remove(tempFilename); + } return; } @@ -1134,7 +1137,10 @@ void CaptureContext::RecompressCapture() if(tempCap) tempCap->Shutdown(); if(!tempFilename.isEmpty()) + { + m_MainWindow->RemoveRecentCapture(tempFilename); QFile::remove(tempFilename); + } } bool CaptureContext::SaveCaptureTo(const rdcstr &captureFile) @@ -1195,7 +1201,10 @@ bool CaptureContext::SaveCaptureTo(const rdcstr &captureFile) // if it was a temporary capture, remove the old instnace if(m_CaptureTemporary) + { + m_MainWindow->RemoveRecentCapture(m_CaptureFile); QFile::remove(m_CaptureFile); + } // Update the filename, and mark that it's local and not temporary now. m_CaptureFile = captureFile; diff --git a/qrenderdoc/Code/Interface/PersistantConfig.cpp b/qrenderdoc/Code/Interface/PersistantConfig.cpp index e65d43a20..f883355c9 100644 --- a/qrenderdoc/Code/Interface/PersistantConfig.cpp +++ b/qrenderdoc/Code/Interface/PersistantConfig.cpp @@ -502,7 +502,23 @@ bool PersistantConfig::Save() LastFileBrowsePath = RDDialog::DefaultBrowsePath; - return Serialize(m_Filename); + // truncate the lists to a maximum of 9 items, allow more to exist in memory + rdcarray capFiles = RecentCaptureFiles; + rdcarray capSettings = RecentCaptureSettings; + + // the oldest items are first, so remove from there + while(RecentCaptureFiles.count() >= 10) + RecentCaptureFiles.erase(0); + while(RecentCaptureSettings.count() >= 10) + RecentCaptureSettings.erase(0); + + bool ret = Serialize(m_Filename); + + // restore lists + RecentCaptureFiles = capFiles; + RecentCaptureSettings = capSettings; + + return ret; } void PersistantConfig::Close() @@ -515,7 +531,12 @@ void PersistantConfig::SetupFormatting() Formatter::setParams(*this); } -void AddRecentFile(rdcarray &recentList, const rdcstr &file, int maxItems) +void RemoveRecentFile(rdcarray &recentList, const rdcstr &file) +{ + recentList.removeOne(QDir::cleanPath(file)); +} + +void AddRecentFile(rdcarray &recentList, const rdcstr &file) { QDir dir(file); QString path = dir.canonicalPath(); @@ -526,17 +547,10 @@ void AddRecentFile(rdcarray &recentList, const rdcstr &file, int maxItem return; } - if(!recentList.contains(path)) - { - recentList.push_back(path); - if(recentList.count() >= maxItems) - recentList.erase(0); - } - else - { + if(recentList.contains(path)) recentList.removeOne(path); - recentList.push_back(path); - } + + recentList.push_back(path); } void PersistantConfig::SetConfigSetting(const rdcstr &name, const rdcstr &value) diff --git a/qrenderdoc/Code/Interface/PersistantConfig.h b/qrenderdoc/Code/Interface/PersistantConfig.h index 0394fcbe1..22fae0edd 100644 --- a/qrenderdoc/Code/Interface/PersistantConfig.h +++ b/qrenderdoc/Code/Interface/PersistantConfig.h @@ -435,16 +435,24 @@ inline rdcstr UnitSuffix(TimeUnit unit) } DOCUMENT(R"(Checks if a given file is in a list. If it is, then it's shuffled to the end. If it's -not then it's added to the end and an item is dropped from the front of the list if necessary to -stay within a given maximum +not then it's added to the end As the name suggests, this is used for tracking a 'recent file' list. :param list recentList: A ``list`` of ``str`` that is mutated by the function. :param str file: The file to add to the list. -:param int maxItems: The maximum allowed length of the list. )"); -void AddRecentFile(rdcarray &recentList, const rdcstr &file, int maxItems); +void AddRecentFile(rdcarray &recentList, const rdcstr &file); + +DOCUMENT(R"(Removes a given file from the list, after normalising the path. If the path isn't +present then the list is not modified. + +As the name suggests, this is used for tracking a 'recent file' list. + +:param list recentList: A ``list`` of ``str`` that is mutated by the function. +:param str file: The file to remove from the list. +)"); +void RemoveRecentFile(rdcarray &recentList, const rdcstr &file); DOCUMENT2(R"(A persistant config file that is automatically loaded and saved, which contains any settings and information that needs to be preserved from one run to the next. diff --git a/qrenderdoc/Code/ReplayManager.cpp b/qrenderdoc/Code/ReplayManager.cpp index b7637e12d..78e7b2fc5 100644 --- a/qrenderdoc/Code/ReplayManager.cpp +++ b/qrenderdoc/Code/ReplayManager.cpp @@ -64,7 +64,7 @@ void ReplayManager::OpenCapture(const QString &capturefile, const ReplayOptions void ReplayManager::DeleteCapture(const rdcstr &capture, bool local) { - if(IsRunning()) + if(IsRunning() && !m_Thread->isCurrentThread()) { AsyncInvoke([this, capture, local](IReplayController *) { DeleteCapture(capture, local); }); return; diff --git a/qrenderdoc/Code/pyrenderdoc/qrenderdoc_stub.cpp b/qrenderdoc/Code/pyrenderdoc/qrenderdoc_stub.cpp index e5faba74c..f8280b4ea 100644 --- a/qrenderdoc/Code/pyrenderdoc/qrenderdoc_stub.cpp +++ b/qrenderdoc/Code/pyrenderdoc/qrenderdoc_stub.cpp @@ -151,7 +151,11 @@ void PersistantConfig::SetupFormatting() { } -void AddRecentFile(rdcarray &recentList, const rdcstr &file, int maxItems) +void AddRecentFile(rdcarray &recentList, const rdcstr &file) +{ +} + +void RemoveRecentFile(rdcarray &recentList, const rdcstr &file) { } diff --git a/qrenderdoc/Windows/Dialogs/CaptureDialog.cpp b/qrenderdoc/Windows/Dialogs/CaptureDialog.cpp index 16e620873..358a01734 100644 --- a/qrenderdoc/Windows/Dialogs/CaptureDialog.cpp +++ b/qrenderdoc/Windows/Dialogs/CaptureDialog.cpp @@ -873,7 +873,7 @@ void CaptureDialog::on_saveSettings_clicked() if(dirinfo.exists()) { SaveSettings(filename); - AddRecentFile(m_Ctx.Config().RecentCaptureSettings, filename, 10); + AddRecentFile(m_Ctx.Config().RecentCaptureSettings, filename); m_Main->PopulateRecentCaptureSettings(); } } @@ -887,7 +887,7 @@ void CaptureDialog::on_loadSettings_clicked() if(!filename.isEmpty() && QFileInfo::exists(filename)) { LoadSettings(filename); - AddRecentFile(m_Ctx.Config().RecentCaptureSettings, filename, 10); + AddRecentFile(m_Ctx.Config().RecentCaptureSettings, filename); } } diff --git a/qrenderdoc/Windows/Dialogs/LiveCapture.cpp b/qrenderdoc/Windows/Dialogs/LiveCapture.cpp index 602f7a9a6..8b09c71cb 100644 --- a/qrenderdoc/Windows/Dialogs/LiveCapture.cpp +++ b/qrenderdoc/Windows/Dialogs/LiveCapture.cpp @@ -396,6 +396,11 @@ void LiveCapture::deleteCapture_triggered() { m_Ctx.Replay().DeleteCapture(cap->path, cap->local); } + + if(cap->saved || cap->local) + { + m_Main->RemoveRecentCapture(cap->path); + } } } @@ -844,9 +849,10 @@ bool LiveCapture::saveCapture(Capture *cap, QString path) if(!cap->saved) m_Ctx.Replay().DeleteCapture(cap->path, cap->local); + m_Main->RemoveRecentCapture(cap->path); cap->saved = true; cap->path = path; - AddRecentFile(m_Ctx.Config().RecentCaptureFiles, path, 10); + AddRecentFile(m_Ctx.Config().RecentCaptureFiles, path); m_Main->PopulateRecentCaptureFiles(); return true; } @@ -875,6 +881,11 @@ void LiveCapture::cleanItems() { m_Ctx.Replay().DeleteCapture(cap->path, cap->local); } + + if(cap->saved || cap->local) + { + m_Main->RemoveRecentCapture(cap->path); + } } } diff --git a/qrenderdoc/Windows/MainWindow.cpp b/qrenderdoc/Windows/MainWindow.cpp index 29d99b11d..ccb88cc18 100644 --- a/qrenderdoc/Windows/MainWindow.cpp +++ b/qrenderdoc/Windows/MainWindow.cpp @@ -911,7 +911,7 @@ bool MainWindow::PromptSaveCaptureAs() if(!success) return false; - AddRecentFile(m_Ctx.Config().RecentCaptureFiles, saveFilename, 10); + AddRecentFile(m_Ctx.Config().RecentCaptureFiles, saveFilename); PopulateRecentCaptureFiles(); SetTitle(saveFilename); @@ -1025,15 +1025,28 @@ bool MainWindow::PromptCloseCapture() CloseCapture(); if(!deletepath.isEmpty()) + { m_Ctx.Replay().DeleteCapture(deletepath, caplocal); + RemoveRecentCapture(deletepath); + } return true; } void MainWindow::CloseCapture() { + QString path = m_Ctx.GetCaptureFilename(); + bool local = m_Ctx.IsCaptureLocal(); + m_Ctx.CloseCapture(); + if(m_OwnTempCapture) + { + m_Ctx.Replay().DeleteCapture(path, local); + RemoveRecentCapture(path); + m_OwnTempCapture = false; + } + ui->action_Save_Capture_Inplace->setEnabled(false); ui->action_Save_Capture_As->setEnabled(false); ui->menu_Export_As->setEnabled(false); @@ -1141,6 +1154,10 @@ void MainWindow::PopulateRecentCaptureFiles() idx++; ui->menu_Recent_Capture_Files->setEnabled(true); + + // only populate the 9 most recent, even if more exist in memory + if(idx == 10) + break; } ui->menu_Recent_Capture_Files->addSeparator(); @@ -1170,6 +1187,10 @@ void MainWindow::PopulateRecentCaptureSettings() idx++; ui->menu_Recent_Capture_Settings->setEnabled(true); + + // only populate the 9 most recent, even if more exist in memory + if(idx == 10) + break; } ui->menu_Recent_Capture_Settings->addSeparator(); @@ -1545,6 +1566,13 @@ void MainWindow::show() QMainWindow::show(); } +void MainWindow::RemoveRecentCapture(const QString &filename) +{ + RemoveRecentFile(m_Ctx.Config().RecentCaptureFiles, filename); + + PopulateRecentCaptureFiles(); +} + void MainWindow::recentCaptureFile(const QString &filename) { if(QFileInfo::exists(filename)) @@ -1559,9 +1587,7 @@ void MainWindow::recentCaptureFile(const QString &filename) if(res == QMessageBox::Yes) { - m_Ctx.Config().RecentCaptureFiles.removeOne(filename); - - PopulateRecentCaptureFiles(); + RemoveRecentCapture(filename); } } } diff --git a/qrenderdoc/Windows/MainWindow.h b/qrenderdoc/Windows/MainWindow.h index 34d2ebe51..8b02dc11e 100644 --- a/qrenderdoc/Windows/MainWindow.h +++ b/qrenderdoc/Windows/MainWindow.h @@ -91,6 +91,8 @@ public: void ShowLiveCapture(LiveCapture *live); void LiveCaptureClosed(LiveCapture *live); + void RemoveRecentCapture(const QString &filename); + QMenu *GetBaseMenu(WindowMenu base, rdcstr name); QList GetMenuActions();