[epiphany] EphyTopicsPalette: Move UI stuff in EphyBookmarkProperties.
- From: Arnaud Bonatti <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany] EphyTopicsPalette: Move UI stuff in EphyBookmarkProperties.
- Date: Sat, 21 Nov 2015 00:26:05 +0000 (UTC)
commit 08c68a580ccf3d7e4fa41356afc24279c9bbe867
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Sat Nov 21 01:17:47 2015 +0100
EphyTopicsPalette: Move UI stuff in EphyBookmarkProperties.
https://bugzilla.gnome.org/show_bug.cgi?id=757669
src/bookmarks/ephy-bookmark-properties.c | 109 +++++++++++++++++--------
src/bookmarks/ephy-topics-palette.c | 134 +++++------------------------
src/bookmarks/ephy-topics-palette.h | 17 +++-
src/resources/bookmark-properties.ui | 41 +++++++++-
4 files changed, 150 insertions(+), 151 deletions(-)
---
diff --git a/src/bookmarks/ephy-bookmark-properties.c b/src/bookmarks/ephy-bookmark-properties.c
index 41fc5bd..c7735a7 100644
--- a/src/bookmarks/ephy-bookmark-properties.c
+++ b/src/bookmarks/ephy-bookmark-properties.c
@@ -64,8 +64,12 @@ struct _EphyBookmarkProperties
GtkEntry *adress_entry;
GtkLabel *topics_label;
GtkExpander *topics_expander;
+ GtkTreeView *topics_tree_view;
GtkScrolledWindow *topics_scrolled_window;
GtkLabel *warning_label;
+
+ /* slave */
+ EphyTopicsPalette *palette;
};
enum
@@ -250,38 +254,73 @@ title_entry_changed_cb (GtkWidget *entry,
}
static void
-location_entry_changed_cb (GtkWidget *entry,
- EphyBookmarkProperties *properties)
+on_topic_edited (GtkCellRendererText *renderer,
+ const char *path_str,
+ const char *new_text,
+ EphyBookmarkProperties *properties)
{
- ephy_bookmarks_set_address (properties->bookmarks,
- properties->bookmark,
- gtk_entry_get_text (GTK_ENTRY (entry)));
+ if (*new_text != 0)
+ {
+ EphyNode *node;
+ node = ephy_bookmarks_add_keyword (properties->bookmarks, new_text);
+ ephy_bookmarks_set_keyword (properties->bookmarks, node, properties->bookmark);
+ }
+ else
+ {
+ ephy_topics_palette_update_list (EPHY_TOPICS_PALETTE (properties->topics_tree_view)); //
TODO hack
+ }
}
static void
-list_mapped_cb (GtkWidget *widget,
- EphyBookmarkProperties *properties)
+on_topic_toggled (GtkCellRendererToggle *cell_renderer,
+ gchar *path,
+ EphyBookmarkProperties *properties)
{
- GdkGeometry geometry;
-
- geometry.min_width = -1;
- geometry.min_height = 230;
- gtk_window_set_geometry_hints (GTK_WINDOW (properties),
- widget, &geometry,
- GDK_HINT_MIN_SIZE);
+ EphyNode *topic;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+
+ model = gtk_tree_view_get_model (properties->topics_tree_view);
+
+ g_return_if_fail (gtk_tree_model_get_iter_from_string (model, &iter, path));
+
+ gtk_tree_model_get (model, &iter, EPHY_TOPICS_PALETTE_COLUMN_NODE, &topic, -1);
+
+ /* Protect against toggling separators. */
+ if (topic == NULL)
+ return;
+
+ if (ephy_node_has_child (topic, properties->bookmark))
+ {
+ ephy_bookmarks_unset_keyword (properties->bookmarks,
+ topic,
+ properties->bookmark);
+ }
+ else
+ {
+ ephy_bookmarks_set_keyword (properties->bookmarks,
+ topic,
+ properties->bookmark);
+ }
+}
+
+static gboolean
+is_separator (GtkTreeModel *model,
+ GtkTreeIter *iter,
+ gpointer data)
+{
+ EphyNode *node;
+ gtk_tree_model_get (model, iter, EPHY_TOPICS_PALETTE_COLUMN_NODE, &node, -1);
+ return (node == NULL);
}
static void
-list_unmapped_cb (GtkWidget *widget,
- EphyBookmarkProperties *properties)
+location_entry_changed_cb (GtkWidget *entry,
+ EphyBookmarkProperties *properties)
{
- GdkGeometry geometry;
-
- geometry.max_height = -1;
- geometry.max_width = G_MAXINT;
- gtk_window_set_geometry_hints (GTK_WINDOW (properties),
- GTK_WIDGET (properties),
- &geometry, GDK_HINT_MAX_SIZE);
+ ephy_bookmarks_set_address (properties->bookmarks,
+ properties->bookmark,
+ gtk_entry_get_text (GTK_ENTRY (entry)));
}
static void
@@ -297,11 +336,10 @@ ephy_bookmark_properties_constructor (GType type,
GObject *object;
EphyBookmarkProperties *properties;
- gboolean lockdown;
- const char *tmp;
- char *unescaped_url;
- GtkWidget *entry;
- GtkWidget *widget;
+ gboolean lockdown;
+ const char *tmp;
+ char *unescaped_url;
+ GtkWidget *entry;
object = G_OBJECT_CLASS (ephy_bookmark_properties_parent_class)->constructor (type,
n_construct_properties,
@@ -341,13 +379,13 @@ ephy_bookmark_properties_constructor (GType type,
gtk_grid_attach (properties->grid, entry, 1, 2, 1, 1);
gtk_widget_set_hexpand (entry, TRUE);
- widget = ephy_topics_palette_new (properties->bookmarks, properties->bookmark);
- gtk_container_add (GTK_CONTAINER (properties->topics_scrolled_window), widget);
- gtk_widget_show (widget);
+ gtk_tree_view_set_row_separator_func (properties->topics_tree_view, is_separator, NULL, NULL);
+
+ properties->palette = ephy_topics_palette_new (properties->bookmarks, properties->bookmark);
+ gtk_tree_view_set_model (properties->topics_tree_view, GTK_TREE_MODEL (ephy_topics_palette_get_store
(properties->palette)));
+
+ /* TODO bind; and the entry?! */
gtk_widget_set_sensitive (GTK_WIDGET (properties->topics_scrolled_window), !lockdown);
- /* TODO remove these hacks */
- g_signal_connect (properties->topics_scrolled_window, "map", G_CALLBACK (list_mapped_cb), properties);
- g_signal_connect (properties->topics_scrolled_window, "unmap", G_CALLBACK (list_unmapped_cb),
properties);
ephy_initial_state_add_expander (GTK_WIDGET (properties->topics_expander),
"bookmark_properties_list", FALSE);
@@ -464,10 +502,13 @@ ephy_bookmark_properties_class_init (EphyBookmarkPropertiesClass *klass)
gtk_widget_class_bind_template_child (widget_class, EphyBookmarkProperties, adress_entry);
gtk_widget_class_bind_template_child (widget_class, EphyBookmarkProperties, topics_label);
gtk_widget_class_bind_template_child (widget_class, EphyBookmarkProperties, topics_expander);
+ gtk_widget_class_bind_template_child (widget_class, EphyBookmarkProperties, topics_tree_view);
gtk_widget_class_bind_template_child (widget_class, EphyBookmarkProperties, topics_scrolled_window);
gtk_widget_class_bind_template_child (widget_class, EphyBookmarkProperties, warning_label);
gtk_widget_class_bind_template_callback (widget_class, title_entry_changed_cb);
+ gtk_widget_class_bind_template_callback (widget_class, on_topic_toggled); // TODO make the row
activatable instead of a little togglebutton
+ gtk_widget_class_bind_template_callback (widget_class, on_topic_edited); // TODO topics’ names are
not editable from there, they are synced with bookmarks... but this is used for... updating the entry \o/ yay
\o/
gtk_widget_class_bind_template_callback (widget_class, location_entry_changed_cb);
gtk_widget_class_bind_template_callback (widget_class, ephy_bookmark_properties_response_cb);
gtk_widget_class_bind_template_callback (widget_class, ephy_bookmark_properties_destroy_cb);
diff --git a/src/bookmarks/ephy-topics-palette.c b/src/bookmarks/ephy-topics-palette.c
index 911d72e..e485a8f 100644
--- a/src/bookmarks/ephy-topics-palette.c
+++ b/src/bookmarks/ephy-topics-palette.c
@@ -51,14 +51,6 @@ enum
enum
{
- COLUMN_TITLE,
- COLUMN_NODE,
- COLUMN_SELECTED,
- COLUMNS
-};
-
-enum
-{
MODE_GROUPED,
MODE_LIST,
MODES
@@ -86,8 +78,8 @@ append_topics (EphyTopicsPalette *palette,
{
if (!*valid) gtk_list_store_append (palette->store, iter);
gtk_list_store_set (palette->store, iter,
- COLUMN_TITLE, NULL,
- COLUMN_NODE, NULL,
+ EPHY_TOPICS_PALETTE_COLUMN_TITLE, NULL,
+ EPHY_TOPICS_PALETTE_COLUMN_NODE, NULL,
-1);
*valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (palette->store), iter);
}
@@ -99,17 +91,17 @@ append_topics (EphyTopicsPalette *palette,
if (!*valid) gtk_list_store_append (palette->store, iter);
gtk_list_store_set (palette->store, iter,
- COLUMN_TITLE, title,
- COLUMN_NODE, node,
- COLUMN_SELECTED, ephy_node_has_child (node, palette->bookmark),
+ EPHY_TOPICS_PALETTE_COLUMN_TITLE, title,
+ EPHY_TOPICS_PALETTE_COLUMN_NODE, node,
+ EPHY_TOPICS_PALETTE_COLUMN_SELECTED, ephy_node_has_child (node,
palette->bookmark),
-1);
*valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (palette->store), iter);
*first = FALSE;
}
}
-static void
-update_list (EphyTopicsPalette *palette)
+void
+ephy_topics_palette_update_list (EphyTopicsPalette *palette)
{
GPtrArray *children, *bookmarks, *topics;
EphyNode *node;
@@ -228,7 +220,7 @@ static void
tree_changed_cb (EphyBookmarks *bookmarks,
EphyTopicsPalette *palette)
{
- update_list (palette);
+ ephy_topics_palette_update_list (palette);
}
static void
@@ -236,7 +228,7 @@ node_added_cb (EphyNode *parent,
EphyNode *child,
EphyTopicsPalette *palette)
{
- update_list (palette);
+ ephy_topics_palette_update_list (palette);
}
static void
@@ -245,7 +237,7 @@ node_changed_cb (EphyNode *parent,
guint property_id,
EphyTopicsPalette *palette)
{
- update_list (palette);
+ ephy_topics_palette_update_list (palette);
}
static void
@@ -254,7 +246,7 @@ node_removed_cb (EphyNode *parent,
guint index,
EphyTopicsPalette *palette)
{
- update_list (palette);
+ ephy_topics_palette_update_list (palette);
}
static void
@@ -286,7 +278,7 @@ ephy_topics_palette_set_property (GObject *object,
break;
case PROP_MODE:
palette->mode = g_value_get_int (value);
- update_list (palette);
+ ephy_topics_palette_update_list (palette);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -294,64 +286,10 @@ ephy_topics_palette_set_property (GObject *object,
}
}
-static void
-cell_edited (GtkCellRendererText *renderer,
- const char *path_str,
- const char *new_text,
- EphyTopicsPalette *palette)
+GtkListStore *
+ephy_topics_palette_get_store (EphyTopicsPalette *palette)
{
- if (*new_text != 0)
- {
- EphyNode *node;
- node = ephy_bookmarks_add_keyword (palette->bookmarks, new_text);
- ephy_bookmarks_set_keyword (palette->bookmarks, node, palette->bookmark);
- }
- else
- {
- update_list (palette);
- }
-}
-
-static void
-toggled (GtkCellRendererToggle *cell_renderer,
- gchar *path,
- EphyTopicsPalette *palette)
-{
- EphyNode *topic;
- GtkTreeModel *model;
- GtkTreeIter iter;
-
- model = gtk_tree_view_get_model (GTK_TREE_VIEW (palette));
-
- g_return_if_fail(gtk_tree_model_get_iter_from_string (model, &iter, path));
-
- gtk_tree_model_get (model, &iter, COLUMN_NODE, &topic, -1);
-
- /* Need to protect against toggling separators. */
- if (topic == NULL) return;
-
- if (ephy_node_has_child (topic, palette->bookmark))
- {
- ephy_bookmarks_unset_keyword (palette->bookmarks,
- topic,
- palette->bookmark);
- }
- else
- {
- ephy_bookmarks_set_keyword (palette->bookmarks,
- topic,
- palette->bookmark);
- }
-}
-
-static gboolean
-is_separator (GtkTreeModel *model,
- GtkTreeIter *iter,
- gpointer data)
-{
- EphyNode *node;
- gtk_tree_model_get (model, iter, COLUMN_NODE, &node, -1);
- return (node == NULL);
+ return palette->store;
}
static GObject *
@@ -362,39 +300,18 @@ ephy_topics_palette_constructor (GType type,
{
GObject *object;
EphyTopicsPalette *palette;
- GtkCellRenderer *renderer;
object = G_OBJECT_CLASS (ephy_topics_palette_parent_class)->constructor (type,
n_construct_properties,
construct_params);
palette = EPHY_TOPICS_PALETTE (object);
- palette->store = gtk_list_store_new (COLUMNS, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_BOOLEAN);
+ palette->store = gtk_list_store_new (EPHY_TOPICS_PALETTE_COLUMNS, G_TYPE_STRING, G_TYPE_POINTER,
G_TYPE_BOOLEAN);
gtk_tree_view_set_model (GTK_TREE_VIEW (object), GTK_TREE_MODEL (palette->store));
g_object_unref (palette->store);
- palette->column = gtk_tree_view_column_new ();
-
- renderer = gtk_cell_renderer_toggle_new ();
- gtk_tree_view_column_pack_start (palette->column, renderer, FALSE);
- gtk_tree_view_column_add_attribute (palette->column, renderer, "active", COLUMN_SELECTED);
- g_signal_connect (renderer, "toggled", G_CALLBACK (toggled), palette);
-
- renderer = gtk_cell_renderer_text_new ();
- gtk_tree_view_column_pack_start (palette->column, renderer, TRUE);
- gtk_tree_view_column_add_attribute (palette->column, renderer, "text", COLUMN_TITLE);
- g_signal_connect (renderer, "edited", G_CALLBACK (cell_edited), palette);
-
- gtk_tree_view_append_column (GTK_TREE_VIEW (object), palette->column);
-
- gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW (object), is_separator, NULL, NULL);
- gtk_tree_view_set_enable_search (GTK_TREE_VIEW (object), TRUE);
- gtk_tree_view_set_search_column (GTK_TREE_VIEW (object), COLUMN_TITLE);
- gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (object), FALSE);
- gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (object)),
GTK_SELECTION_NONE);
-
- update_list (palette);
-
+ ephy_topics_palette_update_list (palette);
+
return object;
}
@@ -403,21 +320,16 @@ ephy_topics_palette_init (EphyTopicsPalette *palette)
{
}
-GtkWidget *
+EphyTopicsPalette *
ephy_topics_palette_new (EphyBookmarks *bookmarks,
- EphyNode *bookmark)
+ EphyNode *bookmark)
{
- EphyTopicsPalette *palette;
-
g_assert (bookmarks != NULL);
- palette = EPHY_TOPICS_PALETTE (g_object_new
- (EPHY_TYPE_TOPICS_PALETTE,
- "bookmarks", bookmarks,
- "bookmark", bookmark,
- NULL));
-
- return GTK_WIDGET (palette);
+ return g_object_new (EPHY_TYPE_TOPICS_PALETTE,
+ "bookmarks", bookmarks,
+ "bookmark", bookmark,
+ NULL);
}
static void
diff --git a/src/bookmarks/ephy-topics-palette.h b/src/bookmarks/ephy-topics-palette.h
index d50cd55..8dd5c10 100644
--- a/src/bookmarks/ephy-topics-palette.h
+++ b/src/bookmarks/ephy-topics-palette.h
@@ -32,10 +32,19 @@ G_BEGIN_DECLS
#define EPHY_TYPE_TOPICS_PALETTE (ephy_topics_palette_get_type ())
G_DECLARE_FINAL_TYPE (EphyTopicsPalette, ephy_topics_palette, EPHY, TOPICS_PALETTE, GtkTreeView);
-GtkWidget *ephy_topics_palette_new (EphyBookmarks *bookmarks,
- EphyNode *bookmark);
-
-void ephy_topics_palette_new_topic (EphyTopicsPalette *palette);
+enum
+{
+ EPHY_TOPICS_PALETTE_COLUMN_TITLE,
+ EPHY_TOPICS_PALETTE_COLUMN_NODE,
+ EPHY_TOPICS_PALETTE_COLUMN_SELECTED,
+ EPHY_TOPICS_PALETTE_COLUMNS
+};
+
+EphyTopicsPalette *ephy_topics_palette_new (EphyBookmarks *bookmarks,
+ EphyNode *bookmark);
+
+void ephy_topics_palette_update_list (EphyTopicsPalette *palette);
+GtkListStore *ephy_topics_palette_get_store (EphyTopicsPalette *palette);
G_END_DECLS
diff --git a/src/resources/bookmark-properties.ui b/src/resources/bookmark-properties.ui
index 39c4c80..49a3ad1 100644
--- a/src/resources/bookmark-properties.ui
+++ b/src/resources/bookmark-properties.ui
@@ -5,7 +5,7 @@
<property name="modal">True</property>
<property name="resizable">False</property>
<property name="width-request">450</property>
- <property name="type_hint">dialog</property>
+ <property name="type-hint">dialog</property>
<property name="border-width">5</property>
<signal name="response" handler="ephy_bookmark_properties_response_cb"/>
<signal name="destroy" handler="ephy_bookmark_properties_destroy_cb"/>
@@ -92,8 +92,45 @@
<object class="GtkScrolledWindow" id="topics_scrolled_window">
<property name="visible">True</property>
<property name="shadow-type">in</property>
- <property name="width-request">290</property>
<property name="height-request">250</property>
+ <child>
+ <object class="GtkTreeView" id="topics_tree_view">
+ <property name="visible">True</property>
+ <property name="search-column">0</property> <!-- COLUMN_TITLE -->
+ <property name="headers-visible">False</property>
+ <child internal-child="selection">
+ <object class="GtkTreeSelection">
+ <property name="mode">none</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkTreeViewColumn" id="topics_column">
+ <property name="sizing">fixed</property>
+ <property name="fixed-width">290</property>
+ <property name="title" translatable="yes">Topics</property>
+ <property name="clickable">True</property>
+ <property name="sort-indicator">True</property>
+ <property name="sort-order">descending</property>
+ <child>
+ <object class="GtkCellRendererToggle">
+ <signal name="toggled" handler="on_topic_toggled"/>
+ </object>
+ <attributes>
+ <attribute name="active">2</attribute> <!-- COLUMN_SELECTED -->
+ </attributes>
+ </child>
+ <child>
+ <object class="GtkCellRendererText">
+ <signal name="edited" handler="on_topic_edited"/>
+ </object>
+ <attributes>
+ <attribute name="text">0</attribute> <!-- COLUMN_TITLE -->
+ </attributes>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
</object>
</child>
</object>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]