1 #if defined(HAVE_CONFIG_H) && !defined(GEANYPY_WINDOWS)
2 # include "config.h"
3 #endif
4
5 #include "geanypy.h"
6
7
8 static PyObject *
Navqueue_goto_line(PyObject * module,PyObject * args,PyObject * kwargs)9 Navqueue_goto_line(PyObject *module, PyObject *args, PyObject *kwargs)
10 {
11 gint line = 1;
12 PyObject *py_old = NULL, *py_new = NULL;
13 Document *py_doc_old, *py_doc_new;
14 GeanyDocument *old_doc, *new_doc;
15 static gchar *kwlist[] = { "old_doc", "new_doc", "line", NULL };
16
17 if (PyArg_ParseTupleAndKeywords(args, kwargs, "OOi", kwlist, &py_old,
18 &py_new, &line))
19 {
20 if (!py_old || py_old == Py_None)
21 old_doc = NULL;
22 else
23 {
24 py_doc_old = (Document *) py_old;
25 old_doc = py_doc_old->doc;
26 }
27
28 if (!py_new || py_new == Py_None)
29 Py_RETURN_NONE;
30 else
31 {
32 py_doc_new = (Document *) py_new;
33 new_doc = py_doc_new->doc;
34 }
35
36 if ( (old_doc != NULL && !DOC_VALID(old_doc)) || !DOC_VALID(new_doc) )
37 Py_RETURN_NONE;
38 if (navqueue_goto_line(old_doc, new_doc, line))
39 Py_RETURN_TRUE;
40 else
41 Py_RETURN_FALSE;
42 }
43
44 Py_RETURN_NONE;
45 }
46
47
48 #ifdef ENABLE_PRIVATE
49 static PyObject *
Navqueue_go_back(PyObject * module)50 Navqueue_go_back(PyObject *module)
51 {
52 navqueue_go_back();
53 Py_RETURN_NONE;
54 }
55
56
57 static PyObject *
Navqueue_go_forward(PyObject * module)58 Navqueue_go_forward(PyObject *module)
59 {
60 navqueue_go_forward();
61 Py_RETURN_NONE;
62 }
63 #endif
64
65
66 static
67 PyMethodDef NavqueueModule_methods[] = {
68 { "goto_line", (PyCFunction) Navqueue_goto_line, METH_KEYWORDS,
69 "Adds old file position and new file position to the navqueue, "
70 "then goes to the new position." },
71 #ifdef ENABLE_PRIVATE
72 { "go_back", (PyCFunction) Navqueue_go_back, METH_NOARGS,
73 "Navigate backwards." },
74 { "go_forward", (PyCFunction) Navqueue_go_forward, METH_NOARGS,
75 "Navigate forward." },
76 #endif
77 { NULL }
78 };
79
80
initnavqueue(void)81 PyMODINIT_FUNC initnavqueue(void)
82 {
83 Py_InitModule3("navqueue", NavqueueModule_methods, "Simple code navigation.");
84 }
85