Commit 97f949ee authored by Ahmad Samir's avatar Ahmad Samir Committed by Tomaz Canabrava
Browse files

SSHManagerPlugin: pass MainWindow* as an arg to activeViewChanged()

Also use a std::vector to hold the plugins associated with a MainWindow,
implicit sharing isn't needed in this use-case.
parent 0776e625
Pipeline #99938 passed with stage
in 1 minute and 54 seconds
......@@ -257,6 +257,10 @@ void MainWindow::activeViewChanged(SessionController *controller)
// Update window icon to newly activated session's icon
updateWindowIcon();
for (IKonsolePlugin *plugin : _plugins) {
plugin->activeViewChanged(controller, this);
}
}
void MainWindow::activeViewTitleChanged(ViewProperties *properties)
......@@ -470,8 +474,8 @@ void MainWindow::newTab()
void MainWindow::addPlugin(IKonsolePlugin *plugin)
{
_plugins.append(plugin);
connect(_viewManager, &Konsole::ViewManager::activeViewChanged, plugin, &IKonsolePlugin::activeViewChanged);
Q_ASSERT(std::find(_plugins.cbegin(), _plugins.cend(), plugin) == _plugins.cend());
_plugins.push_back(plugin);
}
void MainWindow::cloneTab()
......
......@@ -22,6 +22,8 @@
#include "konsole_export.h"
#include <vector>
class QAction;
class KActionMenu;
class KToggleAction;
......@@ -204,7 +206,7 @@ private:
KActionMenu *_newTabMenuAction;
QPointer<SessionController> _pluggedController;
QList<IKonsolePlugin *> _plugins;
std::vector<IKonsolePlugin *> _plugins;
bool _blurEnabled = false;
bool _firstShowEvent = true;
......
......@@ -75,37 +75,14 @@ QList<QAction *> SSHManagerPlugin::menuBarActions(Konsole::MainWindow *mainWindo
return {toggleVisibilityAction};
}
void SSHManagerPlugin::activeViewChanged(Konsole::SessionController *controller)
void SSHManagerPlugin::activeViewChanged(Konsole::SessionController *controller, Konsole::MainWindow *mainWindow)
{
activeViewChangedInternal(QPointer(controller));
}
void SSHManagerPlugin::activeViewChangedInternal(QPointer<Konsole::SessionController> controller)
{
if (!controller) {
qCWarning(KonsoleDebug) << "Active view changed, but no controller";
return;
}
Q_ASSERT(controller);
Q_ASSERT(mainWindow);
if (!controller->view()) {
qCWarning(KonsoleDebug) << controller << "does not have a view";
return;
if (mainWindow) {
d->widgetForWindow[mainWindow]->setCurrentController(controller);
}
auto mainWindow = qobject_cast<Konsole::MainWindow *>(controller->view()->topLevelWidget());
// HACK: if we don't get a mainwindow here this *might* be just opening, call it again
// later on.
// We really shouldn't use an arbitrary time delay, and we need to use a
// QPointer in case it gets deleted while the timer is running.
if (!mainWindow) {
QTimer::singleShot(500, this, [this, controller] {
activeViewChangedInternal(controller);
});
return;
}
d->widgetForWindow[mainWindow]->setCurrentController(controller);
}
#include "sshmanagerplugin.moc"
......@@ -28,12 +28,9 @@ public:
~SSHManagerPlugin() override;
void createWidgetsForMainWindow(Konsole::MainWindow *mainWindow) override;
void activeViewChanged(Konsole::SessionController *controller) override;
void activeViewChanged(Konsole::SessionController *controller, Konsole::MainWindow *mainWindow) override;
QList<QAction *> menuBarActions(Konsole::MainWindow *mainWindow) const override;
private Q_SLOTS:
void activeViewChangedInternal(QPointer<Konsole::SessionController> controller);
private:
std::unique_ptr<SSHManagerPluginPrivate> d;
};
......
......@@ -40,7 +40,7 @@ public:
void removeMainWindow(Konsole::MainWindow *mainWindow);
virtual void createWidgetsForMainWindow(Konsole::MainWindow *mainWindow) = 0;
virtual void activeViewChanged(Konsole::SessionController *controller) = 0;
virtual void activeViewChanged(Konsole::SessionController *controller, Konsole::MainWindow *mainWindow) = 0;
virtual QList<QAction *> menuBarActions(Konsole::MainWindow *mainWindow) const
{
......
Supports Markdown
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