18#include <tqcheckbox.h>
20#include <tqbuttongroup.h>
21#include <tqradiobutton.h>
25#include <kxmlguiclient.h>
27#include <tdeaboutdata.h>
28#include <kstdaction.h>
29#include <tdeapplication.h>
31#include <kstatusbar.h>
32#include <tdeparts/mainwindow.h>
33#include <kdialogbase.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>
43#include <tdetexteditor/document.h>
44#include <tdetexteditor/view.h>
45#include <tdetexteditor/configinterface.h>
46#include <tdeparts/partmanager.h>
48#include <knotifydialog.h>
53#include "partcontroller.h"
54#include "projectmanager.h"
57#include "kdevmakefrontend.h"
59#include "plugincontroller.h"
61#include "kdevplugininfo.h"
63#include "mainwindowshare.h"
65#include "shellextension.h"
67using namespace MainWindowUtils;
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)
78 m_pMainWnd = (KParts::MainWindow*)pParent;
81void MainWindowShare::init()
83 connect(Core::getInstance(), TQ_SIGNAL(contextMenu(TQPopupMenu *,
const Context *)),
84 this, TQ_SLOT(contextMenu(TQPopupMenu *,
const Context *)));
86 connect( m_pMainWnd->actionCollection(), TQ_SIGNAL( actionStatusText(
const TQString & ) ),
87 this, TQ_SLOT( slotActionStatusText(
const TQString & ) ) );
90void MainWindowShare::slotActionStatusText(
const TQString &text )
94 if ( ! m_pMainWnd )
return;
96 KStatusBar * statusBar = m_pMainWnd->statusBar();
98 if ( ! statusBar )
return;
100 statusBar->message( text );
103void MainWindowShare::createActions()
105 ProjectManager::getInstance()->createActions( m_pMainWnd->actionCollection() );
107 KStdAction::quit(this->parent(), TQ_SLOT(close()), m_pMainWnd->actionCollection());
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)));
122 connect( Core::getInstance(), TQ_SIGNAL(activeProcessChanged(KDevPlugin*,
bool)),
123 this, TQ_SLOT(slotActiveProcessChanged(KDevPlugin*,
bool)) );
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.")));
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.")));
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.")));
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.")));
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.")));
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."));
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."));
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."));
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)."));
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)."));
175 action =
new TDEAction( i18n(
"Configure Plugins..."), SmallIconSet(
"configure"), 0, PluginController::getInstance(), TQ_SLOT(selectPlugins()), m_pMainWnd->actionCollection(),
"settings_configure_plugins" );
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 );
182 KDevPartController * partController = API::getInstance()->partController();
183 connect( partController, TQ_SIGNAL(activePartChanged(KParts::Part*)),
this, TQ_SLOT(slotActivePartChanged(KParts::Part* )) );
186void MainWindowShare::slotReportBug()
188 KBugReport a(m_pMainWnd,
true, TDEGlobal::instance()->aboutData() );
192void MainWindowShare::slotToggleMainToolbar()
194 if (m_toggleMainToolbar->isChecked())
195 m_pMainWnd->toolBar(
"mainToolBar")->show();
197 m_pMainWnd->toolBar(
"mainToolBar")->hide();
200void MainWindowShare::slotToggleBuildToolbar()
202 if (m_toggleBuildToolbar->isChecked())
203 m_pMainWnd->toolBar(
"buildToolBar")->show();
205 m_pMainWnd->toolBar(
"buildToolBar")->hide();
208void MainWindowShare::slotToggleViewToolbar()
210 if (m_toggleViewToolbar->isChecked())
211 m_pMainWnd->toolBar(
"viewToolBar")->show();
213 m_pMainWnd->toolBar(
"viewToolBar")->hide();
216void MainWindowShare::slotToggleBrowserToolbar()
218 if (m_toggleBrowserToolbar->isChecked())
219 m_pMainWnd->toolBar(
"browserToolBar")->show();
221 m_pMainWnd->toolBar(
"browserToolBar")->hide();
224void MainWindowShare::slotToggleStatusbar()
226 KStatusBar* sb = (KStatusBar*) m_pMainWnd->statusBar();
227 if (m_toggleStatusbar->isChecked())
233void MainWindowShare::slotStopButtonPressed()
235 Core::getInstance()->doEmitStopButtonPressed();
238void MainWindowShare::slotActiveProcessChanged( KDevPlugin* plugin,
bool active )
244 activeProcesses.append( plugin );
246 activeProcesses.removeRef( plugin );
248 m_stopProcesses->setEnabled( !activeProcesses.isEmpty() );
251void MainWindowShare::slotStopPopupActivated(
int id )
253 KDevPlugin* plugin = activeProcesses.at(
id );
254 if ( plugin && plugin->info()->genericName() == m_stopProcesses->popupMenu()->text(
id ) ) {
255 Core::getInstance()->doEmitStopButtonPressed( plugin );
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 );
269void MainWindowShare::slotStopMenuAboutToShow()
271 TQPopupMenu* popup = m_stopProcesses->popupMenu();
275 for ( KDevPlugin* plugin = activeProcesses.first(); plugin; plugin = activeProcesses.next() ) {
276 popup->insertItem( plugin->info()->genericName(), i++ );
280void MainWindowShare::slotShowMenuBar()
282 if (m_pMainWnd->menuBar()->isVisible()) {
283 m_pMainWnd->menuBar()->hide();
285 m_pMainWnd->menuBar()->show();
287 m_pMainWnd->saveMainWindowSettings( TDEGlobal::config(),
"Mainwindow" );
290void MainWindowShare::slotConfigureNotifications()
292 KNotifyDialog::configure(m_pMainWnd,
"Notification Configuration Dialog");
295void MainWindowShare::slotSettings()
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");
304 TDEConfig* config = kapp->config();
306 config->setGroup(
"Global Settings Dialog");
307 int height = config->readNumEntry(
"Height", 600 );
308 int width = config->readNumEntry(
"Width", 800 );
310 dlg.resize( width, height );
312 Core::getInstance()->doEmitConfigWidget(&dlg);
315 config->setGroup(
"Global Settings Dialog");
316 config->writeEntry(
"Height", dlg.size().height() );
317 config->writeEntry(
"Width", dlg.size().width() );
319 if ( dlg.result() != TQDialog::Rejected )
323void MainWindowShare::slotConfigureEditors()
325 kdDebug(9000) <<
" *** MainWindowShare::slotConfigureEditors()" << endl;
327 KDevPartController * partController = API::getInstance()->partController();
328 KParts::Part * part = partController->activePart();
330 KTextEditor::ConfigInterface * conf =
dynamic_cast<KTextEditor::ConfigInterface*
>( part );
333 kdDebug(9000) <<
"*** No KTextEditor::ConfigInterface for part!" << endl;
338 conf->configDialog();
343void MainWindowShare::slotGUICreated( KParts::Part * part )
347 if ( ! part )
return;
350 if ( !
dynamic_cast<KTextEditor::ConfigInterface *
>( part ) )
352 m_configureEditorAction->setEnabled(
false );
356 m_configureEditorAction->setEnabled(
true );
359 TDEAction * action = part->action(
"set_confdlg");
362 kdDebug(9000) <<
" *** found \"set_confdlg\" action - unplugging" << endl;
366 if ( TDEAction * action = part->action(
"file_save") )
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()) );
373 if ( TDEAction * action = part->action(
"file_reload") )
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()) );
382void MainWindowShare::slotNewToolbarConfig()
386 m_pMainWnd->applyMainWindowSettings( TDEGlobal::config(),
"Mainwindow" );
391void MainWindowShare::slotKeyBindings()
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() );
399 if ( dlg.configure() == KKeyDialog::Accepted )
403 if(
const TQPtrList<KParts::Part> * partlist = PartController::getInstance()->parts() )
405 TQPtrListIterator<KParts::Part> it( *partlist );
406 while ( KParts::Part* part = it.current() )
408 if ( KTextEditor::Document * doc =
dynamic_cast<KTextEditor::Document*
>( part ) )
412 TQPtrList<KTextEditor::View>
const & list = doc->views();
413 TQPtrListIterator<KTextEditor::View> itt( list );
414 while( KTextEditor::View * view = itt.current() )
427void MainWindowShare::slotConfigureToolbars()
429 m_pMainWnd->saveMainWindowSettings( TDEGlobal::config(),
"Mainwindow" );
430 KEditToolbar dlg( m_pMainWnd->factory() );
431 connect(&dlg, TQ_SIGNAL(newToolbarConfig()),
this, TQ_SLOT(slotNewToolbarConfig()));
435void MainWindowShare::contextMenu(TQPopupMenu* popup,
const Context *)
437 if ( m_pMainWnd->menuBar()->isVisible() )
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."));
444void MainWindowShare::slotActivePartChanged( KParts::Part * part )
446 m_configureEditorAction->setEnabled( part &&
dynamic_cast<KTextEditor::Document*
>(part) );
449#include "mainwindowshare.moc"
static void setupShourtcutTips(KXMLGUIClient *client=0)
Setup shourtcut tips.
static ShellExtension * getInstance()
Returns an instance of a shell.
virtual void createGlobalSettingsPage(KDialogBase *dlg)=0
Reimplement to create global settings page in the dialog dlg.
virtual void acceptGlobalSettingsPage(KDialogBase *dlg)=0
Reimplement to perform actions when the global settings page in the dialog dlg is accepted (user clic...