From 6294fcc7536f0a5352ed49afc2c691d197f743d6 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 25 Jul 2015 16:37:07 +0300 Subject: [PATCH] Method Show in Explorer. --HG-- branch : feature --- src/app/tape/tmainwindow.cpp | 59 ++++++++++++++++++++++++++++++++++-- src/app/tape/tmainwindow.h | 1 + src/app/tape/tmainwindow.ui | 4 +-- 3 files changed, 60 insertions(+), 4 deletions(-) diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index 9a5ec1a32..9e1e1b465 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #define DIALOG_MAX_FORMULA_HEIGHT 64 @@ -1262,6 +1263,8 @@ void TMainWindow::InitWindow() connect(ui->plainTextEditDescription, &QPlainTextEdit::textChanged, this, &TMainWindow::SaveMDescription); connect(ui->lineEditFullName, &QLineEdit::editingFinished, this, &TMainWindow::SaveMFullName); + connect(ui->pushButtonShowInExplorer, &QPushButton::clicked, this, &TMainWindow::ShowInGraphicalShell); + InitTable(); } @@ -1333,13 +1336,13 @@ void TMainWindow::SetCurrentFile(const QString &fileName) shownName += ".vit"; } ui->labelPathToFile->setText(tr("")); - ui->pushButtonShowInFolder->setEnabled(false); + ui->pushButtonShowInExplorer->setEnabled(false); } else { ui->labelPathToFile->setText(curFile); ui->labelPathToFile->setToolTip(curFile); - ui->pushButtonShowInFolder->setEnabled(true); + ui->pushButtonShowInExplorer->setEnabled(true); } shownName += "[*]"; setWindowTitle(shownName); @@ -1654,3 +1657,55 @@ void TMainWindow::SetDecimals() break; } } + +//--------------------------------------------------------------------------------------------------------------------- +void TMainWindow::ShowInGraphicalShell() +{ +#ifdef Q_WS_MAC + QStringList args; + args << "-e"; + args << "tell application \"Finder\""; + args << "-e"; + args << "activate"; + args << "-e"; + args << "select POSIX file \""+curFile+"\""; + args << "-e"; + args << "end tell"; + QProcess::startDetached("osascript", args); +#elif defined(Q_WS_WIN) + QStringList args; + args << "/select," << QDir::toNativeSeparators(curFile); + const QString command = "explorer" + " " + args; + QProcess::startDetached(command); +#else + const QString app = "xdg-open %d"; + QString cmd; + for (int i = 0; i < app.size(); ++i) + { + QChar c = app.at(i); + if (c == QLatin1Char('%') && i < app.size()-1) + { + c = app.at(++i); + QString s; + if (c == QLatin1Char('d')) + { + s = QLatin1Char('"') + QFileInfo(curFile).path() + QLatin1Char('"'); + } + else if (c == QLatin1Char('%')) + { + s = c; + } + else + { + s = QLatin1Char('%'); + s += c; + } + cmd += s; + continue; + } + cmd += c; + } + QProcess::startDetached(cmd); +#endif + +} diff --git a/src/app/tape/tmainwindow.h b/src/app/tape/tmainwindow.h index 924bc0667..45af6c831 100644 --- a/src/app/tape/tmainwindow.h +++ b/src/app/tape/tmainwindow.h @@ -91,6 +91,7 @@ private slots: void ShowMData(); void DeployFormula(); + void ShowInGraphicalShell(); void SaveMName(); void SaveMValue(); diff --git a/src/app/tape/tmainwindow.ui b/src/app/tape/tmainwindow.ui index f5d99bd0f..60acd6b44 100644 --- a/src/app/tape/tmainwindow.ui +++ b/src/app/tape/tmainwindow.ui @@ -433,12 +433,12 @@ - + false - Show in folder + Show in Explorer