Fix no newlines warnings. Patch by Peter Oberndorfer
[kdevelopdvcssupport.git] / shell / mainwindow.cpp
blobb5add7b58c24b029d047e03ce1008f626b9ee177
1 /* This file is part of the KDevelop project
2 Copyright 2002 Falk Brettschneider <falkbr@kdevelop.org>
3 Copyright 2003 John Firebaugh <jfirebaugh@kde.org>
4 Copyright 2006 Adam Treat <treat@kde.org>
5 Copyright 2006, 2007 Alexander Dymo <adymo@kdevelop.org>
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA.
22 #include "mainwindow.h"
23 #include "mainwindow_p.h"
25 #include <QtCore/QHash>
26 #include <QtGui/QDockWidget>
27 #include <QtGui/QStackedWidget>
29 #include <KApplication>
30 #include <KActionCollection>
31 #include <kmenu.h>
32 #include <kglobal.h>
33 #include <klocale.h>
34 #include <ktemporaryfile.h>
35 #include <kactioncollection.h>
36 #include <kdebug.h>
37 #include <ktexteditor/view.h>
38 #include <kxmlguifactory.h>
40 #include "shellextension.h"
41 #include "partcontroller.h"
42 #include "plugincontroller.h"
43 #include "uicontroller.h"
44 #include "documentcontroller.h"
46 namespace KDevelop
49 MainWindow::MainWindow( Sublime::Controller *parent, Qt::WFlags flags )
50 : Sublime::MainWindow( parent, flags )
52 KConfigGroup cg = KGlobal::config()->group( "UiSettings" );
53 int bottomleft = cg.readEntry( "BottomLeftCornerOwner", 0 );
54 int bottomright = cg.readEntry( "BottomRightCornerOwner", 0 );
55 kDebug() << "Bottom Left:" << bottomleft;
56 kDebug() << "Bottom Right:" << bottomright;
58 // 0 means vertical dock (left, right), 1 means horizontal dock( top, bottom )
59 if( bottomleft == 0 )
60 setCorner( Qt::BottomLeftCorner, Qt::LeftDockWidgetArea );
61 else if( bottomleft == 1 )
62 setCorner( Qt::BottomLeftCorner, Qt::BottomDockWidgetArea );
64 if( bottomright == 0 )
65 setCorner( Qt::BottomRightCorner, Qt::RightDockWidgetArea );
66 else if( bottomright == 1 )
67 setCorner( Qt::BottomRightCorner, Qt::BottomDockWidgetArea );
69 setObjectName( "MainWindow" );
70 d = new MainWindowPrivate(this);
72 setStandardToolBarMenuEnabled( true );
73 d->setupActions();
75 if( !ShellExtension::getInstance()->xmlFile().isEmpty() )
77 setXMLFile( ShellExtension::getInstance() ->xmlFile() );
80 connect(this->guiFactory(), SIGNAL(clientAdded(KXMLGUIClient*)),
81 d, SLOT(fixToolbar()));
84 MainWindow::~ MainWindow()
86 if (memberList().count() == 1) {
87 // We're closing down...
88 Core::self()->cleanup();
89 Core::self()->deleteLater();
92 delete d;
93 Core::self()->uiControllerInternal()->mainWindowDeleted(this);
96 void MainWindow::loadSettings()
98 kDebug() << "Loading Settings";
99 KConfigGroup cg = KGlobal::config()->group( "UiSettings" );
101 // dock widget corner layout
102 int bottomleft = cg.readEntry( "BottomLeftCornerOwner", 0 );
103 int bottomright = cg.readEntry( "BottomRightCornerOwner", 0 );
104 kDebug() << "Bottom Left:" << bottomleft;
105 kDebug() << "Bottom Right:" << bottomright;
107 // 0 means vertical dock (left, right), 1 means horizontal dock( top, bottom )
108 if( bottomleft == 0 )
109 setCorner( Qt::BottomLeftCorner, Qt::LeftDockWidgetArea );
110 else if( bottomleft == 1 )
111 setCorner( Qt::BottomLeftCorner, Qt::BottomDockWidgetArea );
113 if( bottomright == 0 )
114 setCorner( Qt::BottomRightCorner, Qt::RightDockWidgetArea );
115 else if( bottomright == 1 )
116 setCorner( Qt::BottomRightCorner, Qt::BottomDockWidgetArea );
118 Sublime::MainWindow::loadSettings();
121 void MainWindow::saveSettings()
123 Sublime::MainWindow::saveSettings();
126 void MainWindow::initialize()
128 setupGUI( KXmlGuiWindow::Keys | KXmlGuiWindow::ToolBar | KXmlGuiWindow::Create );
129 Core::self()->partManager()->addManagedTopLevelWidget(this);
130 kDebug() << "Adding plugin-added connection";
131 connect( Core::self()->pluginController(), SIGNAL(pluginLoaded(KDevelop::IPlugin*)),
132 d, SLOT(addPlugin(KDevelop::IPlugin*)));
133 connect( Core::self()->partManager(), SIGNAL(activePartChanged(KParts::Part*)),
134 d, SLOT(activePartChanged(KParts::Part*)));
135 connect( this, SIGNAL(activeViewChanged(Sublime::View*)),
136 d, SLOT(changeActiveView(Sublime::View*)));
137 connect(Core::self()->documentController(), SIGNAL(documentActivated(KDevelop::IDocument*)), SLOT(documentActivated(KDevelop::IDocument*)));
138 connect(Core::self()->documentController(), SIGNAL(documentStateChanged(KDevelop::IDocument*)), SLOT(documentStateChanged(KDevelop::IDocument*)));
139 connect(Core::self()->documentController(), SIGNAL(documentClosed(KDevelop::IDocument*)), SLOT(documentClosed(KDevelop::IDocument*)));
140 /*connect( Core::projectController(), SIGNAL( projectOpened() ),
141 d, SLOT( projectOpened() ) );
142 connect( Core::projectController(), SIGNAL( projectClosed() ),
143 d, SLOT( projectClosed() ) );*/
144 d->setupGui();
147 void MainWindow::cleanup()
151 void MainWindow::fillContextMenu( KMenu *menu, const Context *context )
153 //Perhaps we get rid of this framework and instead have every Context contains
154 //a kactioncollection. Plugins could add their actions directly to the context
155 //object retrieved from Core... ??
156 emit contextMenu( menu, context );
158 //Put this in every context menu so that plugins will be encouraged to allow shortcuts
159 QAction * action = actionCollection() ->action( "settings_configure_shortcuts" );
160 menu->addAction( action );
163 void MainWindow::setVisible( bool visible )
165 KXmlGuiWindow::setVisible( visible );
166 emit finishedLoading();
169 bool MainWindow::queryClose()
171 if (!Core::self()->documentControllerInternal()->saveAllDocumentsForWindow(this, IDocument::Default))
172 return false;
174 return Sublime::MainWindow::queryClose();
177 void MainWindow::documentActivated( IDocument* document )
179 setCaption(document->url().pathOrUrl(), document->state() == IDocument::Modified || document->state() == IDocument::DirtyAndModified);
182 void MainWindow::documentStateChanged( IDocument* document )
184 setCaption(document->url().pathOrUrl(), document->state() == IDocument::Modified || document->state() == IDocument::DirtyAndModified);
187 void MainWindow::documentClosed( IDocument* document )
189 Q_UNUSED(document);
190 if (Core::self()->documentController()->openDocuments().count() == 0)
192 setCaption(QString(), false);
196 void MainWindow::registerStatus(QObject* status)
198 d->registerStatus(status);
203 #include "mainwindow.moc"