From 860d28cd57e2f8c1d9e7027ffc64b4693cccec82 Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 27 Mar 2013 22:13:25 -0300 Subject: [PATCH] Implement Workspace::makeUnique() --- src/widgets/workspace.cpp | 41 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/src/widgets/workspace.cpp b/src/widgets/workspace.cpp index f58338b63..cca970176 100644 --- a/src/widgets/workspace.cpp +++ b/src/widgets/workspace.cpp @@ -29,6 +29,7 @@ #include "widgets/workspace_view.h" #include +#include using namespace ui; using namespace widgets; @@ -168,5 +169,43 @@ WorkspacePart* Workspace::destroyPart(WorkspacePart* part) void Workspace::makeUnique(WorkspaceView* view) { - // TODO + std::vector parts; + std::queue remaining; + remaining.push(getFirstChild()); + while (!remaining.empty()) { + Widget* widget = remaining.front(); + remaining.pop(); + + WorkspacePart* part = dynamic_cast(widget); + if (part && part->getParent() != this) { + while (part->getActiveView()) { + part->removeView(part->getActiveView()); + } + parts.push_back(part); + } + else { + UI_FOREACH_WIDGET(widget->getChildren(), it) { + remaining.push(*it); + } + } + } + + for (std::vector::iterator + it = parts.begin(), end = parts.end(); it != end; ++it) { + WorkspacePart* part = *it; + if (part->getParent() != this) + destroyPart(part); + } + + WorkspacePart* uniquePart = dynamic_cast(getFirstChild()); + ASSERT(uniquePart != NULL); + m_activePart = uniquePart; + + for (WorkspaceViews::iterator it = m_views.begin(), end = m_views.end(); it != end; ++it) { + WorkspaceView* v = *it; + if (!v->getContentWidget()->getParent()) + uniquePart->addView(v); + } + + setActiveView(view); }