Commit 2bdf10ce authored by hjk's avatar hjk
Browse files

debugger: reenable disabling of breakpoints in editor context menu

parent f3d38de9
......@@ -572,15 +572,6 @@ QVariant BreakHandler::data(const QModelIndex &mi, int role) const
static const QString empty = QString(QLatin1Char('-'));
switch (role) {
case RequestFindSimilarBreakpointRole: {
// Complain if data/setData are not used alternately.
QTC_ASSERT(m_lastFoundQueried, return false);
QVariant value = QVariant::fromValue(m_lastFound);
m_lastFoundQueried = false;
m_lastFound = 0; // Reset for "safety".
return value;
}
case CurrentThreadIdRole:
QTC_ASSERT(m_engine, return QVariant());
return m_engine->threadsHandler()->currentThreadId();
......@@ -714,16 +705,6 @@ Qt::ItemFlags BreakHandler::flags(const QModelIndex &index) const
bool BreakHandler::setData(const QModelIndex &index, const QVariant &value, int role)
{
switch (role) {
case RequestFindSimilarBreakpointRole: {
// Complain if data/setData are not used alternately.
QTC_ASSERT(!m_lastFoundQueried, return false);
BreakpointData *needle = value.value<BreakpointData *>();
QTC_ASSERT(needle, return false);
m_lastFound = findSimilarBreakpoint(needle);
m_lastFoundQueried = true;
return true;
}
case RequestActivateBreakpointRole: {
const BreakpointData *data = at(value.toInt());
QTC_ASSERT(data, return false);
......@@ -739,14 +720,6 @@ bool BreakHandler::setData(const QModelIndex &index, const QVariant &value, int
return true;
}
case RequestUpdateBreakpointRole: {
BreakpointData *data = value.value<BreakpointData *>();
QTC_ASSERT(data, return false);
QTC_ASSERT(m_engine, return false);
m_engine->attemptBreakpointSynchronization();
return true;
}
case RequestSynchronizeBreakpointsRole:
QTC_ASSERT(m_engine, return false);
m_engine->attemptBreakpointSynchronization();
......@@ -884,14 +857,12 @@ void BreakHandler::removeBreakpoint(int index)
return;
removeBreakpointHelper(index);
emit layoutChanged();
//saveBreakpoints();
}
void BreakHandler::removeBreakpoint(BreakpointData *data)
{
removeBreakpointHelper(m_bp.indexOf(data));
emit layoutChanged();
//saveBreakpoints();
}
void BreakHandler::toggleBreakpointEnabled(BreakpointData *data)
......@@ -905,7 +876,6 @@ void BreakHandler::toggleBreakpointEnabled(BreakpointData *data)
m_enabled.removeAll(data);
m_disabled.append(data);
}
//saveBreakpoints();
updateMarkers();
}
......@@ -913,7 +883,7 @@ void BreakHandler::appendBreakpoint(BreakpointData *data)
{
append(data);
emit layoutChanged();
saveBreakpoints();
saveBreakpoints(); // FIXME: remove?
updateMarkers();
}
......@@ -922,21 +892,24 @@ void BreakHandler::removeAllBreakpoints()
for (int index = size(); --index >= 0;)
removeBreakpointHelper(index);
emit layoutChanged();
//saveBreakpoints();
updateMarkers();
}
BreakpointData *BreakHandler::findBreakpoint(const QString &fileName, int lineNumber)
{
foreach (BreakpointData *data, m_bp)
if (data->isLocatedAt(fileName, lineNumber))
return data;
return 0;
}
void BreakHandler::toggleBreakpoint(const QString &fileName, int lineNumber)
{
for (int index = size(); --index >= 0;) {
BreakpointData *data = m_bp.at(index);
if (data->isLocatedAt(fileName, lineNumber)) {
removeBreakpointHelper(index);
emit layoutChanged();
return;
}
}
BreakpointData *data = new BreakpointData;
BreakpointData *data = findBreakpoint(fileName, lineNumber);
if (data) {
removeBreakpoint(data);
} else {
data = new BreakpointData;
data->fileName = fileName;
data->lineNumber = QByteArray::number(lineNumber);
data->pending = true;
......@@ -944,6 +917,16 @@ void BreakHandler::toggleBreakpoint(const QString &fileName, int lineNumber)
data->setMarkerLineNumber(lineNumber);
appendBreakpoint(data);
m_engine->attemptBreakpointSynchronization();
}
}
void BreakHandler::toggleBreakpointEnabled(const QString &fileName, int lineNumber)
{
BreakpointData *data = findBreakpoint(fileName, lineNumber);
QTC_ASSERT(data, return);
data->enabled = !data->enabled;
data->updateMarker();
m_engine->attemptBreakpointSynchronization();
}
void BreakHandler::saveSessionData()
......
......@@ -88,6 +88,8 @@ public:
void initializeFromTemplate(BreakHandler *other);
void storeToTemplate(BreakHandler *other);
void toggleBreakpoint(const QString &fileName, int lineNumber);
void toggleBreakpointEnabled(const QString &fileName, int lineNumber);
BreakpointData *findBreakpoint(const QString &fileName, int lineNumber);
public slots:
void appendBreakpoint(BreakpointData *data);
......
......@@ -411,22 +411,6 @@ void BreakWindow::rowActivated(const QModelIndex &index)
setModelData(RequestActivateBreakpointRole, index.row());
}
BreakpointData *BreakWindow::findSimilarBreakpoint(const BreakpointData *needle0)
{
BreakpointData *needle = const_cast<BreakpointData *>(needle0);
QVariant v = QVariant::fromValue<BreakpointData *>(needle);
setModelData(RequestFindSimilarBreakpointRole, v);
QTC_ASSERT(model(), return false);
v = model()->data(QModelIndex(), RequestFindSimilarBreakpointRole);
return v.value<BreakpointData *>();
}
void BreakWindow::updateBreakpoint(BreakpointData *data)
{
QVariant v = QVariant::fromValue<BreakpointData *>(data);
setModelData(RequestUpdateBreakpointRole, v);
}
void BreakWindow::setModelData
(int role, const QVariant &value, const QModelIndex &index)
{
......
......@@ -45,17 +45,10 @@ public:
explicit BreakWindow(QWidget *parent = 0);
~BreakWindow();
BreakpointData *findSimilarBreakpoint(const BreakpointData *needle);
void updateBreakpoint(BreakpointData *data);
//void appendBreakpoint(BreakpointData *data);
//void removeBreakpoint(BreakpointData *data);
QVariant modelData(int role, int index);
public slots:
private slots:
void resizeColumnsToContents();
void setAlwaysResizeColumnsToContents(bool on);
private slots:
void rowActivated(const QModelIndex &index);
void setAlternatingRowColorsHelper(bool on) { setAlternatingRowColors(on); }
void showAddressColumn(bool on);
......
......@@ -194,9 +194,9 @@ enum ModelRoles
RequestSynchronizeBreakpointsRole,
RequestBreakByFunctionRole,
RequestBreakByFunctionMainRole,
RequestFindSimilarBreakpointRole,
RequestUpdateBreakpointRole,
RequestToggleBreakpointRole,
RequestToggleBreakpointEnabledRole,
RequestContextMenuRole,
// Locals and Watchers
LocalsINameRole,
......
......@@ -72,6 +72,7 @@
#include <QtGui/QAbstractItemView>
#include <QtGui/QStandardItemModel>
#include <QtGui/QAction>
#include <QtGui/QMenu>
#include <QtGui/QMessageBox>
#include <QtGui/QPlainTextEdit>
#include <QtGui/QPushButton>
......@@ -197,8 +198,10 @@ bool CommandHandler::setData(const QModelIndex &, const QVariant &value, int rol
//
//////////////////////////////////////////////////////////////////////
class DebuggerEnginePrivate
class DebuggerEnginePrivate : public QObject
{
Q_OBJECT
public:
DebuggerEnginePrivate(DebuggerEngine *engine, const DebuggerStartParameters &sp)
: m_engine(engine),
......@@ -217,6 +220,11 @@ public:
m_disassemblerViewAgent(engine)
{}
public slots:
void breakpointSetRemoveMarginActionTriggered();
void breakpointEnableDisableMarginActionTriggered();
void handleContextMenuRequest(const QVariant &parameters);
public:
DebuggerEngine *m_engine; // Not owned.
DebuggerRunControl *m_runControl; // Not owned.
......@@ -238,6 +246,85 @@ public:
DisassemblerViewAgent m_disassemblerViewAgent;
};
void DebuggerEnginePrivate::breakpointSetRemoveMarginActionTriggered()
{
QAction *act = qobject_cast<QAction *>(sender());
QTC_ASSERT(act, return);
QList<QVariant> list = act->data().toList();
QTC_ASSERT(list.size() == 2, return);
const QString fileName = list.at(0).toString();
const int lineNumber = list.at(1).toInt();
m_breakHandler.toggleBreakpoint(fileName, lineNumber);
}
void DebuggerEnginePrivate::breakpointEnableDisableMarginActionTriggered()
{
QAction *act = qobject_cast<QAction *>(sender());
QTC_ASSERT(act, return);
QList<QVariant> list = act->data().toList();
QTC_ASSERT(list.size() == 2, return);
const QString fileName = list.at(0).toString();
const int lineNumber = list.at(1).toInt();
m_breakHandler.toggleBreakpointEnabled(fileName, lineNumber);
}
void DebuggerEnginePrivate::handleContextMenuRequest(const QVariant &parameters)
{
const QList<QVariant> list = parameters.toList();
QTC_ASSERT(list.size() == 3, return);
TextEditor::ITextEditor *editor =
(TextEditor::ITextEditor *)(list.at(0).value<quint64>());
int lineNumber = list.at(1).toInt();
QMenu *menu = (QMenu *)(list.at(2).value<quint64>());
BreakpointData *data = 0;
QString position;
QString fileName;
if (editor->property("DisassemblerView").toBool()) {
fileName = editor->file()->fileName();
QString line = editor->contents()
.section('\n', lineNumber - 1, lineNumber - 1);
position = _("*") + fileName;
BreakpointData needle;
needle.bpAddress = line.left(line.indexOf(QLatin1Char(' '))).toLatin1();
needle.bpLineNumber = "-1";
data = m_breakHandler.findSimilarBreakpoint(&needle);
} else {
fileName = editor->file()->fileName();
position = fileName + QString(":%1").arg(lineNumber);
data = m_breakHandler.findBreakpoint(fileName, lineNumber);
}
QList<QVariant> args;
args.append(fileName);
args.append(lineNumber);
if (data) {
// existing breakpoint
QAction *act = new QAction(tr("Remove Breakpoint"), menu);
act->setData(args);
connect(act, SIGNAL(triggered()),
this, SLOT(breakpointSetRemoveMarginActionTriggered()));
menu->addAction(act);
QAction *act2;
if (data->enabled)
act2 = new QAction(tr("Disable Breakpoint"), menu);
else
act2 = new QAction(tr("Enable Breakpoint"), menu);
act2->setData(args);
connect(act2, SIGNAL(triggered()),
this, SLOT(breakpointEnableDisableMarginActionTriggered()));
menu->addAction(act2);
} else {
// non-existing
QAction *act = new QAction(tr("Set Breakpoint"), menu);
act->setData(args);
connect(act, SIGNAL(triggered()),
this, SLOT(breakpointSetRemoveMarginActionTriggered()));
menu->addAction(act);
}
}
//////////////////////////////////////////////////////////////////////
//
......@@ -340,15 +427,6 @@ void DebuggerEngine::handleCommand(int role, const QVariant &value)
executeDebuggerCommand(value.toString());
break;
case RequestToolTipByExpressionRole: {
QList<QVariant> list = value.toList();
QTC_ASSERT(list.size() == 3, break);
setToolTipExpression(list.at(0).value<QPoint>(),
(TextEditor::ITextEditor *)(list.at(1).value<quint64>()),
list.at(2).toInt()); // Eeks.
break;
}
case RequestToggleBreakpointRole: {
QList<QVariant> list = value.toList();
QTC_ASSERT(list.size() == 2, break);
......@@ -357,8 +435,25 @@ void DebuggerEngine::handleCommand(int role, const QVariant &value)
breakHandler()->toggleBreakpoint(fileName, lineNumber);
break;
}
case RequestToolTipByExpressionRole: {
QList<QVariant> list = value.toList();
QTC_ASSERT(list.size() == 3, break);
QPoint point = list.at(0).value<QPoint>();
TextEditor::ITextEditor *editor = // Eeks.
(TextEditor::ITextEditor *)(list.at(1).value<quint64>());
int pos = list.at(2).toInt();
setToolTipExpression(point, editor, pos);
break;
}
case RequestContextMenuRole: {
QList<QVariant> list = value.toList();
QTC_ASSERT(list.size() == 3, break);
d->handleContextMenuRequest(list);
break;
}
}
}
void DebuggerEngine::showModuleSymbols
......@@ -960,3 +1055,5 @@ bool DebuggerEngine::isReverseDebugging() const
} // namespace Internal
} // namespace Debugger
#include "debuggerengine.moc"
......@@ -815,8 +815,6 @@ public slots:
void activateDebugMode();
void toggleBreakpoint();
void toggleBreakpoint(const QString &fileName, int lineNumber);
void breakpointSetRemoveMarginActionTriggered();
void breakpointEnableDisableMarginActionTriggered();
void onModeChanged(Core::IMode *mode);
void showSettingsDialog();
......@@ -1785,51 +1783,11 @@ void DebuggerPluginPrivate::requestContextMenu(TextEditor::ITextEditor *editor,
if (!isDebuggable(editor))
return;
BreakpointData *data = 0;
QString position;
if (editor->property("DisassemblerView").toBool()) {
QString fileName = editor->file()->fileName();
QString line = editor->contents()
.section('\n', lineNumber - 1, lineNumber - 1);
position = _("*") + fileName;
BreakpointData needle;
needle.bpAddress = line.left(line.indexOf(QLatin1Char(' '))).toLatin1();
needle.bpLineNumber = "-1";
data = m_breakWindow->findSimilarBreakpoint(&needle);
} else {
QString fileName = editor->file()->fileName();
position = fileName + QString(":%1").arg(lineNumber);
BreakpointData needle;
needle.bpFileName = fileName;
needle.bpLineNumber = QByteArray::number(lineNumber);
data = m_breakWindow->findSimilarBreakpoint(&needle);
}
if (data) {
// existing breakpoint
QAction *act = new QAction(tr("Remove Breakpoint"), menu);
act->setData(position);
connect(act, SIGNAL(triggered()),
this, SLOT(breakpointSetRemoveMarginActionTriggered()));
menu->addAction(act);
QAction *act2;
if (data->enabled)
act2 = new QAction(tr("Disable Breakpoint"), menu);
else
act2 = new QAction(tr("Enable Breakpoint"), menu);
act2->setData(position);
connect(act2, SIGNAL(triggered()),
this, SLOT(breakpointEnableDisableMarginActionTriggered()));
menu->addAction(act2);
} else {
// non-existing
QAction *act = new QAction(tr("Set Breakpoint"), menu);
act->setData(position);
connect(act, SIGNAL(triggered()),
this, SLOT(breakpointSetRemoveMarginActionTriggered()));
menu->addAction(act);
}
QList<QVariant> list;
list.append(quint64(editor));
list.append(lineNumber);
list.append(quint64(menu));
notifyCurrentEngine(RequestContextMenuRole, list);
}
void DebuggerPluginPrivate::toggleBreakpoint()
......@@ -1849,31 +1807,6 @@ void DebuggerPluginPrivate::toggleBreakpoint(const QString &fileName, int lineNu
notifyCurrentEngine(RequestToggleBreakpointRole, list);
}
void DebuggerPluginPrivate::breakpointSetRemoveMarginActionTriggered()
{
QAction *act = qobject_cast<QAction *>(sender());
QTC_ASSERT(act, return);
QString str = act->data().toString();
int pos = str.lastIndexOf(':');
toggleBreakpoint(str.left(pos), str.mid(pos + 1).toInt());
}
void DebuggerPluginPrivate::breakpointEnableDisableMarginActionTriggered()
{
QAction *act = qobject_cast<QAction *>(sender());
QTC_ASSERT(act, return);
QString str = act->data().toString();
int pos = str.lastIndexOf(':');
BreakpointData needle;
needle.bpFileName = str.left(pos);
needle.bpLineNumber = str.mid(pos + 1).toLatin1();
BreakpointData *data = m_breakWindow->findSimilarBreakpoint(&needle);
QTC_ASSERT(data, return);
data->enabled = !data->enabled;
m_breakWindow->updateBreakpoint(data);
}
void DebuggerPluginPrivate::requestMark(ITextEditor *editor, int lineNumber)
{
if (isDebuggable(editor))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment