Use word-boundary option

master
Yevgen Muntyan 2006-04-24 01:28:53 -05:00
parent 88a39130f8
commit e9a850a887
4 changed files with 321 additions and 469 deletions

View File

@ -110,6 +110,8 @@ _as_plugin_prefs_page (MooPlugin *plugin)
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);

View File

@ -44,11 +44,17 @@ typedef struct _ASMatch ASMatch;
typedef struct _ASInfo ASInfo;
typedef enum {
AS_WORD_BOUNDARY = 1 << 0
} ASOptions;
struct _ASInfo {
char *pattern;
char *script;
char *lang;
guint enabled : 1;
ASOptions start_opts : 1;
ASOptions end_opts : 1;
};
struct _ASPlugin {
@ -94,11 +100,6 @@ struct _ASMatch {
guint n_parens;
};
typedef enum {
AS_WORD_BOUNDARY = 1 << 0,
AS_NOT_WORD_BOUNDARY = 1 << 1
} ASOptions;
static gboolean as_plugin_init (ASPlugin *plugin);
static void as_plugin_deinit (ASPlugin *plugin);
@ -147,6 +148,8 @@ static ASInfo *
as_info_new (const char *pattern,
const char *script,
const char *lang,
ASOptions start_opts,
ASOptions end_opts,
gboolean enabled)
{
ASInfo *info;
@ -158,6 +161,9 @@ as_info_new (const char *pattern,
info->script = (script && script[0]) ? g_strdup (script) : NULL;
info->lang = (lang && lang[0]) ? g_ascii_strdown (lang, -1) : NULL;
info->enabled = enabled != 0;
info->start_opts = start_opts;
info->end_opts = end_opts;
return info;
}
@ -184,12 +190,12 @@ cmp_ints (gunichar *c1, gunichar *c2)
static void
append_options (GString *pattern,
ASOptions opts)
ASOptions opts,
gunichar ch)
{
if (opts & AS_WORD_BOUNDARY)
if ((opts & AS_WORD_BOUNDARY) &&
(ch == '_' || g_unichar_isalpha (ch)))
g_string_append (pattern, "\\b");
else if (opts & AS_NOT_WORD_BOUNDARY)
g_string_append (pattern, "\\B");
}
static void
@ -216,6 +222,7 @@ as_string_get_info (const char *string,
ASStringInfo *info = NULL;
char *rev = NULL;
GString *pattern = NULL;
gunichar first, last;
if (!string || !string[0])
{
@ -226,6 +233,8 @@ as_string_get_info (const char *string,
rev = g_utf8_strreverse (string, -1);
rev_len = strlen (rev);
info = g_new0 (ASStringInfo, 1);
first = g_utf8_get_char (string);
last = g_utf8_get_char (rev);
if (string[0] == AS_WILDCARD && string[1] != AS_WILDCARD)
{
@ -243,7 +252,7 @@ as_string_get_info (const char *string,
pattern = g_string_sized_new (rev_len + 16);
if (end_opts)
append_options (pattern, end_opts);
append_options (pattern, end_opts, last);
g_string_append_printf (pattern, "(?P<%d>", string_no);
@ -275,7 +284,7 @@ as_string_get_info (const char *string,
g_string_append (pattern, ")");
if (start_opts)
append_options (pattern, start_opts);
append_options (pattern, start_opts, first);
info->pattern_len = pattern->len;
info->pattern = g_string_free (pattern, FALSE);
@ -677,7 +686,10 @@ as_plugin_load_info (ASPlugin *plugin,
ar = any_lang;
}
sinfo = as_string_get_info (info->pattern, 0, 0, ar->len);
sinfo = as_string_get_info (info->pattern,
info->start_opts,
info->end_opts,
ar->len);
if (!sinfo)
{
@ -723,14 +735,15 @@ as_plugin_parse_config (MooConfig *config)
for (i = 0; i < n_items; ++i)
{
const char *pattern, *lang, *script;
gboolean enabled;
gboolean enabled, word_boundary;
ASInfo *info;
MooConfigItem *item = moo_config_nth_item (config, i);
pattern = moo_config_item_get (item, AS_KEY_PATTERN);
lang = moo_config_item_get (item, AS_KEY_LANG);
enabled = moo_config_get_bool (config, item, AS_KEY_ENABLED);
script = moo_config_item_get_content (item);
enabled = moo_config_get_bool (config, item, AS_KEY_ENABLED);
word_boundary = moo_config_get_bool (config, item, AS_KEY_WORD_BOUNDARY);
if (!pattern)
{
@ -741,7 +754,9 @@ as_plugin_parse_config (MooConfig *config)
if (!script || !script[0])
script = NULL;
info = as_info_new (pattern, script, lang, enabled);
info = as_info_new (pattern, script, lang,
word_boundary ? AS_WORD_BOUNDARY : 0,
0, enabled);
if (info)
list = g_slist_prepend (list, info);
@ -1100,6 +1115,7 @@ _as_plugin_load_config (void)
else
{
moo_config_set_default_bool (config, AS_KEY_ENABLED, TRUE);
moo_config_set_default_bool (config, AS_KEY_WORD_BOUNDARY, TRUE);
}
g_free (file);

View File

@ -1,49 +1,23 @@
<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">
<?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" translatable="yes">window1</property>
<property name="type">GTK_WINDOW_TOPLEVEL</property>
<property name="window_position">GTK_WIN_POS_NONE</property>
<property name="modal">False</property>
<property name="resizable">True</property>
<property name="destroy_with_parent">False</property>
<property name="decorated">True</property>
<property name="skip_taskbar_hint">False</property>
<property name="skip_pager_hint">False</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
<property name="focus_on_map">True</property>
<property name="urgency_hint">False</property>
<property name="title">window1</property>
<child>
<widget class="GtkVBox" id="page">
<property name="border_width">6</property>
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<property name="border_width">6</property>
<child>
<widget class="GtkHBox" id="hbox1">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child>
<widget class="GtkHPaned" id="hpaned1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="position">0</property>
<child>
<widget class="GtkVBox" id="vbox2">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child>
<widget class="GtkScrolledWindow" id="scrolledwindow1">
<property name="visible">True</property>
@ -51,246 +25,221 @@
<property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<property name="shadow_type">GTK_SHADOW_IN</property>
<property name="window_placement">GTK_CORNER_TOP_LEFT</property>
<child>
<widget class="GtkTreeView" id="treeview">
<property name="border_width">3</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="border_width">3</property>
<property name="headers_visible">False</property>
<property name="rules_hint">False</property>
<property name="reorderable">False</property>
<property name="enable_search">True</property>
<property name="fixed_height_mode">False</property>
<property name="hover_selection">False</property>
<property name="hover_expand">False</property>
</widget>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
<child>
<widget class="GtkHBox" id="hbox2">
<property name="border_width">3</property>
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<property name="border_width">3</property>
<child>
<widget class="GtkButton" id="new">
<property name="visible">True</property>
<property name="tooltip" translatable="yes">New item</property>
<property name="can_focus">True</property>
<property name="relief">GTK_RELIEF_NORMAL</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>
<property name="icon_size">4</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
</child>
</widget>
<packing>
<property name="padding">0</property>
<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="tooltip" translatable="yes">Delete item</property>
<property name="can_focus">True</property>
<property name="relief">GTK_RELIEF_NORMAL</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>
<property name="icon_size">4</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="padding">3</property>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="down">
<property name="visible">True</property>
<property name="tooltip" translatable="yes">Move item down</property>
<property name="can_focus">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">False</property>
<child>
<widget class="GtkImage" id="image2">
<property name="visible">True</property>
<property name="stock">gtk-go-down</property>
<property name="icon_size">4</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="pack_type">GTK_PACK_END</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="up">
<property name="visible">True</property>
<property name="tooltip" translatable="yes">Move item up</property>
<property name="can_focus">True</property>
<property name="relief">GTK_RELIEF_NORMAL</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>
<property name="icon_size">4</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
</child>
</widget>
<packing>
<property name="padding">0</property>
<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="can_focus">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="padding">0</property>
<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="shrink">False</property>
<property name="resize">False</property>
<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>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child>
<widget class="GtkHBox" id="hbox3">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<property name="spacing">6</property>
<child>
<widget class="GtkCheckButton" id="enabled">
<property name="visible">True</property>
<property name="tooltip" translatable="yes">Set whether the menu item is enabled</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Enabled</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="active">False</property>
<property name="inconsistent">False</property>
<property name="label">Enabled</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="padding">0</property>
<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="padding">0</property>
<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>
<property name="homogeneous">False</property>
<property name="row_spacing">0</property>
<property name="column_spacing">0</property>
<child>
<widget class="GtkLabel" id="label2">
<widget class="GtkLabel" id="label4">
<property name="visible">True</property>
<property name="label" translatable="yes">Pattern:</property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
<property name="xalign">0.000000</property>
<property name="label">Files:</property>
</widget>
<packing>
<property name="left_attach">0</property>
<property name="right_attach">1</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">fill</property>
<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>
<property name="can_focus">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="can_focus">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="can_focus">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="can_focus">True</property>
<property name="editable">True</property>
<property name="visibility">True</property>
<property name="max_length">0</property>
<property name="text" translatable="yes"></property>
<property name="has_frame">True</property>
<property name="invisible_char">*</property>
<property name="activates_default">True</property>
</widget>
<packing>
@ -301,151 +250,35 @@
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkScrolledWindow" id="scrolledwindow2">
<widget class="GtkLabel" id="label2">
<property name="visible">True</property>
<property name="can_focus">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>
<property name="window_placement">GTK_CORNER_TOP_LEFT</property>
<child>
<widget class="GtkTextView" id="script">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="editable">True</property>
<property name="overwrite">False</property>
<property name="accepts_tab">True</property>
<property name="justification">GTK_JUSTIFY_LEFT</property>
<property name="wrap_mode">GTK_WRAP_NONE</property>
<property name="cursor_visible">True</property>
<property name="pixels_above_lines">0</property>
<property name="pixels_below_lines">0</property>
<property name="pixels_inside_wrap">0</property>
<property name="left_margin">3</property>
<property name="right_margin">3</property>
<property name="indent">0</property>
<property name="text" translatable="yes"></property>
</widget>
</child>
<property name="xalign">0.000000</property>
<property name="label">Pattern:</property>
</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">fill</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label3">
<property name="visible">True</property>
<property name="label" translatable="yes">Script:</property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0</property>
<property name="yalign">0.00999999977648</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
</widget>
<packing>
<property name="left_attach">0</property>
<property name="right_attach">1</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">fill</property>
<property name="y_options">fill</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label4">
<property name="visible">True</property>
<property name="label" translatable="yes">Files:</property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
</widget>
<packing>
<property name="left_attach">0</property>
<property name="right_attach">1</property>
<property name="top_attach">0</property>
<property name="bottom_attach">1</property>
<property name="x_options">fill</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkEntry" id="lang">
<property name="visible">True</property>
<property name="tooltip" translatable="yes">Enter file type or leave blank to enable it for all files</property>
<property name="can_focus">True</property>
<property name="editable">True</property>
<property name="visibility">True</property>
<property name="max_length">0</property>
<property name="text" translatable="yes"></property>
<property name="has_frame">True</property>
<property name="invisible_char">*</property>
<property name="activates_default">False</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">0</property>
<property name="bottom_attach">1</property>
<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="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</widget>
<packing>
<property name="shrink">False</property>
<property name="resize">False</property>
</packing>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="shrink">False</property>
</packing>
</child>
</widget>
</child>
</widget>
</child>
</widget>
</child>
</widget>
</glade-interface>

View File

@ -26,6 +26,7 @@ G_BEGIN_DECLS
#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