[niepce] Issue #34 - Added context menu to gridview



commit 0bdb5ef62a823fa535aad726a0c9a654f9d8fc04
Author: Hubert Figuière <hub figuiere net>
Date:   Fri Dec 27 21:58:17 2019 -0500

    Issue #34 - Added context menu to gridview

 src/niepce/ui/gridviewmodule.cpp | 24 +++++++++++++++---------
 src/niepce/ui/gridviewmodule.hpp | 10 +++-------
 src/niepce/ui/imoduleshell.hpp   |  9 ++++-----
 src/niepce/ui/moduleshell.hpp    |  2 +-
 4 files changed, 23 insertions(+), 22 deletions(-)
---
diff --git a/src/niepce/ui/gridviewmodule.cpp b/src/niepce/ui/gridviewmodule.cpp
index 353ff83..b14e58d 100644
--- a/src/niepce/ui/gridviewmodule.cpp
+++ b/src/niepce/ui/gridviewmodule.cpp
@@ -1,7 +1,7 @@
 /*
  * niepce - ui/gridviewmodule.cpp
  *
- * Copyright (C) 2009-2018 Hubert Figuiere
+ * Copyright (C) 2009-2019 Hubert Figuière
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -36,7 +36,6 @@
 
 namespace ui {
 
-
 GridViewModule::GridViewModule(const IModuleShell & shell,
                                const Glib::RefPtr<ImageListStore> & store)
   : m_shell(shell)
@@ -44,6 +43,7 @@ GridViewModule::GridViewModule(const IModuleShell & shell,
   , m_librarylistview(nullptr)
   , m_lib_splitview(Gtk::ORIENTATION_HORIZONTAL)
   , m_dock(nullptr)
+  , m_context_menu(nullptr)
 {
 }
 
@@ -82,13 +82,11 @@ GridViewModule::on_lib_notification(const eng::LibNotification &ln)
     }
 }
 
-
 void GridViewModule::display_none()
 {
     m_metapanecontroller->display(0, nullptr);
 }
 
-
 Gtk::Widget * GridViewModule::buildWidget()
 {
   if(m_widget) {
@@ -102,6 +100,10 @@ Gtk::Widget * GridViewModule::buildWidget()
   m_librarylistview->property_spacing() = 0;
   m_librarylistview->property_margin() = 0;
 
+  auto shell_menu = m_shell.getMenu();
+  m_context_menu = Gtk::manage(new Gtk::Menu(shell_menu));
+  m_context_menu->attach_to_widget(*m_librarylistview);
+
   m_librarylistview->signal_button_press_event()
       .connect(sigc::mem_fun(*this,  &GridViewModule::on_librarylistview_click));
 
@@ -145,7 +147,6 @@ Gtk::Widget * GridViewModule::buildWidget()
   return m_widget;
 }
 
-
 void GridViewModule::dispatch_action(const std::string & /*action_name*/)
 {
 }
@@ -154,7 +155,6 @@ void GridViewModule::set_active(bool /*active*/)
 {
 }
 
-
 Gtk::IconView * GridViewModule::image_list()
 {
     return m_librarylistview;
@@ -195,7 +195,6 @@ void GridViewModule::select_image(eng::library_id_t id)
     }
 }
 
-
 void GridViewModule::on_metadata_changed(const fwk::PropertyBagPtr & props,
                                          const fwk::PropertyBagPtr & old)
 {
@@ -211,6 +210,14 @@ void GridViewModule::on_rating_changed(int /*id*/, int rating)
 
 bool GridViewModule::on_librarylistview_click(GdkEventButton *e)
 {
+    guint button = 0;
+    GdkEvent* event = (GdkEvent*)e;
+    if (gdk_event_get_button(event, &button)) {
+        if (button == 3) {
+            m_context_menu->popup_at_pointer(event);
+            return false;
+        }
+    }
     double x, y;
     int bx, by;
     bx = by = 0;
@@ -220,7 +227,7 @@ bool GridViewModule::on_librarylistview_click(GdkEventButton *e)
     Gtk::CellRenderer * renderer = nullptr;
     DBG_OUT("click (%f, %f)", x, y);
     m_librarylistview->convert_widget_to_bin_window_coords(x, y, bx, by);
-    if(m_librarylistview->get_item_at_pos(bx, by, path, renderer)){
+    if (m_librarylistview->get_item_at_pos(bx, by, path, renderer)){
         DBG_OUT("found an item");
 
         return true;
@@ -228,7 +235,6 @@ bool GridViewModule::on_librarylistview_click(GdkEventButton *e)
     return false;
 }
 
-
 }
 /*
   Local Variables:
diff --git a/src/niepce/ui/gridviewmodule.hpp b/src/niepce/ui/gridviewmodule.hpp
index 9948ebe..2bd5c46 100644
--- a/src/niepce/ui/gridviewmodule.hpp
+++ b/src/niepce/ui/gridviewmodule.hpp
@@ -1,7 +1,7 @@
 /*
  * niepce - ui/gridviewmodule.hpp
  *
- * Copyright (C) 2009-2014 Hubert Figuiere
+ * Copyright (C) 2009-2019 Hubert Figuière
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -17,10 +17,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-
-
-#ifndef __UI_GRIDVIEWMODULE_HPP_
-#define __UI_GRIDVIEWMODULE_HPP_
+#pragma once
 
 #include <gtkmm/iconview.h>
 #include <gtkmm/scrolledwindow.h>
@@ -90,8 +87,7 @@ private:
   MetaDataPaneController::Ptr  m_metapanecontroller;
   Gtk::Paned                   m_lib_splitview;
   fwk::Dock                   *m_dock;
+  Gtk::Menu* m_context_menu;
 };
 
-
 }
-#endif
diff --git a/src/niepce/ui/imoduleshell.hpp b/src/niepce/ui/imoduleshell.hpp
index cf72289..75aa876 100644
--- a/src/niepce/ui/imoduleshell.hpp
+++ b/src/niepce/ui/imoduleshell.hpp
@@ -1,7 +1,7 @@
 /*
  * niepce - ui/imoduleshell.hpp
  *
- * Copyright (C) 2011-2017 Hubert Figuiere
+ * Copyright (C) 2011-2019 Hubert Figuière
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -17,11 +17,10 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-
-#ifndef _UI_IMODULESHELL_HPP__
-#define _UI_IMODULESHELL_HPP__
+#pragma once
 
 #include <memory>
+#include <giomm/menu.h>
 #include "niepce/ui/selectioncontroller.hpp"
 
 namespace libraryclient {
@@ -37,11 +36,11 @@ public:
     virtual const ui::SelectionController::Ptr & get_selection_controller() const = 0;
     virtual libraryclient::LibraryClientPtr getLibraryClient() const = 0;
     virtual const std::unique_ptr<libraryclient::UIDataProvider>& get_ui_data_provider() const = 0;
+    virtual Glib::RefPtr<Gio::Menu> getMenu() const = 0;
 };
 
 }
 
-#endif
 /*
   Local Variables:
   mode:c++
diff --git a/src/niepce/ui/moduleshell.hpp b/src/niepce/ui/moduleshell.hpp
index 36e76c6..e8e73ab 100644
--- a/src/niepce/ui/moduleshell.hpp
+++ b/src/niepce/ui/moduleshell.hpp
@@ -80,7 +80,7 @@ public:
         {
             return m_libraryclient->getDataProvider();
         }
-    Glib::RefPtr<Gio::Menu> getMenu() const
+    virtual Glib::RefPtr<Gio::Menu> getMenu() const override
         { return m_menu; }
 
     /** called when the content will change


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]