[gnome-text-editor] sidebarrow: move remove code to open popover



commit 16bd78e930dfebca4e45db0da14682c7547352eb
Author: Christian Hergert <chergert redhat com>
Date:   Wed Oct 27 16:14:15 2021 -0700

    sidebarrow: move remove code to open popover
    
    Previously we had the EditorSidebar we were keeping around in case we need
    to go back to it from the popover. Since we've pretty much moved on from
    that design now, we dropped that code in a previous commit.
    
    That means we can do a simpler design and implement removing rows as an
    action on the EditorOpenPopover which simplifies our action muxer quite
    a bit.
    
    Fixes #192

 src/editor-open-popover.c | 27 +++++++++++++++++++++++++++
 src/editor-sidebar-row.c  | 30 ++++++++++++------------------
 src/editor-sidebar-row.ui |  1 -
 3 files changed, 39 insertions(+), 19 deletions(-)
---
diff --git a/src/editor-open-popover.c b/src/editor-open-popover.c
index 167854d..26b2ad6 100644
--- a/src/editor-open-popover.c
+++ b/src/editor-open-popover.c
@@ -24,6 +24,7 @@
 
 #include "editor-application.h"
 #include "editor-open-popover-private.h"
+#include "editor-session-private.h"
 #include "editor-sidebar-item-private.h"
 #include "editor-sidebar-row-private.h"
 #include "editor-window.h"
@@ -236,6 +237,30 @@ editor_open_popover_show (GtkWidget *widget)
   GTK_WIDGET_CLASS (editor_open_popover_parent_class)->show (widget);
 }
 
+static void
+on_remove_row_cb (GtkWidget  *widget,
+                  const char *action_name,
+                  GVariant   *param)
+{
+  EditorOpenPopover *self = (EditorOpenPopover *)widget;
+  g_autoptr(GFile) file = NULL;
+  const char *uri;
+  const char *draft_id;
+
+  g_assert (EDITOR_IS_OPEN_POPOVER (self));
+  g_assert (g_variant_is_of_type (param, G_VARIANT_TYPE ("(ss)")));
+
+  g_variant_get (param, "(&s&s)", &uri, &draft_id);
+
+  if (uri[0] != 0)
+    file = g_file_new_for_uri (uri);
+
+  if (draft_id[0] == 0)
+    draft_id = NULL;
+
+  _editor_session_forget (EDITOR_SESSION_DEFAULT, file, draft_id);
+}
+
 static void
 editor_open_popover_dispose (GObject *object)
 {
@@ -319,6 +344,8 @@ editor_open_popover_class_init (EditorOpenPopoverClass *klass)
   gtk_widget_class_bind_template_callback (widget_class, on_search_entry_activate_cb);
   gtk_widget_class_bind_template_callback (widget_class, on_search_entry_changed_cb);
   gtk_widget_class_bind_template_callback (widget_class, on_search_entry_stop_search_cb);
+
+  gtk_widget_class_install_action (widget_class, "row.remove", "(ss)", on_remove_row_cb);
 }
 
 static void
diff --git a/src/editor-sidebar-row.c b/src/editor-sidebar-row.c
index d7a77f0..b2a0c6c 100644
--- a/src/editor-sidebar-row.c
+++ b/src/editor-sidebar-row.c
@@ -43,6 +43,7 @@ struct _EditorSidebarRow
   GtkLabel          *empty;
   GtkLabel          *age;
   GtkStack          *stack;
+  GtkButton         *remove;
 
   GBinding          *title_binding;
   GBinding          *subtitle_binding;
@@ -100,21 +101,6 @@ age_to_string (GBinding     *binding,
   return TRUE;
 }
 
-static void
-editor_sidebar_row_remove (GtkWidget   *widget,
-                           const gchar *action_name,
-                           GVariant    *param)
-{
-  EditorSidebarRow *self = (EditorSidebarRow *)widget;
-  EditorSession *session = EDITOR_SESSION_DEFAULT;
-
-  g_assert (EDITOR_IS_SIDEBAR_ROW (self));
-
-  _editor_session_forget (session,
-                          _editor_sidebar_item_get_file (self->item),
-                          _editor_sidebar_item_get_draft_id (self->item));
-}
-
 static void
 editor_sidebar_row_dispose (GObject *object)
 {
@@ -185,12 +171,11 @@ editor_sidebar_row_class_init (EditorSidebarRowClass *klass)
   gtk_widget_class_bind_template_child (widget_class, EditorSidebarRow, empty);
   gtk_widget_class_bind_template_child (widget_class, EditorSidebarRow, grid);
   gtk_widget_class_bind_template_child (widget_class, EditorSidebarRow, is_modified);
+  gtk_widget_class_bind_template_child (widget_class, EditorSidebarRow, remove);
   gtk_widget_class_bind_template_child (widget_class, EditorSidebarRow, stack);
   gtk_widget_class_bind_template_child (widget_class, EditorSidebarRow, subtitle);
   gtk_widget_class_bind_template_child (widget_class, EditorSidebarRow, title);
 
-  gtk_widget_class_install_action (widget_class, "row.remove", NULL, editor_sidebar_row_remove);
-
   properties [PROP_ITEM] =
     g_param_spec_object ("item",
                          "Item",
@@ -245,6 +230,10 @@ _editor_sidebar_row_set_item (EditorSidebarRow  *self,
 
   if (item != NULL)
     {
+      GFile *file = _editor_sidebar_item_get_file (item);
+      const char *draft_id = _editor_sidebar_item_get_draft_id (item);
+      g_autofree char *uri = file ? g_file_get_uri (file) : NULL;
+
       self->title_binding =
         g_object_bind_property (self->item, "title",
                                 self->title, "label",
@@ -269,5 +258,10 @@ _editor_sidebar_row_set_item (EditorSidebarRow  *self,
                                      G_BINDING_SYNC_CREATE,
                                      age_to_string,
                                      NULL, self, NULL);
-  }
+      gtk_actionable_set_action_target (GTK_ACTIONABLE (self->remove),
+                                        "(ss)",
+                                        uri ? uri : "",
+                                        draft_id ? draft_id : "");
+      gtk_actionable_set_action_name (GTK_ACTIONABLE (self->remove), "row.remove");
+    }
 }
diff --git a/src/editor-sidebar-row.ui b/src/editor-sidebar-row.ui
index df13d09..dd1571b 100644
--- a/src/editor-sidebar-row.ui
+++ b/src/editor-sidebar-row.ui
@@ -73,7 +73,6 @@
         </child>
         <child>
           <object class="GtkButton" id="remove">
-            <property name="action-name">row.remove</property>
             <property name="valign">center</property>
             <property name="halign">end</property>
             <property name="icon-name">window-close-symbolic</property>


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