Add context menu to Section Arranger

This commit is contained in:
Robin Gareus 2023-08-27 15:20:54 +02:00
parent c199e9a99d
commit 1f6db3a865
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
2 changed files with 64 additions and 23 deletions

View File

@ -24,6 +24,7 @@
#include "gtkmm2ext/keyboard.h"
#include "ardour_ui.h"
#include "context_menu_helper.h"
#include "editor_sections.h"
#include "gui_thread.h"
#include "keyboard.h"
@ -54,6 +55,7 @@ EditorSections::EditorSections ()
_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
_view.signal_key_release_event ().connect (sigc::mem_fun (*this, &EditorSections::key_release), false);
_view.signal_button_press_event ().connect (sigc::mem_fun (*this, &EditorSections::button_press), false);
_view.get_selection ()->signal_changed ().connect (sigc::mem_fun (*this, &EditorSections::selection_changed));
/* DnD source */
@ -340,23 +342,12 @@ EditorSections::drag_data_received (Glib::RefPtr<Gdk::DragContext> const& contex
}
bool
EditorSections::key_release (GdkEventKey* ev)
EditorSections::delete_selected_section ()
{
if (_view.get_selection ()->count_selected_rows () != 1) {
return false;
}
switch (ev->keyval) {
case GDK_KP_Delete:
/* fallthrough */
case GDK_Delete:
/* fallthrough */
case GDK_BackSpace:
break;
default:
return false;
}
TreeView::Selection::ListHandle_Path rows = _view.get_selection ()->get_selected_rows ();
Gtk::TreeModel::Row row = *_model->get_iter (*rows.begin ());
@ -370,6 +361,52 @@ EditorSections::key_release (GdkEventKey* ev)
return true;
}
bool
EditorSections::key_release (GdkEventKey* ev)
{
switch (ev->keyval) {
case GDK_KP_Delete:
/* fallthrough */
case GDK_Delete:
/* fallthrough */
case GDK_BackSpace:
break;
default:
return false;
}
return delete_selected_section ();
}
void
EditorSections::show_context_menu (int button, int time)
{
using namespace Gtk::Menu_Helpers;
Gtk::Menu* menu = ARDOUR_UI_UTILS::shared_popup_menu ();
MenuList& items = menu->items ();
items.push_back (MenuElem (_("Remove the selected Section"), hide_return (sigc::mem_fun (*this, &EditorSections::delete_selected_section))));
menu->popup (button, time);
}
bool
EditorSections::button_press (GdkEventButton* ev)
{
TreeModel::Path path;
TreeViewColumn* column;
int cellx;
int celly;
if (!_view.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
return false;
}
if (Gtkmm2ext::Keyboard::is_context_menu_event (ev)) {
show_context_menu (ev->button, ev->time);
/* return false to select item under the mouse */
}
return false;
}
bool
EditorSections::focus_in (GdkEventFocus*)
{

View File

@ -39,23 +39,27 @@ public:
return _scroller;
}
void redisplay ();
private:
void redisplay ();
bool delete_selected_section ();
void selection_changed ();
void clock_format_changed ();
bool scroll_row_timeout ();
void show_context_menu (int, int);
bool key_release (GdkEventKey*);
bool button_press (GdkEventButton*);
bool focus_in (GdkEventFocus*);
bool focus_out (GdkEventFocus*);
bool enter_notify (GdkEventCrossing*);
bool leave_notify (GdkEventCrossing*);
void drag_data_get (Glib::RefPtr<Gdk::DragContext> const&, Gtk::SelectionData&, guint, guint);
void drag_begin (Glib::RefPtr<Gdk::DragContext> const&);
bool drag_motion (Glib::RefPtr<Gdk::DragContext> const&, int, int, guint);
void drag_data_received (Glib::RefPtr<Gdk::DragContext> const&, int, int, Gtk::SelectionData const&, guint, guint);
void drag_leave (Glib::RefPtr<Gdk::DragContext> const&, guint);
bool key_release (GdkEventKey*);
void selection_changed ();
bool scroll_row_timeout ();
void clock_format_changed ();
bool focus_in (GdkEventFocus*);
bool focus_out (GdkEventFocus*);
bool enter_notify (GdkEventCrossing*);
bool leave_notify (GdkEventCrossing*);
struct Section {
Section ()