1 /*
2 * This file is part of GNOME LaTeX.
3 *
4 * Copyright (C) 2017-2020 - Sébastien Wilmet <swilmet@gnome.org>
5 * Copyright (C) 2018 - Robert Griesel <r.griesel@gmail.com>
6 *
7 * GNOME LaTeX is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * GNOME LaTeX is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with GNOME LaTeX. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 /**
22 * SECTION:latex-commands
23 * @title: LaTeX commands
24 * @short_description: LaTeX menu, Math menu and Edit toolbar
25 */
26
27 #include "config.h"
28 #include "latexila-latex-commands.h"
29 #include <glib/gi18n.h>
30 #include "latexila-utils.h"
31 #include "latexila-view.h"
32
33 /* LaTeX: References */
34 static const AmtkActionInfoEntry action_info_entries_latex_references[] = {
35 { "win.latex-command-with-braces::label", NULL, "\\_label", NULL,
36 N_("Label") },
37 { "win.latex-command-with-braces::ref", NULL, "\\_ref", NULL,
38 N_("Reference to a label") },
39 { "win.latex-command-with-braces::pageref", NULL, "\\_pageref", NULL,
40 N_("Page reference to a label") },
41 { "win.latex-command-with-braces::index", NULL, "\\_index", NULL,
42 N_("Add a word to the index") },
43 { "win.latex-command-with-braces::footnote", NULL, "\\_footnote", NULL,
44 N_("Footnote") },
45 { "win.latex-command-with-braces::cite", NULL, "\\_cite", NULL,
46 N_("Reference to a bibliography item") },
47 { NULL }
48 };
49
50 /* LaTeX: character sizes */
51 static const AmtkActionInfoEntry action_info_entries_latex_character_sizes[] = {
52 { "win.latex-command-char-style::tiny", NULL, "_tiny", NULL, "tiny" },
53 { "win.latex-command-char-style::scriptsize", NULL, "_scriptsize", NULL, "scriptsize" },
54 { "win.latex-command-char-style::footnotesize", NULL, "_footnotesize", NULL, "footnotesize" },
55 { "win.latex-command-char-style::small", NULL, "s_mall", NULL, "small" },
56 { "win.latex-command-char-style::normalsize", NULL, "_normalsize", NULL, "normalsize" },
57 { "win.latex-command-char-style::large", NULL, "_large", NULL, "large" },
58 { "win.latex-command-char-style::Large", NULL, "L_arge", NULL, "Large" },
59 { "win.latex-command-char-style::LARGE", NULL, "LA_RGE", NULL, "LARGE" },
60 { "win.latex-command-char-style::huge", NULL, "_huge", NULL, "huge" },
61 { "win.latex-command-char-style::Huge", NULL, "H_uge", NULL, "Huge" },
62 { NULL }
63 };
64
65 /* LaTeX: Tabular */
66 static const AmtkActionInfoEntry action_info_entries_latex_tabular[] = {
67 { "win.latex-command-env-simple::tabbing", NULL, "\\begin{ta_bbing}", NULL,
68 N_("Tabbing — \\begin{tabbing}") },
69 { "win.latex-command-tabular-tabular", NULL, "\\begin{_tabular}", NULL,
70 N_("Tabular — \\begin{tabular}") },
71 { "win.latex-command-tabular-multicolumn", NULL, "\\_multicolumn", NULL,
72 N_("Multicolumn — \\multicolumn") },
73 { "win.latex-command-with-space::hline", NULL, "\\_hline", NULL,
74 N_("Horizontal line — \\hline") },
75 { "win.latex-command-with-space::vline", NULL, "\\_vline", NULL,
76 N_("Vertical line — \\vline") },
77 { "win.latex-command-tabular-cline", NULL, "\\_cline", NULL,
78 N_("Horizontal line (columns specified) — \\cline") },
79 { NULL }
80 };
81
82 /* LaTeX: Presentation */
83 static const AmtkActionInfoEntry action_info_entries_latex_presentation[] = {
84 { "win.latex-command-presentation-frame", NULL, "\\begin{frame}", NULL,
85 N_("Frame — \\begin{frame}") },
86 { "win.latex-command-presentation-block", NULL, "\\begin{block}", NULL,
87 N_("Block — \\begin{block}") },
88 { "win.latex-command-presentation-columns", NULL, "\\begin{columns}", NULL,
89 N_("Two columns — \\begin{columns}") },
90 { NULL }
91 };
92
93 /* LaTeX: Spacing */
94 static const AmtkActionInfoEntry action_info_entries_latex_spacing[] = {
95 { "win.latex-command-spacing-new-line", NULL, N_("New _Line"), NULL,
96 N_("New Line — \\\\") },
97 { "win.latex-command-with-newline::newpage", NULL, "\\new_page", NULL,
98 N_("New page — \\newpage") },
99 { "win.latex-command-with-newline::linebreak", NULL, "\\l_inebreak", NULL,
100 N_("Line break — \\linebreak") },
101 { "win.latex-command-with-newline::pagebreak", NULL, "\\p_agebreak", NULL,
102 N_("Page break — \\pagebreak") },
103 { "win.latex-command-with-space::bigskip", NULL, "\\_bigskip", NULL,
104 N_("Big skip — \\bigskip") },
105 { "win.latex-command-with-space::medskip", NULL, "\\_medskip", NULL,
106 N_("Medium skip — \\medskip") },
107 { "win.latex-command-with-braces::hspace", NULL, "\\_hspace", NULL,
108 N_("Horizontal space — \\hspace") },
109 { "win.latex-command-with-braces::vspace", NULL, "\\_vspace", NULL,
110 N_("Vertical space — \\vspace") },
111 { "win.latex-command-with-space::noindent", NULL, "\\_noindent", NULL,
112 N_("No paragraph indentation — \\noindent") },
113 { NULL }
114 };
115
116 /* LaTeX: International accents */
117 static const AmtkActionInfoEntry action_info_entries_latex_accents[] = {
118 { "win.latex-command-with-braces('\\'')", "accent0", "\\'", NULL, N_("Acute accent — \\'") },
119 { "win.latex-command-with-braces('`')", "accent1", "\\`", NULL, N_("Grave accent — \\`") },
120 { "win.latex-command-with-braces('^')", "accent2", "\\^", NULL, N_("Circumflex accent — \\^") },
121 { "win.latex-command-with-braces('\"')", "accent3", "\\\"", NULL, N_("Trema — \\\"") },
122 { "win.latex-command-with-braces('~')", "accent4", "\\~", NULL, N_("Tilde — \\~") },
123 { "win.latex-command-with-braces('=')", "accent5", "\\=", NULL, N_("Macron — \\=") },
124 { "win.latex-command-with-braces('.')", "accent6", "\\.", NULL, N_("Dot above — \\.") },
125 { "win.latex-command-with-braces('v')", "accent7", "\\v", NULL, N_("Caron — \\v") },
126 { "win.latex-command-with-braces('u')", "accent8", "\\u", NULL, N_("Breve — \\u") },
127 { "win.latex-command-with-braces('H')", "accent9", "\\H", NULL,
128 N_("Double acute accent — \\H") },
129 { "win.latex-command-with-braces('c')", "accent10", "\\c", NULL, N_("Cedilla — \\c") },
130 { "win.latex-command-with-braces('k')", "accent11", "\\k", NULL, N_("Ogonek — \\k") },
131 { "win.latex-command-with-braces('d')", "accent12", "\\d", NULL, N_("Dot below — \\d") },
132 { "win.latex-command-with-braces('b')", "accent13", "\\b", NULL, N_("Macron below — \\b") },
133 { "win.latex-command-with-braces('r')", "accent14", "\\r", NULL, N_("Ring — \\r") },
134 { "win.latex-command-with-braces('t')", "accent15", "\\t", NULL, N_("Tie — \\t") },
135 { NULL }
136 };
137
138 /* Math Environments */
139 static const AmtkActionInfoEntry action_info_entries_math_environments[] = {
140 { "win.math-command-env-normal", NULL, N_("_Mathematical Environment — $…$"),
141 "<Alt><Shift>M", N_("Mathematical Environment — $…$") },
142 { "win.math-command-env-centered", NULL, N_("_Centered Formula — \\[…\\]"),
143 "<Alt><Shift>E", N_("Centered Formula — \\[…\\]") },
144 { "win.latex-command-env-simple::equation", NULL,
145 N_("_Numbered Equation — \\begin{equation}"), NULL,
146 N_("Numbered Equation — \\begin{equation}") },
147 { "win.math-command-env-array", NULL, N_("_Array of Equations — \\begin{align*}"), NULL,
148 N_("Array of Equations — \\begin{align*}") },
149 { "win.latex-command-env-simple::align", NULL,
150 N_("Numbered Array of _Equations — \\begin{align}"), NULL,
151 N_("Numbered Array of Equations — \\begin{align}") },
152 { NULL }
153 };
154
155 /* Math functions */
156 static const AmtkActionInfoEntry action_info_entries_math_functions[] = {
157 { "win.latex-command-with-space::arccos", NULL, "\\arccos", NULL, NULL },
158 { "win.latex-command-with-space::arcsin", NULL, "\\arcsin", NULL, NULL },
159 { "win.latex-command-with-space::arctan", NULL, "\\arctan", NULL, NULL },
160 { "win.latex-command-with-space::cos", NULL, "\\cos", NULL, NULL },
161 { "win.latex-command-with-space::cosh", NULL, "\\cosh", NULL, NULL },
162 { "win.latex-command-with-space::cot", NULL, "\\cot", NULL, NULL },
163 { "win.latex-command-with-space::coth", NULL, "\\coth", NULL, NULL },
164 { "win.latex-command-with-space::csc", NULL, "\\csc", NULL, NULL },
165 { "win.latex-command-with-space::deg", NULL, "\\deg", NULL, NULL },
166 { "win.latex-command-with-space::det", NULL, "\\det", NULL, NULL },
167 { "win.latex-command-with-space::dim", NULL, "\\dim", NULL, NULL },
168 { "win.latex-command-with-space::exp", NULL, "\\exp", NULL, NULL },
169 { "win.latex-command-with-space::gcd", NULL, "\\gcd", NULL, NULL },
170 { "win.latex-command-with-space::hom", NULL, "\\hom", NULL, NULL },
171 { "win.latex-command-with-space::inf", NULL, "\\inf", NULL, NULL },
172 { "win.latex-command-with-space::ker", NULL, "\\ker", NULL, NULL },
173 { "win.latex-command-with-space::lg", NULL, "\\lg", NULL, NULL },
174 { "win.latex-command-with-space::lim", NULL, "\\lim", NULL, NULL },
175 { "win.latex-command-with-space::liminf", NULL, "\\liminf", NULL, NULL },
176 { "win.latex-command-with-space::limsup", NULL, "\\limsup", NULL, NULL },
177 { "win.latex-command-with-space::ln", NULL, "\\ln", NULL, NULL },
178 { "win.latex-command-with-space::log", NULL, "\\log", NULL, NULL },
179 { "win.latex-command-with-space::max", NULL, "\\max", NULL, NULL },
180 { "win.latex-command-with-space::min", NULL, "\\min", NULL, NULL },
181 { "win.latex-command-with-space::sec", NULL, "\\sec", NULL, NULL },
182 { "win.latex-command-with-space::sin", NULL, "\\sin", NULL, NULL },
183 { "win.latex-command-with-space::sinh", NULL, "\\sinh", NULL, NULL },
184 { "win.latex-command-with-space::sup", NULL, "\\sup", NULL, NULL },
185 { "win.latex-command-with-space::tan", NULL, "\\tan", NULL, NULL },
186 { "win.latex-command-with-space::tanh", NULL, "\\tanh", NULL, NULL },
187 { NULL }
188 };
189
190 /* Math Font Styles */
191 static const AmtkActionInfoEntry action_info_entries_math_font_styles[] = {
192 { "win.latex-command-with-braces::mathrm", "roman", "\\math_rm", NULL,
193 N_("Roman — \\mathrm") },
194 { "win.latex-command-with-braces::mathit", "italic", "\\math_it", NULL,
195 N_("Italic — \\mathit") },
196 { "win.latex-command-with-braces::mathbf", "bold", "\\math_bf", NULL,
197 N_("Bold — \\mathbf") },
198 { "win.latex-command-with-braces::mathsf", "sans_serif", "\\math_sf", NULL,
199 N_("Sans Serif — \\mathsf") },
200 { "win.latex-command-with-braces::mathtt", "typewriter", "\\math_tt", NULL,
201 N_("Typewriter — \\mathtt") },
202 { "win.latex-command-with-braces::mathcal", "mathcal", "\\math_cal", NULL,
203 N_("Calligraphic — \\mathcal") },
204 { "win.latex-command-with-braces::mathbb", "blackboard", "\\_mathbb", NULL,
205 N_("Blackboard (uppercase only) — \\mathbb (amsfonts package)") },
206 { "win.latex-command-with-braces::mathfrak", "mathfrak", "\\math_frak", NULL,
207 N_("Euler Fraktur — \\mathfrak (amsfonts package)") },
208 { NULL }
209 };
210
211 /* Math Accents */
212 static const AmtkActionInfoEntry action_info_entries_math_accents[] = {
213 { "win.latex-command-with-braces::acute", "mathaccent0", "\\_acute", NULL, NULL },
214 { "win.latex-command-with-braces::grave", "mathaccent1", "\\_grave", NULL, NULL },
215 { "win.latex-command-with-braces::tilde", "mathaccent2", "\\_tilde", NULL, NULL },
216 { "win.latex-command-with-braces::bar", "mathaccent3", "\\_bar", NULL, NULL },
217 { "win.latex-command-with-braces::vec", "mathaccent4", "\\_vec", NULL, NULL },
218 { "win.latex-command-with-braces::hat", "mathaccent5", "\\_hat", NULL, NULL },
219 { "win.latex-command-with-braces::check", "mathaccent6", "\\_check", NULL, NULL },
220 { "win.latex-command-with-braces::breve", "mathaccent7", "\\b_reve", NULL, NULL },
221 { "win.latex-command-with-braces::dot", "mathaccent8", "\\_dot", NULL, NULL },
222 { "win.latex-command-with-braces::ddot", "mathaccent9", "\\dd_ot", NULL, NULL },
223 { "win.latex-command-with-braces::mathring", "mathaccent10", "\\_mathring", NULL, NULL },
224 { NULL }
225 };
226
227 /* Math Spaces */
228 static const AmtkActionInfoEntry action_info_entries_math_spaces[] = {
229 { "win.math-command-spaces-small", NULL, N_("_Small"), NULL, N_("Small — \\,") },
230 { "win.math-command-spaces-medium", NULL, N_("_Medium"), NULL, N_("Medium — \\:") },
231 { "win.math-command-spaces-large", NULL, N_("_Large"), NULL, N_("Large — \\;") },
232 { "win.latex-command-with-space::quad", NULL, "\\_quad", NULL, NULL },
233 { "win.latex-command-with-space::qquad", NULL, "\\qqu_ad", NULL, NULL },
234 { NULL }
235 };
236
237 /* Math: Left Delimiters */
238 static const AmtkActionInfoEntry action_info_entries_math_left_delimiters[] = {
239 { "win.math-command-delimiter-left1", NULL, N_("left ("), NULL, NULL },
240 { "win.math-command-delimiter-left2", NULL, N_("left ["), NULL, NULL },
241 { "win.math-command-delimiter-left3", NULL, N_("left { "), NULL, NULL },
242 { "win.math-command-delimiter-left4", NULL, N_("left <"), NULL, NULL },
243 { "win.math-command-delimiter-left5", NULL, N_("left )"), NULL, NULL },
244 { "win.math-command-delimiter-left6", NULL, N_("left ]"), NULL, NULL },
245 { "win.math-command-delimiter-left7", NULL, N_("left }"), NULL, NULL },
246 { "win.math-command-delimiter-left8", NULL, N_("left >"), NULL, NULL },
247 { "win.math-command-delimiter-left9", NULL, N_("left ."), NULL, NULL },
248 { NULL }
249 };
250
251 /* Math: Right Delimiters */
252 static const AmtkActionInfoEntry action_info_entries_math_right_delimiters[] = {
253 { "win.math-command-delimiter-right1", NULL, N_("right )"), NULL, NULL },
254 { "win.math-command-delimiter-right2", NULL, N_("right ]"), NULL, NULL },
255 { "win.math-command-delimiter-right3", NULL, N_("right }"), NULL, NULL },
256 { "win.math-command-delimiter-right4", NULL, N_("right >"), NULL, NULL },
257 { "win.math-command-delimiter-right5", NULL, N_("right ("), NULL, NULL },
258 { "win.math-command-delimiter-right6", NULL, N_("right ["), NULL, NULL },
259 { "win.math-command-delimiter-right7", NULL, N_("right { "), NULL, NULL },
260 { "win.math-command-delimiter-right8", NULL, N_("right <"), NULL, NULL },
261 { "win.math-command-delimiter-right9", NULL, N_("right ."), NULL, NULL },
262 { NULL }
263 };
264
265 /**
266 * latexila_latex_commands_add_action_infos:
267 * @gtk_app: the #GtkApplication instance.
268 *
269 * Creates the #AmtkActionInfo's related to the LaTeX and Math menus, and add
270 * them to the #AmtkActionInfoStore as returned by
271 * tepl_application_get_app_action_info_store().
272 */
273 void
latexila_latex_commands_add_action_infos(GtkApplication * gtk_app)274 latexila_latex_commands_add_action_infos (GtkApplication *gtk_app)
275 {
276 TeplApplication *tepl_app;
277 AmtkActionInfoStore *store;
278
279 const AmtkActionInfoEntry entries[] =
280 {
281 /* action, icon, label, accel, tooltip */
282
283 { "no-gaction-latex-sectioning", "sectioning", N_("_Sectioning") },
284 { "no-gaction-latex-references", "references", N_("_References") },
285 { "no-gaction-latex-environments", "format-justify-center", N_("_Environments") },
286 { "no-gaction-latex-list-environments", "list-itemize", N_("_List Environments") },
287 { "no-gaction-latex-character-size", "character-size", N_("_Characters Sizes") },
288 { "no-gaction-latex-font-styles", "bold", N_("_Font Styles") },
289 { "no-gaction-latex-font-family", NULL, N_("_Font Family") },
290 { "no-gaction-latex-font-series", NULL, N_("F_ont Series") },
291 { "no-gaction-latex-font-shape", NULL, N_("Fo_nt Shape") },
292 { "no-gaction-latex-tabular", "table", N_("_Tabular") },
293 { "no-gaction-latex-presentation", "x-office-presentation", N_("_Presentation") },
294 { "no-gaction-latex-spacing", NULL, N_("_Spacing") },
295 { "no-gaction-latex-accents", NULL, N_("International _Accents") },
296 { "no-gaction-latex-misc", NULL, N_("_Misc") },
297
298 { "no-gaction-math-environments", NULL, N_("_Math Environments") },
299 { "no-gaction-math-functions", NULL, N_("Math _Functions") },
300 { "no-gaction-math-font-styles", NULL, N_("Math Font _Styles") },
301 { "no-gaction-math-accents", NULL, N_("Math _Accents") },
302 { "no-gaction-math-spaces", NULL, N_("Math _Spaces") },
303 { "no-gaction-math-left-delimiters", "delimiters-left", N_("_Left Delimiters") },
304 { "no-gaction-math-right-delimiters", "delimiters-right", N_("Right _Delimiters") },
305
306 /* LaTeX: Sectioning */
307
308 { "win.latex-command-with-braces::part", NULL, "\\_part", NULL,
309 N_("Part") },
310 { "win.latex-command-with-braces::chapter", NULL, "\\_chapter", NULL,
311 N_("Chapter") },
312 { "win.latex-command-with-braces::section", NULL, "\\_section", NULL,
313 N_("Section") },
314 { "win.latex-command-with-braces::subsection", NULL, "\\s_ubsection", NULL,
315 N_("Sub-section") },
316 { "win.latex-command-with-braces::subsubsection", NULL, "\\su_bsubsection", NULL,
317 N_("Sub-sub-section") },
318 { "win.latex-command-with-braces::paragraph", NULL, "\\p_aragraph", NULL,
319 N_("Paragraph") },
320 { "win.latex-command-with-braces::subparagraph", NULL, "\\subpa_ragraph", NULL,
321 N_("Sub-paragraph") },
322
323 /* LaTeX: Environments */
324
325 { "win.latex-command-env-simple::center", "format-justify-center", "\\begin{_center}", NULL,
326 N_("Center — \\begin{center}") },
327 { "win.latex-command-env-simple::flushleft", "format-justify-left", "\\begin{flush_left}", NULL,
328 N_("Align Left — \\begin{flushleft}") },
329 { "win.latex-command-env-simple::flushright", "format-justify-right", "\\begin{flush_right}", NULL,
330 N_("Align Right — \\begin{flushright}") },
331 { "win.latex-command-env-figure", "image-x-generic", "\\begin{_figure}", NULL,
332 N_ ("Figure — \\begin{figure}") },
333 { "win.latex-command-env-table", "table", "\\begin{_table}", NULL,
334 N_("Table — \\begin{table}") },
335 { "win.latex-command-env-simple::quote", NULL, "\\begin{_quote}", NULL,
336 N_("Quote — \\begin{quote}") },
337 { "win.latex-command-env-simple::quotation", NULL, "\\begin{qu_otation}", NULL,
338 N_("Quotation — \\begin{quotation}") },
339 { "win.latex-command-env-simple::verse", NULL, "\\begin{_verse}", NULL,
340 N_("Verse — \\begin{verse}") },
341 { "win.latex-command-env-simple::verbatim", NULL, "\\begin{ver_batim}", NULL,
342 N_("Verbatim — \\begin{verbatim}") },
343 { "win.latex-command-env-simple::minipage", NULL, "\\begin{_minipage}", NULL,
344 N_("Minipage — \\begin{minipage}") },
345 { "win.latex-command-env-simple::titlepage", NULL, "\\begin{titlepage}", NULL,
346 N_("Title page — \\begin{titlepage}") },
347
348 /* LaTeX: list environments */
349
350 { "win.latex-command-list-env-simple::itemize", "list-itemize", "\\begin{_itemize}", NULL,
351 N_("Bulleted List — \\begin{itemize}") },
352 { "win.latex-command-list-env-simple::enumerate", "list-enumerate", "\\begin{_enumerate}", NULL,
353 N_("Enumeration — \\begin{enumerate}") },
354 { "win.latex-command-list-env-description", "list-description", "\\begin{_description}", NULL,
355 N_("Description — \\begin{description}") },
356 { "win.latex-command-list-env-list", NULL, "\\begin{_list}", NULL,
357 N_("Custom list — \\begin{list}") },
358 { "win.latex-command-with-space::item", "list-item", "\\i_tem", "<Alt><Shift>H",
359 N_("List item — \\item") },
360
361 /* LaTeX: font styles */
362
363 { "win.latex-command-with-braces::textbf", "bold", "\\text_bf", "<Control>B",
364 N_("Bold — \\textbf") },
365 { "win.latex-command-with-braces::textit", "italic", "\\text_it", "<Control>I",
366 N_("Italic — \\textit") },
367 { "win.latex-command-with-braces::texttt", "typewriter", "\\text_tt", "<Alt><Shift>T",
368 N_("Typewriter — \\texttt") },
369 { "win.latex-command-with-braces::textsl", "slanted", "\\text_sl", "<Alt><Shift>S",
370 N_("Slanted — \\textsl") },
371 { "win.latex-command-with-braces::textsc", "small_caps", "\\texts_c", "<Alt><Shift>C",
372 N_("Small Capitals — \\textsc") },
373 { "win.latex-command-with-braces::textsf", "sans_serif", "\\texts_f", NULL,
374 N_("Sans Serif — \\textsf") },
375 { "win.latex-command-with-braces::emph", NULL, "\\_emph", "<Control>E",
376 N_("Emphasized — \\emph") },
377 { "win.latex-command-with-braces::underline", "underline", "\\_underline", "<Control>U",
378 N_("Underline — \\underline") },
379
380 { "win.latex-command-char-style::rmfamily", "roman", "\\_rmfamily", NULL,
381 N_("Roman — \\rmfamily") },
382 { "win.latex-command-char-style::sffamily", "sans_serif", "\\_sffamily", NULL,
383 N_("Sans Serif — \\sffamily") },
384 { "win.latex-command-char-style::ttfamily", "typewriter", "\\_ttfamily", NULL,
385 N_("Monospace — \\ttfamily") },
386
387 { "win.latex-command-char-style::mdseries", "roman", "\\_mdseries", NULL,
388 N_("Medium — \\mdseries") },
389 { "win.latex-command-char-style::bfseries", "bold", "\\_bfseries", NULL,
390 N_("Bold — \\bfseries") },
391
392 { "win.latex-command-char-style::upshape", "roman", "\\_upshape", NULL,
393 N_("Upright — \\upshape") },
394 { "win.latex-command-char-style::itshape", "italic", "\\_itshape", NULL,
395 N_("Italic — \\itshape") },
396 { "win.latex-command-char-style::slshape", "slanted", "\\_slshape", NULL,
397 N_("Slanted — \\slshape") },
398 { "win.latex-command-char-style::scshape", "small_caps", "\\s_cshape", NULL,
399 N_("Small Capitals — \\scshape") },
400
401 /* LaTeX: Misc */
402
403 { "win.latex-command-with-braces::documentclass", NULL, "\\_documentclass", NULL,
404 N_("Document class — \\documentclass") },
405 { "win.latex-command-with-braces::usepackage", NULL, "\\_usepackage", NULL,
406 N_("Use package — \\usepackage") },
407 { "win.latex-command-ams-packages", NULL, N_("_AMS packages"), NULL,
408 N_("AMS packages") },
409 { "win.latex-command-with-braces::author", NULL, "\\au_thor", NULL, N_("Author — \\author") },
410 { "win.latex-command-with-braces::title", NULL, "\\t_itle", NULL, N_("Title — \\title") },
411 { "win.latex-command-env-simple::document", NULL, "\\begin{d_ocument}", NULL,
412 N_("Content of the document — \\begin{document}") },
413 { "win.latex-command-simple::maketitle", NULL, "\\_maketitle", NULL,
414 N_("Make title — \\maketitle") },
415 { "win.latex-command-simple::tableofcontents", NULL, "\\tableof_contents", NULL,
416 N_("Table of contents — \\tableofcontents") },
417 { "win.latex-command-env-simple::abstract", NULL, "\\begin{abst_ract}", NULL,
418 N_("Abstract — \\begin{abstract}") },
419 { "win.latex-command-with-braces::includegraphics", NULL, "\\include_graphics", NULL,
420 N_("Include an image (graphicx package) — \\includegraphics") },
421 { "win.latex-command-with-braces::input", NULL, "\\_input", NULL,
422 N_("Include a file — \\input") },
423
424 /* Math misc */
425
426 { "win.math-command-misc-superscript", "math-superscript", N_("_Superscript — ^{}"), NULL,
427 N_("Superscript — ^{}") },
428 { "win.math-command-misc-subscript", "math-subscript", N_("Su_bscript — __{}"), NULL,
429 N_("Subscript — _{}") },
430 { "win.math-command-misc-frac", "math-frac", N_("_Fraction — \\frac{}{}"), "<Alt><Shift>F",
431 N_("Fraction — \\frac{}{}") },
432 { "win.latex-command-with-braces::sqrt", "math-square-root", N_("Square _Root — \\sqrt{}"), NULL,
433 N_("Square Root — \\sqrt{}") },
434 { "win.math-command-misc-nth-root", "math-nth-root", N_("_N-th Root — \\sqrt[]{}"), NULL,
435 N_("N-th Root — \\sqrt[]{}") },
436 };
437
438 g_return_if_fail (GTK_IS_APPLICATION (gtk_app));
439
440 tepl_app = tepl_application_get_from_gtk_application (gtk_app);
441 store = tepl_application_get_app_action_info_store (tepl_app);
442
443 amtk_action_info_store_add_entries (store, entries, G_N_ELEMENTS (entries), GETTEXT_PACKAGE);
444
445 amtk_action_info_store_add_entries (store, action_info_entries_latex_references, -1, GETTEXT_PACKAGE);
446 amtk_action_info_store_add_entries (store, action_info_entries_latex_character_sizes, -1, GETTEXT_PACKAGE);
447 amtk_action_info_store_add_entries (store, action_info_entries_latex_tabular, -1, GETTEXT_PACKAGE);
448 amtk_action_info_store_add_entries (store, action_info_entries_latex_presentation, -1, GETTEXT_PACKAGE);
449 amtk_action_info_store_add_entries (store, action_info_entries_latex_spacing, -1, GETTEXT_PACKAGE);
450 amtk_action_info_store_add_entries (store, action_info_entries_latex_accents, -1, GETTEXT_PACKAGE);
451 amtk_action_info_store_add_entries (store, action_info_entries_math_environments, -1, GETTEXT_PACKAGE);
452 amtk_action_info_store_add_entries (store, action_info_entries_math_functions, -1, GETTEXT_PACKAGE);
453 amtk_action_info_store_add_entries (store, action_info_entries_math_font_styles, -1, GETTEXT_PACKAGE);
454 amtk_action_info_store_add_entries (store, action_info_entries_math_accents, -1, GETTEXT_PACKAGE);
455 amtk_action_info_store_add_entries (store, action_info_entries_math_spaces, -1, GETTEXT_PACKAGE);
456 amtk_action_info_store_add_entries (store, action_info_entries_math_left_delimiters, -1, GETTEXT_PACKAGE);
457 amtk_action_info_store_add_entries (store, action_info_entries_math_right_delimiters, -1, GETTEXT_PACKAGE);
458 }
459
460 /* Util functions */
461
462 static void
insert_text(TeplApplicationWindow * tepl_window,const gchar * text_before,const gchar * text_after,const gchar * text_if_no_selection)463 insert_text (TeplApplicationWindow *tepl_window,
464 const gchar *text_before,
465 const gchar *text_after,
466 const gchar *text_if_no_selection)
467 {
468 TeplView *view;
469 GtkTextBuffer *buffer;
470 GtkTextIter selection_start;
471 GtkTextIter selection_end;
472 gboolean has_selection;
473 gchar *text_before_with_indent;
474 gchar *text_after_with_indent;
475
476 g_return_if_fail (TEPL_IS_APPLICATION_WINDOW (tepl_window));
477 g_return_if_fail (text_before != NULL);
478 g_return_if_fail (text_after != NULL);
479
480 view = tepl_tab_group_get_active_view (TEPL_TAB_GROUP (tepl_window));
481 g_return_if_fail (view != NULL);
482
483 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
484
485 has_selection = gtk_text_buffer_get_selection_bounds (buffer,
486 &selection_start,
487 &selection_end);
488
489 /* Take into account the current indentation. */
490 {
491 gchar *current_indent;
492 gchar *newline_replacement;
493
494 current_indent = tepl_iter_get_line_indentation (&selection_start);
495 newline_replacement = g_strdup_printf ("\n%s", current_indent);
496
497 text_before_with_indent = tepl_utils_str_replace (text_before, "\n", newline_replacement);
498 text_after_with_indent = tepl_utils_str_replace (text_after, "\n", newline_replacement);
499
500 g_free (current_indent);
501 g_free (newline_replacement);
502 }
503
504 gtk_text_buffer_begin_user_action (buffer);
505
506 /* Insert around the selected text.
507 * Move the cursor to the end.
508 */
509 if (has_selection)
510 {
511 GtkTextMark *end_mark;
512 GtkTextIter end_iter;
513
514 end_mark = gtk_text_buffer_create_mark (buffer, NULL, &selection_end, FALSE);
515
516 gtk_text_buffer_insert (buffer, &selection_start, text_before_with_indent, -1);
517
518 gtk_text_buffer_get_iter_at_mark (buffer, &end_iter, end_mark);
519 gtk_text_buffer_delete_mark (buffer, end_mark);
520
521 gtk_text_buffer_insert (buffer, &end_iter, text_after_with_indent, -1);
522 gtk_text_buffer_place_cursor (buffer, &end_iter);
523 }
524 /* No selection */
525 else if (text_if_no_selection != NULL)
526 {
527 gtk_text_buffer_insert_at_cursor (buffer, text_if_no_selection, -1);
528 }
529 /* No selection, move the cursor between the two inserted chunks. */
530 else
531 {
532 GtkTextIter between_iter;
533 GtkTextMark *between_mark;
534
535 gtk_text_buffer_insert_at_cursor (buffer, text_before_with_indent, -1);
536
537 gtk_text_buffer_get_iter_at_mark (buffer,
538 &between_iter,
539 gtk_text_buffer_get_insert (buffer));
540 between_mark = gtk_text_buffer_create_mark (buffer, NULL, &between_iter, TRUE);
541
542 gtk_text_buffer_insert_at_cursor (buffer, text_after_with_indent, -1);
543
544 gtk_text_buffer_get_iter_at_mark (buffer, &between_iter, between_mark);
545 gtk_text_buffer_delete_mark (buffer, between_mark);
546 gtk_text_buffer_place_cursor (buffer, &between_iter);
547 }
548
549 gtk_text_buffer_end_user_action (buffer);
550
551 gtk_widget_grab_focus (GTK_WIDGET (view));
552
553 g_free (text_before_with_indent);
554 g_free (text_after_with_indent);
555 }
556
557 static gchar *
get_indentation(TeplApplicationWindow * tepl_window)558 get_indentation (TeplApplicationWindow *tepl_window)
559 {
560 TeplView *view;
561
562 view = tepl_tab_group_get_active_view (TEPL_TAB_GROUP (tepl_window));
563 g_return_val_if_fail (view != NULL, NULL);
564
565 return latexila_view_get_indentation_style (GTK_SOURCE_VIEW (view));
566 }
567
568 /* When it doesn't make sense to have the selected text between @text_before and
569 * @text_after when calling insert_text(), call this function first.
570 */
571 static void
deselect_text(TeplApplicationWindow * tepl_window)572 deselect_text (TeplApplicationWindow *tepl_window)
573 {
574 TeplBuffer *tepl_buffer;
575 GtkTextBuffer *gtk_buffer;
576 GtkTextIter selection_start;
577 GtkTextIter selection_end;
578
579 tepl_buffer = tepl_tab_group_get_active_buffer (TEPL_TAB_GROUP (tepl_window));
580 g_return_if_fail (tepl_buffer != NULL);
581
582 gtk_buffer = GTK_TEXT_BUFFER (tepl_buffer);
583
584 gtk_text_buffer_get_selection_bounds (gtk_buffer,
585 &selection_start,
586 &selection_end);
587
588 /* Always place cursor at beginning of selection, to have more predictable
589 * results, instead of placing the cursor at the insert mark.
590 */
591 gtk_text_buffer_place_cursor (gtk_buffer, &selection_start);
592 }
593
594 /* GActions implementation */
595
596 static void
latex_command_simple_cb(GSimpleAction * action,GVariant * parameter,gpointer user_data)597 latex_command_simple_cb (GSimpleAction *action,
598 GVariant *parameter,
599 gpointer user_data)
600 {
601 TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
602 const gchar *command;
603 gchar *text_before;
604
605 command = g_variant_get_string (parameter, NULL);
606 text_before = g_strdup_printf ("\\%s", command);
607
608 insert_text (tepl_window, text_before, "", NULL);
609
610 g_free (text_before);
611 }
612
613 static void
latex_command_with_braces_cb(GSimpleAction * action,GVariant * parameter,gpointer user_data)614 latex_command_with_braces_cb (GSimpleAction *action,
615 GVariant *parameter,
616 gpointer user_data)
617 {
618 TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
619 const gchar *command;
620 gchar *text_before;
621
622 command = g_variant_get_string (parameter, NULL);
623 text_before = g_strdup_printf ("\\%s{", command);
624
625 insert_text (tepl_window, text_before, "}", NULL);
626
627 g_free (text_before);
628 }
629
630 static void
latex_command_with_space_cb(GSimpleAction * action,GVariant * parameter,gpointer user_data)631 latex_command_with_space_cb (GSimpleAction *action,
632 GVariant *parameter,
633 gpointer user_data)
634 {
635 TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
636 const gchar *command;
637 gchar *text_before;
638
639 command = g_variant_get_string (parameter, NULL);
640 text_before = g_strdup_printf ("\\%s ", command);
641
642 insert_text (tepl_window, text_before, "", NULL);
643
644 g_free (text_before);
645 }
646
647 static void
latex_command_with_newline_cb(GSimpleAction * action,GVariant * parameter,gpointer user_data)648 latex_command_with_newline_cb (GSimpleAction *action,
649 GVariant *parameter,
650 gpointer user_data)
651 {
652 TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
653 const gchar *command;
654 gchar *text_before;
655
656 command = g_variant_get_string (parameter, NULL);
657 text_before = g_strdup_printf ("\\%s\n", command);
658
659 insert_text (tepl_window, text_before, "", NULL);
660
661 g_free (text_before);
662 }
663
664 static void
latex_command_env_simple_cb(GSimpleAction * action,GVariant * parameter,gpointer user_data)665 latex_command_env_simple_cb (GSimpleAction *action,
666 GVariant *parameter,
667 gpointer user_data)
668 {
669 TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
670 const gchar *environment;
671 gchar *text_before;
672 gchar *text_after;
673
674 environment = g_variant_get_string (parameter, NULL);
675 text_before = g_strdup_printf ("\\begin{%s}\n", environment);
676 text_after = g_strdup_printf ("\n\\end{%s}", environment);
677
678 insert_text (tepl_window, text_before, text_after, NULL);
679
680 g_free (text_before);
681 g_free (text_after);
682 }
683
684 static void
latex_command_env_figure_cb(GSimpleAction * action,GVariant * parameter,gpointer user_data)685 latex_command_env_figure_cb (GSimpleAction *action,
686 GVariant *parameter,
687 gpointer user_data)
688 {
689 TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
690 gchar *indent;
691 gchar *text_before;
692 gchar *text_after;
693
694 indent = get_indentation (tepl_window);
695
696 text_before = g_strdup_printf ("\\begin{figure}\n"
697 "%s\\begin{center}\n"
698 "%s%s\\includegraphics{",
699 indent,
700 indent, indent);
701
702 text_after = g_strdup_printf ("}\n"
703 "%s%s\\caption{}\n"
704 "%s%s\\label{fig:}\n"
705 "%s\\end{center}\n"
706 "\\end{figure}",
707 indent, indent,
708 indent, indent,
709 indent);
710
711 deselect_text (tepl_window);
712 insert_text (tepl_window, text_before, text_after, NULL);
713
714 g_free (indent);
715 g_free (text_before);
716 g_free (text_after);
717 }
718
719 static void
latex_command_env_table_cb(GSimpleAction * action,GVariant * parameter,gpointer user_data)720 latex_command_env_table_cb (GSimpleAction *action,
721 GVariant *parameter,
722 gpointer user_data)
723 {
724 TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
725 gchar *indent;
726 gchar *text_before;
727 gchar *text_after;
728
729 indent = get_indentation (tepl_window);
730
731 text_before = g_strdup_printf ("\\begin{table}\n"
732 "%s\\caption{",
733 indent);
734
735 text_after = g_strdup_printf ("}\n"
736 "%s\\label{tab:}\n"
737 "\n"
738 "%s\\begin{center}\n"
739 "%s%s\\begin{tabular}{cc}\n"
740 "%s%s%s a & b \\\\\n"
741 "%s%s%s c & d \\\\\n"
742 "%s%s\\end{tabular}\n"
743 "%s\\end{center}\n"
744 "\\end{table}",
745 indent,
746 indent,
747 indent, indent,
748 indent, indent, indent,
749 indent, indent, indent,
750 indent, indent,
751 indent);
752
753 deselect_text (tepl_window);
754 insert_text (tepl_window, text_before, text_after, NULL);
755
756 g_free (indent);
757 g_free (text_before);
758 g_free (text_after);
759 }
760
761 static void
latex_command_list_env_simple_cb(GSimpleAction * action,GVariant * parameter,gpointer user_data)762 latex_command_list_env_simple_cb (GSimpleAction *action,
763 GVariant *parameter,
764 gpointer user_data)
765 {
766 TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
767 const gchar *list_env;
768 gchar *indent;
769 gchar *text_before;
770 gchar *text_after;
771
772 list_env = g_variant_get_string (parameter, NULL);
773
774 indent = get_indentation (tepl_window);
775
776 text_before = g_strdup_printf ("\\begin{%s}\n"
777 "%s\\item ",
778 list_env,
779 indent);
780
781 text_after = g_strdup_printf ("\n\\end{%s}", list_env);
782
783 deselect_text (tepl_window);
784 insert_text (tepl_window, text_before, text_after, NULL);
785
786 g_free (indent);
787 g_free (text_before);
788 g_free (text_after);
789 }
790
791 static void
latex_command_list_env_description_cb(GSimpleAction * action,GVariant * parameter,gpointer user_data)792 latex_command_list_env_description_cb (GSimpleAction *action,
793 GVariant *parameter,
794 gpointer user_data)
795 {
796 TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
797 gchar *indent;
798 gchar *text_before;
799 gchar *text_after;
800
801 indent = get_indentation (tepl_window);
802
803 text_before = g_strdup_printf ("\\begin{description}\n"
804 "%s\\item[",
805 indent);
806
807 text_after = g_strdup_printf ("] \n\\end{description}");
808
809 deselect_text (tepl_window);
810 insert_text (tepl_window, text_before, text_after, NULL);
811
812 g_free (indent);
813 g_free (text_before);
814 g_free (text_after);
815 }
816
817 static void
latex_command_list_env_list_cb(GSimpleAction * action,GVariant * parameter,gpointer user_data)818 latex_command_list_env_list_cb (GSimpleAction *action,
819 GVariant *parameter,
820 gpointer user_data)
821 {
822 TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
823 gchar *indent;
824 gchar *text_after;
825
826 indent = get_indentation (tepl_window);
827 text_after = g_strdup_printf ("}{}\n%s\\item \n\\end{list}", indent);
828
829 deselect_text (tepl_window);
830 insert_text (tepl_window, "\\begin{list}{", text_after, NULL);
831
832 g_free (indent);
833 g_free (text_after);
834 }
835
836 static void
latex_command_char_style_cb(GSimpleAction * action,GVariant * parameter,gpointer user_data)837 latex_command_char_style_cb (GSimpleAction *action,
838 GVariant *parameter,
839 gpointer user_data)
840 {
841 TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
842 const gchar *style;
843 TeplBuffer *buffer;
844 TeplSelectionType selection_type;
845 gchar *text_before;
846 gchar *text_after;
847 gchar *text_if_no_selection;
848
849 style = g_variant_get_string (parameter, NULL);
850
851 buffer = tepl_tab_group_get_active_buffer (TEPL_TAB_GROUP (tepl_window));
852 g_return_if_fail (buffer != NULL);
853
854 selection_type = tepl_buffer_get_selection_type (buffer);
855
856 if (selection_type == TEPL_SELECTION_TYPE_MULTIPLE_LINES)
857 {
858 text_before = g_strdup_printf ("\\begin{%s}\n", style);
859 text_after = g_strdup_printf ("\n\\end{%s}", style);
860 text_if_no_selection = NULL;
861 }
862 else
863 {
864 text_before = g_strdup_printf ("{\\%s ", style);
865 text_after = g_strdup_printf ("}");
866 text_if_no_selection = g_strdup_printf ("\\%s ", style);
867 }
868
869 insert_text (tepl_window,
870 text_before,
871 text_after,
872 text_if_no_selection);
873
874 g_free (text_before);
875 g_free (text_after);
876 g_free (text_if_no_selection);
877 }
878
879 static void
latex_command_tabular_tabular_cb(GSimpleAction * action,GVariant * parameter,gpointer user_data)880 latex_command_tabular_tabular_cb (GSimpleAction *action,
881 GVariant *parameter,
882 gpointer user_data)
883 {
884 TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
885 gchar *indent;
886 gchar *text_after;
887
888 indent = get_indentation (tepl_window);
889 text_after = g_strdup_printf ("}\n"
890 "%s a & b \\\\\n"
891 "%s c & d \\\\\n"
892 "\\end{tabular}",
893 indent,
894 indent);
895
896 deselect_text (tepl_window);
897 insert_text (tepl_window,
898 "\\begin{tabular}{cc",
899 text_after,
900 NULL);
901
902 g_free (indent);
903 g_free (text_after);
904 }
905
906 static void
latex_command_tabular_multicolumn_cb(GSimpleAction * action,GVariant * parameter,gpointer user_data)907 latex_command_tabular_multicolumn_cb (GSimpleAction *action,
908 GVariant *parameter,
909 gpointer user_data)
910 {
911 TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
912
913 insert_text (tepl_window, "\\multicolumn{}{}{", "}", NULL);
914 }
915
916 static void
latex_command_tabular_cline_cb(GSimpleAction * action,GVariant * parameter,gpointer user_data)917 latex_command_tabular_cline_cb (GSimpleAction *action,
918 GVariant *parameter,
919 gpointer user_data)
920 {
921 TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
922
923 insert_text (tepl_window, "\\cline{", "-}", NULL);
924 }
925
926 static void
latex_command_presentation_frame_cb(GSimpleAction * action,GVariant * parameter,gpointer user_data)927 latex_command_presentation_frame_cb (GSimpleAction *action,
928 GVariant *parameter,
929 gpointer user_data)
930 {
931 TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
932 gchar *indent;
933 gchar *text_before;
934
935 indent = get_indentation (tepl_window);
936 text_before = g_strdup_printf ("\\begin{frame}\n"
937 "%s\\frametitle{}\n"
938 "%s\\framesubtitle{}\n",
939 indent,
940 indent);
941
942 insert_text (tepl_window,
943 text_before,
944 "\n\\end{frame}",
945 NULL);
946
947 g_free (indent);
948 g_free (text_before);
949 }
950
951 static void
latex_command_presentation_block_cb(GSimpleAction * action,GVariant * parameter,gpointer user_data)952 latex_command_presentation_block_cb (GSimpleAction *action,
953 GVariant *parameter,
954 gpointer user_data)
955 {
956 TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
957
958 insert_text (tepl_window,
959 "\\begin{block}{}\n",
960 "\n\\end{block}",
961 NULL);
962 }
963
964 static void
latex_command_presentation_columns_cb(GSimpleAction * action,GVariant * parameter,gpointer user_data)965 latex_command_presentation_columns_cb (GSimpleAction *action,
966 GVariant *parameter,
967 gpointer user_data)
968 {
969 TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
970 gchar *indent;
971 gchar *text_before;
972 gchar *text_after;
973
974 indent = get_indentation (tepl_window);
975
976 text_before = g_strdup_printf ("\\begin{columns}\n"
977 "%s\\begin{column}{.5\\textwidth}\n",
978 indent);
979
980 text_after = g_strdup_printf ("\n"
981 "%s\\end{column}\n"
982 "%s\\begin{column}{.5\\textwidth}\n\n"
983 "%s\\end{column}\n"
984 "\\end{columns}",
985 indent,
986 indent,
987 indent);
988
989 insert_text (tepl_window, text_before, text_after, NULL);
990
991 g_free (indent);
992 g_free (text_before);
993 g_free (text_after);
994 }
995
996 static void
latex_command_spacing_new_line_cb(GSimpleAction * action,GVariant * parameter,gpointer user_data)997 latex_command_spacing_new_line_cb (GSimpleAction *action,
998 GVariant *parameter,
999 gpointer user_data)
1000 {
1001 TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
1002
1003 insert_text (tepl_window, "\\\\\n", "", NULL);
1004 }
1005
1006 static void
latex_command_ams_packages_cb(GSimpleAction * action,GVariant * parameter,gpointer user_data)1007 latex_command_ams_packages_cb (GSimpleAction *action,
1008 GVariant *parameter,
1009 gpointer user_data)
1010 {
1011 TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
1012
1013 insert_text (tepl_window,
1014 "\\usepackage{amsmath}\n"
1015 "\\usepackage{amsfonts}\n"
1016 "\\usepackage{amssymb}",
1017 "",
1018 NULL);
1019 }
1020
1021 static void
math_command_env_normal_cb(GSimpleAction * action,GVariant * parameter,gpointer user_data)1022 math_command_env_normal_cb (GSimpleAction *action,
1023 GVariant *parameter,
1024 gpointer user_data)
1025 {
1026 TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
1027
1028 insert_text (tepl_window, "$ ", " $", NULL);
1029 }
1030
1031 static void
math_command_env_centered_cb(GSimpleAction * action,GVariant * parameter,gpointer user_data)1032 math_command_env_centered_cb (GSimpleAction *action,
1033 GVariant *parameter,
1034 gpointer user_data)
1035 {
1036 TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
1037
1038 insert_text (tepl_window, "\\[ ", " \\]", NULL);
1039 }
1040
1041 static void
math_command_env_array_cb(GSimpleAction * action,GVariant * parameter,gpointer user_data)1042 math_command_env_array_cb (GSimpleAction *action,
1043 GVariant *parameter,
1044 gpointer user_data)
1045 {
1046 TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
1047
1048 insert_text (tepl_window,
1049 "\\begin{align*}\n",
1050 "\n\\end{align*}",
1051 NULL);
1052 }
1053
1054 static void
math_command_misc_superscript_cb(GSimpleAction * action,GVariant * parameter,gpointer user_data)1055 math_command_misc_superscript_cb (GSimpleAction *action,
1056 GVariant *parameter,
1057 gpointer user_data)
1058 {
1059 TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
1060
1061 insert_text (tepl_window, "^{", "}", NULL);
1062 }
1063
1064 static void
math_command_misc_subscript_cb(GSimpleAction * action,GVariant * parameter,gpointer user_data)1065 math_command_misc_subscript_cb (GSimpleAction *action,
1066 GVariant *parameter,
1067 gpointer user_data)
1068 {
1069 TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
1070
1071 insert_text (tepl_window, "_{", "}", NULL);
1072 }
1073
1074 static void
math_command_misc_frac_cb(GSimpleAction * action,GVariant * parameter,gpointer user_data)1075 math_command_misc_frac_cb (GSimpleAction *action,
1076 GVariant *parameter,
1077 gpointer user_data)
1078 {
1079 TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
1080
1081 insert_text (tepl_window, "\\frac{", "}{}", NULL);
1082 }
1083
1084 static void
math_command_misc_nth_root_cb(GSimpleAction * action,GVariant * parameter,gpointer user_data)1085 math_command_misc_nth_root_cb (GSimpleAction *action,
1086 GVariant *parameter,
1087 gpointer user_data)
1088 {
1089 TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
1090
1091 insert_text (tepl_window, "\\sqrt[]{", "}", NULL);
1092 }
1093
1094 static void
math_command_spaces_small_cb(GSimpleAction * action,GVariant * parameter,gpointer user_data)1095 math_command_spaces_small_cb (GSimpleAction *action,
1096 GVariant *parameter,
1097 gpointer user_data)
1098 {
1099 TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
1100
1101 insert_text (tepl_window, "\\, ", "", NULL);
1102 }
1103
1104 static void
math_command_spaces_medium_cb(GSimpleAction * action,GVariant * parameter,gpointer user_data)1105 math_command_spaces_medium_cb (GSimpleAction *action,
1106 GVariant *parameter,
1107 gpointer user_data)
1108 {
1109 TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
1110
1111 insert_text (tepl_window, "\\: ", "", NULL);
1112 }
1113
1114 static void
math_command_spaces_large_cb(GSimpleAction * action,GVariant * parameter,gpointer user_data)1115 math_command_spaces_large_cb (GSimpleAction *action,
1116 GVariant *parameter,
1117 gpointer user_data)
1118 {
1119 TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
1120
1121 insert_text (tepl_window, "\\; ", "", NULL);
1122 }
1123
1124 static void
math_command_delimiter_left1_cb(GSimpleAction * action,GVariant * parameter,gpointer user_data)1125 math_command_delimiter_left1_cb (GSimpleAction *action,
1126 GVariant *parameter,
1127 gpointer user_data)
1128 {
1129 TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
1130
1131 insert_text (tepl_window, "\\left( ", "", NULL);
1132 }
1133
1134 static void
math_command_delimiter_left2_cb(GSimpleAction * action,GVariant * parameter,gpointer user_data)1135 math_command_delimiter_left2_cb (GSimpleAction *action,
1136 GVariant *parameter,
1137 gpointer user_data)
1138 {
1139 TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
1140
1141 insert_text (tepl_window, "\\left[ ", "", NULL);
1142 }
1143
1144 static void
math_command_delimiter_left3_cb(GSimpleAction * action,GVariant * parameter,gpointer user_data)1145 math_command_delimiter_left3_cb (GSimpleAction *action,
1146 GVariant *parameter,
1147 gpointer user_data)
1148 {
1149 TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
1150
1151 insert_text (tepl_window, "\\left\\lbrace ", "", NULL);
1152 }
1153
1154 static void
math_command_delimiter_left4_cb(GSimpleAction * action,GVariant * parameter,gpointer user_data)1155 math_command_delimiter_left4_cb (GSimpleAction *action,
1156 GVariant *parameter,
1157 gpointer user_data)
1158 {
1159 TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
1160
1161 insert_text (tepl_window, "\\left\\langle ", "", NULL);
1162 }
1163
1164 static void
math_command_delimiter_left5_cb(GSimpleAction * action,GVariant * parameter,gpointer user_data)1165 math_command_delimiter_left5_cb (GSimpleAction *action,
1166 GVariant *parameter,
1167 gpointer user_data)
1168 {
1169 TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
1170
1171 insert_text (tepl_window, "\\left) ", "", NULL);
1172 }
1173
1174 static void
math_command_delimiter_left6_cb(GSimpleAction * action,GVariant * parameter,gpointer user_data)1175 math_command_delimiter_left6_cb (GSimpleAction *action,
1176 GVariant *parameter,
1177 gpointer user_data)
1178 {
1179 TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
1180
1181 insert_text (tepl_window, "\\left] ", "", NULL);
1182 }
1183
1184 static void
math_command_delimiter_left7_cb(GSimpleAction * action,GVariant * parameter,gpointer user_data)1185 math_command_delimiter_left7_cb (GSimpleAction *action,
1186 GVariant *parameter,
1187 gpointer user_data)
1188 {
1189 TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
1190
1191 insert_text (tepl_window, "\\left\\rbrace ", "", NULL);
1192 }
1193
1194 static void
math_command_delimiter_left8_cb(GSimpleAction * action,GVariant * parameter,gpointer user_data)1195 math_command_delimiter_left8_cb (GSimpleAction *action,
1196 GVariant *parameter,
1197 gpointer user_data)
1198 {
1199 TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
1200
1201 insert_text (tepl_window, "\\left\\rangle ", "", NULL);
1202 }
1203
1204 static void
math_command_delimiter_left9_cb(GSimpleAction * action,GVariant * parameter,gpointer user_data)1205 math_command_delimiter_left9_cb (GSimpleAction *action,
1206 GVariant *parameter,
1207 gpointer user_data)
1208 {
1209 TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
1210
1211 insert_text (tepl_window, "\\left. ", "", NULL);
1212 }
1213
1214 static void
math_command_delimiter_right1_cb(GSimpleAction * action,GVariant * parameter,gpointer user_data)1215 math_command_delimiter_right1_cb (GSimpleAction *action,
1216 GVariant *parameter,
1217 gpointer user_data)
1218 {
1219 TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
1220
1221 insert_text (tepl_window, "\\right) ", "", NULL);
1222 }
1223
1224 static void
math_command_delimiter_right2_cb(GSimpleAction * action,GVariant * parameter,gpointer user_data)1225 math_command_delimiter_right2_cb (GSimpleAction *action,
1226 GVariant *parameter,
1227 gpointer user_data)
1228 {
1229 TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
1230
1231 insert_text (tepl_window, "\\right] ", "", NULL);
1232 }
1233
1234 static void
math_command_delimiter_right3_cb(GSimpleAction * action,GVariant * parameter,gpointer user_data)1235 math_command_delimiter_right3_cb (GSimpleAction *action,
1236 GVariant *parameter,
1237 gpointer user_data)
1238 {
1239 TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
1240
1241 insert_text (tepl_window, "\\right\\rbrace ", "", NULL);
1242 }
1243
1244 static void
math_command_delimiter_right4_cb(GSimpleAction * action,GVariant * parameter,gpointer user_data)1245 math_command_delimiter_right4_cb (GSimpleAction *action,
1246 GVariant *parameter,
1247 gpointer user_data)
1248 {
1249 TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
1250
1251 insert_text (tepl_window, "\\right\\rangle ", "", NULL);
1252 }
1253
1254 static void
math_command_delimiter_right5_cb(GSimpleAction * action,GVariant * parameter,gpointer user_data)1255 math_command_delimiter_right5_cb (GSimpleAction *action,
1256 GVariant *parameter,
1257 gpointer user_data)
1258 {
1259 TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
1260
1261 insert_text (tepl_window, "\\right( ", "", NULL);
1262 }
1263
1264 static void
math_command_delimiter_right6_cb(GSimpleAction * action,GVariant * parameter,gpointer user_data)1265 math_command_delimiter_right6_cb (GSimpleAction *action,
1266 GVariant *parameter,
1267 gpointer user_data)
1268 {
1269 TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
1270
1271 insert_text (tepl_window, "\\right[ ", "", NULL);
1272 }
1273
1274 static void
math_command_delimiter_right7_cb(GSimpleAction * action,GVariant * parameter,gpointer user_data)1275 math_command_delimiter_right7_cb (GSimpleAction *action,
1276 GVariant *parameter,
1277 gpointer user_data)
1278 {
1279 TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
1280
1281 insert_text (tepl_window, "\\right\\lbrace ", "", NULL);
1282 }
1283
1284 static void
math_command_delimiter_right8_cb(GSimpleAction * action,GVariant * parameter,gpointer user_data)1285 math_command_delimiter_right8_cb (GSimpleAction *action,
1286 GVariant *parameter,
1287 gpointer user_data)
1288 {
1289 TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
1290
1291 insert_text (tepl_window, "\\right\\langle ", "", NULL);
1292 }
1293
1294 static void
math_command_delimiter_right9_cb(GSimpleAction * action,GVariant * parameter,gpointer user_data)1295 math_command_delimiter_right9_cb (GSimpleAction *action,
1296 GVariant *parameter,
1297 gpointer user_data)
1298 {
1299 TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
1300
1301 insert_text (tepl_window, "\\right. ", "", NULL);
1302 }
1303
1304 static const GActionEntry action_entries[] = {
1305 { "latex-command-simple", latex_command_simple_cb, "s" },
1306 { "latex-command-with-braces", latex_command_with_braces_cb, "s" },
1307 { "latex-command-with-space", latex_command_with_space_cb, "s" },
1308 { "latex-command-with-newline", latex_command_with_newline_cb, "s" },
1309 { "latex-command-env-simple", latex_command_env_simple_cb, "s" },
1310 { "latex-command-env-figure", latex_command_env_figure_cb },
1311 { "latex-command-env-table", latex_command_env_table_cb },
1312 { "latex-command-list-env-simple", latex_command_list_env_simple_cb, "s" },
1313 { "latex-command-list-env-description", latex_command_list_env_description_cb },
1314 { "latex-command-list-env-list", latex_command_list_env_list_cb },
1315 { "latex-command-char-style", latex_command_char_style_cb, "s" },
1316 { "latex-command-tabular-tabular", latex_command_tabular_tabular_cb },
1317 { "latex-command-tabular-multicolumn", latex_command_tabular_multicolumn_cb },
1318 { "latex-command-tabular-cline", latex_command_tabular_cline_cb },
1319 { "latex-command-presentation-frame", latex_command_presentation_frame_cb },
1320 { "latex-command-presentation-block", latex_command_presentation_block_cb },
1321 { "latex-command-presentation-columns", latex_command_presentation_columns_cb },
1322 { "latex-command-spacing-new-line", latex_command_spacing_new_line_cb },
1323 { "latex-command-ams-packages", latex_command_ams_packages_cb },
1324 { "math-command-env-normal", math_command_env_normal_cb },
1325 { "math-command-env-centered", math_command_env_centered_cb },
1326 { "math-command-env-array", math_command_env_array_cb },
1327 { "math-command-misc-superscript", math_command_misc_superscript_cb },
1328 { "math-command-misc-subscript", math_command_misc_subscript_cb },
1329 { "math-command-misc-frac", math_command_misc_frac_cb },
1330 { "math-command-misc-nth-root", math_command_misc_nth_root_cb },
1331 { "math-command-spaces-small", math_command_spaces_small_cb },
1332 { "math-command-spaces-medium", math_command_spaces_medium_cb },
1333 { "math-command-spaces-large", math_command_spaces_large_cb },
1334 { "math-command-delimiter-left1", math_command_delimiter_left1_cb },
1335 { "math-command-delimiter-left2", math_command_delimiter_left2_cb },
1336 { "math-command-delimiter-left3", math_command_delimiter_left3_cb },
1337 { "math-command-delimiter-left4", math_command_delimiter_left4_cb },
1338 { "math-command-delimiter-left5", math_command_delimiter_left5_cb },
1339 { "math-command-delimiter-left6", math_command_delimiter_left6_cb },
1340 { "math-command-delimiter-left7", math_command_delimiter_left7_cb },
1341 { "math-command-delimiter-left8", math_command_delimiter_left8_cb },
1342 { "math-command-delimiter-left9", math_command_delimiter_left9_cb },
1343 { "math-command-delimiter-right1", math_command_delimiter_right1_cb },
1344 { "math-command-delimiter-right2", math_command_delimiter_right2_cb },
1345 { "math-command-delimiter-right3", math_command_delimiter_right3_cb },
1346 { "math-command-delimiter-right4", math_command_delimiter_right4_cb },
1347 { "math-command-delimiter-right5", math_command_delimiter_right5_cb },
1348 { "math-command-delimiter-right6", math_command_delimiter_right6_cb },
1349 { "math-command-delimiter-right7", math_command_delimiter_right7_cb },
1350 { "math-command-delimiter-right8", math_command_delimiter_right8_cb },
1351 { "math-command-delimiter-right9", math_command_delimiter_right9_cb },
1352 };
1353
1354 static void
update_actions_sensitivity(TeplApplicationWindow * tepl_window)1355 update_actions_sensitivity (TeplApplicationWindow *tepl_window)
1356 {
1357 GtkApplicationWindow *gtk_window;
1358 TeplTab *active_tab;
1359 gboolean sensitive;
1360 guint i;
1361
1362 gtk_window = tepl_application_window_get_application_window (tepl_window);
1363
1364 active_tab = tepl_tab_group_get_active_tab (TEPL_TAB_GROUP (tepl_window));
1365 sensitive = active_tab != NULL;
1366
1367 for (i = 0; i < G_N_ELEMENTS (action_entries); i++)
1368 {
1369 const gchar *action_name = action_entries[i].name;
1370 GAction *action;
1371
1372 action = g_action_map_lookup_action (G_ACTION_MAP (gtk_window), action_name);
1373 g_simple_action_set_enabled (G_SIMPLE_ACTION (action), sensitive);
1374 }
1375 }
1376
1377 static void
actions__active_tab_notify_cb(TeplApplicationWindow * tepl_window,GParamSpec * pspec,gpointer user_data)1378 actions__active_tab_notify_cb (TeplApplicationWindow *tepl_window,
1379 GParamSpec *pspec,
1380 gpointer user_data)
1381 {
1382 update_actions_sensitivity (tepl_window);
1383 }
1384
1385 /**
1386 * latexila_latex_commands_add_actions:
1387 * @gtk_window: a #GtkApplicationWindow.
1388 *
1389 * Creates the #GAction's related to the LaTeX and Math menus, and add them to
1390 * @gtk_window.
1391 */
1392 void
latexila_latex_commands_add_actions(GtkApplicationWindow * gtk_window)1393 latexila_latex_commands_add_actions (GtkApplicationWindow *gtk_window)
1394 {
1395 TeplApplicationWindow *tepl_window;
1396
1397 g_return_if_fail (GTK_IS_APPLICATION_WINDOW (gtk_window));
1398
1399 tepl_window = tepl_application_window_get_from_gtk_application_window (gtk_window);
1400
1401 amtk_action_map_add_action_entries_check_dups (G_ACTION_MAP (gtk_window),
1402 action_entries,
1403 G_N_ELEMENTS (action_entries),
1404 tepl_window);
1405
1406 g_signal_connect (tepl_window,
1407 "notify::active-tab",
1408 G_CALLBACK (actions__active_tab_notify_cb),
1409 NULL);
1410
1411 update_actions_sensitivity (tepl_window);
1412 }
1413
1414 static void
tool_button_clicked_cb(GtkToolButton * tool_button,gpointer user_data)1415 tool_button_clicked_cb (GtkToolButton *tool_button,
1416 gpointer user_data)
1417 {
1418 GList *menus_list;
1419 GtkMenu *menu;
1420
1421 menus_list = gtk_menu_get_for_attach_widget (GTK_WIDGET (tool_button));
1422 g_return_if_fail (menus_list != NULL);
1423
1424 menu = GTK_MENU (menus_list->data);
1425
1426 gtk_menu_popup_at_widget (menu,
1427 GTK_WIDGET (tool_button),
1428 GDK_GRAVITY_SOUTH_WEST,
1429 GDK_GRAVITY_NORTH_WEST,
1430 NULL);
1431 }
1432
1433 static void
update_tool_item_sensitivity(TeplApplicationWindow * tepl_window,GtkToolItem * item)1434 update_tool_item_sensitivity (TeplApplicationWindow *tepl_window,
1435 GtkToolItem *item)
1436 {
1437 TeplTab *active_tab;
1438
1439 active_tab = tepl_tab_group_get_active_tab (TEPL_TAB_GROUP (tepl_window));
1440 gtk_widget_set_sensitive (GTK_WIDGET (item), active_tab != NULL);
1441 }
1442
1443 static void
tool_item__active_tab_notify_cb(TeplApplicationWindow * tepl_window,GParamSpec * pspec,GtkToolItem * item)1444 tool_item__active_tab_notify_cb (TeplApplicationWindow *tepl_window,
1445 GParamSpec *pspec,
1446 GtkToolItem *item)
1447 {
1448 update_tool_item_sensitivity (tepl_window, item);
1449 }
1450
1451 static GtkToolItem *
create_tool_item_with_dropdown_menu(GtkApplicationWindow * gtk_window,const gchar * icon_name,const gchar * tooltip,GtkWidget * menu)1452 create_tool_item_with_dropdown_menu (GtkApplicationWindow *gtk_window,
1453 const gchar *icon_name,
1454 const gchar *tooltip,
1455 GtkWidget *menu)
1456 {
1457 AmtkApplicationWindow *amtk_window;
1458 TeplApplicationWindow *tepl_window;
1459 GtkToolItem *item;
1460 GtkWidget *hgrid;
1461 GtkWidget *image;
1462
1463 amtk_window = amtk_application_window_get_from_gtk_application_window (gtk_window);
1464 tepl_window = tepl_application_window_get_from_gtk_application_window (gtk_window);
1465
1466 hgrid = gtk_grid_new ();
1467 image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_LARGE_TOOLBAR);
1468 gtk_container_add (GTK_CONTAINER (hgrid), image);
1469 image = gtk_image_new_from_icon_name ("pan-down-symbolic", GTK_ICON_SIZE_BUTTON);
1470 gtk_container_add (GTK_CONTAINER (hgrid), image);
1471
1472 item = gtk_tool_button_new (hgrid, NULL);
1473 gtk_tool_item_set_homogeneous (item, FALSE);
1474 gtk_widget_set_tooltip_text (GTK_WIDGET (item), tooltip);
1475
1476 gtk_widget_show_all (menu);
1477 gtk_menu_attach_to_widget (GTK_MENU (menu), GTK_WIDGET (item), NULL);
1478 amtk_application_window_connect_menu_to_statusbar (amtk_window, GTK_MENU_SHELL (menu));
1479
1480 g_signal_connect (item,
1481 "clicked",
1482 G_CALLBACK (tool_button_clicked_cb),
1483 NULL);
1484
1485 g_signal_connect (tepl_window,
1486 "notify::active-tab",
1487 G_CALLBACK (tool_item__active_tab_notify_cb),
1488 item);
1489
1490 update_tool_item_sensitivity (tepl_window, item);
1491
1492 return item;
1493 }
1494
1495 static GtkWidget *
create_submenu_latex_sectioning(void)1496 create_submenu_latex_sectioning (void)
1497 {
1498 GtkMenuShell *menu;
1499 AmtkFactory *factory;
1500
1501 menu = GTK_MENU_SHELL (gtk_menu_new ());
1502
1503 factory = amtk_factory_new (NULL);
1504 gtk_menu_shell_append (menu, amtk_factory_create_menu_item (factory, "win.latex-command-with-braces::part"));
1505 gtk_menu_shell_append (menu, amtk_factory_create_menu_item (factory, "win.latex-command-with-braces::chapter"));
1506 gtk_menu_shell_append (menu, gtk_separator_menu_item_new ());
1507 gtk_menu_shell_append (menu, amtk_factory_create_menu_item (factory, "win.latex-command-with-braces::section"));
1508 gtk_menu_shell_append (menu, amtk_factory_create_menu_item (factory, "win.latex-command-with-braces::subsection"));
1509 gtk_menu_shell_append (menu, amtk_factory_create_menu_item (factory, "win.latex-command-with-braces::subsubsection"));
1510 gtk_menu_shell_append (menu, amtk_factory_create_menu_item (factory, "win.latex-command-with-braces::paragraph"));
1511 gtk_menu_shell_append (menu, amtk_factory_create_menu_item (factory, "win.latex-command-with-braces::subparagraph"));
1512 g_object_unref (factory);
1513
1514 return GTK_WIDGET (menu);
1515 }
1516
1517 /**
1518 * latexila_latex_commands_create_edit_toolbar:
1519 * @gtk_window: a #GtkApplicationWindow.
1520 *
1521 * Returns: (transfer floating): a new #GtkToolbar with the most common LaTeX
1522 * actions.
1523 */
1524 GtkToolbar *
latexila_latex_commands_create_edit_toolbar(GtkApplicationWindow * gtk_window)1525 latexila_latex_commands_create_edit_toolbar (GtkApplicationWindow *gtk_window)
1526 {
1527 GtkToolbar *toolbar;
1528 GtkStyleContext *style_context;
1529 AmtkFactory *factory;
1530 GtkToolItem *item;
1531 GtkWidget *menu;
1532
1533 g_return_val_if_fail (GTK_IS_APPLICATION_WINDOW (gtk_window), NULL);
1534
1535 toolbar = GTK_TOOLBAR (gtk_toolbar_new ());
1536 style_context = gtk_widget_get_style_context (GTK_WIDGET (toolbar));
1537 gtk_style_context_add_class (style_context, "gnome-latex-edit-toolbar");
1538
1539 factory = amtk_factory_new (NULL);
1540
1541 item = create_tool_item_with_dropdown_menu (gtk_window, "sectioning", _("Sectioning"), create_submenu_latex_sectioning ());
1542 gtk_toolbar_insert (toolbar, item, -1);
1543
1544 menu = amtk_factory_create_simple_menu (factory, action_info_entries_latex_references, -1);
1545 item = create_tool_item_with_dropdown_menu (gtk_window, "references", _("References"), menu);
1546 gtk_toolbar_insert (toolbar, item, -1);
1547
1548 menu = amtk_factory_create_simple_menu (factory, action_info_entries_latex_character_sizes, -1);
1549 item = create_tool_item_with_dropdown_menu (gtk_window, "character-size", _("Characters Sizes"), menu);
1550 gtk_toolbar_insert (toolbar, item, -1);
1551
1552 gtk_toolbar_insert (toolbar, gtk_separator_tool_item_new (), -1);
1553 gtk_toolbar_insert (toolbar, amtk_factory_create_tool_button (factory, "win.latex-command-with-braces::textbf"), -1);
1554 gtk_toolbar_insert (toolbar, amtk_factory_create_tool_button (factory, "win.latex-command-with-braces::textit"), -1);
1555 gtk_toolbar_insert (toolbar, amtk_factory_create_tool_button (factory, "win.latex-command-with-braces::texttt"), -1);
1556 gtk_toolbar_insert (toolbar, amtk_factory_create_tool_button (factory, "win.latex-command-with-braces::underline"), -1);
1557 gtk_toolbar_insert (toolbar, gtk_separator_tool_item_new (), -1);
1558 gtk_toolbar_insert (toolbar, amtk_factory_create_tool_button (factory, "win.latex-command-env-simple::center"), -1);
1559 gtk_toolbar_insert (toolbar, gtk_separator_tool_item_new (), -1);
1560 gtk_toolbar_insert (toolbar, amtk_factory_create_tool_button (factory, "win.latex-command-list-env-simple::itemize"), -1);
1561 gtk_toolbar_insert (toolbar, amtk_factory_create_tool_button (factory, "win.latex-command-list-env-simple::enumerate"), -1);
1562 gtk_toolbar_insert (toolbar, amtk_factory_create_tool_button (factory, "win.latex-command-list-env-description"), -1);
1563 gtk_toolbar_insert (toolbar, gtk_separator_tool_item_new (), -1);
1564 gtk_toolbar_insert (toolbar, amtk_factory_create_tool_button (factory, "win.latex-command-env-figure"), -1);
1565 gtk_toolbar_insert (toolbar, amtk_factory_create_tool_button (factory, "win.latex-command-env-table"), -1);
1566 gtk_toolbar_insert (toolbar, gtk_separator_tool_item_new (), -1);
1567
1568 menu = amtk_factory_create_simple_menu (factory, action_info_entries_latex_presentation, -1);
1569 item = create_tool_item_with_dropdown_menu (gtk_window, "x-office-presentation", _("Presentation Environments"), menu);
1570 gtk_toolbar_insert (toolbar, item, -1);
1571
1572 gtk_toolbar_insert (toolbar, gtk_separator_tool_item_new (), -1);
1573
1574 menu = amtk_factory_create_simple_menu (factory, action_info_entries_math_environments, -1);
1575 item = create_tool_item_with_dropdown_menu (gtk_window, "math", _("Math Environments"), menu);
1576 gtk_toolbar_insert (toolbar, item, -1);
1577
1578 gtk_toolbar_insert (toolbar, gtk_separator_tool_item_new (), -1);
1579 gtk_toolbar_insert (toolbar, amtk_factory_create_tool_button (factory, "win.math-command-misc-superscript"), -1);
1580 gtk_toolbar_insert (toolbar, amtk_factory_create_tool_button (factory, "win.math-command-misc-subscript"), -1);
1581 gtk_toolbar_insert (toolbar, gtk_separator_tool_item_new (), -1);
1582 gtk_toolbar_insert (toolbar, amtk_factory_create_tool_button (factory, "win.math-command-misc-frac"), -1);
1583 gtk_toolbar_insert (toolbar, amtk_factory_create_tool_button (factory, "win.latex-command-with-braces::sqrt"), -1);
1584 g_object_unref (factory);
1585
1586 gtk_widget_show_all (GTK_WIDGET (toolbar));
1587
1588 return toolbar;
1589 }
1590
1591 static GtkWidget *
create_submenu_latex_environments(void)1592 create_submenu_latex_environments (void)
1593 {
1594 GtkMenuShell *menu;
1595 AmtkFactory *factory;
1596
1597 menu = GTK_MENU_SHELL (gtk_menu_new ());
1598
1599 factory = amtk_factory_new_with_default_application ();
1600 gtk_menu_shell_append (menu, amtk_factory_create_menu_item (factory, "win.latex-command-env-simple::center"));
1601 gtk_menu_shell_append (menu, amtk_factory_create_menu_item (factory, "win.latex-command-env-simple::flushleft"));
1602 gtk_menu_shell_append (menu, amtk_factory_create_menu_item (factory, "win.latex-command-env-simple::flushright"));
1603 gtk_menu_shell_append (menu, gtk_separator_menu_item_new ());
1604 gtk_menu_shell_append (menu, amtk_factory_create_menu_item (factory, "win.latex-command-env-figure"));
1605 gtk_menu_shell_append (menu, amtk_factory_create_menu_item (factory, "win.latex-command-env-table"));
1606 gtk_menu_shell_append (menu, gtk_separator_menu_item_new ());
1607 gtk_menu_shell_append (menu, amtk_factory_create_menu_item (factory, "win.latex-command-env-simple::quote"));
1608 gtk_menu_shell_append (menu, amtk_factory_create_menu_item (factory, "win.latex-command-env-simple::quotation"));
1609 gtk_menu_shell_append (menu, amtk_factory_create_menu_item (factory, "win.latex-command-env-simple::verse"));
1610 gtk_menu_shell_append (menu, amtk_factory_create_menu_item (factory, "win.latex-command-env-simple::verbatim"));
1611 gtk_menu_shell_append (menu, gtk_separator_menu_item_new ());
1612 gtk_menu_shell_append (menu, amtk_factory_create_menu_item (factory, "win.latex-command-env-simple::minipage"));
1613 gtk_menu_shell_append (menu, amtk_factory_create_menu_item (factory, "win.latex-command-env-simple::titlepage"));
1614 g_object_unref (factory);
1615
1616 return GTK_WIDGET (menu);
1617 }
1618
1619 static GtkWidget *
create_submenu_latex_list_environments(void)1620 create_submenu_latex_list_environments (void)
1621 {
1622 GtkMenuShell *menu;
1623 AmtkFactory *factory;
1624
1625 menu = GTK_MENU_SHELL (gtk_menu_new ());
1626
1627 factory = amtk_factory_new_with_default_application ();
1628 gtk_menu_shell_append (menu, amtk_factory_create_menu_item (factory, "win.latex-command-list-env-simple::itemize"));
1629 gtk_menu_shell_append (menu, amtk_factory_create_menu_item (factory, "win.latex-command-list-env-simple::enumerate"));
1630 gtk_menu_shell_append (menu, amtk_factory_create_menu_item (factory, "win.latex-command-list-env-description"));
1631 gtk_menu_shell_append (menu, amtk_factory_create_menu_item (factory, "win.latex-command-list-env-list"));
1632 gtk_menu_shell_append (menu, gtk_separator_menu_item_new ());
1633 gtk_menu_shell_append (menu, amtk_factory_create_menu_item (factory, "win.latex-command-with-space::item"));
1634 g_object_unref (factory);
1635
1636 return GTK_WIDGET (menu);
1637 }
1638
1639 static GtkWidget *
create_submenu_latex_font_styles(void)1640 create_submenu_latex_font_styles (void)
1641 {
1642 GtkMenuShell *menu;
1643 GtkMenuShell *submenu;
1644 GtkWidget *menu_item;
1645 AmtkFactory *factory;
1646 AmtkFactory *factory_no_gaction;
1647
1648 menu = GTK_MENU_SHELL (gtk_menu_new ());
1649 factory = amtk_factory_new_with_default_application ();
1650
1651 factory_no_gaction = amtk_factory_new_with_default_application ();
1652 amtk_factory_set_default_flags (factory_no_gaction, AMTK_FACTORY_IGNORE_GACTION);
1653
1654 gtk_menu_shell_append (menu, amtk_factory_create_menu_item (factory, "win.latex-command-with-braces::textbf"));
1655 gtk_menu_shell_append (menu, amtk_factory_create_menu_item (factory, "win.latex-command-with-braces::textit"));
1656 gtk_menu_shell_append (menu, amtk_factory_create_menu_item (factory, "win.latex-command-with-braces::texttt"));
1657 gtk_menu_shell_append (menu, amtk_factory_create_menu_item (factory, "win.latex-command-with-braces::textsl"));
1658 gtk_menu_shell_append (menu, amtk_factory_create_menu_item (factory, "win.latex-command-with-braces::textsc"));
1659 gtk_menu_shell_append (menu, amtk_factory_create_menu_item (factory, "win.latex-command-with-braces::textsf"));
1660 gtk_menu_shell_append (menu, gtk_separator_menu_item_new ());
1661 gtk_menu_shell_append (menu, amtk_factory_create_menu_item (factory, "win.latex-command-with-braces::emph"));
1662 gtk_menu_shell_append (menu, gtk_separator_menu_item_new ());
1663 gtk_menu_shell_append (menu, amtk_factory_create_menu_item (factory, "win.latex-command-with-braces::underline"));
1664 gtk_menu_shell_append (menu, gtk_separator_menu_item_new ());
1665
1666 menu_item = amtk_factory_create_menu_item (factory_no_gaction, "no-gaction-latex-font-family");
1667 submenu = GTK_MENU_SHELL (gtk_menu_new ());
1668 gtk_menu_shell_append (submenu, amtk_factory_create_menu_item (factory, "win.latex-command-char-style::rmfamily"));
1669 gtk_menu_shell_append (submenu, amtk_factory_create_menu_item (factory, "win.latex-command-char-style::sffamily"));
1670 gtk_menu_shell_append (submenu, amtk_factory_create_menu_item (factory, "win.latex-command-char-style::ttfamily"));
1671 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), GTK_WIDGET (submenu));
1672 gtk_menu_shell_append (menu, menu_item);
1673
1674 menu_item = amtk_factory_create_menu_item (factory_no_gaction, "no-gaction-latex-font-series");
1675 submenu = GTK_MENU_SHELL (gtk_menu_new ());
1676 gtk_menu_shell_append (submenu, amtk_factory_create_menu_item (factory, "win.latex-command-char-style::mdseries"));
1677 gtk_menu_shell_append (submenu, amtk_factory_create_menu_item (factory, "win.latex-command-char-style::bfseries"));
1678 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), GTK_WIDGET (submenu));
1679 gtk_menu_shell_append (menu, menu_item);
1680
1681 menu_item = amtk_factory_create_menu_item (factory_no_gaction, "no-gaction-latex-font-shape");
1682 submenu = GTK_MENU_SHELL (gtk_menu_new ());
1683 gtk_menu_shell_append (submenu, amtk_factory_create_menu_item (factory, "win.latex-command-char-style::upshape"));
1684 gtk_menu_shell_append (submenu, amtk_factory_create_menu_item (factory, "win.latex-command-char-style::itshape"));
1685 gtk_menu_shell_append (submenu, amtk_factory_create_menu_item (factory, "win.latex-command-char-style::slshape"));
1686 gtk_menu_shell_append (submenu, amtk_factory_create_menu_item (factory, "win.latex-command-char-style::scshape"));
1687 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), GTK_WIDGET (submenu));
1688 gtk_menu_shell_append (menu, menu_item);
1689
1690 g_object_unref (factory);
1691 g_object_unref (factory_no_gaction);
1692
1693 return GTK_WIDGET (menu);
1694 }
1695
1696 static GtkWidget *
create_submenu_latex_misc(void)1697 create_submenu_latex_misc (void)
1698 {
1699 GtkMenuShell *menu;
1700 AmtkFactory *factory;
1701
1702 menu = GTK_MENU_SHELL (gtk_menu_new ());
1703
1704 factory = amtk_factory_new_with_default_application ();
1705 gtk_menu_shell_append (menu, amtk_factory_create_menu_item (factory, "win.latex-command-with-braces::documentclass"));
1706 gtk_menu_shell_append (menu, amtk_factory_create_menu_item (factory, "win.latex-command-with-braces::usepackage"));
1707 gtk_menu_shell_append (menu, amtk_factory_create_menu_item (factory, "win.latex-command-ams-packages"));
1708 gtk_menu_shell_append (menu, amtk_factory_create_menu_item (factory, "win.latex-command-with-braces::author"));
1709 gtk_menu_shell_append (menu, amtk_factory_create_menu_item (factory, "win.latex-command-with-braces::title"));
1710 gtk_menu_shell_append (menu, amtk_factory_create_menu_item (factory, "win.latex-command-env-simple::document"));
1711 gtk_menu_shell_append (menu, amtk_factory_create_menu_item (factory, "win.latex-command-simple::maketitle"));
1712 gtk_menu_shell_append (menu, amtk_factory_create_menu_item (factory, "win.latex-command-simple::tableofcontents"));
1713 gtk_menu_shell_append (menu, amtk_factory_create_menu_item (factory, "win.latex-command-env-simple::abstract"));
1714 gtk_menu_shell_append (menu, gtk_separator_menu_item_new ());
1715 gtk_menu_shell_append (menu, amtk_factory_create_menu_item (factory, "win.latex-command-with-braces::includegraphics"));
1716 gtk_menu_shell_append (menu, amtk_factory_create_menu_item (factory, "win.latex-command-with-braces::input"));
1717 g_object_unref (factory);
1718
1719 return GTK_WIDGET (menu);
1720 }
1721
1722 static void
add_menu_item_with_submenu(GtkMenuShell * menu,const gchar * action_name,GtkWidget * submenu)1723 add_menu_item_with_submenu (GtkMenuShell *menu,
1724 const gchar *action_name,
1725 GtkWidget *submenu)
1726 {
1727 AmtkFactory *factory_no_gaction;
1728 GtkWidget *menu_item;
1729
1730 factory_no_gaction = amtk_factory_new_with_default_application ();
1731 amtk_factory_set_default_flags (factory_no_gaction, AMTK_FACTORY_IGNORE_GACTION);
1732
1733 menu_item = amtk_factory_create_menu_item (factory_no_gaction, action_name);
1734 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), submenu);
1735 gtk_menu_shell_append (menu, menu_item);
1736
1737 g_object_unref (factory_no_gaction);
1738 }
1739
1740 static void
add_menu_item_with_subentries(GtkMenuShell * menu,const gchar * action_name,const AmtkActionInfoEntry * entries)1741 add_menu_item_with_subentries (GtkMenuShell *menu,
1742 const gchar *action_name,
1743 const AmtkActionInfoEntry *entries)
1744 {
1745 AmtkFactory *factory;
1746
1747 factory = amtk_factory_new_with_default_application ();
1748 add_menu_item_with_submenu (menu, action_name, amtk_factory_create_simple_menu (factory, entries, -1));
1749 g_object_unref (factory);
1750 }
1751
1752 /**
1753 * latexila_latex_commands_create_latex_menu:
1754 * @gtk_window: a #GtkApplicationWindow.
1755 *
1756 * Returns: (transfer floating): a new #GtkMenu with a lot of LaTeX commands.
1757 */
1758 GtkMenu *
latexila_latex_commands_create_latex_menu(GtkApplicationWindow * gtk_window)1759 latexila_latex_commands_create_latex_menu (GtkApplicationWindow *gtk_window)
1760 {
1761 GtkMenuShell *menu;
1762 AmtkApplicationWindow *amtk_window;
1763
1764 g_return_val_if_fail (GTK_IS_APPLICATION_WINDOW (gtk_window), NULL);
1765
1766 menu = GTK_MENU_SHELL (gtk_menu_new ());
1767
1768 add_menu_item_with_submenu (menu, "no-gaction-latex-sectioning", create_submenu_latex_sectioning ());
1769 add_menu_item_with_subentries (menu, "no-gaction-latex-references", action_info_entries_latex_references);
1770 add_menu_item_with_submenu (menu, "no-gaction-latex-environments", create_submenu_latex_environments ());
1771 add_menu_item_with_submenu (menu, "no-gaction-latex-list-environments", create_submenu_latex_list_environments ());
1772 add_menu_item_with_subentries (menu, "no-gaction-latex-character-size", action_info_entries_latex_character_sizes);
1773 add_menu_item_with_submenu (menu, "no-gaction-latex-font-styles", create_submenu_latex_font_styles ());
1774 add_menu_item_with_subentries (menu, "no-gaction-latex-tabular", action_info_entries_latex_tabular);
1775 add_menu_item_with_subentries (menu, "no-gaction-latex-presentation", action_info_entries_latex_presentation);
1776 add_menu_item_with_subentries (menu, "no-gaction-latex-spacing", action_info_entries_latex_spacing);
1777 add_menu_item_with_subentries (menu, "no-gaction-latex-accents", action_info_entries_latex_accents);
1778 add_menu_item_with_submenu (menu, "no-gaction-latex-misc", create_submenu_latex_misc ());
1779
1780 amtk_window = amtk_application_window_get_from_gtk_application_window (gtk_window);
1781 amtk_application_window_connect_menu_to_statusbar (amtk_window, menu);
1782
1783 gtk_widget_show_all (GTK_WIDGET (menu));
1784 return GTK_MENU (menu);
1785 }
1786
1787 /**
1788 * latexila_latex_commands_create_math_menu:
1789 * @gtk_window: a #GtkApplicationWindow.
1790 *
1791 * Returns: (transfer floating): a new #GtkMenu with a lot of math LaTeX
1792 * commands.
1793 */
1794 GtkMenu *
latexila_latex_commands_create_math_menu(GtkApplicationWindow * gtk_window)1795 latexila_latex_commands_create_math_menu (GtkApplicationWindow *gtk_window)
1796 {
1797 GtkMenuShell *menu;
1798 AmtkFactory *factory;
1799 AmtkApplicationWindow *amtk_window;
1800
1801 g_return_val_if_fail (GTK_IS_APPLICATION_WINDOW (gtk_window), NULL);
1802
1803 menu = GTK_MENU_SHELL (gtk_menu_new ());
1804
1805 add_menu_item_with_subentries (menu, "no-gaction-math-environments", action_info_entries_math_environments);
1806
1807 factory = amtk_factory_new_with_default_application ();
1808 gtk_menu_shell_append (menu, gtk_separator_menu_item_new ());
1809 gtk_menu_shell_append (menu, amtk_factory_create_menu_item (factory, "win.math-command-misc-superscript"));
1810 gtk_menu_shell_append (menu, amtk_factory_create_menu_item (factory, "win.math-command-misc-subscript"));
1811 gtk_menu_shell_append (menu, gtk_separator_menu_item_new ());
1812 gtk_menu_shell_append (menu, amtk_factory_create_menu_item (factory, "win.math-command-misc-frac"));
1813 gtk_menu_shell_append (menu, amtk_factory_create_menu_item (factory, "win.latex-command-with-braces::sqrt"));
1814 gtk_menu_shell_append (menu, amtk_factory_create_menu_item (factory, "win.math-command-misc-nth-root"));
1815 gtk_menu_shell_append (menu, gtk_separator_menu_item_new ());
1816 g_object_unref (factory);
1817
1818 add_menu_item_with_subentries (menu, "no-gaction-math-functions", action_info_entries_math_functions);
1819 add_menu_item_with_subentries (menu, "no-gaction-math-font-styles", action_info_entries_math_font_styles);
1820 add_menu_item_with_subentries (menu, "no-gaction-math-accents", action_info_entries_math_accents);
1821 add_menu_item_with_subentries (menu, "no-gaction-math-spaces", action_info_entries_math_spaces);
1822 add_menu_item_with_subentries (menu, "no-gaction-math-left-delimiters", action_info_entries_math_left_delimiters);
1823 add_menu_item_with_subentries (menu, "no-gaction-math-right-delimiters", action_info_entries_math_right_delimiters);
1824
1825 amtk_window = amtk_application_window_get_from_gtk_application_window (gtk_window);
1826 amtk_application_window_connect_menu_to_statusbar (amtk_window, menu);
1827
1828 gtk_widget_show_all (GTK_WIDGET (menu));
1829 return GTK_MENU (menu);
1830 }
1831