anjuta r4712 - in trunk: . libanjuta/interfaces plugins/scintilla plugins/search plugins/sourceview



Author: sgranjoux
Date: Sun Feb  8 14:11:48 2009
New Revision: 4712
URL: http://svn.gnome.org/viewvc/anjuta?rev=4712&view=rev

Log:
	* plugins/scintilla/text_editor.c,
	plugins/sourceview/sourceview.c,
	libanjuta/interfaces/libanjuta.idl:
	ianjuta_editor_get_length returns value in bytes instead of characters

	* plugins/search/search-replace.c,
	plugins/search/search-replace_backend.c,
	plugins/search/search-replace_backend.h:
	Fix #566531 â Find & Replace results in wrong result for files
	containing multi-byte UTF-8 sequences

	* plugins/search/Makefile.am:
	Define log domains for search plugin


Modified:
   trunk/ChangeLog
   trunk/libanjuta/interfaces/libanjuta.idl
   trunk/plugins/scintilla/text_editor.c
   trunk/plugins/search/Makefile.am
   trunk/plugins/search/search-replace.c
   trunk/plugins/search/search-replace_backend.c
   trunk/plugins/search/search-replace_backend.h
   trunk/plugins/sourceview/sourceview.c

Modified: trunk/libanjuta/interfaces/libanjuta.idl
==============================================================================
--- trunk/libanjuta/interfaces/libanjuta.idl	(original)
+++ trunk/libanjuta/interfaces/libanjuta.idl	Sun Feb  8 14:11:48 2009
@@ -1453,7 +1453,7 @@
 	 * @err: Error propagation and reporting
 	 *
 	 * Get length of complete text in editor. This will be the total
-	 * number of characters in the file or buffer.
+	 * number of bytes in the file or buffer.
 	 *
 	 * Return value: Text length.
 	 */

Modified: trunk/plugins/scintilla/text_editor.c
==============================================================================
--- trunk/plugins/scintilla/text_editor.c	(original)
+++ trunk/plugins/scintilla/text_editor.c	Sun Feb  8 14:11:48 2009
@@ -2265,22 +2265,8 @@
 static gint
 itext_editor_get_length (IAnjutaEditor *editor, GError **e)
 {
-	TextEditor *te = TEXT_EDITOR (editor);
-	
-	/* FIXME: Find a more optimal solution */
-	gint length = scintilla_send_message (SCINTILLA (te->scintilla),
-										  SCI_GETLENGTH, 0, 0);
-	if (length > 0)
-	{
-		gint char_position;
-		gchar *data =
-			(gchar *) aneditor_command (te->editor_id, ANE_GETTEXTRANGE, 0,
-										length);
-		char_position = g_utf8_strlen (data, -1);
-		g_free (data);
-		return char_position;
-	}
-	return 0;
+        return aneditor_command (TEXT_EDITOR (editor)->editor_id,
+		       	ANE_GETLENGTH, 0, 0);
 }
 
 static gchar*

Modified: trunk/plugins/search/Makefile.am
==============================================================================
--- trunk/plugins/search/Makefile.am	(original)
+++ trunk/plugins/search/Makefile.am	Sun Feb  8 14:11:48 2009
@@ -27,6 +27,7 @@
 	$(GNOME_PRINT_UI_CFLAGS) \
 	$(LIBANJUTA_CFLAGS) \
 	-I$(top_srcdir)/tagmanager/include
+	-DG_LOG_DOMAIN=\"libanjuta-search\"
 
 libanjuta_search_la_LDFLAGS = $(ANJUTA_PLUGIN_LDFLAGS)
 

Modified: trunk/plugins/search/search-replace.c
==============================================================================
--- trunk/plugins/search/search-replace.c	(original)
+++ trunk/plugins/search/search-replace.c	Sun Feb  8 14:11:48 2009
@@ -228,7 +228,6 @@
 static gboolean on_message_clicked (GObject* object, gchar* message, gpointer data);
 static void on_message_view_destroyed (gpointer unused, GObject* where_the_object_was);
 static void on_message_buffer_flush (IAnjutaMessageView *view, const gchar *one_line, gpointer data);
-static void save_not_opened_files(FileBuffer *fb);
 static gboolean replace_in_not_opened_files(FileBuffer *fb, MatchInfo *mi, gchar *repl_str);
 static void search_set_action(SearchAction action);
 static void search_set_target(SearchRangeType target);
@@ -355,21 +354,25 @@
 		found_line = (s->action == SA_BOOKMARK) ? -1 : 1;
 
 		se = (SearchEntry *) tmp->data;
-		if (flag_select)
-		{
-			se->start_pos = start_sel;
-			se->end_pos = end_sel;
-		}
-		else
-			end_sel = se->end_pos;
+		
 		if (SE_BUFFER == se->type)
 			fb = file_buffer_new_from_te(se->te);
 		else /* if (SE_FILE == se->type) */
-			fb = file_buffer_new_from_path(se->path, NULL, -1, 0);
-
+			fb = file_buffer_new_from_uri(se->uri);
+		
 		if (fb && fb->buf)
-		{		
-			fb->pos = se->start_pos;
+		{
+			if (flag_select)
+			{
+				se->start_pos = g_utf8_strlen (fb->buf, start_sel);
+				se->end_pos = g_utf8_strlen (fb->buf, end_sel);
+			}
+			else
+			 {
+				end_sel = g_utf8_offset_to_pointer (fb->buf, se->end_pos) - fb->buf;
+			 }
+			
+			fb->pos = g_utf8_offset_to_pointer (fb->buf, se->start_pos) - fb->buf;
 			offset = 0;
 		//FIXME enable clearing of marks by some means other than a 0-match search
 			if (s->action == SA_HIGHLIGHT)	
@@ -402,10 +405,14 @@
 
 						if (IANJUTA_INDICABLE (fb->te))
 						{
+							gint offset;
 							IAnjutaIterable *start_pos, *end_pos;
 							/* end-location is correct for sourceview, 1-too-big for scintilla */
-							start_pos = ianjuta_editor_get_position_from_offset (fb->te, mi->pos, NULL);
-							end_pos = ianjuta_editor_get_position_from_offset (fb->te, mi->pos + mi->len, NULL);
+
+							offset = g_utf8_strlen (fb->buf, mi->pos);
+							start_pos = ianjuta_editor_get_position_from_offset (fb->te, offset, NULL);
+							offset += g_utf8_strlen (fb->buf + mi->pos, mi->len);
+							end_pos = ianjuta_editor_get_position_from_offset (fb->te, offset, NULL);
 							ianjuta_indicable_set (IANJUTA_INDICABLE(fb->te),
 												   start_pos, end_pos,
 												   IANJUTA_INDICABLE_IMPORTANT, NULL);
@@ -417,14 +424,12 @@
 					case SA_BOOKMARK:
 						if (found_line != mi->line)
 						{
-							GFile* file = g_file_new_for_uri (fb->uri);
 							found_line = mi->line + 1; /* different line count between search and editor */
 							ianjuta_document_manager_add_bookmark (sr->docman,
-																   file,
+																   fb->file,
 																   found_line,
 																   NULL);
-							g_object_unref (file);			  
-						}
+	 					}
 						break;
 						
 					case SA_SELECT:
@@ -434,16 +439,19 @@
 								ianjuta_editor_goto_line (fb->te, mi->line, NULL);
 							else
 							{
-								GFile* file = g_file_new_for_uri (fb->uri);
-								fb->te = ianjuta_document_manager_goto_file_line_mark
-									(sr->docman, file, mi->line, FALSE, NULL);
-								g_object_unref (file);
+									fb->te = ianjuta_document_manager_goto_file_line_mark
+									(sr->docman, fb->file, mi->line, FALSE, NULL);
 							}
 							found_line = mi->line;
 						}
 						{
-							IAnjutaIterable* start = ianjuta_editor_get_position_from_offset (fb->te, mi->pos, NULL);
-							IAnjutaIterable* end = ianjuta_editor_get_position_from_offset (fb->te, mi->pos + mi->len, NULL);
+							gint offset;
+							IAnjutaIterable *start, *end;
+
+							offset = g_utf8_strlen (fb->buf, mi->pos);
+							start = ianjuta_editor_get_position_from_offset (fb->te, offset, NULL);
+							offset += g_utf8_strlen (fb->buf + mi->pos, mi->len);
+							end = ianjuta_editor_get_position_from_offset (fb->te, offset, NULL);
 							ianjuta_editor_selection_set(IANJUTA_EDITOR_SELECTION (fb->te), 
 														 start,
 														 end,
@@ -465,18 +473,21 @@
 								ianjuta_editor_goto_line (fb->te, mi->line, NULL);
 							else
 							{
-								GFile* file = g_file_new_for_uri (fb->uri);
 								fb->te = ianjuta_document_manager_goto_file_line_mark
-									(sr->docman, file, mi->line, FALSE, NULL);
-								g_object_unref (file);
+									(sr->docman, fb->file, mi->line, FALSE, NULL);
 							}
 							found_line = mi->line;
 							}
 
 						if (!interactive)
 						{
-							IAnjutaIterable* start = ianjuta_editor_get_position_from_offset (fb->te, mi->pos - offset, NULL);
-							IAnjutaIterable* end = ianjuta_editor_get_position_from_offset (fb->te, mi->pos - offset + mi->len, NULL);
+							gint offset;
+							IAnjutaIterable *start, *end;
+
+							offset = g_utf8_strlen (fb->buf, mi->pos);
+							start = ianjuta_editor_get_position_from_offset (fb->te, offset, NULL);
+							offset += g_utf8_strlen (fb->buf + mi->pos, mi->len);
+							end = ianjuta_editor_get_position_from_offset (fb->te, offset, NULL);
 							ianjuta_editor_selection_set(IANJUTA_EDITOR_SELECTION (fb->te), 
 														 start,
 														 end,
@@ -505,8 +516,13 @@
 								ch = NULL;
 						}
 							{
-								IAnjutaIterable* start = ianjuta_editor_get_position_from_offset (fb->te, mi->pos - os, NULL);
-								IAnjutaIterable* end = ianjuta_editor_get_position_from_offset (fb->te, mi->pos + mi->len - os, NULL);
+								gint offset;
+								IAnjutaIterable *start, *end;
+
+								offset = g_utf8_strlen (fb->buf, mi->pos);
+								start = ianjuta_editor_get_position_from_offset (fb->te, offset, NULL);
+								offset += g_utf8_strlen (fb->buf + mi->pos, mi->len);
+								end = ianjuta_editor_get_position_from_offset (fb->te, offset, NULL);
 								ianjuta_editor_selection_set(IANJUTA_EDITOR_SELECTION (fb->te),  
 															 start,														 
 															 end,
@@ -541,8 +557,13 @@
 						}
 						else
 						{
-							IAnjutaIterable* start = ianjuta_editor_get_position_from_offset (fb->te, mi->pos - offset, NULL);
-							IAnjutaIterable* end = ianjuta_editor_get_position_from_offset (fb->te, mi->pos + mi->len - offset, NULL);
+							gint offset;
+							IAnjutaIterable *start, *end;
+
+							offset = g_utf8_strlen (fb->buf, mi->pos);
+							start = ianjuta_editor_get_position_from_offset (fb->te, offset, NULL);
+							offset += g_utf8_strlen (fb->buf + mi->pos, mi->len);
+							end = ianjuta_editor_get_position_from_offset (fb->te, offset, NULL);
 							ianjuta_editor_selection_set(IANJUTA_EDITOR_SELECTION (fb->te),  
 														 start,
 														 end,
@@ -583,7 +604,7 @@
 			}
 			if (save_file)
 			{
-				save_not_opened_files (fb);
+				g_file_replace_contents (fb->file, fb->buf, fb->len, NULL, FALSE, G_FILE_CREATE_NONE, NULL, NULL, NULL);
 				save_file = FALSE;
 			}
 			
@@ -630,13 +651,17 @@
 {
 	gchar *match_line = file_match_line_from_pos(fb, mi->pos);
 	int line = mi->line;
-	char buf[BUFSIZ];
+	gchar *buf;
+	gchar *path;
 	
 	if (se->type == SE_FILE)
 		++line;
-    snprintf(buf, BUFSIZ, "%s:%d:%s\n", fb->path, line, match_line);
+	path = g_file_get_path (fb->file);
+	buf = g_strdup_printf ("%s:%d:%s\n", path, line, match_line);
+	g_free (path);
 	g_free(match_line);
 	ianjuta_message_view_buffer_append (view, buf, NULL);
+	g_free (buf);
 }
 
 static void
@@ -679,44 +704,6 @@
 	return FALSE;
 }
 
-static void
-save_not_opened_files(FileBuffer *fb)
-{
-	GFile *file;
-	GOutputStream *os;
-	gsize written;
-	gsize size;
-	gchar *buffer;
-
-	file = g_file_new_for_uri (fb->uri);
-	os = G_OUTPUT_STREAM (g_file_replace (file, 
-			NULL,
-			FALSE,
-			G_FILE_CREATE_NONE,
-			NULL,
-			NULL));
-	if (os == NULL)
-	{
-		g_object_unref (file);
-		return;
-	}
-
-	buffer = fb->buf;
-	size = fb->len;
-	do
-	{
-		written = g_output_stream_write (os, 
-				buffer, size, NULL, NULL);
-		
-		size -= written;
-		buffer += size;
-	}
-	while (written != -1 && size > 0);
-	g_output_stream_close(os, NULL, NULL);
-	g_object_unref (os);
-	g_object_unref (file);
-}
-
 static gboolean
 replace_in_not_opened_files(FileBuffer *fb, MatchInfo *mi, gchar *repl_str)
 {

Modified: trunk/plugins/search/search-replace_backend.c
==============================================================================
--- trunk/plugins/search/search-replace_backend.c	(original)
+++ trunk/plugins/search/search-replace_backend.c	Sun Feb  8 14:11:48 2009
@@ -102,10 +102,8 @@
 {
 	if (fb)
 	{
-		if (fb->path)
-			g_free(fb->path);
-		if (fb->uri)
-			g_free (fb->uri);
+		if (fb->file)
+			g_object_unref (fb->file);
 		if (fb->buf)
 			g_free(fb->buf);
 		if (fb->lines)
@@ -118,23 +116,21 @@
 FileBuffer *
 file_buffer_new_from_te (IAnjutaEditor *te)
 {
-	FileBuffer *fb;
-	GFile* file;
+	FileBuffer *fb = NULL;
+	gint len;
 	
 	g_return_val_if_fail(te, NULL);
-	fb = g_new0(FileBuffer, 1);
-	fb->type = FB_EDITOR;
-	fb->te = te;
-	
-	file = ianjuta_file_get_file(IANJUTA_FILE(te), NULL);
-	fb->path = g_file_get_path (file);
-	fb->uri = g_file_get_uri (file);
-	fb->len = ianjuta_editor_get_length(te, NULL);
-	fb->buf = ianjuta_editor_get_text_all (fb->te, NULL);
-	fb->pos = ianjuta_editor_get_offset(fb->te, NULL);
-	fb->line = ianjuta_editor_get_lineno(fb->te, NULL);
 	
-	g_object_unref (file);
+	len = ianjuta_editor_get_length(te, NULL);
+	if (len != 0)
+	{
+		fb = g_new0(FileBuffer, 1);
+		fb->type = FB_EDITOR;
+		fb->te = te;
+		fb->file = ianjuta_file_get_file(IANJUTA_FILE(te), NULL);
+		fb->buf = ianjuta_editor_get_text_all (fb->te, NULL);
+		fb->len = len;
+	}
 	
 	return fb;
 }
@@ -143,121 +139,47 @@
 #define MAX_VALIDATE 500
 
 FileBuffer *
-file_buffer_new_from_path (const char *path, const char *buf, int len, int pos)
+file_buffer_new_from_uri (const gchar *uri)
 {
 	FileBuffer *fb;
-	IAnjutaEditor *te;
+	GFile *file;
 	IAnjutaDocument* doc;
-	GFile* file;
-	char *uri;
-	int i;
-	int lineno;
+	gchar *buffer;
+	gsize length;
 
-	g_return_val_if_fail(path, NULL);
+	g_return_val_if_fail(uri, NULL);
+	
+	
+	file = g_file_new_for_uri (uri);
 	
 	/* There might be an already open TextEditor with this path */
-	file = g_file_new_for_path (path);
-	uri = g_file_get_uri (file);
 	doc = ianjuta_document_manager_find_document_with_file (sr->docman,
 														 file, NULL);
 	if (doc && IANJUTA_IS_EDITOR (doc))
 	{
+		IAnjutaEditor *te;
+		
 		te = IANJUTA_EDITOR (doc);
+		g_object_unref (file);
+
 		return file_buffer_new_from_te(te);
 	}
-	fb = g_new0(FileBuffer, 1);
-	fb->type = FB_FILE;
-	fb->path = g_file_get_path (file);
-	fb->uri = uri;
-	fb->name = strrchr(path, '/');
-	g_object_unref (file);
-	if (fb->name)
-		++ fb->name;
-	else
-		fb->name = fb->path;
-	if (buf && len > 0)
-	{
-		fb->buf = g_new(char, len + 1);
-		memcpy(fb->buf, buf, len);
-		fb->buf[len] = '\0';
-		fb->len = len;
-	}
-	else
-	{
-		GFileInfo *fi;
-		guint64 size;
 
-		file = g_file_new_for_path (fb->path);
-		fi = g_file_query_info (file,
-				G_FILE_ATTRIBUTE_STANDARD_SIZE ","
-				G_FILE_ATTRIBUTE_STANDARD_TYPE,
-				G_FILE_QUERY_INFO_NONE,
-				NULL, NULL);
-		if (fi != NULL && g_file_info_get_file_type(fi) == G_FILE_TYPE_REGULAR)
-		{
-			size = g_file_info_get_attribute_uint64(fi, G_FILE_ATTRIBUTE_STANDARD_SIZE);
-			g_object_unref (fi);
-			fi = NULL;
-
-			if ((fb->len = size) < 0) return NULL;
-			fb->buf = g_new(char, size + 1);
-			{
-				int total_bytes = 0, bytes_read;
-				GInputStream *is;
-				GError* error = NULL;
-
-				is = G_INPUT_STREAM (g_file_read (file, NULL, &error));
-				if (NULL == is)
-				{
-					DEBUG_PRINT("Error opening file: %s", error->message);
-					g_error_free (error);
-					file_buffer_free (fb);
-					g_object_unref (file);
-					return NULL;
-				}
-
-				while (total_bytes < size)
-				{
-					bytes_read = g_input_stream_read (is,
-							fb->buf + total_bytes,
-							size - total_bytes,
-							NULL,
-							&error);
-					if (bytes_read == -1)
-					{
-						DEBUG_PRINT("Error reading from file: %s", error->message);
-						g_error_free (error);
-						file_buffer_free (fb);
-						g_input_stream_close (is, NULL, NULL);
-						g_object_unref (is);
-						g_object_unref (file);
-						return NULL;
-					}
-					total_bytes += bytes_read;
-				}
-
-				g_input_stream_close (is, NULL, NULL);
-				g_object_unref (is);
-				g_object_unref (file);
-				fb->buf[fb->len] = '\0';
-			}
-		}
-		else
-		{
-			if (NULL != fi)
-			{
-				g_object_unref (fi);
-			}
-		}
+	if (!g_file_load_contents (file, NULL, &buffer, &length, NULL, NULL))
+	{
+		/* Unable to read file */
+		g_object_unref (file);
+		
+		return NULL;
 	}
-
-	if (!g_utf8_validate (fb->buf, MIN(MAX_VALIDATE, fb->len), NULL))
+	
+	if (!g_utf8_validate (buffer, MIN(MAX_VALIDATE, length), NULL))
 	{
 		const AnjutaEncoding *encoding_used = NULL;
 		gchar* converted_text;
 		gsize converted_len;
-		converted_text = anjuta_convert_to_utf8 (fb->buf, 
-												 fb->len, 
+		converted_text = anjuta_convert_to_utf8 (buffer, 
+												 length, 
 												 &encoding_used,
 												 &converted_len, 
 												 NULL);
@@ -267,65 +189,69 @@
 			encoding_used =  
 				anjuta_encoding_get_from_charset("ISO-8859-15");
 			
-			converted_text = anjuta_convert_to_utf8 (fb->buf,
-												  fb->len,
+			converted_text = anjuta_convert_to_utf8 (buffer,
+												  length,
 												  &encoding_used,
 												  &converted_len,
 												  NULL);
 		}
+		g_free (buffer);
+		
 		if (converted_text == NULL)
 		{
 			/* Give up */
-			file_buffer_free(fb);
+			g_object_unref (file);
+			
 			return NULL;
 		}
-		else
-		{
-			g_free (fb->buf);
-			fb->buf = converted_text;
-			fb->len = converted_len;
-		}
+		
+		buffer = converted_text;
+		length = converted_len;
 	}
 	
-	if (pos <= 0 || pos > fb->len)
-	{
-		fb->pos = 0;
-		fb->line = 0;
-	}
-	else
-	{
-		fb->pos = pos;
-		fb->line = 0;
-	}
-	/* First line starts at column 0 */
-	fb->lines = g_list_prepend(fb->lines, GINT_TO_POINTER(0));
-	lineno = 0;
-	for (i=0; i < fb->len; ++i)
-	{
-		if ('\n' == fb->buf[i] && '\0' != fb->buf[i+1])
-		{
-			fb->lines = g_list_prepend(fb->lines, GINT_TO_POINTER(i + 1));
-			if (0 == fb->line && fb->pos > i)
-				fb->line = lineno;
-			++ lineno;
-		}
-	}
-	fb->lines = g_list_reverse(fb->lines);
+	fb = g_new0(FileBuffer, 1);
+	fb->type = FB_FILE;
+	
+	fb->file = file;
+	fb->len = length;
+	fb->buf = buffer;
+	
 	return fb;
 }
 
 static long
-file_buffer_line_from_pos(FileBuffer *fb, int pos)
+file_buffer_line_from_pos(FileBuffer *fb, gint pos)
 {
-	GList *tmp;
-	int lineno = -1;
+	gint lineno = -1;
+	
 	g_return_val_if_fail(fb && pos >= 0, 1);
+	
 	if (FB_FILE == fb->type)
 	{
-		gchar* p = g_utf8_offset_to_pointer(fb->buf, pos);
+		GList *tmp;
+		
+		if (fb->lines == NULL)
+		{
+			gint i;
+			/* First line starts at column 0 */
+			fb->lines = g_list_prepend(fb->lines, GINT_TO_POINTER(0));
+			lineno = 0;
+			for (i=0; i < fb->len; ++i)
+			{
+				if ('\n' == fb->buf[i] && '\0' != fb->buf[i+1])
+				{
+					fb->lines = g_list_prepend(fb->lines, GINT_TO_POINTER(i + 1));
+					if (0 == fb->line && fb->pos > i)
+						fb->line = lineno;
+					++ lineno;
+				}
+			}
+			fb->lines = g_list_reverse(fb->lines);
+		}
+		
 		for (tmp = fb->lines; tmp; tmp = g_list_next(tmp))
 		{
-			if (p - fb->buf < GPOINTER_TO_INT(tmp->data))
+			if (pos < GPOINTER_TO_INT(tmp->data))
 				return lineno;
 			++ lineno;
 		}
@@ -334,9 +260,13 @@
 	else if (FB_EDITOR == fb->type)
 	{
 		IAnjutaIterable *position;
-		position = ianjuta_editor_get_position_from_offset (fb->te, pos, NULL);
+		gint offset;
+		
+		offset = g_utf8_strlen (fb->buf, pos);
+		position = ianjuta_editor_get_position_from_offset (fb->te, offset, NULL);
 		lineno = ianjuta_editor_get_line_from_position (fb->te, position, NULL);
 		g_object_unref (position);
+		
 		return lineno;
 	}
 	else
@@ -347,13 +277,11 @@
 file_match_line_from_pos(FileBuffer *fb, int pos)
 {
 	gint length=1;
-	int start;
 	gint i;
 	g_return_val_if_fail(fb && pos >= 0, NULL);
 
-	start = g_utf8_offset_to_pointer(fb->buf, pos) - fb->buf;
-	for (i= start+1; ((fb->buf[i] != '\n') && (fb->buf[i] != '\0')); i++, length++);
-	for (i= start-1; (fb->buf[i] != '\n') && (i >= 0); i--, length++);
+	for (i= pos+1; ((fb->buf[i] != '\n') && (fb->buf[i] != '\0')); i++, length++);
+	for (i= pos -1; (fb->buf[i] != '\n') && (i >= 0); i--, length++);
 	
 	return g_strndup (fb->buf + i + 1, length);
 }
@@ -387,12 +315,8 @@
 	
 			while (node)
 			{
-				gchar *file_path;
-		
 				uri = (const gchar *)node->data;
-				file_path = anjuta_util_get_local_path_from_uri (uri);
-				if (file_path)
-				files = g_list_prepend (files, file_path);
+				files = g_list_prepend (files, g_strdup (uri));
 				node = g_list_next (node);
 			}
 			files = g_list_reverse (files);
@@ -474,7 +398,7 @@
 	}
 
 	g_regex_match_full (s->regex_info, fb->buf, fb->len,
-				   g_utf8_offset_to_pointer (fb->buf, fb->pos) - fb->buf, 
+				   fb->pos, 
 				   G_REGEX_MATCH_NOTEMPTY, &match_info, NULL);
 	
 	if (g_match_info_matches (match_info))
@@ -486,8 +410,8 @@
 		if (g_match_info_fetch_pos (match_info, 0, &start, &end))
 		{
 			DEBUG_PRINT ("Regex: %d %d", start, end);
-			mi->pos = g_utf8_pointer_to_offset (fb->buf, fb->buf + start);
-			mi->len = g_utf8_pointer_to_offset (fb->buf, fb->buf + end) - mi->pos;
+			mi->pos = start;
+			mi->len = end - mi->pos;
 			mi->line = file_buffer_line_from_pos(fb, mi->pos);
 		}
 		for (i = 1; i < g_match_info_get_match_count(match_info); i++) /* Captured subexpressions */
@@ -496,13 +420,13 @@
 			ms = g_new0(MatchSubStr, 1);
 			if (g_match_info_fetch_pos (match_info, i, &start, &end))
 			{
-				ms->start = g_utf8_pointer_to_offset (fb->buf, fb->buf + start);
-				ms->len = g_utf8_pointer_to_offset (fb->buf, fb->buf + end) - ms->start;
+				ms->start =start;
+				ms->len = end - ms->start;
 			}
 			mi->subs = g_list_prepend(mi->subs, ms);
 		}
 		mi->subs = g_list_reverse(mi->subs);
-		fb->pos = g_utf8_pointer_to_offset (fb->buf, fb->buf + end);
+		fb->pos = end;
 	}
 	return mi;
 }
@@ -511,8 +435,8 @@
 							 SearchDirection direction)
 {
 	MatchInfo *mi = g_new0 (MatchInfo, 1);
-	mi->pos = g_utf8_pointer_to_offset(fb->buf, match);
-	mi->len = g_utf8_pointer_to_offset(match, match_end);
+	mi->pos = match - fb->buf;
+	mi->len = match_end - match;
 	mi->line = file_buffer_line_from_pos (fb, mi->pos);
 
 	if (direction == SD_BACKWARD)
@@ -585,7 +509,7 @@
 get_next_utf8_match(FileBuffer *fb, SearchDirection direction, SearchExpression *s)
 {
 	gchar* search_key = normalize(s->search_str, -1, s->match_case);
-	gchar* current = g_utf8_offset_to_pointer (fb->buf, fb->pos);
+	gchar* current = fb->buf + fb->pos;
 	gchar* search_buf;
 	gchar* p = NULL;
 	MatchInfo *mi = NULL;
@@ -667,14 +591,14 @@
 
 static gint search_entry_compare(gconstpointer a, gconstpointer b)
 {
-	gchar* a_path = ((SearchEntry *) a)->path;
-	gchar* b_path = ((SearchEntry *) b)->path;
-	return g_strcmp0(a_path, b_path);
+	gchar* a_uri = ((SearchEntry *) a)->uri;
+	gchar* b_uri = ((SearchEntry *) b)->uri;
+	return g_strcmp0(a_uri, b_uri);
 }
 
 static void search_entry_free (gpointer data, gpointer user_data)
 {
-	g_free (((SearchEntry *)data)->path);
+	g_free (((SearchEntry *)data)->uri);
 	g_free (data);
 }
 
@@ -814,7 +738,7 @@
 			{
 				if (IANJUTA_IS_EDITOR (tmp->data))
 				{
-					gchar *path = NULL;
+					gchar *uri = NULL;
 
 					if (IANJUTA_IS_FILE (tmp->data))
 					{
@@ -822,7 +746,7 @@
 						
 						if (file != NULL)
 						{
-							path = g_file_get_path (file);
+							uri = g_file_get_uri (file);
 							g_object_unref (file);
 						}
 					}
@@ -830,7 +754,7 @@
 					se = g_new0 (SearchEntry, 1);
 					se->type = SE_BUFFER;
 					se->te = IANJUTA_EDITOR (tmp->data);
-					se->path = path;
+					se->uri = uri;
 					se->direction = SD_FORWARD;
 					se->start_pos = 0;
 					se->end_pos = -1;
@@ -869,7 +793,7 @@
 				{
 					se = g_new0(SearchEntry, 1);
 					se->type = SE_FILE;
-					se->path = (char *) tmp->data;
+					se->uri = (char *) tmp->data;
 					se->direction = SD_FORWARD;
 					se->type = SE_FILE;
 					se->start_pos = 0;

Modified: trunk/plugins/search/search-replace_backend.h
==============================================================================
--- trunk/plugins/search/search-replace_backend.h	(original)
+++ trunk/plugins/search/search-replace_backend.h	Sun Feb  8 14:11:48 2009
@@ -143,25 +143,23 @@
 {
 	FileBufferType type;
 
-	/* The following are valid only for files loaded from disk */
-	gchar *name; /* Name of the file */
+	GFile *file;			/* GFile object */
 
-	gchar *path; /* Full path to the file */
-	gchar *uri;  /* URI to the file */
-	gchar *buf; /* Contents of the file, null-terminated */
-	gint len; /* Length of the buffer */
+	gchar *buf;		/* Contents of the file, null-terminated */
+	gsize len;			/* Length of the buffer */
 
-	/* Current position: a count of UTF-8 characters, *not* bytes. */
+	/* Current position: a count of bytes, *not* UTF-8 characters. */
 	gint pos; 
 
-	gint line; /* Current line */
-	GList *lines; /* List of integers specifying line start positions in bytes */
+	gint line; 			/* Current line */
+	GList *lines; 		/* List of integers specifying line start positions in bytes */
 
 	gchar *canonical;   /* buffer text converted to canonical utf-8 form */
 	gchar *canonical_p; /* current pointer into canonical text */
 
 	/* The following are valid only for files corresponding to a TextEditor */
 	IAnjutaEditor *te;
+
 } FileBuffer;
 
 
@@ -176,17 +174,17 @@
 typedef struct _SearchEntry
 {
 	SearchEntryType type;
-	gchar *path;
+	gchar *uri;
 	IAnjutaEditor *te;
 	SearchDirection direction;
-	gint start_pos;
+	gint start_pos;		/* Both position in characters */
 	gint end_pos;
 } SearchEntry;
 	
 typedef struct _MatchInfo
 {
-	gint pos;
-	gint len;
+	gint pos;			/* in bytes */
+	gint len;			/* in bytes */
 	gint line;
 	GList *subs; /* <MatchSubStr *> */
 } MatchInfo;
@@ -202,13 +200,9 @@
 
 FileBuffer *file_buffer_new_from_te (IAnjutaEditor *te);
 
-FileBuffer *
-file_buffer_new_from_path(const char *path, const char *buf, int len, int pos);
-
-FileBuffer *
-file_buffer_new_from_path(const char *path, const char *buf, int len, int pos);
+FileBuffer *file_buffer_new_from_uri(const gchar *uri);
 
-gchar *file_match_line_from_pos(FileBuffer *fb, int pos);
+gchar *file_match_line_from_pos(FileBuffer *fb, gint pos);
 
 MatchInfo *get_next_match(FileBuffer *fb, SearchDirection direction, SearchExpression *s);
 

Modified: trunk/plugins/sourceview/sourceview.c
==============================================================================
--- trunk/plugins/sourceview/sourceview.c	(original)
+++ trunk/plugins/sourceview/sourceview.c	Sun Feb  8 14:11:48 2009
@@ -983,7 +983,7 @@
 static gint ieditor_get_length(IAnjutaEditor *editor, GError **e)
 {
 	/* We do not use gtk_text_buffer_get_char_count here because
-	someone may rely that this is the size of a buffer for all the text */
+	 we need a size in bytes not in characters */
 	
 	GtkTextIter start_iter;
 	GtkTextIter end_iter;
@@ -997,7 +997,7 @@
 								   &end_iter);
 	text = gtk_text_buffer_get_slice(GTK_TEXT_BUFFER(sv->priv->document),
 									&start_iter, &end_iter, TRUE);
-	length = g_utf8_strlen(text,  -1);
+	length = strlen(text);
 	g_free(text);
 
 	return length;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]