Commit 878bb9f9 authored by Leandro Melo's avatar Leandro Melo
Browse files

Make type hierarchy widget reusable accross editors.

parent 2d683cd2
...@@ -168,6 +168,19 @@ CppTypeHierarchyWidget::~CppTypeHierarchyWidget() ...@@ -168,6 +168,19 @@ CppTypeHierarchyWidget::~CppTypeHierarchyWidget()
delete m_delegate; delete m_delegate;
} }
bool CppTypeHierarchyWidget::handleReplacement(Core::IEditor *editor)
{
if (CPPEditorEditable *cppEditable = qobject_cast<CPPEditorEditable *>(editor)) {
if (m_cppEditor) {
m_cppEditor = static_cast<CPPEditor *>(cppEditable->widget());
return true;
}
} else if (!m_cppEditor) {
return true;
}
return false;
}
void CppTypeHierarchyWidget::perform() void CppTypeHierarchyWidget::perform()
{ {
if (!m_cppEditor) if (!m_cppEditor)
...@@ -228,11 +241,13 @@ CppTypeHierarchyStackedWidget::~CppTypeHierarchyStackedWidget() ...@@ -228,11 +241,13 @@ CppTypeHierarchyStackedWidget::~CppTypeHierarchyStackedWidget()
void CppTypeHierarchyStackedWidget::editorChanged(Core::IEditor *editor) void CppTypeHierarchyStackedWidget::editorChanged(Core::IEditor *editor)
{ {
CppTypeHierarchyWidget *replacement = new CppTypeHierarchyWidget(editor); if (!m_typeHiearchyWidgetInstance->handleReplacement(editor)) {
removeWidget(m_typeHiearchyWidgetInstance); CppTypeHierarchyWidget *replacement = new CppTypeHierarchyWidget(editor);
m_typeHiearchyWidgetInstance->deleteLater(); removeWidget(m_typeHiearchyWidgetInstance);
m_typeHiearchyWidgetInstance = replacement; m_typeHiearchyWidgetInstance->deleteLater();
addWidget(m_typeHiearchyWidgetInstance); m_typeHiearchyWidgetInstance = replacement;
addWidget(m_typeHiearchyWidgetInstance);
}
} }
// CppTypeHierarchyFactory // CppTypeHierarchyFactory
......
...@@ -92,6 +92,8 @@ public: ...@@ -92,6 +92,8 @@ public:
CppTypeHierarchyWidget(Core::IEditor *editor); CppTypeHierarchyWidget(Core::IEditor *editor);
virtual ~CppTypeHierarchyWidget(); virtual ~CppTypeHierarchyWidget();
bool handleReplacement(Core::IEditor *editor);
public slots: public slots:
void perform(); void perform();
......
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