Skip to content

Commit 3e00492

Browse files
committed
Show 'Add track' menu when right-cliking on empty area on main Keyboard
1 parent 544b9f5 commit 3e00492

File tree

2 files changed

+53
-9
lines changed

2 files changed

+53
-9
lines changed

src/gui/elems/mainWindow/keyboard/keyboard.cpp

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "gui/drawing.h"
3333
#include "gui/elems/basics/boxtypes.h"
3434
#include "gui/elems/basics/dial.h"
35+
#include "gui/elems/basics/menu.h"
3536
#include "gui/elems/basics/resizerBar.h"
3637
#include "gui/elems/basics/textButton.h"
3738
#include "gui/elems/mainWindow/keyboard/channelButton.h"
@@ -51,6 +52,18 @@ extern giada::v::Ui* g_ui;
5152

5253
namespace giada::v
5354
{
55+
namespace
56+
{
57+
enum class Menu
58+
{
59+
ADD_TRACK = 0
60+
};
61+
} // namespace
62+
63+
/* -------------------------------------------------------------------------- */
64+
/* -------------------------------------------------------------------------- */
65+
/* -------------------------------------------------------------------------- */
66+
5467
geKeyboard::ChannelDragger::ChannelDragger(geKeyboard& k)
5568
: m_keyboard(k)
5669
, m_channelId(-1)
@@ -187,6 +200,27 @@ size_t geKeyboard::countTracks() const
187200

188201
/* -------------------------------------------------------------------------- */
189202

203+
void geKeyboard::showMenu() const
204+
{
205+
geMenu menu;
206+
207+
menu.addItem((ID)Menu::ADD_TRACK, g_ui->getI18Text(LangMap::MAIN_TRACK_BUTTON_ADD_TRACK));
208+
209+
menu.onSelect = [this](ID menuId)
210+
{
211+
switch (static_cast<Menu>(menuId))
212+
{
213+
case Menu::ADD_TRACK:
214+
addTrack();
215+
break;
216+
}
217+
};
218+
219+
menu.popup();
220+
}
221+
222+
/* -------------------------------------------------------------------------- */
223+
190224
void geKeyboard::init()
191225
{
192226
deleteAllTracks();
@@ -260,7 +294,7 @@ int geKeyboard::handle(int e)
260294
}
261295
if (Fl::event_button3())
262296
{
263-
openTrackMenu();
297+
openMenu();
264298
return 1;
265299
}
266300

@@ -355,7 +389,7 @@ geompp::Rect<int> geKeyboard::getTrackBackround(const geTrack& c) const
355389

356390
/* -------------------------------------------------------------------------- */
357391

358-
void geKeyboard::addTrack()
392+
void geKeyboard::addTrack() const
359393
{
360394
c::channel::addTrack();
361395
}
@@ -455,11 +489,15 @@ std::vector<std::string> geKeyboard::getDroppedFilePaths() const
455489

456490
/* -------------------------------------------------------------------------- */
457491

458-
void geKeyboard::openTrackMenu() const
492+
void geKeyboard::openMenu() const
459493
{
460494
const geTrack* track = getTrackAtCursor(Fl::event_x());
461-
if (track == nullptr || track->getChannelAtCursor(Fl::event_y()) != nullptr)
495+
if (track == nullptr) // No track hovered: show Keyboard menu
496+
{
497+
showMenu();
462498
return;
463-
track->showMenu();
499+
}
500+
if (track->getChannelAtCursor(Fl::event_y()) == nullptr) // No channel hovered: show track menu
501+
track->showMenu();
464502
}
465503
} // namespace giada::v

src/gui/elems/mainWindow/keyboard/keyboard.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ class geKeyboard : public geScroll
6666

6767
size_t countTracks() const;
6868

69+
/* showMenu
70+
Displays the menu for adding/removing tracks. */
71+
72+
void showMenu() const;
73+
6974
/* rebuild
7075
Rebuilds this widget from scratch. Used when the model has changed. */
7176

@@ -79,7 +84,7 @@ class geKeyboard : public geScroll
7984
/* addTrack
8085
Adds new track at the end of the stack. */
8186

82-
void addTrack();
87+
void addTrack() const;
8388

8489
/* deleteTrack
8590
Deletes track by index. */
@@ -141,10 +146,11 @@ class geKeyboard : public geScroll
141146

142147
std::vector<std::string> getDroppedFilePaths() const;
143148

144-
/* openTrackMenu
145-
Opens the 'add/remove channel' menu for the track under the cursor. */
149+
/* openMenu
150+
Opens the Track menu for the track under the cursor, or the generic one if
151+
no tracks hovered. */
146152

147-
void openTrackMenu() const;
153+
void openMenu() const;
148154

149155
/* getTrackAtCursor
150156
Returns the track below the cursor. */

0 commit comments

Comments
 (0)