File indexing completed on 2024-04-28 04:37:19

0001 /*
0002     SPDX-FileCopyrightText: 2002 Falk Brettschneider <falkbr@kdevelop.org>
0003     SPDX-FileCopyrightText: 2003 John Firebaugh <jfirebaugh@kde.org>
0004     SPDX-FileCopyrightText: 2006 Adam Treat <treat@kde.org>
0005     SPDX-FileCopyrightText: 2006, 2007 Alexander Dymo <adymo@kdevelop.org>
0006 
0007     SPDX-License-Identifier: LGPL-2.0-or-later
0008 */
0009 
0010 #include <QApplication>
0011 
0012 #include <KConfigGroup>
0013 #include <KNotifyConfigWidget>
0014 #include <KToggleFullScreenAction>
0015 
0016 #include <sublime/area.h>
0017 #include <sublime/view.h>
0018 
0019 #include "core.h"
0020 #include "documentcontroller.h"
0021 #include "mainwindow_p.h"
0022 #include "uicontroller.h"
0023 
0024 #include "mainwindow.h"
0025 #include "loadedpluginsdialog.h"
0026 
0027 #include <interfaces/itoolviewactionlistener.h>
0028 #include <util/scopeddialog.h>
0029 
0030 namespace KDevelop {
0031 
0032 // merge the gotoNext and gotoPrev code, to prevent copy/paste errors
0033 static void gotoPrevNextWindow(bool next)
0034 {
0035     UiController* ui = Core::self()->uiControllerInternal();
0036 
0037     if( !ui->activeSublimeWindow() )
0038         return;
0039 
0040     Sublime::Area* activeArea = ui->activeArea();
0041     if (!activeArea)
0042         return;
0043 
0044     Sublime::View* activeView = ui->activeSublimeWindow()->activeView();
0045 
0046     Sublime::AreaIndex* index = activeArea->indexOf(activeView);
0047     if (!index)
0048         return;
0049 
0050     int viewIndex = index->views().indexOf(activeView);
0051     viewIndex = next ? viewIndex + 1 : viewIndex -1;
0052 
0053     if (viewIndex < 0)
0054         viewIndex = index->views().count() - 1;
0055     else if (viewIndex >= index->views().count())
0056         viewIndex = 0;
0057 
0058     if (viewIndex >= 0 && viewIndex < index->views().count())
0059         ui->activeSublimeWindow()->activateView(index->views().at(viewIndex));
0060 }
0061 
0062 void MainWindowPrivate::gotoNextWindow()
0063 {
0064     gotoPrevNextWindow(true);
0065 }
0066 
0067 void MainWindowPrivate::gotoPreviousWindow()
0068 {
0069     gotoPrevNextWindow(false);
0070 }
0071 
0072 void MainWindowPrivate::selectPrevItem()
0073 {
0074     auto actionListener = qobject_cast<IToolViewActionListener*>(
0075         Core::self()->uiControllerInternal()->activeToolViewActionListener());
0076     if (actionListener) {
0077         actionListener->selectPreviousItem();
0078     }
0079 }
0080 
0081 void MainWindowPrivate::selectNextItem()
0082 {
0083     auto actionListener = qobject_cast<IToolViewActionListener*>(
0084         Core::self()->uiControllerInternal()->activeToolViewActionListener());
0085     if (actionListener) {
0086         actionListener->selectNextItem();
0087     }
0088 }
0089 
0090 void MainWindowPrivate::newToolbarConfig()
0091 {
0092     m_mainWindow->applyMainWindowSettings( KConfigGroup(KSharedConfig::openConfig(), "MainWindow") );
0093 }
0094 
0095 void MainWindowPrivate::settingsDialog()
0096 {
0097     Core::self()->uiControllerInternal()->showSettingsDialog();
0098 }
0099 
0100 void MainWindowPrivate::newWindow()
0101 {
0102     Core::self()->uiController()->switchToArea(m_mainWindow->area()->objectName(), UiController::NewWindow);
0103 }
0104 
0105 void MainWindowPrivate::splitHorizontal()
0106 {
0107     split(Qt::Vertical);
0108 }
0109 
0110 void MainWindowPrivate::splitVertical()
0111 {
0112     split(Qt::Horizontal);
0113 }
0114 
0115 void MainWindowPrivate::split(Qt::Orientation orientation)
0116 {
0117     if (!m_mainWindow->area())
0118         return;
0119     Sublime::View *view = m_mainWindow->activeView();
0120     if (!view)
0121         return;
0122 
0123     Sublime::View *newView = view->document()->createView();
0124     m_mainWindow->area()->addView(newView, view, orientation);
0125 
0126     m_mainWindow->activateView(newView);
0127 }
0128 
0129 static void gotoPrevNextSplit(bool next)
0130 {
0131     UiController* ui = Core::self()->uiControllerInternal();
0132 
0133     if( !ui->activeSublimeWindow() )
0134         return;
0135 
0136     Sublime::Area* area = ui->activeSublimeWindow()->area();
0137     if (!area)
0138         return;
0139 
0140     QList<Sublime::View*> topViews = ui->activeSublimeWindow()->topViews();
0141 
0142     Sublime::View *activeView = ui->activeSublimeWindow()->activeView();
0143     if (!activeView)
0144         return;
0145 
0146     int viewIndex = topViews.indexOf(activeView);
0147     viewIndex = next ? viewIndex + 1 : viewIndex -1;
0148 
0149     if (viewIndex < 0)
0150         viewIndex = topViews.count() - 1;
0151     else if (viewIndex >= topViews.count())
0152         viewIndex = 0;
0153 
0154     if (viewIndex >= 0 && viewIndex < topViews.count())
0155         ui->activeSublimeWindow()->activateView(topViews.at(viewIndex));
0156 }
0157 
0158 void MainWindowPrivate::gotoNextSplit()
0159 {
0160     gotoPrevNextSplit(true);
0161 }
0162 
0163 void MainWindowPrivate::gotoPreviousSplit()
0164 {
0165     gotoPrevNextSplit(false);
0166 }
0167 
0168 void MainWindowPrivate::toggleFullScreen(bool fullScreen)
0169 {
0170     KToggleFullScreenAction::setFullScreen( m_mainWindow, fullScreen );
0171 }
0172 
0173 void MainWindowPrivate::fileNew()
0174 {
0175     Core::self()->documentControllerInternal()->openDocument(DocumentController::nextEmptyDocumentUrl());
0176 }
0177 
0178 void MainWindowPrivate::viewAddNewToolView()
0179 {
0180     Core::self()->uiControllerInternal()->selectNewToolViewToAdd(m_mainWindow);
0181 }
0182 
0183 void MainWindowPrivate::quitAll()
0184 {
0185     QApplication::closeAllWindows();
0186 }
0187 
0188 void MainWindowPrivate::configureNotifications()
0189 {
0190     KNotifyConfigWidget::configure(m_mainWindow);
0191 }
0192 
0193 void MainWindowPrivate::showLoadedPlugins()
0194 {
0195     ScopedDialog<LoadedPluginsDialog> dlg(m_mainWindow);
0196     dlg->exec();
0197 }
0198 
0199 void MainWindowPrivate::contextMenuFileNew()
0200 {
0201     m_mainWindow->activateView(m_tabView);
0202     fileNew();
0203 }
0204 
0205 void MainWindowPrivate::contextMenuSplitHorizontal()
0206 {
0207     m_mainWindow->activateView(m_tabView);
0208     splitHorizontal();
0209 }
0210 
0211 void MainWindowPrivate::contextMenuSplitVertical()
0212 {
0213     m_mainWindow->activateView(m_tabView);
0214     splitVertical();
0215 }
0216 
0217 void MainWindowPrivate::reloadAll()
0218 {
0219     const auto documents = Core::self()->documentController()->openDocuments() ;
0220     for (IDocument* doc : documents) {
0221         doc->reload();
0222     }
0223 }
0224 
0225 }
0226