SF.net SVN: geany: [2693] branches/document-pointer

eht16 at users.sourceforge.net eht16 at xxxxx
Sun Jun 15 15:24:45 UTC 2008


Revision: 2693
          http://geany.svn.sourceforge.net/geany/?rev=2693&view=rev
Author:   eht16
Date:     2008-06-15 08:24:44 -0700 (Sun, 15 Jun 2008)

Log Message:
-----------
Get rid of GeanyDocument::is_valid, use the index value instead.
Remove DOC_IDX_* macros.

Modified Paths:
--------------
    branches/document-pointer/ChangeLog
    branches/document-pointer/src/build.c
    branches/document-pointer/src/callbacks.c
    branches/document-pointer/src/document.c
    branches/document-pointer/src/document.h
    branches/document-pointer/src/editor.c
    branches/document-pointer/src/main.c
    branches/document-pointer/src/msgwindow.c
    branches/document-pointer/src/prefs.c
    branches/document-pointer/src/search.c
    branches/document-pointer/src/symbols.c
    branches/document-pointer/src/ui_utils.c

Modified: branches/document-pointer/ChangeLog
===================================================================
--- branches/document-pointer/ChangeLog	2008-06-15 13:35:48 UTC (rev 2692)
+++ branches/document-pointer/ChangeLog	2008-06-15 15:24:44 UTC (rev 2693)
@@ -4,6 +4,10 @@
    Use document pointer instead of an index to the documents array
    everywhere in the core code.
    Pass a document pointer to the callbacks of all "document-*" signals.
+   Rename utils_check_disk_status() in document_check_disk_status() and
+   move it into document.c.
+   Get rid of GeanyDocument::is_valid, use the index value instead.
+   Remove DOC_IDX_* macros.
 
 
 2008-06-13  Nick Treleaven  <nick(dot)treleaven(at)btinternet(dot)com>

Modified: branches/document-pointer/src/build.c
===================================================================
--- branches/document-pointer/src/build.c	2008-06-15 13:35:48 UTC (rev 2692)
+++ branches/document-pointer/src/build.c	2008-06-15 15:24:44 UTC (rev 2693)
@@ -390,7 +390,7 @@
 
 			for (i = 0; i < documents_array->len; i++)
 			{
-				if (documents[i]->is_valid)
+				if (DOC_VALID(documents[i]))
 					editor_clear_indicators(documents[i]);
 			}
 			break;

Modified: branches/document-pointer/src/callbacks.c
===================================================================
--- branches/document-pointer/src/callbacks.c	2008-06-15 13:35:48 UTC (rev 2692)
+++ branches/document-pointer/src/callbacks.c	2008-06-15 15:24:44 UTC (rev 2693)
@@ -97,7 +97,7 @@
 
 	for (i = 0; i < documents_array->len; i++)
 	{
-		if (documents[i]->is_valid && documents[i]->changed)
+		if (DOC_VALID(documents[i]) && documents[i]->changed)
 		{
 			return FALSE;
 		}

Modified: branches/document-pointer/src/document.c
===================================================================
--- branches/document-pointer/src/document.c	2008-06-15 13:35:48 UTC (rev 2692)
+++ branches/document-pointer/src/document.c	2008-06-15 15:24:44 UTC (rev 2693)
@@ -127,7 +127,7 @@
 	{
 		GeanyDocument *doc = documents[i];
 
-		if (! documents[i]->is_valid || ! doc->real_path) continue;
+		if (documents[i]->index == -1 || ! doc->real_path) continue;
 
 		if (filenamecmp(realname, doc->real_path) == 0)
 		{
@@ -175,7 +175,7 @@
 	{
 		doc = documents[i];
 
-		if (! documents[i]->is_valid || doc->file_name == NULL) continue;
+		if (documents[i]->index == -1 || doc->file_name == NULL) continue;
 
 		if (filenamecmp(utf8_filename, doc->file_name) == 0)
 		{
@@ -199,7 +199,7 @@
 
 	for (i = 0; i < documents_array->len; i++)
 	{
-		if (documents[i]->is_valid && documents[i]->sci == sci)
+		if (documents[i]->index == -1 && documents[i]->sci == sci)
 			return documents[i];
 	}
 	return NULL;
@@ -325,15 +325,15 @@
 }
 
 
-/* Sets is_valid to FALSE and initializes some members to NULL, to mark it uninitialized.
- * The flag is_valid is set to TRUE in document_create(). */
+/* Sets index to -1 and initializes some members to NULL, to mark it uninitialized.
+ * The document index is set in document_create() to mark it as valid. */
 static void init_doc_struct(GeanyDocument *new_doc)
 {
 	Document *full_doc = DOCUMENT(new_doc);
 
 	memset(full_doc, 0, sizeof(Document));
 
-	new_doc->is_valid = FALSE;
+	new_doc->index = -1;
 	new_doc->has_tags = FALSE;
 	new_doc->auto_indent = (editor_prefs.indent_mode != INDENT_NONE);
 	new_doc->line_wrapping = editor_prefs.line_wrapping;
@@ -476,7 +476,6 @@
 	}
 	this = documents[new_idx];
 	init_doc_struct(this);	/* initialize default document settings */
-	this->index = new_idx;
 
 	this->file_name = g_strdup(utf8_filename);
 
@@ -504,7 +503,7 @@
 
 	ui_document_buttons_update();
 
-	this->is_valid = TRUE;	/* do this last to prevent UI updating with NULL items. */
+	this->index = new_idx; /* do this last to prevent UI updating with NULL items. */
 	return this;
 }
 
@@ -521,7 +520,7 @@
 {
 	GeanyDocument *doc = document_get_from_page(page_num);
 
-	if (DOC_VALID(doc))
+	if (doc != NULL)
 	{
 		Document *fdoc = DOCUMENT(doc);
 
@@ -543,7 +542,7 @@
 		g_free(doc->real_path);
 		tm_workspace_remove_object(doc->tm_file, TRUE, TRUE);
 
-		doc->is_valid = FALSE;
+		doc->index = -1;
 		doc->sci = NULL;
 		doc->file_name = NULL;
 		doc->real_path = NULL;
@@ -2128,7 +2127,7 @@
 	gboolean colourise = FALSE;
 	gboolean ft_changed;
 
-	if (type == NULL || ! DOC_VALID(doc))
+	if (type == NULL || doc == NULL)
 		return;
 
 	geany_debug("%s : %s (%s)",
@@ -2462,7 +2461,7 @@
 #ifdef GEANY_DEBUG
 GeanyDocument *doc_at(gint idx)
 {
-	return DOC_IDX_VALID(idx) ? documents[idx] : NULL;
+	return (idx >= 0) ? documents[idx] : NULL;
 }
 #endif
 
@@ -2482,7 +2481,7 @@
 	doc_indexes = g_array_new(FALSE, FALSE, sizeof(gint));
 	for (n = 0; n < (gint) documents_array->len; n++)
 	{
-		if (DOC_IDX_VALID(n))
+		if (DOC_VALID(documents[n]))
 			g_array_append_val(doc_indexes, n);
 	}
 	delay_colourise = TRUE;
@@ -2522,7 +2521,7 @@
 	/* colourise all in the doc_set */
 	for (n = 0; n < documents_array->len; n++)
 	{
-		if (doc_set[n] && documents[n]->is_valid)
+		if (doc_set[n] && documents[n]->index != -1)
 			sci_colourise(documents[n]->sci, 0, -1);
 	}
 	delay_colourise = FALSE;
@@ -2584,7 +2583,7 @@
 	/* all documents should now be accounted for, so ignore any changes */
 	for (i = 0; i < len; i++)
 	{
-		if (documents[i]->is_valid && documents[i]->changed)
+		if (documents[i]->index != -1 && documents[i]->changed)
 		{
 			documents[i]->changed = FALSE;
 		}
@@ -2600,7 +2599,7 @@
 	/* check all documents have been accounted for */
 	for (i = 0; i < len; i++)
 	{
-		if (documents[i]->is_valid)
+		if (documents[i]->index != -1)
 		{
 			g_return_if_fail(!documents[i]->changed);
 		}

Modified: branches/document-pointer/src/document.h
===================================================================
--- branches/document-pointer/src/document.h	2008-06-15 13:35:48 UTC (rev 2692)
+++ branches/document-pointer/src/document.h	2008-06-15 15:24:44 UTC (rev 2693)
@@ -69,8 +69,6 @@
  **/
 struct GeanyDocument
 {
-	/** General flag to represent this document is active and all properties are set correctly. */
-	gboolean		 is_valid;
 	gint			 index;		/**< Index in the documents array. */
 	/** Whether this %document support source code symbols(tags) to show in the sidebar. */
 	gboolean		 has_tags;
@@ -133,23 +131,17 @@
  * This is useful when @a doc_ptr was stored some time earlier and documents may have been
  * closed since then.
  * @note This should not be used to check the result of the main API functions,
- * these only need a NULL-pointer check - @c p_document->get_current() != @c NULL. */
+ * these only need a NULL-pointer check - @c p_document->get_current() != @c NULL.
+ * This is only useful when iterating over the documents array or when using stored document
+ * pointers like in msgwindow treeviews. */
 #define DOC_VALID(doc_ptr) \
-	((doc_ptr) != NULL && (doc_ptr)->is_valid)
+	((doc_ptr) != NULL && (doc_ptr)->index != -1)
 
 /** NULL-safe way to get the index of @a doc_ptr in the documents array. */
 #define DOC_IDX(doc_ptr) \
 	(doc_ptr ? doc_ptr->index : -1)
 
 /**
- *  DOC_IDX_VALID checks whether the passed index points to a valid %document object by checking
- *  important properties. It returns FALSE if the index is not valid and then this index
- *  must not be used.
- **/
-#define DOC_IDX_VALID(doc_idx) \
-	((doc_idx) >= 0 && (guint)(doc_idx) < documents_array->len && documents[doc_idx]->is_valid)
-
-/**
  *  DOC_FILENAME returns the filename of the %document corresponding to the passed index or
  *  GEANY_STRING_UNTITLED (e.g. _("untitled")) if the %document's filename was not yet set.
  *  This macro never returns NULL.
@@ -157,9 +149,6 @@
 #define DOC_FILENAME(doc) \
 	((doc->file_name != NULL) ? (doc->file_name) : GEANY_STRING_UNTITLED)
 
-#define DOC_IDX_FILENAME(doc_idx) \
-	((documents[doc_idx]->file_name != NULL) ? (documents[doc_idx]->file_name) : \
-		GEANY_STRING_UNTITLED)
 
 
 /* These functions will replace the older functions. For now they have a documents_ prefix. */

Modified: branches/document-pointer/src/editor.c
===================================================================
--- branches/document-pointer/src/editor.c	2008-06-15 13:35:48 UTC (rev 2692)
+++ branches/document-pointer/src/editor.c	2008-06-15 15:24:44 UTC (rev 2693)
@@ -85,7 +85,7 @@
 {
 	GeanyDocument *doc = user_data;
 
-	if (! DOC_VALID(doc))
+	if (doc == NULL)
 		return FALSE;
 
 	editor_info.click_pos = sci_get_position_from_xy(doc->sci, (gint)event->x, (gint)event->y, FALSE);

Modified: branches/document-pointer/src/main.c
===================================================================
--- branches/document-pointer/src/main.c	2008-06-15 13:35:48 UTC (rev 2692)
+++ branches/document-pointer/src/main.c	2008-06-15 15:24:44 UTC (rev 2693)
@@ -679,13 +679,13 @@
 	{
 		doc = document_open_file(filename, FALSE, NULL, NULL);
 		/* add recent file manually because opening_session_files is set */
-		if (DOC_VALID(doc))
+		if (doc != NULL)
 			ui_add_recent_file(doc->file_name);
 	}
 	else if (filename != NULL)
 	{	/* create new file if it doesn't exist */
 		doc = document_new_file(filename, NULL, NULL);
-		if (DOC_VALID(doc))
+		if (doc != NULL)
 		{
 			ui_add_recent_file(doc->file_name);
 		}

Modified: branches/document-pointer/src/msgwindow.c
===================================================================
--- branches/document-pointer/src/msgwindow.c	2008-06-15 13:35:48 UTC (rev 2692)
+++ branches/document-pointer/src/msgwindow.c	2008-06-15 15:24:44 UTC (rev 2693)
@@ -807,7 +807,7 @@
 		GeanyDocument *old_doc = document_get_current();
 
 		gtk_tree_model_get(model, &iter, 0, &line, 1, &doc, 3, &string, -1);
-		/* doc may have been closed, so check doc->is_valid: */
+		/* doc may have been closed, so check doc->index: */
 		if (line >= 0 && DOC_VALID(doc))
 		{
 			ret = navqueue_goto_line(old_doc, doc, line);

Modified: branches/document-pointer/src/prefs.c
===================================================================
--- branches/document-pointer/src/prefs.c	2008-06-15 13:35:48 UTC (rev 2692)
+++ branches/document-pointer/src/prefs.c	2008-06-15 15:24:44 UTC (rev 2693)
@@ -824,7 +824,7 @@
 				editor_prefs.use_tabs = use_tabs;
 				for (i = 0; i < documents_array->len; i++)
 				{
-					if (documents[i]->is_valid)
+					if (DOC_VALID(documents[i]))
 						editor_set_use_tabs(documents[i], editor_prefs.use_tabs);
 				}
 			}
@@ -977,7 +977,7 @@
 		/* re-colourise all open documents, if tab width or long line settings have changed */
 		for (i = 0; i < documents_array->len; i++)
 		{
-			if (documents[i]->is_valid)
+			if (DOC_VALID(documents[i]))
 			{
 				document_apply_update_prefs(documents[i]);
 				if (! editor_prefs.folding)
@@ -1046,7 +1046,7 @@
 			{
 				Document *fdoc = DOCUMENT(documents[i]);
 
-				if (documents[i]->is_valid && GTK_IS_WIDGET(fdoc->tag_tree))
+				if (DOC_VALID(documents[i]) && GTK_IS_WIDGET(fdoc->tag_tree))
 					ui_widget_modify_font_from_string(fdoc->tag_tree,
 						interface_prefs.tagbar_font);
 			}

Modified: branches/document-pointer/src/search.c
===================================================================
--- branches/document-pointer/src/search.c	2008-06-15 13:35:48 UTC (rev 2692)
+++ branches/document-pointer/src/search.c	2008-06-15 15:24:44 UTC (rev 2693)
@@ -856,14 +856,14 @@
 		gboolean check_close = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
 						lookup_widget(GTK_WIDGET(widgets.find_dialog), "check_close")));
 
+		if (doc == NULL)
+			return;
+
 		search_replace_escape = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
 						lookup_widget(GTK_WIDGET(widgets.find_dialog), "check_escape")));
 		search_data.backwards = FALSE;
 		search_data.search_bar = FALSE;
 
-		if (DOC_VALID(doc))
-			return;
-
 		g_free(search_data.text);
 		search_data.text = g_strdup(gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(user_data)))));
 		if (strlen(search_data.text) == 0 ||
@@ -1012,8 +1012,6 @@
 			{
 				GeanyDocument *tmp_doc = document_get_from_page(n);
 
-				if (! tmp_doc->is_valid) continue;
-
 				if (document_replace_all(tmp_doc, find, replace, search_flags_re,
 					search_replace_escape_re)) count++;
 			}
@@ -1409,7 +1407,7 @@
 		guint i;
 		for (i = 0; i < documents_array->len; i++)
 		{
-			if (documents[i]->is_valid)
+			if (DOC_VALID(documents[i]))
 				if (find_document_usage(documents[i], search_text, flags) > 0) found = TRUE;
 		}
 	}

Modified: branches/document-pointer/src/symbols.c
===================================================================
--- branches/document-pointer/src/symbols.c	2008-06-15 13:35:48 UTC (rev 2692)
+++ branches/document-pointer/src/symbols.c	2008-06-15 15:24:44 UTC (rev 2693)
@@ -846,7 +846,7 @@
 	filetype_id ft_id;
 	Document *fdoc;
 
-	g_return_val_if_fail(DOC_VALID(doc), FALSE);
+	g_return_val_if_fail(doc != NULL, FALSE);
 
 	ft_id = FILETYPE_ID(doc->file_type);
 	fdoc = DOCUMENT(doc);

Modified: branches/document-pointer/src/ui_utils.c
===================================================================
--- branches/document-pointer/src/ui_utils.c	2008-06-15 13:35:48 UTC (rev 2692)
+++ branches/document-pointer/src/ui_utils.c	2008-06-15 15:24:44 UTC (rev 2693)
@@ -555,7 +555,7 @@
 	{
 		/* check whether there are files where changes were made and if there are some,
 		 * we need the save all button / item */
-		if (documents[i]->is_valid && documents[i]->changed)
+		if (DOC_VALID(documents[i]) && documents[i]->changed)
 		{
 			dirty_tabs = TRUE;
 			break;


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