Revert "git: Use combo box instead of tree view for remotes"
[anjuta.git] / plugins / git / git-remotes-pane.c
blob7cfae46767c98896a17cc68546450da73d24e962
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 * anjuta
4 * Copyright (C) James Liggett 2010 <jrliggett@cox.net>
5 *
6 * anjuta is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * anjuta is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 * See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "git-remotes-pane.h"
22 struct _GitRemotesPanePriv
24 GtkBuilder *builder;
25 gchar *selected_remote;
28 G_DEFINE_TYPE (GitRemotesPane, git_remotes_pane, GIT_TYPE_PANE);
30 static gboolean
31 on_remote_selected (GtkTreeSelection *selection, GtkTreeModel *model,
32 GtkTreePath *path, gboolean path_currently_selected,
33 GitRemotesPane *self)
35 GtkTreeIter iter;
37 if (!path_currently_selected)
39 gtk_tree_model_get_iter (model, &iter, path);
41 g_free (self->priv->selected_remote);
42 gtk_tree_model_get (model, &iter, 0, &(self->priv->selected_remote), -1);
44 anjuta_dock_pane_notify_single_selection_changed (ANJUTA_DOCK_PANE (self));
47 return TRUE;
50 static void
51 git_remotes_pane_init (GitRemotesPane *self)
53 gchar *objects[] = {"remotes_pane",
54 "remotes_list_model",
55 NULL};
56 GError *error = NULL;
57 GtkTreeView *remotes_view;
58 GtkTreeSelection *selection;
60 self->priv = g_new0 (GitRemotesPanePriv, 1);
61 self->priv->builder = gtk_builder_new ();
63 if (!gtk_builder_add_objects_from_file (self->priv->builder, BUILDER_FILE,
64 objects,
65 &error))
67 g_warning ("Couldn't load builder file: %s", error->message);
68 g_error_free (error);
71 remotes_view = GTK_TREE_VIEW (gtk_builder_get_object (self->priv->builder,
72 "remotes_view"));
73 selection = gtk_tree_view_get_selection (remotes_view);
76 gtk_tree_selection_set_select_function (selection,
77 (GtkTreeSelectionFunc) on_remote_selected,
78 self, NULL);
81 static void
82 git_remotes_pane_finalize (GObject *object)
84 GitRemotesPane *self;
86 self = GIT_REMOTES_PANE (object);
88 g_object_unref (self->priv->builder);
89 g_free (self->priv->selected_remote);
90 g_free (self->priv);
92 G_OBJECT_CLASS (git_remotes_pane_parent_class)->finalize (object);
95 static GtkWidget *
96 git_remotes_pane_get_widget (AnjutaDockPane *pane)
98 GitRemotesPane *self;
100 self = GIT_REMOTES_PANE (pane);
102 return GTK_WIDGET (gtk_builder_get_object (self->priv->builder,
103 "remotes_pane"));
106 static void
107 git_remotes_pane_class_init (GitRemotesPaneClass *klass)
109 GObjectClass* object_class = G_OBJECT_CLASS (klass);
110 AnjutaDockPaneClass* pane_class = ANJUTA_DOCK_PANE_CLASS (klass);
112 object_class->finalize = git_remotes_pane_finalize;
113 pane_class->get_widget = git_remotes_pane_get_widget;
114 pane_class->refresh = NULL;
117 static void
118 on_remote_list_command_data_arrived (AnjutaCommand *command,
119 GitRemotesPane *self)
121 GtkListStore *remotes_list_model;
122 GQueue *output;
123 gchar *remote;
124 GtkTreeIter iter;
126 remotes_list_model = GTK_LIST_STORE (gtk_builder_get_object (self->priv->builder,
127 "remotes_list_model"));
128 output = git_raw_output_command_get_output (GIT_RAW_OUTPUT_COMMAND (command));
130 while (g_queue_peek_head (output))
132 remote = g_queue_pop_head (output);
134 gtk_list_store_append (remotes_list_model, &iter);
135 gtk_list_store_set (remotes_list_model, &iter, 0, remote, -1);
137 g_free (remote);
141 AnjutaDockPane *
142 git_remotes_pane_new (Git *plugin)
144 GitRemotesPane *self;
145 GtkListStore *remotes_list_model;
147 self = g_object_new (GIT_TYPE_REMOTES_PANE, "plugin", plugin, NULL);
148 remotes_list_model = GTK_LIST_STORE (gtk_builder_get_object (self->priv->builder,
149 "remotes_list_model"));
151 g_signal_connect_swapped (G_OBJECT (plugin->remote_list_command),
152 "command-started",
153 G_CALLBACK (gtk_list_store_clear),
154 remotes_list_model);
156 g_signal_connect (G_OBJECT (plugin->remote_list_command), "data-arrived",
157 G_CALLBACK (on_remote_list_command_data_arrived),
158 self);
160 return ANJUTA_DOCK_PANE (self);
163 gchar *
164 git_remotes_pane_get_selected_remote (GitRemotesPane *self)
166 return g_strdup (self->priv->selected_remote);