[Geany] GITdiff plugin, need help

Yura Siamashka yurand2 at xxxxx
Sat Nov 3 21:59:51 UTC 2007


Hi

On Sat, Nov 03, 2007 at 06:57:52PM +0100, Enrico Tröger wrote:
> On Sat, 3 Nov 2007 12:50:41 +0200, Yura Siamashka <yurand2 at gmail.com>
> wrote:
> > Here is updated version of gitdiff. I had to add document_set_changed
> > function to color tab as unmodified.
> > 
> > To geany devs: Can you commit
> > plugin_add_set_text_changed_function.patch? Any chance to include
> > gitdiff in geany?
> I'll add the document_set_changed() to the API, no problem.
Nice, thanks.

> I'm not sure we should include your plugin, maybe you can just make a
> tarball and put it on some webspace, similar to how Jeff has it done
> for his Lua plugin. Maybe, we'll add some autotools stuff to ease work
> with external plugins.
I guess I will do that. git diff still need some works. (For example don't add 
anything to menu if you don't have git installed, gray button if you are not 
in git repositary) 

> 
> Btw, I like the idea of re-using the already created tab for a new diff
> on the same file. Maybe this should be ported to the svndiff plugin.
Here is patch. It depend on plugin_add_set_text_changed_function.patch.

Best regards,
Yura Semashko
-------------- next part --------------
Index: plugins/svndiff.c
===================================================================
--- plugins/svndiff.c	(revision 2011)
+++ plugins/svndiff.c	(working copy)
@@ -37,17 +37,29 @@
 GeanyData		*geany_data;
 
 
-VERSION_CHECK(25)
+VERSION_CHECK(27)
 
 PLUGIN_INFO(_("SVNdiff"), _("Plugin to create a patch of a file against svn"), VERSION)
 
+static int find_by_filename(const gchar* filename)
+{
+	gint i;
+	for (i = 0; i < doc_array->len; i++)
+	{
+		if ( DOC_IDX_VALID(i) && doc_list[i].file_name && 
+		     strcmp(doc_list[i].file_name, filename) == 0)
+			return i;
+	}
+	return -1;
+}
 
 /* name_prefix should be in UTF-8, and can have a path. */
 static void show_output(const gchar *std_output, const gchar *name_prefix,
 		const gchar *force_encoding)
 {
 	gchar	*text, *detect_enc = NULL;
-	gint 	new_idx;
+	gint 	idx, page;
+	GtkNotebook *book;
 	gchar	*filename;
 
 	filename = g_path_get_basename(name_prefix);
@@ -66,10 +78,23 @@
 	}
 	if (text)
 	{
-		new_idx = geany_data->document->new_file(filename,
+		idx = find_by_filename(filename);
+		if ( idx == -1)
+		{
+			idx = geany_data->document->new_file(filename,
 			geany_data->filetypes[GEANY_FILETYPES_DIFF], text);
-
-		geany_data->document->set_encoding(new_idx,
+		}
+		else
+		{
+			geany_data->sci->set_text(doc_list[idx].sci, text);
+			book = GTK_NOTEBOOK(app->notebook);
+			page = gtk_notebook_page_num(book, GTK_WIDGET(doc_list[idx].sci));
+			gtk_notebook_set_current_page(book, page);
+			doc_list[idx].changed = FALSE;
+			documents->set_text_changed(idx);
+		}
+		
+		geany_data->document->set_encoding(idx,
 			force_encoding ? force_encoding : detect_enc);
 	}
 	else
@@ -81,7 +106,6 @@
 	g_free(filename);
 }
 
-
 static gchar *make_diff(const gchar *svn_file)
 {
 	gchar	*std_output = NULL;


More information about the Users mailing list