[buoh/cleanups: 3/7] Port comic-list to GtkBuilder
- From: Jan Tojnar <jtojnar src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [buoh/cleanups: 3/7] Port comic-list to GtkBuilder
- Date: Tue, 25 Sep 2018 00:07:38 +0000 (UTC)
commit 895c3600b14dd3a4695dd74b1c92fa5059ba1514
Author: Jan Tojnar <jtojnar gmail com>
Date: Fri Sep 14 23:42:50 2018 +0200
Port comic-list to GtkBuilder
https://gitlab.gnome.org/GNOME/buoh/issues/5
data/meson.build | 1 +
data/org.gnome.buoh.gresource.xml | 1 +
data/ui/comic-list.ui | 41 +++++++++++++++++++++
po/POTFILES.in | 1 +
src/buoh-comic-list.c | 75 ++++++++++++++-------------------------
src/buoh-comic-list.h | 2 ++
src/buoh-window.c | 3 ++
7 files changed, 75 insertions(+), 49 deletions(-)
---
diff --git a/data/meson.build b/data/meson.build
index 92eb566..ec37c83 100644
--- a/data/meson.build
+++ b/data/meson.build
@@ -1,5 +1,6 @@
ui_files = files(
'ui/add-comic-dialog.ui',
+ 'ui/comic-list.ui',
'ui/properties-dialog.ui',
'ui/view-comic.ui',
'ui/view-message.ui',
diff --git a/data/org.gnome.buoh.gresource.xml b/data/org.gnome.buoh.gresource.xml
index 9aa884c..a8e54ed 100644
--- a/data/org.gnome.buoh.gresource.xml
+++ b/data/org.gnome.buoh.gresource.xml
@@ -3,6 +3,7 @@
<gresource prefix="/org/gnome/buoh">
<file>buoh-ui.xml</file>
<file>ui/add-comic-dialog.ui</file>
+ <file>ui/comic-list.ui</file>
<file>ui/properties-dialog.ui</file>
<file>ui/view-comic.ui</file>
<file>ui/view-message.ui</file>
diff --git a/data/ui/comic-list.ui b/data/ui/comic-list.ui
new file mode 100644
index 0000000..01900b9
--- /dev/null
+++ b/data/ui/comic-list.ui
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.22.1 -->
+<interface>
+ <requires lib="gtk+" version="3.20"/>
+ <template class="BuohComicList" parent="GtkBin">
+ <property name="border-width">6</property>
+ <child>
+ <object class="GtkScrolledWindow">
+ <property name="visible">1</property>
+ <property name="can-focus">1</property>
+ <property name="shadow-type">in</property>
+ <child>
+ <object class="GtkTreeView" id="tree_view">
+ <property name="visible">1</property>
+ <property name="can-focus">1</property>
+ <child internal-child="selection">
+ <object class="GtkTreeSelection">
+ <signal handler="buoh_comic_list_selection_changed" name="changed" object="BuohComicList"
swapped="no"/>
+ </object>
+ </child>
+ <child>
+ <object class="GtkTreeViewColumn">
+ <property name="title" translatable="yes">Title</property>
+ <child>
+ <object class="GtkCellRendererText">
+ <property name="xalign">0</property>
+ <property name="ellipsize">end</property>
+ </object>
+ <attributes>
+ <!-- COMIC_LIST_TITLE -->
+ <attribute name="text">1</attribute>
+ </attributes>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </template>
+</interface>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index a772126..20f8f62 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -3,6 +3,7 @@
data/org.gnome.buoh.desktop.in
data/org.gnome.buoh.gschema.xml
data/ui/add-comic-dialog.ui
+data/ui/comic-list.ui
data/ui/properties-dialog.ui
data/ui/view-comic.ui
data/ui/view-message.ui
diff --git a/src/buoh-comic-list.c b/src/buoh-comic-list.c
index 1c9b5b1..2972200 100644
--- a/src/buoh-comic-list.c
+++ b/src/buoh-comic-list.c
@@ -26,7 +26,6 @@
#include "buoh-comic-list.h"
struct _BuohComicListPrivate {
- GtkWidget *swindow;
GtkWidget *tree_view;
GtkTreeModel *model;
BuohComicManager *comic_manager;
@@ -72,7 +71,9 @@ buoh_comic_list_selection_changed (GtkTreeSelection *selection, gpointer gdata)
buoh_view_set_comic (comic_list->priv->view, comic);
buoh_debug ("selection changed: set comic");
} else {
- buoh_view_clear (comic_list->priv->view);
+ if (comic_list->priv->view != NULL) {
+ buoh_view_clear (comic_list->priv->view);
+ }
}
}
@@ -91,53 +92,13 @@ buoh_comic_list_visible (GtkTreeModel *model,
static void
buoh_comic_list_init (BuohComicList *buoh_comic_list)
{
- GtkTreeModel *model;
- GtkCellRenderer *renderer;
- GtkTreeViewColumn *column;
- GtkTreeSelection *selection;
buoh_comic_list->priv = buoh_comic_list_get_instance_private (buoh_comic_list);
buoh_comic_list->priv->comic_manager = NULL;
buoh_comic_list->priv->view = NULL;
- model = buoh_get_comics_model (BUOH);
- buoh_comic_list->priv->model = gtk_tree_model_filter_new (model, NULL);
- gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (buoh_comic_list->priv->model),
- buoh_comic_list_visible,
- NULL, NULL);
-
- buoh_comic_list->priv->tree_view = gtk_tree_view_new_with_model (buoh_comic_list->priv->model);
- renderer = gtk_cell_renderer_text_new ();
- g_object_set (G_OBJECT (renderer),
- "ellipsize-set", TRUE,
- "ellipsize", PANGO_ELLIPSIZE_END,
- NULL);
- column = gtk_tree_view_column_new_with_attributes (_("Title"), renderer,
- "text", COMIC_LIST_TITLE,
- NULL);
- gtk_tree_view_insert_column (GTK_TREE_VIEW (buoh_comic_list->priv->tree_view),
- column, COMIC_LIST_TITLE);
-
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (buoh_comic_list->priv->tree_view));
- g_signal_connect (selection, "changed",
- G_CALLBACK (buoh_comic_list_selection_changed),
- (gpointer) buoh_comic_list);
-
- buoh_comic_list->priv->swindow = gtk_scrolled_window_new (NULL, NULL);
- gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (buoh_comic_list->priv->swindow),
- GTK_POLICY_AUTOMATIC,
- GTK_POLICY_AUTOMATIC);
- gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (buoh_comic_list->priv->swindow),
- GTK_SHADOW_IN);
- gtk_container_add (GTK_CONTAINER (buoh_comic_list->priv->swindow),
- buoh_comic_list->priv->tree_view);
- gtk_widget_show (buoh_comic_list->priv->tree_view);
-
- gtk_container_add (GTK_CONTAINER (buoh_comic_list), buoh_comic_list->priv->swindow);
- gtk_widget_show (buoh_comic_list->priv->swindow);
-
- gtk_widget_show (GTK_WIDGET (buoh_comic_list));
+ gtk_widget_init_template (GTK_WIDGET (buoh_comic_list));
}
static void
@@ -150,6 +111,12 @@ buoh_comic_list_class_init (BuohComicListClass *klass)
widget_class->size_allocate = buoh_comic_list_size_allocate;
object_class->finalize = buoh_comic_list_finalize;
+
+ gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/buoh/ui/comic-list.ui");
+
+ gtk_widget_class_bind_template_child_private (widget_class, BuohComicList, tree_view);
+
+ gtk_widget_class_bind_template_callback (widget_class, buoh_comic_list_selection_changed);
}
static void
@@ -215,12 +182,7 @@ buoh_comic_list_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
GtkWidget *
buoh_comic_list_new (void)
{
- GtkWidget *buoh_comic_list;
-
- buoh_comic_list = GTK_WIDGET (g_object_new (BUOH_TYPE_COMIC_LIST,
- "border-width", 6,
- NULL));
- return buoh_comic_list;
+ return GTK_WIDGET (g_object_new (BUOH_TYPE_COMIC_LIST, NULL));
}
void
@@ -236,6 +198,21 @@ buoh_comic_list_set_view (BuohComicList *comic_list, BuohView *view)
comic_list->priv->view = view;
}
+void
+buoh_comic_list_set_model (BuohComicList *comic_list, GtkTreeModel *model)
+{
+ g_return_if_fail (BUOH_IS_COMIC_LIST (comic_list));
+ g_return_if_fail (GTK_IS_TREE_MODEL (model));
+
+ comic_list->priv->model = gtk_tree_model_filter_new (model, NULL);
+ gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (comic_list->priv->model),
+ buoh_comic_list_visible,
+ NULL, NULL);
+
+ gtk_tree_view_set_model (GTK_TREE_VIEW (comic_list->priv->tree_view),
+ comic_list->priv->model);
+}
+
GtkWidget *
buoh_comic_list_get_list (BuohComicList *comic_list)
{
diff --git a/src/buoh-comic-list.h b/src/buoh-comic-list.h
index ccccc34..122539a 100644
--- a/src/buoh-comic-list.h
+++ b/src/buoh-comic-list.h
@@ -52,6 +52,8 @@ GtkWidget *buoh_comic_list_new (void);
void buoh_comic_list_set_view (BuohComicList *comic_list,
BuohView *view);
+void buoh_comic_list_set_model (BuohComicList *comic_list,
+ GtkTreeModel *model);
GtkWidget *buoh_comic_list_get_list (BuohComicList *comic_list);
void buoh_comic_list_clear_selection (BuohComicList *comic_list);
BuohComicManager *buoh_comic_list_get_selected (BuohComicList *comic_list);
diff --git a/src/buoh-window.c b/src/buoh-window.c
index c133b88..3500ba1 100644
--- a/src/buoh-window.c
+++ b/src/buoh-window.c
@@ -232,6 +232,7 @@ static void
buoh_window_init (BuohWindow *buoh_window)
{
GtkWidget *tree_view;
+ GtkTreeModel *model;
GtkTreeSelection *selection;
GtkWidget *vbox, *paned, *menubar;
GtkWidget *toolbar;
@@ -346,6 +347,8 @@ buoh_window_init (BuohWindow *buoh_window)
/* buoh comic list */
buoh_window->priv->comic_list = BUOH_COMIC_LIST (buoh_comic_list_new ());
+ model = buoh_get_comics_model (BUOH);
+ buoh_comic_list_set_model (buoh_window->priv->comic_list, model);
buoh_comic_list_set_view (buoh_window->priv->comic_list, buoh_window->priv->view);
gtk_paned_pack1 (GTK_PANED (paned), GTK_WIDGET (buoh_window->priv->comic_list),
TRUE, FALSE);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]