From 5763dfbe2d192bc61f239cacc417d8412cf800d3 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Wed, 3 Dec 2008 18:03:54 +0000 Subject: [PATCH] Add document_index(), filetypes_index() array accessor functions to the plugin API. git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@3310 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 4 ++++ plugins/geanyfunctions.h | 4 ++++ src/document.c | 10 +++++----- src/document.h | 8 ++++---- src/filetypes.c | 11 +++++++++++ src/filetypes.h | 2 ++ src/plugindata.h | 4 +++- src/plugins.c | 7 ++++--- 8 files changed, 37 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index ee70ddb71..03f69ca2e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -8,6 +8,10 @@ the geanyfunctions.h macro works. Deprecate p_sci->send_message(). Add scintilla_new() to the plugin API. + * src/plugindata.h, src/filetypes.c, src/filetypes.h, src/document.c, + src/plugins.c, src/document.h, plugins/geanyfunctions.h: + Add document_index(), filetypes_index() array accessor functions to + the plugin API. 2008-12-02 Nick Treleaven diff --git a/plugins/geanyfunctions.h b/plugins/geanyfunctions.h index 38a06e4d4..f16e56033 100644 --- a/plugins/geanyfunctions.h +++ b/plugins/geanyfunctions.h @@ -36,6 +36,8 @@ This allows the use of normal API function names in plugins. */ p_document->set_filetype #define document_close \ p_document->close +#define document_index \ + p_document->index #define editor_get_indent_prefs \ p_editor->get_indent_prefs #define editor_create_widget \ @@ -226,6 +228,8 @@ This allows the use of normal API function names in plugins. */ p_filetypes->detect_from_file #define filetypes_lookup_by_name \ p_filetypes->lookup_by_name +#define filetypes_index \ + p_filetypes->index #define navqueue_goto_line \ p_navqueue->goto_line #define main_reload_configuration \ diff --git a/src/document.c b/src/document.c index 14a7b0afb..93a971666 100644 --- a/src/document.c +++ b/src/document.c @@ -2470,14 +2470,14 @@ GdkColor *document_get_status_color(GeanyDocument *doc) } -/* useful debugging function (usually debug macros aren't enabled so can't use - * documents[idx]) */ -#ifdef GEANY_DEBUG -GeanyDocument *doc_at(gint idx) +/** Accessor function for @ref GeanyData::documents_array items. + * @warning Always check the returned document is valid (@c doc->is_valid). + * @param idx @c documents_array index. + * @return The document, or @c NULL if @a idx is out of range. */ +GeanyDocument *document_index(gint idx) { return (idx >= 0 && idx < (gint) documents_array->len) ? documents[idx] : NULL; } -#endif /* create a new file and copy file content and properties */ diff --git a/src/document.h b/src/document.h index 6da6d3d0a..c56ba5d16 100644 --- a/src/document.h +++ b/src/document.h @@ -112,10 +112,8 @@ struct GeanyDocument extern GPtrArray *documents_array; -/** - * This wraps documents_array so it can be used with C array syntax. - * Example: documents[0]->sci = NULL; - **/ +/* Wrap documents_array so it can be used with C array syntax. + * Example: documents[0]->sci = NULL; */ #define documents ((GeanyDocument **)documents_array->pdata) /** Check that the @a doc_ptr document still exists (has not been closed). @@ -160,6 +158,8 @@ void document_set_text_changed(GeanyDocument *doc, gboolean changed); void document_set_filetype(GeanyDocument *doc, GeanyFiletype *type); +GeanyDocument *document_index(gint idx); + GeanyDocument *document_find_by_sci(ScintillaObject *sci); gint document_get_notebook_page(GeanyDocument *doc); diff --git a/src/filetypes.c b/src/filetypes.c index 981b6381c..f1f81400a 100644 --- a/src/filetypes.c +++ b/src/filetypes.c @@ -1432,3 +1432,14 @@ void filetypes_read_extensions(void) g_key_file_free(userconfig); } + +/** Accessor function for @ref GeanyData::filetypes_array items. + * Example: @code ft = filetypes_index(GEANY_FILETYPES_C); @endcode + * @param idx @c filetypes_array index. + * @return The filetype, or @c NULL if @a idx is out of range. */ +GeanyFiletype *filetypes_index(gint idx) +{ + return (idx >= 0 && idx < (gint) filetypes_array->len) ? filetypes[idx] : NULL; +} + + diff --git a/src/filetypes.h b/src/filetypes.h index 257fd8992..c1bf8a7fb 100644 --- a/src/filetypes.h +++ b/src/filetypes.h @@ -158,6 +158,8 @@ void filetypes_init_types(void); void filetypes_read_extensions(void); +GeanyFiletype *filetypes_index(gint idx); + GeanyFiletype *filetypes_detect_from_document(GeanyDocument *doc); GeanyFiletype *filetypes_detect_from_extension(const gchar *utf8_filename); diff --git a/src/plugindata.h b/src/plugindata.h index 4ba9d6b9c..6ebb3c3df 100644 --- a/src/plugindata.h +++ b/src/plugindata.h @@ -45,7 +45,7 @@ enum { /** The Application Programming Interface (API) version, incremented * whenever any plugin data types are modified or appended to. */ - GEANY_API_VERSION = 114, + GEANY_API_VERSION = 115, /** The Application Binary Interface (ABI) version, incremented whenever * existing fields in the plugin data types have to be changed or reordered. */ @@ -246,6 +246,7 @@ typedef struct DocumentFuncs void (*set_text_changed) (struct GeanyDocument *doc, gboolean changed); void (*set_filetype) (struct GeanyDocument *doc, struct GeanyFiletype *type); gboolean (*close) (GeanyDocument *doc); + struct GeanyDocument* (*index)(gint idx); } DocumentFuncs; @@ -452,6 +453,7 @@ typedef struct FiletypeFuncs { GeanyFiletype* (*detect_from_file) (const gchar *utf8_filename); GeanyFiletype* (*lookup_by_name) (const gchar *name); + GeanyFiletype* (*index)(gint idx); /* Remember to convert any filetype_id arguments to GeanyFiletype pointers in any * appended functions */ } diff --git a/src/plugins.c b/src/plugins.c index 872039e15..928f80b96 100644 --- a/src/plugins.c +++ b/src/plugins.c @@ -126,7 +126,8 @@ static DocumentFuncs doc_funcs = { &document_set_encoding, &document_set_text_changed, &document_set_filetype, - &document_close + &document_close, + &document_index }; static EditorFuncs editor_funcs = { @@ -268,10 +269,10 @@ static HighlightingFuncs highlighting_funcs = { &highlighting_get_style }; - static FiletypeFuncs filetype_funcs = { &filetypes_detect_from_file, - &filetypes_lookup_by_name + &filetypes_lookup_by_name, + &filetypes_index }; static NavQueueFuncs navqueue_funcs = {