Commit a1634b54 authored by Jan Paul Batrina's avatar Jan Paul Batrina
Browse files

Konsole plugin: Simplify tracking of urlChanged

parent 672d7aa0
......@@ -294,7 +294,7 @@ void KateConsole::slotPipeToConsole()
sendInput(v->document()->text());
}
void KateConsole::slotSync(KTextEditor::View *)
void KateConsole::slotSync()
{
if (m_mw->activeView()) {
QUrl u = m_mw->activeView()->document()->url();
......@@ -307,11 +307,15 @@ void KateConsole::slotSync(KTextEditor::View *)
}
}
void KateConsole::slotSync(const KTextEditor::Document *doc) {
const KTextEditor::View *activeView = m_mw->activeView();
if (activeView && activeView->document() == doc) {
slotSync();
void KateConsole::slotViewOrUrlChanged(KTextEditor::View *view)
{
disconnect(m_urlChangedConnection);
if (view) {
KTextEditor::Document *doc = view->document();
m_urlChangedConnection = connect(doc, &KParts::ReadOnlyPart::urlChanged, this, &KateConsole::slotSync);
}
slotSync();
}
void KateConsole::slotManualSync()
......@@ -419,25 +423,11 @@ void KateConsole::slotToggleFocus()
void KateConsole::readConfig()
{
const auto slotSyncView = static_cast<void (KateConsole::*)(KTextEditor::View *)>(&KateConsole::slotSync);
const auto slotSyncDoc = static_cast<void (KateConsole::*)(const KTextEditor::Document *)>(&KateConsole::slotSync);
disconnect(m_mw, &KTextEditor::MainWindow::viewChanged, this, slotSyncView);
disconnect(m_mw, &KTextEditor::MainWindow::viewCreated, this, nullptr);
QList<KTextEditor::View *> views = m_mw->views();
for (KTextEditor::View *view : views) {
disconnect(view->document(), &KTextEditor::Document::documentUrlChanged, this, slotSyncDoc);
}
disconnect(m_mw, &KTextEditor::MainWindow::viewChanged, this, &KateConsole::slotViewOrUrlChanged);
disconnect(m_urlChangedConnection);
if (KConfigGroup(KSharedConfig::openConfig(), "Konsole").readEntry("AutoSyncronize", true)) {
connect(m_mw, &KTextEditor::MainWindow::viewChanged, this, slotSyncView);
// sync path when document url changes (e.g. document is saved or document is opened but viewChanged is not emitted)
for (KTextEditor::View *view : views) {
connect(view->document(), &KTextEditor::Document::documentUrlChanged, this, slotSyncDoc, Qt::UniqueConnection);
}
connect(m_mw, &KTextEditor::MainWindow::viewCreated, this, [this, slotSyncDoc](KTextEditor::View *view) {
connect(view->document(), &KTextEditor::Document::documentUrlChanged, this, slotSyncDoc, Qt::UniqueConnection);
});
connect(m_mw, &KTextEditor::MainWindow::viewChanged, this, &KateConsole::slotViewOrUrlChanged);
}
if (KConfigGroup(KSharedConfig::openConfig(), "Konsole").readEntry("SetEditor", false))
......
......@@ -16,6 +16,7 @@
#include <QKeyEvent>
#include <QList>
#include <QPointer>
#include <KXMLGUIClient>
......@@ -131,8 +132,12 @@ public Q_SLOTS:
/**
* synchronize the konsole with the current document (cd to the directory)
*/
void slotSync(KTextEditor::View *view = nullptr);
void slotSync(const KTextEditor::Document *doc);
void slotSync();
/**
* synchronize the konsole when the current document's url changes (e.g. save as)
*/
void slotViewOrUrlChanged(KTextEditor::View *view = nullptr);
/**
* When syncing is done by the user, also show the terminal if it is hidden
......@@ -196,6 +201,7 @@ private:
KateKonsolePlugin *m_plugin;
QString m_currentPath;
QMetaObject::Connection m_urlChangedConnection;
};
class KateKonsoleConfigPage : public KTextEditor::ConfigPage
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment