Commit 2493140e authored by Paolo Borelli's avatar Paolo Borelli Committed by Paolo Borelli

implement configure_dialog support for python plugins and make sure to

2006-01-06  Paolo Borelli  <pborelli@katamail.com>

	* gedit/gedit-plugin.[ch]:
	* gedit/gedit-python-plugin.c:

	implement configure_dialog support for python plugins and make
	sure to chain up to the default gedit-plugin methods if a python
	plugin doesn't override a method.
	Patch from Jesse Van Den Kieboom and Raphael Slinckx.
parent 75e61957
2006-01-06 Paolo Borelli <pborelli@katamail.com>
* gedit/gedit-plugin.[ch]:
* gedit/gedit-python-plugin.c:
implement configure_dialog support for python plugins and make
sure to chain up to the default gedit-plugin methods if a python
plugin doesn't override a method.
Patch from Jesse Van Den Kieboom and Raphael Slinckx.
2006-01-05 Paolo Maggi <paolo@gnome.org>
* gedit/gedit-view.c (gedit_view_class_init): added reset_searched_text
......
......@@ -48,6 +48,13 @@ create_configure_dialog (GeditPlugin *plugin)
return NULL;
}
static gboolean
is_configurable (GeditPlugin *plugin)
{
return (GEDIT_PLUGIN_GET_CLASS (plugin)->create_configure_dialog !=
create_configure_dialog);
}
static void
gedit_plugin_class_init (GeditPluginClass *klass)
{
......@@ -56,6 +63,7 @@ gedit_plugin_class_init (GeditPluginClass *klass)
klass->update_ui = dummy;
klass->create_configure_dialog = create_configure_dialog;
klass->is_configurable = is_configurable;
}
static void
......@@ -99,8 +107,7 @@ gedit_plugin_is_configurable (GeditPlugin *plugin)
{
g_return_val_if_fail (GEDIT_IS_PLUGIN (plugin), FALSE);
return (GEDIT_PLUGIN_GET_CLASS (plugin)->create_configure_dialog !=
create_configure_dialog);
return GEDIT_PLUGIN_GET_CLASS (plugin)->is_configurable (plugin);
}
GtkWidget *
......
......@@ -80,14 +80,19 @@ struct _GeditPluginClass
void (*update_ui) (GeditPlugin *plugin,
GeditWindow *window);
GtkWidget *(*create_configure_dialog)
GtkWidget *(*create_configure_dialog)
(GeditPlugin *plugin);
/* Plugins should not override this, it's handled automatically by
the GeditPluginClass */
gboolean (*is_configurable)
(GeditPlugin *plugin);
/* Padding for future expansion */
void (*_gedit_reserved1) (void);
void (*_gedit_reserved2) (void);
void (*_gedit_reserved3) (void);
void (*_gedit_reserved4) (void);
void (*_gedit_reserved4) (void);
};
/*
......
......@@ -31,52 +31,182 @@
static GObjectClass *parent_class;
static void
static PyObject *
call_python_method (GeditPythonObject *object,
GeditWindow *window,
gchar *method)
{
PyGILState_STATE state = pyg_gil_state_ensure ();
PyObject *py_ret = NULL;
if (!PyObject_HasAttrString (object->instance, method))
g_return_val_if_fail (PyObject_HasAttrString (object->instance, method), NULL);
if (window == NULL)
{
pyg_gil_state_release (state);
return;
py_ret = PyObject_CallMethod (object->instance,
method,
NULL);
}
py_ret = PyObject_CallMethod (object->instance,
method,
"(N)",
pygobject_new (G_OBJECT (window)));
else
{
py_ret = PyObject_CallMethod (object->instance,
method,
"(N)",
pygobject_new (G_OBJECT (window)));
}
if (!py_ret)
PyErr_Print ();
Py_XDECREF (py_ret);
pyg_gil_state_release (state);
return py_ret;
}
static gboolean
check_py_object_is_gtk_widget (PyObject *py_obj)
{
static PyTypeObject *_PyGtkWidget_Type = NULL;
if (_PyGtkWidget_Type == NULL)
{
PyObject *module;
if ((module = PyImport_ImportModule ("gtk")))
{
PyObject *moddict = PyModule_GetDict (module);
_PyGtkWidget_Type = (PyTypeObject *) PyDict_GetItemString (moddict, "Widget");
}
if (_PyGtkWidget_Type == NULL)
{
PyErr_SetString(PyExc_TypeError, "could not find python gtk widget type");
PyErr_Print();
return FALSE;
}
}
return PyObject_TypeCheck (py_obj, _PyGtkWidget_Type) ? TRUE : FALSE;
}
static void
impl_update_ui (GeditPlugin *plugin,
GeditWindow *window)
{
call_python_method ((GeditPythonObject *) plugin, window, "update_ui");
PyGILState_STATE state = pyg_gil_state_ensure ();
GeditPythonObject *object = (GeditPythonObject *)plugin;
if (PyObject_HasAttrString (object->instance, "update_ui"))
{
PyObject *py_ret = call_python_method (object, window, "update_ui");
if (py_ret)
{
Py_XDECREF (py_ret);
}
}
else
GEDIT_PLUGIN_CLASS (parent_class)->update_ui (plugin, window);
pyg_gil_state_release (state);
}
static void
impl_deactivate (GeditPlugin *plugin,
GeditWindow *window)
{
call_python_method ((GeditPythonObject *) plugin, window, "deactivate");
PyGILState_STATE state = pyg_gil_state_ensure ();
GeditPythonObject *object = (GeditPythonObject *)plugin;
if (PyObject_HasAttrString (object->instance, "deactivate"))
{
PyObject *py_ret = call_python_method (object, window, "deactivate");
if (py_ret)
{
Py_XDECREF (py_ret);
}
}
else
GEDIT_PLUGIN_CLASS (parent_class)->deactivate (plugin, window);
pyg_gil_state_release (state);
}
static void
impl_activate (GeditPlugin *plugin,
GeditWindow *window)
{
call_python_method ((GeditPythonObject *) plugin, window, "activate");
PyGILState_STATE state = pyg_gil_state_ensure ();
GeditPythonObject *object = (GeditPythonObject *)plugin;
if (PyObject_HasAttrString (object->instance, "activate"))
{
PyObject *py_ret = call_python_method (object, window, "activate");
if (py_ret)
{
Py_XDECREF (py_ret);
}
}
else
GEDIT_PLUGIN_CLASS (parent_class)->activate (plugin, window);
pyg_gil_state_release (state);
}
static GtkWidget *
impl_create_configure_dialog (GeditPlugin *plugin)
{
PyGILState_STATE state = pyg_gil_state_ensure ();
GeditPythonObject *object = (GeditPythonObject *)plugin;
GtkWidget *ret = NULL;
if (PyObject_HasAttrString (object->instance, "create_configure_dialog"))
{
PyObject *py_ret = call_python_method (object, NULL, "create_configure_dialog");
if (py_ret)
{
if (check_py_object_is_gtk_widget (py_ret))
{
ret = GTK_WIDGET (pygobject_get (py_ret));
g_object_ref (ret);
}
else
{
PyErr_SetString(PyExc_TypeError, "return value for create_configure_dialog is not a GtkWidget");
PyErr_Print();
}
Py_DECREF (py_ret);
}
}
else
ret = GEDIT_PLUGIN_CLASS (parent_class)->create_configure_dialog (plugin);
pyg_gil_state_release (state);
return ret;
}
static gboolean
impl_is_configurable (GeditPlugin *plugin)
{
PyGILState_STATE state = pyg_gil_state_ensure ();
GeditPythonObject *object = (GeditPythonObject *) plugin;
PyObject *dict = object->instance->ob_type->tp_dict;
gboolean result;
if (dict == NULL)
result = FALSE;
else if (!PyDict_Check(dict))
result = FALSE;
else
result = PyDict_GetItemString(dict, "create_configure_dialog") != NULL;
pyg_gil_state_release (state);
return result;
}
static void
gedit_python_object_init (GeditPythonObject *object)
{
......@@ -116,6 +246,8 @@ gedit_python_object_class_init (GeditPythonObjectClass *klass,
plugin_class->activate = impl_activate;
plugin_class->deactivate = impl_deactivate;
plugin_class->update_ui = impl_update_ui;
plugin_class->create_configure_dialog = impl_create_configure_dialog;
plugin_class->is_configurable = impl_is_configurable;
}
GType
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment