SF.net SVN: geany: [468] trunk

ntrel at users.sourceforge.net ntrel at xxxxx
Tue Jun 20 11:55:44 UTC 2006


Revision: 468
Author:   ntrel
Date:     2006-06-20 04:55:34 -0700 (Tue, 20 Jun 2006)
ViewCVS:  http://svn.sourceforge.net/geany/?rev=468&view=rev

Log Message:
-----------
Go back to the same line when reloading. Fix start selection bug when clicking in the current file if it has changed

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/src/callbacks.c
    trunk/src/document.c
    trunk/src/document.h
    trunk/src/utils.c
    trunk/src/utils.h
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2006-06-19 18:31:17 UTC (rev 467)
+++ trunk/ChangeLog	2006-06-20 11:55:34 UTC (rev 468)
@@ -1,3 +1,11 @@
+2006-06-20  Nick Treleaven  <nick.treleaven at btinternet.com>
+
+ * src/utils.c, src/utils.h, src/callbacks.c, src/document.c,
+   src/document.h: Go back to the same line when reloading.
+                   Fix start selection bug when clicking in the
+                   current file if it has changed.
+
+
 2006-06-19  Enrico Troeger  <enrico.troeger at uvena.de>
 
   * THANKS, src/about.c: Added translator credits.

Modified: trunk/src/callbacks.c
===================================================================
--- trunk/src/callbacks.c	2006-06-19 18:31:17 UTC (rev 467)
+++ trunk/src/callbacks.c	2006-06-20 11:55:34 UTC (rev 468)
@@ -457,7 +457,7 @@
 				 ("Are you sure you want to reload '%s'?\nAny unsaved changes will be lost."),
 				 basename))
 	{
-		document_open_file(idx, NULL, 0, doc_list[idx].readonly, doc_list[idx].file_type);
+		document_reload_file(idx);
 	}
 
 	g_free(basename);
@@ -973,7 +973,7 @@
 #ifndef GEANY_WIN32
 	if (event->button == 1)
 	{
-		utils_check_disk_status(idx);
+		return utils_check_disk_status(idx);
 	}
 #endif
 

Modified: trunk/src/document.c
===================================================================
--- trunk/src/document.c	2006-06-19 18:31:17 UTC (rev 467)
+++ trunk/src/document.c	2006-06-20 11:55:34 UTC (rev 468)
@@ -526,17 +526,17 @@
 	doc_list[idx].changed = FALSE;
 	doc_list[idx].file_name = g_strdup(utf8_filename);
 	doc_list[idx].encoding = enc;
+
+	sci_goto_pos(doc_list[idx].sci, pos, TRUE);
+
 	if (reload)
 	{
-		sci_goto_pos(doc_list[idx].sci, 0, FALSE);
 		msgwin_status_add(_("File %s reloaded."), utf8_filename);
 	}
 	else
 	{
 		filetype *use_ft = (ft != NULL) ? ft : filetypes_get_from_filename(utf8_filename);
 
-		sci_goto_pos(doc_list[idx].sci, pos, TRUE);
-
 		if (readonly) gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(
 							lookup_widget(app->window, "set_file_readonly1")), TRUE);
 		/* This is so ugly, but the checkbox in the file menu can be still checked from a previous
@@ -585,6 +585,19 @@
 }
 
 
+int document_reload_file(gint idx)
+{
+	gint pos = 0;
+	if (idx < 0 || ! doc_list[idx].is_valid)
+		return -1;
+
+	// try to set the cursor to the position before reloading
+	pos = sci_get_current_position(doc_list[idx].sci);
+	return document_open_file(idx, NULL, pos, doc_list[idx].readonly,
+		doc_list[idx].file_type);
+}
+
+
 /* This saves the file */
 void document_save_file(gint idx)
 {

Modified: trunk/src/document.h
===================================================================
--- trunk/src/document.h	2006-06-19 18:31:17 UTC (rev 467)
+++ trunk/src/document.h	2006-06-20 11:55:34 UTC (rev 468)
@@ -81,7 +81,9 @@
  */
 int document_open_file(gint, const gchar*, gint, gboolean, filetype*);
 
+int document_reload_file(gint idx);
 
+
 /* This saves the file, which is in on-disk encoding (which may not
    be UTF-8). */
 void document_save_file (gint);

Modified: trunk/src/utils.c
===================================================================
--- trunk/src/utils.c	2006-06-19 18:31:17 UTC (rev 467)
+++ trunk/src/utils.c	2006-06-20 11:55:34 UTC (rev 468)
@@ -911,26 +911,26 @@
 }
 
 
-void utils_check_disk_status(gint idx)
+gboolean utils_check_disk_status(gint idx)
 {
 #ifndef GEANY_WIN32
 	struct stat st;
 	time_t t;
 	gchar *locale_filename;
 
-	if (idx == -1 || doc_list[idx].file_name == NULL) return;
+	if (idx == -1 || doc_list[idx].file_name == NULL) return FALSE;
 
 	t = time(NULL);
 
-	if (doc_list[idx].last_check > (t - GEANY_CHECK_FILE_DELAY)) return;
+	if (doc_list[idx].last_check > (t - GEANY_CHECK_FILE_DELAY)) return FALSE;
 
 	locale_filename = g_locale_from_utf8(doc_list[idx].file_name, -1, NULL, NULL, NULL);
-	if (stat(locale_filename, &st) != 0) return;
+	if (stat(locale_filename, &st) != 0) return FALSE;
 
 	if (doc_list[idx].mtime > t || st.st_mtime > t)
 	{
 		geany_debug("Strange: Something is wrong with the time stamps.");
-		return;
+		return FALSE;
 	}
 
 	if (doc_list[idx].mtime < st.st_mtime)
@@ -941,17 +941,17 @@
 					 ("The file '%s' on the disk is more recent than\n"
 					  "the current buffer.\nDo you want to reload it?"), basename))
 		{
-			document_open_file(idx, NULL, 0, doc_list[idx].readonly, doc_list[idx].file_type);
+			document_reload_file(idx);
 			doc_list[idx].last_check = t;
 		}
 		else
 			doc_list[idx].mtime = st.st_mtime;
 
 		g_free(basename);
-		return;
+		return TRUE; //file has changed
 	}
 #endif
-	return;
+	return FALSE;
 }
 
 

Modified: trunk/src/utils.h
===================================================================
--- trunk/src/utils.h	2006-06-19 18:31:17 UTC (rev 467)
+++ trunk/src/utils.h	2006-06-20 11:55:34 UTC (rev 468)
@@ -96,7 +96,7 @@
  */
 gchar *utils_find_open_xml_tag(const gchar sel[], gint size, gboolean check_tag);
 
-void utils_check_disk_status(gint idx);
+gboolean utils_check_disk_status(gint idx);
 
 //gchar *utils_get_current_tag(gint idx, gint direction);
 gint utils_get_current_function(gint idx, const gchar **tagname);


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