Kaydet (Commit) d6c1d1e8 authored tarafından Enrico Tröger's avatar Enrico Tröger

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.

git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@3567 ea778897-0a13-0410-b9d1-a72fbfd435f5
üst 0e8e7a68
......@@ -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>
......
......@@ -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 \
......
......@@ -2675,9 +2675,19 @@ static void document_redo_add(GeanyDocument *doc, guint type, gpointer data)
}
/* 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};
......
......@@ -223,6 +223,6 @@ void document_undo_add(GeanyDocument *doc, guint type, gpointer data);
void document_update_tab_label(GeanyDocument *doc);
GdkColor *document_get_status_color(GeanyDocument *doc);
const GdkColor *document_get_status_color(GeanyDocument *doc);
#endif
......@@ -1248,6 +1248,35 @@ void editor_find_current_word(GeanyEditor *editor, gint pos, gchar *word, size_t
}
/**
* 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)
......
......@@ -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_snippets_free(void);
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);
......
......@@ -252,6 +252,7 @@ typedef struct DocumentFuncs
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 @@ typedef struct EditorFuncs
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. */
......
......@@ -137,7 +137,8 @@ static DocumentFuncs doc_funcs = {
&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 @@ static EditorFuncs editor_funcs = {
&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 @@ void plugin_add_toolbar_item(GeanyPlugin *plugin, GtkToolItem *item)
* 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);
......
......@@ -318,7 +318,7 @@ void treeviews_openfiles_add(GeanyDocument *doc)
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 @@ void treeviews_openfiles_update(GeanyDocument *doc)
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);
}
......
......@@ -1309,7 +1309,7 @@ void ui_combo_box_prepend_text_once(GtkComboBox *combo, const gchar *text)
* 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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment