Skip to content

Commit

Permalink
Show in File Explorer context menu option (#82)
Browse files Browse the repository at this point in the history
* Add Open in File Explorer in context menu

* Fixed and refactored file explorer option

* Added file explorer translation

* Show in Explorer: Better Linux support
  • Loading branch information
Treeways committed Sep 12, 2023
1 parent 4fcfa2b commit 1fba89c
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 3 deletions.
61 changes: 59 additions & 2 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,17 +526,21 @@ void MainWindow::createLevelListContextMenu(const QPoint &pos)

QAction openLevel(tr("Open In Level Editor"), this);
QAction sarcExplorer(tr("Open In Sarc Explorer"), this);
QAction fileExplorer(tr("Show In File Explorer"), this);
QAction removeLevel(tr("Remove Level"), this);

connect(&openLevel, SIGNAL(triggered()), this, SLOT(openLevelFromConextMenu()));
connect(&sarcExplorer, SIGNAL(triggered()), this, SLOT(openInSarcExplorer()));
connect(&fileExplorer, SIGNAL(triggered()), this, SLOT(showInFileExplorer()));
connect(&removeLevel, SIGNAL(triggered()), this, SLOT(on_removeLevelBtn_clicked()));

openLevel.setData(QVariant(pos));
sarcExplorer.setData(QVariant(pos));
fileExplorer.setData(QVariant(pos));

contextMenu.addAction(&openLevel);
contextMenu.addAction(&sarcExplorer);
contextMenu.addAction(&fileExplorer);
contextMenu.addSeparator();
contextMenu.addAction(&removeLevel);

Expand All @@ -552,17 +556,21 @@ void MainWindow::createTilesetListContextMenu(const QPoint &pos)

QAction openTileset(tr("Open In Tileset Editor"), this);
QAction sarcExplorer(tr("Open In Sarc Explorer"), this);
QAction fileExplorer(tr("Show In File Explorer"), this);
QAction removeTileset(tr("Remove Tileset"), this);

connect(&openTileset, SIGNAL(triggered()), this, SLOT(openTilesetFromConextMenu()));
connect(&sarcExplorer, SIGNAL(triggered()), this, SLOT(openInSarcExplorer()));
connect(&fileExplorer, SIGNAL(triggered()), this, SLOT(showInFileExplorer()));
connect(&removeTileset, SIGNAL(triggered()), this, SLOT(on_removeTilesetBtn_clicked()));

openTileset.setData(QVariant(pos));
sarcExplorer.setData(QVariant(pos));
fileExplorer.setData(QVariant(pos));

contextMenu.addAction(&openTileset);
contextMenu.addAction(&sarcExplorer);
contextMenu.addAction(&fileExplorer);
contextMenu.addSeparator();
contextMenu.addAction(&removeTileset);

Expand Down Expand Up @@ -595,6 +603,56 @@ void MainWindow::openTilesetFromConextMenu()
void MainWindow::openInSarcExplorer()
{
QAction* action = qobject_cast<QAction*>(sender());
QString path = getFilePath(action);

SarcExplorerWindow* sarcExplorer = new SarcExplorerWindow(this, path, settings);
sarcExplorer->show();
}

void MainWindow::showInFileExplorer()
{
QAction* action = qobject_cast<QAction*>(sender());
QString path = getFilePath(action);

QFileInfo info(path);
#if defined(Q_OS_WIN)
QStringList args;
if (!info.isDir())
args << "/select,";
args << QDir::toNativeSeparators(path);
if (QProcess::startDetached("explorer", args))
return;
#elif defined(Q_OS_MAC)
QStringList args;
args << "-e";
args << "tell application \"Finder\"";
args << "-e";
args << "activate";
args << "-e";
args << "select POSIX file \"" + path + "\"";
args << "-e";
args << "end tell";
args << "-e";
args << "return";
if (!QProcess::execute("/usr/bin/osascript", args))
return;
#elif defined(Q_OS_LINUX)
QStringList args;
args << "--session";
args << "--dest=org.freedesktop.FileManager1";
args << "--type=method_call";
args << "/org/freedesktop/FileManager1";
args << "org.freedesktop.FileManager1.ShowItems";
args << "array:string:file://" + path;
args << "string:";
if (QProcess::startDetached("dbus-send", args))
return;
#endif
QDesktopServices::openUrl(QUrl::fromLocalFile(info.isDir()? path : info.path()));
}

QString MainWindow::getFilePath(QAction* action)
{
QPoint pos = action->data().toPoint();

QString path;
Expand All @@ -613,6 +671,5 @@ void MainWindow::openInSarcExplorer()
if (!path.endsWith(".sarc"))
path.append(".sarc");

SarcExplorerWindow* sarcExplorer = new SarcExplorerWindow(this, path, settings);
sarcExplorer->show();
return path;
}
4 changes: 4 additions & 0 deletions mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ private slots:
void openTilesetFromConextMenu();

void openInSarcExplorer();

void showInFileExplorer();

private:
Ui::MainWindow *ui;
Expand All @@ -102,6 +104,8 @@ private slots:
void setNightmode(bool nightmode);

void changeEvent(QEvent* event);

QString getFilePath(QAction* action);
};

#endif // MAINWINDOW_H
2 changes: 1 addition & 1 deletion mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@
<x>0</x>
<y>0</y>
<width>436</width>
<height>22</height>
<height>21</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
Expand Down
4 changes: 4 additions & 0 deletions resource/translations/English.ts
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,10 @@ Connection to %1 failed!</source>
<source>Open In Tileset Editor</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Show In File Explorer</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>File</source>
<translation type="unfinished"></translation>
Expand Down

0 comments on commit 1fba89c

Please sign in to comment.