Implement support for listing and merging branches.
[anjuta-git-plugin.git] / plugins / git / git-branch-combo-model.c
blob83c9953aed5e146236e1a73f00533701e466944c
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 * anjuta
4 * Copyright (C) James Liggett 2008 <jrliggett@cox.net>
5 *
6 * anjuta is free software.
7 *
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)
11 * any later version.
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 "git-branch-combo-model.h"
27 enum
29 COL_ACTIVE,
30 COL_NAME,
32 NUM_COLS
35 GitBranchComboData *
36 git_branch_combo_data_new (GtkListStore *model, GtkComboBox *combo_box,
37 GladeXML *gxml, Git *plugin)
39 GitBranchComboData *data;
41 data = g_new0 (GitBranchComboData, 1);
42 data->model = model;
43 data->combo_box = combo_box;
44 data->gxml = gxml;
45 data->plugin = plugin;
47 return data;
50 void
51 git_branch_combo_data_free (GitBranchComboData *data)
53 g_object_unref (data->gxml);
54 g_free (data);
57 GtkListStore *
58 git_branch_combo_model_new (void)
60 return gtk_list_store_new (NUM_COLS, G_TYPE_STRING, G_TYPE_STRING);
63 void
64 git_branch_combo_model_setup_widget (GtkWidget *widget)
66 GtkCellRenderer *renderer;
68 /* Active column */
69 renderer = gtk_cell_renderer_pixbuf_new ();
70 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (widget), renderer, FALSE);
71 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (widget), renderer,
72 "stock-id", COL_ACTIVE);
74 /* Name column */
75 renderer = gtk_cell_renderer_text_new ();
76 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (widget), renderer, FALSE);
77 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (widget), renderer,
78 "text", COL_NAME);
81 void
82 git_branch_combo_model_append (GtkListStore *model, GitBranch *branch)
84 gchar *name;
85 GtkTreeIter iter;
87 name = git_branch_get_name (branch);
89 gtk_list_store_append (model, &iter);
90 gtk_list_store_set (model, &iter, COL_NAME, name, -1);
92 if (git_branch_is_active (branch))
93 gtk_list_store_set (model, &iter, COL_ACTIVE, GTK_STOCK_YES, -1);
95 g_free (name);
98 gchar *
99 git_branch_combo_model_get_branch (GtkListStore *model, GtkTreeIter *iter)
101 gchar *branch;
103 gtk_tree_model_get (GTK_TREE_MODEL (model), iter, COL_NAME, &branch, -1);
105 return branch;