| 363 | } |
| 364 | |
| 365 | void BreakpointModel::markContextMenuRequested(KTextEditor::Document* document, Mark mark, QPoint pos, bool& handled) |
| 366 | { |
| 367 | int type = mark.type; |
| 368 | qCDebug(DEBUGGER) << type; |
| 369 | |
| 370 | if (!(document->editableMarks() & BreakpointMark)) { |
| 371 | return; // breakpoints are forbidden in this document, so let KTextEditor show its default context menu |
| 372 | } |
| 373 | |
| 374 | Breakpoint *b = nullptr; |
| 375 | if ((type & AllBreakpointMarks)) { |
| 376 | b = breakpoint(document->url(), mark.line); |
| 377 | if (!b) { |
| 378 | QMessageBox::critical(nullptr, i18n("Breakpoint not found"), i18n("Couldn't find breakpoint at %1:%2", document->url().toString(), mark.line)); |
| 379 | } |
| 380 | } else if (!(type & MarkType::Bookmark)) // neither breakpoint nor bookmark |
| 381 | return; |
| 382 | |
| 383 | QMenu menu; // TODO: needs qwidget |
| 384 | QAction* breakpointAction = menu.addAction(QIcon::fromTheme(QStringLiteral("breakpoint")), i18n("&Breakpoint")); |
| 385 | breakpointAction->setCheckable(true); |
| 386 | breakpointAction->setChecked(b); |
| 387 | QAction* enableAction = nullptr; |
| 388 | if (b) { |
| 389 | enableAction = b->enabled() ? |
| 390 | menu.addAction(QIcon::fromTheme(QStringLiteral("dialog-cancel")), i18n("&Disable Breakpoint")) : |
| 391 | menu.addAction(QIcon::fromTheme(QStringLiteral("dialog-ok-apply")), i18n("&Enable Breakpoint")); |
| 392 | } |
| 393 | menu.addSeparator(); |
| 394 | QAction* bookmarkAction = menu.addAction(QIcon::fromTheme(QStringLiteral("bookmark-new")), i18n("&Bookmark")); |
| 395 | bookmarkAction->setCheckable(true); |
| 396 | bookmarkAction->setChecked((type & MarkType::Bookmark)); |
| 397 | |
| 398 | QAction* triggeredAction = menu.exec(pos); |
| 399 | if (triggeredAction) { |
| 400 | if (triggeredAction == bookmarkAction) { |
| 401 | if ((type & MarkType::Bookmark)) |
| 402 | document->removeMark(mark.line, MarkType::Bookmark); |
| 403 | else |
| 404 | document->addMark(mark.line, MarkType::Bookmark); |
| 405 | } else if (triggeredAction == breakpointAction) { |
| 406 | if (b) { |
| 407 | removeBreakpoint(b); |
| 408 | } else { |
| 409 | addCodeBreakpoint(document->url(), mark.line); |
| 410 | } |
| 411 | } else if (triggeredAction == enableAction) { |
| 412 | b->setData(Breakpoint::EnableColumn, b->enabled() ? Qt::Unchecked : Qt::Checked); |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | handled = true; |
| 417 | } |
| 418 | |
| 419 | |
| 420 | QVariant |