From 3e004928e72dcf0913d35cde945bad89e50044c0 Mon Sep 17 00:00:00 2001 From: gvnnz Date: Fri, 11 Oct 2024 19:44:52 +0200 Subject: [PATCH] Show 'Add track' menu when right-cliking on empty area on main Keyboard --- .../elems/mainWindow/keyboard/keyboard.cpp | 48 +++++++++++++++++-- src/gui/elems/mainWindow/keyboard/keyboard.h | 14 ++++-- 2 files changed, 53 insertions(+), 9 deletions(-) diff --git a/src/gui/elems/mainWindow/keyboard/keyboard.cpp b/src/gui/elems/mainWindow/keyboard/keyboard.cpp index 88ed00bc3..d857b66bc 100644 --- a/src/gui/elems/mainWindow/keyboard/keyboard.cpp +++ b/src/gui/elems/mainWindow/keyboard/keyboard.cpp @@ -32,6 +32,7 @@ #include "gui/drawing.h" #include "gui/elems/basics/boxtypes.h" #include "gui/elems/basics/dial.h" +#include "gui/elems/basics/menu.h" #include "gui/elems/basics/resizerBar.h" #include "gui/elems/basics/textButton.h" #include "gui/elems/mainWindow/keyboard/channelButton.h" @@ -51,6 +52,18 @@ extern giada::v::Ui* g_ui; namespace giada::v { +namespace +{ +enum class Menu +{ + ADD_TRACK = 0 +}; +} // namespace + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + geKeyboard::ChannelDragger::ChannelDragger(geKeyboard& k) : m_keyboard(k) , m_channelId(-1) @@ -187,6 +200,27 @@ size_t geKeyboard::countTracks() const /* -------------------------------------------------------------------------- */ +void geKeyboard::showMenu() const +{ + geMenu menu; + + menu.addItem((ID)Menu::ADD_TRACK, g_ui->getI18Text(LangMap::MAIN_TRACK_BUTTON_ADD_TRACK)); + + menu.onSelect = [this](ID menuId) + { + switch (static_cast(menuId)) + { + case Menu::ADD_TRACK: + addTrack(); + break; + } + }; + + menu.popup(); +} + +/* -------------------------------------------------------------------------- */ + void geKeyboard::init() { deleteAllTracks(); @@ -260,7 +294,7 @@ int geKeyboard::handle(int e) } if (Fl::event_button3()) { - openTrackMenu(); + openMenu(); return 1; } @@ -355,7 +389,7 @@ geompp::Rect geKeyboard::getTrackBackround(const geTrack& c) const /* -------------------------------------------------------------------------- */ -void geKeyboard::addTrack() +void geKeyboard::addTrack() const { c::channel::addTrack(); } @@ -455,11 +489,15 @@ std::vector geKeyboard::getDroppedFilePaths() const /* -------------------------------------------------------------------------- */ -void geKeyboard::openTrackMenu() const +void geKeyboard::openMenu() const { const geTrack* track = getTrackAtCursor(Fl::event_x()); - if (track == nullptr || track->getChannelAtCursor(Fl::event_y()) != nullptr) + if (track == nullptr) // No track hovered: show Keyboard menu + { + showMenu(); return; - track->showMenu(); + } + if (track->getChannelAtCursor(Fl::event_y()) == nullptr) // No channel hovered: show track menu + track->showMenu(); } } // namespace giada::v diff --git a/src/gui/elems/mainWindow/keyboard/keyboard.h b/src/gui/elems/mainWindow/keyboard/keyboard.h index ddeaa0a7b..8eac4f3e4 100644 --- a/src/gui/elems/mainWindow/keyboard/keyboard.h +++ b/src/gui/elems/mainWindow/keyboard/keyboard.h @@ -66,6 +66,11 @@ class geKeyboard : public geScroll size_t countTracks() const; + /* showMenu + Displays the menu for adding/removing tracks. */ + + void showMenu() const; + /* rebuild Rebuilds this widget from scratch. Used when the model has changed. */ @@ -79,7 +84,7 @@ class geKeyboard : public geScroll /* addTrack Adds new track at the end of the stack. */ - void addTrack(); + void addTrack() const; /* deleteTrack Deletes track by index. */ @@ -141,10 +146,11 @@ class geKeyboard : public geScroll std::vector getDroppedFilePaths() const; - /* openTrackMenu - Opens the 'add/remove channel' menu for the track under the cursor. */ + /* openMenu + Opens the Track menu for the track under the cursor, or the generic one if + no tracks hovered. */ - void openTrackMenu() const; + void openMenu() const; /* getTrackAtCursor Returns the track below the cursor. */