From 08e1f9a954a3bb0471971389fab293a928b76275 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Fri, 15 Oct 2021 00:50:27 -0400 Subject: [PATCH] Add port name and "Duplicate/create new cable" to port context menu. --- include/engine/PortInfo.hpp | 2 ++ src/app/PortWidget.cpp | 17 +++++++++++++---- src/engine/PortInfo.cpp | 9 +++++++++ 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/include/engine/PortInfo.hpp b/include/engine/PortInfo.hpp index e97a0d24..823e4f97 100644 --- a/include/engine/PortInfo.hpp +++ b/include/engine/PortInfo.hpp @@ -28,6 +28,8 @@ struct PortInfo { virtual ~PortInfo() {} virtual std::string getName(); + /** Returns name with "input" or "output" appended. */ + std::string getFullName(); virtual std::string getDescription(); }; diff --git a/src/app/PortWidget.cpp b/src/app/PortWidget.cpp index 4ec02bb6..08ec2e91 100644 --- a/src/app/PortWidget.cpp +++ b/src/app/PortWidget.cpp @@ -20,9 +20,7 @@ struct PortTooltip : ui::Tooltip { engine::Port* port = portWidget->getPort(); engine::PortInfo* portInfo = portWidget->getPortInfo(); // Label - text = portInfo->getName(); - text += " "; - text += (portWidget->type == engine::Port::INPUT) ? "input" : "output"; + text = portInfo->getFullName(); // Description std::string description = portInfo->getDescription(); if (description != "") { @@ -130,8 +128,11 @@ void PortWidget::createContextMenu() { ui::Menu* menu = createMenu(); WeakPtr weakThis = this; - CableWidget* cw = APP->scene->rack->getTopCable(this); + engine::PortInfo* portInfo = getPortInfo(); + assert(portInfo); + menu->addChild(createMenuLabel(portInfo->getFullName())); + CableWidget* cw = APP->scene->rack->getTopCable(this); menu->addChild(createMenuItem("Delete top cable", RACK_MOD_SHIFT_NAME "+click", [=]() { if (!weakThis) @@ -141,6 +142,14 @@ void PortWidget::createContextMenu() { !cw )); + // TODO + if (type == engine::Port::INPUT) { + menu->addChild(createMenuItem("Duplicate cable", RACK_MOD_CTRL_NAME "+drag", NULL, true)); + } + else { + menu->addChild(createMenuItem("Create new cable", RACK_MOD_CTRL_NAME "+drag", NULL, true)); + } + // TODO } diff --git a/src/engine/PortInfo.cpp b/src/engine/PortInfo.cpp index d3df05d5..3acdc5e8 100644 --- a/src/engine/PortInfo.cpp +++ b/src/engine/PortInfo.cpp @@ -12,6 +12,15 @@ std::string PortInfo::getName() { return name; } + +std::string PortInfo::getFullName() { + std::string name = getName(); + name += " "; + name += (type == Port::INPUT) ? "input" : "output"; + return name; +} + + std::string PortInfo::getDescription() { return description; }