Fix no newlines warnings. Patch by Peter Oberndorfer
[kdevelopdvcssupport.git] / shell / mainwindow_p.cpp
blob102cd77e6bc4ada3d1108d716c3650ddfd7b09e8
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_p.h"
24 #include <QApplication>
25 #include <QStackedWidget>
27 #include <kmenu.h>
28 #include <kdebug.h>
29 #include <klocale.h>
30 #include <kstatusbar.h>
31 #include <kxmlguiclient.h>
32 #include <kxmlguifactory.h>
34 #include <kparts/part.h>
35 #include <ktexteditor/view.h>
36 #include <ktexteditor/document.h>
37 #include <ktexteditor/editor.h>
39 #include <kstandardaction.h>
40 #include <kselectaction.h>
41 #include <ktogglefullscreenaction.h>
42 #include <kactioncollection.h>
43 #include <ktoolbarpopupaction.h>
45 #include <sublime/area.h>
46 #include <sublime/view.h>
47 #include <sublime/document.h>
49 #include <interfaces/iplugin.h>
51 #include "core.h"
52 #include "partdocument.h"
53 #include "partcontroller.h"
54 #include "uicontroller.h"
55 #include "statusbar.h"
57 #include "mainwindow.h"
59 namespace KDevelop {
61 bool MainWindowPrivate::s_quitRequested = false;
63 MainWindowPrivate::MainWindowPrivate(MainWindow *mainWindow)
64 : m_mainWindow(mainWindow), m_statusBar(0), lastXMLGUIClientView(0)
68 void MainWindowPrivate::setupGui()
70 m_statusBar = new KDevelop::StatusBar(m_mainWindow);
71 m_mainWindow->setStatusBar(m_statusBar);
74 void MainWindowPrivate::addPlugin( IPlugin *plugin )
76 kDebug() << "add plugin" << plugin << plugin->componentData().componentName();
77 Q_ASSERT( plugin );
79 m_mainWindow->guiFactory()->addClient( plugin );
82 void MainWindowPrivate::removePlugin( IPlugin *plugin )
84 Q_ASSERT( plugin );
86 m_mainWindow->guiFactory()->removeClient( plugin );
89 void MainWindowPrivate::activePartChanged(KParts::Part *part)
91 if ( Core::self()->uiController()->activeMainWindow() == m_mainWindow)
92 m_mainWindow->createGUI(part);
95 void MainWindowPrivate::changeActiveView(Sublime::View *view)
97 // If the previous view was KXMLGUIClient, remove its actions
98 // In the case that that view was removed, lastActiveView
99 // will auto-reset, and xmlguifactory will disconnect that
100 // client, I think.
101 if (lastXMLGUIClientView)
103 kDebug() << "clearing last XML GUI client" << lastXMLGUIClientView;
104 m_mainWindow->guiFactory()->removeClient(
105 dynamic_cast<KXMLGUIClient*>(lastXMLGUIClientView));
106 disconnect (lastXMLGUIClientView, SIGNAL(destroyed(QObject*)), this, 0);
107 lastXMLGUIClientView = NULL;
110 m_statusBar->viewChanged(view);
112 if (!view)
113 return;
115 QWidget* viewWidget = view->widget();
116 Q_ASSERT(viewWidget);
118 kDebug() << "changing active view to" << view << "doc" << view->document() << "mw" << m_mainWindow;
120 IDocument *doc = dynamic_cast<KDevelop::IDocument*>(view->document());
121 if (doc)
123 //activate part if it is not yet activated
124 doc->activate(view, m_mainWindow);
126 else
128 //activated view is not a part document so we need to remove active part gui
129 ///@todo adymo: only this window needs to remove GUI
130 // KParts::Part *activePart = Core::self()->partManager()->activePart();
131 // if (activePart)
132 // guiFactory()->removeClient(activePart);
136 // If the new view is KXMLGUIClient, add it.
137 if (KXMLGUIClient* c = dynamic_cast<KXMLGUIClient*>(viewWidget))
139 lastXMLGUIClientView = viewWidget;
140 m_mainWindow->guiFactory()->addClient(c);
141 connect(viewWidget, SIGNAL(destroyed(QObject*)),
142 this, SLOT(xmlguiclientDestroyed(QObject*)));
146 void MainWindowPrivate::xmlguiclientDestroyed(QObject* obj)
148 /* We're informed the QWidget for the active view that is also
149 KXMLGUIclient is dying. KXMLGUIFactory will not like deleted
150 clients, really. Unfortunately, there's nothing we can do
151 at this point. For example, KateView derives from QWidget and
152 KXMLGUIClient. The destroyed() signal is emitted by ~QWidget.
153 At this point, event attempt to cross-cast to KXMLGUIClient
154 is undefined behaviour. We hope to catch view deletion a bit
155 later, but if we fail, we better report it now, rather than
156 get a weird crash a bit later. */
157 Q_ASSERT(false && "xmlgui clients management is messed up");
160 void MainWindowPrivate::setupActions()
162 KStandardAction::quit( this, SLOT( quitAll() ), actionCollection() );
164 KAction *action;
166 QString app = qApp->applicationName();
167 QString text = i18n( "Configure %1", app );
168 action = KStandardAction::preferences( this, SLOT( settingsDialog() ),
169 actionCollection());
170 action->setToolTip( text );
171 action->setWhatsThis( QString( "<b>%1</b><p>%2<p>" ).arg( text ).arg(
172 i18n( "Lets you customize %1.", app ) ) );
174 action = KStandardAction::showStatusbar( this, SLOT( toggleStatusbar() ),
175 actionCollection());
176 action->setText( i18n( "Show &Statusbar" ) );
177 action->setToolTip( i18n( "Show statusbar" ) );
178 action->setWhatsThis( i18n( "<b>Show statusbar</b><p>Hides or shows the statusbar.</p>" ) );
180 // KToolBarPopupAction *popupAction;
181 // popupAction = new KToolBarPopupAction( KIcon( "process-stop" ),
182 // i18n( "&Stop" ),
183 // actionCollection()
184 // );
185 // actionCollection()->addAction( "stop_processes",popupAction );
187 // popupAction->setShortcut( Qt::Key_Escape );
188 // popupAction->setToolTip( i18n( "Stop" ) );
189 // popupAction->setWhatsThis( i18n( "<b>Stop</b><p>Stops all running processes." ) );
190 // popupAction->setEnabled( false );
191 // connect( popupAction, SIGNAL( triggered() ),
192 // this, SLOT( stopButtonPressed() ) );
193 // connect( popupAction->menu(), SIGNAL( aboutToShow() ),
194 // this, SLOT( stopMenuAboutToShow() ) );
195 // connect( popupAction->menu(), SIGNAL( triggered( Action* ) ),
196 // this, SLOT( stopPopupActivated( QAction* ) ) );
198 action = KStandardAction::showMenubar(
199 this, SLOT( showMenuBar() ),
200 actionCollection());
201 action->setToolTip( action->text() );
202 action->setWhatsThis( QString( "<b>%1</b><p>%2<p>" ).arg( action->text() ).arg( i18n( "Lets you toggle the menubar on/off." ) ) );
204 action = actionCollection()->addAction( "view_next_window" );
205 action->setText( i18n( "&Next Window" ) );
206 connect( action, SIGNAL( triggered( bool ) ), SLOT( gotoNextWindow() ) );
207 action->setShortcut( Qt::ALT + Qt::Key_Right );
208 action->setToolTip( i18n( "Next window" ) );
209 action->setWhatsThis( i18n( "<b>Next window</b><p>Switches to the next window.</p>" ) );
210 action->setIcon(KIcon("go-next"));
212 action = actionCollection()->addAction( "view_previous_window" );
213 action->setText( i18n( "&Previous Window" ) );
214 connect( action, SIGNAL( triggered( bool ) ), SLOT( gotoPreviousWindow() ) );
215 action->setShortcut( Qt::ALT + Qt::Key_Left );
216 action->setToolTip( i18n( "Previous window" ) );
217 action->setWhatsThis( i18n( "<b>Previous window</b><p>Switches to the previous window.</p>" ) );
218 action->setIcon(KIcon("go-previous"));
220 action = actionCollection()->addAction( "view_last_window" );
221 action->setText( i18n( "&Last Accessed Window" ) );
222 connect( action, SIGNAL( triggered( bool ) ), SLOT( gotoLastWindow() ) );
223 action->setShortcut( Qt::ALT + Qt::Key_Up );
224 action->setToolTip( i18n( "Last accessed window" ) );
225 action->setWhatsThis( i18n( "<b>Last accessed window</b><p>Switches to the last viewed window (Hold the Alt key pressed and walk on by repeating the Up key).</p>" ) );
227 action = actionCollection()->addAction( "view_first_window" );
228 action->setText( i18n( "&First Accessed Window" ) );
229 connect( action, SIGNAL( triggered( bool ) ), SLOT( gotoFirstWindow() ) );
230 action->setShortcut( Qt::ALT + Qt::Key_Down );
231 action->setToolTip( i18n( "First accessed window" ) );
232 action->setWhatsThis( i18n( "<b>First accessed window</b><p>Switches to the first accessed window (Hold the Alt key pressed and walk on by repeating the Down key).</p>" ) );
234 action = actionCollection()->addAction( "new_window" );
235 action->setIcon(KIcon( "window-new" ));
236 action->setText( i18n( "&New Window" ) );
237 action->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_N );
238 connect( action, SIGNAL( triggered( bool ) ), SLOT( newWindow() ) );
239 action->setToolTip( i18n( "New Window" ) );
240 action->setWhatsThis( i18n( "<b>New Window</b><p>Creates a new window with a duplicate of current area.</p>" ) );
242 action = actionCollection()->addAction( "split_horizontal" );
243 action->setIcon(KIcon( "view-split-top-bottom" ));
244 action->setText( i18n( "Split View &Top/Bottom" ) );
245 action->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_T );
246 connect( action, SIGNAL( triggered( bool ) ), SLOT( splitHorizontal() ) );
247 action->setToolTip( i18n( "Split Horizontal" ) );
248 action->setWhatsThis( i18n( "<b>Split Horizontal</b><p>Splitts the current view horizontally.</p>" ) );
250 action = actionCollection()->addAction( "split_vertical" );
251 action->setIcon(KIcon( "view-split-left-right" ));
252 action->setText( i18n( "Split View &Left/Right" ) );
253 action->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_L );
254 connect( action, SIGNAL( triggered( bool ) ), SLOT( splitVertical() ) );
255 action->setToolTip( i18n( "Split Vertical" ) );
256 action->setWhatsThis( i18n( "<b>Split Vertical</b><p>Splitts the current view vertically.</p>" ) );
258 action = new KToggleFullScreenAction(m_mainWindow, this);
259 action->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_F11 );
260 actionCollection()->addAction( "fullscreen", action );
261 connect(action, SIGNAL(triggered(bool)), SLOT(toggleFullScreen(bool)));
263 action = actionCollection()->addAction( "file_new" );
264 action->setIcon(KIcon("document-new"));
265 action->setShortcut( Qt::CTRL + Qt::Key_N );
266 action->setText( i18n( "&New File" ) );
267 connect( action, SIGNAL( triggered( bool ) ), SLOT( fileNew() ) );
268 action->setToolTip( i18n( "New File" ) );
269 action->setWhatsThis( i18n( "<b>New File</b><p>Creates an empty file.</p>" ) );
271 action = actionCollection()->addAction( "add_toolview" );
272 action->setIcon(KIcon("window-new"));
273 action->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_V );
274 action->setText( i18n( "&Add Tool View..." ) );
275 connect( action, SIGNAL( triggered( bool ) ), SLOT( viewAddNewToolView() ) );
276 action->setToolTip( i18n( "Add Tool View" ) );
277 action->setWhatsThis( i18n( "<b>Add Tool View</b><p>Adds a new tool view to this window.</p>" ) );
280 KActionCollection * MainWindowPrivate::actionCollection()
282 return m_mainWindow->actionCollection();
285 /* Make sure that the main toolbar has only items from our actionCollection
286 and not from anywhere else. Presently, when new XMLGUI client is added,
287 it's actions are always merged, and there's no clear way to stop this.
288 So, we execute the below code whenever a new client is added. */
289 void MainWindowPrivate::fixToolbar()
291 QWidget* w = m_mainWindow->guiFactory()->container(
292 "mainToolBar", m_mainWindow);
293 if (w)
294 foreach (QAction *a, w->actions())
296 if (m_mainWindow->actionCollection()->action(a->objectName()) != a)
298 w->removeAction(a);
303 bool MainWindowPrivate::applicationQuitRequested() const
305 return s_quitRequested;
308 void MainWindowPrivate::registerStatus(QObject* status)
310 m_statusBar->registerStatus(status);
315 #include "mainwindow_actions.cpp"
316 #include "mainwindow_p.moc"