Commit eec53984 authored by con's avatar con

Prevent deletion of find tool bar when place holder is deleted.

This happens for example when removing a split editor.
parent 51f20d40
......@@ -40,7 +40,7 @@ using namespace Core;
FindToolBarPlaceHolder *FindToolBarPlaceHolder::m_current = 0;
FindToolBarPlaceHolder::FindToolBarPlaceHolder(QWidget *owner, QWidget *parent)
: QWidget(parent), m_widget(owner)
: QWidget(parent), m_owner(owner), m_subWidget(0)
{
setLayout(new QVBoxLayout);
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
......@@ -51,11 +51,28 @@ FindToolBarPlaceHolder::FindToolBarPlaceHolder(QWidget *owner, QWidget *parent)
FindToolBarPlaceHolder::~FindToolBarPlaceHolder()
{
ExtensionSystem::PluginManager::instance()->removeObject(this);
if (m_subWidget) {
m_subWidget->setVisible(false);
m_subWidget->setParent(0);
}
if (m_current == this)
m_current = 0;
}
QWidget *FindToolBarPlaceHolder::widget() const
QWidget *FindToolBarPlaceHolder::owner() const
{
return m_widget;
return m_owner;
}
void FindToolBarPlaceHolder::setWidget(QWidget *widget)
{
if (m_subWidget) {
m_subWidget->setVisible(false);
m_subWidget->setParent(0);
}
m_subWidget = widget;
if (m_subWidget)
layout()->addWidget(m_subWidget);
}
FindToolBarPlaceHolder *FindToolBarPlaceHolder::getCurrent()
......
......@@ -31,6 +31,8 @@
#define FINDPLACEHOLDER_H
#include "core_global.h"
#include <QtCore/QPointer>
#include <QtGui/QWidget>
namespace Core {
......@@ -43,13 +45,15 @@ class CORE_EXPORT FindToolBarPlaceHolder : public QWidget
public:
FindToolBarPlaceHolder(QWidget *owner, QWidget *parent = 0);
~FindToolBarPlaceHolder();
QWidget *widget() const;
QWidget *owner() const;
void setWidget(QWidget *widget);
static FindToolBarPlaceHolder *getCurrent();
static void setCurrent(FindToolBarPlaceHolder *placeHolder);
private:
QWidget *m_widget;
QWidget *m_owner;
QPointer<QWidget> m_subWidget;
static FindToolBarPlaceHolder *m_current;
};
......
......@@ -107,6 +107,7 @@ void FindPlugin::extensionsInitialized()
void FindPlugin::shutdown()
{
m_findToolBar->setVisible(false);
m_findToolBar->setParent(0);
m_currentDocumentFind->removeConnections();
writeSettings();
......
......@@ -264,14 +264,6 @@ bool FindToolBar::eventFilter(QObject *obj, QEvent *event)
return Core::Utils::StyledBar::eventFilter(obj, event);
}
void FindToolBar::removeFromParent()
{
setVisible(false);
setParent(0);
Core::FindToolBarPlaceHolder::setCurrent(0);
}
void FindToolBar::adaptToCandidate()
{
updateFindAction();
......@@ -534,7 +526,7 @@ Core::FindToolBarPlaceHolder *FindToolBar::findToolBarPlaceHolder() const
QWidget *candidate = QApplication::focusWidget();
while (candidate) {
foreach (Core::FindToolBarPlaceHolder *ph, placeholders) {
if (ph->widget() == candidate)
if (ph->owner() == candidate)
return ph;
}
candidate = candidate->parentWidget();
......@@ -551,11 +543,10 @@ void FindToolBar::openFind()
return;
Core::FindToolBarPlaceHolder *previousHolder = Core::FindToolBarPlaceHolder::getCurrent();
if (previousHolder)
disconnect(previousHolder, SIGNAL(destroyed(QObject*)), this, SLOT(removeFromParent()));
previousHolder->setWidget(0);
Core::FindToolBarPlaceHolder::setCurrent(holder);
connect(holder, SIGNAL(destroyed(QObject*)), this, SLOT(removeFromParent()));
m_currentDocumentFind->acceptCandidate();
holder->layout()->addWidget(this);
holder->setWidget(this);
holder->setVisible(true);
setVisible(true);
setFocus();
......
......@@ -84,7 +84,7 @@ private slots:
void setRegularExpressions(bool regexp);
void adaptToCandidate();
void removeFromParent();
protected:
bool focusNextPrevChild(bool next);
......
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