[gnote] Add ability to add and remove accelerators to GlobalKeybinder



commit e8be97f175af5de8a62c245b9500ecbbcc31eab4
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Sun Jan 17 15:15:18 2021 +0200

    Add ability to add and remove accelerators to GlobalKeybinder

 src/utils.cpp | 12 ++++++++++--
 src/utils.hpp |  6 +++---
 2 files changed, 13 insertions(+), 5 deletions(-)
---
diff --git a/src/utils.cpp b/src/utils.cpp
index 2b83dd72..b932fa14 100644
--- a/src/utils.cpp
+++ b/src/utils.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2010-2017,2019-2020 Aurimas Cernius
+ * Copyright (C) 2010-2017,2019-2021 Aurimas Cernius
  * Copyright (C) 2010 Debarshi Ray
  * Copyright (C) 2009 Hubert Figuiere
  *
@@ -282,7 +282,7 @@ namespace gnote {
     }
 
 
-    void GlobalKeybinder::add_accelerator(const sigc::slot<void> & handler, guint key, 
+    void* GlobalKeybinder::add_accelerator(const sigc::slot<void> & handler, guint key,
                                           Gdk::ModifierType modifiers, Gtk::AccelFlags flags)
     {
       Gtk::MenuItem *foo = manage(new Gtk::MenuItem ());
@@ -295,6 +295,14 @@ namespace gnote {
       foo->show ();
       foo->set_sensitive(m_fake_menu.get_sensitive());
       m_fake_menu.append (*foo);
+      return foo;
+    }
+
+    void GlobalKeybinder::remove_accelerator(void *accel)
+    {
+      auto widget = static_cast<Gtk::Widget*>(accel);
+      m_fake_menu.remove(*widget);
+      delete widget;
     }
 
     void GlobalKeybinder::enabled(bool enable)
diff --git a/src/utils.hpp b/src/utils.hpp
index cb685d8e..941b958d 100644
--- a/src/utils.hpp
+++ b/src/utils.hpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2011-2013,2015-2017,2019-2020 Aurimas Cernius
+ * Copyright (C) 2011-2013,2015-2017,2019-2021 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -86,8 +86,8 @@ class Preferences;
           m_fake_menu.set_accel_group(accel_group);
         }
 
-      void add_accelerator(const sigc::slot<void> & , guint, Gdk::ModifierType, 
-                           Gtk::AccelFlags);
+      void *add_accelerator(const sigc::slot<void> & , guint, Gdk::ModifierType, Gtk::AccelFlags);
+      void remove_accelerator(void*);
       void enabled(bool enable);
       bool enabled() const
         {


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