[gnome-notes/wip/igaldino/menu-popover] toolbar: Secondary menu popover change



commit 407d9c998094f6d7944346988449d5948f80df9c
Author: Isaque Galdino <igaldino gmail com>
Date:   Wed Oct 24 19:36:57 2018 -0300

    toolbar: Secondary menu popover change
    
    Change secondary popup menu to a popover menu and move related code from
    main-toolbar to window (window-base) source code.

 data/resources/main-toolbar.ui | 165 +++++++++++++++++++++++------------------
 src/bjb-main-toolbar.c         |  76 +------------------
 src/bjb-window-base.c          | 101 ++++++++++++++++++++++++-
 3 files changed, 193 insertions(+), 149 deletions(-)
---
diff --git a/data/resources/main-toolbar.ui b/data/resources/main-toolbar.ui
index 83512cb..09c3206 100644
--- a/data/resources/main-toolbar.ui
+++ b/data/resources/main-toolbar.ui
@@ -190,18 +190,14 @@
 
     <child>
       <object class="GtkMenuButton" id="menu_button">
-        <property name="visible">1</property>
-        <property name="direction">none</property>
-        <property name="tooltip-text" translatable="yes">More options…</property>
-        <property name="popup">menu</property>
-        <style>
-         <class name="image-button"/>
-        </style>
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="tooltip-text" translatable="yes">More options</property>
+        <property name="popover">menu</property>
         <child>
           <object class="GtkImage">
             <property name="visible">1</property>
             <property name="icon-name">view-more-symbolic</property>
-            <property name="icon-size">1</property>
           </object>
         </child>
       </object>
@@ -344,81 +340,104 @@
     </child>
   </object>
 
-  <object class="GtkMenu" id="menu">
-    <property name="visible">1</property>
-
+  <object class="GtkPopoverMenu" id="menu">
+    <property name="can_focus">False</property>
     <child>
-      <object class="GtkMenuItem" id="new_window_item">
-        <property name="visible">1</property>
-        <property name="label" translatable="yes">Open in New Window</property>
-        <signal name="activate" handler="on_detached_clicked_cb" swapped="yes"/>
-      </object>
-    </child>
+      <object class="GtkBox">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="margin">12</property>
+        <property name="orientation">vertical</property>
 
-    <child>
-      <object class="GtkSeparatorMenuItem">
-        <property name="visible" bind-source="new_window_item" bind-property="visible" bind-flags="default"/>
-      </object>
-    </child>
+        <child>
+          <object class="GtkModelButton" id="new_window_item">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="text" translatable="yes">Open in New Window</property>
+            <property name="action-name">win.detach-window</property>
+          </object>
+        </child>
 
-    <child>
-      <object class="GtkMenuItem" id="undo_item">
-        <property name="visible">1</property>
-        <property name="label" translatable="yes">Undo</property>
-        <signal name="activate" handler="on_undo_or_redo_cb" swapped="yes"/>
-      </object>
-    </child>
+        <child>
+          <object class="GtkSeparator">
+            <property name="margin-top">6</property>
+            <property name="margin-bottom">6</property>
+            <property name="visible" bind-source="new_window_item" bind-property="visible" 
bind-flags="default|sync-create"/>
+          </object>
+        </child>
 
-    <child>
-      <object class="GtkMenuItem" id="redo_item">
-        <property name="visible">1</property>
-        <property name="label" translatable="yes">Redo</property>
-        <signal name="activate" handler="on_undo_or_redo_cb" swapped="yes"/>
-      </object>
-    </child>
+        <child>
+          <object class="GtkModelButton" id="undo_item">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="text" translatable="yes">Undo</property>
+            <property name="action-name">win.undo</property>
+          </object>
+        </child>
 
-    <child>
-      <object class="GtkSeparatorMenuItem">
-        <property name="visible">1</property>
-      </object>
-    </child>
+        <child>
+          <object class="GtkModelButton" id="redo_item">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="text" translatable="yes">Redo</property>
+            <property name="action-name">win.redo</property>
+          </object>
+        </child>
 
-    <child>
-      <object class="GtkMenuItem" id="notebook_item">
-        <property name="visible">1</property>
-        <property name="label" translatable="yes">Notebooks</property>
-        <signal name="activate" handler="action_view_tags_callback" swapped="yes"/>
-      </object>
-    </child>
+        <child>
+          <object class="GtkSeparator">
+            <property name="margin-top">6</property>
+            <property name="margin-bottom">6</property>
+            <property name="visible">True</property>
+          </object>
+        </child>
 
-    <child>
-      <object class="GtkMenuItem" id="email_item">
-        <property name="visible">1</property>
-        <property name="label" translatable="yes">Email this Note</property>
-        <signal name="activate" handler="on_email_cb" swapped="yes"/>
-      </object>
-    </child>
+        <child>
+          <object class="GtkModelButton" id="notebook_item">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="text" translatable="yes">Notebooks</property>
+            <property name="action-name">win.view-notebooks</property>
+          </object>
+        </child>
 
-    <child>
-      <object class="GtkMenuItem" id="trash_item">
-        <property name="visible">1</property>
-        <property name="label" translatable="yes">Move to Trash</property>
-        <signal name="activate" handler="trash_item_callback" swapped="yes"/>
-      </object>
-    </child>
+        <child>
+          <object class="GtkModelButton" id="email_item">
+            <property name="visible">1</property>
+            <property name="can_focus">False</property>
+            <property name="text" translatable="yes">Email this Note</property>
+            <property name="action-name">win.email</property>
+          </object>
+        </child>
 
-    <child>
-      <object class="GtkSeparatorMenuItem">
-        <property name="visible">1</property>
-      </object>
-    </child>
+        <child>
+          <object class="GtkModelButton" id="trash_item">
+            <property name="visible">1</property>
+            <property name="can_focus">False</property>
+            <property name="text" translatable="yes">Move to Trash</property>
+            <property name="action-name">win.trash</property>
+          </object>
+        </child>
+
+        <child>
+          <object class="GtkSeparator">
+            <property name="margin-top">6</property>
+            <property name="margin-bottom">6</property>
+            <property name="visible">True</property>
+          </object>
+        </child>
+
+        <child>
+          <object class="GtkLabel" id="last_update_item">
+            <property name="visible">True</property>
+            <property name="sensitive">False</property>
+            <property name="margin-left">6</property>
+            <property name="xalign">0</property>
+          </object>
+        </child>
 
-    <child>
-      <object class="GtkMenuItem" id="last_update_item">
-        <property name="visible">1</property>
-        <property name="sensitive">0</property>
       </object>
     </child>
-
   </object>
-</interface>
+
+</interface>
\ No newline at end of file
diff --git a/src/bjb-main-toolbar.c b/src/bjb-main-toolbar.c
index 1da5a97..7836a81 100644
--- a/src/bjb-main-toolbar.c
+++ b/src/bjb-main-toolbar.c
@@ -428,74 +428,7 @@ on_last_updated_cb (BijiItem       *note,
    */
   label = g_strdup_printf (_("Last updated %s"),
                            biji_note_obj_get_last_change_date_string (self->note));
-  gtk_menu_item_set_label (GTK_MENU_ITEM (self->last_update_item), label);
-}
-
-static void
-action_view_tags_callback (BjbMainToolbar *self)
-{
-  GList *list = NULL;
-
-  g_assert (BJB_IS_MAIN_TOOLBAR (self));
-
-  list = g_list_append (list, self->note);
-  bjb_organize_dialog_new (self->window, list);
-  g_list_free (list);
-}
-
-static void
-trash_item_callback (BjbMainToolbar *self)
-{
-  g_assert (BJB_IS_MAIN_TOOLBAR (self));
-
-  if (!self->note)
-    return;
-
-  /* Delete the note from notebook
-   * The deleted note will emit a signal. */
-  biji_item_trash (BIJI_ITEM (self->note));
-}
-
-static void
-on_undo_or_redo_cb (BjbMainToolbar *self,
-                    GtkWidget      *menu_item)
-{
-  BijiWebkitEditor *editor;
-
-  g_assert (BJB_IS_MAIN_TOOLBAR (self));
-  g_assert (GTK_IS_MENU_ITEM (menu_item));
-
-  if (!self->note)
-    return;
-
-  editor = BIJI_WEBKIT_EDITOR (biji_note_obj_get_editor (self->note));
-
-  if (menu_item == self->undo_item)
-    biji_webkit_editor_undo (editor);
-  else
-    biji_webkit_editor_redo (editor);
-}
-
-static void
-on_detached_clicked_cb (BjbMainToolbar *self)
-{
-  BijiNoteObj *note;
-
-  g_assert (BJB_IS_MAIN_TOOLBAR (self));
-
-  note = bjb_window_base_get_note (BJB_WINDOW_BASE (self->window));
-  bjb_window_base_switch_to (BJB_WINDOW_BASE (self->window),
-                             BJB_WINDOW_BASE_MAIN_VIEW);
-  bijiben_new_window_for_note (g_application_get_default (), note);
-}
-
-static void
-on_email_cb (BjbMainToolbar *self,
-             GtkWidget      *menu_item)
-{
-  g_return_if_fail (self->note);
-
-  on_email_note_callback (self->note);
+  gtk_label_set_text (GTK_LABEL (self->last_update_item), label);
 }
 
 static void
@@ -870,13 +803,6 @@ bjb_main_toolbar_class_init (BjbMainToolbarClass *klass)
   gtk_widget_class_bind_template_callback (widget_class, on_view_mode_clicked);
   gtk_widget_class_bind_template_callback (widget_class, on_empty_clicked_callback);
   gtk_widget_class_bind_template_callback (widget_class, on_color_button_clicked);
-
-  /* Menu items */
-  gtk_widget_class_bind_template_callback (widget_class, on_detached_clicked_cb);
-  gtk_widget_class_bind_template_callback (widget_class, on_undo_or_redo_cb);
-  gtk_widget_class_bind_template_callback (widget_class, action_view_tags_callback);
-  gtk_widget_class_bind_template_callback (widget_class, trash_item_callback);
-  gtk_widget_class_bind_template_callback (widget_class, on_email_cb);
 }
 
 BjbMainToolbar *
diff --git a/src/bjb-window-base.c b/src/bjb-window-base.c
index cf0f43e..6de4f83 100644
--- a/src/bjb-window-base.c
+++ b/src/bjb-window-base.c
@@ -12,7 +12,8 @@
 #include "bjb-main-toolbar.h"
 #include "bjb-main-view.h"
 #include "bjb-note-view.h"
-
+#include "bjb-organize-dialog.h"
+#include "bjb-share.h"
 
 #define BIJIBEN_MAIN_WIN_TITLE N_("Notes")
 #define SAVE_GEOMETRY_ID_TIMEOUT 100 /* ms */
@@ -191,6 +192,91 @@ on_key_pressed_cb (GtkWidget *w, GdkEvent *event, gpointer user_data)
   return FALSE;
 }
 
+static void
+on_detach_window_cb (GSimpleAction *action,
+                     GVariant      *parameter,
+                     gpointer       user_data)
+{
+  BjbWindowBase *self = BJB_WINDOW_BASE (user_data);
+  BijiNoteObj   *note = bjb_window_base_get_note (self);
+
+  if (!note)
+    return;
+
+  bjb_window_base_switch_to (self, BJB_WINDOW_BASE_MAIN_VIEW);
+  bijiben_new_window_for_note (g_application_get_default (), note);
+}
+
+static void
+on_undo_cb (GSimpleAction *action,
+            GVariant      *parameter,
+            gpointer       user_data)
+{
+  BijiNoteObj *note = bjb_window_base_get_note (BJB_WINDOW_BASE (user_data));
+
+  if (!note)
+    return;
+
+  biji_webkit_editor_undo (BIJI_WEBKIT_EDITOR (biji_note_obj_get_editor (note)));
+}
+
+static void
+on_redo_cb (GSimpleAction *action,
+            GVariant      *parameter,
+            gpointer       user_data)
+{
+  BijiNoteObj *note = bjb_window_base_get_note (BJB_WINDOW_BASE (user_data));
+
+  if (!note)
+    return;
+
+  biji_webkit_editor_redo (BIJI_WEBKIT_EDITOR (biji_note_obj_get_editor (note)));
+}
+
+static void
+on_view_notebooks_cb (GSimpleAction *action,
+                      GVariant      *parameter,
+                      gpointer       user_data)
+{
+  BjbWindowBase *self = BJB_WINDOW_BASE (user_data);
+  BijiNoteObj *note = bjb_window_base_get_note (self);
+  g_autoptr (GList) list = NULL;
+
+  if (!note)
+    return;
+
+  list = g_list_append (list, note);
+  bjb_organize_dialog_new (GTK_WINDOW (self), list);
+}
+
+static void
+on_email_cb (GSimpleAction *action,
+             GVariant      *parameter,
+             gpointer       user_data)
+{
+  BijiNoteObj *note = bjb_window_base_get_note (BJB_WINDOW_BASE (user_data));
+
+  if (!note)
+    return;
+
+  on_email_note_callback (note);
+}
+
+static void
+on_trash_cb (GSimpleAction *action,
+             GVariant      *parameter,
+             gpointer       user_data)
+{
+  BijiNoteObj *note = bjb_window_base_get_note (BJB_WINDOW_BASE (user_data));
+
+  if (!note)
+    return;
+
+  /* Delete the note from notebook
+   * The deleted note will emit a signal. */
+  biji_item_trash (BIJI_ITEM (note));
+}
+
 static void
 bjb_window_base_save_geometry (BjbWindowBase *self)
 {
@@ -240,6 +326,14 @@ bjb_window_base_configure_event (GtkWidget         *widget,
                                                                            event);
 }
 
+static GActionEntry win_entries[] = {
+  { "detach-window", on_detach_window_cb, NULL, NULL, NULL },
+  { "undo", on_undo_cb, NULL, NULL, NULL },
+  { "redo", on_redo_cb, NULL, NULL, NULL },
+  { "view-notebooks", on_view_notebooks_cb, NULL, NULL, NULL },
+  { "email", on_email_cb, NULL, NULL, NULL },
+  { "trash", on_trash_cb, NULL, NULL, NULL },
+};
 
 /* Gobj */
 static void
@@ -249,6 +343,11 @@ bjb_window_base_constructed (GObject *obj)
 
   G_OBJECT_CLASS (bjb_window_base_parent_class)->constructed (obj);
 
+  g_action_map_add_action_entries (G_ACTION_MAP (self),
+                                   win_entries,
+                                   G_N_ELEMENTS (win_entries),
+                                   self);
+
   self->settings = bjb_app_get_settings ((gpointer) g_application_get_default ());
 
   gtk_window_set_position (GTK_WINDOW (self),GTK_WIN_POS_CENTER);


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