[epiphany/wip/bookmarks: 4/4] bookmark-properties-grid: Save the grid's parent so it can be destroyed when bookmark is removed
- From: Iulian Radu <iulianradu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/wip/bookmarks: 4/4] bookmark-properties-grid: Save the grid's parent so it can be destroyed when bookmark is removed
- Date: Mon, 8 Aug 2016 14:03:24 +0000 (UTC)
commit 154931fb825c0216910016e3d13d0e225b9b16a9
Author: Iulian Radu <iulian radu67 gmail com>
Date: Mon Aug 8 16:58:47 2016 +0300
bookmark-properties-grid: Save the grid's parent so it can be destroyed when bookmark is removed
src/ephy-bookmark-properties-grid.c | 46 ++++++++++++++++---------
src/ephy-bookmark-properties-grid.h | 5 ++-
src/ephy-bookmark-row.c | 3 +-
src/ephy-bookmarks-manager.c | 6 ---
src/ephy-toolbar.c | 39 ++++++++++++++++++++-
src/resources/gtk/bookmark-properties-grid.ui | 2 -
6 files changed, 73 insertions(+), 28 deletions(-)
---
diff --git a/src/ephy-bookmark-properties-grid.c b/src/ephy-bookmark-properties-grid.c
index f6976cb..0f1548f 100644
--- a/src/ephy-bookmark-properties-grid.c
+++ b/src/ephy-bookmark-properties-grid.c
@@ -34,6 +34,9 @@ struct _EphyBookmarkPropertiesGrid {
EphyBookmark *bookmark;
EphyBookmarkPropertiesGridType type;
+ GtkWidget *parent;
+
+ EphyBookmarksManager *manager;
GtkWidget *popover_bookmark_label;
GtkWidget *name_entry;
@@ -51,6 +54,7 @@ enum {
PROP_0,
PROP_BOOKMARK,
PROP_TYPE,
+ PROP_PARENT,
LAST_PROP
};
@@ -113,7 +117,6 @@ static void
ephy_bookmark_properties_grid_tag_widget_button_clicked_cb (EphyBookmarkPropertiesGrid *self,
GtkButton *button)
{
- EphyBookmarksManager *manager = ephy_shell_get_bookmarks_manager (ephy_shell_get_default ());
GtkWidget *box;
GtkWidget *flow_box_child;
GtkLabel *label;
@@ -125,7 +128,7 @@ ephy_bookmark_properties_grid_tag_widget_button_clicked_cb (EphyBookmarkProperti
g_assert (GTK_IS_BOX (box));
label = g_object_get_data (G_OBJECT (box), "label");
- ephy_bookmarks_manager_remove_tag (manager, gtk_label_get_text (label));
+ ephy_bookmarks_manager_remove_tag (self->manager, gtk_label_get_text (label));
flow_box_child = gtk_widget_get_parent (box);
gtk_widget_destroy (flow_box_child);
@@ -202,7 +205,6 @@ ephy_bookmarks_properties_grid_actions_add_tag (GSimpleAction *action,
gpointer user_data)
{
EphyBookmarkPropertiesGrid *self = user_data;
- EphyBookmarksManager *manager = ephy_shell_get_bookmarks_manager (ephy_shell_get_default ());
GtkEntryBuffer *buffer;
GtkWidget *widget;
const char *text;
@@ -213,7 +215,7 @@ ephy_bookmarks_properties_grid_actions_add_tag (GSimpleAction *action,
text = gtk_entry_buffer_get_text (buffer);
/* Add tag to the list of all tags. */
- ephy_bookmarks_manager_add_tag (manager, text);
+ ephy_bookmarks_manager_add_tag (self->manager, text);
/* Add tag to the bookmark's list of tags. */
ephy_bookmark_add_tag (self->bookmark, text);
@@ -238,10 +240,9 @@ ephy_bookmarks_properties_grid_actions_remove_bookmark (GSimpleAction *action,
g_signal_emit_by_name (self->bookmark, "removed");
- if (self->type == EPHY_BOOKMARK_PROPERTIES_GRID_TYPE_POPOVER)
- gtk_widget_destroy (gtk_widget_get_parent (GTK_WIDGET (self)));
- else
- gtk_widget_destroy (gtk_widget_get_parent (gtk_widget_get_parent (GTK_WIDGET (self))));
+ ephy_bookmarks_manager_remove_bookmark (self->manager, self->bookmark);
+
+ gtk_widget_destroy (self->parent);
}
static void
@@ -249,14 +250,13 @@ ephy_bookmark_properties_grid_buffer_text_changed_cb (EphyBookmarkPropertiesGrid
GParamSpec *pspec,
GtkEntryBuffer *buffer)
{
- EphyBookmarksManager *manager = ephy_shell_get_bookmarks_manager (ephy_shell_get_default ());
const char *text;
g_assert (EPHY_IS_BOOKMARK_PROPERTIES_GRID (self));
g_assert (GTK_IS_ENTRY_BUFFER (buffer));
text = gtk_entry_buffer_get_text (buffer);
- if (strlen (text) >= 3 && !ephy_bookmarks_manager_tag_exists (manager, text))
+ if (strlen (text) >= 3 && !ephy_bookmarks_manager_tag_exists (self->manager, text))
gtk_widget_set_sensitive (self->add_tag_button, TRUE);
else
gtk_widget_set_sensitive (self->add_tag_button, FALSE);
@@ -277,6 +277,9 @@ ephy_bookmark_properties_grid_set_property (GObject *object,
case PROP_TYPE:
self->type = g_value_get_enum (value);
break;
+ case PROP_PARENT:
+ self->parent = g_value_dup_object (value);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@@ -310,7 +313,6 @@ static void
ephy_bookmark_properties_grid_constructed (GObject *object)
{
EphyBookmarkPropertiesGrid *self = EPHY_BOOKMARK_PROPERTIES_GRID (object);
- EphyBookmarksManager *manager = ephy_shell_get_bookmarks_manager (ephy_shell_get_default ());
GSequence *tags;
GSequence *bookmark_tags;
GSequenceIter *iter;
@@ -345,7 +347,7 @@ ephy_bookmark_properties_grid_constructed (GObject *object)
}
/* Create tag widgets */
- tags = ephy_bookmarks_manager_get_tags (manager);
+ tags = ephy_bookmarks_manager_get_tags (self->manager);
bookmark_tags = ephy_bookmark_get_tags (self->bookmark);
for (iter = g_sequence_get_begin_iter (tags);
!g_sequence_iter_is_end (iter);
@@ -374,9 +376,9 @@ ephy_bookmark_properties_grid_constructed (GObject *object)
static void
ephy_bookmark_properties_grid_destroy (GtkWidget *widget)
{
- EphyBookmarksManager *manager = ephy_shell_get_bookmarks_manager (ephy_shell_get_default ());
+ EphyBookmarkPropertiesGrid *self = EPHY_BOOKMARK_PROPERTIES_GRID (widget);
- ephy_bookmarks_manager_save_to_file_async (manager, NULL, NULL, NULL);
+ ephy_bookmarks_manager_save_to_file_async (self->manager, NULL, NULL, NULL);
GTK_WIDGET_CLASS (ephy_bookmark_properties_grid_parent_class)->destroy (widget);
}
@@ -407,6 +409,13 @@ ephy_bookmark_properties_grid_class_init (EphyBookmarkPropertiesGridClass *klass
EPHY_BOOKMARK_PROPERTIES_GRID_TYPE_DIALOG,
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
+ obj_properties[PROP_PARENT] =
+ g_param_spec_object ("parent",
+ "A GtkWidget",
+ "The dialog or popover that needs to be destroyed when the bookmark is removed",
+ GTK_TYPE_WIDGET,
+ G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
+
g_object_class_install_properties (object_class, LAST_PROP, obj_properties);
gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/epiphany/gtk/bookmark-properties-grid.ui");
@@ -432,6 +441,8 @@ ephy_bookmark_properties_grid_init (EphyBookmarkPropertiesGrid *self)
gtk_widget_init_template (GTK_WIDGET (self));
+ self->manager = ephy_shell_get_bookmarks_manager (ephy_shell_get_default ());
+
gtk_flow_box_set_sort_func (GTK_FLOW_BOX (self->tags_box),
(GtkFlowBoxSortFunc)flow_box_sort_func,
NULL, NULL);
@@ -451,14 +462,17 @@ ephy_bookmark_properties_grid_init (EphyBookmarkPropertiesGrid *self)
}
GtkWidget *
-ephy_bookmark_properties_grid_new (EphyBookmark *bookmark,
- EphyBookmarkPropertiesGridType type)
+ephy_bookmark_properties_grid_new (EphyBookmark *bookmark,
+ EphyBookmarkPropertiesGridType type,
+ GtkWidget *parent)
{
g_return_val_if_fail (EPHY_IS_BOOKMARK (bookmark), NULL);
+ g_return_val_if_fail (GTK_IS_WIDGET (parent), NULL);
return g_object_new (EPHY_TYPE_BOOKMARK_PROPERTIES_GRID,
"bookmark", bookmark,
"type", type,
+ "parent", parent,
NULL);
}
diff --git a/src/ephy-bookmark-properties-grid.h b/src/ephy-bookmark-properties-grid.h
index 389aeae..37cb0e9 100644
--- a/src/ephy-bookmark-properties-grid.h
+++ b/src/ephy-bookmark-properties-grid.h
@@ -35,8 +35,9 @@ typedef enum {
EPHY_BOOKMARK_PROPERTIES_GRID_TYPE_POPOVER
} EphyBookmarkPropertiesGridType;
-GtkWidget *ephy_bookmark_properties_grid_new (EphyBookmark *bookmark,
- EphyBookmarkPropertiesGridType type);
+GtkWidget *ephy_bookmark_properties_grid_new (EphyBookmark *bookmark,
+ EphyBookmarkPropertiesGridType type,
+ GtkWidget *parent);
GtkWidget *ephy_bookmark_properties_grid_get_add_tag_button (EphyBookmarkPropertiesGrid *self);
diff --git a/src/ephy-bookmark-row.c b/src/ephy-bookmark-row.c
index bffe2b3..5c41297 100644
--- a/src/ephy-bookmark-row.c
+++ b/src/ephy-bookmark-row.c
@@ -63,7 +63,8 @@ ephy_bookmark_row_button_clicked_cb (EphyBookmarkRow *row,
content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
grid = ephy_bookmark_properties_grid_new (ephy_bookmark_row_get_bookmark (row),
- EPHY_BOOKMARK_PROPERTIES_GRID_TYPE_DIALOG);
+ EPHY_BOOKMARK_PROPERTIES_GRID_TYPE_DIALOG,
+ dialog);
gtk_window_set_default (GTK_WINDOW (dialog),
ephy_bookmark_properties_grid_get_add_tag_button (EPHY_BOOKMARK_PROPERTIES_GRID
(grid)));
diff --git a/src/ephy-bookmarks-manager.c b/src/ephy-bookmarks-manager.c
index 277bb7b..fb15106 100644
--- a/src/ephy-bookmarks-manager.c
+++ b/src/ephy-bookmarks-manager.c
@@ -220,12 +220,6 @@ ephy_bookmarks_manager_add_bookmark (EphyBookmarksManager *self,
if (g_sequence_iter_is_end (prev_iter)
|| ephy_bookmark_get_time_added (g_sequence_get (prev_iter)) != ephy_bookmark_get_time_added
(bookmark)) {
- g_signal_connect_object (bookmark,
- "removed",
- G_CALLBACK (ephy_bookmarks_manager_remove_bookmark),
- self,
- G_CONNECT_SWAPPED);
-
g_sequence_insert_before (iter, bookmark);
/* Update list */
diff --git a/src/ephy-toolbar.c b/src/ephy-toolbar.c
index 768ff3c..a49c4b4 100644
--- a/src/ephy-toolbar.c
+++ b/src/ephy-toolbar.c
@@ -566,6 +566,37 @@ ephy_toolbar_change_combined_stop_reload_state (GSimpleAction *action,
image);
}
+/**
+ * update_bookmarked_status_cb:
+ * @bookmark: an #EphyBookmark pbject
+ * @toolbar: an #EphyToolbar widget
+ *
+ * Remove bookmarked status if the @bookmark was removed.
+ *
+ **/
+static void
+update_bookmarked_status_cb (EphyBookmark *bookmark,
+ EphyToolbar *toolbar)
+{
+ EphyEmbed *embed;
+ EphyWebView *view;
+ const char *address;
+
+ g_assert (EPHY_IS_BOOKMARK (bookmark));
+ g_assert (EPHY_IS_TOOLBAR (toolbar));
+
+ embed = ephy_embed_container_get_active_child
+ (EPHY_EMBED_CONTAINER (toolbar->window));
+ view = ephy_embed_get_web_view (embed);
+
+ address = ephy_web_view_get_address (view);
+
+ if (g_strcmp0 (ephy_bookmark_get_url (bookmark), address) == 0) {
+ ephy_location_entry_set_bookmarked_status (EPHY_LOCATION_ENTRY (toolbar->entry),
+ FALSE);
+ }
+}
+
static void
add_bookmark_button_clicked_cb (EphyLocationEntry *entry,
gpointer *user_data)
@@ -587,6 +618,10 @@ add_bookmark_button_clicked_cb (EphyLocationEntry *entry,
bookmark = ephy_bookmark_new (g_strdup (location),
g_strdup (ephy_embed_get_title (embed)),
g_sequence_new (g_free));
+
+ g_signal_connect_object (bookmark, "removed",
+ G_CALLBACK (update_bookmarked_status_cb),
+ toolbar, 0);
ephy_bookmarks_manager_add_bookmark (manager, bookmark);
ephy_location_entry_set_bookmarked_status (entry, TRUE);
}
@@ -597,7 +632,9 @@ add_bookmark_button_clicked_cb (EphyLocationEntry *entry,
&rectangle);
gtk_popover_set_pointing_to (GTK_POPOVER (popover), &rectangle);
gtk_container_add (GTK_CONTAINER (popover),
- ephy_bookmark_properties_grid_new (bookmark,
EPHY_BOOKMARK_PROPERTIES_GRID_TYPE_POPOVER));
+ ephy_bookmark_properties_grid_new (bookmark,
+ EPHY_BOOKMARK_PROPERTIES_GRID_TYPE_POPOVER,
+ popover));
gtk_widget_show (popover);
}
diff --git a/src/resources/gtk/bookmark-properties-grid.ui b/src/resources/gtk/bookmark-properties-grid.ui
index d3c640a..af2b8d0 100644
--- a/src/resources/gtk/bookmark-properties-grid.ui
+++ b/src/resources/gtk/bookmark-properties-grid.ui
@@ -38,9 +38,7 @@
</child>
<child>
<object class="GtkEntry" id="name_entry">
- <property name="max-length">40</property>
<property name="max-width-chars">40</property>
- <property name="width-chars">40</property>
<property name="visible">true</property>
</object>
<packing>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]