| 286 | } |
| 287 | |
| 288 | QWidget* UiController::findToolView(const QString& name, IToolViewFactory *factory, FindFlags flags) |
| 289 | { |
| 290 | Q_D(UiController); |
| 291 | |
| 292 | auto* const area = restoredActiveArea(); |
| 293 | if (!area) { |
| 294 | return nullptr; |
| 295 | } |
| 296 | |
| 297 | const auto& views = area->toolViews(); |
| 298 | const auto it = std::find_if(views.cbegin(), views.cend(), [&name](const Sublime::View* view) { |
| 299 | return view->document()->title() == name; |
| 300 | }); |
| 301 | if (it != views.cend()) { |
| 302 | auto* const view = *it; |
| 303 | auto* const widget = view->widget(); |
| 304 | Q_ASSERT(widget); |
| 305 | if(flags & Raise) |
| 306 | area->raiseToolView(view); |
| 307 | return widget; |
| 308 | } |
| 309 | |
| 310 | QWidget* ret = nullptr; |
| 311 | |
| 312 | if(flags & Create) |
| 313 | { |
| 314 | Sublime::ToolDocument* doc = d->factoryDocuments.value(factory); |
| 315 | if(!doc) { |
| 316 | doc = new Sublime::ToolDocument(name, this, new UiToolViewFactory(factory)); |
| 317 | d->factoryDocuments.insert(factory, doc); |
| 318 | } |
| 319 | |
| 320 | const auto* const view = addToolViewToArea(factory, doc, area); |
| 321 | if (view) { |
| 322 | ret = view->widget(); |
| 323 | Q_ASSERT(ret); |
| 324 | } |
| 325 | |
| 326 | if(flags & Raise) |
| 327 | findToolView(name, factory, Raise); |
| 328 | } |
| 329 | |
| 330 | return ret; |
| 331 | } |
| 332 | |
| 333 | void UiController::raiseToolView(const QString& documentSpecifier) |
| 334 | { |