• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • KDevelop Generic Shell
 

KDevelop Generic Shell

  • src
mainwindowshare.cpp
1/***************************************************************************
2 mainwindowshare.cpp - shared stuff of the main widgets
3 -------------------
4 begin : 19 Dec 2002
5 copyright : (C) 2002 by Falk Brettschneider
6 email : falk@kdevelop.org
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#include <tqcheckbox.h>
19#include <tqvbox.h>
20#include <tqbuttongroup.h>
21#include <tqradiobutton.h>
22#include <tqdir.h>
23#include <tqregexp.h>
24
25#include <kxmlguiclient.h>
26#include <tdeaction.h>
27#include <tdeaboutdata.h>
28#include <kstdaction.h>
29#include <tdeapplication.h>
30#include <tdelocale.h>
31#include <kstatusbar.h>
32#include <tdeparts/mainwindow.h>
33#include <kdialogbase.h>
34#include <tdeconfig.h>
35#include <kkeydialog.h>
36#include <tdemenubar.h>
37#include <kedittoolbar.h>
38#include <kbugreport.h>
39#include <kurlrequester.h>
40#include <tdepopupmenu.h>
41#include <kiconloader.h>
42
43#include <tdetexteditor/document.h>
44#include <tdetexteditor/view.h>
45#include <tdetexteditor/configinterface.h>
46#include <tdeparts/partmanager.h>
47#include <kdebug.h>
48#include <knotifydialog.h>
49
50
51#include <config.h>
52
53#include "partcontroller.h"
54#include "projectmanager.h"
55#include "core.h"
56#include "api.h"
57#include "kdevmakefrontend.h"
58#include "toplevel.h"
59#include "plugincontroller.h"
60
61#include "kdevplugininfo.h"
62
63#include "mainwindowshare.h"
64
65#include "shellextension.h"
66
67using namespace MainWindowUtils;
68
69MainWindowShare::MainWindowShare(TQObject* pParent, const char* name)
70 :TQObject(pParent, name)
71 ,m_toggleMainToolbar(0L)
72 ,m_toggleBuildToolbar(0L)
73 ,m_toggleViewToolbar(0L)
74 ,m_toggleBrowserToolbar(0L)
75 ,m_toggleStatusbar(0L)
76 ,m_stopProcesses(0L)
77{
78 m_pMainWnd = (KParts::MainWindow*)pParent;
79}
80
81void MainWindowShare::init()
82{
83 connect(Core::getInstance(), TQ_SIGNAL(contextMenu(TQPopupMenu *, const Context *)),
84 this, TQ_SLOT(contextMenu(TQPopupMenu *, const Context *)));
85
86 connect( m_pMainWnd->actionCollection(), TQ_SIGNAL( actionStatusText( const TQString & ) ),
87 this, TQ_SLOT( slotActionStatusText( const TQString & ) ) );
88}
89
90void MainWindowShare::slotActionStatusText( const TQString &text )
91{
92// kdDebug(9000) << "MainWindowShare::slotActionStatusText() - " << text << endl;
93
94 if ( ! m_pMainWnd ) return;
95
96 KStatusBar * statusBar = m_pMainWnd->statusBar();
97
98 if ( ! statusBar ) return;
99
100 statusBar->message( text );
101}
102
103void MainWindowShare::createActions()
104{
105 ProjectManager::getInstance()->createActions( m_pMainWnd->actionCollection() );
106
107 KStdAction::quit(this->parent(), TQ_SLOT(close()), m_pMainWnd->actionCollection());
108
109 TDEAction* action;
110
111 m_stopProcesses = new TDEToolBarPopupAction( i18n( "&Stop" ), "process-stop",
112 Key_Escape, this, TQ_SLOT(slotStopButtonPressed()),
113 m_pMainWnd->actionCollection(), "stop_processes" );
114 m_stopProcesses->setToolTip(i18n("Stop"));
115 m_stopProcesses->setWhatsThis(i18n("<b>Stop</b><p>Stops all running processes (like building process, grep command, etc.). When placed onto a toolbar provides a popup menu to choose a process to stop."));
116 m_stopProcesses->setEnabled( false );
117 connect(m_stopProcesses->popupMenu(), TQ_SIGNAL(aboutToShow()),
118 this, TQ_SLOT(slotStopMenuAboutToShow()));
119 connect(m_stopProcesses->popupMenu(), TQ_SIGNAL(activated(int)),
120 this, TQ_SLOT(slotStopPopupActivated(int)));
121
122 connect( Core::getInstance(), TQ_SIGNAL(activeProcessChanged(KDevPlugin*, bool)),
123 this, TQ_SLOT(slotActiveProcessChanged(KDevPlugin*, bool)) );
124
125 action = KStdAction::showMenubar(
126 this, TQ_SLOT(slotShowMenuBar()),
127 m_pMainWnd->actionCollection(), "settings_show_menubar" );
128 action->setToolTip(beautifyToolTip(action->text()));
129 action->setWhatsThis(TQString("<b>%1</b><p>%2").arg(beautifyToolTip(action->text())).arg(i18n("Lets you switch the menubar on/off.")));
130
131 action = KStdAction::keyBindings(
132 this, TQ_SLOT(slotKeyBindings()),
133 m_pMainWnd->actionCollection(), "settings_configure_shortcuts" );
134 action->setToolTip(beautifyToolTip(action->text()));
135 action->setWhatsThis(TQString("<b>%1</b><p>%2").arg(beautifyToolTip(action->text())).arg(i18n("Lets you configure shortcut keys.")));
136
137 action = KStdAction::configureToolbars(
138 this, TQ_SLOT(slotConfigureToolbars()),
139 m_pMainWnd->actionCollection(), "settings_configure_toolbars" );
140 action->setToolTip(beautifyToolTip(action->text()));
141 action->setWhatsThis(TQString("<b>%1</b><p>%2").arg(beautifyToolTip(action->text())).arg(i18n("Lets you configure toolbars.")));
142
143 action = KStdAction::configureNotifications(
144 this, TQ_SLOT(slotConfigureNotifications()),
145 m_pMainWnd->actionCollection(), "settings_configure_notifications" );
146 action->setToolTip(beautifyToolTip(action->text()));
147 action->setWhatsThis(TQString("<b>%1</b><p>%2").arg(beautifyToolTip(action->text())).arg(i18n("Lets you configure system notifications.")));
148
149 action = KStdAction::preferences(this, TQ_SLOT(slotSettings()),
150 m_pMainWnd->actionCollection(), "settings_configure" );
151 action->setToolTip( i18n( "Configure TDevelop" ) );
152 action->setWhatsThis(TQString("<b>%1</b><p>%2").arg(i18n( "Configure TDevelop" )).arg(i18n("Lets you customize TDevelop.")));
153
154 m_toggleStatusbar = KStdAction::showToolbar(this, TQ_SLOT(slotToggleStatusbar()),m_pMainWnd->actionCollection(), "settings_statusbar");
155 m_toggleStatusbar->setText(i18n("Show &Statusbar"));
156 m_toggleStatusbar->setToolTip( i18n("Show statusbar") );
157 m_toggleStatusbar->setWhatsThis(i18n("<b>Show statusbar</b><p>Hides or shows the statusbar."));
158
159 action = new TDEAction( i18n("&Next Window"), ALT+Key_Right, this, TQ_SIGNAL(gotoNextWindow()),m_pMainWnd->actionCollection(), "view_next_window");
160 action->setToolTip( i18n("Next window") );
161 action->setWhatsThis(i18n("<b>Next window</b><p>Switches to the next window."));
162
163 action = new TDEAction( i18n("&Previous Window"), ALT+Key_Left, this, TQ_SIGNAL(gotoPreviousWindow()),m_pMainWnd->actionCollection(), "view_previous_window");
164 action->setToolTip( i18n("Previous window") );
165 action->setWhatsThis(i18n("<b>Previous window</b><p>Switches to the previous window."));
166
167 action = new TDEAction( i18n("&Last Accessed Window"), ALT+Key_Up, this, TQ_SIGNAL(gotoLastWindow()), m_pMainWnd->actionCollection(), "view_last_window");
168 action->setToolTip( i18n("Last accessed window") );
169 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)."));
170
171 action = new TDEAction( i18n("&First Accessed Window"), ALT+Key_Down, this, TQ_SIGNAL(gotoFirstWindow()), m_pMainWnd->actionCollection(), "view_first_window");
172 action->setToolTip( i18n("First accessed window") );
173 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)."));
174
175 action = new TDEAction( i18n("Configure Plugins..."), SmallIconSet("configure"), 0, PluginController::getInstance(), TQ_SLOT(selectPlugins()), m_pMainWnd->actionCollection(), "settings_configure_plugins" );
176
177 m_configureEditorAction = new TDEAction( i18n("Configure &Editor..."), SmallIconSet("configure"), 0, this, TQ_SLOT( slotConfigureEditors() ), m_pMainWnd->actionCollection(), "settings_configure_editors");
178 m_configureEditorAction->setToolTip( i18n("Configure editor settings") );
179 m_configureEditorAction->setWhatsThis(i18n("<b>Configure editor</b><p>Opens editor configuration dialog."));
180 m_configureEditorAction->setEnabled( false );
181
182 KDevPartController * partController = API::getInstance()->partController();
183 connect( partController, TQ_SIGNAL(activePartChanged(KParts::Part*)), this, TQ_SLOT(slotActivePartChanged(KParts::Part* )) );
184}
185
186void MainWindowShare::slotReportBug()
187{
188 KBugReport a(m_pMainWnd, true, TDEGlobal::instance()->aboutData() );
189 a.exec();
190}
191
192void MainWindowShare::slotToggleMainToolbar()
193{
194 if (m_toggleMainToolbar->isChecked())
195 m_pMainWnd->toolBar("mainToolBar")->show();
196 else
197 m_pMainWnd->toolBar("mainToolBar")->hide();
198}
199
200void MainWindowShare::slotToggleBuildToolbar()
201{
202 if (m_toggleBuildToolbar->isChecked())
203 m_pMainWnd->toolBar("buildToolBar")->show();
204 else
205 m_pMainWnd->toolBar("buildToolBar")->hide();
206}
207
208void MainWindowShare::slotToggleViewToolbar()
209{
210 if (m_toggleViewToolbar->isChecked())
211 m_pMainWnd->toolBar("viewToolBar")->show();
212 else
213 m_pMainWnd->toolBar("viewToolBar")->hide();
214}
215
216void MainWindowShare::slotToggleBrowserToolbar()
217{
218 if (m_toggleBrowserToolbar->isChecked())
219 m_pMainWnd->toolBar("browserToolBar")->show();
220 else
221 m_pMainWnd->toolBar("browserToolBar")->hide();
222}
223
224void MainWindowShare::slotToggleStatusbar()
225{
226 KStatusBar* sb = (KStatusBar*) m_pMainWnd->statusBar();
227 if (m_toggleStatusbar->isChecked())
228 sb->show();
229 else
230 sb->hide();
231}
232
233void MainWindowShare::slotStopButtonPressed()
234{
235 Core::getInstance()->doEmitStopButtonPressed();
236}
237
238void MainWindowShare::slotActiveProcessChanged( KDevPlugin* plugin, bool active )
239{
240 if ( !plugin )
241 return;
242
243 if ( active ) {
244 activeProcesses.append( plugin );
245 } else {
246 activeProcesses.removeRef( plugin );
247 }
248 m_stopProcesses->setEnabled( !activeProcesses.isEmpty() );
249}
250
251void MainWindowShare::slotStopPopupActivated( int id )
252{
253 KDevPlugin* plugin = activeProcesses.at( id );
254 if ( plugin && plugin->info()->genericName() == m_stopProcesses->popupMenu()->text( id ) ) {
255 Core::getInstance()->doEmitStopButtonPressed( plugin );
256 return;
257 } else {
258 // oops... list has changed in the meantime
259 TQString str = m_stopProcesses->popupMenu()->text( id );
260 for ( plugin = activeProcesses.first(); plugin; plugin = activeProcesses.next() ) {
261 if ( plugin->info()->genericName() == str ) {
262 Core::getInstance()->doEmitStopButtonPressed( plugin );
263 return;
264 }
265 }
266 }
267}
268
269void MainWindowShare::slotStopMenuAboutToShow()
270{
271 TQPopupMenu* popup = m_stopProcesses->popupMenu();
272 popup->clear();
273
274 int i = 0;
275 for ( KDevPlugin* plugin = activeProcesses.first(); plugin; plugin = activeProcesses.next() ) {
276 popup->insertItem( plugin->info()->genericName(), i++ );
277 }
278}
279
280void MainWindowShare::slotShowMenuBar()
281{
282 if (m_pMainWnd->menuBar()->isVisible()) {
283 m_pMainWnd->menuBar()->hide();
284 } else {
285 m_pMainWnd->menuBar()->show();
286 }
287 m_pMainWnd->saveMainWindowSettings( TDEGlobal::config(), "Mainwindow" );
288}
289
290void MainWindowShare::slotConfigureNotifications()
291{
292 KNotifyDialog::configure(m_pMainWnd, "Notification Configuration Dialog");
293}
294
295void MainWindowShare::slotSettings()
296{
297 KDialogBase dlg(KDialogBase::IconList, i18n("Configure TDevelop"),
298 KDialogBase::Help|KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok, m_pMainWnd,
299 "customization dialog");
300 dlg.setHelp("setup");
301
302 ShellExtension::getInstance()->createGlobalSettingsPage(&dlg);
303
304 TDEConfig* config = kapp->config();
305
306 config->setGroup("Global Settings Dialog");
307 int height = config->readNumEntry( "Height", 600 );
308 int width = config->readNumEntry( "Width", 800 );
309
310 dlg.resize( width, height );
311
312 Core::getInstance()->doEmitConfigWidget(&dlg);
313 dlg.exec();
314
315 config->setGroup("Global Settings Dialog");
316 config->writeEntry( "Height", dlg.size().height() );
317 config->writeEntry( "Width", dlg.size().width() );
318
319 if ( dlg.result() != TQDialog::Rejected )
320 ShellExtension::getInstance()->acceptGlobalSettingsPage(&dlg);
321}
322
323void MainWindowShare::slotConfigureEditors()
324{
325 kdDebug(9000) << " *** MainWindowShare::slotConfigureEditors()" << endl;
326
327 KDevPartController * partController = API::getInstance()->partController();
328 KParts::Part * part = partController->activePart();
329
330 KTextEditor::ConfigInterface * conf = dynamic_cast<KTextEditor::ConfigInterface*>( part );
331 if ( ! conf )
332 {
333 kdDebug(9000) << "*** No KTextEditor::ConfigInterface for part!" << endl;
334 return;
335 }
336
337 // show the modal config dialog for this part if it has a ConfigInterface
338 conf->configDialog();
339 conf->writeConfig();
340
341}
342
343void MainWindowShare::slotGUICreated( KParts::Part * part )
344{
345// kdDebug(9000) << "MainWindowShare::slotGUICreated()" << endl;
346
347 if ( ! part ) return;
348
349 // disable configuration entry if created part is not an editor
350 if ( ! dynamic_cast<KTextEditor::ConfigInterface *>( part ) )
351 {
352 m_configureEditorAction->setEnabled( false );
353 return;
354 }
355
356 m_configureEditorAction->setEnabled( true );
357
358 // remove the part's merged menu entry
359 TDEAction * action = part->action("set_confdlg"); // name from katepartui.rc
360 if ( action )
361 {
362 kdDebug(9000) << " *** found \"set_confdlg\" action - unplugging" << endl;
363 action->unplugAll();
364 }
365
366 if ( TDEAction * action = part->action("file_save") )
367 {
368 kdDebug(9000) << " *** found \"file_save\" action - disconnecting" << endl;
369 disconnect( action, TQ_SIGNAL(activated()), 0, 0 );
370 connect( action, TQ_SIGNAL(activated()), PartController::getInstance(), TQ_SLOT(slotSave()) );
371 }
372
373 if ( TDEAction * action = part->action("file_reload") )
374 {
375 kdDebug(9000) << " *** found \"file_reload\" action - disconnecting" << endl;
376 disconnect( action, TQ_SIGNAL(activated()), 0, 0 );
377 connect( action, TQ_SIGNAL(activated()), PartController::getInstance(), TQ_SLOT(slotReload()) );
378 }
379}
380
381// called when OK ar Apply is clicked in the EditToolbar Dialog
382void MainWindowShare::slotNewToolbarConfig()
383{
384 // replug actionlists here...
385
386 m_pMainWnd->applyMainWindowSettings( TDEGlobal::config(), "Mainwindow" );
387
388// PartController::getInstance()->reinstallPopups();
389}
390
391void MainWindowShare::slotKeyBindings()
392{
393 KKeyDialog dlg( false, m_pMainWnd );
394 TQPtrList<KXMLGUIClient> clients = m_pMainWnd->guiFactory()->clients();
395 for( TQPtrListIterator<KXMLGUIClient> it( clients );
396 it.current(); ++it ) {
397 dlg.insert( (*it)->actionCollection() );
398 }
399 if ( dlg.configure() == KKeyDialog::Accepted )
400 {
401 // this is needed for when we have multiple embedded kateparts and change one of them.
402 // it also needs to be done to their views, as they too have actioncollections to update
403 if( const TQPtrList<KParts::Part> * partlist = PartController::getInstance()->parts() )
404 {
405 TQPtrListIterator<KParts::Part> it( *partlist );
406 while ( KParts::Part* part = it.current() )
407 {
408 if ( KTextEditor::Document * doc = dynamic_cast<KTextEditor::Document*>( part ) )
409 {
410 doc->reloadXML();
411
412 TQPtrList<KTextEditor::View> const & list = doc->views();
413 TQPtrListIterator<KTextEditor::View> itt( list );
414 while( KTextEditor::View * view = itt.current() )
415 {
416 view->reloadXML();
417 ++itt;
418 }
419 }
420 ++it;
421 }
422 }
423 Core::setupShourtcutTips();
424 }
425}
426
427void MainWindowShare::slotConfigureToolbars()
428{
429 m_pMainWnd->saveMainWindowSettings( TDEGlobal::config(), "Mainwindow" );
430 KEditToolbar dlg( m_pMainWnd->factory() );
431 connect(&dlg, TQ_SIGNAL(newToolbarConfig()), this, TQ_SLOT(slotNewToolbarConfig()));
432 dlg.exec();
433}
434
435void MainWindowShare::contextMenu(TQPopupMenu* popup, const Context *)
436{
437 if ( m_pMainWnd->menuBar()->isVisible() )
438 return;
439
440 int id = popup->insertItem( i18n("Show &Menubar"), m_pMainWnd->menuBar(), TQ_SLOT(show()) );
441 popup->TQMenuData::setWhatsThis(id, i18n("<b>Show menubar</b><p>Lets you switch the menubar on/off."));
442}
443
444void MainWindowShare::slotActivePartChanged( KParts::Part * part )
445{
446 m_configureEditorAction->setEnabled( part && dynamic_cast<KTextEditor::Document*>(part) );
447}
448
449#include "mainwindowshare.moc"
Core::setupShourtcutTips
static void setupShourtcutTips(KXMLGUIClient *client=0)
Setup shourtcut tips.
Definition core.cpp:31
ShellExtension::getInstance
static ShellExtension * getInstance()
Returns an instance of a shell.
Definition shellextension.h:42
ShellExtension::createGlobalSettingsPage
virtual void createGlobalSettingsPage(KDialogBase *dlg)=0
Reimplement to create global settings page in the dialog dlg.
ShellExtension::acceptGlobalSettingsPage
virtual void acceptGlobalSettingsPage(KDialogBase *dlg)=0
Reimplement to perform actions when the global settings page in the dialog dlg is accepted (user clic...

KDevelop Generic Shell

Skip menu "KDevelop Generic Shell"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

KDevelop Generic Shell

Skip menu "KDevelop Generic Shell"
  • buildtools
  •   lib
  •     base
  •     parsers
  •       autotools
  •       qmake
  •     widgets
  •   api
  • languages
  •   lib
  •     debugger
  •     designer_integration
  •     interfaces
  • lib
  •   catalog
  •   interfaces
  •     extensions
  •     external
  •     extras
  •   util
  •   widgets
  •     propeditor
  • parts
  •   documentation
  •     interfaces
  • src
  •   profileengine
  •     lib
Generated for KDevelop Generic Shell by doxygen 1.15.0
This website is maintained by Timothy Pearson.