1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 * Copyright (C) James Liggett 2010 <jrliggett@cox.net>
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
25 gchar
*selected_remote
;
28 G_DEFINE_TYPE (GitRemotesPane
, git_remotes_pane
, GIT_TYPE_PANE
);
31 on_remote_selected (GtkTreeSelection
*selection
, GtkTreeModel
*model
,
32 GtkTreePath
*path
, gboolean path_currently_selected
,
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
));
51 git_remotes_pane_init (GitRemotesPane
*self
)
53 gchar
*objects
[] = {"remotes_pane",
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
,
67 g_warning ("Couldn't load builder file: %s", error
->message
);
71 remotes_view
= GTK_TREE_VIEW (gtk_builder_get_object (self
->priv
->builder
,
73 selection
= gtk_tree_view_get_selection (remotes_view
);
76 gtk_tree_selection_set_select_function (selection
,
77 (GtkTreeSelectionFunc
) on_remote_selected
,
82 git_remotes_pane_finalize (GObject
*object
)
86 self
= GIT_REMOTES_PANE (object
);
88 g_object_unref (self
->priv
->builder
);
89 g_free (self
->priv
->selected_remote
);
92 G_OBJECT_CLASS (git_remotes_pane_parent_class
)->finalize (object
);
96 git_remotes_pane_get_widget (AnjutaDockPane
*pane
)
100 self
= GIT_REMOTES_PANE (pane
);
102 return GTK_WIDGET (gtk_builder_get_object (self
->priv
->builder
,
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
;
118 on_remote_list_command_data_arrived (AnjutaCommand
*command
,
119 GitRemotesPane
*self
)
121 GtkListStore
*remotes_list_model
;
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);
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
),
153 G_CALLBACK (gtk_list_store_clear
),
156 g_signal_connect (G_OBJECT (plugin
->remote_list_command
), "data-arrived",
157 G_CALLBACK (on_remote_list_command_data_arrived
),
160 return ANJUTA_DOCK_PANE (self
);
164 git_remotes_pane_get_selected_remote (GitRemotesPane
*self
)
166 return g_strdup (self
->priv
->selected_remote
);