1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 02:36:34 +01:00

SideBarManager: Remove interfaces by pointer not id

This commit is contained in:
David Rosca 2018-02-26 20:28:34 +01:00
parent 791c9f6b1d
commit abd30880a5
No known key found for this signature in database
GPG Key ID: EBC3FC294452C6D8
7 changed files with 17 additions and 7 deletions

View File

@ -137,8 +137,13 @@ void SideBarManager::addSidebar(const QString &id, SideBarInterface* interface)
s_sidebars[id] = interface; s_sidebars[id] = interface;
} }
void SideBarManager::removeSidebar(const QString &id) void SideBarManager::removeSidebar(SideBarInterface *interface)
{ {
const QString id = s_sidebars.key(interface);
if (id.isEmpty()) {
return;
}
s_sidebars.remove(id); s_sidebars.remove(id);
foreach (BrowserWindow* window, mApp->windows()) { foreach (BrowserWindow* window, mApp->windows()) {

View File

@ -69,7 +69,7 @@ public:
void closeSideBar(); void closeSideBar();
static void addSidebar(const QString &id, SideBarInterface* interface); static void addSidebar(const QString &id, SideBarInterface* interface);
static void removeSidebar(const QString &id); static void removeSidebar(SideBarInterface *interface);
private Q_SLOTS: private Q_SLOTS:
void slotShowSideBar(); void slotShowSideBar();

View File

@ -163,7 +163,7 @@ void TabManagerPlugin::setTabBarVisible(bool visible)
void TabManagerPlugin::removeManagerWidget() void TabManagerPlugin::removeManagerWidget()
{ {
if (viewType() == ShowAsSideBar) { if (viewType() == ShowAsSideBar) {
SideBarManager::removeSidebar("TabManager"); SideBarManager::removeSidebar(m_controller);
} }
else if (viewType() == ShowAsWindow) { else if (viewType() == ShowAsWindow) {
// remove statusbar icon // remove statusbar icon

View File

@ -68,7 +68,8 @@ void TestPlugin::init(InitState state, const QString &settingsPath)
mApp->plugins()->registerAppEventHandler(PluginProxy::MousePressHandler, this); mApp->plugins()->registerAppEventHandler(PluginProxy::MousePressHandler, this);
// Adding new sidebar into application // Adding new sidebar into application
SideBarManager::addSidebar("testplugin-sidebar", new TestPlugin_Sidebar(this)); m_sideBar = new TestPlugin_Sidebar(this);
SideBarManager::addSidebar("testplugin-sidebar", m_sideBar);
} }
void TestPlugin::unload() void TestPlugin::unload()
@ -79,7 +80,8 @@ void TestPlugin::unload()
// it will be also called if we return false from testPlugin() // it will be also called if we return false from testPlugin()
// Removing sidebar from application // Removing sidebar from application
SideBarManager::removeSidebar("testplugin-sidebar"); SideBarManager::removeSidebar(m_sideBar);
delete m_sideBar;
// Deleting settings dialog if opened // Deleting settings dialog if opened
delete m_settings.data(); delete m_settings.data();

View File

@ -26,6 +26,8 @@
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QPointer> #include <QPointer>
class TestPlugin_Sidebar;
class TestPlugin : public QObject, public PluginInterface class TestPlugin : public QObject, public PluginInterface
{ {
Q_OBJECT Q_OBJECT
@ -53,6 +55,7 @@ private:
WebView* m_view; WebView* m_view;
QString m_settingsPath; QString m_settingsPath;
TestPlugin_Sidebar *m_sideBar = nullptr;
}; };
#endif // TESTPLUGIN_H #endif // TESTPLUGIN_H

View File

@ -80,7 +80,7 @@ void VerticalTabsPlugin::unload()
{ {
setTabBarVisible(true); setTabBarVisible(true);
SideBarManager::removeSidebar(QSL("VerticalTabs")); SideBarManager::removeSidebar(m_controller);
delete m_controller; delete m_controller;
m_controller = nullptr; m_controller = nullptr;

View File

@ -41,7 +41,7 @@ class HelloPlugin(Falkon.PluginInterface, QtCore.QObject):
def unload(self): def unload(self):
print("unload") print("unload")
Falkon.SideBarManager.removeSidebar("hellopython-sidebar") Falkon.SideBarManager.removeSidebar(self.sidebar)
for window in Falkon.MainApplication.instance().windows(): for window in Falkon.MainApplication.instance().windows():
self.mainWindowDeleted(window) self.mainWindowDeleted(window)