Skip to content

Commit b1b9e34

Browse files
Open containing folder for editor tabs
1 parent 070acd4 commit b1b9e34

5 files changed

Lines changed: 49 additions & 31 deletions

File tree

src/ui/FileSystemBrowser.cpp

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include "src/ui/MainWindow.h"
66
#include "src/util/Utils.h"
77
#include "src/editors/EditorBase.h"
8-
#include "src/Application.h"
98
#include <qaction.h>
109
#include <qmenu.h>
1110
#include <qevent.h>
@@ -35,33 +34,18 @@ FileSystemBrowser::~FileSystemBrowser()
3534
delete ui;
3635
}
3736

38-
void FileSystemBrowser::createActions(Application& app)
39-
{
40-
app.getOrCreateShortcutSettingsSection("global", "Global");
41-
42-
#ifdef Q_OS_WIN
43-
const QString showInOSName = "Open in Explorer";
44-
#elif Q_OS_MAC
45-
const QString showInOSName = "Reveal in Finder";
46-
#else
47-
const QString showInOSName = "Open in a file manager";
48-
#endif
49-
app.registerAction("global", "show_in_os", showInOSName,
50-
"Opens a file folder in an OS file manager",
51-
QIcon(), QKeySequence(), false);
52-
}
53-
5437
void FileSystemBrowser::setupContextMenu()
5538
{
5639
setContextMenuPolicy(Qt::DefaultContextMenu);
5740

58-
Application* app = qobject_cast<Application*>(qApp);
59-
60-
auto actionShowInOS = app->getAction("global/show_in_os");
61-
connect(actionShowInOS, &QAction::triggered, this, &FileSystemBrowser::showFileInOS);
41+
QAction* actionOpenContainingFolder = new QAction(this);
42+
actionOpenContainingFolder->setText("Open Containing Folder");
43+
actionOpenContainingFolder->setToolTip("Opens a file folder in an OS file manager");
44+
actionOpenContainingFolder->setStatusTip("Opens a file folder in an OS file manager");
45+
connect(actionOpenContainingFolder, &QAction::triggered, this, &FileSystemBrowser::openContainingFolderForSelection);
6246

6347
contextMenu = new QMenu(this);
64-
contextMenu->addAction(actionShowInOS);
48+
contextMenu->addAction(actionOpenContainingFolder);
6549
}
6650

6751
void FileSystemBrowser::contextMenuEvent(QContextMenuEvent* event)
@@ -71,7 +55,7 @@ void FileSystemBrowser::contextMenuEvent(QContextMenuEvent* event)
7155
contextMenu->exec(event->globalPos());
7256
}
7357

74-
void FileSystemBrowser::showFileInOS()
58+
void FileSystemBrowser::openContainingFolderForSelection()
7559
{
7660
auto selection = ui->view->selectionModel()->selectedIndexes();
7761
for (auto modelIndex : selection)

src/ui/FileSystemBrowser.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,15 @@ class FileSystemBrowser;
1414

1515
class QToolButton;
1616
class QMenu;
17-
class Application;
1817

1918
class FileSystemBrowser : public QDockWidget
2019
{
2120
Q_OBJECT
2221

2322
public:
2423

25-
static void createActions(Application& app);
26-
2724
explicit FileSystemBrowser(QWidget *parent = nullptr);
28-
~FileSystemBrowser();
25+
virtual ~FileSystemBrowser() override;
2926

3027
void setDirectory(const QString& dir);
3128

@@ -55,7 +52,7 @@ private slots:
5552
virtual void contextMenuEvent(QContextMenuEvent* event) override;
5653

5754
void setupContextMenu();
58-
void showFileInOS();
55+
void openContainingFolderForSelection();
5956

6057
Ui::FileSystemBrowser *ui;
6158
QMenu* contextMenu = nullptr;

src/ui/MainWindow.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "src/util/Settings.h"
1515
#include "src/util/SettingsEntry.h"
1616
#include "src/util/RecentlyUsed.h"
17+
#include "src/util/Utils.h"
1718
#include "src/cegui/CEGUIManager.h"
1819
#include "src/cegui/CEGUIProject.h"
1920
#include "src/editors/NoEditor.h"
@@ -85,7 +86,6 @@ MainWindow::MainWindow(QWidget *parent) :
8586
connect(projectManager, &ProjectManager::itemOpenRequested, this, &MainWindow::openEditorTab);
8687
addDockWidget(Qt::DockWidgetArea::LeftDockWidgetArea, projectManager);
8788

88-
FileSystemBrowser::createActions(*qobject_cast<Application*>(qApp));
8989
fsBrowser = new FileSystemBrowser(this);
9090
//fsBrowser->setVisible(false);
9191
connect(fsBrowser, &FileSystemBrowser::fileOpenRequested, this, &MainWindow::openEditorTab);
@@ -603,6 +603,8 @@ void MainWindow::slot_tabBarCustomContextMenuRequested(const QPoint& pos)
603603
menu->addSeparator();
604604
menu->addAction(ui->actionCloseOtherTabs);
605605
menu->addAction(ui->actionCloseAllTabs);
606+
menu->addSeparator();
607+
menu->addAction(ui->actionOpenContainingFolder);
606608

607609
/*
608610
if (tabIdx >= 0)
@@ -660,6 +662,7 @@ void MainWindow::on_tabs_currentChanged(int index)
660662
ui->actionSaveAs->setEnabled(hasEditor);
661663
ui->actionCloseTab->setEnabled(hasEditor);
662664
ui->actionCloseOtherTabs->setEnabled(hasEditor);
665+
ui->actionOpenContainingFolder->setEnabled(hasEditor);
663666

664667
if (currentEditor)
665668
{
@@ -767,6 +770,12 @@ void MainWindow::on_actionCloseAllTabs_triggered()
767770
}
768771
}
769772

773+
void MainWindow::on_actionOpenContainingFolder_triggered()
774+
{
775+
if (auto editor = getEditorForTab(ui->tabs->currentWidget()))
776+
Utils::showInGraphicalShell(editor->getFilePath());
777+
}
778+
770779
void MainWindow::on_actionPreviousTab_triggered()
771780
{
772781
if (ui->tabs->count() < 2) return;

src/ui/MainWindow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ private slots:
8383
void on_actionCloseTab_triggered();
8484
void on_actionCloseOtherTabs_triggered();
8585
void on_actionCloseAllTabs_triggered();
86+
void on_actionOpenContainingFolder_triggered();
8687
void on_actionPreviousTab_triggered();
8788
void on_actionNextTab_triggered();
8889
void on_actionZoomIn_triggered();

ui/MainWindow.ui

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@
200200
<addaction name="separator"/>
201201
<addaction name="actionCloseOtherTabs"/>
202202
<addaction name="actionCloseAllTabs"/>
203+
<addaction name="separator"/>
204+
<addaction name="actionOpenContainingFolder"/>
203205
</widget>
204206
<widget class="QMenu" name="menuEditor">
205207
<property name="enabled">
@@ -306,7 +308,10 @@
306308
<normaloff>:/icons/actions/close_other_tabs.png</normaloff>:/icons/actions/close_other_tabs.png</iconset>
307309
</property>
308310
<property name="text">
309-
<string>Close Other</string>
311+
<string>Close Other Tabs</string>
312+
</property>
313+
<property name="toolTip">
314+
<string>Close Other Tabs</string>
310315
</property>
311316
<property name="shortcut">
312317
<string>Ctrl+Shift+F4</string>
@@ -318,7 +323,10 @@
318323
<normaloff>:/icons/actions/close_all_tabs.png</normaloff>:/icons/actions/close_all_tabs.png</iconset>
319324
</property>
320325
<property name="text">
321-
<string>Close All</string>
326+
<string>Close All Tabs</string>
327+
</property>
328+
<property name="toolTip">
329+
<string>Close All Tabs</string>
322330
</property>
323331
<property name="shortcut">
324332
<string>Ctrl+F4</string>
@@ -701,6 +709,25 @@
701709
<string>CEGUI Debug Info</string>
702710
</property>
703711
</action>
712+
<action name="actionOpenContainingFolder">
713+
<property name="enabled">
714+
<bool>false</bool>
715+
</property>
716+
<property name="text">
717+
<string>Open Containing Folder</string>
718+
</property>
719+
<property name="toolTip">
720+
<string>Opens a file folder in an OS file manager</string>
721+
</property>
722+
</action>
723+
<action name="actionTabCopyFullPath">
724+
<property name="text">
725+
<string>Copy Full Path</string>
726+
</property>
727+
<property name="toolTip">
728+
<string>Copy the full file path to the clipboard</string>
729+
</property>
730+
</action>
704731
</widget>
705732
<resources>
706733
<include location="../data/Resources.qrc"/>

0 commit comments

Comments
 (0)