1 #if defined(HAVE_CONFIG_H) && !defined(GEANYPY_WINDOWS)
2 # include "config.h"
3 #endif
4
5 #include "geanypy.h"
6
7
8 static void
IndentPrefs_dealloc(IndentPrefs * self)9 IndentPrefs_dealloc(IndentPrefs *self)
10 {
11 self->ob_type->tp_free((PyObject *) self);
12 }
13
14
15 static int
IndentPrefs_init(IndentPrefs * self,PyObject * args,PyObject * kwds)16 IndentPrefs_init(IndentPrefs *self, PyObject *args, PyObject *kwds)
17 {
18 self->indent_prefs = NULL;
19 return 0;
20 }
21
22
23 static PyObject *
IndentPrefs_get_property(IndentPrefs * self,const gchar * prop_name)24 IndentPrefs_get_property(IndentPrefs *self, const gchar *prop_name)
25 {
26 g_return_val_if_fail(self != NULL, NULL);
27 g_return_val_if_fail(prop_name != NULL, NULL);
28
29 if (!self->indent_prefs)
30 {
31 PyErr_SetString(PyExc_RuntimeError,
32 "IndentPrefs instance not initialized properly");
33 return NULL;
34 }
35
36 if (g_str_equal(prop_name, "width"))
37 return PyInt_FromLong((glong) self->indent_prefs->width);
38 else if (g_str_equal(prop_name, "type"))
39 return PyInt_FromLong((glong) self->indent_prefs->type);
40 else if (g_str_equal(prop_name, "hard_tab_width"))
41 return PyInt_FromLong((glong) self->indent_prefs->hard_tab_width);
42
43 Py_RETURN_NONE;
44 }
45 GEANYPY_PROPS_READONLY(IndentPrefs);
46
47
48 static PyGetSetDef IndentPrefs_getseters[] = {
49 GEANYPY_GETSETDEF(IndentPrefs, "width", "Indent width in characters."),
50 GEANYPY_GETSETDEF(IndentPrefs, "type",
51 "Whether to use tabs, spaces, or both to indent."),
52 GEANYPY_GETSETDEF(IndentPrefs, "hard_tab_width",
53 "Width of a tab, but only when using INDENT_TYPE_BOTH."),
54 { NULL }
55 };
56
57
58 PyTypeObject IndentPrefsType = {
59 PyObject_HEAD_INIT(NULL)
60 0, /* ob_size */
61 "geany.editor.IndentPrefs", /* tp_name */
62 sizeof(IndentPrefs), /* tp_basicsize */
63 0, /* tp_itemsize */
64 (destructor) IndentPrefs_dealloc, /* tp_dealloc */
65 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* tp_print - tp_as_buffer */
66 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
67 "Wrapper around a GeanyIndentPrefs structure.", /* tp_doc */
68 0, 0, 0, 0, 0, 0, 0, 0, /* tp_traverse - tp_members */
69 IndentPrefs_getseters, /* tp_getset */
70 0, 0, 0, 0, 0, /* tp_base - tp_dictoffset */
71 (initproc) IndentPrefs_init, /* tp_init */
72 0, 0, /* tp_alloc - tp_new */
73 };
74
75
IndentPrefs_create_new_from_geany_indent_prefs(GeanyIndentPrefs * indent_prefs)76 IndentPrefs *IndentPrefs_create_new_from_geany_indent_prefs(GeanyIndentPrefs *indent_prefs)
77 {
78 IndentPrefs *self;
79 self = (IndentPrefs *) PyObject_CallObject((PyObject *) &IndentPrefsType, NULL);
80 self->indent_prefs = indent_prefs;
81 return self;
82 }
83