| 44 | } |
| 45 | |
| 46 | void BreakpointView::contextMenuEvent(QContextMenuEvent *event) |
| 47 | { |
| 48 | DTreeView::contextMenuEvent(event); |
| 49 | BreakpointModel *bpModel = static_cast<BreakpointModel *>(model()); |
| 50 | if (bpModel->breakpointSize() == 0) |
| 51 | return; |
| 52 | |
| 53 | bool allSelectEnabled = true; |
| 54 | bool allSelectDisabled = true; |
| 55 | //selectedRows |
| 56 | auto rows = selectionModel()->selectedRows(); |
| 57 | for (auto row : rows) { |
| 58 | auto bp = bpModel->BreakpointAt(row.row()); |
| 59 | if (bp.enabled) |
| 60 | allSelectDisabled = false; |
| 61 | else |
| 62 | allSelectEnabled = false; |
| 63 | } |
| 64 | |
| 65 | //all rows |
| 66 | bool allEnabled = true; |
| 67 | bool allDisabled = true; |
| 68 | QModelIndexList allRows; |
| 69 | for (int index = 0; index < bpModel->breakpointSize(); index++) { |
| 70 | allRows.append(bpModel->index(index, 0)); |
| 71 | auto bp = bpModel->BreakpointAt(index); |
| 72 | if (bp.enabled) |
| 73 | allDisabled = false; |
| 74 | else |
| 75 | allEnabled = false; |
| 76 | } |
| 77 | |
| 78 | QMenu menu(this); |
| 79 | if (!allSelectEnabled) |
| 80 | menu.addAction(tr("Enable selected breakpoints"), this, [=]() { enableBreakpoints(rows); }); |
| 81 | if (!allSelectDisabled) |
| 82 | menu.addAction(tr("Disable selected breakpoints"), this, [=]() { disableBreakpoints(rows); }); |
| 83 | menu.addSeparator(); |
| 84 | |
| 85 | if (!rows.isEmpty()) |
| 86 | menu.addAction(tr("Remove selected breakpoints"), this, [=]() { removeBreakpoints(rows); }); |
| 87 | |
| 88 | menu.addAction(tr("Remove all breakpoints"), this, [=]() { removeBreakpoints(allRows); }); |
| 89 | menu.addSeparator(); |
| 90 | |
| 91 | if (!allEnabled) |
| 92 | menu.addAction(tr("Enable all breakpoints"), this, [=]() { enableBreakpoints(allRows); }); |
| 93 | if (!allDisabled) |
| 94 | menu.addAction(tr("Disable all breakpoints"), this, [=]() { disableBreakpoints(allRows); }); |
| 95 | |
| 96 | // select one item |
| 97 | if (rows.size() == 1) { |
| 98 | menu.addAction(tr("Edit Condition"), this, [=]() { editBreakpointCondition(rows.at(0)); }); |
| 99 | } |
| 100 | |
| 101 | menu.exec(event->globalPos()); |
| 102 | } |
| 103 | |