File: subversion-diff-dialog.c

package info (click to toggle)
anjuta 2%3A3.34.0-8
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 72,440 kB
  • sloc: ansic: 207,444; sh: 47,499; cpp: 11,461; makefile: 3,586; yacc: 2,821; perl: 2,094; lex: 1,546; xml: 904; python: 149; sql: 99; javascript: 51; java: 10
file content (195 lines) | stat: -rw-r--r-- 6,112 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
 * anjuta
 * Copyright (C) James Liggett 2007 <jrliggett@cox.net>
 *
 * Portions based on the original Subversion plugin 
 * Copyright (C) Johannes Schmid 2005 
 * 
 * anjuta is free software.
 * 
 * You may redistribute it and/or modify it under the terms of the
 * GNU General Public License, as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option)
 * any later version.
 * 
 * anjuta is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with anjuta.  If not, write to:
 * 	The Free Software Foundation, Inc.,
 * 	51 Franklin Street, Fifth Floor
 * 	Boston, MA  02110-1301, USA.
 */

#include "subversion-diff-dialog.h"

#define BROWSE_BUTTON_DIFF_DIALOG "browse_button_diff_dialog"

static void
subversion_show_diff (const gchar *path, gboolean recursive, 
					  gboolean save_files, Subversion *plugin)
{
	IAnjutaDocumentManager *docman;
	gchar *filename;
	gchar *editor_name;
	IAnjutaEditor *editor;
	SvnDiffCommand *diff_command;
	guint pulse_timer_id;
	
	docman = anjuta_shell_get_interface (ANJUTA_PLUGIN (plugin)->shell,
										 IAnjutaDocumentManager, NULL);
	filename = get_filename_from_full_path ((gchar *) path);
	editor_name = g_strdup_printf ("%s %s.diff", _("[Head/Working Copy]"),
								   filename);
	editor = ianjuta_document_manager_add_buffer(docman, editor_name, 
												 "", NULL);
	
	g_free (filename);
	g_free (editor_name);
	
	diff_command = svn_diff_command_new ((gchar *) path, 
										 SVN_DIFF_REVISION_NONE,
										 SVN_DIFF_REVISION_NONE,
										 plugin->project_root_dir,
										 recursive);
	
	pulse_timer_id = status_bar_progress_pulse (plugin,
												_("Subversion: " 
												  "Retrieving "
												  "diff…"));
	
	g_signal_connect (G_OBJECT (diff_command), "command-finished",
					  G_CALLBACK (stop_status_bar_progress_pulse),
					  GUINT_TO_POINTER (pulse_timer_id));
	
	
	g_signal_connect (G_OBJECT (diff_command), "command-finished",
					  G_CALLBACK (on_diff_command_finished), 
					  plugin);
	
	g_signal_connect (G_OBJECT (diff_command), "data-arrived",
					  G_CALLBACK (send_diff_command_output_to_editor),
					  editor);
	
	g_object_weak_ref (G_OBJECT (editor), 
					   (GWeakNotify) disconnect_data_arrived_signals,
					   diff_command);
	
	if (save_files)
		ianjuta_file_savable_save (IANJUTA_FILE_SAVABLE (docman), NULL);
	
	anjuta_command_start (ANJUTA_COMMAND (diff_command));
}

static void
on_subversion_diff_response(GtkDialog* dialog, gint response, SubversionData* data)
{	
	GtkWidget *diff_path_entry;
	GtkWidget *diff_no_recursive_check;
	GtkWidget *diff_revision_entry;
	GtkWidget *diff_save_open_files_check;
	const gchar *path;
	const gchar *revision_text;
	glong revision;
	
	switch (response)
	{
		case GTK_RESPONSE_OK:
		{
			diff_path_entry = GTK_WIDGET (gtk_builder_get_object (data->bxml, 
													"diff_path_entry"));
			diff_no_recursive_check = GTK_WIDGET (gtk_builder_get_object (data->bxml, 
															"diff_no_recursive_check"));
			diff_revision_entry = GTK_WIDGET (gtk_builder_get_object (data->bxml, 
														"diff_revision_entry"));
			diff_save_open_files_check = GTK_WIDGET (gtk_builder_get_object (data->bxml,
															   "diff_save_open_files_check"));
			path = g_strdup (gtk_entry_get_text (GTK_ENTRY (diff_path_entry)));
			revision_text = gtk_entry_get_text (GTK_ENTRY (diff_revision_entry));
			revision = atol (revision_text);
			
			if (!check_input (GTK_WIDGET (dialog), diff_path_entry, 
							  _("Please enter a path.")))
			{
				break;
			}

			subversion_show_diff (path, 
								  !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (diff_no_recursive_check)),
								  gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (diff_save_open_files_check)),
								  data->plugin);
			
			subversion_data_free(data);
			gtk_widget_destroy(GTK_WIDGET(dialog));
			break;
		}
		default:
		{
			gtk_widget_destroy(GTK_WIDGET(dialog));
			subversion_data_free(data);
			break;
		}
	}
}

static void
subversion_diff_dialog (GtkAction *action, Subversion *plugin, gchar *filename)
{
	GtkBuilder *bxml = gtk_builder_new ();
	GtkWidget *subversion_diff; 
	GtkWidget *diff_path_entry;
	GtkWidget *diff_whole_project_check;
	GtkWidget *button;
	SubversionData *data;
	GError* error = NULL;

	if (!gtk_builder_add_from_file (bxml, GLADE_FILE, &error))
	{
		g_warning ("Couldn't load builder file: %s", error->message);
		g_error_free (error);
	}

	subversion_diff = GTK_WIDGET (gtk_builder_get_object (bxml, "subversion_diff"));
	diff_path_entry = GTK_WIDGET (gtk_builder_get_object (bxml, "diff_path_entry"));
	diff_whole_project_check = GTK_WIDGET (gtk_builder_get_object (bxml, 
													"diff_whole_project_check"));
	data = subversion_data_new (plugin, bxml);
	
	g_object_set_data (G_OBJECT (diff_whole_project_check), "fileentry", 
					   diff_path_entry);
	
	if (filename)
		gtk_entry_set_text (GTK_ENTRY (diff_path_entry), filename);
	
	
	g_signal_connect(G_OBJECT (diff_whole_project_check), "toggled", 
					 G_CALLBACK (on_whole_project_toggled), 
					 plugin);
	init_whole_project (plugin, diff_whole_project_check, !filename);

	button = GTK_WIDGET (gtk_builder_get_object (bxml, BROWSE_BUTTON_DIFF_DIALOG));
	g_signal_connect(G_OBJECT(button), "clicked", 
		G_CALLBACK(on_subversion_browse_button_clicked), diff_path_entry);

	g_signal_connect (G_OBJECT (subversion_diff), "response", 
					  G_CALLBACK (on_subversion_diff_response), 
					  data);
	
	gtk_widget_show (subversion_diff);
}

void 
on_menu_subversion_diff (GtkAction* action, Subversion* plugin)
{
	subversion_diff_dialog (action, plugin, NULL);
}

void 
on_fm_subversion_diff (GtkAction *action, Subversion *plugin)
{
	subversion_show_diff (plugin->fm_current_filename, TRUE, FALSE, plugin);
}