1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 * Copyright (C) James Liggett 2007 <jrliggett@cox.net>
6 * anjuta is free software.
8 * You may redistribute it and/or modify it under the terms of the
9 * GNU General Public License, as published by the Free Software
10 * Foundation; either version 2 of the License, or (at your option)
13 * anjuta is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 * See the GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with anjuta. If not, write to:
20 * The Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor
22 * Boston, MA 02110-1301, USA.
25 #include "anjuta-vcs-status-tree-view.h"
37 ANJUTA_VCS_STATUS_TREE_VIEW_CONSTRUCT_STATUS_CODES
= 1,
38 ANJUTA_VCS_STATUS_TREE_VIEW_SHOW_STATUS
41 struct _AnjutaVcsStatusTreeViewPriv
44 GHashTable
*selected_paths
;
49 G_DEFINE_TYPE (AnjutaVcsStatusTreeView
, anjuta_vcs_status_tree_view
,
53 on_selected_column_toggled (GtkCellRendererToggle
*renderer
,
55 AnjutaVcsStatusTreeView
*self
)
61 gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (self
->priv
->store
),
64 gtk_tree_model_get (GTK_TREE_MODEL (self
->priv
->store
), &iter
,
66 COL_SELECTED
, &selected
, -1);
68 gtk_list_store_set (self
->priv
->store
, &iter
,
69 COL_SELECTED
, !selected
, -1);
76 anjuta_vcs_status_tree_view_create_columns (AnjutaVcsStatusTreeView
*self
)
78 GtkTreeViewColumn
*column
;
79 GtkCellRenderer
*renderer
;
82 column
= gtk_tree_view_column_new ();
83 renderer
= gtk_cell_renderer_toggle_new ();
84 gtk_tree_view_column_pack_start (column
, renderer
, TRUE
);
85 gtk_tree_view_append_column (GTK_TREE_VIEW (self
), column
);
86 gtk_tree_view_column_add_attribute (column
, renderer
, "active",
89 g_signal_connect (G_OBJECT (renderer
), "toggled",
90 G_CALLBACK (on_selected_column_toggled
),
94 column
= gtk_tree_view_column_new ();
95 renderer
= gtk_cell_renderer_text_new ();
96 gtk_tree_view_column_pack_start (column
, renderer
, TRUE
);
97 gtk_tree_view_append_column (GTK_TREE_VIEW (self
), column
);
98 gtk_tree_view_column_add_attribute (column
, renderer
, "text",
102 column
= gtk_tree_view_column_new ();
103 renderer
= gtk_cell_renderer_text_new ();
104 gtk_tree_view_column_pack_start (column
, renderer
, TRUE
);
105 gtk_tree_view_append_column (GTK_TREE_VIEW (self
), column
);
106 gtk_tree_view_column_add_attribute (column
, renderer
, "text",
109 gtk_tree_view_set_model (GTK_TREE_VIEW (self
),
110 GTK_TREE_MODEL (self
->priv
->store
));
111 g_object_unref (self
->priv
->store
);
116 path_sort (GtkTreeModel
*model
, GtkTreeIter
*a
, GtkTreeIter
*b
,
123 gtk_tree_model_get (model
, a
, COL_PATH
, &path1
, -1);
124 gtk_tree_model_get (model
, b
, COL_PATH
, &path2
, -1);
126 compare_value
= strcmp (path1
, path2
);
131 return compare_value
;
135 anjuta_vcs_status_tree_view_init (AnjutaVcsStatusTreeView
*self
)
137 GtkTreeSortable
*sortable
;
139 self
->priv
= g_new0 (AnjutaVcsStatusTreeViewPriv
, 1);
140 self
->priv
->store
= gtk_list_store_new (NUM_COLS
,
144 self
->priv
->selected_paths
= g_hash_table_new_full (g_str_hash
,
149 anjuta_vcs_status_tree_view_create_columns (self
);
150 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (self
), FALSE
);
152 sortable
= GTK_TREE_SORTABLE (self
->priv
->store
);
153 gtk_tree_sortable_set_sort_column_id (sortable
, COL_PATH
,
155 gtk_tree_sortable_set_sort_func (sortable
, COL_PATH
, path_sort
, NULL
,
160 anjuta_vcs_status_tree_view_finalize (GObject
*object
)
162 AnjutaVcsStatusTreeView
*self
;
164 self
= ANJUTA_VCS_STATUS_TREE_VIEW (object
);
166 g_hash_table_destroy (self
->priv
->selected_paths
);
169 G_OBJECT_CLASS (anjuta_vcs_status_tree_view_parent_class
)->finalize (object
);
173 anjuta_vcs_status_tree_view_set_property (GObject
*object
, guint property_id
,
175 GParamSpec
*param_spec
)
177 AnjutaVcsStatusTreeView
*self
;
178 GtkTreeView
*tree_view
;
179 GtkTreeViewColumn
*column
;
181 self
= ANJUTA_VCS_STATUS_TREE_VIEW (object
);
185 case ANJUTA_VCS_STATUS_TREE_VIEW_CONSTRUCT_STATUS_CODES
:
186 self
->priv
->status_codes
= g_value_get_flags (value
);
188 case ANJUTA_VCS_STATUS_TREE_VIEW_SHOW_STATUS
:
189 tree_view
= GTK_TREE_VIEW (object
);
190 column
= gtk_tree_view_get_column (tree_view
, COL_STATUS
);
191 self
->priv
->show_status
= g_value_get_boolean (value
);
193 gtk_tree_view_column_set_visible (column
, self
->priv
->show_status
);
196 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, property_id
, param_spec
);
202 anjuta_vcs_status_tree_view_get_property (GObject
*object
, guint property_id
,
203 GValue
*value
, GParamSpec
*param_spec
)
205 AnjutaVcsStatusTreeView
*self
;
207 self
= ANJUTA_VCS_STATUS_TREE_VIEW (object
);
211 case ANJUTA_VCS_STATUS_TREE_VIEW_CONSTRUCT_STATUS_CODES
:
212 g_value_set_flags (value
, self
->priv
->status_codes
);
214 case ANJUTA_VCS_STATUS_TREE_VIEW_SHOW_STATUS
:
215 g_value_set_boolean (value
, self
->priv
->show_status
);
218 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, property_id
, param_spec
);
224 anjuta_vcs_status_tree_view_class_init (AnjutaVcsStatusTreeViewClass
*klass
)
226 GObjectClass
* object_class
= G_OBJECT_CLASS (klass
);
227 GParamSpec
*param_spec
;
229 object_class
->finalize
= anjuta_vcs_status_tree_view_finalize
;
230 object_class
->get_property
= anjuta_vcs_status_tree_view_get_property
;
231 object_class
->set_property
= anjuta_vcs_status_tree_view_set_property
;
233 param_spec
= g_param_spec_flags ("status-codes", "Status codes",
234 "Control which status codes are shown in "
236 ANJUTA_TYPE_VCS_STATUS
,
237 ANJUTA_VCS_DEFAULT_STATUS_CODES
,
239 G_PARAM_CONSTRUCT_ONLY
);
240 g_object_class_install_property (object_class
,
241 ANJUTA_VCS_STATUS_TREE_VIEW_CONSTRUCT_STATUS_CODES
,
244 param_spec
= g_param_spec_boolean ("show-status", "Show status",
245 "Show or hide status description",
248 g_object_class_install_property (object_class
,
249 ANJUTA_VCS_STATUS_TREE_VIEW_SHOW_STATUS
,
255 anjuta_vcs_status_tree_view_new (void)
257 return g_object_new (ANJUTA_VCS_TYPE_STATUS_TREE_VIEW
, NULL
);
261 anjuta_vcs_status_tree_view_destroy (AnjutaVcsStatusTreeView
*self
)
263 g_object_unref (self
);
267 anjuta_vcs_status_tree_view_add (AnjutaVcsStatusTreeView
*self
, gchar
*path
,
268 AnjutaVcsStatus status
, gboolean selected
)
272 if (status
& self
->priv
->status_codes
)
274 gtk_list_store_append (self
->priv
->store
, &iter
);
276 gtk_list_store_set (self
->priv
->store
, &iter
,
277 COL_SELECTED
, selected
,
283 g_hash_table_insert (self
->priv
->selected_paths
, g_strdup (path
),
289 case ANJUTA_VCS_STATUS_MODIFIED
:
290 gtk_list_store_set (self
->priv
->store
, &iter
, COL_STATUS
,
293 case ANJUTA_VCS_STATUS_ADDED
:
294 gtk_list_store_set (self
->priv
->store
, &iter
, COL_STATUS
,
297 case ANJUTA_VCS_STATUS_DELETED
:
298 gtk_list_store_set (self
->priv
->store
, &iter
, COL_STATUS
,
301 case ANJUTA_VCS_STATUS_CONFLICTED
:
302 gtk_list_store_set (self
->priv
->store
, &iter
, COL_STATUS
,
305 case ANJUTA_VCS_STATUS_MISSING
:
306 gtk_list_store_set (self
->priv
->store
, &iter
, COL_STATUS
,
309 case ANJUTA_VCS_STATUS_NONE
:
318 select_all_paths (GtkTreeModel
*model
, GtkTreePath
*path
, GtkTreeIter
*iter
,
319 AnjutaVcsStatusTreeView
*self
)
321 gtk_list_store_set (self
->priv
->store
, iter
,
329 anjuta_vcs_status_tree_view_select_all (AnjutaVcsStatusTreeView
*self
)
331 gtk_tree_model_foreach (GTK_TREE_MODEL (self
->priv
->store
),
332 (GtkTreeModelForeachFunc
) select_all_paths
,
337 unselect_all_paths (GtkTreeModel
*model
, GtkTreePath
*path
, GtkTreeIter
*iter
,
338 AnjutaVcsStatusTreeView
*self
)
340 gtk_list_store_set (self
->priv
->store
, iter
,
348 anjuta_vcs_status_tree_view_unselect_all (AnjutaVcsStatusTreeView
*self
)
350 gtk_tree_model_foreach (GTK_TREE_MODEL (self
->priv
->store
),
351 (GtkTreeModelForeachFunc
) unselect_all_paths
,
356 create_selected_paths_list (GtkTreeModel
*model
, GtkTreePath
*path
,
357 GtkTreeIter
*iter
, GList
**list
)
362 gtk_tree_model_get (model
, iter
,
363 COL_SELECTED
, &selected
,
364 COL_PATH
, &file_path
,
368 *list
= g_list_append (*list
, g_strdup (file_path
));
374 anjuta_vcs_status_tree_view_get_selected (AnjutaVcsStatusTreeView
*self
)
380 gtk_tree_model_foreach (GTK_TREE_MODEL (self
->priv
->store
),
381 (GtkTreeModelForeachFunc
) create_selected_paths_list
,