1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804
|
/*
SPDX-FileCopyrightText: 2007 Alexander Dymo <adymo@kdevelop.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "uicontroller.h"
#include <QAction>
#include <QApplication>
#include <QDialog>
#include <QListWidget>
#include <QPushButton>
#include <QMap>
#include <QPointer>
#include <QTimer>
#include <QVBoxLayout>
#include <KLocalizedString>
#include <KXMLGUIClient>
#include <sublime/area.h>
#include <sublime/view.h>
#include <sublime/tooldocument.h>
#include <sublime/holdupdates.h>
#include <interfaces/itoolviewactionlistener.h>
#include <sublime/message.h>
#include <util/scopeddialog.h>
#include "core.h"
#include "configpage.h"
#include "configdialog.h"
#include "debug.h"
#include "editorconfigpage.h"
#include "shellextension.h"
#include "plugincontroller.h"
#include "session.h"
#include "mainwindow.h"
#include "workingsetcontroller.h"
#include "workingsets/workingset.h"
#include "settings/bgpreferences.h"
#include "settings/languagepreferences.h"
#include "settings/environmentpreferences.h"
#include "settings/pluginpreferences.h"
#include "settings/projectpreferences.h"
#include "settings/sourceformattersettings.h"
#include "settings/uipreferences.h"
#include "settings/templateconfig.h"
#include "settings/analyzerspreferences.h"
#include "settings/documentationpreferences.h"
#include "settings/runtimespreferences.h"
namespace KDevelop {
class UiControllerPrivate {
public:
UiControllerPrivate(Core* core, UiController* controller)
: core(core)
, areasRestored(false)
, m_controller(controller)
{
if (Core::self()->workingSetControllerInternal())
Core::self()->workingSetControllerInternal()->initializeController(m_controller);
m_controller->connect(m_controller, &Sublime::Controller::mainWindowAdded, m_controller, &UiController::mainWindowAdded);
QMap<QString, Sublime::Position> desired;
desired[QStringLiteral("org.kdevelop.ClassBrowserView")] = Sublime::Left;
desired[QStringLiteral("org.kdevelop.DocumentsView")] = Sublime::Left;
desired[QStringLiteral("org.kdevelop.ProjectsView")] = Sublime::Left;
desired[QStringLiteral("org.kdevelop.FileManagerView")] = Sublime::Left;
desired[QStringLiteral("org.kdevelop.ProblemReporterView")] = Sublime::Bottom;
desired[QStringLiteral("org.kdevelop.OutputView")] = Sublime::Bottom;
desired[QStringLiteral("org.kdevelop.ContextBrowser")] = Sublime::Bottom;
desired[QStringLiteral("org.kdevelop.KonsoleView")] = Sublime::Bottom;
desired[QStringLiteral("org.kdevelop.SnippetView")] = Sublime::Right;
desired[QStringLiteral("org.kdevelop.ExternalScriptView")] = Sublime::Right;
desired[QStringLiteral("org.kdevelop.ScratchpadView")] = Sublime::Left;
auto* a = new Sublime::Area(m_controller, QStringLiteral("code"), i18nc("area", "Code"));
a->setDesiredToolViews(desired);
a->setIconName(QStringLiteral("document-edit"));
m_controller->addDefaultArea(a);
desired.clear();
desired[QStringLiteral("org.kdevelop.debugger.VariablesView")] = Sublime::Left;
desired[QStringLiteral("org.kdevelop.debugger.BreakpointsView")] = Sublime::Bottom;
desired[QStringLiteral("org.kdevelop.debugger.StackView")] = Sublime::Bottom;
desired[QStringLiteral("org.kdevelop.debugger.ConsoleView")] = Sublime::Bottom;
desired[QStringLiteral("org.kdevelop.KonsoleView")] = Sublime::Bottom;
a = new Sublime::Area(m_controller, QStringLiteral("debug"), i18nc("area", "Debug"));
a->setDesiredToolViews(desired);
a->setIconName(QStringLiteral("debug-run"));
m_controller->addDefaultArea(a);
desired.clear();
desired[QStringLiteral("org.kdevelop.ProjectsView")] = Sublime::Left;
desired[QStringLiteral("org.kdevelop.PatchReview")] = Sublime::Bottom;
a = new Sublime::Area(m_controller, QStringLiteral("review"), i18nc("area", "Review"));
a->setDesiredToolViews(desired);
a->setIconName(QStringLiteral("text-x-patch"));
m_controller->addDefaultArea(a);
if(!(Core::self()->setupFlags() & Core::NoUi))
{
defaultMainWindow = new MainWindow(m_controller);
m_controller->addMainWindow(defaultMainWindow);
activeSublimeWindow = defaultMainWindow;
}
else
{
activeSublimeWindow = defaultMainWindow = nullptr;
}
m_assistantTimer.setSingleShot(true);
m_assistantTimer.setInterval(100);
}
void widgetChanged(QWidget*, QWidget* now)
{
if (now) {
auto* win = qobject_cast<Sublime::MainWindow*>(now->window());
if( win )
{
activeSublimeWindow = win;
}
}
}
Core* const core;
QPointer<MainWindow> defaultMainWindow;
QHash<IToolViewFactory*, Sublime::ToolDocument*> factoryDocuments;
QPointer<Sublime::MainWindow> activeSublimeWindow;
bool areasRestored;
/// QWidget implementing IToolViewActionListener interface, or null
QPointer<QWidget> activeActionListener;
QTimer m_assistantTimer;
private:
UiController *m_controller;
};
class UiToolViewFactory: public Sublime::ToolFactory {
public:
explicit UiToolViewFactory(IToolViewFactory *factory): m_factory(factory) {}
~UiToolViewFactory() override { delete m_factory; }
QWidget* create(Sublime::ToolDocument *doc, QWidget *parent = nullptr) override
{
Q_UNUSED( doc );
return m_factory->create(parent);
}
QList< QAction* > contextMenuActions(QWidget* viewWidget) const override
{
return m_factory->contextMenuActions( viewWidget );
}
QList<QAction*> toolBarActions( QWidget* viewWidget ) const override
{
return m_factory->toolBarActions( viewWidget );
}
QString id() const override { return m_factory->id(); }
private:
IToolViewFactory* const m_factory;
};
class ViewSelectorItem: public QListWidgetItem {
public:
explicit ViewSelectorItem(const QString& text, IToolViewFactory* factory, QListWidget* parent = nullptr, int type = Type)
: QListWidgetItem(text, parent, type)
, factory(factory)
{}
IToolViewFactory* const factory;
};
class NewToolViewListWidget: public QListWidget {
Q_OBJECT
public:
explicit NewToolViewListWidget(MainWindow *mw, QWidget* parent = nullptr)
:QListWidget(parent), m_mw(mw)
{
connect(this, &NewToolViewListWidget::doubleClicked, this, &NewToolViewListWidget::addNewToolViewByDoubleClick);
}
Q_SIGNALS:
void addNewToolView(MainWindow *mw, QListWidgetItem *item);
private Q_SLOTS:
void addNewToolViewByDoubleClick(const QModelIndex& index)
{
QListWidgetItem *item = itemFromIndex(index);
// Disable item so that the tool view can not be added again.
item->setFlags(item->flags() & ~Qt::ItemIsEnabled);
emit addNewToolView(m_mw, item);
}
private:
MainWindow* const m_mw;
};
UiController::UiController(Core *core)
: Sublime::Controller(nullptr), IUiController()
, d_ptr(new UiControllerPrivate(core, this))
{
setObjectName(QStringLiteral("UiController"));
if (!defaultMainWindow() || (Core::self()->setupFlags() & Core::NoUi))
return;
setupActions();
}
UiController::~UiController() = default;
void UiController::setupActions()
{
}
void UiController::mainWindowAdded(Sublime::MainWindow* mainWindow)
{
connect(mainWindow, &MainWindow::activeToolViewChanged, this, &UiController::slotActiveToolViewChanged);
connect(mainWindow, &MainWindow::areaChanged, this, &UiController::slotAreaChanged); // also check after area reconstruction
connect(mainWindow, &MainWindow::areaCleared, Core::self()->workingSetControllerInternal(), &WorkingSetController::saveArea);
}
// FIXME: currently, this always create new window. Probably,
// should just rename it.
void UiController::switchToArea(const QString &areaName, SwitchMode switchMode)
{
if (switchMode == ThisWindow) {
showArea(areaName, activeSublimeWindow());
return;
}
auto *main = new MainWindow(this);
addMainWindow(main);
showArea(areaName, main);
main->initialize();
// WTF? First, enabling this code causes crashes since we
// try to disconnect some already-deleted action, or something.
// Second, this code will disconnection the clients from guiFactory
// of the previous main window. Ick!
#if 0
//we need to add all existing guiclients to the new mainwindow
//@todo adymo: add only ones that belong to the area (when the area code is there)
const auto clients = oldMain->guiFactory()->clients();
for (KXMLGUIClient *client : clients) {
main->guiFactory()->addClient(client);
}
#endif
main->show();
}
QWidget* UiController::findToolView(const QString& name, IToolViewFactory *factory, FindFlags flags)
{
Q_D(UiController);
if(!d->areasRestored || !activeArea())
return nullptr;
const QList<Sublime::View*> views = activeArea()->toolViews();
for (Sublime::View* view : views) {
auto* doc = qobject_cast<Sublime::ToolDocument*>(view->document());
if(doc && doc->title() == name && view->widget()) {
if(flags & Raise)
view->requestRaise();
return view->widget();
}
}
QWidget* ret = nullptr;
if(flags & Create)
{
Sublime::ToolDocument* doc = d->factoryDocuments.value(factory);
if(!doc) {
doc = new Sublime::ToolDocument(name, this, new UiToolViewFactory(factory));
d->factoryDocuments.insert(factory, doc);
}
Sublime::View* view = addToolViewToArea(factory, doc, activeArea());
if(view)
ret = view->widget();
if(flags & Raise)
findToolView(name, factory, Raise);
}
return ret;
}
void UiController::raiseToolView(QWidget* toolViewWidget)
{
Q_D(UiController);
if(!d->areasRestored)
return;
const QList<Sublime::View*> views = activeArea()->toolViews();
for (Sublime::View* view : views) {
if(view->widget() == toolViewWidget) {
view->requestRaise();
return;
}
}
}
void UiController::addToolView(const QString & name, IToolViewFactory *factory, FindFlags state)
{
Q_D(UiController);
if (!factory)
return;
qCDebug(SHELL) ;
auto *doc = new Sublime::ToolDocument(name, this, new UiToolViewFactory(factory));
d->factoryDocuments[factory] = doc;
/* Until areas are restored, we don't know which views should be really
added, and which not, so we just record view availability. */
if (d->areasRestored && state != None) {
const auto areas = allAreas();
for (Sublime::Area* area : areas) {
addToolViewToArea(factory, doc, area);
}
}
}
void KDevelop::UiController::raiseToolView(Sublime::View * view)
{
const auto areas = allAreas();
for (Sublime::Area* area : areas) {
if( area->toolViews().contains( view ) )
area->raiseToolView( view );
}
slotActiveToolViewChanged(view);
}
void UiController::slotAreaChanged(Sublime::Area*)
{
// this slot gets call if an area in *any* MainWindow changed
// so let's first get the "active area"
const auto area = activeSublimeWindow()->area();
if (area) {
// walk through shown tool views and maku sure the
const auto shownIds = area->shownToolViews(Sublime::AllPositions);
for (Sublime::View* toolView : qAsConst(area->toolViews())) {
if (shownIds.contains(toolView->document()->documentSpecifier())) {
slotActiveToolViewChanged(toolView);
}
}
}
}
void UiController::slotActiveToolViewChanged(Sublime::View* view)
{
Q_D(UiController);
if (!view) {
return;
}
// record the last active tool view action listener
if (qobject_cast<IToolViewActionListener*>(view->widget())) {
d->activeActionListener = view->widget();
}
}
void KDevelop::UiController::removeToolView(IToolViewFactory *factory)
{
Q_D(UiController);
if (!factory)
return;
qCDebug(SHELL) ;
//delete the tooldocument
Sublime::ToolDocument *doc = d->factoryDocuments.value(factory);
///@todo adymo: on document deletion all its views shall be also deleted
for (Sublime::View* view : doc->views()) {
const auto areas = allAreas();
for (Sublime::Area *area : areas) {
if (area->removeToolView(view))
view->deleteLater();
}
}
d->factoryDocuments.remove(factory);
delete doc;
}
Sublime::Area *UiController::activeArea()
{
Sublime::MainWindow *m = activeSublimeWindow();
if (m)
return activeSublimeWindow()->area();
return nullptr;
}
Sublime::MainWindow *UiController::activeSublimeWindow()
{
Q_D(UiController);
return d->activeSublimeWindow;
}
MainWindow *UiController::defaultMainWindow()
{
Q_D(UiController);
return d->defaultMainWindow;
}
void UiController::initialize()
{
defaultMainWindow()->initialize();
connect(qApp, &QApplication::focusChanged, this, [this](QWidget* old, QWidget* now) {
Q_D(UiController);
d->widgetChanged(old, now);
});
}
void UiController::cleanup()
{
for (Sublime::MainWindow* w : mainWindows()) {
w->saveSettings();
}
saveAllAreas(KSharedConfig::openConfig());
// disconnect early to prevent UB due to accessing partially destroyed UiController
// in the focusChanged handler above
disconnect(qApp, nullptr, this, nullptr);
}
void UiController::selectNewToolViewToAdd(MainWindow *mw)
{
Q_D(UiController);
if (!mw || !mw->area())
return;
ScopedDialog<QDialog> dia(mw);
dia->setWindowTitle(i18nc("@title:window", "Select Tool View to Add"));
auto mainLayout = new QVBoxLayout(dia);
auto *list = new NewToolViewListWidget(mw, dia);
list->setSelectionMode(QAbstractItemView::ExtendedSelection);
list->setSortingEnabled(true);
for (QHash<IToolViewFactory*, Sublime::ToolDocument*>::const_iterator it = d->factoryDocuments.constBegin();
it != d->factoryDocuments.constEnd(); ++it)
{
auto* item = new ViewSelectorItem(it.value()->title(), it.key(), list);
if (!item->factory->allowMultiple() && toolViewPresent(it.value(), mw->area())) {
// Disable item if the tool view is already present.
item->setFlags(item->flags() & ~Qt::ItemIsEnabled);
}
list->addItem(item);
}
list->setFocus();
connect(list, &NewToolViewListWidget::addNewToolView, this, &UiController::addNewToolView);
mainLayout->addWidget(list);
auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel);
auto okButton = buttonBox->button(QDialogButtonBox::Ok);
okButton->setDefault(true);
okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
dia->connect(buttonBox, &QDialogButtonBox::accepted, dia.data(), &QDialog::accept);
dia->connect(buttonBox, &QDialogButtonBox::rejected, dia.data(), &QDialog::reject);
mainLayout->addWidget(buttonBox);
if (dia->exec() == QDialog::Accepted)
{
const auto items = list->selectedItems();
for (QListWidgetItem* item : items) {
addNewToolView(mw, item);
}
}
}
void UiController::addNewToolView(MainWindow *mw, QListWidgetItem* item)
{
Q_D(UiController);
auto *current = static_cast<ViewSelectorItem*>(item);
Sublime::ToolDocument *doc = d->factoryDocuments[current->factory];
Sublime::View *view = doc->createView();
mw->area()->addToolView(view,
Sublime::dockAreaToPosition(current->factory->defaultPosition()));
current->factory->viewCreated(view);
}
void UiController::showSettingsDialog()
{
ConfigDialog cfgDlg(activeMainWindow());
auto editorConfigPage = new EditorConfigPage(&cfgDlg);
auto languageConfigPage = new LanguagePreferences(&cfgDlg);
auto analyzersPreferences = new AnalyzersPreferences(&cfgDlg);
auto documentationPreferences = new DocumentationPreferences(&cfgDlg);
auto runtimesPreferences = new RuntimesPreferences(&cfgDlg);
auto templateConfig = new TemplateConfig(&cfgDlg);
const auto configPages = QVector<KDevelop::ConfigPage*> {
new UiPreferences(&cfgDlg),
new PluginPreferences(&cfgDlg),
new SourceFormatterSettings(&cfgDlg),
new ProjectPreferences(&cfgDlg),
new EnvironmentPreferences(QString(), &cfgDlg),
templateConfig,
documentationPreferences,
analyzersPreferences,
runtimesPreferences,
languageConfigPage,
editorConfigPage
};
for (auto page : configPages) {
cfgDlg.appendConfigPage(page);
}
cfgDlg.appendSubConfigPage(languageConfigPage, new BGPreferences(&cfgDlg));
auto addPluginPages = [&](IPlugin* plugin) {
for (int i = 0, numPages = plugin->configPages(); i < numPages; ++i) {
auto page = plugin->configPage(i, &cfgDlg);
if (!page)
continue;
if (page->configPageType() == ConfigPage::LanguageConfigPage) {
cfgDlg.appendSubConfigPage(languageConfigPage, page);
} else if (page->configPageType() == ConfigPage::AnalyzerConfigPage) {
cfgDlg.appendSubConfigPage(analyzersPreferences, page);
} else if (page->configPageType() == ConfigPage::RuntimeConfigPage) {
cfgDlg.appendSubConfigPage(runtimesPreferences, page);
} else if (page->configPageType() == ConfigPage::DocumentationConfigPage) {
cfgDlg.appendSubConfigPage(documentationPreferences, page);
} else {
cfgDlg.insertConfigPage(editorConfigPage, page);
}
}
};
auto plugins = ICore::self()->pluginController()->loadedPlugins();
std::sort(plugins.begin(), plugins.end());
for (IPlugin* plugin : qAsConst(plugins)) {
addPluginPages(plugin);
}
// TODO: only load settings if a UI related page was changed?
connect(&cfgDlg, &ConfigDialog::configSaved, activeSublimeWindow(), &Sublime::MainWindow::loadSettings);
// make sure that pages get added whenever a new plugin is loaded (probably from the plugin selection dialog)
// removal on plugin unload is already handled in ConfigDialog
connect(ICore::self()->pluginController(), &IPluginController::pluginLoaded, &cfgDlg, addPluginPages);
cfgDlg.exec();
}
Sublime::Controller* UiController::controller()
{
return this;
}
KParts::MainWindow *UiController::activeMainWindow()
{
return activeSublimeWindow();
}
void UiController::saveArea(Sublime::Area * area, KConfigGroup & group)
{
area->save(group);
auto workingSet = area->workingSet();
if (!workingSet.isEmpty()) {
WorkingSet* set = Core::self()->workingSetControllerInternal()->workingSet(workingSet);
set->saveFromArea(area);
}
for (auto w : mainWindows()) {
if (area == w->area()) {
Core::self()->activeSession()->config()->group("Working File Sets").writeEntry("Active Working Set", workingSet);
}
}
}
void UiController::loadArea(Sublime::Area * area, const KConfigGroup & group)
{
area->load(group);
if (!area->workingSet().isEmpty()) {
WorkingSet* set = Core::self()->workingSetControllerInternal()->workingSet(area->workingSet());
Q_ASSERT(set->isConnected(area));
Q_UNUSED(set);
}
}
void UiController::saveAllAreas(const KSharedConfigPtr& config)
{
KConfigGroup uiConfig(config, "User Interface");
int wc = mainWindows().size();
uiConfig.writeEntry("Main Windows Count", wc);
for (int w = 0; w < wc; ++w)
{
KConfigGroup mainWindowConfig(&uiConfig,
QStringLiteral("Main Window %1").arg(w));
for (Sublime::Area* defaultArea : defaultAreas()) {
// FIXME: using object name seems ugly.
QString type = defaultArea->objectName();
Sublime::Area* area = this->area(w, type);
KConfigGroup areaConfig(&mainWindowConfig, QLatin1String("Area ") + type);
areaConfig.deleteGroup();
areaConfig.writeEntry("id", type);
saveArea(area, areaConfig);
areaConfig.sync();
}
}
uiConfig.sync();
}
void UiController::loadAllAreas(const KSharedConfigPtr& config)
{
Q_D(UiController);
KConfigGroup uiConfig(config, "User Interface");
int wc = uiConfig.readEntry("Main Windows Count", 1);
/* It is expected the main windows are restored before
restoring areas. */
if (wc > mainWindows().size())
wc = mainWindows().size();
/* Offer all tool views to the default areas. */
for (Sublime::Area* area : defaultAreas()) {
QHash<IToolViewFactory*, Sublime::ToolDocument*>::const_iterator i, e;
for (i = d->factoryDocuments.constBegin(),
e = d->factoryDocuments.constEnd(); i != e; ++i)
{
addToolViewIfWanted(i.key(), i.value(), area);
}
}
/* Restore per-windows areas. */
for (int w = 0; w < wc; ++w)
{
KConfigGroup mainWindowConfig(&uiConfig,
QStringLiteral("Main Window %1").arg(w));
Sublime::MainWindow *mw = mainWindows()[w];
/* We loop over default areas. This means that if
the config file has an area of some type that is not
in default set, we'd just ignore it. I think it's fine --
the model were a given mainwindow can has it's own
area types not represented in the default set is way
too complex. */
for (Sublime::Area* defaultArea : defaultAreas()) {
QString type = defaultArea->objectName();
Sublime::Area* area = this->area(w, type);
KConfigGroup areaConfig(&mainWindowConfig, QLatin1String("Area ") + type);
qCDebug(SHELL) << "Trying to restore area " << type;
/* This is just an easy check that a group exists, to
avoid "restoring" area from empty config group, wiping
away programmatically installed defaults. */
if (areaConfig.readEntry("id", "") == type)
{
qCDebug(SHELL) << "Restoring area " << type;
loadArea(area, areaConfig);
}
// At this point we know which tool views the area wants.
// Tender all tool views we have.
QHash<IToolViewFactory*, Sublime::ToolDocument*>::const_iterator i, e;
for (i = d->factoryDocuments.constBegin(),
e = d->factoryDocuments.constEnd(); i != e; ++i)
{
addToolViewIfWanted(i.key(), i.value(), area);
}
}
// Force reload of the changes.
showAreaInternal(mw->area(), mw);
mw->area()->setWorkingSet(Core::self()->activeSession()->config()->group("Working File Sets").readEntry("Active Working Set", QString()));
mw->enableAreaSettingsSave();
}
d->areasRestored = true;
}
void UiController::addToolViewToDockArea(IToolViewFactory* factory, Qt::DockWidgetArea area)
{
Q_D(UiController);
addToolViewToArea(factory, d->factoryDocuments.value(factory), activeArea(), Sublime::dockAreaToPosition(area));
}
bool UiController::toolViewPresent(Sublime::ToolDocument* doc, Sublime::Area* area)
{
for (Sublime::View *view : doc->views()) {
if( area->toolViews().contains( view ) )
return true;
}
return false;
}
void UiController::addToolViewIfWanted(IToolViewFactory* factory,
Sublime::ToolDocument* doc,
Sublime::Area* area)
{
if (area->wantToolView(factory->id()))
{
addToolViewToArea(factory, doc, area);
}
}
Sublime::View* UiController::addToolViewToArea(IToolViewFactory* factory,
Sublime::ToolDocument* doc,
Sublime::Area* area, Sublime::Position p)
{
Sublime::View* view = doc->createView();
area->addToolView(
view,
p == Sublime::AllPositions ? Sublime::dockAreaToPosition(factory->defaultPosition()) : p);
connect(view, &Sublime::View::raise,
this, QOverload<Sublime::View*>::of(&UiController::raiseToolView));
factory->viewCreated(view);
return view;
}
void UiController::registerStatus(QObject* status)
{
Sublime::MainWindow* w = activeSublimeWindow();
if (!w) return;
auto* mw = qobject_cast<KDevelop::MainWindow*>(w);
if (!mw) return;
mw->registerStatus(status);
}
void UiController::showErrorMessage(const QString& message, int timeout)
{
Sublime::MainWindow* w = activeSublimeWindow();
if (!w) return;
auto* mw = qobject_cast<KDevelop::MainWindow*>(w);
if (!mw) return;
QMetaObject::invokeMethod(mw, "showErrorMessage", Q_ARG(QString, message), Q_ARG(int, timeout));
}
void UiController::postMessage(Sublime::Message* message)
{
// if Core has flag Core::NoUi there also is no window, so caught as well here
Sublime::MainWindow* window = activeSublimeWindow();
if (!window) {
delete message;
return;
}
QMetaObject::invokeMethod(window, "postMessage", Q_ARG(Sublime::Message*, message));
}
const QHash< IToolViewFactory*, Sublime::ToolDocument* >& UiController::factoryDocuments() const
{
Q_D(const UiController);
return d->factoryDocuments;
}
QWidget* UiController::activeToolViewActionListener() const
{
Q_D(const UiController);
return d->activeActionListener;
}
QList<Sublime::Area*> UiController::allAreas() const
{
return Sublime::Controller::allAreas();
}
}
#include "uicontroller.moc"
#include "moc_uicontroller.cpp"
|