diff --git a/debugger/breakpoint/breakpointmodel.h b/debugger/breakpoint/breakpointmodel.h --- a/debugger/breakpoint/breakpointmodel.h +++ b/debugger/breakpoint/breakpointmodel.h @@ -140,6 +140,7 @@ private: enum MarkType { + BookMark = KTextEditor::MarkInterface::Bookmark, BreakpointMark = KTextEditor::MarkInterface::BreakpointActive, ReachedBreakpointMark = KTextEditor::MarkInterface::BreakpointReached, DisabledBreakpointMark = KTextEditor::MarkInterface::BreakpointDisabled, diff --git a/debugger/breakpoint/breakpointmodel.cpp b/debugger/breakpoint/breakpointmodel.cpp --- a/debugger/breakpoint/breakpointmodel.cpp +++ b/debugger/breakpoint/breakpointmodel.cpp @@ -29,6 +29,8 @@ #include #include #include +#include +#include #include "../interfaces/icore.h" #include "../interfaces/idebugcontroller.h" @@ -111,7 +113,7 @@ iface->setMarkPixmap((MarkInterface::MarkTypes)PendingBreakpointMark, *pendingBreakpointPixmap()); iface->setMarkPixmap((MarkInterface::MarkTypes)ReachedBreakpointMark, *reachedBreakpointPixmap()); iface->setMarkPixmap((MarkInterface::MarkTypes)DisabledBreakpointMark, *disabledBreakpointPixmap()); - iface->setEditableMarks( MarkInterface::Bookmark | BreakpointMark ); + iface->setEditableMarks( BookMark | BreakpointMark ); updateMarks(); } } @@ -135,14 +137,18 @@ int type = mark.type; qCDebug(DEBUGGER) << type; + KTextEditor::MarkInterface *miface = qobject_cast(document); + Breakpoint *b = nullptr; if ((type & AllBreakpointMarks)) { b = breakpoint(document->url(), mark.line); if (!b) { QMessageBox::critical(nullptr, i18n("Breakpoint not found"), i18n("Couldn't find breakpoint at %1:%2", document->url().toString(), mark.line)); } - } else if (!(type & MarkInterface::Bookmark)) // neither breakpoint nor bookmark + } else if (!type && (miface->editableMarks() & ~(BookMark | AllBreakpointMarks))) { + // there are not just breakpoints and bookmarks to handle, use default menu return; + } QMenu menu; QAction* breakpointAction = menu.addAction(QIcon::fromTheme(QStringLiteral("breakpoint")), i18n("&Breakpoint")); @@ -155,18 +161,46 @@ menu.addAction(QIcon::fromTheme(QStringLiteral("dialog-ok-apply")), i18n("&Enable Breakpoint")); } menu.addSeparator(); - QAction* bookmarkAction = menu.addAction(QIcon::fromTheme(QStringLiteral("bookmark-new")), i18n("&Bookmark")); + QAction* bookmarkAction = menu.addAction(QIcon::fromTheme(QStringLiteral("bookmark-new")), i18n("Book&mark")); bookmarkAction->setCheckable(true); - bookmarkAction->setChecked((type & MarkInterface::Bookmark)); + bookmarkAction->setChecked((type & BookMark)); + + // add menu for selection of default mark type + QMenu selectDefaultMark; + auto selectDefaultMarkActionGroup = new QActionGroup(&selectDefaultMark); + + QAction* defaultBreakpointAction = + selectDefaultMark.addAction(QIcon::fromTheme(QStringLiteral("breakpoint")), i18n("&Breakpoint")); + selectDefaultMarkActionGroup->addAction(defaultBreakpointAction); + defaultBreakpointAction->setCheckable(true); + QAction* defaultBookmarkAction = + selectDefaultMark.addAction(QIcon::fromTheme(QStringLiteral("bookmark-new")), i18n("Book&mark")); + selectDefaultMarkActionGroup->addAction(defaultBookmarkAction); + defaultBookmarkAction->setCheckable(true); + + // document does not provide a valid ConfigInterface, try views instead + KTextEditor::ConfigInterface *ciface = nullptr; + foreach (KTextEditor::View* view, document->views()) { + if ((ciface = qobject_cast(view))) + break; + } + if (ciface) { + const unsigned int defaultMarkType = ciface->configValue(QStringLiteral("default-mark-type")).toUInt(); + if (defaultMarkType == BreakpointMark) + defaultBreakpointAction->setChecked(true); + else if (defaultMarkType == BookMark) + defaultBookmarkAction->setChecked(true); + + menu.addAction(i18n("Set Default Mark &Type"))->setMenu(&selectDefaultMark); + } QAction* triggeredAction = menu.exec(pos); if (triggeredAction) { if (triggeredAction == bookmarkAction) { - KTextEditor::MarkInterface *iface = qobject_cast(document); - if ((type & MarkInterface::Bookmark)) - iface->removeMark(mark.line, MarkInterface::Bookmark); + if ((type & BookMark)) + miface->removeMark(mark.line, BookMark); else - iface->addMark(mark.line, MarkInterface::Bookmark); + miface->addMark(mark.line, BookMark); } else if (triggeredAction == breakpointAction) { if (b) { b->setDeleted(); @@ -183,6 +217,10 @@ } } else if (triggeredAction == enableAction) { b->setData(Breakpoint::EnableColumn, b->enabled() ? Qt::Unchecked : Qt::Checked); + } else if (triggeredAction == defaultBreakpointAction) { + ciface->setConfigValue(QStringLiteral("default-mark-type"), BreakpointMark); + } else if (triggeredAction == defaultBookmarkAction) { + ciface->setConfigValue(QStringLiteral("default-mark-type"), BookMark); } }