SF.net SVN: geany: [1968] trunk

frlan at users.sourceforge.net frlan at xxxxx
Tue Oct 23 11:49:28 UTC 2007


Revision: 1968
          http://geany.svn.sourceforge.net/geany/?rev=1968&view=rev
Author:   frlan
Date:     2007-10-23 04:49:28 -0700 (Tue, 23 Oct 2007)

Log Message:
-----------
SVNdiff: Improvment of handling of non-UTF diffs

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/plugins/svndiff.c

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2007-10-22 17:10:02 UTC (rev 1967)
+++ trunk/ChangeLog	2007-10-23 11:49:28 UTC (rev 1968)
@@ -1,3 +1,9 @@
+2007-10-23  Frank Lanitz  <frank(at)frank(dot)uvena(dot)de>
+
+ * plugins/svndiff.c:
+   Small improvments in handling of non UTF-8 diffs.
+
+
 2007-10-22  Enrico Tröger  <enrico(dot)troeger(at)uvena(dot)de>
 
  * src/notebook.c: Don't make notebook tabs higher than necessary.

Modified: trunk/plugins/svndiff.c
===================================================================
--- trunk/plugins/svndiff.c	2007-10-22 17:10:02 UTC (rev 1967)
+++ trunk/plugins/svndiff.c	2007-10-23 11:49:28 UTC (rev 1968)
@@ -18,11 +18,9 @@
  *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
-
 /* SVNdiff plugin */
 /* This small plugin uses svn to generate a diff against the current
- * version inside svn. Keep in mind, that it saves your version you currently working
- * on and some changes may get lost by accident. */
+ * version inside svn.*/
 
 #include "geany.h"
 #include "support.h"
@@ -38,9 +36,9 @@
 #define doc_array	geany_data->doc_array
 
 
-VERSION_CHECK(21)
+VERSION_CHECK(25)
 
-PLUGIN_INFO(_("SVNdiff"), _("Plugin to create a patch of a file against svn"), "0.0.2")
+PLUGIN_INFO(_("SVNdiff"), _("Plugin to create a patch of a file against svn"), "0.0.3")
 
 
 /* Callback if menu item was acitvated */
@@ -52,23 +50,32 @@
 	gchar	*std_output = NULL;
 	gchar	*std_err = NULL;
 	gint	exit_code;
-	GError	*error_code = NULL;
+	GError	*error = NULL;
+	gint 	new_idx;
+	gchar	*text = NULL;
+	gchar	*base_name = NULL;
+	gchar 	*short_name = NULL;
+	gchar 	*locale_filename = NULL;
 
 	idx = geany_data->document->get_cur_idx();
 
+	if (doc_list[idx].file_name == NULL)
+	{
+		geany_data->dialogs->show_save_as();
+	}
+	else if (doc_list[idx].changed)
+	{
+		geany_data->document->save_file(idx, FALSE);
+	}
+
     // Stolen from export.c. Thanks for it, Enrico ;)
     if (doc_list[idx].file_name != NULL)
 	{
-		gchar *base_name = g_path_get_basename(doc_list[idx].file_name);
-		gchar *short_name = utils->remove_ext_from_filename(base_name);
-		gchar *locale_filename = utils->get_locale_from_utf8(doc_list[idx].file_name);
+		base_name = g_path_get_basename(doc_list[idx].file_name);
+		short_name = utils->remove_ext_from_filename(base_name);
+		locale_filename = utils->get_locale_from_utf8(doc_list[idx].file_name);
 
 
-		if (! geany_data->document->save_file(idx, TRUE))
-		{
-			geany_data->msgwindow->status_add(_("File %s couldn't be saved."
-			"Will go on with last saved version."),base_name);
-		}
 		// use '' quotation for Windows compatibility
 		command = g_strdup_printf("svn diff --non-interactive '%s'", locale_filename);
 
@@ -79,14 +86,29 @@
 		g_free(locale_filename);
 
 
-		if (g_spawn_command_line_sync(command, &std_output, &std_err, &exit_code, &error_code))
+		if (g_spawn_command_line_sync(command, &std_output, &std_err, &exit_code, &error))
 		{
 			if (! exit_code)
 			{
 				if (std_output == NULL || std_output[0] != '\0')
 				{
-					geany_data->document->new_file(diff_file_name,
-						geany_data->filetypes[GEANY_FILETYPES_DIFF], std_output);
+
+					// need to convert input text from the encoding of the original file into
+					// UTF-8 because internally Geany always needs UTF-8
+					text = geany_data->encoding->convert_to_utf8_from_charset(
+						std_output, -1, doc_list[idx].encoding, TRUE);
+
+					if (text == NULL)
+					{
+						geany_data->msgwindow->status_add(_("Could not parse the output of svn diff"));
+					}
+					else
+					{
+						new_idx = geany_data->document->new_file(diff_file_name,
+							geany_data->filetypes[GEANY_FILETYPES_DIFF], text);
+						geany_data->document->set_encoding(new_idx, doc_list[idx].encoding);
+						g_free(text);
+					}
 				}
 				else
 				{
@@ -95,7 +117,7 @@
 			}
 			else // SVN returns some error
 			{
-				// TODO print std_err or print detailed error messages based on exit_code
+				/// TODO print std_err or print detailed error messages based on exit_code
 				geany_data->msgwindow->status_add(
 					_("SVN exited with an error. Error code was: %d."), exit_code);
 			}
@@ -115,6 +137,7 @@
 	}
 	g_free(std_output);
 	g_free(std_err);
+	g_free(error);
 }
 
 
@@ -129,9 +152,8 @@
 	gtk_container_add(GTK_CONTAINER(geany_data->tools_menu), svndiff_item);
 	g_signal_connect(G_OBJECT(svndiff_item), "activate", G_CALLBACK(item_activated), NULL);
 
-	// keep a pointer to the menu item, so we can remove it when the
-	// plugin is unloaded
 	plugin_fields->menu_item = svndiff_item;
+	plugin_fields->flags = PLUGIN_IS_DOCUMENT_SENSITIVE;
 }
 
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the Commits mailing list