| 276 | |
| 277 | |
| 278 | void PortWidget::createContextMenu() { |
| 279 | ui::Menu* menu = createMenu(); |
| 280 | WeakPtr<PortWidget> weakThis = this; |
| 281 | |
| 282 | engine::PortInfo* portInfo = getPortInfo(); |
| 283 | assert(portInfo); |
| 284 | menu->addChild(createMenuLabel(portInfo->getFullName())); |
| 285 | |
| 286 | std::vector<CableWidget*> cws = APP->scene->rack->getCompleteCablesOnPort(this); |
| 287 | CableWidget* topCw = cws.empty() ? NULL : cws.back(); |
| 288 | |
| 289 | menu->addChild(createMenuItem(string::translate("PortWidget.deleteTopCable"), widget::getKeyCommandName(0, RACK_MOD_SHIFT) + string::translate("key.click"), |
| 290 | [=]() { |
| 291 | if (!weakThis) |
| 292 | return; |
| 293 | weakThis->deleteTopCableAction(); |
| 294 | }, |
| 295 | !topCw |
| 296 | )); |
| 297 | |
| 298 | { |
| 299 | PortCloneCableItem* item = createMenuItem<PortCloneCableItem>(string::translate("PortWidget.cloneTopCable"), widget::getKeyCommandName(0, RACK_MOD_CTRL | RACK_MOD_SHIFT) + string::translate("key.drag")); |
| 300 | item->disabled = !topCw; |
| 301 | item->pw = this; |
| 302 | item->cw = topCw; |
| 303 | menu->addChild(item); |
| 304 | } |
| 305 | |
| 306 | { |
| 307 | PortCreateCableItem* item = createMenuItem<PortCreateCableItem>(string::translate("PortWidget.createCableTop"), widget::getKeyCommandName(0, RACK_MOD_CTRL) + string::translate("key.drag")); |
| 308 | item->pw = this; |
| 309 | menu->addChild(item); |
| 310 | } |
| 311 | |
| 312 | menu->addChild(new ui::MenuSeparator); |
| 313 | |
| 314 | // New cable items |
| 315 | for (size_t colorId = 0; colorId < settings::cableColors.size(); colorId++) { |
| 316 | NVGcolor color = settings::cableColors[colorId]; |
| 317 | std::string label = get(settings::cableLabels, colorId); |
| 318 | if (label == "") |
| 319 | label = string::f("#%lld", (long long) (colorId + 1)); |
| 320 | PortCreateCableColorItem* item = createMenuItem<PortCreateCableColorItem>(string::translate("PortWidget.createCable") + label); |
| 321 | item->pw = this; |
| 322 | item->color = color; |
| 323 | item->colorId = colorId; |
| 324 | menu->addChild(item); |
| 325 | } |
| 326 | |
| 327 | if (!cws.empty()) { |
| 328 | menu->addChild(new ui::MenuSeparator); |
| 329 | menu->addChild(createMenuLabel(string::translate("key.clickDrag") + string::translate("PortWidget.grabCable"))); |
| 330 | |
| 331 | // Cable items |
| 332 | for (auto it = cws.rbegin(); it != cws.rend(); it++) { |
| 333 | CableWidget* cw = *it; |
| 334 | PortWidget* pw = (type == engine::Port::INPUT) ? cw->outputPort : cw->inputPort; |
| 335 | engine::PortInfo* portInfo = pw->getPortInfo(); |
nothing calls this directly
no test coverage detected