MCPcopy Create free account
hub / github.com/VCVRack/Rack / createContextMenu

Method createContextMenu

src/app/PortWidget.cpp:278–353  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

276
277
278void 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();

Callers

nothing calls this directly

Calls 15

createMenuFunction · 0.85
createMenuLabelFunction · 0.85
createMenuItemFunction · 0.85
translateFunction · 0.85
getKeyCommandNameFunction · 0.85
getFunction · 0.85
addChildMethod · 0.80
deleteTopCableActionMethod · 0.80
getPortInfoMethod · 0.80
fFunction · 0.50
getFullNameMethod · 0.45

Tested by

no test coverage detected