Add a function to reveal a file in the platform's external file browser

This commit is contained in:
baldurk
2018-02-07 16:07:08 +00:00
parent 8374e2f01f
commit 9f87e6e013
2 changed files with 16 additions and 1 deletions
+14 -1
View File
@@ -25,7 +25,7 @@
#include "QRDUtils.h"
#include <QAbstractTextDocumentLayout>
#include <QApplication>
#include <QElapsedTimer>
#include <QDesktopServices>
#include <QElapsedTimer>
#include <QFileSystemModel>
#include <QFontDatabase>
@@ -1425,6 +1425,19 @@ bool RunProcessAsAdmin(const QString &fullExecutablePath, const QStringList &par
#endif
}
void RevealFilenameInExternalFileBrowser(const QString &filePath)
{
#if defined(Q_OS_WIN32)
// on windows we can ask explorer to highlight the exact file.
QProcess::startDetached(lit("explorer.exe"), QStringList() << lit("/select,")
<< QDir::toNativeSeparators(filePath));
#else
// on all other platforms, we just use QDesktopServices to invoke the external file browser on the
// directory and hope that's close enough.
QDesktopServices::openUrl(QFileInfo(filePath).absoluteDir().absolutePath());
#endif
}
QStringList ParseArgsList(const QString &args)
{
QStringList ret;
+2
View File
@@ -526,6 +526,8 @@ bool IsRunningAsAdmin();
bool RunProcessAsAdmin(const QString &fullExecutablePath, const QStringList &params,
std::function<void()> finishedCallback = std::function<void()>());
void RevealFilenameInExternalFileBrowser(const QString &filePath);
void ShowProgressDialog(QWidget *window, const QString &labelText, ProgressFinishedMethod finished,
ProgressUpdateMethod update = ProgressUpdateMethod());