moo_edit_window_set_action_langs()
parent
ba649ef5f9
commit
68cf1cbb9b
|
@ -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
|
void
|
||||||
moo_edit_window_remove_action_check (const char *action_id,
|
moo_edit_window_remove_action_check (const char *action_id,
|
||||||
const char *action_prop)
|
const char *action_prop)
|
||||||
|
|
|
@ -63,6 +63,9 @@ typedef void (*MooEditWindowCheckActionFunc) (MooAction *action,
|
||||||
GValue *prop_value,
|
GValue *prop_value,
|
||||||
gpointer data);
|
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,
|
void moo_edit_window_add_action_check (const char *action_id,
|
||||||
const char *action_prop,
|
const char *action_prop,
|
||||||
MooEditWindowCheckActionFunc func,
|
MooEditWindowCheckActionFunc func,
|
||||||
|
|
|
@ -62,6 +62,7 @@ class Plugin(moo.edit.Plugin):
|
||||||
icon_stock_id=moo.utils.STOCK_EXECUTE,
|
icon_stock_id=moo.utils.STOCK_EXECUTE,
|
||||||
accel="<shift>F9",
|
accel="<shift>F9",
|
||||||
callback=self.run_file)
|
callback=self.run_file)
|
||||||
|
moo.edit.window_set_action_langs("RunFile", "sensitive", ["python"])
|
||||||
self.add_ui("ToolsMenu", "RunFile")
|
self.add_ui("ToolsMenu", "RunFile")
|
||||||
|
|
||||||
def show_log_window(self, window):
|
def show_log_window(self, window):
|
||||||
|
|
|
@ -521,6 +521,36 @@
|
||||||
(return-type "none")
|
(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
|
;; From mooindenter.h
|
||||||
|
|
||||||
|
|
|
@ -312,3 +312,56 @@ _wrap_moo_edit_class_remove_action (G_GNUC_UNUSED PyObject *self, PyObject *args
|
||||||
|
|
||||||
return_None;
|
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;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue