Updated Spanish translation
[anjuta.git] / plugins / git / git-stash-changes-pane.c
blobc0d366e341a77437e45ea9d3ce2f4039b23ae0fc
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 * git-shell-test
4 * Copyright (C) James Liggett 2010 <jrliggett@cox.net>
5 *
6 * git-shell-test 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 * git-shell-test 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-stash-changes-pane.h"
22 struct _GitStashChangesPanePriv
24 GtkBuilder *builder;
27 G_DEFINE_TYPE (GitStashChangesPane, git_stash_changes_pane, GIT_TYPE_PANE);
29 static void
30 on_ok_action_activated (GtkAction *action, GitStashChangesPane *self)
32 Git *plugin;
33 AnjutaColumnTextView *message_view;
34 GtkToggleButton *stash_index_check;
35 gchar *message;
36 GitStashSaveCommand *save_command;
38 plugin = ANJUTA_PLUGIN_GIT (anjuta_dock_pane_get_plugin (ANJUTA_DOCK_PANE (self)));
39 message_view = ANJUTA_COLUMN_TEXT_VIEW (gtk_builder_get_object (self->priv->builder,
40 "message_view"));
41 stash_index_check = GTK_TOGGLE_BUTTON (gtk_builder_get_object (self->priv->builder,
42 "stash_index_check"));
43 message = anjuta_column_text_view_get_text (message_view);
45 /* Don't pass an empty message */
46 if (!g_utf8_strlen (message, -1))
48 g_free (message);
49 message = NULL;
52 save_command = git_stash_save_command_new (plugin->project_root_directory,
53 gtk_toggle_button_get_active (stash_index_check),
54 message);
56 g_free (message);
58 g_signal_connect (G_OBJECT (save_command), "command-finished",
59 G_CALLBACK (git_pane_report_errors),
60 plugin);
63 g_signal_connect (G_OBJECT (save_command), "command-finished",
64 G_CALLBACK (g_object_unref),
65 NULL);
67 anjuta_command_start (ANJUTA_COMMAND (save_command));
70 git_pane_remove_from_dock (GIT_PANE (self));
74 static void
75 git_stash_changes_pane_init (GitStashChangesPane *self)
77 gchar *objects[] = {"stash_changes_pane",
78 "ok_action",
79 "cancel_action",
80 NULL};
81 GError *error = NULL;
82 GtkAction *ok_action;
83 GtkAction *cancel_action;
85 self->priv = g_new0 (GitStashChangesPanePriv, 1);
86 self->priv->builder = gtk_builder_new ();
88 if (!gtk_builder_add_objects_from_file (self->priv->builder, BUILDER_FILE,
89 objects,
90 &error))
92 g_warning ("Couldn't load builder file: %s", error->message);
93 g_error_free (error);
96 ok_action = GTK_ACTION (gtk_builder_get_object (self->priv->builder,
97 "ok_action"));
98 cancel_action = GTK_ACTION (gtk_builder_get_object (self->priv->builder,
99 "cancel_action"));
101 g_signal_connect (G_OBJECT (ok_action), "activate",
102 G_CALLBACK (on_ok_action_activated),
103 self);
105 g_signal_connect_swapped (G_OBJECT (cancel_action), "activate",
106 G_CALLBACK (git_pane_remove_from_dock),
107 self);
110 static void
111 git_stash_changes_pane_finalize (GObject *object)
113 GitStashChangesPane *self;
115 self = GIT_STASH_CHANGES_PANE (object);
117 g_object_unref (self->priv->builder);
118 g_free (self->priv);
120 G_OBJECT_CLASS (git_stash_changes_pane_parent_class)->finalize (object);
123 static GtkWidget *
124 get_widget (AnjutaDockPane *pane)
126 GitStashChangesPane *self;
128 self = GIT_STASH_CHANGES_PANE (pane);
130 return GTK_WIDGET (gtk_builder_get_object (self->priv->builder,
131 "stash_changes_pane"));
134 static void
135 git_stash_changes_pane_class_init (GitStashChangesPaneClass *klass)
137 GObjectClass* object_class = G_OBJECT_CLASS (klass);
138 AnjutaDockPaneClass* pane_class = ANJUTA_DOCK_PANE_CLASS (klass);
140 object_class->finalize = git_stash_changes_pane_finalize;
141 pane_class->get_widget = get_widget;
142 pane_class->refresh = NULL;
146 AnjutaDockPane *
147 git_stash_changes_pane_new (Git *plugin)
149 return g_object_new (GIT_TYPE_STASH_CHANGES_PANE, "plugin", plugin, NULL);
152 void
153 on_stash_changes_button_clicked (GtkAction *action, Git *plugin)
155 AnjutaDockPane *stash_changes_pane;
157 stash_changes_pane = git_stash_changes_pane_new (plugin);
159 anjuta_dock_replace_command_pane (ANJUTA_DOCK (plugin->dock), "StashChanges",
160 _("Stash Uncommitted Changes"), NULL,
161 stash_changes_pane, GDL_DOCK_BOTTOM, NULL, 0, NULL);