git: Implement the add files pane
[anjuta.git] / plugins / git / git-add-files-pane.c
blob9f13516289615efa5ecdb87ec5ff86ca13c925f8
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-add-files-pane.h"
22 struct _GitAddFilesPanePriv
24 GtkBuilder *builder;
27 G_DEFINE_TYPE (GitAddFilesPane, git_add_files_pane, GIT_TYPE_PANE);
29 static void
30 on_ok_button_clicked (GtkButton *button, GitAddFilesPane *self)
32 Git *plugin;
33 AnjutaFileList *file_list;
34 GtkToggleButton *force_check;
35 GList *paths;
36 GitAddCommand *add_command;
38 plugin = ANJUTA_PLUGIN_GIT (anjuta_dock_pane_get_plugin (ANJUTA_DOCK_PANE (self)));
39 file_list = ANJUTA_FILE_LIST (gtk_builder_get_object (self->priv->builder,
40 "file_list"));
41 force_check = GTK_TOGGLE_BUTTON (gtk_builder_get_object (self->priv->builder,
42 "force_check"));
43 paths = anjuta_file_list_get_paths (file_list);
44 add_command = git_add_command_new_list (plugin->project_root_directory,
45 paths,
46 gtk_toggle_button_get_active (force_check));
48 git_command_free_string_list (paths);
50 g_signal_connect (G_OBJECT (add_command), "command-finished",
51 G_CALLBACK (g_object_unref),
52 NULL);
54 anjuta_command_start (ANJUTA_COMMAND (add_command));
56 anjuta_dock_remove_pane (ANJUTA_DOCK (plugin->dock),
57 ANJUTA_DOCK_PANE (self));
60 static void
61 on_cancel_button_clicked (GtkButton *button, GitAddFilesPane *self)
63 Git *plugin;
65 plugin = ANJUTA_PLUGIN_GIT (anjuta_dock_pane_get_plugin (ANJUTA_DOCK_PANE (self)));
67 anjuta_dock_remove_pane (ANJUTA_DOCK (plugin->dock),
68 ANJUTA_DOCK_PANE (self));
71 static void
72 git_add_files_pane_init (GitAddFilesPane *self)
74 gchar *objects[] = {"add_pane",
75 NULL};
76 GError *error = NULL;
77 GtkWidget *ok_button;
78 GtkWidget *cancel_button;
80 self->priv = g_new0 (GitAddFilesPanePriv, 1);
81 self->priv->builder = gtk_builder_new ();
83 if (!gtk_builder_add_objects_from_file (self->priv->builder, BUILDER_FILE,
84 objects,
85 &error))
87 g_warning ("Couldn't load builder file: %s", error->message);
88 g_error_free (error);
91 ok_button = GTK_WIDGET (gtk_builder_get_object (self->priv->builder,
92 "ok_button"));
93 cancel_button = GTK_WIDGET (gtk_builder_get_object (self->priv->builder,
94 "cancel_button"));
96 g_signal_connect (G_OBJECT (ok_button), "clicked",
97 G_CALLBACK (on_ok_button_clicked),
98 self);
100 g_signal_connect (G_OBJECT (cancel_button), "clicked",
101 G_CALLBACK (on_cancel_button_clicked),
102 self);
105 static void
106 git_add_files_pane_finalize (GObject *object)
108 GitAddFilesPane *self;
110 self = GIT_ADD_FILES_PANE (object);
112 g_object_unref (self->priv->builder);
113 g_free (self->priv);
115 G_OBJECT_CLASS (git_add_files_pane_parent_class)->finalize (object);
118 static GtkWidget *
119 git_add_files_pane_get_widget (AnjutaDockPane *pane)
121 GitAddFilesPane *self;
123 self = GIT_ADD_FILES_PANE (pane);
125 return GTK_WIDGET (gtk_builder_get_object (self->priv->builder,
126 "add_pane"));
129 static void
130 git_add_files_pane_class_init (GitAddFilesPaneClass *klass)
132 GObjectClass* object_class = G_OBJECT_CLASS (klass);
133 AnjutaDockPaneClass* pane_class = ANJUTA_DOCK_PANE_CLASS (klass);
135 object_class->finalize = git_add_files_pane_finalize;
136 pane_class->get_widget = git_add_files_pane_get_widget;
137 pane_class->refresh = NULL;
140 AnjutaDockPane *
141 git_add_files_pane_new (Git *plugin)
143 GitAddFilesPane *self;
144 AnjutaFileList *file_list;
146 self = g_object_new (GIT_TYPE_ADD_FILES_PANE, "plugin", plugin, NULL);
147 file_list = ANJUTA_FILE_LIST (gtk_builder_get_object (self->priv->builder,
148 "file_list"));
150 anjuta_file_list_set_relative_path (file_list,
151 plugin->project_root_directory);
153 return ANJUTA_DOCK_PANE (self);
156 void
157 on_add_button_clicked (GtkAction *action, Git* plugin)
159 AnjutaDockPane *pane;
161 pane = git_add_files_pane_new (plugin);
163 anjuta_dock_add_pane (ANJUTA_DOCK (plugin->dock), "AddFiles",
164 _("Add Files"), NULL, pane, GDL_DOCK_BOTTOM,
165 NULL, 0, NULL);