diff --git a/kdbg/dbgmainwnd.cpp b/kdbg/dbgmainwnd.cpp index e0c061b..35d9832 100644 --- a/kdbg/dbgmainwnd.cpp +++ b/kdbg/dbgmainwnd.cpp @@ -65,6 +65,7 @@ DebuggerMainWnd::DebuggerMainWnd() : m_outputTermProc(new QProcess), m_ttyLevel(-1), /* no tty yet */ m_popForeground(false), + m_lowerWindow(false), m_backTimeout(1000), m_tabWidth(0), m_sourceFilter(defaultSourceFilter), @@ -119,6 +120,7 @@ DebuggerMainWnd::DebuggerMainWnd() : connect(m_watches, SIGNAL(textDropped(const QString&)), SLOT(slotAddWatch(const QString&))); connect(&m_filesWindow->m_findDlg, SIGNAL(closed()), SLOT(updateUI())); + connect(&m_filesWindow->m_gotoDlg, SIGNAL(closed()), SLOT(updateUI())); connect(m_filesWindow, SIGNAL(newFileLoaded()), SLOT(slotNewFileLoaded())); connect(m_filesWindow, SIGNAL(toggleBreak(const QString&,int,const DbgAddr&,bool)), @@ -277,6 +279,7 @@ void DebuggerMainWnd::initKAction() m_findAction = KStandardAction::find(m_filesWindow, SLOT(slotViewFind()), actionCollection()); KStandardAction::findNext(m_filesWindow, SLOT(slotFindForward()), actionCollection()); KStandardAction::findPrev(m_filesWindow, SLOT(slotFindBackward()), actionCollection()); + m_gotoAction = KStandardAction::gotoLine(m_filesWindow, &WinStack::slotViewGoto, actionCollection()); struct { QWidget* w; QString id; QAction** act; } dw[] = { { m_btWindow, "view_stack", &m_btWindowAction }, @@ -441,6 +444,7 @@ static const char DebuggerGroup[] = "Debugger"; static const char DebuggerCmdStr[] = "DebuggerCmdStr"; static const char PreferencesGroup[] = "Preferences"; static const char PopForeground[] = "PopForeground"; +static const char LowerWindow[] = "LowerWindow"; static const char BackTimeout[] = "BackTimeout"; static const char TabWidth[] = "TabWidth"; static const char SourceFileFilter[] = "SourceFileFilter"; @@ -464,6 +468,7 @@ void DebuggerMainWnd::saveSettings(KSharedConfigPtr config) KConfigGroup pg(config->group(PreferencesGroup)); pg.writeEntry(PopForeground, m_popForeground); + pg.writeEntry(LowerWindow, m_lowerWindow); pg.writeEntry(BackTimeout, m_backTimeout); pg.writeEntry(TabWidth, m_tabWidth); pg.writeEntry(SourceFileFilter, m_sourceFilter); @@ -501,6 +506,7 @@ void DebuggerMainWnd::restoreSettings(KSharedConfigPtr config) KConfigGroup pg(config->group(PreferencesGroup)); m_popForeground = pg.readEntry(PopForeground, false); + m_lowerWindow = pg.readEntry(LowerWindow, false); m_backTimeout = pg.readEntry(BackTimeout, 1000); m_tabWidth = pg.readEntry(TabWidth, 0); m_sourceFilter = pg.readEntry(SourceFileFilter, m_sourceFilter); @@ -516,6 +522,8 @@ void DebuggerMainWnd::updateUI() { m_findAction->setChecked(m_filesWindow->m_findDlg.isVisible()); m_findAction->setEnabled(m_filesWindow->hasWindows()); + m_gotoAction->setChecked(m_filesWindow->m_gotoDlg.isVisible()); + m_gotoAction->setEnabled(m_filesWindow->hasWindows()); m_bpSetAction->setEnabled(m_debugger->canChangeBreakpoints()); m_bpSetTempAction->setEnabled(m_debugger->canChangeBreakpoints()); m_bpEnableAction->setEnabled(m_debugger->canChangeBreakpoints()); @@ -858,6 +866,7 @@ void DebuggerMainWnd::slotFileGlobalSettings() PrefMisc prefMisc(&dlg); prefMisc.setPopIntoForeground(m_popForeground); + prefMisc.setLowerWindow(m_lowerWindow); prefMisc.setBackTimeout(m_backTimeout); prefMisc.setTabWidth(m_tabWidth); prefMisc.setSourceFilter(m_sourceFilter); @@ -871,6 +880,7 @@ void DebuggerMainWnd::slotFileGlobalSettings() setDebuggerCmdStr(prefDebugger.debuggerCmd()); setTerminalCmd(prefDebugger.terminal()); m_popForeground = prefMisc.popIntoForeground(); + m_lowerWindow = prefMisc.isLowerWindowRqed(); m_backTimeout = prefMisc.backTimeout(); m_tabWidth = prefMisc.tabWidth(); m_sourceFilter = prefMisc.sourceFilter(); @@ -1081,9 +1091,13 @@ void DebuggerMainWnd::slotProgramStopped() void DebuggerMainWnd::intoBackground() { - if (m_popForeground) { - m_backTimer.setSingleShot(true); - m_backTimer.start(m_backTimeout); + if (m_popForeground) + { + if (m_lowerWindow) + { + m_backTimer.setSingleShot(true); + m_backTimer.start(m_backTimeout); + } } } diff --git a/kdbg/dbgmainwnd.h b/kdbg/dbgmainwnd.h index a1e4d6f..e74341d 100644 --- a/kdbg/dbgmainwnd.h +++ b/kdbg/dbgmainwnd.h @@ -87,6 +87,7 @@ class DebuggerMainWnd : public KXmlGuiWindow QAction* m_coreDumpAction; QAction* m_settingsAction; QAction* m_findAction; + QAction* m_gotoAction; QAction* m_btWindowAction; QAction* m_localVariablesAction; QAction* m_watchesAction; @@ -149,6 +150,7 @@ class DebuggerMainWnd : public KXmlGuiWindow QString createOutputWindow(); bool m_popForeground; /* whether main wnd raises when prog stops */ + bool m_lowerWindow; /* whether m_backTimeout is used. */ int m_backTimeout; /* when wnd goes back */ int m_tabWidth; /* tab width in characters (can be 0) */ QString m_sourceFilter; diff --git a/kdbg/prefmisc.cpp b/kdbg/prefmisc.cpp index aba3c28..58af36f 100644 --- a/kdbg/prefmisc.cpp +++ b/kdbg/prefmisc.cpp @@ -11,7 +11,7 @@ PrefMisc::PrefMisc(QWidget* parent) : QWidget(parent), m_grid(this), m_popForeground(this), - m_backTimeoutLabel(this), + m_lowerWindow(this), m_backTimeout(this), m_tabWidthLabel(this), m_tabWidth(this), @@ -22,14 +22,17 @@ PrefMisc::PrefMisc(QWidget* parent) : { m_popForeground.setText(i18n("&Pop into foreground when program stops")); m_popForeground.setMinimumSize(m_popForeground.sizeHint()); + connect( &m_popForeground, SIGNAL(toggled(bool)), this, SLOT(setPopIntoForeground(bool)) ); m_grid.addWidget(&m_popForeground, 0, 0, 1, 2); m_grid.addItem(new QSpacerItem(0, m_popForeground.sizeHint().height()), 0, 0); - m_backTimeoutLabel.setText(i18n("Time until window goes &back (in milliseconds):")); - m_backTimeoutLabel.setMinimumSize(m_backTimeoutLabel.sizeHint()); - m_backTimeoutLabel.setBuddy(&m_backTimeout); + m_lowerWindow.setText(i18n("&Lower window after [ms]:")); + const QString backTimeoutTT_Cqs( i18n("Lower the kdbg window with continuing execution of the debuge.") ); + m_lowerWindow.setToolTip( backTimeoutTT_Cqs ); + m_lowerWindow.setMinimumSize(m_lowerWindow.sizeHint()); + connect( &m_lowerWindow, SIGNAL(toggled(bool)), this, SLOT(setLowerWindow(bool)) ); m_backTimeout.setMinimumSize(m_backTimeout.sizeHint()); - m_grid.addWidget(&m_backTimeoutLabel, 1, 0); + m_grid.addWidget(&m_lowerWindow, 1, 0); m_grid.addWidget(&m_backTimeout, 1, 1); setupEditGroup(i18n("&Tabstop every (characters):"), diff --git a/kdbg/prefmisc.h b/kdbg/prefmisc.h index fc90cc5..41ba4d7 100644 --- a/kdbg/prefmisc.h +++ b/kdbg/prefmisc.h @@ -14,6 +14,7 @@ class PrefMisc : public QWidget { + Q_OBJECT public: PrefMisc(QWidget* parent); @@ -21,8 +22,7 @@ class PrefMisc : public QWidget protected: QCheckBox m_popForeground; - - QLabel m_backTimeoutLabel; + QCheckBox m_lowerWindow; QLineEdit m_backTimeout; QLabel m_tabWidthLabel; @@ -37,7 +37,7 @@ class PrefMisc : public QWidget public: bool popIntoForeground() const { return m_popForeground.isChecked(); } - void setPopIntoForeground(bool pop) { m_popForeground.setChecked(pop); } + bool isLowerWindowRqed() const { return m_lowerWindow.isChecked(); } int backTimeout() const; void setBackTimeout(int to); int tabWidth() const; @@ -46,6 +46,22 @@ class PrefMisc : public QWidget void setSourceFilter(const QString& f) { m_sourceFilter.setText(f); } QString headerFilter() const { return m_headerFilter.text(); } void setHeaderFilter(const QString& f) { m_headerFilter.setText(f); } + +public slots: + void setPopIntoForeground(bool pop) + { + m_popForeground.setChecked(pop); + m_lowerWindow.setEnabled(pop); + if ( isLowerWindowRqed() ) + { + m_backTimeout.setEnabled(pop); + } + } + void setLowerWindow(bool is) + { + m_lowerWindow.setChecked(is); + m_backTimeout.setEnabled(is); + } }; #endif // PREFMISC_H diff --git a/kdbg/sourcewnd.cpp b/kdbg/sourcewnd.cpp index 6f70599..ebc9f9f 100644 --- a/kdbg/sourcewnd.cpp +++ b/kdbg/sourcewnd.cpp @@ -339,6 +339,35 @@ void SourceWindow::find(const QString& text, bool caseSensitive, FindDirection d setTextCursor(cursor); } +void SourceWindow::gotoLine( const QString& text) +{ + bool isSuc; + int lineGoto = text.toInt(&isSuc); + if (!isSuc) + { + return; + } + + { /* Because of assert at lineToRow(): */ + if ( m_rowToLine.size() == 0 ) + { + return; + } + if ( static_cast(lineGoto) >= m_rowToLine.size() ) + { + lineGoto = m_rowToLine.size() - 1; + } + } + int row = lineToRow(lineGoto); /*< if assembly is visible row != line. */ + + QTextCursor cursor(document()); + cursor.setPosition(0); // goto file first line + + isSuc = cursor.movePosition(QTextCursor::Down, QTextCursor::MoveAnchor, row - 1); + + setTextCursor( cursor ); +} + void SourceWindow::infoMousePress(QMouseEvent* ev) { // we handle left and middle button diff --git a/kdbg/sourcewnd.h b/kdbg/sourcewnd.h index 8eb5566..b5626f5 100644 --- a/kdbg/sourcewnd.h +++ b/kdbg/sourcewnd.h @@ -35,6 +35,10 @@ class SourceWindow : public QPlainTextEdit void setPC(bool set, int lineNo, const DbgAddr& address, int frameNo); enum FindDirection { findForward = 1, findBackward = -1 }; void find(const QString& text, bool caseSensitive, FindDirection dir); + /** + * Scrolls to the specified line number given as text + */ + void gotoLine( const QString& text); bool wordAtPoint(const QPoint& p, QString& word, QRect& r); /** * Translates row number (zero-based) to zero-based source line number. diff --git a/kdbg/winstack.cpp b/kdbg/winstack.cpp index 45ea5a0..7be217d 100644 --- a/kdbg/winstack.cpp +++ b/kdbg/winstack.cpp @@ -31,6 +31,9 @@ WinStack::WinStack(QWidget* parent) : connect(&m_findDlg.m_buttonBackward, SIGNAL(clicked()), SLOT(slotFindBackward())); + connect( &m_gotoDlg.m_lineText, + SIGNAL(returnPressed()), SLOT(slotGotoLine())); + connect(this, SIGNAL(setTabWidth(int)), this, SLOT(slotSetTabWidth(int))); connect(this, SIGNAL(tabCloseRequested(int)), this, SLOT(slotCloseTab(int))); @@ -245,6 +248,14 @@ void WinStack::slotFindBackward() SourceWindow::findBackward); } +void WinStack::slotGotoLine() +{ + if (activeWindow() != 0) + activeWindow()->gotoLine(m_gotoDlg.lineText()); + + m_gotoDlg.done(1); // hide dialog +} + bool WinStack::event(QEvent* evt) { if (evt->type() != QEvent::ToolTip) @@ -335,6 +346,18 @@ void WinStack::slotViewFind() } } +void WinStack::slotViewGoto() +{ + if (m_gotoDlg.isVisible()) + { + m_gotoDlg.done(0); + } + else + { + m_gotoDlg.show(); + } +} + void WinStack::slotBrkptSet() { QString file; @@ -437,3 +460,48 @@ void FindDialog::done(int result) QDialog::done(result); emit closed(); } + + +GotoDialog::GotoDialog() : + QDialog(), + m_label(this), + m_lineText(this), + m_buttonClose(this) +{ + const QString label(i18n("Goto line")); + setWindowTitle(label); + setWindowModality( Qt::ApplicationModal ); + setWindowFlags( windowFlags() | Qt::WindowStaysOnTopHint ); + + m_label.setText(label); + + m_lineText.setMinimumSize(100, 24); + m_lineText.setMaxLength(10000); + m_lineText.setFrame(true); + m_lineText.setFocus(); + + m_buttonClose.setText(i18n("Close")); + connect(&m_buttonClose, SIGNAL(clicked()), SLOT(reject())); + + m_layout.addWidget(&m_label); + m_layout.addWidget(&m_lineText); + m_layout.addWidget(&m_buttonClose); + + setLayout(&m_layout); +} + +GotoDialog::~GotoDialog() +{ +} + +void GotoDialog::closeEvent(QCloseEvent* ev) +{ + QDialog::closeEvent(ev); + emit closed(); +} + +void GotoDialog::done(int result) +{ + QDialog::done(result); + emit closed(); +} diff --git a/kdbg/winstack.h b/kdbg/winstack.h index 173378e..e75f3e3 100644 --- a/kdbg/winstack.h +++ b/kdbg/winstack.h @@ -8,6 +8,7 @@ #define WINSTACK_H #include +#include #include #include #include @@ -50,6 +51,30 @@ class FindDialog : public QDialog }; +/** Class for Goto Line dialog. */ +class GotoDialog : public QDialog +{ + Q_OBJECT +public: + GotoDialog(); + ~GotoDialog(); + + QString lineText() const { return m_lineText.text(); } + void done(int result) override; + + QLabel m_label; + QLineEdit m_lineText; + QPushButton m_buttonClose; + +signals: + void closed(); + +protected: + void closeEvent(QCloseEvent* ev) override; + QHBoxLayout m_layout; +}; + + class WinStack : public QTabWidget { Q_OBJECT @@ -84,6 +109,7 @@ class WinStack : public QTabWidget public slots: virtual void slotFindForward(); virtual void slotFindBackward(); + virtual void slotGotoLine(); virtual void activate(const QString& filename, int lineNo, const DbgAddr& address); void updatePC(const QString& filename, int lineNo, const DbgAddr& address, int frameNo); void reloadAllFiles(); @@ -92,6 +118,7 @@ public slots: void slotFileReload(); void slotViewFind(); + void slotViewGoto(); void slotBrkptSet(); void slotBrkptSetTemp(); void slotBrkptEnable(); @@ -137,6 +164,7 @@ public slots: public: // find dialog FindDialog m_findDlg; + GotoDialog m_gotoDlg; }; #endif // WINSTACK_H