Skip to content

Goto line dialog #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
20 changes: 17 additions & 3 deletions kdbg/dbgmainwnd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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)),
Expand Down Expand Up @@ -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 },
Expand Down Expand Up @@ -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";
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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());
Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand Down Expand Up @@ -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);
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please mimic the coding style that you see elsewhere in this project: No space after the opening parenthesis and before the closing parenthesis. Do not use the _Ci, which looks like a type indicator. Do not use this->. Do not copy the member variable unnecessarily, it does not make the code easier to read and reason about.

}
}

Expand Down
2 changes: 2 additions & 0 deletions kdbg/dbgmainwnd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
13 changes: 8 additions & 5 deletions kdbg/prefmisc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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):"),
Expand Down
22 changes: 19 additions & 3 deletions kdbg/prefmisc.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@

class PrefMisc : public QWidget
{
Q_OBJECT
public:
PrefMisc(QWidget* parent);

QGridLayout m_grid;

protected:
QCheckBox m_popForeground;

QLabel m_backTimeoutLabel;
QCheckBox m_lowerWindow;
QLineEdit m_backTimeout;

QLabel m_tabWidthLabel;
Expand All @@ -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;
Expand All @@ -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
29 changes: 29 additions & 0 deletions kdbg/sourcewnd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_t>(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
Expand Down
4 changes: 4 additions & 0 deletions kdbg/sourcewnd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
68 changes: 68 additions & 0 deletions kdbg/winstack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
28 changes: 28 additions & 0 deletions kdbg/winstack.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#define WINSTACK_H

#include <QDialog>
#include <QLabel>
#include <QLineEdit>
#include <QCheckBox>
#include <QPushButton>
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand All @@ -92,6 +118,7 @@ public slots:

void slotFileReload();
void slotViewFind();
void slotViewGoto();
void slotBrkptSet();
void slotBrkptSetTemp();
void slotBrkptEnable();
Expand Down Expand Up @@ -137,6 +164,7 @@ public slots:
public:
// find dialog
FindDialog m_findDlg;
GotoDialog m_gotoDlg;
};

#endif // WINSTACK_H