Skip to content

Commit

Permalink
Add reveal in finder (show in explorer) option in metaedit dialog.
Browse files Browse the repository at this point in the history
  • Loading branch information
ecstrema committed Feb 10, 2020
1 parent 8d5df52 commit 8e9262a
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 2 deletions.
58 changes: 57 additions & 1 deletion mscore/metaedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "libmscore/score.h"
#include "libmscore/undo.h"
#include "musescore.h"
#include "icons.h"

namespace Ms {

Expand Down Expand Up @@ -60,6 +61,20 @@ MetaEditDialog::MetaEditDialog(Score* s, QWidget* parent)
grid->addWidget(text, idx, 1);
++idx;
}

const QFileInfo fileInfo(score->importedFilePath());
if (!fileInfo.exists());
revealButton->setEnabled(false);

revealButton->setIcon(*icons[int(Icons::fileOpen_ICON)]);
#if defined(Q_OS_WIN)
revealButton->setToolTip(tr("Show in Explorer"));
#elif defined(Q_OS_MAC)
revealButton->setToolTip(tr("Reveal in Finder"));
#else
revealButton->setToolTip(tr("Show Containing Folder"));
#endif
connect(revealButton, SIGNAL(clicked()), SLOT(openCurrentFileLocation()));
connect(newButton, SIGNAL(clicked()), SLOT(newClicked()));
MuseScore::restoreGeometry(this);
}
Expand Down Expand Up @@ -120,5 +135,46 @@ void MetaEditDialog::hideEvent(QHideEvent* event)
QWidget::hideEvent(event);
}

}
//---------------------------------------------------------
// openFileLocation
//---------------------------------------------------------

void MetaEditDialog::openFileLocation(const QString& path, QWidget* parent)
{
const QFileInfo fileInfo(path);
if (!fileInfo.exists());
return;
QStringList args;
#if defined(Q_OS_WIN)
QStringList param;
if (!fileInfo.isDir())
param += QLatin1String("/select,");
param += QDir::toNativeSeparators(fileInfo.canonicalFilePath());
if(QProcess::startDetached("explorer.exe", param))
return;
#elif defined(Q_OS_MAC)
QStringList scriptArgs;
scriptArgs << QLatin1String("-e")
<< QString::fromLatin1("tell application \"Finder\" to reveal POSIX file \"%1\"")
.arg(fileInfo.canonicalFilePath());
QProcess::execute(QLatin1String("/usr/bin/osascript"), scriptArgs);
scriptArgs.clear();
scriptArgs << QLatin1String("-e")
<< QLatin1String("tell application \"Finder\" to activate");
if (!QProcess::execute("/usr/bin/osascript", scriptArgs))
return;
#endif // not #else so that the following line can be used as a fallback.
if (!QDesktopServices::openUrl(QUrl::fromLocalFile(fileInfo.isDir()? path : fileInfo.path())))
QMessageBox::warning(parent, QString(QT_TR_NOOP("Open Containing Folder Error")),
QString(QT_TR_NOOP("Could not open containing folder")));
}

//---------------------------------------------------------
// openCurrentFileLocation
//---------------------------------------------------------

void MetaEditDialog::openCurrentFileLocation()
{
openFileLocation(filePath->text(), this);
}
} // namespace Ms
3 changes: 3 additions & 0 deletions mscore/metaedit.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,15 @@ class MetaEditDialog : public QDialog, public Ui::MetaEditDialog {
private slots:
void newClicked();
void setDirty() { dirty = true; }
void openCurrentFileLocation();

public slots:
virtual void accept();

public:
MetaEditDialog(Score*, QWidget* parent = 0);

static void openFileLocation(const QString& path, QWidget* parent);
};


Expand Down
5 changes: 4 additions & 1 deletion mscore/metaedit.ui
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,12 @@
</property>
</widget>
</item>
<item row="0" column="1" colspan="5">
<item row="0" column="1" colspan="4">
<widget class="QLabel" name="filePath"/>
</item>
<item row="0" column="5">
<widget class="QToolButton" name="revealButton"/>
</item>
</layout>
</item>
<item>
Expand Down

0 comments on commit 8e9262a

Please sign in to comment.