[niepce/gtk4] gtk4: Fix context menus
- From: Hubert Figuière <hub src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [niepce/gtk4] gtk4: Fix context menus
- Date: Mon, 18 Apr 2022 19:23:42 +0000 (UTC)
commit 8d7d7f830e2c1111cb57a006c9ac71099033cb73
Author: Hubert Figuière <hub figuiere net>
Date: Mon Apr 18 15:23:24 2022 -0400
gtk4: Fix context menus
src/niepce/ui/gridviewmodule.cpp | 8 +++++++-
src/niepce/ui/workspacecontroller.cpp | 16 ++++++++++------
src/niepce/ui/workspacecontroller.hpp | 1 +
3 files changed, 18 insertions(+), 7 deletions(-)
---
diff --git a/src/niepce/ui/gridviewmodule.cpp b/src/niepce/ui/gridviewmodule.cpp
index a66f76e..dc94e93 100644
--- a/src/niepce/ui/gridviewmodule.cpp
+++ b/src/niepce/ui/gridviewmodule.cpp
@@ -134,6 +134,11 @@ Gtk::Widget * GridViewModule::buildWidget()
auto shell_menu = m_shell.getMenu();
m_context_menu = Gtk::manage(new Gtk::PopoverMenu(shell_menu));
+ m_context_menu->set_parent(*m_librarylistview);
+ m_librarylistview->signal_unrealize().connect([this] {
+ m_context_menu->unparent();
+ });
+
auto gesture = Gtk::GestureClick::create();
m_librarylistview->add_controller(gesture);
@@ -242,6 +247,7 @@ void GridViewModule::on_rating_changed(GtkCellRenderer*, eng::library_id_t /*id*
void GridViewModule::on_librarylistview_click(const Glib::RefPtr<Gtk::GestureClick>& gesture, double x,
double y)
{
auto button = gesture->get_current_button();
+ DBG_OUT("GridView click handler, button: %u", button);
if (button == 3 && !m_librarylistview->get_selected_items().empty()) {
m_context_menu->set_pointing_to(Gdk::Rectangle(x, y, 1, 1));
m_context_menu->popup();
@@ -250,7 +256,7 @@ void GridViewModule::on_librarylistview_click(const Glib::RefPtr<Gtk::GestureCli
}
Gtk::TreeModel::Path path;
Gtk::CellRenderer * renderer = nullptr;
- DBG_OUT("click (%f, %f)", x, y);
+ DBG_OUT("GridView click (%f, %f)", x, y);
if (m_librarylistview->get_item_at_pos(x, y, path, renderer)){
DBG_OUT("found an item");
}
diff --git a/src/niepce/ui/workspacecontroller.cpp b/src/niepce/ui/workspacecontroller.cpp
index 0b05030..741ea28 100644
--- a/src/niepce/ui/workspacecontroller.cpp
+++ b/src/niepce/ui/workspacecontroller.cpp
@@ -431,10 +431,10 @@ Gtk::Widget * WorkspaceController::buildWidget()
add_btn->set_direction(Gtk::ArrowType::NONE);
add_btn->set_icon_name("view-more-symbolic");
- auto menu = Gio::Menu::create();
+ m_menu = Gio::Menu::create();
auto section = Gio::Menu::create();
- menu->append_section(section);
+ m_menu->append_section(section);
fwk::add_menu_action(m_action_group.get(), "NewFolder",
sigc::mem_fun(*this,
&WorkspaceController::action_new_folder),
@@ -449,14 +449,20 @@ Gtk::Widget * WorkspaceController::buildWidget()
action->set_enabled(false);
section = Gio::Menu::create();
- menu->append_section(section);
+ m_menu->append_section(section);
fwk::add_menu_action(m_action_group.get(), "Import",
sigc::mem_fun(*this,
&WorkspaceController::action_file_import),
section, _("_Import..."), "workspace");
- add_btn->set_menu_model(menu);
+ add_btn->set_menu_model(m_menu);
+
+ m_context_menu = Gtk::manage(new Gtk::PopoverMenu(m_menu));
+ m_context_menu->set_parent(m_librarytree);
+ m_librarytree.signal_unrealize().connect([this] {
+ m_context_menu->unparent();
+ });
header->append(*add_btn);
m_vbox.append(*header);
@@ -465,8 +471,6 @@ Gtk::Widget * WorkspaceController::buildWidget()
m_librarytree.set_vexpand(true);
scrolled->set_child(m_librarytree);
- m_context_menu = Gtk::manage(new Gtk::PopoverMenu(menu));
-
m_librarytree.get_selection()->signal_changed().connect([this] {
this->on_libtree_selection();
});
diff --git a/src/niepce/ui/workspacecontroller.hpp b/src/niepce/ui/workspacecontroller.hpp
index d3349cf..a578442 100644
--- a/src/niepce/ui/workspacecontroller.hpp
+++ b/src/niepce/ui/workspacecontroller.hpp
@@ -143,6 +143,7 @@ private:
Gtk::Box m_vbox;
Gtk::Label m_label;
Gtk::TreeView m_librarytree;
+ Glib::RefPtr<Gio::Menu> m_menu;
Gtk::PopoverMenu* m_context_menu;
Gtk::TreeModel::iterator m_folderNode; /**< the folder node */
Gtk::TreeModel::iterator m_projectNode; /**< the project node */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]