From efb565a1497860a8af18dd1c97d81ec79a3dce93 Mon Sep 17 00:00:00 2001 From: FrostyBee Date: Mon, 19 Aug 2024 15:46:48 -0400 Subject: [PATCH] Add show the currently opened .tex document in file explorer (#1752) (#3770) --- src/editors.cpp | 39 +++++++++++++++++++++++++++++++++++++++ src/editors.h | 2 ++ 2 files changed, 41 insertions(+) diff --git a/src/editors.cpp b/src/editors.cpp index 7659d160f7..839045c567 100644 --- a/src/editors.cpp +++ b/src/editors.cpp @@ -404,8 +404,16 @@ void Editors::tabBarContextMenu(const QPoint &point) act = menu.addAction((splitter->orientation() == Qt::Horizontal) ? tr("Split Vertically") : tr("Split Horizontally")); connect(act, SIGNAL(triggered()), SLOT(changeSplitOrientation())); + menu.addSeparator(); if (editorUnderCursor) { + act = menu.addAction(tr("Copy file path")); + act->setData(QVariant::fromValue(editorUnderCursor->getDocument())); + connect(act, SIGNAL(triggered()), SLOT(copyFilePath())); + // Open the containing folder of the currently opened document. + act = menu.addAction(msgGraphicalShellAction()); + act->setData(QVariant::fromValue(editorUnderCursor->getDocument())); + connect(act, SIGNAL(triggered()), SLOT(showInGraphicalShell_())); menu.addSeparator(); QString text = tr("Set Read-Only"); if (editorUnderCursor->editor->isReadOnly()) @@ -432,6 +440,37 @@ void Editors::onEditorChangeByTabClick(LatexEditorView *from, LatexEditorView *t emit editorAboutToChangeByTabClick(currentEditor(), to); } + +/*! + * \brief copy file path of document to clipboard + * + * Called from the tab's context menu of the currently opened document + */ +void Editors::copyFilePath() +{ + QAction *action = qobject_cast(sender()); + if (!action) return; + LatexDocument *document = qvariant_cast(action->data()); + if (!document) return; + QClipboard* clipboard = QGuiApplication::clipboard(); + if (!clipboard) return; + clipboard->setText(document->getFileInfo().absoluteFilePath()); +} +/*! + * \brief open directory in external explorer + * + * Called from the tab's context menu of the currently opened document + */ + +void Editors::showInGraphicalShell_() +{ + QAction *action = qobject_cast(sender()); + if (!action) return; + LatexDocument *document = qvariant_cast(action->data()); + if (!document) return; + showInGraphicalShell(this, document->getFileName()); +} + /*! * Called from and action with data() set to an editor. Moves the editor to the other tabGroup. * This currently assumes a restriction to two tab groups. diff --git a/src/editors.h b/src/editors.h index cc70e6e8b2..c7e94c4a9e 100644 --- a/src/editors.h +++ b/src/editors.h @@ -63,6 +63,8 @@ protected slots: void moveAllToOtherTabGroup(); void moveAllOthersToOtherTabGroup(); void moveToTabGroup(LatexEditorView *edView, TxsTabWidget *target, int targetIndex); + void showInGraphicalShell_(); + void copyFilePath(); protected: TxsTabWidget *tabWidgetFromEditor(LatexEditorView *edView) const;