Implement showing diffs of commits.
[anjuta-git-plugin.git] / plugins / git / git-diff-dialog.c
blobc7f1218776a7cc723f673b8aa0aef4b468728639
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-diff-dialog.h"
27 /* FIXME: We don't really have a dialog yet. Implement that when we have an FM
28 * context menu (for diffing individual files.) A dialog isn't really needed
29 * for just getting project-wide uncommitted changes. */
31 static void
32 git_diff (Git *plugin)
34 IAnjutaDocumentManager *document_manager;
35 IAnjutaEditor *editor;
36 GitDiffCommand *diff_command;
38 document_manager = anjuta_shell_get_interface (ANJUTA_PLUGIN (plugin)->shell,
39 IAnjutaDocumentManager,
40 NULL);
41 editor = ianjuta_document_manager_add_buffer (document_manager,
42 "Uncommitted Changes.diff",
43 "", NULL);
45 diff_command = git_diff_command_new (plugin->project_root_directory);
47 g_signal_connect (G_OBJECT (diff_command), "data-arrived",
48 G_CALLBACK (send_raw_command_output_to_editor),
49 editor);
51 g_signal_connect (G_OBJECT (diff_command), "command_finished",
52 G_CALLBACK (on_diff_command_finished),
53 plugin);
55 anjuta_command_start (ANJUTA_COMMAND (diff_command));
59 static void
60 git_commit_diff (Git *plugin)
62 GitRevision *revision;
63 gchar *sha;
64 gchar *short_sha;
65 gchar *editor_name;
66 IAnjutaDocumentManager *document_manager;
67 IAnjutaEditor *editor;
68 GitDiffTreeCommand *diff_command;
70 revision = git_log_get_selected_revision (plugin);
72 if (revision)
74 sha = git_revision_get_sha (revision);
75 short_sha = git_revision_get_short_sha (revision);
76 editor_name = g_strdup_printf ("Commit %s.diff", short_sha);
78 document_manager = anjuta_shell_get_interface (ANJUTA_PLUGIN (plugin)->shell,
79 IAnjutaDocumentManager,
80 NULL);
81 editor = ianjuta_document_manager_add_buffer (document_manager,
82 editor_name,
83 "", NULL);
85 g_free (short_sha);
86 g_free (editor_name);
89 diff_command = git_diff_tree_command_new (plugin->project_root_directory,
90 sha);
92 g_signal_connect (G_OBJECT (diff_command), "data-arrived",
93 G_CALLBACK (send_raw_command_output_to_editor),
94 editor);
96 g_signal_connect (G_OBJECT (diff_command), "command_finished",
97 G_CALLBACK (on_diff_command_finished),
98 plugin);
100 anjuta_command_start (ANJUTA_COMMAND (diff_command));
104 void
105 on_menu_git_diff (GtkAction *action, Git *plugin)
107 git_diff (plugin);
110 void
111 on_log_menu_git_commit_diff (GtkAction *action, Git *plugin)
113 git_commit_diff (plugin);