Allow better filters for user tools
parent
88438a8c89
commit
108f51c246
|
@ -17,6 +17,7 @@
|
|||
<child>
|
||||
<widget class="GtkScrolledWindow" id="scrolledwindow1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</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>
|
||||
|
@ -36,8 +37,9 @@
|
|||
<child>
|
||||
<widget class="GtkButton" id="new">
|
||||
<property name="visible">True</property>
|
||||
<property name="focus_on_click">False</property>
|
||||
<property name="tooltip" translatable="yes">New item</property>
|
||||
<property name="focus_on_click">False</property>
|
||||
<property name="response_id">0</property>
|
||||
<child>
|
||||
<widget class="GtkImage" id="image3">
|
||||
<property name="visible">True</property>
|
||||
|
@ -53,8 +55,9 @@
|
|||
<child>
|
||||
<widget class="GtkButton" id="delete">
|
||||
<property name="visible">True</property>
|
||||
<property name="focus_on_click">False</property>
|
||||
<property name="tooltip" translatable="yes">Delete item</property>
|
||||
<property name="focus_on_click">False</property>
|
||||
<property name="response_id">0</property>
|
||||
<child>
|
||||
<widget class="GtkImage" id="image4">
|
||||
<property name="visible">True</property>
|
||||
|
@ -72,8 +75,9 @@
|
|||
<child>
|
||||
<widget class="GtkButton" id="up">
|
||||
<property name="visible">True</property>
|
||||
<property name="focus_on_click">False</property>
|
||||
<property name="tooltip" translatable="yes">Move item up</property>
|
||||
<property name="focus_on_click">False</property>
|
||||
<property name="response_id">0</property>
|
||||
<child>
|
||||
<widget class="GtkImage" id="image1">
|
||||
<property name="visible">True</property>
|
||||
|
@ -91,8 +95,9 @@
|
|||
<child>
|
||||
<widget class="GtkButton" id="down">
|
||||
<property name="visible">True</property>
|
||||
<property name="focus_on_click">False</property>
|
||||
<property name="tooltip" translatable="yes">Move item down</property>
|
||||
<property name="focus_on_click">False</property>
|
||||
<property name="response_id">0</property>
|
||||
<child>
|
||||
<widget class="GtkImage" id="image2">
|
||||
<property name="visible">True</property>
|
||||
|
@ -128,12 +133,19 @@
|
|||
<property name="visible">True</property>
|
||||
<property name="n_rows">5</property>
|
||||
<property name="n_columns">2</property>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkCheckButton" id="enabled">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">Enabled</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="focus_on_click">False</property>
|
||||
<property name="response_id">0</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
</widget>
|
||||
<packing>
|
||||
|
@ -155,7 +167,7 @@
|
|||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkEntry" id="langs">
|
||||
<widget class="GtkEntry" id="filter">
|
||||
<property name="visible">True</property>
|
||||
</widget>
|
||||
<packing>
|
||||
|
@ -191,29 +203,6 @@
|
|||
<property name="y_options"></property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkLabel" id="filter_label">
|
||||
<property name="xalign">1</property>
|
||||
<property name="label" translatable="yes">Filter:</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="top_attach">3</property>
|
||||
<property name="bottom_attach">4</property>
|
||||
<property name="x_options">GTK_FILL</property>
|
||||
<property name="y_options"></property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkEntry" id="filter">
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="right_attach">2</property>
|
||||
<property name="top_attach">3</property>
|
||||
<property name="bottom_attach">4</property>
|
||||
<property name="y_options"></property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkHBox" id="hbox3">
|
||||
<property name="visible">True</property>
|
||||
|
@ -273,6 +262,7 @@
|
|||
</child>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="resize">True</property>
|
||||
<property name="shrink">False</property>
|
||||
</packing>
|
||||
</child>
|
||||
|
@ -285,11 +275,12 @@
|
|||
<property name="visible">True</property>
|
||||
<property name="title">window2</property>
|
||||
<child>
|
||||
<widget class="GtkVBox" id="moo_script_page">
|
||||
<widget class="GtkVBox" id="lua_page">
|
||||
<property name="visible">True</property>
|
||||
<child>
|
||||
<widget class="GtkScrolledWindow" id="scrolledwindow2">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
|
||||
<property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
|
||||
<property name="shadow_type">GTK_SHADOW_ETCHED_IN</property>
|
||||
|
@ -465,6 +456,7 @@ Something
|
|||
<child>
|
||||
<widget class="GtkScrolledWindow" id="scrolledwindow4">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
|
||||
<property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
|
||||
<property name="shadow_type">GTK_SHADOW_ETCHED_IN</property>
|
||||
|
@ -490,6 +482,7 @@ Something
|
|||
<child>
|
||||
<widget class="GtkScrolledWindow" id="scrolledwindow3">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
|
||||
<property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
|
||||
<property name="shadow_type">GTK_SHADOW_ETCHED_IN</property>
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include "mooedit/mooeditaction.h"
|
||||
#include "mooedit/mooeditaction-factory.h"
|
||||
#include "mooedit/mooedit-private.h"
|
||||
#include "mooedit/mooeditfiltersettings.h"
|
||||
#include <glib/gregex.h>
|
||||
#include <string.h>
|
||||
|
||||
|
@ -28,7 +29,7 @@ typedef enum {
|
|||
|
||||
struct _MooEditActionPrivate {
|
||||
MooEdit *doc;
|
||||
GSList *langs;
|
||||
MooEditFilter *file_filter;
|
||||
GRegex *filters[N_FILTERS];
|
||||
};
|
||||
|
||||
|
@ -48,7 +49,7 @@ G_DEFINE_TYPE (MooEditAction, moo_edit_action, MOO_TYPE_ACTION)
|
|||
enum {
|
||||
PROP_0,
|
||||
PROP_DOC,
|
||||
PROP_LANGS,
|
||||
PROP_FILE_FILTER,
|
||||
PROP_FILTER_SENSITIVE,
|
||||
PROP_FILTER_VISIBLE
|
||||
};
|
||||
|
@ -72,8 +73,7 @@ moo_edit_action_finalize (GObject *object)
|
|||
if (action->priv->filters[i])
|
||||
unuse_filter_regex (action->priv->filters[i]);
|
||||
|
||||
g_slist_foreach (action->priv->langs, (GFunc) g_free, NULL);
|
||||
g_slist_free (action->priv->langs);
|
||||
_moo_edit_filter_free (action->priv->file_filter);
|
||||
|
||||
G_OBJECT_CLASS(moo_edit_action_parent_class)->finalize (object);
|
||||
}
|
||||
|
@ -118,20 +118,12 @@ moo_edit_action_get_property (GObject *object,
|
|||
|
||||
|
||||
static void
|
||||
string_slist_free (GSList *list)
|
||||
moo_edit_action_set_file_filter (MooEditAction *action,
|
||||
const char *string)
|
||||
{
|
||||
g_slist_foreach (list, (GFunc) g_free, NULL);
|
||||
g_slist_free (list);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
moo_edit_action_set_langs (MooEditAction *action,
|
||||
const char *string)
|
||||
{
|
||||
string_slist_free (action->priv->langs);
|
||||
action->priv->langs = _moo_edit_parse_langs (string);
|
||||
g_object_notify (G_OBJECT (action), "langs");
|
||||
_moo_edit_filter_free (action->priv->file_filter);
|
||||
action->priv->file_filter = _moo_edit_filter_new (string);
|
||||
g_object_notify (G_OBJECT (action), "file-filter");
|
||||
}
|
||||
|
||||
|
||||
|
@ -173,8 +165,8 @@ moo_edit_action_set_property (GObject *object,
|
|||
g_object_notify (object, "doc");
|
||||
break;
|
||||
|
||||
case PROP_LANGS:
|
||||
moo_edit_action_set_langs (action, g_value_get_string (value));
|
||||
case PROP_FILE_FILTER:
|
||||
moo_edit_action_set_file_filter (action, g_value_get_string (value));
|
||||
break;
|
||||
|
||||
case PROP_FILTER_SENSITIVE:
|
||||
|
@ -234,25 +226,18 @@ get_current_line (MooEdit *doc)
|
|||
static gboolean
|
||||
moo_edit_action_check_visible_real (MooEditAction *action)
|
||||
{
|
||||
MooLang *lang;
|
||||
gboolean visible = TRUE;
|
||||
GRegex *filter = action->priv->filters[FILTER_VISIBLE];
|
||||
|
||||
if (!action->priv->doc)
|
||||
return gtk_action_get_visible (GTK_ACTION (action));
|
||||
|
||||
if (!action->priv->langs && !filter)
|
||||
if (!action->priv->file_filter && !filter)
|
||||
return gtk_action_get_visible (GTK_ACTION (action));
|
||||
|
||||
if (visible && action->priv->langs)
|
||||
{
|
||||
lang = moo_text_view_get_lang (MOO_TEXT_VIEW (action->priv->doc));
|
||||
|
||||
if (!g_slist_find_custom (action->priv->langs,
|
||||
_moo_lang_id (lang),
|
||||
(GCompareFunc) strcmp))
|
||||
if (visible && action->priv->file_filter)
|
||||
if (!_moo_edit_filter_match (action->priv->file_filter, action->priv->doc))
|
||||
visible = FALSE;
|
||||
}
|
||||
|
||||
if (visible && filter)
|
||||
{
|
||||
|
@ -315,10 +300,10 @@ moo_edit_action_class_init (MooEditActionClass *klass)
|
|||
G_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_LANGS,
|
||||
g_param_spec_string ("langs",
|
||||
"langs",
|
||||
"langs",
|
||||
PROP_FILE_FILTER,
|
||||
g_param_spec_string ("file-filter",
|
||||
"file-filter",
|
||||
"file-filter",
|
||||
NULL,
|
||||
G_PARAM_WRITABLE));
|
||||
|
||||
|
|
|
@ -14,11 +14,16 @@
|
|||
#define MOOEDIT_COMPILATION
|
||||
#include "mooedit/mooeditfiltersettings.h"
|
||||
#include "mooedit/mooeditprefs.h"
|
||||
#include "mooedit/mooeditaction.h"
|
||||
#include "mooutils/mooprefs.h"
|
||||
#include "mooutils/mooutils-misc.h"
|
||||
#include "mooutils/mooutils-debug.h"
|
||||
#include <glib/gregex.h>
|
||||
#include <string.h>
|
||||
#ifndef __WIN32__
|
||||
#include <fnmatch.h>
|
||||
#endif
|
||||
|
||||
|
||||
MOO_DEBUG_INIT(filters, FALSE)
|
||||
|
||||
|
@ -27,6 +32,20 @@ MOO_DEBUG_INIT(filters, FALSE)
|
|||
#define PROP_FILTER "filter"
|
||||
#define PROP_CONFIG "config"
|
||||
|
||||
typedef enum {
|
||||
MOO_EDIT_FILTER_LANGS,
|
||||
MOO_EDIT_FILTER_GLOBS,
|
||||
MOO_EDIT_FILTER_REGEX
|
||||
} MooEditFilterType;
|
||||
|
||||
struct _MooEditFilter {
|
||||
MooEditFilterType type;
|
||||
union {
|
||||
GSList *langs;
|
||||
GSList *globs;
|
||||
GRegex *regex;
|
||||
} u;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
GRegex *regex;
|
||||
|
@ -44,6 +63,211 @@ static char *filter_settings_store_get_setting (FilterSettingsStore *store,
|
|||
const char *filename);
|
||||
|
||||
|
||||
MooEditFilter *
|
||||
_moo_edit_filter_new (const char *string)
|
||||
{
|
||||
g_return_val_if_fail (string && string[0], NULL);
|
||||
|
||||
if (!strncmp (string, "langs:", strlen ("langs:")))
|
||||
return _moo_edit_filter_new_langs (string + strlen ("langs:"));
|
||||
if (!strncmp (string, "globs:", strlen ("globs:")))
|
||||
return _moo_edit_filter_new_globs (string + strlen ("globs:"));
|
||||
if (!strncmp (string, "regex:", strlen ("regex:")))
|
||||
return _moo_edit_filter_new_regex (string + strlen ("regex:"));
|
||||
|
||||
return _moo_edit_filter_new_globs (string);
|
||||
}
|
||||
|
||||
MooEditFilter *
|
||||
_moo_edit_filter_new_langs (const char *string)
|
||||
{
|
||||
MooEditFilter *filt;
|
||||
|
||||
g_return_val_if_fail (string != NULL, NULL);
|
||||
|
||||
filt = g_new0 (MooEditFilter, 1);
|
||||
filt->type = MOO_EDIT_FILTER_LANGS;
|
||||
filt->u.langs = _moo_edit_parse_langs (string);
|
||||
|
||||
return filt;
|
||||
}
|
||||
|
||||
MooEditFilter *
|
||||
_moo_edit_filter_new_regex (const char *string)
|
||||
{
|
||||
MooEditFilter *filt;
|
||||
GRegex *regex;
|
||||
GError *error = NULL;
|
||||
|
||||
g_return_val_if_fail (string != NULL, NULL);
|
||||
|
||||
regex = g_regex_new (string, G_REGEX_OPTIMIZE, 0, &error);
|
||||
|
||||
if (!regex)
|
||||
{
|
||||
g_warning ("%s: invalid regex '%s': %s", G_STRFUNC,
|
||||
string, error->message);
|
||||
g_error_free (NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
filt = g_new0 (MooEditFilter, 1);
|
||||
filt->type = MOO_EDIT_FILTER_REGEX;
|
||||
filt->u.regex = regex;
|
||||
|
||||
return filt;
|
||||
}
|
||||
|
||||
static GSList *
|
||||
parse_globs (const char *string)
|
||||
{
|
||||
char **pieces, **p;
|
||||
GSList *list = NULL;
|
||||
|
||||
if (!string)
|
||||
return NULL;
|
||||
|
||||
pieces = g_strsplit_set (string, " \t\r\n;,", 0);
|
||||
|
||||
if (!pieces)
|
||||
return NULL;
|
||||
|
||||
for (p = pieces; *p != NULL; ++p)
|
||||
{
|
||||
g_strstrip (*p);
|
||||
|
||||
if (**p)
|
||||
list = g_slist_prepend (list, g_strdup (*p));
|
||||
}
|
||||
|
||||
g_strfreev (pieces);
|
||||
return g_slist_reverse (list);
|
||||
}
|
||||
|
||||
MooEditFilter *
|
||||
_moo_edit_filter_new_globs (const char *string)
|
||||
{
|
||||
MooEditFilter *filt;
|
||||
|
||||
g_return_val_if_fail (string != NULL, NULL);
|
||||
|
||||
filt = g_new0 (MooEditFilter, 1);
|
||||
filt->type = MOO_EDIT_FILTER_GLOBS;
|
||||
filt->u.globs = parse_globs (string);
|
||||
|
||||
return filt;
|
||||
}
|
||||
|
||||
void
|
||||
_moo_edit_filter_free (MooEditFilter *filter)
|
||||
{
|
||||
if (filter)
|
||||
{
|
||||
switch (filter->type)
|
||||
{
|
||||
case MOO_EDIT_FILTER_GLOBS:
|
||||
case MOO_EDIT_FILTER_LANGS:
|
||||
g_slist_foreach (filter->u.langs, (GFunc) g_free, NULL);
|
||||
g_slist_free (filter->u.langs);
|
||||
break;
|
||||
case MOO_EDIT_FILTER_REGEX:
|
||||
g_regex_unref (filter->u.regex);
|
||||
break;
|
||||
}
|
||||
|
||||
g_free (filter);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static gboolean
|
||||
moo_edit_filter_check_globs (GSList *globs,
|
||||
MooEdit *doc)
|
||||
{
|
||||
char *name = NULL;
|
||||
|
||||
name = moo_edit_get_filename (doc);
|
||||
|
||||
if (name)
|
||||
{
|
||||
char *tmp = name;
|
||||
name = g_path_get_basename (tmp);
|
||||
g_free (tmp);
|
||||
}
|
||||
|
||||
while (globs)
|
||||
{
|
||||
if (name)
|
||||
{
|
||||
if (fnmatch (globs->data, name, 0) == 0)
|
||||
{
|
||||
g_free (name);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!strcmp (globs->data, "*"))
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
globs = globs->next;
|
||||
}
|
||||
|
||||
g_free (name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
moo_edit_filter_check_langs (GSList *langs,
|
||||
MooEdit *doc)
|
||||
{
|
||||
MooLang *lang;
|
||||
const char *id;
|
||||
|
||||
lang = moo_text_view_get_lang (MOO_TEXT_VIEW (doc));
|
||||
id = _moo_lang_id (lang);
|
||||
|
||||
while (langs)
|
||||
{
|
||||
if (!strcmp (langs->data, id))
|
||||
return TRUE;
|
||||
langs = langs->next;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
moo_edit_filter_check_regex (GRegex *regex,
|
||||
MooEdit *doc)
|
||||
{
|
||||
const char *name = moo_edit_get_display_name (doc);
|
||||
g_return_val_if_fail (name != NULL, FALSE);
|
||||
return g_regex_match (regex, name, 0, NULL);
|
||||
}
|
||||
|
||||
gboolean
|
||||
_moo_edit_filter_match (MooEditFilter *filter,
|
||||
MooEdit *doc)
|
||||
{
|
||||
g_return_val_if_fail (filter != NULL, FALSE);
|
||||
g_return_val_if_fail (MOO_IS_EDIT (doc), FALSE);
|
||||
|
||||
switch (filter->type)
|
||||
{
|
||||
case MOO_EDIT_FILTER_GLOBS:
|
||||
return moo_edit_filter_check_globs (filter->u.globs, doc);
|
||||
case MOO_EDIT_FILTER_LANGS:
|
||||
return moo_edit_filter_check_langs (filter->u.langs, doc);
|
||||
case MOO_EDIT_FILTER_REGEX:
|
||||
return moo_edit_filter_check_regex (filter->u.regex, doc);
|
||||
}
|
||||
|
||||
g_return_val_if_reached (FALSE);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
filter_setting_free (FilterSetting *setting)
|
||||
{
|
||||
|
|
|
@ -18,17 +18,27 @@
|
|||
#ifndef MOO_EDIT_FILTER_SETTINGS_H
|
||||
#define MOO_EDIT_FILTER_SETTINGS_H
|
||||
|
||||
#include <glib.h>
|
||||
#include <mooedit/mooedit.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
||||
void _moo_edit_filter_settings_load (void);
|
||||
typedef struct _MooEditFilter MooEditFilter;
|
||||
|
||||
GSList *_moo_edit_filter_settings_get_strings (void);
|
||||
void _moo_edit_filter_settings_set_strings (GSList *strings);
|
||||
MooEditFilter *_moo_edit_filter_new (const char *string);
|
||||
MooEditFilter *_moo_edit_filter_new_langs (const char *string);
|
||||
MooEditFilter *_moo_edit_filter_new_regex (const char *string);
|
||||
MooEditFilter *_moo_edit_filter_new_globs (const char *string);
|
||||
void _moo_edit_filter_free (MooEditFilter *filter);
|
||||
gboolean _moo_edit_filter_match (MooEditFilter *filter,
|
||||
MooEdit *doc);
|
||||
|
||||
char *_moo_edit_filter_settings_get_for_file (const char *filename);
|
||||
void _moo_edit_filter_settings_load (void);
|
||||
|
||||
GSList *_moo_edit_filter_settings_get_strings (void);
|
||||
void _moo_edit_filter_settings_set_strings (GSList *strings);
|
||||
|
||||
char *_moo_edit_filter_settings_get_for_file (const char *filename);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "mooedit/statusbar-glade.h"
|
||||
#include "mooedit/mooedit-private.h"
|
||||
#include "mooedit/mooeditor-private.h"
|
||||
#include "mooedit/mooeditfiltersettings.h"
|
||||
#include "mooedit/moolang.h"
|
||||
#include "mooedit/mootextbuffer.h"
|
||||
#include "mooedit/mooeditprefs.h"
|
||||
|
@ -129,7 +130,7 @@ static void moo_edit_window_get_property (GObject *object,
|
|||
GParamSpec *pspec);
|
||||
|
||||
|
||||
static gboolean moo_edit_window_close (MooEditWindow *window);
|
||||
static gboolean moo_edit_window_close (MooWindow *window);
|
||||
|
||||
static void setup_notebook (MooEditWindow *window);
|
||||
static void update_window_title (MooEditWindow *window);
|
||||
|
@ -304,7 +305,7 @@ moo_edit_window_class_init (MooEditWindowClass *klass)
|
|||
gobject_class->set_property = moo_edit_window_set_property;
|
||||
gobject_class->get_property = moo_edit_window_get_property;
|
||||
gtkobject_class->destroy = moo_edit_window_destroy;
|
||||
window_class->close = (gboolean (*) (MooWindow*)) moo_edit_window_close;
|
||||
window_class->close = moo_edit_window_close;
|
||||
|
||||
moo_edit_tab_atom = gdk_atom_intern ("MOO_EDIT_TAB", FALSE);
|
||||
text_uri_atom = gdk_atom_intern ("text/uri-list", FALSE);
|
||||
|
@ -1185,9 +1186,10 @@ moo_edit_window_close_all (MooEditWindow *window)
|
|||
|
||||
|
||||
static gboolean
|
||||
moo_edit_window_close (MooEditWindow *window)
|
||||
moo_edit_window_close (MooWindow *window)
|
||||
{
|
||||
moo_editor_close_window (window->priv->editor, window, TRUE);
|
||||
MooEditWindow *edit_window = MOO_EDIT_WINDOW (window);
|
||||
moo_editor_close_window (edit_window->priv->editor, edit_window, TRUE);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -3394,32 +3396,6 @@ moo_edit_window_remove_action_check (const char *action_id,
|
|||
}
|
||||
|
||||
|
||||
static gboolean
|
||||
check_action_langs (G_GNUC_UNUSED GtkAction *action,
|
||||
G_GNUC_UNUSED MooEditWindow *window,
|
||||
MooEdit *doc,
|
||||
gpointer langs_list)
|
||||
{
|
||||
gboolean value = FALSE;
|
||||
|
||||
if (doc)
|
||||
{
|
||||
MooLang *lang = moo_text_view_get_lang (MOO_TEXT_VIEW (doc));
|
||||
value = NULL != g_slist_find_custom (langs_list, _moo_lang_id (lang),
|
||||
(GCompareFunc) strcmp);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
static void
|
||||
string_list_free (gpointer list)
|
||||
{
|
||||
g_slist_foreach (list, (GFunc) g_free, NULL);
|
||||
g_slist_free (list);
|
||||
}
|
||||
|
||||
|
||||
GSList *
|
||||
_moo_edit_parse_langs (const char *string)
|
||||
{
|
||||
|
@ -3446,23 +3422,39 @@ _moo_edit_parse_langs (const char *string)
|
|||
return g_slist_reverse (list);
|
||||
}
|
||||
|
||||
void
|
||||
moo_edit_window_set_action_langs (const char *action_id,
|
||||
MooActionCheckType type,
|
||||
const char *langs)
|
||||
|
||||
static gboolean
|
||||
check_action_filter (G_GNUC_UNUSED GtkAction *action,
|
||||
G_GNUC_UNUSED MooEditWindow *window,
|
||||
MooEdit *doc,
|
||||
gpointer filter)
|
||||
{
|
||||
GSList *langs_list;
|
||||
gboolean value = FALSE;
|
||||
|
||||
if (doc)
|
||||
value = _moo_edit_filter_match (filter, doc);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
void
|
||||
moo_edit_window_set_action_filter (const char *action_id,
|
||||
MooActionCheckType type,
|
||||
const char *filter_string)
|
||||
{
|
||||
MooEditFilter *filter = NULL;
|
||||
|
||||
g_return_if_fail (action_id != NULL);
|
||||
g_return_if_fail (type < N_ACTION_CHECKS);
|
||||
|
||||
langs_list = _moo_edit_parse_langs (langs);
|
||||
if (filter_string)
|
||||
filter = _moo_edit_filter_new (filter_string);
|
||||
|
||||
if (langs_list)
|
||||
if (filter)
|
||||
moo_edit_window_set_action_check (action_id, type,
|
||||
check_action_langs,
|
||||
langs_list,
|
||||
string_list_free);
|
||||
check_action_filter,
|
||||
filter,
|
||||
(GDestroyNotify) _moo_edit_filter_free);
|
||||
else
|
||||
moo_edit_window_remove_action_check (action_id, type);
|
||||
}
|
||||
|
|
|
@ -73,9 +73,9 @@ void moo_edit_window_set_action_check (const char *action_id,
|
|||
MooActionCheckFunc func,
|
||||
gpointer data,
|
||||
GDestroyNotify notify);
|
||||
void moo_edit_window_set_action_langs (const char *action_id,
|
||||
void moo_edit_window_set_action_filter (const char *action_id,
|
||||
MooActionCheckType type,
|
||||
const char *langs);
|
||||
const char *filter);
|
||||
|
||||
MooEdit *moo_edit_window_get_active_doc (MooEditWindow *window);
|
||||
void moo_edit_window_set_active_doc (MooEditWindow *window,
|
||||
|
|
|
@ -101,7 +101,7 @@ new_row (MooPrefsDialogPage *page,
|
|||
GtkTreeViewColumn *column;
|
||||
|
||||
info = _moo_user_tool_info_new ();
|
||||
info->cmd_factory = moo_command_factory_lookup ("moo-script");
|
||||
info->cmd_factory = moo_command_factory_lookup ("lua");
|
||||
info->cmd_data = info->cmd_factory ? moo_command_data_new (info->cmd_factory->n_keys) : NULL;
|
||||
info->name = g_strdup (_("New Command"));
|
||||
info->options = g_strdup ("need-doc");
|
||||
|
@ -161,7 +161,7 @@ update_widgets (MooPrefsDialogPage *page,
|
|||
_moo_command_display_set (helper, info->cmd_factory, info->cmd_data);
|
||||
|
||||
gtk_toggle_button_set_active (GET_WID ("enabled"), info->enabled);
|
||||
set_text (page, "langs", info->langs);
|
||||
set_text (page, "filter", info->filter);
|
||||
set_text (page, "options", info->options);
|
||||
|
||||
_moo_user_tool_info_unref (info);
|
||||
|
@ -169,7 +169,7 @@ update_widgets (MooPrefsDialogPage *page,
|
|||
else
|
||||
{
|
||||
gtk_toggle_button_set_active (GET_WID ("enabled"), FALSE);
|
||||
set_text (page, "langs", NULL);
|
||||
set_text (page, "filter", NULL);
|
||||
set_text (page, "options", NULL);
|
||||
_moo_command_display_set (helper, NULL, NULL);
|
||||
}
|
||||
|
@ -228,7 +228,7 @@ update_model (MooPrefsDialogPage *page,
|
|||
changed = TRUE;
|
||||
}
|
||||
|
||||
changed = get_text (page, "langs", &info->langs) || changed;
|
||||
changed = get_text (page, "filter", &info->filter) || changed;
|
||||
changed = get_text (page, "options", &info->options) || changed;
|
||||
|
||||
if (changed)
|
||||
|
@ -406,7 +406,7 @@ main_page_apply (MooPrefsDialogPage *main_page)
|
|||
|
||||
|
||||
GtkWidget *
|
||||
_moo_user_tools_prefs_page_new (void)
|
||||
moo_user_tools_prefs_page_new (void)
|
||||
{
|
||||
MooPrefsDialogPage *page;
|
||||
MooPrefsDialogPage *page_menu, *page_context;
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
G_BEGIN_DECLS
|
||||
|
||||
|
||||
GtkWidget *_moo_user_tools_prefs_page_new (void);
|
||||
GtkWidget *moo_user_tools_prefs_page_new (void);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
#include "mooedit/mooeditor.h"
|
||||
#include "mooedit/mooeditaction.h"
|
||||
#include "mooedit/mooeditaction-factory.h"
|
||||
#include "mooedit/mookeyfile.h"
|
||||
#include "mooutils/mooutils-misc.h"
|
||||
#include "mooutils/mooutils-debug.h"
|
||||
#include "mooutils/mooaccel.h"
|
||||
|
@ -33,6 +32,7 @@
|
|||
#define KEY_ACCEL "accel"
|
||||
#define KEY_MENU "menu"
|
||||
#define KEY_LANGS "langs"
|
||||
#define KEY_FILTER "filter"
|
||||
#define KEY_POSITION "position"
|
||||
#define KEY_COMMAND "command"
|
||||
#define KEY_NAME "name"
|
||||
|
@ -333,8 +333,8 @@ load_tool (MooUserToolInfo *info)
|
|||
check_sensitive_func,
|
||||
NULL, NULL);
|
||||
|
||||
if (info->langs)
|
||||
moo_edit_window_set_action_langs (info->id, MOO_ACTION_CHECK_ACTIVE, info->langs);
|
||||
if (info->filter)
|
||||
moo_edit_window_set_action_filter (info->id, MOO_ACTION_CHECK_ACTIVE, info->filter);
|
||||
|
||||
break;
|
||||
|
||||
|
@ -346,7 +346,7 @@ load_tool (MooUserToolInfo *info)
|
|||
"label", info->name,
|
||||
"accel", info->accel,
|
||||
"command", cmd,
|
||||
"langs", info->langs,
|
||||
"file-filter", info->filter,
|
||||
NULL);
|
||||
break;
|
||||
}
|
||||
|
@ -448,6 +448,7 @@ parse_item (MooKeyFileItem *item,
|
|||
char *os;
|
||||
char *position = NULL;
|
||||
MooUserToolInfo *info;
|
||||
char *langs;
|
||||
|
||||
if (strcmp (moo_key_file_item_name (item), ITEM_TOOL))
|
||||
{
|
||||
|
@ -486,7 +487,6 @@ parse_item (MooKeyFileItem *item,
|
|||
|
||||
info->accel = moo_key_file_item_steal (item, KEY_ACCEL);
|
||||
info->menu = moo_key_file_item_steal (item, KEY_MENU);
|
||||
info->langs = moo_key_file_item_steal (item, KEY_LANGS);
|
||||
position = moo_key_file_item_steal (item, KEY_POSITION);
|
||||
|
||||
if (position)
|
||||
|
@ -502,6 +502,16 @@ parse_item (MooKeyFileItem *item,
|
|||
g_free (position);
|
||||
}
|
||||
|
||||
if ((langs = moo_key_file_item_steal (item, KEY_LANGS)))
|
||||
{
|
||||
info->filter = g_strdup_printf ("langs: %s", langs);
|
||||
g_free (langs);
|
||||
}
|
||||
else
|
||||
{
|
||||
info->filter = moo_key_file_item_steal (item, KEY_FILTER);
|
||||
}
|
||||
|
||||
info->cmd_data = _moo_command_parse_item (item, info->name, file,
|
||||
&info->cmd_factory,
|
||||
&info->options);
|
||||
|
@ -666,45 +676,22 @@ static void
|
|||
generate_id (MooUserToolInfo *info,
|
||||
GHashTable *ids)
|
||||
{
|
||||
char *base, *name;
|
||||
guint i;
|
||||
|
||||
g_return_if_fail (info->id == NULL);
|
||||
|
||||
if (info->name)
|
||||
name = get_name (info->name);
|
||||
else
|
||||
name = NULL;
|
||||
|
||||
base = g_strdup_printf ("MooUserTool_%s", name ? name : "");
|
||||
g_strcanon (base, G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "_", '_');
|
||||
|
||||
if (!g_hash_table_lookup (ids, base))
|
||||
for (i = 0; ; ++i)
|
||||
{
|
||||
info->id = base;
|
||||
base = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
guint i = 0;
|
||||
char *id = g_strdup_printf ("MooUserTool%u", i);
|
||||
|
||||
while (TRUE)
|
||||
if (!g_hash_table_lookup (ids, id))
|
||||
{
|
||||
char *tmp = g_strdup_printf ("%s_%u", base, i);
|
||||
|
||||
if (!g_hash_table_lookup (ids, tmp))
|
||||
{
|
||||
info->id = tmp;
|
||||
break;
|
||||
}
|
||||
|
||||
g_free (tmp);
|
||||
|
||||
i += 1;
|
||||
info->id = id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
g_free (name);
|
||||
g_free (base);
|
||||
g_free (id);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -776,7 +763,7 @@ info_equal (MooUserToolInfo *info1,
|
|||
_moo_str_equal (info1->name, info2->name) &&
|
||||
_moo_str_equal (info1->accel, info2->accel) &&
|
||||
_moo_str_equal (info1->menu, info2->menu) &&
|
||||
_moo_str_equal (info1->langs, info2->langs) &&
|
||||
_moo_str_equal (info1->filter, info2->filter) &&
|
||||
_moo_str_equal (info1->options, info2->options) &&
|
||||
_moo_command_factory_data_equal (info1->cmd_factory, info1->cmd_data, info2->cmd_data);
|
||||
}
|
||||
|
@ -874,8 +861,8 @@ _moo_edit_save_user_tools (MooUserToolType type,
|
|||
moo_key_file_item_set (item, KEY_ACCEL, info->accel);
|
||||
if (info->menu && info->menu[0])
|
||||
moo_key_file_item_set (item, KEY_MENU, info->menu);
|
||||
if (info->langs && info->langs[0])
|
||||
moo_key_file_item_set (item, KEY_LANGS, info->langs);
|
||||
if (info->filter && info->filter[0])
|
||||
moo_key_file_item_set (item, KEY_FILTER, info->filter);
|
||||
if (!info->enabled)
|
||||
moo_key_file_item_set_bool (item, KEY_ENABLED, info->enabled);
|
||||
if (info->position != MOO_USER_TOOL_POS_END)
|
||||
|
@ -938,7 +925,7 @@ _moo_user_tool_info_unref (MooUserToolInfo *info)
|
|||
g_free (info->name);
|
||||
g_free (info->accel);
|
||||
g_free (info->menu);
|
||||
g_free (info->langs);
|
||||
g_free (info->filter);
|
||||
g_free (info->options);
|
||||
g_free (info->file);
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ typedef struct {
|
|||
char *name;
|
||||
char *accel;
|
||||
char *menu;
|
||||
char *langs;
|
||||
char *filter;
|
||||
char *options;
|
||||
MooUserToolPosition position;
|
||||
MooUserToolOSType os_type;
|
||||
|
|
|
@ -43,7 +43,7 @@ class Plugin(moo.edit.Plugin):
|
|||
stock_id=moo.utils.STOCK_EXECUTE,
|
||||
accel="<shift>F9",
|
||||
callback=self.run_file)
|
||||
moo.edit.window_set_action_langs("RunFile", moo.edit.ACTION_CHECK_SENSITIVE, "python")
|
||||
moo.edit.window_set_action_filter("RunFile", moo.edit.ACTION_CHECK_SENSITIVE, "langs:python")
|
||||
xml.add_item(self.ui_merge_id, "ToolsMenu",
|
||||
"RunFile", "RunFile", -1)
|
||||
|
||||
|
|
|
@ -543,13 +543,13 @@
|
|||
)
|
||||
|
||||
|
||||
(define-function window_set_action_langs
|
||||
(c-name "moo_edit_window_set_action_langs")
|
||||
(define-function window_set_action_filter
|
||||
(c-name "moo_edit_window_set_action_filter")
|
||||
(return-type "none")
|
||||
(parameters
|
||||
'("const-char*" "action_id")
|
||||
'("MooActionCheckType" "type")
|
||||
'("const-char*" "langs")
|
||||
'("const-char*" "filter")
|
||||
)
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue