moo_edit_window_set_action_langs()

master
Yevgen Muntyan 2006-05-05 16:17:32 -05:00
parent ba649ef5f9
commit 68cf1cbb9b
5 changed files with 144 additions and 0 deletions

View File

@ -2565,6 +2565,63 @@ moo_edit_window_add_action_check (const char *action_id,
}
static void
check_action_langs (G_GNUC_UNUSED MooAction *action,
MooEdit *doc,
G_GNUC_UNUSED GParamSpec *pspec,
GValue *prop_value,
gpointer langs)
{
MooLang *lang;
gboolean value;
lang = moo_text_view_get_lang (MOO_TEXT_VIEW (doc));
value = NULL != g_slist_find_custom (langs, moo_lang_id (lang),
(GCompareFunc) strcmp);
g_value_set_boolean (prop_value, value);
}
static GSList *
string_list_copy (GSList *list)
{
GSList *copy = NULL;
while (list)
{
copy = g_slist_prepend (copy, g_strdup (list->data));
list = list->next;
}
return g_slist_reverse (copy);
}
static void
string_list_free (gpointer list)
{
g_slist_foreach (list, (GFunc) g_free, NULL);
g_slist_free (list);
}
void
moo_edit_window_set_action_langs (const char *action_id,
const char *action_prop,
GSList *langs)
{
g_return_if_fail (action_id != NULL);
g_return_if_fail (action_prop != NULL);
if (langs)
moo_edit_window_add_action_check (action_id, action_prop,
check_action_langs,
string_list_copy (langs),
string_list_free);
else
moo_edit_window_remove_action_check (action_id, action_prop);
}
void
moo_edit_window_remove_action_check (const char *action_id,
const char *action_prop)

View File

@ -63,6 +63,9 @@ typedef void (*MooEditWindowCheckActionFunc) (MooAction *action,
GValue *prop_value,
gpointer data);
void moo_edit_window_set_action_langs (const char *action_id,
const char *action_prop,
GSList *langs);
void moo_edit_window_add_action_check (const char *action_id,
const char *action_prop,
MooEditWindowCheckActionFunc func,

View File

@ -62,6 +62,7 @@ class Plugin(moo.edit.Plugin):
icon_stock_id=moo.utils.STOCK_EXECUTE,
accel="<shift>F9",
callback=self.run_file)
moo.edit.window_set_action_langs("RunFile", "sensitive", ["python"])
self.add_ui("ToolsMenu", "RunFile")
def show_log_window(self, window):

View File

@ -521,6 +521,36 @@
(return-type "none")
)
(define-function window_set_action_langs
(c-name "moo_edit_window_set_action_langs")
(return-type "none")
(parameters
'("const-char*" "action_id")
'("const-char*" "action_prop")
'("GSList*" "langs")
)
)
(define-function window_add_action_check
(c-name "moo_edit_window_add_action_check")
(return-type "none")
(parameters
'("const-char*" "action_id")
'("const-char*" "action_prop")
'("MooEditWindowCheckActionFunc" "func")
'("gpointer" "data")
)
)
(define-function window_remove_action_check
(c-name "moo_edit_window_remove_action_check")
(return-type "none")
(parameters
'("const-char*" "action_id")
'("const-char*" "action_prop")
)
)
;; From mooindenter.h

View File

@ -312,3 +312,56 @@ _wrap_moo_edit_class_remove_action (G_GNUC_UNUSED PyObject *self, PyObject *args
return_None;
}
%%
override moo_edit_window_set_action_langs kwargs
static PyObject *
_wrap_moo_edit_window_set_action_langs (G_GNUC_UNUSED PyObject *self, PyObject *args, PyObject *kwargs)
{
GSList *langs = NULL;
PyObject *py_langs;
const char *action_id, *action_prop;
char *kwlist[] = {(char*) "action_id", (char*) "action_prop", (char*) "langs", NULL};
if (!PyArg_ParseTupleAndKeywords (args, kwargs, (char*) "ssO:window_set_action_langs",
kwlist, &action_id, &action_prop, &py_langs))
return NULL;
if (py_langs != Py_None)
{
int n_items, i;
char *lang_id;
py_langs = PySequence_Fast (py_langs, "langs must be a sequence or None");
if (!py_langs)
return NULL;
n_items = PySequence_Fast_GET_SIZE (py_langs);
for (i = 0; i < n_items; ++i)
{
PyObject *lang = PySequence_Fast_GET_ITEM (py_langs, i);
if (!PyString_Check (lang))
{
Py_DECREF (py_langs);
g_slist_foreach (langs, (GFunc) g_free, NULL);
g_slist_free (langs);
return_TypeErr ("langs must be a sequence of strings");
}
lang_id = moo_lang_id_from_name (PyString_AS_STRING (lang));
langs = g_slist_prepend (langs, lang_id);
}
langs = g_slist_reverse (langs);
}
moo_edit_window_set_action_langs (action_id, action_prop, langs);
Py_DECREF (py_langs);
g_slist_foreach (langs, (GFunc) g_free, NULL);
g_slist_free (langs);
return_None;
}