SF.net SVN: geany: [2704] branches/document-pointer
ntrel at users.sourceforge.net
ntrel at xxxxx
Wed Jun 18 14:18:38 UTC 2008
Revision: 2704
http://geany.svn.sourceforge.net/geany/?rev=2704&view=rev
Author: ntrel
Date: 2008-06-18 07:18:26 -0700 (Wed, 18 Jun 2008)
Log Message:
-----------
Bring back GeanyDocument::is_valid field as it is clearer and more
descriptive than using doc->index != -1.
Add deprecated macros DOC_IDX_VALID and DOC_IDX in plugindata.h,
which can make porting outside plugins easier; of course, it is
better to rewrite the code to use document pointers.
Use is_valid instead of the DOC_VALID macro when iterating over
documents_array, as there are never NULL pointers in it.
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/plugindata.h
branches/document-pointer/src/prefs.c
branches/document-pointer/src/search.c
branches/document-pointer/src/ui_utils.c
Modified: branches/document-pointer/ChangeLog
===================================================================
--- branches/document-pointer/ChangeLog 2008-06-18 13:37:03 UTC (rev 2703)
+++ branches/document-pointer/ChangeLog 2008-06-18 14:18:26 UTC (rev 2704)
@@ -7,6 +7,15 @@
Make doc_at() debug function check idx is within range.
* src/build.c, src/search.c:
Minor formatting.
+ * src/build.c, src/prefs.c, src/plugindata.h, src/callbacks.c,
+ src/search.c, src/document.c, src/document.h, src/ui_utils.c:
+ Bring back GeanyDocument::is_valid field as it is clearer and more
+ descriptive than using doc->index != -1.
+ Add deprecated macros DOC_IDX_VALID and DOC_IDX in plugindata.h,
+ which can make porting outside plugins easier; of course, it is
+ better to rewrite the code to use document pointers.
+ Use is_valid instead of the DOC_VALID macro when iterating over
+ documents_array, as there are never NULL pointers in it.
2008-06-16 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
Modified: branches/document-pointer/src/build.c
===================================================================
--- branches/document-pointer/src/build.c 2008-06-18 13:37:03 UTC (rev 2703)
+++ branches/document-pointer/src/build.c 2008-06-18 14:18:26 UTC (rev 2704)
@@ -390,7 +390,7 @@
for (i = 0; i < documents_array->len; i++)
{
- if (DOC_VALID(documents[i]))
+ if (documents[i]->is_valid)
editor_clear_indicators(documents[i]);
}
break;
Modified: branches/document-pointer/src/callbacks.c
===================================================================
--- branches/document-pointer/src/callbacks.c 2008-06-18 13:37:03 UTC (rev 2703)
+++ branches/document-pointer/src/callbacks.c 2008-06-18 14:18:26 UTC (rev 2704)
@@ -97,7 +97,7 @@
for (i = 0; i < documents_array->len; i++)
{
- if (DOC_VALID(documents[i]) && documents[i]->changed)
+ if (documents[i]->is_valid && documents[i]->changed)
{
return FALSE;
}
Modified: branches/document-pointer/src/document.c
===================================================================
--- branches/document-pointer/src/document.c 2008-06-18 13:37:03 UTC (rev 2703)
+++ branches/document-pointer/src/document.c 2008-06-18 14:18:26 UTC (rev 2704)
@@ -127,7 +127,7 @@
{
GeanyDocument *doc = documents[i];
- if (documents[i]->index == -1 || ! doc->real_path) continue;
+ if (! documents[i]->is_valid || ! doc->real_path) continue;
if (filenamecmp(realname, doc->real_path) == 0)
{
@@ -175,7 +175,7 @@
{
doc = documents[i];
- if (documents[i]->index == -1 || doc->file_name == NULL) continue;
+ if (! documents[i]->is_valid || doc->file_name == NULL) continue;
if (filenamecmp(utf8_filename, doc->file_name) == 0)
{
@@ -200,7 +200,7 @@
for (i = 0; i < documents_array->len; i++)
{
- if (documents[i]->index != -1 && documents[i]->sci == sci)
+ if (documents[i]->is_valid && documents[i]->sci == sci)
return documents[i];
}
return NULL;
@@ -327,15 +327,15 @@
}
-/* 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. */
+/* 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(). */
static void init_doc_struct(GeanyDocument *new_doc)
{
Document *full_doc = DOCUMENT(new_doc);
memset(full_doc, 0, sizeof(Document));
- new_doc->index = -1;
+ new_doc->is_valid = FALSE;
new_doc->has_tags = FALSE;
new_doc->auto_indent = (editor_prefs.indent_mode != INDENT_NONE);
new_doc->line_wrapping = editor_prefs.line_wrapping;
@@ -477,6 +477,7 @@
}
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 +505,7 @@
ui_document_buttons_update();
- this->index = new_idx; /* do this last to prevent UI updating with NULL items. */
+ this->is_valid = TRUE; /* do this last to prevent UI updating with NULL items. */
return this;
}
@@ -543,7 +544,7 @@
g_free(doc->real_path);
tm_workspace_remove_object(doc->tm_file, TRUE, TRUE);
- doc->index = -1;
+ doc->is_valid = FALSE;
doc->sci = NULL;
doc->file_name = NULL;
doc->real_path = NULL;
@@ -2487,7 +2488,7 @@
doc_indexes = g_array_new(FALSE, FALSE, sizeof(gint));
for (n = 0; n < (gint) documents_array->len; n++)
{
- if (DOC_VALID(documents[n]))
+ if (documents[n]->is_valid)
g_array_append_val(doc_indexes, n);
}
delay_colourise = TRUE;
@@ -2527,7 +2528,7 @@
/* colourise all in the doc_set */
for (n = 0; n < documents_array->len; n++)
{
- if (doc_set[n] && documents[n]->index != -1)
+ if (doc_set[n] && documents[n]->is_valid)
sci_colourise(documents[n]->sci, 0, -1);
}
delay_colourise = FALSE;
@@ -2589,7 +2590,7 @@
/* all documents should now be accounted for, so ignore any changes */
for (i = 0; i < len; i++)
{
- if (documents[i]->index != -1 && documents[i]->changed)
+ if (documents[i]->is_valid && documents[i]->changed)
{
documents[i]->changed = FALSE;
}
@@ -2605,7 +2606,7 @@
/* check all documents have been accounted for */
for (i = 0; i < len; i++)
{
- if (documents[i]->index != -1)
+ if (documents[i]->is_valid)
{
g_return_if_fail(!documents[i]->changed);
}
Modified: branches/document-pointer/src/document.h
===================================================================
--- branches/document-pointer/src/document.h 2008-06-18 13:37:03 UTC (rev 2703)
+++ branches/document-pointer/src/document.h 2008-06-18 14:18:26 UTC (rev 2704)
@@ -69,6 +69,8 @@
**/
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;
@@ -131,16 +133,10 @@
* 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.
- * This is only useful when iterating over the documents array or when using stored document
- * pointers like in msgwindow treeviews. */
+ * these only need a NULL-pointer check - @c p_document->get_current() != @c NULL. */
#define DOC_VALID(doc_ptr) \
- ((doc_ptr) != NULL && (doc_ptr)->index != -1)
+ ((doc_ptr) != NULL && (doc_ptr)->is_valid)
-/** 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_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.
Modified: branches/document-pointer/src/plugindata.h
===================================================================
--- branches/document-pointer/src/plugindata.h 2008-06-18 13:37:03 UTC (rev 2703)
+++ branches/document-pointer/src/plugindata.h 2008-06-18 14:18:26 UTC (rev 2704)
@@ -36,12 +36,12 @@
/* The API version should be incremented whenever any plugin data types below are
* modified or appended to. */
-static const gint api_version = 69;
+static const gint api_version = 70;
/* The ABI version should be incremented whenever existing fields in the plugin
* data types below have to be changed or reordered. It should stay the same if fields
* are only appended, as this doesn't affect existing fields. */
-static const gint abi_version = 38;
+static const gint abi_version = 39;
/** Check the plugin can be loaded by Geany.
* This performs runtime checks that try to ensure:
@@ -460,6 +460,12 @@
#define doc_array documents_array
+/** 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)
+#define DOC_IDX_VALID(doc_idx) \
+ ((doc_idx) >= 0 && (guint)(doc_idx) < documents_array->len && documents[doc_idx]->is_valid)
+
#endif /* GEANY_DISABLE_DEPRECATED */
#endif
Modified: branches/document-pointer/src/prefs.c
===================================================================
--- branches/document-pointer/src/prefs.c 2008-06-18 13:37:03 UTC (rev 2703)
+++ branches/document-pointer/src/prefs.c 2008-06-18 14:18:26 UTC (rev 2704)
@@ -824,7 +824,7 @@
editor_prefs.use_tabs = use_tabs;
for (i = 0; i < documents_array->len; i++)
{
- if (DOC_VALID(documents[i]))
+ if (documents[i]->is_valid)
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 (DOC_VALID(documents[i]))
+ if (documents[i]->is_valid)
{
document_apply_update_prefs(documents[i]);
if (! editor_prefs.folding)
@@ -1046,7 +1046,7 @@
{
Document *fdoc = DOCUMENT(documents[i]);
- if (DOC_VALID(documents[i]) && GTK_IS_WIDGET(fdoc->tag_tree))
+ if (documents[i]->is_valid && 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-18 13:37:03 UTC (rev 2703)
+++ branches/document-pointer/src/search.c 2008-06-18 14:18:26 UTC (rev 2704)
@@ -1407,7 +1407,7 @@
guint i;
for (i = 0; i < documents_array->len; i++)
{
- if (DOC_VALID(documents[i]))
+ if (documents[i]->is_valid)
if (find_document_usage(documents[i], search_text, flags) > 0)
found = TRUE;
}
Modified: branches/document-pointer/src/ui_utils.c
===================================================================
--- branches/document-pointer/src/ui_utils.c 2008-06-18 13:37:03 UTC (rev 2703)
+++ branches/document-pointer/src/ui_utils.c 2008-06-18 14:18:26 UTC (rev 2704)
@@ -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 (DOC_VALID(documents[i]) && documents[i]->changed)
+ if (documents[i]->is_valid && 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