Make toolbar visible again.
[kdbg.git] / kdbg / dbgmainwnd.cpp
blob37d8d7de8c8b441c3d2099bd00f20356eb5c357c
1 // $Id$
3 // Copyright by Johannes Sixt
4 // This file is under GPL, the GNU General Public Licence
6 #include <kapp.h>
7 #if QT_VERSION >= 200
8 #include <klocale.h> /* i18n */
9 #include <kmenubar.h>
10 #include <kconfig.h>
11 #endif
12 #include <kiconloader.h>
13 #include <kstdaccel.h>
14 #include <kfiledialog.h>
15 #include <kprocess.h>
16 #include <qlistbox.h>
17 #include <qfileinfo.h>
18 #include "dbgmainwnd.h"
19 #include "debugger.h"
20 #include "updateui.h"
21 #include "commandids.h"
22 #include "winstack.h"
23 #include "brkpt.h"
24 #include "threadlist.h"
25 #include "memwindow.h"
26 #include "ttywnd.h"
27 #include "mydebug.h"
30 DebuggerMainWnd::DebuggerMainWnd(const char* name) :
31 DockMainWindow(name),
32 DebuggerMainWndBase()
34 setDockManager(new DockManager( this, QString(name)+"_DockManager"));
36 QPixmap p;
38 DockWidget* dw0 = createDockWidget("Source", p);
39 dw0->setCaption(i18n("Source"));
40 m_filesWindow = new WinStack(dw0, "files");
41 setView(dw0);
43 DockWidget* dw1 = createDockWidget("Stack", p);
44 dw1->setCaption(i18n("Stack"));
45 m_btWindow = new QListBox(dw1, "backtrace");
46 DockWidget* dw2 = createDockWidget("Locals", p);
47 dw2->setCaption(i18n("Locals"));
48 m_localVariables = new ExprWnd(dw2, "locals");
49 DockWidget* dw3 = createDockWidget("Watches", p);
50 dw3->setCaption(i18n("Watches"));
51 m_watches = new WatchWindow(dw3, "watches");
52 DockWidget* dw4 = createDockWidget("Registers", p);
53 dw4->setCaption(i18n("Registers"));
54 m_registers = new RegisterView(dw4, "registers");
55 DockWidget* dw5 = createDockWidget("Breakpoints", p);
56 dw5->setCaption(i18n("Breakpoints"));
57 m_bpTable = new BreakpointTable(dw5, "breakpoints");
58 DockWidget* dw6 = createDockWidget("Output", p);
59 dw6->setCaption(i18n("Output"));
60 m_ttyWindow = new TTYWindow(dw6, "output");
61 DockWidget* dw7 = createDockWidget("Threads", p);
62 dw7->setCaption(i18n("Threads"));
63 m_threads = new ThreadList(dw7, "threads");
64 DockWidget* dw8 = createDockWidget("Memory", p);
65 dw8->setCaption(i18n("Memory"));
66 m_memoryWindow = new MemoryWindow(dw8, "memory");
68 m_menuRecentExecutables = new QPopupMenu();
70 initMenu();
71 initToolbar();
73 setupDebugger(m_localVariables, m_watches->watchVariables(), m_btWindow);
74 m_bpTable->setDebugger(m_debugger);
75 m_memoryWindow->setDebugger(m_debugger);
77 connect(m_watches, SIGNAL(addWatch()), SLOT(slotAddWatch()));
78 connect(m_watches, SIGNAL(deleteWatch()), m_debugger, SLOT(slotDeleteWatch()));
80 m_filesWindow->setWindowMenu(m_menuWindow);
81 connect(&m_filesWindow->m_findDlg, SIGNAL(closed()), SLOT(updateUI()));
82 connect(m_filesWindow, SIGNAL(newFileLoaded()),
83 SLOT(slotNewFileLoaded()));
84 connect(m_filesWindow, SIGNAL(toggleBreak(const QString&,int,const DbgAddr&,bool)),
85 this, SLOT(slotToggleBreak(const QString&,int,const DbgAddr&,bool)));
86 connect(m_filesWindow, SIGNAL(enadisBreak(const QString&,int,const DbgAddr&)),
87 this, SLOT(slotEnaDisBreak(const QString&,int,const DbgAddr&)));
88 connect(m_debugger, SIGNAL(activateFileLine(const QString&,int,const DbgAddr&)),
89 m_filesWindow, SLOT(activate(const QString&,int,const DbgAddr&)));
90 connect(m_debugger, SIGNAL(executableUpdated()),
91 m_filesWindow, SLOT(reloadAllFiles()));
92 connect(m_debugger, SIGNAL(updatePC(const QString&,int,const DbgAddr&,int)),
93 m_filesWindow, SLOT(updatePC(const QString&,int,const DbgAddr&,int)));
94 // value popup communication
95 connect(m_filesWindow, SIGNAL(initiateValuePopup(const QString&)),
96 m_debugger, SLOT(slotValuePopup(const QString&)));
97 connect(m_debugger, SIGNAL(valuePopup(const QString&)),
98 m_filesWindow, SLOT(slotShowValueTip(const QString&)));
99 // disassembling
100 connect(m_filesWindow, SIGNAL(disassemble(const QString&, int)),
101 m_debugger, SLOT(slotDisassemble(const QString&, int)));
102 connect(m_debugger, SIGNAL(disassembled(const QString&,int,const QList<DisassembledCode>&)),
103 m_filesWindow, SLOT(slotDisassembled(const QString&,int,const QList<DisassembledCode>&)));
104 // program stopped
105 connect(m_debugger, SIGNAL(programStopped()), SLOT(slotProgramStopped()));
106 connect(&m_backTimer, SIGNAL(timeout()), SLOT(slotBackTimer()));
107 // tab width
108 connect(this, SIGNAL(setTabWidth(int)), m_filesWindow, SIGNAL(setTabWidth(int)));
110 // Establish communication when right clicked on file window.
111 connect(&m_filesWindow->m_menuFloat, SIGNAL(activated(int)),
112 SLOT(menuCallback(int)));
114 // Connection when right clicked on file window before any file is
115 // loaded.
116 connect(&m_filesWindow->m_menuFileFloat, SIGNAL(activated(int)),
117 SLOT(menuCallback(int)));
119 // route unhandled menu items to winstack
120 connect(this, SIGNAL(forwardMenuCallback(int)), m_filesWindow, SLOT(menuCallback(int)));
121 // file/line updates
122 connect(m_filesWindow, SIGNAL(fileChanged()), SLOT(slotFileChanged()));
123 connect(m_filesWindow, SIGNAL(lineChanged()), SLOT(slotLineChanged()));
125 // connect breakpoint table
126 connect(m_bpTable, SIGNAL(activateFileLine(const QString&,int,const DbgAddr&)),
127 m_filesWindow, SLOT(activate(const QString&,int,const DbgAddr&)));
128 connect(m_debugger, SIGNAL(updateUI()), m_bpTable, SLOT(updateUI()));
129 connect(m_debugger, SIGNAL(breakpointsChanged()), m_bpTable, SLOT(updateBreakList()));
131 connect(m_debugger, SIGNAL(registersChanged(QList<RegisterInfo>&)),
132 m_registers, SLOT(updateRegisters(QList<RegisterInfo>&)));
134 connect(m_debugger, SIGNAL(memoryDumpChanged(const QString&, QList<MemoryDump>&)),
135 m_memoryWindow, SLOT(slotNewMemoryDump(const QString&, QList<MemoryDump>&)));
136 connect(m_debugger, SIGNAL(saveProgramSpecific(KSimpleConfig*)),
137 m_memoryWindow, SLOT(saveProgramSpecific(KSimpleConfig*)));
138 connect(m_debugger, SIGNAL(restoreProgramSpecific(KSimpleConfig*)),
139 m_memoryWindow, SLOT(restoreProgramSpecific(KSimpleConfig*)));
141 // thread window
142 connect(m_debugger, SIGNAL(threadsChanged(QList<ThreadInfo>&)),
143 m_threads, SLOT(updateThreads(QList<ThreadInfo>&)));
144 connect(m_threads, SIGNAL(setThread(int)),
145 m_debugger, SLOT(setThread(int)));
147 // view menu changes when docking state changes
148 connect(dockManager, SIGNAL(change()), SLOT(updateUI()));
150 // popup menu of the local variables window
151 m_popupLocals = new QPopupMenu;
152 m_popupLocals->insertItem(i18n("Watch Expression"),
153 this, SLOT(slotLocalsToWatch()));
154 connect(m_localVariables, SIGNAL(rightPressed(int, const QPoint&)),
155 this, SLOT(slotLocalsPopup(int, const QPoint&)));
157 restoreSettings(kapp->getConfig());
159 connect(m_menuRecentExecutables, SIGNAL(activated(int)), SLOT(slotRecentExec(int)));
160 fillRecentExecMenu();
162 updateUI();
163 m_bpTable->updateUI();
164 slotFileChanged();
167 DebuggerMainWnd::~DebuggerMainWnd()
169 saveSettings(kapp->getConfig());
170 // must delete m_debugger early since it references our windows
171 delete m_debugger;
172 m_debugger = 0;
173 // must disconnect from dockManager since it keeps emitting signals
174 dockManager->disconnect(this);
176 delete m_memoryWindow;
177 delete m_threads;
178 delete m_ttyWindow;
179 delete m_bpTable;
180 delete m_registers;
181 delete m_watches;
182 delete m_localVariables;
183 delete m_btWindow;
184 delete m_filesWindow;
186 delete m_menuWindow;
187 delete m_menuBrkpt;
188 delete m_menuProgram;
189 delete m_menuView;
190 delete m_menuFile;
193 void DebuggerMainWnd::initMenu()
195 m_menuFile = new QPopupMenu;
196 m_menuFile->insertItem(i18n("&Open Source..."), ID_FILE_OPEN);
197 m_menuFile->insertItem(i18n("&Reload Source"), ID_FILE_RELOAD);
198 m_menuFile->insertSeparator();
199 m_menuFile->insertItem(i18n("&Executable..."), ID_FILE_EXECUTABLE);
200 m_menuFile->insertItem(i18n("Recent E&xecutables"), m_menuRecentExecutables);
201 m_menuFile->insertItem(i18n("&Settings..."), ID_FILE_PROG_SETTINGS);
202 m_menuFile->insertItem(i18n("&Core dump..."), ID_FILE_COREFILE);
203 m_menuFile->insertSeparator();
204 m_menuFile->insertItem(i18n("&Global Options..."), ID_FILE_GLOBAL_OPTIONS);
205 m_menuFile->insertSeparator();
206 m_menuFile->insertItem(i18n("&Quit"), ID_FILE_QUIT);
207 m_menuFile->setAccel(keys->open(), ID_FILE_OPEN);
208 m_menuFile->setAccel(keys->quit(), ID_FILE_QUIT);
210 m_menuView = new QPopupMenu;
211 m_menuView->setCheckable(true);
212 m_menuView->insertItem(i18n("&Find..."), ID_VIEW_FINDDLG);
213 m_menuView->insertSeparator();
214 i18n("Source &code");
215 m_menuView->insertItem(i18n("Stac&k"), ID_VIEW_STACK);
216 m_menuView->insertItem(i18n("&Locals"), ID_VIEW_LOCALS);
217 m_menuView->insertItem(i18n("&Watched expressions"), ID_VIEW_WATCHES);
218 m_menuView->insertItem(i18n("&Registers"), ID_VIEW_REGISTERS);
219 m_menuView->insertItem(i18n("&Breakpoints"), ID_BRKPT_LIST);
220 m_menuView->insertItem(i18n("T&hreads"), ID_VIEW_THREADS);
221 m_menuView->insertItem(i18n("&Output"), ID_VIEW_OUTPUT);
222 m_menuView->insertItem(i18n("&Memory"), ID_VIEW_MEMORY);
223 m_menuView->insertSeparator();
224 m_menuView->insertItem(i18n("Toggle &Toolbar"), ID_VIEW_TOOLBAR);
225 m_menuView->insertItem(i18n("Toggle &Statusbar"), ID_VIEW_STATUSBAR);
226 m_menuView->setAccel(keys->find(), ID_VIEW_FINDDLG);
228 m_menuProgram = new QPopupMenu;
229 m_menuProgram->insertItem(i18n("&Run"), ID_PROGRAM_RUN);
230 m_menuProgram->insertItem(i18n("Step &into"), ID_PROGRAM_STEP);
231 m_menuProgram->insertItem(i18n("Step &over"), ID_PROGRAM_NEXT);
232 m_menuProgram->insertItem(i18n("Step o&ut"), ID_PROGRAM_FINISH);
233 m_menuProgram->insertItem(i18n("Run to &cursor"), ID_PROGRAM_UNTIL);
234 m_menuProgram->insertItem(i18n("Step i&nto by instruction"), ID_PROGRAM_STEPI);
235 m_menuProgram->insertItem(i18n("Step o&ver by instruction"), ID_PROGRAM_NEXTI);
236 m_menuProgram->insertSeparator();
237 m_menuProgram->insertItem(i18n("&Break"), ID_PROGRAM_BREAK);
238 m_menuProgram->insertItem(i18n("&Kill"), ID_PROGRAM_KILL);
239 m_menuProgram->insertItem(i18n("Re&start"), ID_PROGRAM_RUN_AGAIN);
240 m_menuProgram->insertItem(i18n("A&ttach..."), ID_PROGRAM_ATTACH);
241 m_menuProgram->insertSeparator();
242 m_menuProgram->insertItem(i18n("&Arguments..."), ID_PROGRAM_ARGS);
243 m_menuProgram->setAccel(Key_F5, ID_PROGRAM_RUN);
244 m_menuProgram->setAccel(Key_F8, ID_PROGRAM_STEP);
245 m_menuProgram->setAccel(SHIFT+Key_F8, ID_PROGRAM_STEPI);
246 m_menuProgram->setAccel(Key_F10, ID_PROGRAM_NEXT);
247 m_menuProgram->setAccel(SHIFT+Key_F10, ID_PROGRAM_NEXTI);
248 m_menuProgram->setAccel(Key_F6, ID_PROGRAM_FINISH);
249 m_menuProgram->setAccel(Key_F7, ID_PROGRAM_UNTIL);
251 m_menuBrkpt = new QPopupMenu;
252 m_menuBrkpt->insertItem(i18n("Set/Clear &breakpoint"), ID_BRKPT_SET);
253 m_menuBrkpt->insertItem(i18n("Set &temporary breakpoint"), ID_BRKPT_TEMP);
254 m_menuBrkpt->insertItem(i18n("&Enable/Disable breakpoint"), ID_BRKPT_ENABLE);
255 m_menuBrkpt->setAccel(Key_F9, ID_BRKPT_SET);
256 m_menuBrkpt->setAccel(SHIFT+Key_F9, ID_BRKPT_TEMP);
257 m_menuBrkpt->setAccel(CTRL+Key_F9, ID_BRKPT_ENABLE);
259 m_menuWindow = new QPopupMenu;
260 m_menuWindow->insertItem(i18n("&More..."), ID_WINDOW_MORE);
262 connect(m_menuFile, SIGNAL(activated(int)), SLOT(menuCallback(int)));
263 connect(m_menuView, SIGNAL(activated(int)), SLOT(menuCallback(int)));
264 connect(m_menuProgram, SIGNAL(activated(int)), SLOT(menuCallback(int)));
265 connect(m_menuBrkpt, SIGNAL(activated(int)), SLOT(menuCallback(int)));
266 connect(m_menuWindow, SIGNAL(activated(int)), SLOT(menuCallback(int)));
268 KMenuBar* menu = menuBar();
269 menu->insertItem(i18n("&File"), m_menuFile);
270 menu->insertItem(i18n("&View"), m_menuView);
271 menu->insertItem(i18n("E&xecution"), m_menuProgram);
272 menu->insertItem(i18n("&Breakpoint"), m_menuBrkpt);
273 menu->insertItem(i18n("&Window"), m_menuWindow);
276 #if QT_VERSION < 200
277 static QPixmap BarIcon(const char* name)
279 return kapp->getIconLoader()->loadIcon(name);
281 #endif
283 void DebuggerMainWnd::initToolbar()
285 KToolBar* toolbar = toolBar();
286 toolbar->insertButton(BarIcon("execopen.xpm"),ID_FILE_EXECUTABLE, true,
287 i18n("Executable"));
288 toolbar->insertButton(BarIcon("fileopen.xpm"),ID_FILE_OPEN, true,
289 i18n("Open a source file"));
290 toolbar->insertButton(BarIcon("reload.xpm"),ID_FILE_RELOAD, true,
291 i18n("Reload source file"));
292 toolbar->insertSeparator();
293 toolbar->insertButton(BarIcon("pgmrun.xpm"),ID_PROGRAM_RUN, true,
294 i18n("Run/Continue"));
295 toolbar->insertButton(BarIcon("pgmstep.xpm"),ID_PROGRAM_STEP, true,
296 i18n("Step into"));
297 toolbar->insertButton(BarIcon("pgmnext.xpm"),ID_PROGRAM_NEXT, true,
298 i18n("Step over"));
299 toolbar->insertButton(BarIcon("pgmfinish.xpm"),ID_PROGRAM_FINISH, true,
300 i18n("Step out"));
301 toolbar->insertButton(BarIcon("pgmstepi.xpm"),ID_PROGRAM_STEPI, true,
302 i18n("Step into by instruction"));
303 toolbar->insertButton(BarIcon("pgmnexti.xpm"),ID_PROGRAM_NEXTI, true,
304 i18n("Step over by instruction"));
305 toolbar->insertSeparator();
306 toolbar->insertButton(BarIcon("brkpt.xpm"),ID_BRKPT_SET, true,
307 i18n("Breakpoint"));
308 toolbar->insertSeparator();
309 toolbar->insertButton(BarIcon("search.xpm"),ID_VIEW_FINDDLG, true,
310 i18n("Search"));
312 connect(toolbar, SIGNAL(clicked(int)), SLOT(menuCallback(int)));
313 toolbar->setBarPos(KToolBar::Top);
315 initAnimation();
317 KStatusBar* statusbar = statusBar();
318 statusbar->insertItem(m_statusActive, ID_STATUS_ACTIVE);
319 m_lastActiveStatusText = m_statusActive;
320 statusbar->insertItem(i18n("Line 00000"), ID_STATUS_LINENO);
321 statusbar->insertItem("", ID_STATUS_MSG); /* message pane */
323 // reserve some translations
324 i18n("Restart");
325 i18n("Core dump");
329 * We must override KTMainWindow's handling of close events since we have
330 * only one toplevel window, which lives on the stack (which KTMainWindow
331 * can't live with :-( )
333 void DebuggerMainWnd::closeEvent(QCloseEvent* e)
335 #if QT_VERSION >= 200
336 clearWFlags(WDestructiveClose);
337 #endif
339 if (m_debugger != 0) {
340 m_debugger->shutdown();
343 e->accept();
344 kapp->quit();
348 // instance properties
349 void DebuggerMainWnd::saveProperties(KConfig* config)
351 // session management
352 QString executable = "";
353 if (m_debugger != 0) {
354 executable = m_debugger->executable();
356 config->writeEntry("executable", executable);
359 void DebuggerMainWnd::readProperties(KConfig* config)
361 // session management
362 QString execName = config->readEntry("executable");
364 TRACE("readProperties: executable=" + execName);
365 if (!execName.isEmpty()) {
366 debugProgram(execName);
370 const char WindowGroup[] = "Windows";
372 void DebuggerMainWnd::saveSettings(KConfig* config)
374 KConfigGroupSaver g(config, WindowGroup);
376 writeDockConfig(config);
378 DebuggerMainWndBase::saveSettings(config);
381 void DebuggerMainWnd::restoreSettings(KConfig* config)
383 KConfigGroupSaver g(config, WindowGroup);
385 readDockConfig(config);
387 DebuggerMainWndBase::restoreSettings(config);
389 emit setTabWidth(m_tabWidth);
392 void DebuggerMainWnd::menuCallback(int item)
394 switch (item) {
395 case ID_FILE_OPEN:
397 QString fileName = myGetFileName(i18n("Open"),
398 m_lastDirectory,
399 makeSourceFilter(), this);
401 if (!fileName.isEmpty())
403 QFileInfo fi(fileName);
404 m_lastDirectory = fi.dirPath();
405 m_filesWindow->setExtraDirectory(m_lastDirectory);
406 m_filesWindow->activateFile(fileName);
409 break;
410 case ID_FILE_QUIT:
411 if (m_debugger != 0) {
412 m_debugger->shutdown();
414 kapp->quit();
415 break;
416 case ID_VIEW_TOOLBAR:
417 enableToolBar();
418 break;
419 case ID_VIEW_STATUSBAR:
420 enableStatusBar();
421 break;
422 case ID_PROGRAM_UNTIL:
423 if (m_debugger != 0)
425 QString file;
426 int lineNo;
427 if (m_filesWindow->activeLine(file, lineNo))
428 m_debugger->runUntil(file, lineNo);
430 break;
431 case ID_BRKPT_LIST:
432 showhideWindow(m_bpTable);
433 break;
434 case ID_VIEW_SOURCE:
435 showhideWindow(m_filesWindow);
436 break;
437 case ID_VIEW_STACK:
438 showhideWindow(m_btWindow);
439 break;
440 case ID_VIEW_LOCALS:
441 showhideWindow(m_localVariables);
442 break;
443 case ID_VIEW_WATCHES:
444 showhideWindow(m_watches);
445 break;
446 case ID_VIEW_REGISTERS:
447 showhideWindow(m_registers);
448 break;
449 case ID_VIEW_THREADS:
450 showhideWindow(m_threads);
451 break;
452 case ID_VIEW_MEMORY:
453 showhideWindow(m_memoryWindow);
454 break;
455 case ID_VIEW_OUTPUT:
456 showhideWindow(m_ttyWindow);
457 break;
458 default:
459 // forward all others
460 if (!handleCommand(item))
461 emit forwardMenuCallback(item);
462 else if (item == ID_FILE_EXECUTABLE) {
463 // special: this may have changed m_lastDirectory
464 m_filesWindow->setExtraDirectory(m_lastDirectory);
465 fillRecentExecMenu();
466 } else {
467 // start timer to move window into background
468 switch (item) {
469 case ID_PROGRAM_STEP:
470 case ID_PROGRAM_STEPI:
471 case ID_PROGRAM_NEXT:
472 case ID_PROGRAM_NEXTI:
473 case ID_PROGRAM_FINISH:
474 case ID_PROGRAM_UNTIL:
475 case ID_PROGRAM_RUN:
476 if (m_popForeground)
477 intoBackground();
478 break;
482 updateUI();
485 void DebuggerMainWnd::updateUI()
487 // enumerate all menus
489 UpdateMenuUI updateMenu(m_menuFile, this, SLOT(updateUIItem(UpdateUI*)));
490 updateMenu.iterateMenu();
493 UpdateMenuUI updateMenu(m_menuView, this, SLOT(updateUIItem(UpdateUI*)));
494 updateMenu.iterateMenu();
497 UpdateMenuUI updateMenu(m_menuProgram, this, SLOT(updateUIItem(UpdateUI*)));
498 updateMenu.iterateMenu();
501 UpdateMenuUI updateMenu(m_menuBrkpt, this, SLOT(updateUIItem(UpdateUI*)));
502 updateMenu.iterateMenu();
505 // Update winstack float popup items
507 UpdateMenuUI updateMenu(&m_filesWindow->m_menuFloat, this,
508 SLOT(updateUIItem(UpdateUI*)));
509 updateMenu.iterateMenu();
512 // Update winstack float file popup items
514 UpdateMenuUI updateMenu(&m_filesWindow->m_menuFileFloat, this,
515 SLOT(updateUIItem(UpdateUI*)));
516 updateMenu.iterateMenu();
519 // toolbar
520 static const int toolIds[] = {
521 ID_PROGRAM_RUN, ID_PROGRAM_STEP, ID_PROGRAM_NEXT, ID_PROGRAM_FINISH,
522 ID_PROGRAM_STEPI, ID_PROGRAM_NEXTI,
523 ID_BRKPT_SET
525 UpdateToolbarUI updateToolbar(toolBar(), this, SLOT(updateUIItem(UpdateUI*)),
526 toolIds, sizeof(toolIds)/sizeof(toolIds[0]));
527 updateToolbar.iterateToolbar();
529 // update statusbar
530 QString newStatus;
531 if (m_debugger->isProgramActive())
532 newStatus = m_statusActive;
533 if (newStatus != m_lastActiveStatusText) {
534 statusBar()->changeItem(newStatus, ID_STATUS_ACTIVE);
535 m_lastActiveStatusText = newStatus;
537 // line number is updated in slotLineChanged
540 void DebuggerMainWnd::dockUpdateHelper(UpdateUI* item, QWidget* w)
542 if (canChangeDockVisibility(w)) {
543 item->enable(true);
544 item->setCheck(isDockVisible(w));
545 } else {
546 item->enable(false);
547 item->setCheck(false);
551 void DebuggerMainWnd::updateUIItem(UpdateUI* item)
553 switch (item->id) {
554 case ID_VIEW_FINDDLG:
555 item->setCheck(m_filesWindow->m_findDlg.isVisible());
556 break;
557 case ID_BRKPT_SET:
558 case ID_BRKPT_TEMP:
559 item->enable(m_debugger->canChangeBreakpoints());
560 break;
561 case ID_BRKPT_ENABLE:
562 item->enable(m_debugger->canChangeBreakpoints());
563 break;
564 case ID_BRKPT_LIST:
565 dockUpdateHelper(item, m_bpTable);
566 break;
567 case ID_VIEW_SOURCE:
568 dockUpdateHelper(item, m_filesWindow);
569 break;
570 case ID_VIEW_STACK:
571 dockUpdateHelper(item, m_btWindow);
572 break;
573 case ID_VIEW_LOCALS:
574 dockUpdateHelper(item, m_localVariables);
575 break;
576 case ID_VIEW_WATCHES:
577 dockUpdateHelper(item, m_watches);
578 break;
579 case ID_VIEW_REGISTERS:
580 dockUpdateHelper(item, m_registers);
581 break;
582 case ID_VIEW_THREADS:
583 dockUpdateHelper(item, m_threads);
584 break;
585 case ID_VIEW_MEMORY:
586 dockUpdateHelper(item, m_memoryWindow);
587 break;
588 case ID_VIEW_OUTPUT:
589 dockUpdateHelper(item, m_ttyWindow);
590 break;
591 default:
592 DebuggerMainWndBase::updateUIItem(item);
593 break;
597 void DebuggerMainWnd::updateLineItems()
599 m_filesWindow->updateLineItems(m_debugger);
602 void DebuggerMainWnd::slotAddWatch()
604 if (m_debugger != 0) {
605 QString t = m_watches->watchText();
606 m_debugger->addWatch(t);
610 void DebuggerMainWnd::slotFileChanged()
612 // set caption
613 #if QT_VERSION < 200
614 QString caption = kapp->getCaption();
615 #else
616 QString caption;
617 #endif
618 if (m_debugger->haveExecutable()) {
619 // basename part of executable
620 QString executable = m_debugger->executable();
621 const char* execBase = executable.data();
622 int lastSlash = executable.findRev('/');
623 if (lastSlash >= 0)
624 execBase += lastSlash + 1;
625 #if QT_VERSION < 200
626 caption += ": ";
627 #endif
628 caption += execBase;
630 QString file;
631 int line;
632 bool anyWindows = m_filesWindow->activeLine(file, line);
633 updateLineStatus(anyWindows ? line : -1);
634 if (anyWindows) {
635 caption += " (";
636 caption += file;
637 caption += ")";
639 setCaption(caption);
642 void DebuggerMainWnd::slotLineChanged()
644 QString file;
645 int line;
646 bool anyWindows = m_filesWindow->activeLine(file, line);
647 updateLineStatus(anyWindows ? line : -1);
650 void DebuggerMainWnd::slotNewFileLoaded()
652 // updates program counter in the new file
653 if (m_debugger != 0)
654 m_filesWindow->updateLineItems(m_debugger);
657 void DebuggerMainWnd::updateLineStatus(int lineNo)
659 if (lineNo < 0) {
660 statusBar()->changeItem("", ID_STATUS_LINENO);
661 } else {
662 QString strLine;
663 strLine.sprintf(i18n("Line %d"), lineNo + 1);
664 statusBar()->changeItem(strLine, ID_STATUS_LINENO);
668 DockWidget* DebuggerMainWnd::dockParent(QWidget* w)
670 while ((w = w->parentWidget()) != 0) {
671 if (w->isA("DockWidget"))
672 return static_cast<DockWidget*>(w);
674 return 0;
677 bool DebuggerMainWnd::isDockVisible(QWidget* w)
679 DockWidget* d = dockParent(w);
680 return d != 0 && d->mayBeHide();
683 bool DebuggerMainWnd::canChangeDockVisibility(QWidget* w)
685 DockWidget* d = dockParent(w);
686 return d != 0 && (d->mayBeHide() || d->mayBeShow());
689 void DebuggerMainWnd::showhideWindow(QWidget* w)
691 DockWidget* d = dockParent(w);
692 if (d == 0) {
693 TRACE(QString("no dockParent found: ") + d->name());
694 return;
696 d->changeHideShowState();
697 // updateUI();
700 KToolBar* DebuggerMainWnd::dbgToolBar()
702 return toolBar();
705 KStatusBar* DebuggerMainWnd::dbgStatusBar()
707 return statusBar();
710 QWidget* DebuggerMainWnd::dbgMainWnd()
712 return this;
715 TTYWindow* DebuggerMainWnd::ttyWindow()
717 return m_ttyWindow;
720 void DebuggerMainWnd::slotNewStatusMsg()
722 DebuggerMainWndBase::slotNewStatusMsg();
725 void DebuggerMainWnd::slotAnimationTimeout()
727 DebuggerMainWndBase::slotAnimationTimeout();
730 void DebuggerMainWnd::doGlobalOptions()
732 int oldTabWidth = m_tabWidth;
734 DebuggerMainWndBase::doGlobalOptions();
736 if (m_tabWidth != oldTabWidth) {
737 emit setTabWidth(m_tabWidth);
741 void DebuggerMainWnd::slotDebuggerStarting()
743 DebuggerMainWndBase::slotDebuggerStarting();
746 void DebuggerMainWnd::slotToggleBreak(const QString& fileName, int lineNo,
747 const DbgAddr& address, bool temp)
749 // lineNo is zero-based
750 if (m_debugger != 0) {
751 m_debugger->setBreakpoint(fileName, lineNo, address, temp);
755 void DebuggerMainWnd::slotEnaDisBreak(const QString& fileName, int lineNo,
756 const DbgAddr& address)
758 // lineNo is zero-based
759 if (m_debugger != 0) {
760 m_debugger->enableDisableBreakpoint(fileName, lineNo, address);
764 QString DebuggerMainWnd::createOutputWindow()
766 QString tty = DebuggerMainWndBase::createOutputWindow();
767 if (!tty.isEmpty()) {
768 connect(m_outputTermProc, SIGNAL(processExited(KProcess*)),
769 SLOT(slotTermEmuExited()));
771 return tty;
774 void DebuggerMainWnd::slotTermEmuExited()
776 shutdownTermWindow();
779 #include <X11/Xlib.h> /* XRaiseWindow, XLowerWindow */
781 void DebuggerMainWnd::slotProgramStopped()
783 // when the program stopped, move the window to the foreground
784 if (m_popForeground) {
785 ::XRaiseWindow(x11Display(), winId());
787 m_backTimer.stop();
790 void DebuggerMainWnd::intoBackground()
792 m_backTimer.start(m_backTimeout, true); /* single-shot */
795 void DebuggerMainWnd::slotBackTimer()
797 ::XLowerWindow(x11Display(), winId());
800 void DebuggerMainWnd::slotRecentExec(int item)
802 if (item >= 0 && item < int(m_recentExecList.count())) {
803 QString exe = m_recentExecList.at(item);
804 if (debugProgramInteractive(exe)) {
805 addRecentExec(exe);
806 } else {
807 removeRecentExec(exe);
809 fillRecentExecMenu();
813 void DebuggerMainWnd::fillRecentExecMenu()
815 m_menuRecentExecutables->clear();
816 for (uint i = 0; i < m_recentExecList.count(); i++) {
817 m_menuRecentExecutables->insertItem(m_recentExecList.at(i), i);
821 QString DebuggerMainWnd::makeSourceFilter()
823 QString f;
824 f = m_sourceFilter + " " + m_headerFilter + i18n("|All source files\n");
825 f += m_sourceFilter + i18n("|Source files\n");
826 f += m_headerFilter + i18n("|Header files\n");
827 f += i18n("*|All files");
828 return f;
832 * Pop up the context menu in the locals window
834 void DebuggerMainWnd::slotLocalsPopup(int, const QPoint& pt)
836 if (m_popupLocals->isVisible()) {
837 m_popupLocals->hide();
838 } else {
839 m_popupLocals->popup(m_localVariables->mapToGlobal(pt));
844 * Copies the currently selected item to the watch window.
846 void DebuggerMainWnd::slotLocalsToWatch()
848 int idx = m_localVariables->currentItem();
850 if (idx >= 0 && m_debugger != 0) {
851 QString text = m_localVariables->exprStringAt(idx);
852 m_debugger->addWatch(text);
857 #include "dbgmainwnd.moc"