From cbd6f6417c21c05f13437bc2b1a7b98aca145fa4 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 17 Apr 2017 13:29:44 -0700 Subject: [PATCH] allow clicking on results row to show dir --- tools/oven/src/ui/DomainBakeWidget.cpp | 2 +- tools/oven/src/ui/ModelBakeWidget.cpp | 2 +- tools/oven/src/ui/ResultsWindow.cpp | 48 ++++++++++++++++++++++++-- tools/oven/src/ui/ResultsWindow.h | 7 +++- 4 files changed, 54 insertions(+), 5 deletions(-) diff --git a/tools/oven/src/ui/DomainBakeWidget.cpp b/tools/oven/src/ui/DomainBakeWidget.cpp index cd2d9f8e3c..34ae0680af 100644 --- a/tools/oven/src/ui/DomainBakeWidget.cpp +++ b/tools/oven/src/ui/DomainBakeWidget.cpp @@ -226,7 +226,7 @@ void DomainBakeWidget::bakeButtonClicked() { // add a pending row to the results window to show that this bake is in process auto resultsWindow = qApp->getMainWindow()->showResultsWindow(); auto resultsRowName = _domainNameLineEdit->text().isEmpty() ? fileToBakeURL.fileName() : _domainNameLineEdit->text(); - auto resultsRow = resultsWindow->addPendingResultRow(resultsRowName); + auto resultsRow = resultsWindow->addPendingResultRow(resultsRowName, outputDirectory); // keep the unique ptr to the domain baker and the index to the row representing it in the results table _bakers.emplace_back(std::move(domainBaker), resultsRow); diff --git a/tools/oven/src/ui/ModelBakeWidget.cpp b/tools/oven/src/ui/ModelBakeWidget.cpp index 2841262fee..f5204020da 100644 --- a/tools/oven/src/ui/ModelBakeWidget.cpp +++ b/tools/oven/src/ui/ModelBakeWidget.cpp @@ -205,7 +205,7 @@ void ModelBakeWidget::bakeButtonClicked() { // add a pending row to the results window to show that this bake is in process auto resultsWindow = qApp->getMainWindow()->showResultsWindow(); - auto resultsRow = resultsWindow->addPendingResultRow(modelToBakeURL.fileName()); + auto resultsRow = resultsWindow->addPendingResultRow(modelToBakeURL.fileName(), outputDirectory); // keep a unique_ptr to this baker // and remember the row that represents it in the results table diff --git a/tools/oven/src/ui/ResultsWindow.cpp b/tools/oven/src/ui/ResultsWindow.cpp index 36b7e83177..387e3698b8 100644 --- a/tools/oven/src/ui/ResultsWindow.cpp +++ b/tools/oven/src/ui/ResultsWindow.cpp @@ -9,7 +9,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include +#include #include #include #include @@ -50,12 +50,53 @@ void ResultsWindow::setupUI() { _resultsTable->horizontalHeader()->resizeSection(0, 0.25 * FIXED_WINDOW_WIDTH); _resultsTable->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents); + // make sure we hear about cell clicks so that we can show the output directory for the given row + connect(_resultsTable, &QTableWidget::cellClicked, this, &ResultsWindow::handleCellClicked); + // set the layout of this widget to the created layout setLayout(resultsLayout); } +void revealDirectory(const QDir& dirToReveal) { -int ResultsWindow::addPendingResultRow(const QString& fileName) { + // See http://stackoverflow.com/questions/3490336/how-to-reveal-in-finder-or-show-in-explorer-with-qt + // for details + + // Mac, Windows support folder or file. +#if defined(Q_OS_WIN) + const QString explorer = Environment::systemEnvironment().searchInPath(QLatin1String("explorer.exe")); + if (explorer.isEmpty()) { + QMessageBox::warning(parent, + tr("Launching Windows Explorer failed"), + tr("Could not find explorer.exe in path to launch Windows Explorer.")); + return; + } + + QString param = QLatin1String("/select,") + QDir::toNativeSeparators(dirToReveal.absolutePath()); + + QString command = explorer + " " + param; + QProcess::startDetached(command); + +#elif defined(Q_OS_MAC) + QStringList scriptArgs; + scriptArgs << QLatin1String("-e") + << QString::fromLatin1("tell application \"Finder\" to reveal POSIX file \"%1\"").arg(dirToReveal.absolutePath()); + QProcess::execute(QLatin1String("/usr/bin/osascript"), scriptArgs); + + scriptArgs.clear(); + scriptArgs << QLatin1String("-e") << QLatin1String("tell application \"Finder\" to activate"); + QProcess::execute("/usr/bin/osascript", scriptArgs); +#endif + +} + +void ResultsWindow::handleCellClicked(int rowIndex, int columnIndex) { + // use revealDirectory to show the output directory for this row + revealDirectory(_outputDirectories[rowIndex]); +} + + +int ResultsWindow::addPendingResultRow(const QString& fileName, const QDir& outputDirectory) { int rowIndex = _resultsTable->rowCount(); _resultsTable->insertRow(rowIndex); @@ -69,6 +110,9 @@ int ResultsWindow::addPendingResultRow(const QString& fileName) { statusItem->setFlags(statusItem->flags() & ~Qt::ItemIsEditable); _resultsTable->setItem(rowIndex, 1, statusItem); + // push an output directory to our list so we can show it if the user clicks on this bake in the results table + _outputDirectories.push_back(outputDirectory); + return rowIndex; } diff --git a/tools/oven/src/ui/ResultsWindow.h b/tools/oven/src/ui/ResultsWindow.h index b7e380a631..ae7bb0e327 100644 --- a/tools/oven/src/ui/ResultsWindow.h +++ b/tools/oven/src/ui/ResultsWindow.h @@ -12,6 +12,7 @@ #ifndef hifi_ResultsWindow_h #define hifi_ResultsWindow_h +#include #include class QTableWidget; @@ -24,11 +25,15 @@ public: void setupUI(); - int addPendingResultRow(const QString& fileName); + int addPendingResultRow(const QString& fileName, const QDir& outputDirectory); void changeStatusForRow(int rowIndex, const QString& result); +private slots: + void handleCellClicked(int rowIndex, int columnIndex); + private: QTableWidget* _resultsTable { nullptr }; + QList _outputDirectories; }; #endif // hifi_ResultsWindow_h