forked from raw-bacon/vi-xournalpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.lua
281 lines (214 loc) · 5.78 KB
/
api.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
-- line width
function clickVeryFine()
app.uiAction({["action"] = "ACTION_SIZE_VERY_FINE"})
end
function clickFine()
app.uiAction({["action"] = "ACTION_SIZE_FINE"})
end
function clickMedium()
app.uiAction({["action"] = "ACTION_SIZE_MEDIUM"})
end
function clickThick()
app.uiAction({["action"] = "ACTION_SIZE_THICK"})
end
function clickVeryThick()
app.uiAction({["action"] = "ACTION_SIZE_VERY_THICK"})
end
-- tools
function clickPen()
app.uiAction({["action"] = "ACTION_TOOL_PEN"})
end
function clickEraser()
app.uiAction({["action"] = "ACTION_TOOL_ERASER"})
end
function clickHighlighter()
app.uiAction({["action"] = "ACTION_TOOL_HIGHLIGHTER"})
end
function clickSelectRegion()
app.uiAction({["action"] = "ACTION_TOOL_SELECT_REGION"})
end
function clickSelectRectangle()
app.uiAction({["action"] = "ACTION_TOOL_SELECT_RECT"})
end
function clickSelectObject()
app.uiAction({["action"] = "ACTION_TOOL_SELECT_OBJECT"})
end
function clickTex()
app.uiAction({["action"] = "ACTION_TEX"})
end
function clickDelete()
app.uiAction({["action"] = "ACTION_DELETE"})
end
-- shapes
function clickRuler(enabled)
app.uiAction({["action"] = "ACTION_RULER", ["enabled"] = enabled})
end
function clickArrow(enabled)
app.uiAction({["action"] = "ACTION_TOOL_DRAW_ARROW", ["enabled"] = enabled})
end
function clickEllipse(enabled)
app.uiAction({["action"] = "ACTION_TOOL_DRAW_ELLIPSE", ["enabled"] = enabled})
end
function clickRectangle(enabled)
app.uiAction({["action"] = "ACTION_TOOL_DRAW_RECT", ["enabled"] = enabled})
end
function clickCoordSystem(enabled)
app.uiAction({["action"] = "ACTION_TOOL_DRAW_COORDINATE_SYSTEM", ["enabled"] = enabled})
end
function clickSpline(enabled)
app.uiAction({["action"] = "ACTION_TOOL_DRAW_SPLINE", ["enabled"] = enabled})
end
function clickFill(enabled)
app.uiAction({["action"] = "ACTION_TOOL_FILL", ["selection"] = true, ["enabled"] = enabled})
end
-- linestyle
function clickPlain()
app.uiAction({["action"] = "ACTION_TOOL_LINE_STYLE_PLAIN"})
end
function clickDotted()
app.uiAction({["action"] = "ACTION_TOOL_LINE_STYLE_DOT"})
end
function clickDashed()
app.uiAction({["action"] = "ACTION_TOOL_LINE_STYLE_DASH"})
end
function clickDashDotted()
app.uiAction({["action"] = "ACTION_TOOL_LINE_STYLE_DASH_DOT"})
end
-- color
function changeToolColor(color)
local result = app.changeToolColor({["color"] = color, ["selection"] = true})
-- change text tool color too, because (with the default template) the TEX tool also uses that color
app.changeToolColor({["color"] = color, ["tool"] = "TEXT"})
end
-- zooming
function clickZoomIn()
app.uiAction({["action"] = "ACTION_ZOOM_IN"})
end
function clickZoomOut()
app.uiAction({["action"] = "ACTION_ZOOM_OUT"})
end
function clickZoomFit()
app.uiAction({["action"] = "ACTION_ZOOM_FIT"})
end
-- page
function clickCopyPage()
app.sidebarAction("COPY")
end
function clickDeletePage()
app.uiAction({["action"] = "ACTION_DELETE_PAGE"})
end
function clickMoveUp()
app.sidebarAction("MOVE_UP")
end
function clickMoveDown()
app.sidebarAction("MOVE_DOWN")
end
function clickNewBefore()
app.sidebarAction("NEW_BEFORE")
end
function clickNewAfter()
app.sidebarAction("NEW_AFTER")
end
function clickNewLayer()
app.uiAction({["action"] = "ACTION_NEW_LAYER"})
end
function clickDeleteLayer()
app.uiAction({["action"] = "ACTION_DELETE_LAYER"})
end
-- navigation
function clickGoToFirstPage()
app.scrollToPage(1)
end
function clickGoToTop()
app.scrollToPos(0, 0, false)
end
function goToPage(page)
app.scrollToPage(page)
end
function goToPos(x, y)
app.scrollToPos(x, y)
end
function clickScrollPageDown()
app.scrollToPage(1, true)
end
function clickScrollPageUp()
app.scrollToPage(-1, true)
end
function clickGoToBottom()
local docStructure = app.getDocumentStructure()
local currentPage = docStructure["currentPage"]
local pageHeight = app.getDocumentStructure()["pages"][currentPage]["pageHeight"]
app.scrollToPos(0, pageHeight, false)
end
function clickGoToLastPage()
-- it gets clamped in applib_scrollToPage anyway.
app.scrollToPage(1000000000)
end
function currentPage()
return app.getDocumentStructure()["currentPage"]
end
function clickLayerDown()
app.uiAction({["action"] = "ACTION_GOTO_PREVIOUS_LAYER"})
end
function clickLayerUp()
app.uiAction({["action"] = "ACTION_GOTO_NEXT_LAYER"})
end
-- history
function clickUndo()
app.uiAction({["action"] = "ACTION_UNDO"})
end
function clickRedo()
app.uiAction({["action"] = "ACTION_REDO"})
end
-- files
function clickAnnotatePDF()
app.uiAction({["action"] = "ACTION_ANNOTATE_PDF"})
end
function clickExportAsPDF()
app.uiAction({["action"] = "ACTION_EXPORT_AS_PDF"})
end
function clickSave()
app.uiAction({["action"] = "ACTION_SAVE"})
end
function clickSaveAs()
app.uiAction({["action"] = "ACTION_SAVE_AS"})
end
function clickOpen()
app.uiAction({["action"] = "ACTION_OPEN"})
end
-- background
function clickRuledBG()
app.changeCurrentPageBackground("ruled");
end
function clickGraphBG()
app.changeCurrentPageBackground("graph");
end
function clickIsometricGraphBG()
app.changeCurrentPageBackground("isograph");
end
function clickDottedGraphBG()
app.changeCurrentPageBackground("dotted");
end
function clickIsometricDottedGraphBG()
app.changeCurrentPageBackground("isodotted");
end
function clickPlainBG()
app.changeCurrentPageBackground("plain");
end
-- snapping
function clickGridSnap(enabled)
-- it only toggles, ie. enabled = true / false is not used
app.uiAction({
["action"] = "ACTION_GRID_SNAPPING",
["group"] = "GROUP_GRID_SNAPPING",
["enabled"] = enabled
})
end
function clickRotationSnap(enabled)
-- it only toggles, ie. enabled = true / false is not used
app.uiAction({
["action"] = "ACTION_ROTATION_SNAPPING",
["group"] = "GROUP_SNAPPING",
["enabled"] = enabled
})
end