Removed completion stuff

This commit is contained in:
Yevgen Muntyan 2008-08-18 06:46:49 -05:00
parent 9e5b9d35c1
commit 50fdb834bf
28 changed files with 2 additions and 13841 deletions

View File

@ -11,17 +11,8 @@ libmooedit_la_LIBADD = \
plugins/libmooeditplugins.la \
libgtksourceview.la
completion_sources = \
moocompletionsimple.c \
moocompletionsimple.h \
mootextcompletion.c \
mootextcompletion.h \
mootextpopup.c \
mootextpopup.h
libmooedit_la_SOURCES = \
$(moocommand_stuff) \
$(completion_sources) \
moocommand-lua.c \
moocommand-lua.h \
mooedit-lua-api.c \

View File

@ -1,703 +0,0 @@
/*
* moocompletionsimple.c
*
* Copyright (C) 2004-2007 by Yevgen Muntyan <muntyan@math.tamu.edu>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation.
*
* See COPYING file that comes with this distribution.
*/
#include "mooedit/moocompletionsimple.h"
#include "mooedit/mootextpopup.h"
#include "marshals.h"
#include <glib/gregex.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include <string.h>
#define MOO_COMPLETION_VAR_MATCH "match"
#define MOO_COMPLETION_VAR_COMPLETION "completion"
enum {
COLUMN_DATA,
COLUMN_GROUP
};
/* same as GCompletionFunc - must not allocate a new string;
must allow two simultaneous calls */
typedef char* (*MooCompletionStringFunc) (gpointer data);
typedef void (*MooCompletionFreeFunc) (gpointer data);
typedef int (*MooCompletionCmpFunc) (gpointer data1,
gpointer data2);
struct _MooCompletionSimplePrivate {
GSList *groups;
GSList *active_groups;
gboolean groups_found;
GList *data;
MooCompletionStringFunc string_func;
MooCompletionFreeFunc free_func;
MooCompletionCmpFunc cmp_func;
};
struct _MooCompletionGroup {
char *name;
GRegex *regex;
guint *parens;
guint n_parens;
GCompletion *cmpl;
GList *data;
char *suffix;
gpointer script;
MooCompletionFreeFunc free_func;
};
static void moo_completion_simple_dispose (GObject *object);
static void moo_completion_simple_populate (MooTextCompletion *cmpl,
GtkTreeModel *model,
GtkTextIter *cursor,
const char *text);
static void moo_completion_simple_complete (MooTextCompletion *cmpl,
GtkTreeModel *model,
GtkTreeIter *iter);
static int list_sort_func (GtkTreeModel *model,
GtkTreeIter *a,
GtkTreeIter *b,
MooCompletionSimple *cmpl);
static char *completion_text_func (GtkTreeModel *model,
GtkTreeIter *iter,
gpointer data);
static MooCompletionSimple *moo_completion_simple_new (MooCompletionStringFunc string_func,
MooCompletionFreeFunc free_func,
MooCompletionCmpFunc cmp_func);
static MooCompletionGroup *moo_completion_group_new (const char *name,
MooCompletionStringFunc string_func,
MooCompletionFreeFunc free_func);
static void moo_completion_group_free (MooCompletionGroup *group);
static gboolean moo_completion_group_find (MooCompletionGroup *group,
const char *line,
int *start_pos,
int *end_pos);
static GList *moo_completion_group_complete (MooCompletionGroup *group,
const char *text,
char **prefix);
static void moo_completion_simple_finish (MooTextCompletion *cmpl);
G_DEFINE_TYPE (MooCompletionSimple, moo_completion_simple, MOO_TYPE_TEXT_COMPLETION)
static void
moo_completion_simple_dispose (GObject *object)
{
MooCompletionSimple *cmpl = MOO_COMPLETION_SIMPLE (object);
if (cmpl->priv)
{
g_slist_foreach (cmpl->priv->groups, (GFunc) moo_completion_group_free, NULL);
g_slist_free (cmpl->priv->groups);
g_slist_free (cmpl->priv->active_groups);
g_free (cmpl->priv);
cmpl->priv = NULL;
}
G_OBJECT_CLASS(moo_completion_simple_parent_class)->dispose (object);
}
static void
moo_completion_simple_class_init (MooCompletionSimpleClass *klass)
{
MooTextCompletionClass *cmpl_clas = MOO_TEXT_COMPLETION_CLASS(klass);
G_OBJECT_CLASS(klass)->dispose = moo_completion_simple_dispose;
cmpl_clas->populate = moo_completion_simple_populate;
cmpl_clas->finish = moo_completion_simple_finish;
cmpl_clas->complete = moo_completion_simple_complete;
}
static void
moo_completion_simple_init (MooCompletionSimple *cmpl)
{
GtkListStore *store;
cmpl->priv = g_new0 (MooCompletionSimplePrivate, 1);
store = gtk_list_store_new (2, G_TYPE_POINTER, G_TYPE_POINTER);
gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (store),
COLUMN_DATA,
(GtkTreeIterCompareFunc) list_sort_func,
cmpl, NULL);
moo_text_completion_set_model (MOO_TEXT_COMPLETION (cmpl),
GTK_TREE_MODEL (store));
moo_text_completion_set_text_func (MOO_TEXT_COMPLETION (cmpl),
completion_text_func, cmpl,
NULL);
g_object_unref (store);
}
static GtkTextBuffer *
get_buffer (MooCompletionSimple *cmpl)
{
return moo_text_completion_get_buffer (MOO_TEXT_COMPLETION (cmpl));
}
static char *
moo_completion_simple_find_groups (MooCompletionSimple *cmpl,
GtkTextIter *cursor,
const char *line)
{
GSList *l;
gboolean found = FALSE;
int start_pos = -1, end_pos = -1;
char *text = NULL;
for (l = cmpl->priv->groups; l != NULL; l = l->next)
{
int start_pos_here, end_pos_here;
MooCompletionGroup *grp = l->data;
if (!moo_completion_group_find (grp, line, &start_pos_here, &end_pos_here))
continue;
if (!found)
{
found = TRUE;
start_pos = start_pos_here;
end_pos = end_pos_here;
}
if (start_pos_here == start_pos && end_pos_here == end_pos)
cmpl->priv->active_groups =
g_slist_prepend (cmpl->priv->active_groups, grp);
}
if (found)
{
GtkTextIter start, end;
cmpl->priv->active_groups = g_slist_reverse (cmpl->priv->active_groups);
start = end = *cursor;
gtk_text_iter_set_line_index (&start, start_pos);
gtk_text_iter_set_line_index (&end, end_pos);
text = gtk_text_iter_get_slice (&start, &end);
moo_text_completion_set_region (MOO_TEXT_COMPLETION (cmpl), &start, &end);
}
return text;
}
static int
list_sort_func (GtkTreeModel *model,
GtkTreeIter *a,
GtkTreeIter *b,
MooCompletionSimple *cmpl)
{
gpointer data1, data2;
g_assert (MOO_IS_COMPLETION_SIMPLE (cmpl));
g_assert (cmpl->priv->cmp_func != NULL);
gtk_tree_model_get (model, a, COLUMN_DATA, &data1, -1);
gtk_tree_model_get (model, b, COLUMN_DATA, &data2, -1);
return cmpl->priv->cmp_func (data1, data2);
}
static void
moo_completion_simple_exec_script (G_GNUC_UNUSED MooCompletionSimple *cmpl,
G_GNUC_UNUSED MooCompletionGroup *group,
G_GNUC_UNUSED GtkTextIter *start,
G_GNUC_UNUSED GtkTextIter *end,
G_GNUC_UNUSED const char *completion)
{
// char *match;
// GtkTextView *doc;
//
// doc = moo_text_completion_get_doc (MOO_TEXT_COMPLETION (cmpl));
// ctx = moo_edit_script_context_new (doc, NULL);
// match = gtk_text_iter_get_slice (start, end);
//
// ms_context_assign_string (ctx, MOO_COMPLETION_VAR_MATCH, match);
// ms_context_assign_string (ctx, MOO_COMPLETION_VAR_COMPLETION, completion);
//
// gtk_text_buffer_delete (get_buffer (cmpl), start, end);
// gtk_text_buffer_place_cursor (get_buffer (cmpl), start);
// result = ms_top_node_eval (group->script, ctx);
//
// if (result)
// ms_value_unref (result);
// else
// g_warning ("%s: %s", G_STRLOC,
// ms_context_get_error_msg (ctx));
//
// g_free (match);
// g_object_unref (ctx);
}
static void
moo_completion_simple_complete (MooTextCompletion *text_cmpl,
GtkTreeModel *model,
GtkTreeIter *iter)
{
char *text, *old_text;
GtkTextIter start, end;
gpointer data = NULL;
MooCompletionGroup *group = NULL;
gboolean set_cursor = FALSE;
MooCompletionSimple *cmpl = MOO_COMPLETION_SIMPLE (text_cmpl);
g_return_if_fail (cmpl->priv->active_groups != NULL);
gtk_tree_model_get (model, iter, COLUMN_DATA, &data, COLUMN_GROUP, &group, -1);
g_assert (group != NULL);
text = cmpl->priv->string_func ? cmpl->priv->string_func (data) : data;
g_return_if_fail (text != NULL);
moo_text_completion_get_region (MOO_TEXT_COMPLETION (cmpl), &start, &end);
old_text = gtk_text_iter_get_slice (&start, &end);
if (group->script)
{
moo_completion_simple_exec_script (cmpl, group, &start, &end, text);
}
else
{
if (strcmp (text, old_text) != 0)
{
_moo_text_completion_replace_text (MOO_TEXT_COMPLETION (cmpl),
&start, &end, text);
set_cursor = TRUE;
}
if (group->suffix)
{
gboolean do_insert = TRUE;
if (!gtk_text_iter_ends_line (&start))
{
char *old_suffix;
end = start;
gtk_text_iter_forward_to_line_end (&end);
old_suffix = gtk_text_iter_get_slice (&start, &end);
if (!strncmp (group->suffix, old_suffix, strlen (group->suffix)))
{
do_insert = FALSE;
gtk_text_iter_forward_chars (&start, g_utf8_strlen (group->suffix, -1));
set_cursor = TRUE;
}
g_free (old_suffix);
}
if (do_insert)
{
_moo_text_completion_replace_text (text_cmpl, &start, &start, group->suffix);
set_cursor = TRUE;
}
}
}
if (set_cursor)
gtk_text_buffer_place_cursor (get_buffer (cmpl), &start);
g_free (old_text);
}
static void
moo_completion_simple_populate (MooTextCompletion *text_cmpl,
GtkTreeModel *model,
GtkTextIter *cursor,
const char *text)
{
GSList *l;
const char *prefix = text;
char *freeme = NULL;
MooCompletionSimple *cmpl = MOO_COMPLETION_SIMPLE (text_cmpl);
if (!cmpl->priv->groups_found)
{
freeme = moo_completion_simple_find_groups (cmpl, cursor, text);
if (!freeme)
return;
cmpl->priv->groups_found = TRUE;
prefix = freeme;
}
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (model),
GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID,
GTK_SORT_ASCENDING);
for (l = cmpl->priv->active_groups; l != NULL; l = l->next)
{
GList *list;
MooCompletionGroup *group;
group = l->data;
list = moo_completion_group_complete (group, prefix, NULL);
while (list)
{
GtkTreeIter iter;
gtk_list_store_append (GTK_LIST_STORE (model), &iter);
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
COLUMN_DATA, list->data,
COLUMN_GROUP, group,
-1);
list = list->next;
}
}
if (cmpl->priv->cmp_func)
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (model),
COLUMN_DATA, GTK_SORT_ASCENDING);
g_free (freeme);
}
static void
moo_completion_simple_finish (MooTextCompletion *text_cmpl)
{
MooCompletionSimple *cmpl = MOO_COMPLETION_SIMPLE (text_cmpl);
g_slist_free (cmpl->priv->active_groups);
cmpl->priv->active_groups = NULL;
cmpl->priv->groups_found = FALSE;
}
static MooCompletionSimple *
moo_completion_simple_new (MooCompletionStringFunc string_func,
MooCompletionFreeFunc free_func,
MooCompletionCmpFunc cmp_func)
{
MooCompletionSimple *cmpl = g_object_new (MOO_TYPE_COMPLETION_SIMPLE, NULL);
cmpl->priv->string_func = string_func;
cmpl->priv->free_func = free_func;
cmpl->priv->cmp_func = cmp_func;
return cmpl;
}
static void
text_cell_data_func (G_GNUC_UNUSED GtkTreeViewColumn *tree_column,
GtkCellRenderer *cell,
GtkTreeModel *tree_model,
GtkTreeIter *iter,
MooCompletionSimple *cmpl)
{
gpointer data = NULL;
char *text;
g_assert (MOO_IS_COMPLETION_SIMPLE (cmpl));
gtk_tree_model_get (tree_model, iter, 0, &data, -1);
text = cmpl->priv->string_func ? cmpl->priv->string_func (data) : data;
g_return_if_fail (text != NULL);
g_object_set (cell, "text", text, NULL);
}
static char *
completion_text_func (GtkTreeModel *model,
GtkTreeIter *iter,
gpointer user_data)
{
MooCompletionSimple *cmpl = user_data;
gpointer data = NULL;
char *text;
gtk_tree_model_get (model, iter, 0, &data, -1);
text = cmpl->priv->string_func ? cmpl->priv->string_func (data) : data;
g_return_val_if_fail (text != NULL, NULL);
return g_strdup (text);
}
MooTextCompletion *
moo_completion_simple_new_text (GList *words)
{
MooCompletionSimple *cmpl;
GtkCellRenderer *cell;
MooTextPopup *popup;
cmpl = moo_completion_simple_new (NULL, g_free, (MooCompletionCmpFunc) strcmp);
if (words)
{
MooCompletionGroup *group = moo_completion_simple_new_group (cmpl, NULL);
moo_completion_group_add_data (group, words);
moo_completion_group_set_pattern (group, "\\w*", NULL, 0);
}
popup = moo_text_completion_get_popup (MOO_TEXT_COMPLETION (cmpl));
cell = gtk_cell_renderer_text_new ();
gtk_cell_layout_clear (GTK_CELL_LAYOUT (popup->column));
gtk_tree_view_column_pack_start (popup->column, cell, TRUE);
gtk_tree_view_column_set_cell_data_func (popup->column, cell,
(GtkTreeCellDataFunc) text_cell_data_func,
g_object_ref (cmpl),
g_object_unref);
return MOO_TEXT_COMPLETION (cmpl);
}
MooCompletionGroup *
moo_completion_simple_new_group (MooCompletionSimple *cmpl,
const char *name)
{
MooCompletionGroup *group;
g_return_val_if_fail (MOO_IS_COMPLETION_SIMPLE (cmpl), NULL);
group = moo_completion_group_new (name,
cmpl->priv->string_func,
cmpl->priv->free_func);
cmpl->priv->groups = g_slist_append (cmpl->priv->groups, group);
return group;
}
/****************************************************************************/
/* MooCompletionGroup
*/
MooCompletionGroup *
moo_completion_group_new (const char *name,
MooCompletionStringFunc string_func,
MooCompletionFreeFunc free_func)
{
MooCompletionGroup *group = g_new0 (MooCompletionGroup, 1);
group->cmpl = g_completion_new (string_func);
group->free_func = free_func;
group->name = g_strdup (name);
return group;
}
void
moo_completion_group_add_data (MooCompletionGroup *group,
GList *data)
{
g_return_if_fail (group != NULL);
if (!data)
return;
g_completion_clear_items (group->cmpl);
group->data = g_list_concat (group->data, data);
g_completion_add_items (group->cmpl, group->data);
}
void
moo_completion_group_remove_data (MooCompletionGroup *group,
GList *data)
{
g_return_if_fail (group != NULL);
if (!data)
return;
g_completion_remove_items (group->cmpl, data);
}
static gboolean
moo_completion_group_find (MooCompletionGroup *group,
const char *line,
int *start_pos_p,
int *end_pos_p)
{
GMatchInfo *match_info;
g_return_val_if_fail (group != NULL, FALSE);
g_return_val_if_fail (line != NULL, FALSE);
g_return_val_if_fail (group->regex != NULL, FALSE);
if (g_regex_match (group->regex, line, 0, &match_info))
{
guint i;
for (i = 0; i < group->n_parens; ++i)
{
int start_pos = -1, end_pos = -1;
g_match_info_fetch_pos (match_info, group->parens[i],
&start_pos, &end_pos);
if (start_pos >= 0 && end_pos >= 0)
{
if (start_pos_p)
*start_pos_p = start_pos;
if (end_pos_p)
*end_pos_p = end_pos;
g_match_info_free (match_info);
return TRUE;
}
}
}
g_match_info_free (match_info);
return FALSE;
}
static GList *
moo_completion_group_complete (MooCompletionGroup *group,
const char *text,
char **prefix)
{
char *dummy = NULL;
GList *list;
if (!prefix)
prefix = &dummy;
/* g_completion_complete_utf8 wants prefix != NULL */
list = g_completion_complete_utf8 (group->cmpl, text, prefix);
g_free (dummy);
return list;
}
void
moo_completion_group_set_pattern (MooCompletionGroup *group,
const char *pattern,
const guint *parens,
guint n_parens)
{
GRegex *regex;
GError *error = NULL;
char *real_pattern;
g_return_if_fail (group != NULL);
g_return_if_fail (pattern && pattern[0]);
g_return_if_fail (!parens || n_parens);
real_pattern = g_strdup_printf ("%s$", pattern);
regex = g_regex_new (real_pattern, G_REGEX_OPTIMIZE, 0, &error);
if (!regex)
{
g_warning ("%s: %s", G_STRLOC, error->message);
g_error_free (error);
goto err;
}
if (group->regex)
g_regex_unref (group->regex);
group->regex = regex;
g_free (group->parens);
if (!parens)
{
group->parens = g_new0 (guint, 1);
group->n_parens = 1;
}
else
{
group->parens = g_memdup (parens, n_parens * sizeof (guint));
group->n_parens = n_parens;
}
g_free (real_pattern);
return;
err:
if (error)
g_error_free (error);
if (regex)
g_regex_unref (regex);
g_free (real_pattern);
}
void
moo_completion_group_set_suffix (MooCompletionGroup *group,
const char *suffix)
{
g_return_if_fail (group != NULL);
if (group->suffix != suffix)
{
g_free (group->suffix);
group->suffix = (suffix && suffix[0]) ? g_strdup (suffix) : NULL;
}
}
void
moo_completion_group_set_script (G_GNUC_UNUSED MooCompletionGroup *group,
G_GNUC_UNUSED const char *script)
{
// g_return_if_fail (group != NULL);
//
// if (group->script)
// {
// ms_node_unref (group->script);
// group->script = NULL;
// }
//
// if (script)
// group->script = ms_script_parse (script);
}
static void
moo_completion_group_free (MooCompletionGroup *group)
{
g_return_if_fail (group != NULL);
if (group->regex)
g_regex_unref (group->regex);
g_free (group->parens);
g_completion_free (group->cmpl);
g_free (group->suffix);
g_free (group->name);
// if (group->script)
// ms_node_unref (group->script);
if (group->free_func)
g_list_foreach (group->data, (GFunc) group->free_func, NULL);
g_list_free (group->data);
g_free (group);
}

View File

@ -1,73 +0,0 @@
/*
* moocompletionsimple.h
*
* Copyright (C) 2004-2007 by Yevgen Muntyan <muntyan@math.tamu.edu>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation.
*
* See COPYING file that comes with this distribution.
*/
#ifndef MOO_COMPLETION_SIMPLE_H
#define MOO_COMPLETION_SIMPLE_H
#include "mooedit/mootextcompletion.h"
#include <gtk/gtkliststore.h>
G_BEGIN_DECLS
#define MOO_TYPE_COMPLETION_SIMPLE (moo_completion_simple_get_type ())
#define MOO_COMPLETION_SIMPLE(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), MOO_TYPE_COMPLETION_SIMPLE, MooCompletionSimple))
#define MOO_COMPLETION_SIMPLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MOO_TYPE_COMPLETION_SIMPLE, MooCompletionSimpleClass))
#define MOO_IS_COMPLETION_SIMPLE(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), MOO_TYPE_COMPLETION_SIMPLE))
#define MOO_IS_COMPLETION_SIMPLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MOO_TYPE_COMPLETION_SIMPLE))
#define MOO_COMPLETION_SIMPLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MOO_TYPE_COMPLETION_SIMPLE, MooCompletionSimpleClass))
typedef struct _MooCompletionSimple MooCompletionSimple;
typedef struct _MooCompletionSimplePrivate MooCompletionSimplePrivate;
typedef struct _MooCompletionSimpleClass MooCompletionSimpleClass;
typedef struct _MooCompletionGroup MooCompletionGroup;
struct _MooCompletionSimple
{
MooTextCompletion base;
MooCompletionSimplePrivate *priv;
};
struct _MooCompletionSimpleClass
{
MooTextCompletionClass base_class;
};
GType moo_completion_simple_get_type (void) G_GNUC_CONST;
/* steals data */
void moo_completion_group_add_data (MooCompletionGroup *group,
GList *data);
void moo_completion_group_remove_data (MooCompletionGroup *group,
GList *data);
void moo_completion_group_set_pattern (MooCompletionGroup *group,
const char *pattern,
const guint *parens,
guint n_parens);
void moo_completion_group_set_suffix (MooCompletionGroup *group,
const char *suffix);
void moo_completion_group_set_script (MooCompletionGroup *group,
const char *script);
/* steals words */
MooTextCompletion *moo_completion_simple_new_text (GList *words);
MooCompletionGroup *moo_completion_simple_new_group (MooCompletionSimple *cmpl,
const char *name);
G_END_DECLS
#endif /* MOO_COMPLETION_SIMPLE_H */

View File

@ -916,10 +916,6 @@ moo_plugin_init_builtin (void)
_moo_ctags_plugin_init ();
#endif
#endif
#if 0
_moo_completion_plugin_init ();
_moo_active_strings_plugin_init ();
#endif
}

View File

@ -1,753 +0,0 @@
/*
* mootextcompletion.c
*
* Copyright (C) 2004-2007 by Yevgen Muntyan <muntyan@math.tamu.edu>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation.
*
* See COPYING file that comes with this distribution.
*/
#include "mooedit/mootextcompletion.h"
#include "mooutils/mooaccel.h"
#include "marshals.h"
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include <string.h>
struct _MooTextCompletionPrivate {
GtkTextView *doc;
GtkTextBuffer *buffer;
GtkTextMark *start;
GtkTextMark *end;
GtkTreeModel *model;
MooTextCompletionTextFunc text_func;
gpointer text_func_data;
GDestroyNotify text_func_data_notify;
MooTextPopup *popup;
guint shown : 1;
guint working : 1;
};
static void moo_text_completion_dispose (GObject *object);
static void moo_text_completion_try_complete_real (MooTextCompletion *cmpl,
gboolean automatic);
static void moo_text_completion_complete_real (MooTextCompletion *cmpl,
GtkTreeModel *model,
GtkTreeIter *iter);
static void moo_text_completion_populate (MooTextCompletion *cmpl,
GtkTreeModel *model,
GtkTextIter *cursor,
const char *text);
static void moo_text_completion_complete (MooTextCompletion *cmpl,
GtkTreeIter *iter);
static void moo_text_completion_update (MooTextCompletion *cmpl);
static void moo_text_completion_update_real (MooTextCompletion *cmpl);
static void moo_text_completion_replace_text_real (MooTextCompletion *cmpl,
GtkTextIter *start,
GtkTextIter *end,
const char *text);
static gboolean moo_text_completion_empty (MooTextCompletion *cmpl);
static gboolean moo_text_completion_unique (MooTextCompletion *cmpl,
GtkTreeIter *iter);
static void moo_text_completion_finish (MooTextCompletion *cmpl);
static char *find_common_prefix (MooTextCompletion *cmpl,
const char *text);
static char *default_text_func (GtkTreeModel *model,
GtkTreeIter *iter,
gpointer data);
static void cell_data_func (GtkTreeViewColumn *column,
GtkCellRenderer *cell,
GtkTreeModel *model,
GtkTreeIter *iter,
MooTextCompletion *cmpl);
static void on_popup_activate (MooTextCompletion *cmpl,
GtkTreeModel *model,
GtkTreeIter *iter);
static gboolean popup_key_press (MooTextCompletion *cmpl,
GdkEventKey *event);
enum {
FINISH,
N_SIGNALS
};
static guint signals[N_SIGNALS];
G_DEFINE_TYPE (MooTextCompletion, moo_text_completion, G_TYPE_OBJECT)
static void
moo_text_completion_class_init (MooTextCompletionClass *klass)
{
G_OBJECT_CLASS(klass)->dispose = moo_text_completion_dispose;
klass->try_complete = moo_text_completion_try_complete_real;
klass->update = moo_text_completion_update_real;
klass->complete = moo_text_completion_complete_real;
klass->replace_text = moo_text_completion_replace_text_real;
signals[FINISH] = g_signal_new ("finish",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (MooTextCompletionClass, finish),
NULL, NULL,
_moo_marshal_VOID__VOID,
G_TYPE_NONE, 0);
}
void
moo_text_completion_init (MooTextCompletion *cmpl)
{
GtkCellRenderer *cell;
cmpl->priv = g_new0 (MooTextCompletionPrivate, 1);
cmpl->priv->doc = NULL;
cmpl->priv->buffer = NULL;
cmpl->priv->start = NULL;
cmpl->priv->end = NULL;
cmpl->priv->model = GTK_TREE_MODEL (gtk_list_store_new (1, G_TYPE_STRING));
cmpl->priv->text_func = default_text_func;
cmpl->priv->text_func_data = GINT_TO_POINTER (0);
cmpl->priv->text_func_data_notify = NULL;
cmpl->priv->popup = g_object_new (MOO_TYPE_TEXT_POPUP, NULL);
cell = gtk_cell_renderer_text_new ();
gtk_tree_view_column_pack_start (cmpl->priv->popup->column, cell, TRUE);
gtk_tree_view_column_set_cell_data_func (cmpl->priv->popup->column, cell,
(GtkTreeCellDataFunc) cell_data_func,
cmpl, NULL);
moo_text_popup_set_model (cmpl->priv->popup, cmpl->priv->model);
g_signal_connect_swapped (cmpl->priv->popup, "activate",
G_CALLBACK (on_popup_activate), cmpl);
g_signal_connect_swapped (cmpl->priv->popup, "text-changed",
G_CALLBACK (moo_text_completion_update), cmpl);
g_signal_connect_swapped (cmpl->priv->popup, "hide",
G_CALLBACK (moo_text_completion_hide), cmpl);
g_signal_connect_swapped (cmpl->priv->popup, "key-press-event",
G_CALLBACK (popup_key_press), cmpl);
}
static void
moo_text_completion_dispose (GObject *object)
{
MooTextCompletion *cmpl = MOO_TEXT_COMPLETION (object);
if (cmpl->priv)
{
moo_text_completion_set_doc (cmpl, NULL);
moo_text_completion_set_text_func (cmpl, NULL, NULL, NULL);
g_object_unref (cmpl->priv->model);
moo_text_popup_set_model (cmpl->priv->popup, NULL);
g_signal_handlers_disconnect_by_func (cmpl->priv->popup,
(gpointer) on_popup_activate,
cmpl);
g_signal_handlers_disconnect_by_func (cmpl->priv->popup,
(gpointer) moo_text_completion_update,
cmpl);
g_signal_handlers_disconnect_by_func (cmpl->priv->popup,
(gpointer) moo_text_completion_hide,
cmpl);
g_object_unref (cmpl->priv->popup);
g_free (cmpl->priv);
cmpl->priv = NULL;
}
G_OBJECT_CLASS (moo_text_completion_parent_class)->dispose (object);
}
void
moo_text_completion_try_complete (MooTextCompletion *cmpl,
gboolean automatic)
{
g_return_if_fail (MOO_IS_TEXT_COMPLETION (cmpl));
g_return_if_fail (MOO_TEXT_COMPLETION_GET_CLASS (cmpl)->try_complete != NULL);
g_return_if_fail (moo_text_completion_get_doc (cmpl) != NULL);
MOO_TEXT_COMPLETION_GET_CLASS (cmpl)->try_complete (cmpl, automatic);
}
static void
moo_text_completion_try_complete_real (MooTextCompletion *cmpl,
gboolean automatic)
{
GtkTextIter start, end;
GtkTreeIter iter;
char *line = NULL;
char *text = NULL;
char *prefix = NULL;
g_return_if_fail (cmpl->priv->buffer != NULL);
g_return_if_fail (!cmpl->priv->shown);
gtk_text_buffer_get_iter_at_mark (cmpl->priv->buffer, &end,
gtk_text_buffer_get_insert (cmpl->priv->buffer));
start = end;
if (!gtk_text_iter_starts_line (&start))
gtk_text_iter_set_line_offset (&start, 0);
line = gtk_text_iter_get_slice (&start, &end);
cmpl->priv->working = TRUE;
moo_text_completion_set_region (cmpl, &end, &end);
moo_text_completion_populate (cmpl, cmpl->priv->model, &end, line);
if (moo_text_completion_empty (cmpl))
goto finish;
if (moo_text_completion_unique (cmpl, &iter))
{
if (!automatic)
{
moo_text_completion_complete (cmpl, &iter);
goto finish;
}
prefix = moo_text_completion_get_text (cmpl, cmpl->priv->model, &iter);
if (prefix)
{
moo_text_completion_get_region (cmpl, &start, NULL);
end = start;
gtk_text_iter_forward_chars (&end, g_utf8_strlen (prefix, -1));
text = gtk_text_iter_get_slice (&start, &end);
if (!strcmp (prefix, text))
goto finish;
}
}
else if (!automatic)
{
moo_text_completion_get_region (cmpl, &start, &end);
text = gtk_text_iter_get_slice (&start, &end);
prefix = find_common_prefix (cmpl, text);
if (prefix && strcmp (text, prefix) != 0)
_moo_text_completion_replace_text (cmpl, &start, &end, prefix);
}
moo_text_completion_show (cmpl);
g_free (text);
g_free (prefix);
g_free (line);
return;
finish:
moo_text_completion_finish (cmpl);
g_free (text);
g_free (prefix);
g_free (line);
}
void
_moo_text_completion_replace_text (MooTextCompletion *cmpl,
GtkTextIter *start,
GtkTextIter *end,
const char *text)
{
g_return_if_fail (MOO_IS_TEXT_COMPLETION (cmpl));
g_return_if_fail (start != NULL && end != NULL);
gtk_text_buffer_begin_user_action (cmpl->priv->buffer);
MOO_TEXT_COMPLETION_GET_CLASS (cmpl)->replace_text (cmpl, start, end, text);
gtk_text_buffer_end_user_action (cmpl->priv->buffer);
}
static void
moo_text_completion_replace_text_real (MooTextCompletion *cmpl,
GtkTextIter *start,
GtkTextIter *end,
const char *text)
{
if (!gtk_text_iter_equal (start, end))
gtk_text_buffer_delete (cmpl->priv->buffer, start, end);
if (text && text[0])
gtk_text_buffer_insert (cmpl->priv->buffer, start, text, -1);
}
static void
moo_text_completion_complete (MooTextCompletion *cmpl,
GtkTreeIter *iter)
{
g_return_if_fail (MOO_TEXT_COMPLETION_GET_CLASS(cmpl)->complete != NULL);
gtk_text_buffer_begin_user_action (cmpl->priv->buffer);
MOO_TEXT_COMPLETION_GET_CLASS(cmpl)->complete (cmpl, cmpl->priv->model, iter);
gtk_text_buffer_end_user_action (cmpl->priv->buffer);
moo_text_completion_finish (cmpl);
}
static void
moo_text_completion_complete_real (MooTextCompletion *cmpl,
GtkTreeModel *model,
GtkTreeIter *iter)
{
char *text, *old_text;
GtkTextIter start, end;
gboolean set_cursor = FALSE;
text = moo_text_completion_get_text (cmpl, model, iter);
g_return_if_fail (text != NULL);
moo_text_completion_get_region (cmpl, &start, &end);
old_text = gtk_text_buffer_get_slice (cmpl->priv->buffer,
&start, &end, TRUE);
if (strcmp (text, old_text) != 0)
{
_moo_text_completion_replace_text (cmpl, &start, &end, text);
set_cursor = TRUE;
}
if (set_cursor)
gtk_text_buffer_place_cursor (cmpl->priv->buffer, &start);
g_free (old_text);
g_free (text);
}
char *
moo_text_completion_get_text (MooTextCompletion *cmpl,
GtkTreeModel *model,
GtkTreeIter *iter)
{
g_return_val_if_fail (MOO_IS_TEXT_COMPLETION (cmpl), NULL);
g_return_val_if_fail (model == cmpl->priv->model, NULL);
g_return_val_if_fail (iter != NULL, NULL);
g_return_val_if_fail (cmpl->priv->text_func != NULL, NULL);
return cmpl->priv->text_func (model, iter, cmpl->priv->text_func_data);
}
static void
moo_text_completion_populate (MooTextCompletion *cmpl,
GtkTreeModel *model,
GtkTextIter *cursor,
const char *text)
{
g_return_if_fail (MOO_TEXT_COMPLETION_GET_CLASS (cmpl)->populate != NULL);
if (GTK_IS_LIST_STORE (cmpl->priv->model))
gtk_list_store_clear (GTK_LIST_STORE (cmpl->priv->model));
MOO_TEXT_COMPLETION_GET_CLASS (cmpl)->populate (cmpl, model, cursor, text);
}
static void
moo_text_completion_update (MooTextCompletion *cmpl)
{
g_return_if_fail (MOO_TEXT_COMPLETION_GET_CLASS(cmpl)->update != NULL);
MOO_TEXT_COMPLETION_GET_CLASS(cmpl)->update (cmpl);
}
static void
moo_text_completion_update_real (MooTextCompletion *cmpl)
{
GtkTextIter start, end;
char *text;
g_return_if_fail (cmpl->priv->shown);
moo_text_completion_get_region (cmpl, &start, &end);
text = gtk_text_iter_get_slice (&start, &end);
moo_text_completion_populate (cmpl, cmpl->priv->model, &end, text);
/* XXX preserve selected row */
if (!moo_text_completion_empty (cmpl))
moo_text_popup_update (cmpl->priv->popup);
else
moo_text_completion_hide (cmpl);
g_free (text);
}
static gboolean
moo_text_completion_empty (MooTextCompletion *cmpl)
{
return !gtk_tree_model_iter_n_children (cmpl->priv->model, NULL);
}
static gboolean
moo_text_completion_unique (MooTextCompletion *cmpl,
GtkTreeIter *iter)
{
return gtk_tree_model_iter_n_children (cmpl->priv->model, NULL) == 1 &&
gtk_tree_model_get_iter_first (cmpl->priv->model, iter);
}
void
moo_text_completion_show (MooTextCompletion *cmpl)
{
GtkTextIter iter;
g_return_if_fail (MOO_IS_TEXT_COMPLETION (cmpl));
cmpl->priv->shown = TRUE;
moo_text_completion_get_region (cmpl, &iter, NULL);
moo_text_popup_show (cmpl->priv->popup, &iter);
}
static void
moo_text_completion_finish (MooTextCompletion *cmpl)
{
gboolean emit = FALSE;
if (cmpl->priv->working)
{
cmpl->priv->working = FALSE;
emit = TRUE;
}
if (cmpl->priv->shown)
moo_text_completion_hide (cmpl);
if (emit)
g_signal_emit (cmpl, signals[FINISH], 0);
}
void
moo_text_completion_hide (MooTextCompletion *cmpl)
{
g_return_if_fail (MOO_IS_TEXT_COMPLETION (cmpl));
if (cmpl->priv->shown)
{
cmpl->priv->shown = FALSE;
moo_text_popup_hide (cmpl->priv->popup);
if (GTK_IS_LIST_STORE (cmpl->priv->model))
gtk_list_store_clear (GTK_LIST_STORE (cmpl->priv->model));
}
if (cmpl->priv->working)
moo_text_completion_finish (cmpl);
}
static void
on_popup_activate (MooTextCompletion *cmpl,
G_GNUC_UNUSED GtkTreeModel *model,
GtkTreeIter *iter)
{
moo_text_completion_complete (cmpl, iter);
}
static gboolean
popup_key_press (MooTextCompletion *cmpl,
GdkEventKey *event)
{
GtkTreeIter iter;
if (moo_accel_check_event (GTK_WIDGET (cmpl->priv->doc), event, GDK_Tab, 0) &&
moo_text_completion_unique (cmpl, &iter))
{
moo_text_completion_complete (cmpl, &iter);
return TRUE;
}
return FALSE;
}
static char *
find_common_prefix (MooTextCompletion *cmpl,
const char *text)
{
GtkTreeIter iter;
guint text_len;
char *prefix = NULL;
guint prefix_len = 0;
g_return_val_if_fail (text != NULL, NULL);
if (!text[0])
return NULL;
text_len = strlen (text);
if (!gtk_tree_model_get_iter_first (cmpl->priv->model, &iter))
return NULL;
do
{
char *entry;
entry = moo_text_completion_get_text (cmpl, cmpl->priv->model, &iter);
if (!entry)
continue;
if (!prefix)
{
prefix = g_strdup (entry);
prefix_len = g_utf8_strlen (entry, -1);
}
else
{
guint i;
char *p, *e;
for (p = prefix, e = entry, i = 0; *e && i < prefix_len; ++i)
{
if (g_utf8_get_char (p) != g_utf8_get_char (e))
{
prefix_len = i;
break;
}
p = g_utf8_next_char (p);
e = g_utf8_next_char (e);
}
}
g_free (entry);
}
while ((!prefix || prefix_len) &&
gtk_tree_model_iter_next (cmpl->priv->model, &iter));
if (prefix && !prefix_len)
{
g_free (prefix);
prefix = NULL;
}
if (prefix)
* g_utf8_offset_to_pointer (prefix, prefix_len) = 0;
return prefix;
}
static char *
default_text_func (GtkTreeModel *model,
GtkTreeIter *iter,
gpointer data)
{
char *text = NULL;
int column = GPOINTER_TO_INT (data);
g_return_val_if_fail (column >= 0, NULL);
g_return_val_if_fail (gtk_tree_model_get_column_type (model, column) == G_TYPE_STRING, NULL);
gtk_tree_model_get (model, iter, column, &text, -1);
return text;
}
static void
cell_data_func (G_GNUC_UNUSED GtkTreeViewColumn *column,
GtkCellRenderer *cell,
GtkTreeModel *model,
GtkTreeIter *iter,
MooTextCompletion *cmpl)
{
char *text = moo_text_completion_get_text (cmpl, model, iter);
g_object_set (cell, "text", text, NULL);
g_free (text);
}
void
moo_text_completion_set_doc (MooTextCompletion *cmpl,
GtkTextView *doc)
{
g_return_if_fail (MOO_IS_TEXT_COMPLETION (cmpl));
g_return_if_fail (!doc || GTK_IS_TEXT_VIEW (doc));
if (cmpl->priv->doc == doc)
return;
moo_text_completion_hide (cmpl);
if (cmpl->priv->doc)
{
if (cmpl->priv->start)
gtk_text_buffer_delete_mark (cmpl->priv->buffer, cmpl->priv->start);
if (cmpl->priv->end)
gtk_text_buffer_delete_mark (cmpl->priv->buffer, cmpl->priv->end);
g_object_unref (cmpl->priv->buffer);
g_object_unref (cmpl->priv->doc);
cmpl->priv->start = cmpl->priv->end = NULL;
cmpl->priv->buffer = NULL;
cmpl->priv->doc = NULL;
}
if (doc)
{
cmpl->priv->doc = g_object_ref (doc);
cmpl->priv->buffer = g_object_ref (gtk_text_view_get_buffer (doc));
}
moo_text_popup_set_doc (cmpl->priv->popup, doc);
}
GtkTextView *
moo_text_completion_get_doc (MooTextCompletion *cmpl)
{
g_return_val_if_fail (MOO_IS_TEXT_COMPLETION (cmpl), NULL);
return cmpl->priv->doc;
}
GtkTextBuffer *
moo_text_completion_get_buffer (MooTextCompletion *cmpl)
{
g_return_val_if_fail (MOO_IS_TEXT_COMPLETION (cmpl), NULL);
return cmpl->priv->buffer;
}
void
moo_text_completion_set_region (MooTextCompletion *cmpl,
const GtkTextIter *start,
const GtkTextIter *end)
{
g_return_if_fail (MOO_IS_TEXT_COMPLETION (cmpl));
g_return_if_fail (start && end);
g_return_if_fail (cmpl->priv->buffer != NULL);
if (!cmpl->priv->start)
{
cmpl->priv->start = gtk_text_buffer_create_mark (cmpl->priv->buffer, NULL, start, TRUE);
cmpl->priv->end = gtk_text_buffer_create_mark (cmpl->priv->buffer, NULL, end, FALSE);
}
else
{
gtk_text_buffer_move_mark (cmpl->priv->buffer, cmpl->priv->start, start);
gtk_text_buffer_move_mark (cmpl->priv->buffer, cmpl->priv->end, end);
}
moo_text_popup_set_position (cmpl->priv->popup, start);
}
gboolean
moo_text_completion_get_region (MooTextCompletion *cmpl,
GtkTextIter *start,
GtkTextIter *end)
{
g_return_val_if_fail (MOO_IS_TEXT_COMPLETION (cmpl), FALSE);
if (!cmpl->priv->start)
return FALSE;
if (start)
gtk_text_buffer_get_iter_at_mark (cmpl->priv->buffer, start,
cmpl->priv->start);
if (end)
gtk_text_buffer_get_iter_at_mark (cmpl->priv->buffer, end,
cmpl->priv->end);
return TRUE;
}
void
moo_text_completion_set_model (MooTextCompletion *cmpl,
GtkTreeModel *model)
{
g_return_if_fail (MOO_IS_TEXT_COMPLETION (cmpl));
g_return_if_fail (!model || GTK_IS_TREE_MODEL (model));
if (model == cmpl->priv->model)
return;
if (cmpl->priv->model)
{
g_object_unref (cmpl->priv->model);
cmpl->priv->model = NULL;
}
if (model)
cmpl->priv->model = g_object_ref (model);
moo_text_popup_set_model (cmpl->priv->popup, model);
}
GtkTreeModel *
moo_text_completion_get_model (MooTextCompletion *cmpl)
{
g_return_val_if_fail (MOO_IS_TEXT_COMPLETION (cmpl), NULL);
return cmpl->priv->model;
}
void
moo_text_completion_set_text_column (MooTextCompletion *cmpl,
int column)
{
g_return_if_fail (MOO_IS_TEXT_COMPLETION (cmpl));
g_return_if_fail (column >= 0);
moo_text_completion_set_text_func (cmpl, default_text_func,
GINT_TO_POINTER (column), NULL);
}
void
moo_text_completion_set_text_func (MooTextCompletion *cmpl,
MooTextCompletionTextFunc func,
gpointer data,
GDestroyNotify notify)
{
GDestroyNotify old_notify;
gpointer old_data;
g_return_if_fail (MOO_IS_TEXT_COMPLETION (cmpl));
old_notify = cmpl->priv->text_func_data_notify;
old_data = cmpl->priv->text_func_data;
cmpl->priv->text_func = NULL;
cmpl->priv->text_func_data = NULL;
cmpl->priv->text_func_data_notify = NULL;
if (func)
{
cmpl->priv->text_func = func;
cmpl->priv->text_func_data = data;
cmpl->priv->text_func_data_notify = notify;
}
if (old_notify)
old_notify (old_data);
}
MooTextPopup *
moo_text_completion_get_popup (MooTextCompletion *cmpl)
{
g_return_val_if_fail (MOO_IS_TEXT_COMPLETION (cmpl), NULL);
return cmpl->priv->popup;
}

View File

@ -1,111 +0,0 @@
/*
* mootextcompletion.h
*
* Copyright (C) 2004-2007 by Yevgen Muntyan <muntyan@math.tamu.edu>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation.
*
* See COPYING file that comes with this distribution.
*/
#ifndef MOO_TEXT_COMPLETION_H
#define MOO_TEXT_COMPLETION_H
#include "mooedit/mootextpopup.h"
#include <gtk/gtkliststore.h>
G_BEGIN_DECLS
#define MOO_TYPE_TEXT_COMPLETION (moo_text_completion_get_type ())
#define MOO_TEXT_COMPLETION(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), MOO_TYPE_TEXT_COMPLETION, MooTextCompletion))
#define MOO_TEXT_COMPLETION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MOO_TYPE_TEXT_COMPLETION, MooTextCompletionClass))
#define MOO_IS_TEXT_COMPLETION(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), MOO_TYPE_TEXT_COMPLETION))
#define MOO_IS_TEXT_COMPLETION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MOO_TYPE_TEXT_COMPLETION))
#define MOO_TEXT_COMPLETION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MOO_TYPE_TEXT_COMPLETION, MooTextCompletionClass))
typedef struct _MooTextCompletion MooTextCompletion;
typedef struct _MooTextCompletionPrivate MooTextCompletionPrivate;
typedef struct _MooTextCompletionClass MooTextCompletionClass;
struct _MooTextCompletion
{
GObject parent;
MooTextCompletionPrivate *priv;
};
struct _MooTextCompletionClass
{
GObjectClass parent_class;
void (*try_complete) (MooTextCompletion *cmpl,
gboolean automatic);
void (*finish) (MooTextCompletion *cmpl);
void (*update) (MooTextCompletion *cmpl);
void (*complete) (MooTextCompletion *cmpl,
GtkTreeModel *model,
GtkTreeIter *iter);
void (*populate) (MooTextCompletion *cmpl,
GtkTreeModel *model,
GtkTextIter *cursor,
const char *text);
void (*replace_text) (MooTextCompletion *cmpl,
GtkTextIter *start,
GtkTextIter *end,
const char *text);
};
typedef char *(*MooTextCompletionTextFunc) (GtkTreeModel *model,
GtkTreeIter *iter,
gpointer data);
GType moo_text_completion_get_type (void) G_GNUC_CONST;
void moo_text_completion_try_complete (MooTextCompletion *cmpl,
gboolean automatic);
void moo_text_completion_hide (MooTextCompletion *cmpl);
void moo_text_completion_show (MooTextCompletion *cmpl);
void moo_text_completion_set_doc (MooTextCompletion *cmpl,
GtkTextView *doc);
GtkTextView *moo_text_completion_get_doc (MooTextCompletion *cmpl);
GtkTextBuffer *moo_text_completion_get_buffer (MooTextCompletion *cmpl);
void moo_text_completion_set_region (MooTextCompletion *cmpl,
const GtkTextIter *start,
const GtkTextIter *end);
gboolean moo_text_completion_get_region (MooTextCompletion *cmpl,
GtkTextIter *start,
GtkTextIter *end);
void moo_text_completion_set_model (MooTextCompletion *cmpl,
GtkTreeModel *model);
GtkTreeModel *moo_text_completion_get_model (MooTextCompletion *cmpl);
void moo_text_completion_set_text_column (MooTextCompletion *cmpl,
int column);
void moo_text_completion_set_text_func (MooTextCompletion *cmpl,
MooTextCompletionTextFunc func,
gpointer data,
GDestroyNotify notify);
char *moo_text_completion_get_text (MooTextCompletion *cmpl,
GtkTreeModel *model,
GtkTreeIter *iter);
MooTextPopup *moo_text_completion_get_popup (MooTextCompletion *cmpl);
void _moo_text_completion_replace_text (MooTextCompletion *cmpl,
GtkTextIter *start,
GtkTextIter *end,
const char *text);
G_END_DECLS
#endif /* MOO_TEXT_COMPLETION_H */

File diff suppressed because it is too large Load Diff

View File

@ -1,88 +0,0 @@
/*
* mootextpopup.h
*
* Copyright (C) 2004-2007 by Yevgen Muntyan <muntyan@math.tamu.edu>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation.
*
* See COPYING file that comes with this distribution.
*/
#ifndef MOO_TEXT_POPUP_H
#define MOO_TEXT_POPUP_H
#include <gtk/gtktextview.h>
#include <gtk/gtktreeviewcolumn.h>
G_BEGIN_DECLS
#define MOO_TYPE_TEXT_POPUP (moo_text_popup_get_type ())
#define MOO_TEXT_POPUP(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), MOO_TYPE_TEXT_POPUP, MooTextPopup))
#define MOO_TEXT_POPUP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MOO_TYPE_TEXT_POPUP, MooTextPopupClass))
#define MOO_IS_TEXT_POPUP(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), MOO_TYPE_TEXT_POPUP))
#define MOO_IS_TEXT_POPUP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MOO_TYPE_TEXT_POPUP))
#define MOO_TEXT_POPUP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MOO_TYPE_TEXT_POPUP, MooTextPopupClass))
typedef struct _MooTextPopup MooTextPopup;
typedef struct _MooTextPopupPrivate MooTextPopupPrivate;
typedef struct _MooTextPopupClass MooTextPopupClass;
struct _MooTextPopup
{
GObject parent;
GtkTreeViewColumn *column;
MooTextPopupPrivate *priv;
};
struct _MooTextPopupClass
{
GObjectClass parent_class;
void (*show) (MooTextPopup *popup);
void (*hide) (MooTextPopup *popup);
void (*activate) (MooTextPopup *popup,
GtkTreeModel *model,
GtkTreeIter *iter);
void (*text_changed) (MooTextPopup *popup);
gboolean (*key_press_event) (MooTextPopup *popup,
GdkEventKey *event);
};
GType moo_text_popup_get_type (void) G_GNUC_CONST;
MooTextPopup *moo_text_popup_new (GtkTextView *doc);
void moo_text_popup_set_doc (MooTextPopup *popup,
GtkTextView *doc);
GtkTextView *moo_text_popup_get_doc (MooTextPopup *popup);
void moo_text_popup_set_model (MooTextPopup *popup,
GtkTreeModel *model);
GtkTreeModel *moo_text_popup_get_model (MooTextPopup *popup);
gboolean moo_text_popup_show (MooTextPopup *popup,
const GtkTextIter *where);
void moo_text_popup_update (MooTextPopup *popup);
void moo_text_popup_activate (MooTextPopup *popup);
void moo_text_popup_hide (MooTextPopup *popup);
gboolean moo_text_popup_get_position (MooTextPopup *popup,
GtkTextIter *iter);
void moo_text_popup_set_position (MooTextPopup *popup,
const GtkTextIter *iter);
gboolean moo_text_popup_get_selected (MooTextPopup *popup,
GtkTreeIter *iter);
void moo_text_popup_select (MooTextPopup *popup,
GtkTreeIter *iter);
G_END_DECLS
#endif /* MOO_TEXT_POPUP_H */

View File

@ -10,6 +10,7 @@ AM_CFLAGS = \
-I.. \
$(MOO_CFLAGS)
###########################################################################
# ctags
#
@ -22,6 +23,7 @@ libctags_la_SOURCES = \
ctags/ctags-view.c \
ctags/ctags-view.h
###########################################################################
# fileselector
#

View File

@ -1,31 +0,0 @@
astringsdir = $(MOO_DATA_DIR)
astrings_DATA = \
as.cfg
EXTRA_DIST = \
as-plugin.glade \
$(astrings_DATA)
astrings_sources = \
as-plugin.c \
as-plugin.h \
as-plugin-prefs.c \
as-plugin-script.c \
as-plugin-script.h \
as-plugin-glade.h
BUILT_SOURCES = \
as-plugin-glade.h
as-plugin-glade.h: as-plugin.glade $(XML2H)
$(SHELL) $(XML2H) AS_PLUGIN_GLADE_UI $(srcdir)/as-plugin.glade > $@.tmp && \
mv $@.tmp $@
noinst_LTLIBRARIES = libastrings.la
libastrings_la_SOURCES = $(astrings_sources)
AM_CFLAGS = \
-I../../.. \
-I$(top_builddir) \
$(MOO_CFLAGS) \
$(MOO_DEBUG_CFLAGS)

View File

@ -1,209 +0,0 @@
/*
* as-plugin-prefs.c
*
* Copyright (C) 2004-2007 by Yevgen Muntyan <muntyan@math.tamu.edu>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation.
*
* See COPYING file that comes with this distribution.
*/
#include "as-plugin.h"
#include "mooedit/plugins/activestrings/as-plugin-glade.h"
#include "mooutils/mooprefsdialogpage.h"
#include "mooutils/mooutils-misc.h"
#include "mooutils/mooutils-fs.h"
#include "mooutils/mooutils-treeview.h"
#include "mooutils/mooi18n.h"
#include <string.h>
static void prefs_page_apply (MooGladeXML *xml);
static void prefs_page_init (MooGladeXML *xml);
static void pattern_data_func (GtkTreeViewColumn *column,
GtkCellRenderer *cell,
GtkTreeModel *model,
GtkTreeIter *iter);
static void new_item (MooConfigHelper *helper,
MooConfig *config,
MooConfigItem *item);
static MooPlugin *
get_plugin (MooGladeXML *xml)
{
return g_object_get_data (G_OBJECT (xml), "as-plugin");
}
static void
setup_script_view (MooTextView *script)
{
MooLangMgr *mgr;
MooLang *lang;
MooIndenter *indent;
g_object_set (script, "highlight-current-line", FALSE, NULL);
mgr = moo_editor_get_lang_mgr (moo_editor_instance ());
lang = moo_lang_mgr_get_lang (mgr, "MooScript");
if (lang)
moo_text_view_set_lang (script, lang);
moo_text_view_set_font_from_string (script, "Monospace");
indent = moo_indenter_new (NULL, NULL);
moo_text_view_set_indenter (script, indent);
g_object_set (indent, "use-tabs", FALSE, "indent", 2, NULL);
g_object_unref (indent);
}
GtkWidget *
_as_plugin_prefs_page (MooPlugin *plugin)
{
MooPrefsDialogPage *page;
MooGladeXML *xml;
GtkWidget *treeview;
GtkTreeViewColumn *column;
GtkCellRenderer *cell;
MooConfigHelper *helper;
xml = moo_glade_xml_new_empty (GETTEXT_PACKAGE);
moo_glade_xml_map_id (xml, "script", MOO_TYPE_TEXT_VIEW);
page = moo_prefs_dialog_page_new_from_xml ("Active Strings", GTK_STOCK_CONVERT,
xml, AS_PLUGIN_GLADE_UI,
"page", NULL);
g_object_set_data_full (G_OBJECT (xml), "as-plugin",
g_object_ref (plugin), (GDestroyNotify) g_object_unref);
g_signal_connect_swapped (page, "apply", G_CALLBACK (prefs_page_apply), xml);
g_signal_connect_swapped (page, "init", G_CALLBACK (prefs_page_init), xml);
setup_script_view (moo_glade_xml_get_widget (xml, "script"));
treeview = moo_glade_xml_get_widget (xml, "treeview");
column = gtk_tree_view_column_new ();
gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
cell = gtk_cell_renderer_text_new ();
gtk_tree_view_column_pack_start (column, cell, TRUE);
gtk_tree_view_column_set_cell_data_func (column, cell,
(GtkTreeCellDataFunc) pattern_data_func,
NULL, NULL);
helper = _moo_config_helper_new (treeview,
moo_glade_xml_get_widget (xml, "new"),
moo_glade_xml_get_widget (xml, "delete"),
moo_glade_xml_get_widget (xml, "up"),
moo_glade_xml_get_widget (xml, "down"));
_moo_config_helper_add_widget (helper, moo_glade_xml_get_widget (xml, "pattern"),
AS_KEY_PATTERN, TRUE);
_moo_config_helper_add_widget (helper, moo_glade_xml_get_widget (xml, "lang"),
AS_KEY_LANG, FALSE);
_moo_config_helper_add_widget (helper, moo_glade_xml_get_widget (xml, "enabled"),
AS_KEY_ENABLED, TRUE);
_moo_config_helper_add_widget (helper, moo_glade_xml_get_widget (xml, "word_boundary"),
AS_KEY_WORD_BOUNDARY, FALSE);
_moo_config_helper_add_widget (helper, moo_glade_xml_get_widget (xml, "script"),
NULL, FALSE);
g_signal_connect (helper, "new-item",
G_CALLBACK (new_item), NULL);
g_object_set_data_full (G_OBJECT (treeview),
"as-plugin-config-helper",
helper, g_object_unref);
g_object_unref (xml);
return GTK_WIDGET (page);
}
static void
pattern_data_func (G_GNUC_UNUSED GtkTreeViewColumn *column,
GtkCellRenderer *cell,
GtkTreeModel *model,
GtkTreeIter *iter)
{
gboolean enabled;
const char *pattern;
MooConfigItem *item = NULL;
gtk_tree_model_get (model, iter, 0, &item, -1);
g_return_if_fail (item != NULL);
pattern = moo_config_item_get (item, AS_KEY_PATTERN);
enabled = moo_config_get_bool (MOO_CONFIG (model), item, AS_KEY_ENABLED);
g_object_set (cell, "text", pattern,
"foreground", enabled ? NULL : "grey",
"style", enabled ? PANGO_STYLE_NORMAL : PANGO_STYLE_ITALIC,
NULL);
}
static void
prefs_page_apply (MooGladeXML *xml)
{
GtkWidget *treeview;
MooConfig *config;
MooConfigHelper *helper;
GError *error = NULL;
treeview = moo_glade_xml_get_widget (xml, "treeview");
helper = g_object_get_data (G_OBJECT (treeview), "as-plugin-config-helper");
_moo_config_helper_update_model (helper, NULL, NULL);
config = MOO_CONFIG (gtk_tree_view_get_model (GTK_TREE_VIEW (treeview)));
if (!moo_config_get_modified (config))
return;
_as_plugin_save_config (config, &error);
if (error)
{
g_critical ("%s: could not save config: %s",
G_STRLOC, error->message);
g_error_free (error);
}
_as_plugin_reload (get_plugin (xml));
}
static void
prefs_page_init (MooGladeXML *xml)
{
MooConfig *config;
GtkWidget *treeview;
config = _as_plugin_load_config ();
if (!config)
config = moo_config_new ();
moo_config_set_default_bool (config, AS_KEY_ENABLED, TRUE);
treeview = moo_glade_xml_get_widget (xml, "treeview");
gtk_tree_view_set_model (GTK_TREE_VIEW (treeview), GTK_TREE_MODEL (config));
_moo_tree_view_select_first (GTK_TREE_VIEW (treeview));
g_object_unref (config);
}
static void
new_item (G_GNUC_UNUSED MooConfigHelper *helper,
MooConfig *config,
MooConfigItem *item)
{
moo_config_set (config, item, AS_KEY_PATTERN, "?", TRUE);
}

View File

@ -1,90 +0,0 @@
/*
* as-plugin-script.c
*
* Copyright (C) 2004-2007 by Yevgen Muntyan <muntyan@math.tamu.edu>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation.
*
* See COPYING file that comes with this distribution.
*/
#include "as-plugin-script.h"
#include "mooedit/mooedit-script.h"
static void
as_plugin_context_setup (MSContext *ctx,
MooEdit *doc,
char *match,
char **parens,
guint n_parens)
{
guint i;
MSValue *val;
val = ms_value_string (match);
ms_context_assign_positional (ctx, 0, val);
ms_value_unref (val);
for (i = 0; i < n_parens; ++i)
{
val = ms_value_string (parens[i]);
ms_context_assign_positional (ctx, i + 1, val);
ms_value_unref (val);
}
moo_edit_script_context_set_doc (MOO_EDIT_SCRIPT_CONTEXT (ctx),
GTK_TEXT_VIEW (doc));
}
static void
as_plugin_context_clear (MSContext *ctx,
guint n_parens)
{
guint i;
for (i = 0; i < n_parens + 1; ++i)
ms_context_assign_positional (ctx, i, NULL);
moo_edit_script_context_set_doc (MOO_EDIT_SCRIPT_CONTEXT (ctx), NULL);
}
gboolean
_as_plugin_context_exec (MSContext *ctx,
MSNode *script,
MooEdit *doc,
GtkTextIter *insert,
char *match,
char **parens,
guint n_parens)
{
MSValue *val;
gboolean success;
g_return_val_if_fail (MOO_IS_EDIT_SCRIPT_CONTEXT (ctx), FALSE);
g_return_val_if_fail (script != NULL, FALSE);
g_return_val_if_fail (MOO_IS_EDIT (doc), FALSE);
g_return_val_if_fail (insert != NULL, FALSE);
g_return_val_if_fail (match != NULL, FALSE);
g_return_val_if_fail (!n_parens || parens, FALSE);
as_plugin_context_setup (ctx, doc, match, parens, n_parens);
val = ms_top_node_eval (script, ctx);
success = val != NULL;
ms_value_unref (val);
if (!success)
{
g_print ("%s\n", ms_context_get_error_msg (ctx));
ms_context_clear_error (ctx);
}
as_plugin_context_clear (ctx, n_parens);
return success;
}

View File

@ -1,37 +0,0 @@
/*
* as-plugin-script.h
*
* Copyright (C) 2004-2007 by Yevgen Muntyan <muntyan@math.tamu.edu>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation.
*
* See COPYING file that comes with this distribution.
*/
#ifndef __AS_PLUGIN_SCRIPT_H__
#define __AS_PLUGIN_SCRIPT_H__
#include <mooscript/mooscript-context.h>
#include <mooscript/mooscript-node.h>
#include <mooedit/mooedit.h>
G_BEGIN_DECLS
#define _as_plugin_context_exec _moo_as_plugin_context_exec
gboolean _as_plugin_context_exec (MSContext *ctx,
MSNode *script,
MooEdit *doc,
GtkTextIter *insert,
char *match,
char **parens,
guint n_parens);
G_END_DECLS
#endif /* __AS_PLUGIN_SCRIPT_H__ */

File diff suppressed because it is too large Load Diff

View File

@ -1,272 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<glade-interface>
<widget class="GtkWindow" id="window1">
<property name="visible">True</property>
<property name="title">window1</property>
<child>
<widget class="GtkVBox" id="page">
<property name="visible">True</property>
<property name="border_width">6</property>
<child>
<widget class="GtkHBox" id="hbox1">
<property name="visible">True</property>
<child>
<widget class="GtkHPaned" id="hpaned1">
<property name="visible">True</property>
<child>
<widget class="GtkVBox" id="vbox2">
<property name="visible">True</property>
<child>
<widget class="GtkScrolledWindow" id="scrolledwindow1">
<property name="visible">True</property>
<property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<property name="shadow_type">GTK_SHADOW_IN</property>
<child>
<widget class="GtkTreeView" id="treeview">
<property name="visible">True</property>
<property name="border_width">3</property>
<property name="headers_visible">False</property>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkHBox" id="hbox2">
<property name="visible">True</property>
<property name="border_width">3</property>
<child>
<widget class="GtkButton" id="new">
<property name="visible">True</property>
<property name="focus_on_click">False</property>
<property name="tooltip">New item</property>
<child>
<widget class="GtkImage" id="image3">
<property name="visible">True</property>
<property name="stock">gtk-new</property>
</widget>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="delete">
<property name="visible">True</property>
<property name="focus_on_click">False</property>
<property name="tooltip">Delete item</property>
<child>
<widget class="GtkImage" id="image4">
<property name="visible">True</property>
<property name="stock">gtk-delete</property>
</widget>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="padding">3</property>
<property name="position">1</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="up">
<property name="visible">True</property>
<property name="focus_on_click">False</property>
<property name="tooltip">Move item up</property>
<child>
<widget class="GtkImage" id="image1">
<property name="visible">True</property>
<property name="stock">gtk-go-up</property>
</widget>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="pack_type">GTK_PACK_END</property>
<property name="position">3</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="down">
<property name="visible">True</property>
<property name="focus_on_click">False</property>
<property name="tooltip">Move item down</property>
<child>
<widget class="GtkImage" id="image2">
<property name="visible">True</property>
<property name="stock">gtk-go-down</property>
</widget>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="pack_type">GTK_PACK_END</property>
<property name="position">2</property>
</packing>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</widget>
<packing>
<property name="resize">False</property>
<property name="shrink">False</property>
</packing>
</child>
<child>
<widget class="GtkVBox" id="vbox3">
<property name="visible">True</property>
<child>
<widget class="GtkHBox" id="hbox3">
<property name="visible">True</property>
<property name="spacing">6</property>
<child>
<widget class="GtkCheckButton" id="enabled">
<property name="visible">True</property>
<property name="label">Enabled</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkCheckButton" id="word_boundary">
<property name="visible">True</property>
<property name="draw_indicator">True</property>
<child>
<widget class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="label">Word boundary</property>
<property name="pattern"></property>
</widget>
</child>
</widget>
<packing>
<property name="position">1</property>
</packing>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkTable" id="table">
<property name="visible">True</property>
<property name="n_rows">3</property>
<property name="n_columns">2</property>
<child>
<widget class="GtkLabel" id="label4">
<property name="visible">True</property>
<property name="xalign">0.000000</property>
<property name="label">Files:</property>
</widget>
<packing>
<property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkEntry" id="lang">
<property name="visible">True</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label3">
<property name="visible">True</property>
<property name="xalign">0.000000</property>
<property name="yalign">0.010000</property>
<property name="label">Script:</property>
</widget>
<packing>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkScrolledWindow" id="scrolledwindow2">
<property name="visible">True</property>
<property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<property name="shadow_type">GTK_SHADOW_IN</property>
<child>
<widget class="GtkTextView" id="script">
<property name="visible">True</property>
<property name="left_margin">3</property>
<property name="right_margin">3</property>
</widget>
</child>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkEntry" id="pattern">
<property name="visible">True</property>
<property name="activates_default">True</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label2">
<property name="visible">True</property>
<property name="xalign">0.000000</property>
<property name="label">Pattern:</property>
</widget>
<packing>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
</widget>
<packing>
<property name="position">1</property>
</packing>
</child>
</widget>
<packing>
<property name="resize">False</property>
<property name="shrink">False</property>
</packing>
</child>
</widget>
</child>
</widget>
</child>
</widget>
</child>
</widget>
</glade-interface>

View File

@ -1,49 +0,0 @@
/*
* as-plugin.h
*
* Copyright (C) 2004-2007 by Yevgen Muntyan <muntyan@math.tamu.edu>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation.
*
* See COPYING file that comes with this distribution.
*/
#include "mooedit/mooplugin.h"
#include "mooutils/mooconfig.h"
#ifndef __AS_PLUGIN_H__
#define __AS_PLUGIN_H__
G_BEGIN_DECLS
#define AS_FILE "as.cfg"
#define AS_KEY_PATTERN "pattern"
#define AS_KEY_LANG "lang"
#define AS_KEY_ENABLED "enabled"
#define AS_KEY_WORD_BOUNDARY "word-boundary"
#define AS_PLUGIN_ID "ActiveStrings"
#define AS_PREFS_ROOT MOO_PLUGIN_PREFS_ROOT "/" AS_PLUGIN_ID
#define AS_FILE_PREFS_KEY AS_PREFS_ROOT "/file"
#define _as_plugin_prefs_page _moo_as_plugin_prefs_page
#define _as_plugin_reload _moo_as_plugin_reload
#define _as_plugin_load_config _moo_as_plugin_load_config
#define _as_plugin_save_config _moo_as_plugin_save_config
GtkWidget *_as_plugin_prefs_page (MooPlugin *plugin);
void _as_plugin_reload (MooPlugin *plugin);
MooConfig *_as_plugin_load_config (void);
gboolean _as_plugin_save_config (MooConfig *config,
GError **error);
G_END_DECLS
#endif /* __AS_PLUGIN_H__ */

View File

@ -1,44 +0,0 @@
pattern: @code
enabled: false
lang: texinfo
Insert("{}"); Left();
pattern: @dfn
enabled: false
lang: texinfo
Insert("{}"); Left();
pattern: @end
enabled: false
lang: texinfo
Insert("{}"); Left();
pattern: @item
enabled: false
lang: texinfo
Insert("{}"); Left();
pattern: @kbd
enabled: false
lang: texinfo
Insert("{}"); Left();
pattern: @noindent
enabled: false
lang: texinfo
Insert("\n");
pattern: @samp
enabled: false
lang: texinfo
Insert("{}"); Left();
pattern: @var
enabled: false
lang: texinfo
Insert("{}"); Left();
pattern: @example
enabled: false
lang: texinfo
Insert("\n");

View File

@ -1,32 +0,0 @@
completiondir = $(MOO_DATA_DIR)/completion
completion_DATA = \
files/gap.lst \
files/latex.cfg
EXTRA_DIST = \
$(completion_DATA) \
completion.glade \
files/texinfo.cfg
completion_sources = \
completion-glade.h \
completion-plugin.c \
completion.c \
completion.h
BUILT_SOURCES = \
completion-glade.h
completion-glade.h: completion.glade $(XML2H)
$(SHELL) $(XML2H) COMPLETION_PLUGIN_GLADE_XML $(srcdir)/completion.glade > $@.tmp && \
mv $@.tmp $@
noinst_LTLIBRARIES = libcompletion.la
libcompletion_la_SOURCES = $(completion_sources)
AM_CFLAGS = \
-I../../.. \
-I$(top_builddir) \
$(MOO_CFLAGS) \
$(MOO_DEBUG_CFLAGS)

View File

@ -1,256 +0,0 @@
/*
* completion-plugin.c
*
* Copyright (C) 2004-2007 by Yevgen Muntyan <muntyan@math.tamu.edu>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation.
*
* See COPYING file that comes with this distribution.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "completion.h"
#include "completion-glade.h"
#include "mooedit/mooplugin-macro.h"
#include "mooedit/plugins/mooeditplugins.h"
#include "mooedit/marshals.h"
#include "mooutils/mooi18n.h"
#include "mooutils/mooprefsdialogpage.h"
#include <string.h>
#define AUTO_COMPLETE_PREFS_KEY CMPL_PREFS_ROOT "/auto_complete"
#define POPUP_INTERVAL_PREFS_KEY CMPL_PREFS_ROOT "/auto_complete_timeout"
static gboolean cmpl_plugin_init (CmplPlugin *plugin);
static void cmpl_plugin_deinit (CmplPlugin *plugin);
static void
focused_doc_changed (MooEditor *editor,
G_GNUC_UNUSED gpointer whatever,
CmplPlugin *plugin)
{
MooEdit *doc = NULL;
g_object_get (editor, "focused-doc", &doc, NULL);
_cmpl_plugin_set_focused_doc (plugin, doc);
if (doc)
g_object_unref (doc);
}
static void
set_auto_complete (CmplPlugin *plugin,
gboolean auto_complete)
{
MooEditor *editor = moo_editor_instance ();
auto_complete = auto_complete != 0;
if (auto_complete == plugin->auto_complete)
return;
plugin->auto_complete = auto_complete;
if (auto_complete)
{
g_signal_connect (editor, "notify::focused-doc",
G_CALLBACK (focused_doc_changed),
plugin);
focused_doc_changed (editor, NULL, plugin);
}
else
{
g_signal_handlers_disconnect_by_func (editor, (gpointer) focused_doc_changed, plugin);
_cmpl_plugin_set_focused_doc (plugin, NULL);
}
}
static void
set_popup_interval (CmplPlugin *plugin,
int interval)
{
if (interval <= 0)
{
g_warning ("%s: oops", G_STRLOC);
interval = DEFAULT_POPUP_TIMEOUT;
}
plugin->popup_interval = interval;
}
static void
prefs_notify (const char *key,
const GValue *newval,
CmplPlugin *plugin)
{
if (!strcmp (key, AUTO_COMPLETE_PREFS_KEY))
set_auto_complete (plugin, g_value_get_boolean (newval));
else if (!strcmp (key, POPUP_INTERVAL_PREFS_KEY))
set_popup_interval (plugin, g_value_get_int (newval));
}
static void
completion_callback (MooEditWindow *window)
{
CmplPlugin *plugin;
MooEdit *doc;
plugin = moo_plugin_lookup (CMPL_PLUGIN_ID);
g_return_if_fail (plugin != NULL);
doc = moo_edit_window_get_active_doc (window);
g_return_if_fail (doc != NULL);
_completion_complete (plugin, doc, FALSE);
}
static gboolean
cmpl_plugin_init (CmplPlugin *plugin)
{
MooWindowClass *klass = g_type_class_ref (MOO_TYPE_EDIT_WINDOW);
MooEditor *editor = moo_editor_instance ();
MooUIXML *xml = moo_editor_get_ui_xml (editor);
g_return_val_if_fail (klass != NULL, FALSE);
g_return_val_if_fail (editor != NULL, FALSE);
moo_window_class_new_action (klass, "CompleteWord", NULL,
"display-name", _("Complete Word"),
"label", _("Complete Word"),
"tooltip", _("Complete Word"),
"accel", MOO_EDIT_ACCEL_COMPLETE,
"closure-callback", completion_callback,
"condition::sensitive", "has-open-document",
NULL);
if (xml)
{
plugin->ui_merge_id = moo_ui_xml_new_merge_id (xml);
moo_ui_xml_add_item (xml, plugin->ui_merge_id,
"Editor/Menubar/Edit",
"CompleteWord", "CompleteWord", -1);
}
plugin->cmpl_quark = g_quark_from_static_string ("moo-completion");
_cmpl_plugin_load (plugin);
moo_prefs_new_key_bool (AUTO_COMPLETE_PREFS_KEY, FALSE);
moo_prefs_new_key_int (POPUP_INTERVAL_PREFS_KEY, DEFAULT_POPUP_TIMEOUT);
plugin->prefs_notify =
moo_prefs_notify_connect (AUTO_COMPLETE_PREFS_KEY,
MOO_PREFS_MATCH_PREFIX,
(MooPrefsNotify) prefs_notify,
plugin, NULL);
set_auto_complete (plugin, moo_prefs_get_bool (AUTO_COMPLETE_PREFS_KEY));
set_popup_interval (plugin, moo_prefs_get_int (POPUP_INTERVAL_PREFS_KEY));
g_type_class_unref (klass);
return TRUE;
}
static void
cmpl_plugin_deinit (CmplPlugin *plugin)
{
MooWindowClass *klass = g_type_class_ref (MOO_TYPE_EDIT_WINDOW);
MooEditor *editor = moo_editor_instance ();
MooUIXML *xml = moo_editor_get_ui_xml (editor);
_cmpl_plugin_clear (plugin);
moo_window_class_remove_action (klass, "CompleteWord");
if (plugin->ui_merge_id)
moo_ui_xml_remove_ui (xml, plugin->ui_merge_id);
plugin->ui_merge_id = 0;
moo_prefs_notify_disconnect (plugin->prefs_notify);
plugin->prefs_notify = 0;
set_auto_complete (plugin, FALSE);
g_type_class_unref (klass);
}
static GtkWidget *
cmpl_plugin_prefs_page (G_GNUC_UNUSED CmplPlugin *plugin)
{
MooPrefsDialogPage *page;
MooGladeXML *xml;
xml = moo_glade_xml_new_empty (GETTEXT_PACKAGE);
page = moo_prefs_dialog_page_new_from_xml (_("Completion"), NULL,
xml, COMPLETION_PLUGIN_GLADE_XML,
"page", CMPL_PREFS_ROOT);
g_object_unref (xml);
return GTK_WIDGET (page);
}
static void
set_lang_completion_meth (CmplPlugin *plugin,
const char *lang,
MooTextCompletion *cmpl)
{
_cmpl_plugin_set_lang_completion (plugin, lang, cmpl);
}
static void
set_doc_completion_meth (CmplPlugin *plugin,
MooEdit *doc,
MooTextCompletion *cmpl)
{
_cmpl_plugin_set_doc_completion (plugin, doc, cmpl);
}
MOO_PLUGIN_DEFINE_INFO (cmpl,
/* Completion plugin name */
N_("Completion"),
/* Completion plugin description */
N_("Provides text completion"),
"Yevgen Muntyan <muntyan@tamu.edu>",
MOO_VERSION, NULL)
MOO_PLUGIN_DEFINE_FULL (Cmpl, cmpl,
cmpl_plugin_init, cmpl_plugin_deinit,
NULL, NULL, NULL, NULL,
cmpl_plugin_prefs_page, 0, 0)
gboolean
_moo_completion_plugin_init (void)
{
GType ptype = cmpl_plugin_get_type ();
if (!moo_plugin_register (CMPL_PLUGIN_ID,
cmpl_plugin_get_type (),
&cmpl_plugin_info,
NULL))
return FALSE;
moo_plugin_method_new ("set-lang-completion", ptype,
G_CALLBACK (set_lang_completion_meth),
_moo_marshal_VOID__STRING_OBJECT,
G_TYPE_NONE, 2,
G_TYPE_STRING,
MOO_TYPE_TEXT_COMPLETION);
moo_plugin_method_new ("set-doc-completion", ptype,
G_CALLBACK (set_doc_completion_meth),
_moo_marshal_VOID__OBJECT_OBJECT,
G_TYPE_NONE, 2,
MOO_TYPE_EDIT,
MOO_TYPE_TEXT_COMPLETION);
return TRUE;
}

View File

@ -1,709 +0,0 @@
/*
* completion.c
*
* Copyright (C) 2004-2007 by Yevgen Muntyan <muntyan@math.tamu.edu>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation.
*
* See COPYING file that comes with this distribution.
*/
#include "completion.h"
#include "mooedit/moocompletionsimple.h"
#include "mooedit/mookeyfile.h"
#include "mooutils/mooutils-misc.h"
#include "mooutils/mooutils-fs.h"
#include "mooutils/moopython.h"
#include <gdk/gdkkeysyms.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <errno.h>
#include <string.h>
#include <time.h>
typedef enum {
DATA_FILE_SIMPLE,
DATA_FILE_CONFIG,
DATA_FILE_PYTHON
} DataFileType;
#define DATA_FILE_INVALID ((DataFileType) -1)
typedef struct {
char *path;
DataFileType type;
time_t mtime;
MooTextCompletion *cmpl;
} CmplData;
static CmplData *cmpl_data_new (void);
static void cmpl_data_free (CmplData *data);
static void cmpl_data_clear (CmplData *data);
static CmplData *cmpl_plugin_load_data (CmplPlugin *plugin,
const char *id);
static GList *
parse_words (const char *string,
const char *prefix,
const char *path)
{
GList *list = NULL;
char **words, **p;
g_return_val_if_fail (string != NULL, NULL);
words = g_strsplit_set (string, " \t\r\n", 0);
for (p = words; p && *p; ++p)
{
if (p[0][0] && p[0][1])
{
if (!g_utf8_validate (*p, -1, NULL))
{
g_critical ("%s: invalid utf8 in '%s'",
G_STRLOC, path);
}
else if (prefix)
{
list = g_list_prepend (list, g_strdup_printf ("%s%s", prefix, *p));
}
else
{
list = g_list_prepend (list, *p);
*p = NULL;
}
}
g_free (*p);
}
g_free (words);
return g_list_reverse (list);
}
static void
cmpl_data_read_simple_file (CmplData *data)
{
GError *error = NULL;
GList *list;
char *contents;
g_return_if_fail (data->cmpl == NULL);
g_return_if_fail (data->path != NULL);
g_file_get_contents (data->path, &contents, NULL, &error);
if (error)
{
g_warning ("%s: could not read file '%s': %s",
G_STRLOC, data->path, error->message);
g_error_free (error);
return;
}
list = parse_words (contents, NULL, data->path);
data->cmpl = moo_completion_simple_new_text (list);
_moo_message ("read %d words from %s", g_list_length (list), data->path);
g_free (contents);
}
static guint *
parse_numbers (const char *string,
guint *n_numbers_p)
{
guint *numbers;
guint n_numbers, i;
char **pieces, **p;
GSList *list = NULL;
g_return_val_if_fail (string != NULL, NULL);
pieces = g_strsplit_set (string, " \t,;:", 0);
g_return_val_if_fail (pieces != NULL, NULL);
for (p = pieces; p && *p; ++p)
{
if (**p)
{
guint64 n64;
guint n;
errno = 0;
n64 = g_ascii_strtoull (*p, NULL, 10);
if (errno || n64 > 10000)
{
g_warning ("%s: could not parse number '%s'", G_STRLOC, *p);
goto error;
}
n = n64;
list = g_slist_prepend (list, GUINT_TO_POINTER (n));
}
}
list = g_slist_reverse (list);
n_numbers = g_slist_length (list);
numbers = g_new (guint, n_numbers);
for (i = 0; i < n_numbers; ++i)
{
numbers[i] = GPOINTER_TO_UINT (list->data);
list = g_slist_delete_link (list, list);
}
if (n_numbers_p)
*n_numbers_p = n_numbers;
g_strfreev (pieces);
return numbers;
error:
g_strfreev (pieces);
g_slist_free (list);
return NULL;
}
static void
cmpl_data_read_config_file (CmplData *data)
{
MooKeyFile *key_file;
guint i, n_items;
MooCompletionGroup *group = NULL;
GError *error = NULL;
g_return_if_fail (data->cmpl == NULL);
g_return_if_fail (data->path != NULL);
data->cmpl = moo_completion_simple_new_text (NULL);
key_file = moo_key_file_new_from_file (data->path, &error);
if (!key_file)
{
g_warning ("%s", error->message);
g_error_free (error);
return;
}
n_items = moo_key_file_n_items (key_file);
g_return_if_fail (n_items != 0);
for (i = 0; i < n_items; ++i)
{
MooKeyFileItem *item;
const char *pattern, *prefix, *suffix, *script;
const char *groups;
guint *parens;
guint n_parens;
GList *words;
item = moo_key_file_nth_item (key_file, i);
pattern = moo_key_file_item_get (item, "pattern");
prefix = moo_key_file_item_get (item, "prefix");
suffix = moo_key_file_item_get (item, "insert-suffix");
script = moo_key_file_item_get (item, "insert-script");
groups = moo_key_file_item_get (item, "group");
groups = groups ? groups : moo_key_file_item_get (item, "groups");
groups = groups ? groups : "0";
if (!pattern)
{
g_warning ("%s: pattern missing", G_STRLOC);
continue;
}
parens = parse_numbers (groups, &n_parens);
if (!parens)
{
g_warning ("%s: invalid group string '%s'", G_STRLOC, groups);
continue;
}
words = parse_words (moo_key_file_item_get_content (item),
prefix, data->path);
if (!words)
{
g_warning ("%s: empty group", G_STRLOC);
g_free (parens);
continue;
}
_moo_message ("read %d words for patttern '%s' from %s",
g_list_length (words), pattern, data->path);
group = moo_completion_simple_new_group (MOO_COMPLETION_SIMPLE (data->cmpl), NULL);
moo_completion_group_add_data (group, words);
moo_completion_group_set_pattern (group, pattern, parens, n_parens);
if (script && script[0])
moo_completion_group_set_script (group, script);
else if (suffix && suffix[0])
moo_completion_group_set_suffix (group, suffix);
g_free (parens);
}
moo_key_file_unref (key_file);
if (!group)
{
g_warning ("%s: no completions", G_STRLOC);
return;
}
}
static void
cmpl_data_read_python_file (CmplData *data)
{
FILE *file;
MooPyObject *dict = NULL;
MooPyObject *res = NULL;
MooPyObject *py_cmpl = NULL;
MooCompletionSimple *cmpl;
g_return_if_fail (data->cmpl == NULL);
g_return_if_fail (data->path != NULL);
if (!moo_python_running ())
return;
file = _moo_fopen (data->path, "rb");
g_return_if_fail (file != NULL);
dict = moo_python_create_script_dict ("__completion_module__");
res = moo_python_run_file (file, data->path, dict, dict);
fclose (file);
if (!res)
{
g_message ("error executing file '%s'", data->path);
moo_PyErr_Print ();
goto out;
}
py_cmpl = moo_py_dict_get_item (dict, "__completion__");
if (!py_cmpl)
{
g_message ("no '__completion__' variable in file '%s'", data->path);
goto out;
}
cmpl = moo_gobject_from_py_object (py_cmpl);
if (!MOO_IS_TEXT_COMPLETION (cmpl))
{
g_message ("'__completion__' variable in file '%s' is not of type MooTextCompletion", data->path);
goto out;
}
data->cmpl = g_object_ref (cmpl);
out:
if (!data->cmpl)
data->cmpl = moo_completion_simple_new_text (NULL);
moo_Py_DECREF (dict);
moo_Py_DECREF (res);
moo_Py_DECREF (py_cmpl);
}
static void
cmpl_data_read_file (CmplData *data)
{
g_return_if_fail (data->path != NULL);
g_return_if_fail (data->cmpl == NULL);
switch (data->type)
{
case DATA_FILE_SIMPLE:
cmpl_data_read_simple_file (data);
break;
case DATA_FILE_CONFIG:
cmpl_data_read_config_file (data);
break;
case DATA_FILE_PYTHON:
cmpl_data_read_python_file (data);
break;
}
}
static CmplData *
cmpl_plugin_load_data (CmplPlugin *plugin,
const char *id)
{
CmplData *data;
g_return_val_if_fail (id != NULL, NULL);
data = g_hash_table_lookup (plugin->data, id);
if (!data)
{
data = cmpl_data_new ();
g_hash_table_insert (plugin->data, g_strdup (id), data);
}
else if (!data->cmpl && data->path)
{
cmpl_data_read_file (data);
}
return data;
}
static CmplData *
cmpl_data_new (void)
{
return g_new0 (CmplData, 1);
}
static void
cmpl_data_clear (CmplData *data)
{
g_free (data->path);
if (data->cmpl)
g_object_unref (data->cmpl);
data->path = NULL;
data->cmpl = NULL;
}
static void
cmpl_data_free (CmplData *data)
{
if (data)
{
cmpl_data_clear (data);
g_free (data);
}
}
void
_cmpl_plugin_set_lang_completion (CmplPlugin *plugin,
const char *lang,
MooTextCompletion *cmpl)
{
CmplData *data;
g_return_if_fail (!cmpl || MOO_IS_TEXT_COMPLETION (cmpl));
if (!lang || !lang[0])
lang = _moo_lang_id (NULL);
data = cmpl_data_new ();
data->cmpl = g_object_ref (cmpl);
g_hash_table_insert (plugin->data, g_strdup (lang), data);
}
void
_cmpl_plugin_set_doc_completion (CmplPlugin *plugin,
MooEdit *doc,
MooTextCompletion *cmpl)
{
g_return_if_fail (MOO_IS_EDIT (doc));
g_return_if_fail (!cmpl || MOO_IS_TEXT_COMPLETION (cmpl));
g_object_set_qdata_full (G_OBJECT (doc),
plugin->cmpl_quark,
g_object_ref (cmpl),
g_object_unref);
}
static void
cmpl_plugin_check_file (CmplPlugin *plugin,
const char *path,
DataFileType type,
const char *id)
{
struct stat buf;
CmplData *data;
/* TODO: filename encoding */
if (stat (path, &buf) == -1)
{
int err_no = errno;
g_warning ("%s: could not stat file '%s': %s",
G_STRLOC, path, g_strerror (err_no));
return;
}
if (!S_ISREG (buf.st_mode))
{
g_warning ("%s: '%s' is not a regular file",
G_STRLOC, path);
return;
}
data = g_hash_table_lookup (plugin->data, id);
if (data)
{
if (data->path && !strcmp (data->path, path) && data->mtime == buf.st_mtime)
return;
cmpl_data_clear (data);
}
else
{
data = cmpl_data_new ();
g_hash_table_insert (plugin->data, g_strdup (id), data);
}
data->path = g_strdup (path);
data->type = type;
data->mtime = buf.st_mtime;
_moo_message ("found file '%s' for lang '%s'", path, id);
}
static void
cmpl_plugin_load_dir (CmplPlugin *plugin,
const char *path)
{
GDir *dir;
const char *base;
if (!(dir = g_dir_open (path, 0, NULL)))
return;
while ((base = g_dir_read_name (dir)))
{
guint i, len;
char *file, *name, *id;
DataFileType type = DATA_FILE_INVALID;
const char *suffixes[] = {
CMPL_FILE_SUFFIX_LIST,
CMPL_FILE_SUFFIX_CONFIG,
CMPL_FILE_SUFFIX_PYTHON
};
DataFileType types[] = {
DATA_FILE_SIMPLE,
DATA_FILE_CONFIG,
DATA_FILE_PYTHON
};
name = g_ascii_strdown (base, -1);
len = strlen (name);
for (i = 0; i < G_N_ELEMENTS (suffixes); ++i)
{
if (g_str_has_suffix (base, suffixes[i]))
{
name[len - strlen (suffixes[i])] = 0;
if (name[0])
type = types[i];
break;
}
}
if (type == DATA_FILE_INVALID)
continue;
id = _moo_lang_id_from_name (name);
file = g_build_filename (path, base, NULL);
cmpl_plugin_check_file (plugin, file, type, id);
g_free (name);
g_free (id);
g_free (file);
}
g_dir_close (dir);
}
void
_cmpl_plugin_load (CmplPlugin *plugin)
{
char **dirs;
guint n_dirs, i;
plugin->data = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
(GDestroyNotify) cmpl_data_free);
dirs = _moo_strv_reverse (moo_get_data_subdirs (CMPL_DIR, MOO_DATA_SHARE, &n_dirs));
for (i = 0; i < n_dirs; ++i)
cmpl_plugin_load_dir (plugin, dirs[i]);
g_strfreev (dirs);
}
void
_cmpl_plugin_clear (CmplPlugin *plugin)
{
g_hash_table_destroy (plugin->data);
plugin->data = NULL;
}
static MooTextCompletion *
get_doc_completion (CmplPlugin *plugin,
MooEdit *doc)
{
MooTextCompletion *cmpl = NULL;
cmpl = g_object_get_qdata (G_OBJECT (doc), plugin->cmpl_quark);
if (!cmpl)
{
MooLang *lang;
CmplData *data;
lang = moo_text_view_get_lang (MOO_TEXT_VIEW (doc));
data = cmpl_plugin_load_data (plugin, _moo_lang_id (lang));
g_return_val_if_fail (data != NULL, NULL);
cmpl = data->cmpl;
}
return cmpl;
}
static void
completion_finished (MooTextCompletion *cmpl,
CmplPlugin *plugin)
{
plugin->working = FALSE;
g_signal_handlers_disconnect_by_func (cmpl, (gpointer) completion_finished, plugin);
}
void
_completion_complete (CmplPlugin *plugin,
MooEdit *doc,
gboolean automatic)
{
MooTextCompletion *cmpl;
g_return_if_fail (!plugin->working);
g_return_if_fail (MOO_IS_EDIT (doc));
cmpl = get_doc_completion (plugin, doc);
if (cmpl)
{
plugin->working = TRUE;
moo_text_completion_set_doc (cmpl, GTK_TEXT_VIEW (doc));
g_signal_connect (cmpl, "finish", G_CALLBACK (completion_finished), plugin);
moo_text_completion_try_complete (cmpl, automatic);
}
}
static gboolean
popup_timeout (CmplPlugin *plugin)
{
plugin->popup_timeout = 0;
if (!plugin->working)
_completion_complete (plugin, plugin->focused_doc, TRUE);
return FALSE;
}
static void
remove_popup_timeout (CmplPlugin *plugin)
{
if (plugin->popup_timeout)
g_source_remove (plugin->popup_timeout);
plugin->popup_timeout = 0;
}
static void
reinstall_popup_timeout (CmplPlugin *plugin)
{
remove_popup_timeout (plugin);
if (!plugin->working)
{
if (!plugin->popup_timeout)
plugin->popup_timeout =
_moo_timeout_add (plugin->popup_interval, (GSourceFunc) popup_timeout, plugin);
}
}
static gboolean
doc_key_press (CmplPlugin *plugin)
{
remove_popup_timeout (plugin);
return FALSE;
}
static gboolean
doc_char_inserted (CmplPlugin *plugin)
{
reinstall_popup_timeout (plugin);
return FALSE;
}
static void
connect_doc (CmplPlugin *plugin,
MooEdit *doc)
{
g_signal_connect_swapped (doc, "key-press-event",
G_CALLBACK (doc_key_press),
plugin);
g_signal_connect_swapped (doc, "char-inserted",
G_CALLBACK (doc_char_inserted),
plugin);
}
static void
disconnect_doc (CmplPlugin *plugin,
MooEdit *doc)
{
remove_popup_timeout (plugin);
g_signal_handlers_disconnect_by_func (doc, (gpointer) doc_key_press, plugin);
g_signal_handlers_disconnect_by_func (doc, (gpointer) doc_char_inserted, plugin);
}
void
_cmpl_plugin_set_focused_doc (CmplPlugin *plugin,
MooEdit *doc)
{
if (plugin->focused_doc == doc)
return;
if (plugin->focused_doc)
{
disconnect_doc (plugin, plugin->focused_doc);
plugin->focused_doc = NULL;
}
if (doc)
{
plugin->focused_doc = doc;
connect_doc (plugin, doc);
}
}

View File

@ -1,70 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!-- Generated with glade3
Version: 3.0.0
Date: Thu Dec 7 00:28:09 2006
User: muntyan
Host: munt10
-->
<glade-interface>
<widget class="GtkWindow" id="window1">
<child>
<widget class="GtkVBox" id="page">
<property name="visible">True</property>
<property name="border_width">6</property>
<child>
<widget class="GtkCheckButton" id="checkbutton1">
<property name="visible">True</property>
<property name="label" translatable="yes">Enable autocompletion</property>
<property name="draw_indicator">True</property>
<property name="moo_prefs_key">auto_complete</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkHBox" id="hbox1">
<property name="visible">True</property>
<property name="spacing">3</property>
<child>
<widget class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="label" translatable="yes" comments="Autocompletion timeout, in milliseconds">Autocompletion timeout, ms:</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkSpinButton" id="spinbutton1">
<property name="visible">True</property>
<property name="adjustment">0.000000 0.000000 10000.000000 1.000000 10.000000 10.000000</property>
<property name="numeric">True</property>
<property name="moo_prefs_key">auto_complete_timeout</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
<child>
<placeholder/>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
<child>
<placeholder/>
</child>
</widget>
</child>
</widget>
</glade-interface>

View File

@ -1,76 +0,0 @@
/*
* completion.h
*
* Copyright (C) 2004-2007 by Yevgen Muntyan <muntyan@math.tamu.edu>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation.
*
* See COPYING file that comes with this distribution.
*/
#include "mooedit/mooplugin.h"
#include "mooedit/mootextcompletion.h"
#ifndef __COMPLETION_H__
#define __COMPLETION_H__
G_BEGIN_DECLS
#define CMPL_PLUGIN_ID "Completion"
#define CMPL_PREFS_ROOT MOO_PLUGIN_PREFS_ROOT "/" CMPL_PLUGIN_ID
#define CMPL_DIR "completion"
#define CMPL_FILE_SUFFIX_LIST ".lst"
#define CMPL_FILE_SUFFIX_CONFIG ".cfg"
#define CMPL_FILE_SUFFIX_PYTHON ".py"
#define DEFAULT_POPUP_TIMEOUT 100
#define _completion_complete _moo_completion_plugin_complete
#define _cmpl_plugin_load _moo_completion_plugin_load
#define _cmpl_plugin_clear _moo_completion_plugin_clear
#define _cmpl_plugin_set_lang_completion _moo_completion_plugin_set_lang_completion
#define _cmpl_plugin_set_doc_completion _moo_completion_plugin_set_doc_completion
#define _cmpl_plugin_set_focused_doc _moo_completion_plugin_set_focused_doc
#define _cmpl_plugin_set_auto_complete _moo_completion_plugin_set_auto_complete
typedef struct {
MooPlugin parent;
guint ui_merge_id;
GQuark cmpl_quark;
GHashTable *data; /* char* -> CompletionData* */
guint prefs_notify;
gboolean auto_complete;
MooEdit *focused_doc;
guint popup_timeout;
int popup_interval;
gboolean working;
} CmplPlugin;
void _completion_complete (CmplPlugin *plugin,
MooEdit *doc,
gboolean automatic);
void _cmpl_plugin_load (CmplPlugin *plugin);
void _cmpl_plugin_clear (CmplPlugin *plugin);
void _cmpl_plugin_set_focused_doc (CmplPlugin *plugin,
MooEdit *doc);
void _cmpl_plugin_set_lang_completion (CmplPlugin *plugin,
const char *lang,
MooTextCompletion *cmpl);
void _cmpl_plugin_set_doc_completion (CmplPlugin *plugin,
MooEdit *doc,
MooTextCompletion *cmpl);
G_END_DECLS
#endif /* __COMPLETION_H__ */

File diff suppressed because it is too large Load Diff

View File

@ -1,44 +0,0 @@
[entry]
pattern = \\documentclass{(\w*)
insert-suffix = }
group = 1
article report letter book slides
[entry]
pattern = \\(begin|end){(\w*)
group = 2
insert-suffix = }
array center description document enumerate eqnarray equation figure
flushleft flushright itemize letter list minipage picture quotation
quote table tabular thebibliography theorem titlepage verbatim verse
[entry]
pattern = \\\w*
prefix = \
addtocounter alph arabic fnsymbol newcounter refstepcounter roman
stepcounter setcounter usecounter value label pageref ref newcommand
newenvironment newtheorem newfont footnote footnotemark footnotetext
flushbottom onecolumn raggedbottom twocolumn newlength setlength
addtolength settodepth settoheight settowidth cleardoublepage
clearpage enlargethispage fussy hyphenation linebreak newline newpage
nolinebreak nopagebreak pagebreak sloppy indent noindent par cdots
ddots frac ldots overbrace overline sqrt underbrace underline vdots
maketitle author date thanks title pagenumbering pagestyle markboth
markright thispagestyle dotfill hfill hrulefill hspace
addvspace bigskip medskip smallskip vfill vspace fbox framebox makebox
mbox newsavebox parbox raisebox rule savebox sbox usebox part chapter
section subsection subsubsection paragraph subparagraph include includeonly
input addcontentsline addtocontents typein typeout textrm textit emph
textmd textbf textup textsl textsf textsc texttt textnormal mathrm mathbf
mathsf mathtt mathit mathnormal mathcal tiny scriptsize footnotesize
small normalsize large Large LARGE huge Huge
alpha beta gamma delta epsilon zeta eta theta iota kappa lambda mu nu
xi omicron pi rho sigma tau upsilon phi varphi chi psi omega
Alpha Beta Gamma Delta Epsilon Zeta Eta Theta Iota Kappa Lambda Mu Nu
Xi Omicron Pi Rho Sigma Tau Upsilon Phi Chi Psi Omega
[entry]
pattern = \\\w*
prefix = \
insert-script = Insert(completion, "{}"); Left();
begin end documentclass

View File

@ -1,243 +0,0 @@
pattern: @.*
prefix: @
insert-script: Insert(completion, "{}"); Left();
code
pattern: @.*
prefix: @
xref
WHITESPACE
w
vtable
vskip
vindex
var
value
v
url
uref
unnumberedsubsubsec
unnumberedsubsec
unnumberedsec
unnumbered
udotaccent
ubaraccent
u
top
today{}
titlepage
titlefont
title
tindex
tieaccent
thistitle
thispage
thisfile
thischaptername
thischapter
TeX{}
tex
table
tab
t
synindex
syncodeindex
summarycontents
subtitle
subsubsection
subsubheading
subsection
subheading
strong
ss{}
sp
smalllisp
smallexample
smallbook
shorttitlepage
shortcontents
settitle
setfilename
setchapternewpage
set
section
sc
samp
ringaccent
result{}
registeredsymbol{}
refill
ref
raisesections
r
quotation
questiondown{}
pxref
printindex
print{}
pounds{}
point{}
pindex
paragraphindent
page
OE{}
oe{}
oddheading
oddfooting
O{}
o{}
noindent
node
need
multitable
minus{}
menu
math
majorheading
macro
lowersections
lisp
L{}
l{}
kindex
key
kbdinputstyle
kbd
itemx
itemize
item
insertcopying
inforef
include
image
ignore
iftex
ifset
ifnottex
ifnotinfo
ifnothtml
ifinfo
ifhtml
ifclear
i
hyphenation
html
headings
heading
H
group
ftable
format
footnotestyle
footnote
flushright
flushleft
findex
finalout
file
expansion{}
exdent
exclamdown{}
example
everyheading
everyfooting
evenheading
evenfooting
error{}
equiv{}
enumerate
end
enddots{}
emph
email
dots{}
dotaccent
dmn
display
direntry
dircategory
dfn
detailmenu{}
defvarx
defvar
defunx
defun
deftypevrx
deftypevr
deftypevarx
deftypevar
deftypemethodx
deftypemethod
deftypefunx
deftypefun
deftypefnx
deftypefn
deftpx
deftp
defspecx
defspec
defopx
defoptx
defopt
defop
defmethodx
defmethod
defmacx
defmac
defivarx
defivar
definfoenclose
defindex
deffnx
deffn
defcvx
defcv
defcodeindex
copyright{}
contents
comment
clear
cite
cindex
chapter
chapheading
centerchap
center
cartouche
bye
bullet{}
b
author
asis
appendixsubsubsec
appendixsubsec
appendixsection
appendixsec
appendix
afourpaper
AE{}
ae{}
AA{}
aa{}
*
{
.
?
^
}
"
'
!
:
,
-
=
=
`
pattern: @end
insert-script: Insert(" ", completion);
vtable titlepage tex table smalllisp smallexample quotation multitable
menu lisp itemize ignore iftex ifset ifnottex ifnotinfo ifnothtml ifinfo
ifhtml ifclear html group ftable format flushright flushleft example
enumerate direntry cartouche

View File

@ -23,8 +23,6 @@ gboolean _moo_ctags_plugin_init (void);
#endif
gboolean _moo_find_plugin_init (void);
gboolean _moo_active_strings_plugin_init (void);
gboolean _moo_completion_plugin_init (void);
gboolean _moo_file_selector_plugin_init (void);
gboolean _moo_project_plugin_init (void);
gboolean _moo_file_list_plugin_init (void);

View File

@ -41,8 +41,6 @@ moo/mooedit/glade/mooprintpreview.glade
moo/mooedit/glade/mooquicksearch.glade
moo/mooedit/glade/mootextfind.glade
moo/mooedit/glade/mootextgotoline.glade
moo/mooedit/plugins/completion/completion.glade
moo/mooedit/plugins/completion/completion-plugin.c
moo/mooedit/plugins/moofilelist.c
moo/mooedit/plugins/moofileselector.c
moo/mooedit/plugins/moofileselector.glade

View File

@ -92,8 +92,6 @@ moo/mooedit/langs/verilog.lang
moo/mooedit/langs/vhdl.lang
moo/mooedit/langs/xml.lang
moo/mooedit/langs/yacc.lang
moo/mooedit/plugins/completion/completion-plugin.c
moo/mooedit/plugins/completion/completion.glade
moo/moopython/plugins/pyproject/mprj/config/view.py
moo/moopython/plugins/pyproject/mprj/manager.py
moo/moopython/plugins/pyproject/mprj/optdialog.py