diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ephy-state.c | 58 | ||||
-rw-r--r-- | lib/ephy-state.h | 4 | ||||
-rw-r--r-- | lib/widgets/ephy-node-view.c | 79 | ||||
-rw-r--r-- | lib/widgets/ephy-node-view.h | 15 |
4 files changed, 104 insertions, 52 deletions
diff --git a/lib/ephy-state.c b/lib/ephy-state.c index 5debe8cf5..e89c2db88 100644 --- a/lib/ephy-state.c +++ b/lib/ephy-state.c @@ -26,6 +26,7 @@ #include <string.h> #include <gtk/gtkwindow.h> +#include <gtk/gtkpaned.h> #define STATES_FILE "states.xml" @@ -270,6 +271,63 @@ ephy_state_add_window (GtkWidget *window, G_CALLBACK (window_state_event_cb), node, 0); } +static gboolean +paned_size_allocate_cb (GtkWidget *paned, + GtkAllocation *allocation, + EphyNode *node) +{ + int width; + GValue value = { 0, }; + + width = gtk_paned_get_position (GTK_PANED (paned)); + + g_value_init (&value, G_TYPE_INT); + g_value_set_int (&value, width); + ephy_node_set_property (node, EPHY_NODE_STATE_PROP_WIDTH, + &value); + g_value_unset (&value); + + return FALSE; +} + +void +ephy_state_add_paned (GtkWidget *paned, + const char *name, + int default_width) +{ + EphyNode *node; + int width; + + ensure_states (); + + node = find_by_name (name); + if (node == NULL) + { + GValue value = { 0, }; + + node = ephy_node_new (); + ephy_node_add_child (states, node); + + g_value_init (&value, G_TYPE_STRING); + g_value_set_string (&value, name); + ephy_node_set_property (node, EPHY_NODE_STATE_PROP_NAME, + &value); + g_value_unset (&value); + + g_value_init (&value, G_TYPE_INT); + g_value_set_int (&value, default_width); + ephy_node_set_property (node, EPHY_NODE_STATE_PROP_WIDTH, + &value); + g_value_unset (&value); + } + + width = ephy_node_get_property_int (node, EPHY_NODE_STATE_PROP_WIDTH); + gtk_paned_set_position (GTK_PANED (paned), width); + + g_signal_connect_object (paned, "size_allocate", + G_CALLBACK (paned_size_allocate_cb), node, 0); +} + void ephy_state_save (void) { diff --git a/lib/ephy-state.h b/lib/ephy-state.h index 7e05e6106..9d6388ac4 100644 --- a/lib/ephy-state.h +++ b/lib/ephy-state.h @@ -31,6 +31,10 @@ void ephy_state_add_window (GtkWidget *window, int default_width, int default_heigth); +void ephy_state_add_paned (GtkWidget *paned, + const char *name, + int default_width); + void ephy_state_save (void); G_END_DECLS diff --git a/lib/widgets/ephy-node-view.c b/lib/widgets/ephy-node-view.c index 1d8eba5cd..3d52afd21 100644 --- a/lib/widgets/ephy-node-view.c +++ b/lib/widgets/ephy-node-view.c @@ -64,7 +64,6 @@ struct EphyNodeViewPrivate int default_sort_column_id; int priority_prop_id; - int priority_column_id; gboolean editing; int editable_property; @@ -659,7 +658,6 @@ ephy_node_view_sort_func (GtkTreeModel *model, GValue a_value = {0, }; GValue b_value = {0, }; gchar *stra, *strb; - gtk_tree_model_get_value (model, a, column, &a_value); gtk_tree_model_get_value (model, b, column, &b_value); @@ -702,24 +700,6 @@ ephy_node_view_sort_func (GtkTreeModel *model, } -static gboolean -set_sort_column_id (EphyNodeView *view) -{ - GList *sort_order = NULL; - sort_order = g_list_append (sort_order, GINT_TO_POINTER (view->priv->priority_column_id)); - sort_order = g_list_append (sort_order, GINT_TO_POINTER (view->priv->default_sort_column_id)); - - gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (view->priv->sortmodel), - GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, - GTK_SORT_ASCENDING); - gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (view->priv->sortmodel), - ephy_node_view_sort_func, - sort_order, - (GtkDestroyNotify) g_list_free); - - return FALSE; -} - static void provide_priority (EphyNode *node, GValue *value, EphyNodeView *view) { @@ -744,9 +724,13 @@ provide_text_weight (EphyNode *node, GValue *value, EphyNodeView *view) (node, view->priv->priority_prop_id); if (priority == EPHY_NODE_VIEW_ALL_PRIORITY || priority == EPHY_NODE_VIEW_SPECIAL_PRIORITY) + { g_value_set_int (value, PANGO_WEIGHT_BOLD); + } else + { g_value_set_int (value, PANGO_WEIGHT_NORMAL); + } } GtkTreeViewColumn * @@ -755,14 +739,14 @@ ephy_node_view_add_column (EphyNodeView *view, GType value_type, int prop_id, int priority_prop_id, - gboolean editable, - gboolean sortable) + EphyNodeViewFlags flags) { GtkTreeViewColumn *gcolumn; GtkCellRenderer *renderer; int column; - g_return_val_if_fail (!editable || view->priv->editable_renderer == NULL, NULL); + g_return_val_if_fail (!(flags & EPHY_NODE_VIEW_EDITABLE) || + view->priv->editable_renderer == NULL, NULL); column = ephy_tree_model_node_add_prop_column (view->priv->nodemodel, value_type, prop_id); @@ -770,7 +754,7 @@ ephy_node_view_add_column (EphyNodeView *view, gcolumn = (GtkTreeViewColumn *) gtk_tree_view_column_new (); renderer = gtk_cell_renderer_text_new (); - if (editable) + if (flags & EPHY_NODE_VIEW_EDITABLE) { view->priv->editable_renderer = renderer; view->priv->editable_column = gcolumn; @@ -782,10 +766,12 @@ ephy_node_view_add_column (EphyNodeView *view, gtk_tree_view_column_set_attributes (gcolumn, renderer, "text", column, NULL); - if (priority_prop_id > 0) + if (priority_prop_id >= 0) { int wcol; + view->priv->priority_prop_id = priority_prop_id; + wcol = ephy_tree_model_node_add_func_column (view->priv->nodemodel, G_TYPE_INT, (EphyTreeModelNodeValueFunc) provide_text_weight, @@ -794,25 +780,41 @@ ephy_node_view_add_column (EphyNodeView *view, "weight", wcol); } - gtk_tree_view_column_set_sizing (gcolumn, - GTK_TREE_VIEW_COLUMN_AUTOSIZE); gtk_tree_view_column_set_title (gcolumn, title); gtk_tree_view_append_column (GTK_TREE_VIEW (view), gcolumn); - if (sortable) + if (flags & EPHY_NODE_VIEW_USER_SORT) + { + GList *order = NULL; + + order = g_list_append (order, GINT_TO_POINTER (column)); + gtk_tree_sortable_set_sort_func + (GTK_TREE_SORTABLE (view->priv->sortmodel), + column, ephy_node_view_sort_func, + order, (GtkDestroyNotify)g_list_free); + gtk_tree_view_column_set_sort_column_id (gcolumn, column); + } + else if (flags & EPHY_NODE_VIEW_AUTO_SORT) { int scol; + GList *order = NULL; scol = ephy_tree_model_node_add_func_column (view->priv->nodemodel, G_TYPE_INT, (EphyTreeModelNodeValueFunc) provide_priority, view); - view->priv->priority_column_id = scol; - view->priv->priority_prop_id = priority_prop_id; - view->priv->default_sort_column_id = column; - g_idle_add ((GSourceFunc) set_sort_column_id, view); + order = g_list_append (order, GINT_TO_POINTER (scol)); + order = g_list_append (order, GINT_TO_POINTER (column)); + gtk_tree_sortable_set_default_sort_func + (GTK_TREE_SORTABLE (view->priv->sortmodel), + ephy_node_view_sort_func, + order, (GtkDestroyNotify)g_list_free); + gtk_tree_sortable_set_sort_column_id + (GTK_TREE_SORTABLE (view->priv->sortmodel), + GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, + GTK_SORT_ASCENDING); } return gcolumn; @@ -1084,16 +1086,3 @@ ephy_node_view_has_selection (EphyNodeView *view, gboolean *multiple) return rows > 0; } - -void -ephy_node_view_enable_sort (EphyNodeView *view, - GtkTreeIterCompareFunc sort_func, - gpointer data, - GtkDestroyNotify destroy) -{ - gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (view->priv->sortmodel), - GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, - GTK_SORT_ASCENDING); - gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (view->priv->sortmodel), - sort_func, data, destroy); -} diff --git a/lib/widgets/ephy-node-view.h b/lib/widgets/ephy-node-view.h index 148b376b1..47a71d463 100644 --- a/lib/widgets/ephy-node-view.h +++ b/lib/widgets/ephy-node-view.h @@ -52,6 +52,13 @@ typedef enum EPHY_NODE_VIEW_NORMAL_PRIORITY } EphyNodeViewPriority; +typedef enum +{ + EPHY_NODE_VIEW_AUTO_SORT = 1, + EPHY_NODE_VIEW_USER_SORT = 2, + EPHY_NODE_VIEW_EDITABLE = 4 +} EphyNodeViewFlags; + typedef struct { GtkTreeViewClass parent; @@ -74,8 +81,7 @@ GtkTreeViewColumn *ephy_node_view_add_column (EphyNodeView *view, GType value_type, int prop_id, int priority_prop_id, - gboolean editable, - gboolean sortable); + EphyNodeViewFlags flags); void ephy_node_view_add_icon_column (EphyNodeView *view, EphyTreeModelNodeValueFunc func); @@ -106,11 +112,6 @@ gboolean ephy_node_view_is_editing (EphyNodeView *view, gboolean ephy_node_view_is_target (EphyNodeView *view); -void ephy_node_view_enable_sort (EphyNodeView *view, - GtkTreeIterCompareFunc sort_func, - gpointer data, - GtkDestroyNotify destroy); - G_END_DECLS #endif /* EPHY_NODE_VIEW_H */ |