Kaydet (Commit) 13b673d8 authored tarafından Nick Treleaven's avatar Nick Treleaven

Go back to the same line when reloading. Fix start selection bug when clicking…

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

git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@468 ea778897-0a13-0410-b9d1-a72fbfd435f5
üst 2b362ef8
2006-06-20 Nick Treleaven <nick.treleaven@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@uvena.de> 2006-06-19 Enrico Troeger <enrico.troeger@uvena.de>
* THANKS, src/about.c: Added translator credits. * THANKS, src/about.c: Added translator credits.
......
...@@ -457,7 +457,7 @@ on_toolbutton23_clicked (GtkToolButton *toolbutton, ...@@ -457,7 +457,7 @@ on_toolbutton23_clicked (GtkToolButton *toolbutton,
("Are you sure you want to reload '%s'?\nAny unsaved changes will be lost."), ("Are you sure you want to reload '%s'?\nAny unsaved changes will be lost."),
basename)) basename))
{ {
document_open_file(idx, NULL, 0, doc_list[idx].readonly, doc_list[idx].file_type); document_reload_file(idx);
} }
g_free(basename); g_free(basename);
...@@ -973,7 +973,7 @@ on_editor_button_press_event (GtkWidget *widget, ...@@ -973,7 +973,7 @@ on_editor_button_press_event (GtkWidget *widget,
#ifndef GEANY_WIN32 #ifndef GEANY_WIN32
if (event->button == 1) if (event->button == 1)
{ {
utils_check_disk_status(idx); return utils_check_disk_status(idx);
} }
#endif #endif
......
...@@ -526,17 +526,17 @@ int document_open_file(gint idx, const gchar *filename, gint pos, gboolean reado ...@@ -526,17 +526,17 @@ int document_open_file(gint idx, const gchar *filename, gint pos, gboolean reado
doc_list[idx].changed = FALSE; doc_list[idx].changed = FALSE;
doc_list[idx].file_name = g_strdup(utf8_filename); doc_list[idx].file_name = g_strdup(utf8_filename);
doc_list[idx].encoding = enc; doc_list[idx].encoding = enc;
sci_goto_pos(doc_list[idx].sci, pos, TRUE);
if (reload) if (reload)
{ {
sci_goto_pos(doc_list[idx].sci, 0, FALSE);
msgwin_status_add(_("File %s reloaded."), utf8_filename); msgwin_status_add(_("File %s reloaded."), utf8_filename);
} }
else else
{ {
filetype *use_ft = (ft != NULL) ? ft : filetypes_get_from_filename(utf8_filename); 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( if (readonly) gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(
lookup_widget(app->window, "set_file_readonly1")), TRUE); 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 /* This is so ugly, but the checkbox in the file menu can be still checked from a previous
...@@ -585,6 +585,19 @@ int document_open_file(gint idx, const gchar *filename, gint pos, gboolean reado ...@@ -585,6 +585,19 @@ int document_open_file(gint idx, const gchar *filename, gint pos, gboolean reado
} }
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 */ /* This saves the file */
void document_save_file(gint idx) void document_save_file(gint idx)
{ {
......
...@@ -81,6 +81,8 @@ void document_new_file(filetype *ft); ...@@ -81,6 +81,8 @@ void document_new_file(filetype *ft);
*/ */
int document_open_file(gint, const gchar*, gint, gboolean, filetype*); 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 /* This saves the file, which is in on-disk encoding (which may not
be UTF-8). */ be UTF-8). */
......
...@@ -911,26 +911,26 @@ gchar *utils_find_open_xml_tag(const gchar sel[], gint size, gboolean check_tag) ...@@ -911,26 +911,26 @@ 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)
{ {
#ifndef GEANY_WIN32 #ifndef GEANY_WIN32
struct stat st; struct stat st;
time_t t; time_t t;
gchar *locale_filename; 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); 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); 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) if (doc_list[idx].mtime > t || st.st_mtime > t)
{ {
geany_debug("Strange: Something is wrong with the time stamps."); geany_debug("Strange: Something is wrong with the time stamps.");
return; return FALSE;
} }
if (doc_list[idx].mtime < st.st_mtime) if (doc_list[idx].mtime < st.st_mtime)
...@@ -941,17 +941,17 @@ void utils_check_disk_status(gint idx) ...@@ -941,17 +941,17 @@ void utils_check_disk_status(gint idx)
("The file '%s' on the disk is more recent than\n" ("The file '%s' on the disk is more recent than\n"
"the current buffer.\nDo you want to reload it?"), basename)) "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; doc_list[idx].last_check = t;
} }
else else
doc_list[idx].mtime = st.st_mtime; doc_list[idx].mtime = st.st_mtime;
g_free(basename); g_free(basename);
return; return TRUE; //file has changed
} }
#endif #endif
return; return FALSE;
} }
......
...@@ -96,7 +96,7 @@ gchar *utils_convert_to_utf8_from_charset(const gchar *buffer, gsize size, const ...@@ -96,7 +96,7 @@ gchar *utils_convert_to_utf8_from_charset(const gchar *buffer, gsize size, const
*/ */
gchar *utils_find_open_xml_tag(const gchar sel[], gint size, gboolean check_tag); 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); //gchar *utils_get_current_tag(gint idx, gint direction);
gint utils_get_current_function(gint idx, const gchar **tagname); gint utils_get_current_function(gint idx, const gchar **tagname);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment