diff options
Diffstat (limited to 'src/panels/terminal')
| -rw-r--r-- | src/panels/terminal/terminalpanel.cpp | 31 | ||||
| -rw-r--r-- | src/panels/terminal/terminalpanel.h | 5 |
2 files changed, 32 insertions, 4 deletions
diff --git a/src/panels/terminal/terminalpanel.cpp b/src/panels/terminal/terminalpanel.cpp index 92ba18bf5..a357b31ac 100644 --- a/src/panels/terminal/terminalpanel.cpp +++ b/src/panels/terminal/terminalpanel.cpp @@ -31,6 +31,7 @@ TerminalPanel::TerminalPanel(QWidget *parent) : Panel(parent) , m_clearTerminal(true) + , m_syncUrl(true) , m_mostLocalUrlJob(nullptr) , m_layout(nullptr) , m_terminal(nullptr) @@ -40,6 +41,7 @@ TerminalPanel::TerminalPanel(QWidget *parent) , m_konsolePartCurrentDirectory() , m_sendCdToTerminalHistory() , m_kiofuseInterface(QStringLiteral("org.kde.KIOFuse"), QStringLiteral("/org/kde/KIOFuse"), QDBusConnection::sessionBus()) + , m_switchTerminalUrlSyncAction(nullptr) { m_layout = new QVBoxLayout(this); m_layout->setContentsMargins(0, 0, 0, 0); @@ -102,6 +104,16 @@ void TerminalPanel::dockVisibilityChanged() } } +void TerminalPanel::switchSync(bool syncUrl) +{ + m_syncUrl = syncUrl; +} + +void TerminalPanel::setSwitchTerminalUrlSyncAction(QAction *urlToggle) +{ + m_switchTerminalUrlSyncAction = urlToggle; +} + QString TerminalPanel::runningProgramName() const { return m_terminal ? m_terminal->foregroundProcessName() : QString(); @@ -133,7 +145,7 @@ bool TerminalPanel::urlChanged() return false; } - const bool sendInput = m_terminal && !hasProgramRunning() && isVisible(); + const bool sendInput = m_terminal && !hasProgramRunning() && isVisible() && m_syncUrl; if (sendInput) { changeDir(url()); } @@ -178,6 +190,10 @@ void TerminalPanel::showEvent(QShowEvent *event) }); } + const QList<QAction *> additional = {m_switchTerminalUrlSyncAction}; + + QMetaObject::invokeMethod(m_konsolePart, "setContextMenuAdditionalActions", Q_ARG(QList<QAction *>, additional)); + } else { if (!m_konsolePartMissingMessage) { const auto konsoleInstallUrl = QUrl("appstream://org.kde.konsole.desktop"); @@ -242,6 +258,13 @@ void TerminalPanel::changeDir(const QUrl &url) sendCdToTerminalKIOFuse(url); } +void TerminalPanel::emitUrlChanged(const QUrl &url) +{ + if (m_syncUrl) { + Q_EMIT changeUrl(url); + } +} + void TerminalPanel::sendCdToTerminal(const QString &dir, HistoryPolicy addToHistory) { if (dir == m_konsolePartCurrentDirectory // We are already there @@ -320,7 +343,7 @@ void TerminalPanel::slotKonsolePartCurrentDirectoryChanged(const QString &dir) KMountPoint::Ptr mountPoint = KMountPoint::currentMountPoints().findByPath(m_konsolePartCurrentDirectory); if (mountPoint && mountPoint->mountType() != QStringLiteral("fuse.kio-fuse")) { // Not in KIOFUse mount, so just switch to the corresponding URL. - Q_EMIT changeUrl(url); + emitUrlChanged(url); return; } @@ -330,11 +353,11 @@ void TerminalPanel::slotKonsolePartCurrentDirectoryChanged(const QString &dir) watcher->deleteLater(); if (reply.isError()) { // KIOFuse errored out... just show the normal URL - Q_EMIT changeUrl(url); + emitUrlChanged(url); } else { // Our location happens to be in a KIOFuse mount and is mounted. // Let's change the DolphinView to point to the remote URL equivalent. - Q_EMIT changeUrl(QUrl::fromUserInput(reply.value())); + emitUrlChanged(QUrl::fromUserInput(reply.value())); } }); } diff --git a/src/panels/terminal/terminalpanel.h b/src/panels/terminal/terminalpanel.h index 8eee3c10f..0aaf921c0 100644 --- a/src/panels/terminal/terminalpanel.h +++ b/src/panels/terminal/terminalpanel.h @@ -55,6 +55,8 @@ public: public Q_SLOTS: void terminalExited(); void dockVisibilityChanged(); + void switchSync(bool syncUrl); + void setSwitchTerminalUrlSyncAction(QAction *urlToggle); Q_SIGNALS: void hideTerminalPanel(); @@ -77,11 +79,13 @@ private: enum class HistoryPolicy { AddToHistory, SkipHistory }; void changeDir(const QUrl &url); + void emitUrlChanged(const QUrl &url); void sendCdToTerminal(const QString &path, HistoryPolicy addToHistory = HistoryPolicy::AddToHistory); void sendCdToTerminalKIOFuse(const QUrl &url); private: bool m_clearTerminal; + bool m_syncUrl; KIO::StatJob *m_mostLocalUrlJob; QVBoxLayout *m_layout; @@ -92,6 +96,7 @@ private: QString m_konsolePartCurrentDirectory; QQueue<QString> m_sendCdToTerminalHistory; org::kde::KIOFuse::VFS m_kiofuseInterface; + QAction *m_switchTerminalUrlSyncAction; }; #endif // TERMINALPANEL_H |
