1 #if defined(HAVE_CONFIG_H) && !defined(GEANYPY_WINDOWS)
2 # include "config.h"
3 #endif
4 
5 #include "geanypy.h"
6 
7 
8 typedef struct
9 {
10 	PyObject_HEAD
11 	GeanySearchPrefs *search_prefs;
12 } SearchPrefs;
13 
14 
15 static void
SearchPrefs_dealloc(SearchPrefs * self)16 SearchPrefs_dealloc(SearchPrefs *self)
17 {
18 	g_return_if_fail(self != NULL);
19 	self->ob_type->tp_free((PyObject *) self);
20 }
21 
22 
23 static int
SearchPrefs_init(SearchPrefs * self)24 SearchPrefs_init(SearchPrefs *self)
25 {
26 	g_return_val_if_fail(self != NULL, -1);
27 	self->search_prefs = geany_data->search_prefs;
28 	return 0;
29 }
30 
31 
32 static PyObject *
SearchPrefs_get_property(SearchPrefs * self,const gchar * prop_name)33 SearchPrefs_get_property(SearchPrefs *self, const gchar *prop_name)
34 {
35 	g_return_val_if_fail(self != NULL, NULL);
36 	g_return_val_if_fail(prop_name != NULL, NULL);
37 
38 	if (!self->search_prefs)
39 	{
40 		PyErr_SetString(PyExc_RuntimeError,
41 			"SearchPrefs instance not initialized properly");
42 		return NULL;
43 	}
44 
45 	if (g_str_equal(prop_name, "use_current_word"))
46 	{
47 		if (self->search_prefs->use_current_word)
48 			Py_RETURN_TRUE;
49 		else
50 			Py_RETURN_FALSE;
51 	}
52 
53 	Py_RETURN_NONE;
54 }
55 GEANYPY_PROPS_READONLY(SearchPrefs);
56 
57 
58 static PyGetSetDef SearchPrefs_getseters[] = {
59 	GEANYPY_GETSETDEF(SearchPrefs, "use_current_word",
60 		"Use current word for default search text."),
61 	{ NULL }
62 };
63 
64 
65 static PyTypeObject SearchPrefsType = {
66 	PyObject_HEAD_INIT(NULL)
67 	0,											/* ob_size */
68 	"geany.search.SearchPrefs",							/* tp_name */
69 	sizeof(SearchPrefs),								/* tp_basicsize */
70 	0,											/* tp_itemsize */
71 	(destructor) SearchPrefs_dealloc,					/* tp_dealloc */
72 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,	/* tp_print - tp_as_buffer */
73 	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,	/* tp_flags */
74 	"Wrapper around a GeanySearchPrefs structure.",		/* tp_doc  */
75 	0, 0, 0, 0, 0, 0, 0, 0,						/* tp_traverse - tp_members */
76 	SearchPrefs_getseters,								/* tp_getset */
77 	0, 0, 0, 0, 0,								/* tp_base - tp_dictoffset */
78 	(initproc) SearchPrefs_init,						/* tp_init */
79 	0, 0,										/* tp_alloc - tp_new */
80 };
81 
82 
83 static PyObject *
Search_show_find_in_files_dialog(PyObject * self,PyObject * args,PyObject * kwargs)84 Search_show_find_in_files_dialog(PyObject *self, PyObject *args, PyObject *kwargs)
85 {
86 	gchar *dir = NULL;
87 	static gchar *kwlist[] = { "init_dir", NULL };
88 
89 	PyArg_ParseTupleAndKeywords(args, kwargs, "s", kwlist, &dir);
90 	search_show_find_in_files_dialog(dir);
91 
92 	Py_RETURN_NONE;
93 }
94 
95 
96 static PyMethodDef SearchPrefsModule_methods[] = {
97 	{ "show_find_in_files_dialog",
98 		(PyCFunction) Search_show_find_in_files_dialog,
99 		METH_KEYWORDS,
100 		"Shows the Find in Files dialog, taking an optional directory "
101 		"to search in for the dialog or if not specified then uses "
102 		"the current document's directory." },
103 	{ NULL }
104 };
105 
106 
initsearch(void)107 PyMODINIT_FUNC initsearch(void)
108 {
109 	PyObject *m;
110 
111 	SearchPrefsType.tp_new = PyType_GenericNew;
112 	if (PyType_Ready(&SearchPrefsType) < 0)
113 		return;
114 
115 	m = Py_InitModule3("search", SearchPrefsModule_methods,
116 			"Search preferences and information.");
117 
118 	Py_INCREF(&SearchPrefsType);
119 	PyModule_AddObject(m, "SearchPrefs", (PyObject *) &SearchPrefsType);
120 }
121