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

KDevelop Generic Shell

  • src
simplemainwindow.cpp
1/***************************************************************************
2 * Copyright (C) 2005 by Alexander Dymo *
3 * adymo@kdevelop.org *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU Library General Public License as *
7 * published by the Free Software Foundation; either version 2 of the *
8 * License, or (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU Library General Public *
16 * License along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
20#include "simplemainwindow.h"
21
22#include <tqtextedit.h>
23
24#include <tdeaction.h>
25#include <kstdaction.h>
26#include <tdeparts/part.h>
27#include <tdepopupmenu.h>
28#include <tdemenubar.h>
29#include <tdemessagebox.h>
30#include <tdelocale.h>
31#include <kiconloader.h>
32#include <kedittoolbar.h>
33#include <tdetexteditor/view.h>
34#include <tdetexteditor/document.h>
35#include <tdeapplication.h>
36#include <kurldrag.h>
37#include <tdeconfig.h>
38
39#include <ddockwindow.h>
40#include <dtabwidget.h>
41#include <profile.h>
42#include <profileengine.h>
43#include <designer.h>
44#include <kdevproject.h>
45#include <urlutil.h>
46
47#include "api.h"
48#include "core.h"
49#include "plugincontroller.h"
50#include "mainwindowshare.h"
51#include "shellextension.h"
52#include "partcontroller.h"
53#include "statusbar.h"
54#include "documentationpart.h"
55#include "toplevel.h"
56#include "projectmanager.h"
57#include "editorproxy.h"
58#include "multibuffer.h"
59
60SimpleMainWindow::SimpleMainWindow(TQWidget* parent, const char *name)
61 :DMainWindow(parent, name)
62{
63 resize(800, 600); // starts tdevelop at 800x600 the first time
64 m_mainWindowShare = new MainWindowShare(this);
65
66 connect(m_bottomDock, TQ_SIGNAL(hidden()), this, TQ_SLOT(raiseEditor()));
67 connect(m_leftDock, TQ_SIGNAL(hidden()), this, TQ_SLOT(raiseEditor()));
68 connect(m_rightDock, TQ_SIGNAL(hidden()), this, TQ_SLOT(raiseEditor()));
69}
70
71SimpleMainWindow::~ SimpleMainWindow( )
72{
73 TopLevel::invalidateInstance( this );
74}
75
76void SimpleMainWindow::init()
77{
78 actionCollection()->setHighlightingEnabled( true );
79 setStandardToolBarMenuEnabled( true );
80 setXMLFile(ShellExtension::getInstance()->xmlFile());
81
82 createFramework();
83 createActions();
84 new KDevStatusBar(this);
85
86 setAcceptDrops(true);
87
88 createGUI(0);
89
90 m_mainWindowShare->init();
91 setupWindowMenu();
92
93 // Add TDE Programming handbook to Help menu
94 TQMenuBar *mbar = menuBar();
95 TDEPopupMenu *help_menu = dynamic_cast<TDEPopupMenu*>
96 (menuBar()->findItem(mbar->idAt(mbar->count()-1))->popup());
97 if (help_menu)
98 {
99 help_menu->insertItem(SmallIconSet("contents"), i18n("TDevelop &Programming Handbook"),
100 this, TQ_SLOT(slotProgrammingHandbook()), 0, -1, 1);
101 }
102
103 menuBar()->setEnabled( false );
104
105 //FIXME: this checks only for global offers which is not quite correct because
106 //a profile can offer core plugins and no global plugins.
107 if ( PluginController::getInstance()->engine().allOffers(ProfileEngine::Global).isEmpty() )
108 {
109 KMessageBox::sorry( this, i18n("Unable to find plugins, TDevelop will not work"
110 " properly.\nPlease make sure "
111 "that TDevelop is installed in your TDE directory; otherwise, you have "
112 "to add TDevelop's installation "
113 "path to the environment variable TDEDIRS and run tdebuildsycoca. Restart "
114 "TDevelop afterwards.\n"
115 "Example for BASH users:\nexport TDEDIRS=/path/to/tdevelop:$TDEDIRS && tdebuildsycoca"),
116 i18n("Could Not Find Plugins") );
117 }
118
119 connect(Core::getInstance(), TQ_SIGNAL(coreInitialized()), this, TQ_SLOT(slotCoreInitialized()));
120 connect(Core::getInstance(), TQ_SIGNAL(projectOpened()), this, TQ_SLOT(projectOpened()));
121 connect(Core::getInstance(), TQ_SIGNAL(projectClosed()), this, TQ_SLOT(projectClosed()));
122 connect(Core::getInstance(), TQ_SIGNAL(contextMenu(TQPopupMenu *, const Context *)),
123 this, TQ_SLOT(contextMenu(TQPopupMenu *, const Context *)));
124 connect(PartController::getInstance(), TQ_SIGNAL(partURLChanged(KParts::ReadOnlyPart *)),
125 this, TQ_SLOT(slotPartURLChanged(KParts::ReadOnlyPart * )));
126 connect(PartController::getInstance(), TQ_SIGNAL(activePartChanged(KParts::Part*)),
127 this, TQ_SLOT(activePartChanged(KParts::Part*)));
128
129 connect(PartController::getInstance(),
130 TQ_SIGNAL(documentChangedState(const KURL &, DocumentState)),
131 this, TQ_SLOT(documentChangedState(const KURL&, DocumentState)));
132
133 loadSettings();
134}
135
136void SimpleMainWindow::dragEnterEvent( TQDragEnterEvent *event )
137{
138 event->accept(KURLDrag::canDecode(event));
139}
140
141void SimpleMainWindow::dropEvent( TQDropEvent *event )
142{
143 slotDropEvent(event);
144}
145
146void SimpleMainWindow::slotDropEvent( TQDropEvent *event )
147{
148 KURL::List list;
149 if ( !KURLDrag::decode( event, list ) ) return;
150
151 KURL::List::Iterator it = list.begin();
152 while( it != list.end() )
153 {
154 kdDebug(9000) << "drop url:" << *it << endl;
155 PartController::getInstance()->editDocument( *it );
156 ++it;
157 }
158}
159
160void SimpleMainWindow::contextMenu(TQPopupMenu *popupMenu, const Context *context)
161{
162 int cont = context->type();
163 m_splitURLs.clear();
164 if (cont == Context::EditorContext)
165 {
166 KURL url = static_cast<const EditorContext*>(context)->url();
167 TQWidget *w = widgetForURL(url);
168 if (w && m_widgetTabs[w] && m_widgetTabs[w]->count() > 1)
169 {
170 m_splitURLs.append(url);
171 m_splitHor1->plug(popupMenu);
172 m_splitVer1->plug(popupMenu);
173 popupMenu->insertSeparator();
174 }
175 }
176 else if (cont == Context::FileContext)
177 {
178 if (PartController::getInstance()->openURLs().count() > 0)
179 {
180 KURL::List urls = static_cast<const FileContext*>(context)->urls();
181 KURL::List::ConstIterator it = urls.begin();
182 while ( it != urls.end() )
183 {
184 if ( !URLUtil::isDirectory( *it ) )
185 {
186 m_splitURLs.append( *it );
187 }
188 ++it;
189 }
190
191 if ( m_splitURLs.isEmpty() ) return;
192
193 bool isOpen = true;
194 for (KURL::List::const_iterator it = m_splitURLs.begin(); it != m_splitURLs.end(); ++it)
195 {
196 if (!PartController::getInstance()->openURLs().contains(*it) && (*it).isValid())
197 {
198 isOpen = false;
199 break;
200 }
201 }
202
203 if ( (isOpen && PartController::getInstance()->openURLs().count() == 1) ||
204 (m_splitURLs.count() == 1 && !(*m_splitURLs.begin()).isValid() ) )
205 {
206 return;
207 }
208
209 popupMenu->insertSeparator();
210 if (isOpen)
211 {
212 m_splitHor1->plug(popupMenu);
213 m_splitVer1->plug(popupMenu);
214 }
215 else
216 {
217 m_splitHor2->plug(popupMenu);
218 m_splitVer2->plug(popupMenu);
219 }
220 }
221 }
222}
223
224void SimpleMainWindow::embedPartView(TQWidget *view, const TQString &title, const TQString &/*toolTip*/)
225{
226 kdDebug() << "SimpleMainWindow::embedPartView: " << view << endl;
227 if (!view )
228 return;
229
230 TQString shortName = title;
231 shortName = shortName.right( shortName.length() - (shortName.findRev('/') +1));
232
233 addWidget(view, title);
234 view->show();
235}
236
237void SimpleMainWindow::embedSelectView(TQWidget *view, const TQString &title, const TQString &/*toolTip*/)
238{
239 embedView( DDockWindow::Left, view, title );
240}
241
242void SimpleMainWindow::embedOutputView(TQWidget *view, const TQString &title, const TQString &/*toolTip*/)
243{
244 embedView( DDockWindow::Bottom, view, title );
245}
246
247void SimpleMainWindow::embedSelectViewRight(TQWidget *view, const TQString &title, const TQString &/*toolTip*/)
248{
249 embedView( DDockWindow::Right, view, title );
250}
251
252void SimpleMainWindow::embedView( DDockWindow::Position pos, TQWidget * view, const TQString & title )
253{
254 if ( !hasDockWidget( view ) )
255 {
256 DDockWindow::Position position = recallToolViewPosition( view->name(), pos );
257 addDockWidget(position, view, title);
258 }
259}
260
261DDockWindow::Position SimpleMainWindow::recallToolViewPosition( const TQString & name, DDockWindow::Position defaultPos )
262{
263 TDEConfig * config = kapp->config();
264 config->setGroup( "DToolDockPosition" );
265
266 TQString position = config->readEntry( name );
267
268 if ( name == "unknown" )
269 {
270 kdDebug() << name << endl;
271 }
272
273 if ( position == "DockLeft" ) return DDockWindow::Left;
274 if ( position == "DockRight" ) return DDockWindow::Right;
275 if ( position == "DockBottom" ) return DDockWindow::Bottom;
276
277 return defaultPos;
278}
279
280void SimpleMainWindow::rememberToolViewPosition( const TQString & name, DDockWindow::Position pos )
281{
282 TDEConfig * config = kapp->config();
283 config->setGroup( "DToolDockPosition" );
284
285 TQString position = "unknown";
286
287 switch( pos )
288 {
289 case DDockWindow::Left:
290 position = "DockLeft";
291 break;
292 case DDockWindow::Right:
293 position = "DockRight";
294 break;
295 case DDockWindow::Bottom:
296 position = "DockBottom";
297 break;
298 default: ;
299 }
300
301 config->writeEntry( name, position );
302}
303
304
305void SimpleMainWindow::removeView(TQWidget *view)
306{
307 if (!view)
308 return;
309
310 //try to remove it from all parts of main window
311 //@fixme This method needs to be divided in two - one for docks and one for part views
312 if (hasDockWidget(view))
313 {
314 rememberToolViewPosition( view->name(), dockWidgetPosition(view) );
315 removeDockWidget(view);
316 }
317 else
318 removeWidget(view);
319}
320
321void SimpleMainWindow::setViewAvailable(TQWidget *pView, bool bEnabled)
322{
323 DDockWindow *dock;
324 if (hasDockWidget(pView))
325 dock = toolWindow(dockWidgetPosition(pView));
326 else
327 return;
328
329 bEnabled ? dock->showWidget(pView) : dock->hideWidget(pView);
330}
331
332void SimpleMainWindow::raiseView(TQWidget *view)
333{
334 //adymo: a workaround to make editor wrappers work:
335 //editor view is passed to this function but the ui library knows only
336 //of its parent which is an editor wrapper, simply replacing the view
337 //by its wrapper helps here
338 if (view->parent())
339 kdDebug() << view->parent()->className() << endl;
340 if (view->parent() && (view->parent()->isA("EditorWrapper") || view->parent()->isA("MultiBuffer")))
341 {
342// kdDebug() << "parent is editor wrapper: " <<
343// static_cast<EditorWrapper*>(view->parent()) << endl;
344 view = (TQWidget*)view->parent();
345 }
346
347 if (hasDockWidget(view))
348 {
349 DDockWindow *dock = toolWindow(dockWidgetPosition(view));
350 dock->raiseWidget(view);
351 }
352 else if (m_widgets.contains(view) && m_widgetTabs.contains(view))
353 m_widgetTabs[view]->showPage(view);
354}
355
356void SimpleMainWindow::lowerView(TQWidget * view)
357{
358 if (!hasDockWidget(view))
359 return;
360
361 DDockWindow *dock = toolWindow(dockWidgetPosition(view));
362 dock->lowerWidget(view);
363}
364
365void SimpleMainWindow::loadSettings()
366{
367 TDEConfig *config = kapp->config();
368
369 ProjectManager::getInstance()->loadSettings();
370 applyMainWindowSettings(config, "SimpleMainWindow");
371
372 Core::setupShourtcutTips();
373}
374
375void SimpleMainWindow::saveSettings( )
376{
377 TDEConfig *config = kapp->config();
378
379 ProjectManager::getInstance()->saveSettings();
380 saveMainWindowSettings(config, "SimpleMainWindow");
381
382 TQMap<TQWidget*, DDockWindow::Position>::iterator it = m_docks.begin();
383 while ( it != m_docks.end() )
384 {
385 if ( !strcmp(it.key()->name(), "unnamed") )
386 {
387 kdError() << "Toolviews must have a name : " << it.key() << endl;
388 }
389
390 rememberToolViewPosition( it.key()->name(), it.data() );
391 ++it;
392 }
393
394 DMainWindow::saveSettings();
395}
396
397void SimpleMainWindow::setCurrentDocumentCaption( const TQString &caption )
398{
399 if( !PartController::getInstance()->activePart() ) return;
400
401 if (TQWidget *widget = EditorProxy::getInstance()->topWidgetForPart(PartController::getInstance()->activePart()))
402 {
403 widget->setCaption(caption);
404 }
405}
406
407TDEMainWindow *SimpleMainWindow::main()
408{
409 return this;
410}
411
412void SimpleMainWindow::createFramework()
413{
414 PartController::createInstance( this );
415
416 connect(PartController::getInstance(), TQ_SIGNAL(activePartChanged(KParts::Part*)),
417 this, TQ_SLOT(createGUI(KParts::Part*)));
418}
419
420void SimpleMainWindow::createActions()
421{
422 m_raiseEditor = new TDEAction(i18n("Raise &Editor"), ALT+Key_C,
423 this, TQ_SLOT(raiseEditor()), actionCollection(), "raise_editor");
424 m_raiseEditor->setToolTip(i18n("Raise editor"));
425 m_raiseEditor->setWhatsThis(i18n("<b>Raise editor</b><p>Focuses the editor."));
426
427 m_lowerAllDocks = new TDEAction(i18n("Lower All Docks"), CTRL+SHIFT+Key_C,
428 this, TQ_SLOT(lowerAllDocks()), actionCollection(), "lower_all_docks");
429
430 new TDEAction(i18n("Switch to next TabWidget"), 0, this,
431 TQ_SLOT(switchToNextTabWidget()), actionCollection(), "switch_to_next_tabwidget" );
432
433 m_splitHor = new TDEAction(i18n("Split &Horizontal"), CTRL+SHIFT+Key_T,
434 this, TQ_SLOT(slotSplitHorizontalBase()), actionCollection(), "split_h");
435 m_splitHor->setIcon("view_top_bottom");
436
437 m_splitVer = new TDEAction(i18n("Split &Vertical"), CTRL+SHIFT+Key_L,
438 this, TQ_SLOT(slotSplitVerticalBase()), actionCollection(), "split_v");
439 m_splitVer->setIcon("view_left_right");
440
441 m_splitHor1 = new TDEAction(i18n("Split &Horizontal"), 0,
442 this, TQ_SLOT(slotSplitHorizontal()), actionCollection(), "split_h1");
443 m_splitHor1->setIcon("view_top_bottom");
444
445 m_splitVer1 = new TDEAction(i18n("Split &Vertical"), 0,
446 this, TQ_SLOT(slotSplitVertical()), actionCollection(), "split_v1");
447 m_splitVer1->setIcon("view_left_right");
448
449 m_splitHor2 = new TDEAction(i18n("Split &Horizontal and Open"), 0,
450 this, TQ_SLOT(slotSplitHorizontal()), actionCollection(), "split_h2");
451 m_splitHor2->setIcon("view_top_bottom");
452
453 m_splitVer2 = new TDEAction(i18n("Split &Vertical and Open"), 0,
454 this, TQ_SLOT(slotSplitVertical()), actionCollection(), "split_v2");
455 m_splitVer2->setIcon("view_left_right");
456
457 m_raiseLeftDock = new TDEAction(i18n("Switch Left Dock"), CTRL+SHIFT+ALT+Key_L,
458 this, TQ_SLOT(raiseLeftDock()), actionCollection(), "switch_left_dock");
459
460 m_raiseRightDock = new TDEAction(i18n("Switch Right Dock"), CTRL+SHIFT+ALT+Key_R,
461 this, TQ_SLOT(raiseRightDock()), actionCollection(), "switch_right_dock");
462
463 m_raiseBottomDock = new TDEAction(i18n("Switch Bottom Dock"), CTRL+SHIFT+ALT+Key_B,
464 this, TQ_SLOT(raiseBottomDock()), actionCollection(), "switch_bottom_dock");
465
466 KStdAction::configureToolbars(this, TQ_SLOT(configureToolbars()),
467 actionCollection(), "set_configure_toolbars");
468
469 m_mainWindowShare->createActions();
470
471 connect(m_mainWindowShare, TQ_SIGNAL(gotoNextWindow()), this, TQ_SLOT(gotoNextWindow()));
472 connect(m_mainWindowShare, TQ_SIGNAL(gotoPreviousWindow()), this, TQ_SLOT(gotoPreviousWindow()));
473 connect(m_mainWindowShare, TQ_SIGNAL(gotoFirstWindow()), this, TQ_SLOT(gotoFirstWindow()));
474 connect(m_mainWindowShare, TQ_SIGNAL(gotoLastWindow()), this, TQ_SLOT(gotoLastWindow()));
475}
476
477void SimpleMainWindow::raiseEditor()
478{
479 kdDebug() << "SimpleMainWindow::raiseEditor" << endl;
480 KDevPartController *partcontroller = API::getInstance()->partController();
481 if (partcontroller->activePart() && partcontroller->activePart()->widget())
482 partcontroller->activePart()->widget()->setFocus();
483}
484
485void SimpleMainWindow::gotoNextWindow()
486{
487 if (m_bottomDock->isActive())
488 m_bottomDock->selectNextWidget();
489 else if (m_rightDock->isActive())
490 m_rightDock->selectNextWidget();
491 else if (m_leftDock->isActive())
492 m_leftDock->selectNextWidget();
493 else
494 {
495 if ((m_activeTabWidget->currentPageIndex() + 1) < m_activeTabWidget->count())
496 m_activeTabWidget->setCurrentPage(m_activeTabWidget->currentPageIndex() + 1);
497 else
498 m_activeTabWidget->setCurrentPage(0);
499 }
500}
501
502void SimpleMainWindow::gotoPreviousWindow()
503{
504 if (m_bottomDock->isActive())
505 m_bottomDock->selectPrevWidget();
506 else if (m_rightDock->isActive())
507 m_rightDock->selectPrevWidget();
508 else if (m_leftDock->isActive())
509 m_leftDock->selectPrevWidget();
510 else
511 {
512 if ((m_activeTabWidget->currentPageIndex() - 1) >= 0)
513 m_activeTabWidget->setCurrentPage(m_activeTabWidget->currentPageIndex() - 1);
514 else
515 m_activeTabWidget->setCurrentPage(m_activeTabWidget->count() - 1);
516 }
517}
518
519void SimpleMainWindow::gotoFirstWindow()
520{
521 //@TODO: Implement me
522}
523
524void SimpleMainWindow::gotoLastWindow()
525{
526 //@TODO: implement me
527}
528
529void SimpleMainWindow::slotCoreInitialized()
530{
531 menuBar()->setEnabled(true);
532}
533
534void SimpleMainWindow::projectOpened()
535{
536 setCaption(TQString());
537}
538
539void SimpleMainWindow::slotPartURLChanged(KParts::ReadOnlyPart *part)
540{
541 if (TQWidget *widget = EditorProxy::getInstance()->topWidgetForPart(part))
542 {
543 kdDebug() << "new caption for widget: " << part->url().fileName() << endl;
544 widget->setCaption(part->url().fileName());
545 }
546 //do smth with caption: ro_part->url().fileName()
547}
548
549void SimpleMainWindow::documentChangedState(const KURL &url, DocumentState state)
550{
551 TQWidget * widget = EditorProxy::getInstance()->topWidgetForPart(
552 PartController::getInstance()->partForURL(url));
553 kdDebug() << "SimpleMainWindow::documentChangedState: " << widget << endl;
554 if (widget)
555 {
556 //calculate the icon size if showTabIcons is false
557 //this is necessary to avoid tab resizing by setIcon() call
558 int isize = 16;
559 if (m_activeTabWidget && !m_showIconsOnTabs)
560 {
561 isize = m_activeTabWidget->fontMetrics().height() - 1;
562 isize = isize > 16 ? 16 : isize;
563 }
564 switch (state)
565 {
566 // we should probably restore the original icon instead of just using "tdevelop",
567 // but I have never seen any other icon in use so this should do for now
568 case Clean:
569 if (m_showIconsOnTabs)
570 widget->setIcon(SmallIcon("tdevelop", isize));
571 else
572 widget->setIcon(TQPixmap());
573 break;
574 case Modified:
575 widget->setIcon(SmallIcon("document-save", isize));
576 break;
577 case Dirty:
578 widget->setIcon(SmallIcon("document-revert", isize));
579 break;
580 case DirtyAndModified:
581 widget->setIcon(SmallIcon("process-stop", isize));
582 break;
583 }
584 }
585 setCaption(url.url());
586}
587
588void SimpleMainWindow::closeTab()
589{
590// actionCollection()->action("file_close")->activate();
591 if (sender()->isA("TQToolButton") && sender()->parent()->isA("DTabWidget"))
592 {
593 DTabWidget *tab = (DTabWidget*)sender()->parent();
594 if (tab && tab->currentPage())
595 closeTab(tab->currentPage());
596 }
597}
598
599void SimpleMainWindow::tabContext(TQWidget *w, const TQPoint &p)
600{
601 DTabWidget *tabWidget = static_cast<DTabWidget*>(const_cast<TQObject*>(sender()));
602 if (!tabWidget)
603 return;
604
605 TDEPopupMenu tabMenu;
606 tabMenu.insertTitle(tabWidget->tabLabel(w));
607
608 //Find the document on whose tab the user clicked
609 m_currentTabURL = TQString();
610 TQPtrListIterator<KParts::Part> it(*PartController::getInstance()->parts());
611 while (KParts::Part* part = it.current())
612 {
613 TQWidget *top_widget = EditorProxy::getInstance()->topWidgetForPart(part);
614 if (top_widget == w)
615 {
616 if (KParts::ReadOnlyPart *ro_part = dynamic_cast<KParts::ReadOnlyPart*>(part))
617 {
618 m_currentTabURL = ro_part->url();
619 tabMenu.insertItem(i18n("Close"), 0);
620
621 if (PartController::getInstance()->parts()->count() > 1)
622 tabMenu.insertItem(i18n("Close All Others"), 4);
623
624 if( KParts::ReadWritePart * rw_part = dynamic_cast<KParts::ReadWritePart*>( ro_part ) )
625 {
626 if( rw_part->isModified() ) tabMenu.insertItem( i18n("Save"),1);
627 tabMenu.insertItem( i18n("Reload"),2);
628 }
629
630 if (dynamic_cast<HTMLDocumentationPart*>(ro_part))
631 {
632 tabMenu.insertItem(i18n("Duplicate"), 3);
633 break;
634 }
635
636 //Create the file context
637 KURL::List list;
638 list << m_currentTabURL;
639 FileContext context( list );
640 Core::getInstance()->fillContextMenu(&tabMenu, &context);
641 }
642 break;
643 }
644 ++it;
645 }
646
647 connect(&tabMenu, TQ_SIGNAL(activated(int)), this, TQ_SLOT(tabContextActivated(int)));
648 tabMenu.exec(p);
649}
650
651void SimpleMainWindow::tabContextActivated(int id)
652{
653 if(m_currentTabURL.isEmpty())
654 return;
655
656 switch(id)
657 {
658 case 0:
659 PartController::getInstance()->closeFile(m_currentTabURL);
660 break;
661 case 1:
662 PartController::getInstance()->saveFile(m_currentTabURL);
663 break;
664 case 2:
665 PartController::getInstance()->reloadFile(m_currentTabURL);
666 break;
667 case 3:
668 PartController::getInstance()->showDocument(m_currentTabURL, true);
669 break;
670 case 4:
671 PartController::getInstance()->closeAllOthers(m_currentTabURL);
672 break;
673 default:
674 break;
675 }
676}
677
678void SimpleMainWindow::configureToolbars()
679{
680 saveMainWindowSettings(TDEGlobal::config(), "SimpleMainWindow");
681 KEditToolbar dlg(factory());
682 connect(&dlg, TQ_SIGNAL(newToolbarConfig()), this, TQ_SLOT(slotNewToolbarConfig()));
683 dlg.exec();
684}
685
686void SimpleMainWindow::slotNewToolbarConfig()
687{
688// setupWindowMenu();
689 m_mainWindowShare->slotGUICreated(PartController::getInstance()->activePart());
690 applyMainWindowSettings(TDEGlobal::config(), "SimpleMainWindow");
691}
692
693bool SimpleMainWindow::queryClose()
694{
695 saveSettings();
696 return Core::getInstance()->queryClose();
697}
698
699bool SimpleMainWindow::queryExit()
700{
701 return true;
702}
703
704void SimpleMainWindow::setupWindowMenu()
705{
706 // get the xmlgui created one instead
707 m_windowMenu = static_cast<TQPopupMenu*>(main()->child("window", "TDEPopupMenu"));
708
709 if (!m_windowMenu)
710 {
711 kdDebug(9000) << "Couldn't find the XMLGUI window menu. Creating new." << endl;
712
713 m_windowMenu = new TQPopupMenu(main(), "window");
714 menuBar()->insertItem(i18n("&Window"), m_windowMenu);
715 }
716
717 actionCollection()->action("file_close")->plug(m_windowMenu);
718 actionCollection()->action("file_close_all")->plug(m_windowMenu);
719 actionCollection()->action("file_closeother")->plug(m_windowMenu);
720
721 TQObject::connect(m_windowMenu, TQ_SIGNAL(activated(int)), this, TQ_SLOT(openURL(int)));
722 TQObject::connect(m_windowMenu, TQ_SIGNAL(aboutToShow()), this, TQ_SLOT(fillWindowMenu()));
723}
724
725void SimpleMainWindow::openURL(int w)
726{
727 TQValueList<TQPair<int, KURL> >::ConstIterator it = m_windowList.begin();
728 while (it != m_windowList.end())
729 {
730 if ((*it).first == w)
731 {
732 KURL url((*it).second);
733 if (!url.isEmpty())
734 {
735 PartController::getInstance()->editDocument(url);
736 return;
737 }
738 }
739 ++it;
740 }
741}
742
743void SimpleMainWindow::fillWindowMenu()
744{
745 // clear menu
746 TQValueList< TQPair< int, KURL > >::ConstIterator it = m_windowList.begin();
747 while (it != m_windowList.end())
748 {
749 m_windowMenu->removeItem( (*it).first );
750 ++it;
751 }
752
753 int temp = 0;
754
755 TQMap<TQString, KURL> map;
756 TQStringList string_list;
757 KURL::List list = PartController::getInstance()->openURLs();
758 KURL::List::Iterator itt = list.begin();
759 while (itt != list.end())
760 {
761 map[(*itt).fileName()] = *itt;
762 string_list.append((*itt).fileName());
763 ++itt;
764 }
765 string_list.sort();
766
767 list.clear();
768 for(uint i = 0; i != string_list.size(); ++i)
769 list.append(map[string_list[i]]);
770
771 itt = list.begin();
772 int i = 0;
773
774 if (list.count() > 0)
775 m_windowList << qMakePair(m_windowMenu->insertSeparator(), KURL());
776
777 while (itt != list.end())
778 {
779 temp = m_windowMenu->insertItem( i < 10 ? TQString("&%1 %2").arg(i).arg((*itt).fileName()) : (*itt).fileName() );
780 m_windowList << qMakePair(temp, *itt);
781 ++i;
782 ++itt;
783 }
784}
785
786void SimpleMainWindow::slotSplitVertical()
787{
788 DTabWidget *tab = splitVertical();
789 openDocumentsAfterSplit(tab);
790}
791
792void SimpleMainWindow::slotSplitHorizontal()
793{
794 DTabWidget *tab = splitHorizontal();
795 openDocumentsAfterSplit(tab);
796}
797
798void SimpleMainWindow::slotSplitVerticalBase()
799{
800 if (KParts::ReadOnlyPart *ro_part = activePartForSplitting())
801 {
802 m_splitURLs << ro_part->url();
803 slotSplitVertical();
804 }
805}
806
807KParts::ReadOnlyPart *SimpleMainWindow::activePartForSplitting()
808{
809 if (PartController::getInstance()->openURLs().count() < 2)
810 return 0;
811 m_splitURLs.clear();
812 KParts::ReadOnlyPart *ro_part =
813 dynamic_cast<KParts::ReadOnlyPart*>(PartController::getInstance()->activePart());
814 return ro_part;
815}
816
817void SimpleMainWindow::slotSplitHorizontalBase()
818{
819 if (KParts::ReadOnlyPart *ro_part = activePartForSplitting())
820 {
821 m_splitURLs << ro_part->url();
822 slotSplitHorizontal();
823 }
824}
825
826void SimpleMainWindow::openDocumentsAfterSplit(DTabWidget *tab)
827{
828 if (m_splitURLs.count() > 0)
829 {
830 for (KURL::List::const_iterator it = m_splitURLs.begin(); it != m_splitURLs.end(); ++it)
831 {
832 KParts::ReadOnlyPart *part = PartController::getInstance()->partForURL(*it);
833 if (!part)
834 PartController::getInstance()->editDocument(*it);
835 else
836 {
837 PartController::getInstance()->activatePart( part );
838 TQWidget *inTab = widgetForURL(*it);
839 if (inTab)
840 {
841 DTabWidget *oldTab = m_widgetTabs[inTab];
842 TQString title = oldTab->tabLabel(inTab);
843 removeWidget(inTab);
844 addWidget(tab, inTab, title);
845 }
846 }
847 }
848 m_splitURLs.clear();
849 }
850}
851
852TQWidget *SimpleMainWindow::widgetForURL(KURL url)
853{
854 KParts::ReadOnlyPart *part = PartController::getInstance()->partForURL(url);
855 return widgetInTab( part ? part->widget() : 0 );
856}
857
858TQWidget *SimpleMainWindow::widgetInTab(TQWidget *w)
859{
860 TQWidget *inTab = 0;
861 if (w && w->parent() && w->parent()->isA("EditorProxy"))
862 inTab = (TQWidget*)w->parent();
863 else if (w && w->parent() && w->parent()->isA("MultiBuffer")
864 && w->parent()->parent() && w->parent()->parent()->isA("EditorProxy"))
865 inTab = (TQWidget*)w->parent()->parent();
866 else if (w && w->parent() && w->parent()->isA("MultiBuffer"))
867 inTab = (TQWidget*)w->parent();
868 else
869 inTab = w;
870 return inTab;
871}
872
873void SimpleMainWindow::closeTab(TQWidget *w)
874{
875 const TQPtrList<KParts::Part> *partlist = PartController::getInstance()->parts();
876 TQPtrListIterator<KParts::Part> it(*partlist);
877 while (KParts::Part* part = it.current())
878 {
879 TQWidget *widget = EditorProxy::getInstance()->topWidgetForPart(part);
880 if (widget && widget == w)
881 {
882 // weirdness beyond weirdness.. sometimes the active view is an embedded splitter with two files
883 // so we check if the widget is a multibuffer, in which case we let it decide what part to close
884 if (MultiBuffer * mb = dynamic_cast<MultiBuffer*>( widget ) )
885 {
886 PartController::getInstance()->closePart( mb->activeBuffer() );
887 }
888 else
889 {
890 PartController::getInstance()->closePart(part);
891 }
892 return;
893 }
894 ++it;
895 }
896}
897
898void SimpleMainWindow::activePartChanged(KParts::Part *part)
899{
900 if (!part)
901 return;
902 TQWidget *w = part->widget();
903 kdDebug() << "active part widget is : " << w << endl;
904 TQWidget *inTab = widgetInTab(w);
905 if (m_widgetTabs[inTab] != 0)
906 {
907 kdDebug() << " setting m_activeTabWidget " << endl;
908 m_activeTabWidget = m_widgetTabs[inTab];
909 }
910}
911
912void SimpleMainWindow::createGUI(KParts::Part *part) {
913 if ( !part )
914 setCaption( TQString() );
915 DMainWindow::createGUI(part);
916
917 m_mainWindowShare->slotGUICreated( part );
918}
919
920void SimpleMainWindow::raiseBottomDock()
921{
922 raiseDock(m_bottomDock);
923}
924
925void SimpleMainWindow::raiseLeftDock()
926{
927 raiseDock(m_leftDock);
928}
929
930void SimpleMainWindow::raiseRightDock()
931{
932 raiseDock(m_rightDock);
933}
934
935void SimpleMainWindow::raiseDock(DDockWindow *dock)
936{
937 dock->selectLastWidget();
938}
939
940void SimpleMainWindow::lowerAllDocks()
941{
942 m_bottomDock->lowerWidget( m_bottomDock->currentWidget() );
943 m_leftDock->lowerWidget( m_leftDock->currentWidget() );
944 m_rightDock->lowerWidget( m_rightDock->currentWidget() );
945}
946
947void SimpleMainWindow::switchToNextTabWidget()
948{
949 TQValueList<DTabWidget*> tabWidgets = m_widgetTabs.values();
950
951 if ( tabWidgets.count() < 2 ) return;
952
953 TQValueList<DTabWidget*> reduced;
954 TQValueList<DTabWidget*>::iterator it = tabWidgets.begin();
955 while ( it != tabWidgets.end() )
956 {
957 if ( !reduced.contains( *it ) )
958 {
959 reduced << *it;
960 }
961 ++it;
962 }
963
964 it = reduced.begin();
965 while ( it != reduced.end() )
966 {
967 if ( *it == m_activeTabWidget )
968 {
969 if ( ++it != reduced.end() )
970 {
971 if ( (*it)->currentPage() )
972 (*it)->currentPage()->setFocus();
973 }
974 else
975 {
976 if ( (*reduced.begin())->currentPage() )
977 (*reduced.begin())->currentPage()->setFocus();
978 }
979 return;
980 }
981 ++it;
982 }
983}
984
985void SimpleMainWindow::setCaption(const TQString &caption)
986{
987 kdDebug(9000) << k_funcinfo << endl;
988
989 bool modified = false;
990 if ( !caption.isEmpty() )
991 {
992 KURL url( caption );
993 DocumentState const state = PartController::getInstance()->documentState( url );
994 modified = ( state == Modified || state == DirtyAndModified );
995 }
996
997 KDevProject *project = API::getInstance()->project();
998 if (project)
999 {
1000 TQString projectname = project->projectName();
1001
1002 TQString suffix(".kdevelop");
1003 if (projectname.endsWith(suffix))
1004 projectname.truncate(projectname.length() - suffix.length());
1005
1006 if (!caption.isEmpty())
1007 DMainWindow::setCaption(projectname + " - " + caption, modified);
1008 else
1009 DMainWindow::setCaption(projectname, modified);
1010 }
1011 else
1012 DMainWindow::setCaption(caption, modified);
1013}
1014
1015void SimpleMainWindow::projectClosed()
1016{
1017 DMainWindow::setCaption(TQString());
1018}
1019
1020void SimpleMainWindow::slotProgrammingHandbook()
1021{
1022 kapp->invokeHelp(TQString::null, "tde_app_devel");
1023}
1024
1025#include "simplemainwindow.moc"
Core::setupShourtcutTips
static void setupShourtcutTips(KXMLGUIClient *client=0)
Setup shourtcut tips.
Definition core.cpp:31
MainWindowShare
Shared main window functionality.
Definition mainwindowshare.h:31
ShellExtension::getInstance
static ShellExtension * getInstance()
Returns an instance of a shell.
Definition shellextension.h:42
TopLevel::invalidateInstance
static void invalidateInstance(KDevMainWindow *instance)
Signal that the object has been (or is about to be) destroyed.
Definition toplevel.cpp:31

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.