Revision: 3567 http://geany.svn.sourceforge.net/geany/?rev=3567&view=rev Author: eht16 Date: 2009-02-08 19:52:21 +0000 (Sun, 08 Feb 2009)
Log Message: ----------- Add editor_get_word_at_pos() as a convenient function to retrieve the word at a given position. Make document_get_status_color() returning a const GdkColor. Add editor_get_word_at_pos() and document_get_status_color() to the plugin API.
Modified Paths: -------------- trunk/ChangeLog trunk/plugins/geanyfunctions.h trunk/src/document.c trunk/src/document.h trunk/src/editor.c trunk/src/editor.h trunk/src/plugindata.h trunk/src/plugins.c trunk/src/treeviews.c trunk/src/ui_utils.c
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2009-02-08 19:51:49 UTC (rev 3566) +++ trunk/ChangeLog 2009-02-08 19:52:21 UTC (rev 3567) @@ -5,6 +5,14 @@ Return TRUE if appropriate in the event handlers. * plugins/vcdiff.c: Fix path quoting problems on Windows. + * plugins/geanyfunctions.h, src/document.c, src/document.h, + src/editor.c, src/editor.h, src/plugindata.h, src/plugins.c, + src/treeviews.c, src/ui_utils.c: + Add editor_get_word_at_pos() as a convenient function to retrieve + the word at a given position. + Make document_get_status_color() returning a const GdkColor. + Add editor_get_word_at_pos() and document_get_status_color() to the + plugin API.
2009-02-08 Frank Lanitz <frank(at)frank(dot)uvena(dot)de>
Modified: trunk/plugins/geanyfunctions.h =================================================================== --- trunk/plugins/geanyfunctions.h 2009-02-08 19:51:49 UTC (rev 3566) +++ trunk/plugins/geanyfunctions.h 2009-02-08 19:52:21 UTC (rev 3567) @@ -46,6 +46,8 @@ geany_functions->p_document->save_file_as #define document_rename_file \ geany_functions->p_document->rename_file +#define document_get_status_color \ + geany_functions->p_document->get_status_color #define editor_get_indent_prefs \ geany_functions->p_editor->get_indent_prefs #define editor_create_widget \ @@ -58,6 +60,8 @@ geany_functions->p_editor->indicator_clear #define editor_set_indent_type \ geany_functions->p_editor->set_indent_type +#define editor_get_word_at_pos \ + geany_functions->p_editor->get_word_at_pos #define scintilla_send_message \ geany_functions->p_scintilla->send_message #define scintilla_new \
Modified: trunk/src/document.c =================================================================== --- trunk/src/document.c 2009-02-08 19:51:49 UTC (rev 3566) +++ trunk/src/document.c 2009-02-08 19:52:21 UTC (rev 3567) @@ -2675,9 +2675,19 @@ }
-/* Gets the status colour of the document, or NULL if default widget - * colouring should be used. */ -GdkColor *document_get_status_color(GeanyDocument *doc) +/** + * Gets the status colour of the document, or NULL if default widget colouring should be used. + * Returned colours are red if the document has changes, green is the document is read-only + * or simply NULL if the document is unmodified but writable. + * + * @param doc The document to use. + * + * @return The colour for the document or NULL if the default colour should be used. The colour + * object is owned by Geany and should not be modified or freed. + * + * @since 0.16 + */ +const GdkColor *document_get_status_color(GeanyDocument *doc) { static GdkColor red = {0, 0xFFFF, 0, 0}; static GdkColor green = {0, 0, 0x7FFF, 0};
Modified: trunk/src/document.h =================================================================== --- trunk/src/document.h 2009-02-08 19:51:49 UTC (rev 3566) +++ trunk/src/document.h 2009-02-08 19:52:21 UTC (rev 3567) @@ -223,6 +223,6 @@
void document_update_tab_label(GeanyDocument *doc);
-GdkColor *document_get_status_color(GeanyDocument *doc); +const GdkColor *document_get_status_color(GeanyDocument *doc);
#endif
Modified: trunk/src/editor.c =================================================================== --- trunk/src/editor.c 2009-02-08 19:51:49 UTC (rev 3566) +++ trunk/src/editor.c 2009-02-08 19:52:21 UTC (rev 3567) @@ -1248,6 +1248,35 @@ }
+/** + * Finds the word at the position specified by @c pos. If any word is found, it is returned. + * Otherwise NULL is returned. + * Additional wordchars can be specified to define what to consider as a word. + * + * @param editor The editor to operate on. + * @param pos The position where the word should be read from. + * Maybe @a -1 to use the current position. + * @param wordchars The wordchars to separate words. wordchars mean all characters to count + * as part of a word. Maybe @a NULL to use the default wordchars, + * see @ref GEANY_WORDCHARS. + * + * @return A newly-allocated string containing the word at the given @c pos or NULL. + * Should be freed when no longer needed. + * + * @since 0.16 + */ +gchar *editor_get_word_at_pos(GeanyEditor *editor, gint pos, const gchar *wordchars) +{ + static gchar cword[GEANY_MAX_WORD_LENGTH]; + + g_return_val_if_fail(editor != NULL, FALSE); + + read_current_word(editor, pos, cword, sizeof(cword), wordchars, FALSE); + + return (*cword == '\0') ? NULL : g_strdup(cword); +} + + /* Read the word up to position @a pos. */ static const gchar * editor_read_word_stem(GeanyEditor *editor, gint pos, const gchar *wordchars)
Modified: trunk/src/editor.h =================================================================== --- trunk/src/editor.h 2009-02-08 19:51:49 UTC (rev 3566) +++ trunk/src/editor.h 2009-02-08 19:52:21 UTC (rev 3567) @@ -28,6 +28,7 @@ #include "Scintilla.h" #include "ScintillaWidget.h"
+/** Default character set to define which characters shoud be treated as part of a word. */ #define GEANY_WORDCHARS "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" #define GEANY_MAX_WORD_LENGTH 192
@@ -217,6 +218,8 @@ void editor_find_current_word(GeanyEditor *editor, gint pos, gchar *word, size_t wordlen, const gchar *wc);
+gchar *editor_get_word_at_pos(GeanyEditor *editor, gint pos, const gchar *wordchars); + gchar *editor_get_default_selection(GeanyEditor *editor, gboolean use_current_word, const gchar *wordchars);
void editor_select_word(GeanyEditor *editor);
Modified: trunk/src/plugindata.h =================================================================== --- trunk/src/plugindata.h 2009-02-08 19:51:49 UTC (rev 3566) +++ trunk/src/plugindata.h 2009-02-08 19:52:21 UTC (rev 3567) @@ -252,6 +252,7 @@ struct GeanyDocument* (*index)(gint idx); gboolean (*save_file_as) (struct GeanyDocument *doc, const gchar *utf8_fname); void (*rename_file) (struct GeanyDocument *doc, const gchar *new_filename); + const GdkColor* (*get_status_color) (struct GeanyDocument *doc); } DocumentFuncs;
@@ -518,6 +519,7 @@ void (*indicator_clear) (struct GeanyEditor *editor, gint indic);
void (*set_indent_type)(struct GeanyEditor *editor, GeanyIndentType type); + gchar* (*get_word_at_pos) (struct GeanyEditor *editor, gint pos, const gchar *wordchars);
/* Remember to convert any GeanyDocument or ScintillaObject pointers in any * appended functions to GeanyEditor pointers. */
Modified: trunk/src/plugins.c =================================================================== --- trunk/src/plugins.c 2009-02-08 19:51:49 UTC (rev 3566) +++ trunk/src/plugins.c 2009-02-08 19:52:21 UTC (rev 3567) @@ -137,7 +137,8 @@ &document_close, &document_index, &document_save_file_as, - &document_rename_file + &document_rename_file, + &document_get_status_color };
static EditorFuncs editor_funcs = { @@ -146,7 +147,8 @@ &editor_indicator_set_on_range, &editor_indicator_set_on_line, &editor_indicator_clear, - &editor_set_indent_type + &editor_set_indent_type, + &editor_get_word_at_pos };
static ScintillaFuncs scintilla_funcs = { @@ -1331,7 +1333,10 @@ * This is necessary if you register new GTypes in your plugin, e.g. when using own classes * using the GObject system. * - * @param plugin Must be @ref geany_plugin. */ + * @param plugin Must be @ref geany_plugin. + * + * @since 0.16 + */ void plugin_module_make_resident(GeanyPlugin *plugin) { g_return_if_fail(plugin);
Modified: trunk/src/treeviews.c =================================================================== --- trunk/src/treeviews.c 2009-02-08 19:51:49 UTC (rev 3566) +++ trunk/src/treeviews.c 2009-02-08 19:52:21 UTC (rev 3567) @@ -318,7 +318,7 @@ GtkTreeIter *iter = &doc->priv->iter; GtkTreeIter *parent = get_doc_parent(doc); gchar *basename; - GdkColor *color = document_get_status_color(doc); + const GdkColor *color = document_get_status_color(doc);
gtk_tree_store_append(store_openfiles, iter, parent);
@@ -363,7 +363,7 @@ if (utils_str_equal(fname, DOC_FILENAME(doc))) { /* just update color */ - GdkColor *color = document_get_status_color(doc); + const GdkColor *color = document_get_status_color(doc);
gtk_tree_store_set(store_openfiles, iter, DOCUMENTS_COLOR, color, -1); }
Modified: trunk/src/ui_utils.c =================================================================== --- trunk/src/ui_utils.c 2009-02-08 19:51:49 UTC (rev 3566) +++ trunk/src/ui_utils.c 2009-02-08 19:52:21 UTC (rev 3567) @@ -1309,7 +1309,7 @@ * document status. */ void ui_update_tab_status(GeanyDocument *doc) { - GdkColor *color = document_get_status_color(doc); + const GdkColor *color = document_get_status_color(doc);
/* NULL color will reset to default */ gtk_widget_modify_fg(doc->priv->tab_label, GTK_STATE_NORMAL, color);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.