SF.net SVN: geany: [922] trunk
ntrel at users.sourceforge.net
ntrel at xxxxx
Tue Oct 24 13:41:43 UTC 2006
Revision: 922
http://svn.sourceforge.net/geany/?rev=922&view=rev
Author: ntrel
Date: 2006-10-24 06:41:34 -0700 (Tue, 24 Oct 2006)
Log Message:
-----------
Fix setting document unchanged state when using Undo/Redo for
encoding or BOM changes.
Add sci_is_modified().
Added useful doc() function used only when debugging.
Modified Paths:
--------------
trunk/ChangeLog
trunk/src/document.c
trunk/src/document.h
trunk/src/sciwrappers.c
trunk/src/sciwrappers.h
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2006-10-23 20:56:11 UTC (rev 921)
+++ trunk/ChangeLog 2006-10-24 13:41:34 UTC (rev 922)
@@ -1,3 +1,13 @@
+2006-10-24 Nick Treleaven <nick.treleaven at btinternet.com>
+
+ * src/sciwrappers.h, src/sciwrappers.c, src/document.h,
+ src/document.c:
+ Fix setting document unchanged state when using Undo/Redo for
+ encoding or BOM changes.
+ Add sci_is_modified().
+ Added useful doc() function used only when debugging.
+
+
2006-10-23 Enrico Tröger <enrico.troeger at uvena.de>
* src/encodings.c, src/encodings.h, src/document.c, src/callbacks.c,
Modified: trunk/src/document.c
===================================================================
--- trunk/src/document.c 2006-10-23 20:56:11 UTC (rev 921)
+++ trunk/src/document.c 2006-10-24 13:41:34 UTC (rev 922)
@@ -179,6 +179,7 @@
ui_save_buttons_toggle(doc_list[idx].changed);
ui_set_window_title(idx);
+ ui_update_statusbar(idx, -1);
}
}
@@ -318,6 +319,8 @@
// store important pointers in the tab list
this->file_name = (filename) ? g_strdup(filename) : NULL;
this->encoding = NULL;
+ this->saved_encoding.encoding = NULL;
+ this->saved_encoding.has_bom = FALSE;
this->tm_file = NULL;
this->iter = iter;
this->file_type = NULL;
@@ -357,6 +360,7 @@
msgwin_status_add(_("File %s closed."),
(doc_list[idx].file_name) ? doc_list[idx].file_name : GEANY_STRING_UNTITLED);
g_free(doc_list[idx].encoding);
+ g_free(doc_list[idx].saved_encoding.encoding);
g_free(doc_list[idx].file_name);
tm_workspace_remove_object(doc_list[idx].tm_file, TRUE);
doc_list[idx].is_valid = FALSE;
@@ -383,6 +387,15 @@
}
+// used to keep a record of the unchanged document state encoding
+static void store_saved_encoding(gint idx)
+{
+ g_free(doc_list[idx].saved_encoding.encoding);
+ doc_list[idx].saved_encoding.encoding = g_strdup(doc_list[idx].encoding);
+ doc_list[idx].saved_encoding.has_bom = doc_list[idx].has_bom;
+}
+
+
/* This creates a new document, by clearing the text widget and setting the
current filename to NULL. */
void document_new_file(filetype *ft)
@@ -406,6 +419,9 @@
sci_empty_undo_buffer(doc_list[idx].sci);
doc_list[idx].encoding = g_strdup(encodings[app->pref_editor_default_encoding].charset);
+ // store the opened encoding for undo/redo
+ store_saved_encoding(idx);
+
//document_set_filetype(idx, (ft == NULL) ? filetypes[GEANY_FILETYPES_ALL] : ft);
document_set_filetype(idx, ft); // also clears taglist
if (ft == NULL) filetypes[GEANY_FILETYPES_ALL]->style_func_ptr(doc_list[idx].sci);
@@ -665,6 +681,7 @@
doc_list[idx].file_name = g_strdup(utf8_filename);
doc_list[idx].encoding = enc;
doc_list[idx].has_bom = bom;
+ store_saved_encoding(idx); // store the opened encoding for undo/redo
if (cl_options.goto_line >= 0)
{ // goto line which was specified on command line and then undefine the line
@@ -835,6 +852,9 @@
return FALSE;
}
+ // store the opened encoding for undo/redo
+ store_saved_encoding(idx);
+
// ignore the following things if we are quitting
if (! app->quitting)
{
@@ -1636,6 +1656,16 @@
}
+static void update_changed_state(gint idx)
+{
+ doc_list[idx].changed =
+ (sci_is_modified(doc_list[idx].sci) ||
+ doc_list[idx].has_bom != doc_list[idx].saved_encoding.has_bom ||
+ ! utils_strcmp(doc_list[idx].encoding, doc_list[idx].saved_encoding.encoding));
+ document_set_text_changed(idx);
+}
+
+
void document_undo(gint idx)
{
undo_action *action;
@@ -1689,6 +1719,7 @@
}
g_free(action); // free the action which was taken from the stack
+ update_changed_state(idx);
ui_update_popup_reundo_items(idx);
//geany_debug("%s: new stack height: %d", __func__, g_trash_stack_height(&doc_list[idx].undo_actions));
}
@@ -1757,6 +1788,7 @@
}
g_free(action); // free the action which was taken from the stack
+ update_changed_state(idx);
ui_update_popup_reundo_items(idx);
//geany_debug("%s: new stack height: %d", __func__, g_trash_stack_height(&doc_list[idx].redo_actions));
}
@@ -1783,4 +1815,9 @@
}
+// useful debugging function (usually debug macros aren't enabled)
+document *doc(gint idx)
+{
+ return DOC_IDX_VALID(idx) ? &doc_list[idx] : NULL;
+}
Modified: trunk/src/document.h
===================================================================
--- trunk/src/document.h 2006-10-23 20:56:11 UTC (rev 921)
+++ trunk/src/document.h 2006-10-24 13:41:34 UTC (rev 922)
@@ -35,6 +35,13 @@
#include "filetypes.h"
+typedef struct FileEncoding
+{
+ gchar *encoding;
+ gboolean has_bom;
+} FileEncoding;
+
+
/* structure for representing an open tab with all its related stuff. */
typedef struct document
{
@@ -61,6 +68,7 @@
time_t mtime;
GTrashStack *undo_actions;
GTrashStack *redo_actions;
+ FileEncoding saved_encoding;
} document;
Modified: trunk/src/sciwrappers.c
===================================================================
--- trunk/src/sciwrappers.c 2006-10-23 20:56:11 UTC (rev 921)
+++ trunk/src/sciwrappers.c 2006-10-24 13:41:34 UTC (rev 922)
@@ -273,6 +273,12 @@
}
+gboolean sci_is_modified(ScintillaObject *sci)
+{
+ return (SSM(sci, SCI_GETMODIFY, 0, 0) != 0);
+}
+
+
void sci_zoom_in( ScintillaObject* sci )
{
SSM( sci, SCI_ZOOMIN,0,0);
Modified: trunk/src/sciwrappers.h
===================================================================
--- trunk/src/sciwrappers.h 2006-10-23 20:56:11 UTC (rev 921)
+++ trunk/src/sciwrappers.h 2006-10-24 13:41:34 UTC (rev 922)
@@ -45,6 +45,7 @@
void sci_empty_undo_buffer (ScintillaObject* sci);
void sci_end_undo_action (ScintillaObject* sci);
void sci_start_undo_action (ScintillaObject* sci);
+gboolean sci_is_modified (ScintillaObject *sci);
void sci_set_visible_eols (ScintillaObject* sci, gboolean set );
gboolean sci_get_visible_eols (ScintillaObject* sci);
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