geany  1.38
About: Geany is a text editor (using GTK2) with basic features of an integrated development environment (syntax highlighting, code folding, symbol name auto-completion, ...). F: office T: editor programming GTK+ IDE
  Fossies Dox: geany-1.38.tar.bz2  ("unofficial" and yet experimental doxygen-generated source code documentation)  

htmlchars.c
Go to the documentation of this file.
1/*
2 * htmlchars.c - this file is part of Geany, a fast and lightweight IDE
3 *
4 * Copyright 2007 The Geany contributors
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21/* HTML Characters plugin (Inserts HTML character entities like '&') */
22
23#ifdef HAVE_CONFIG_H
24# include "config.h"
25#endif
26
27#include "geanyplugin.h"
28#include <string.h>
29#include "SciLexer.h"
30
31
34
35
37
38PLUGIN_SET_INFO(_("HTML Characters"), _("Inserts HTML character entities like '&amp;'."), VERSION,
39 _("The Geany developer team"))
40
41
42/* Keybinding(s) */
43enum
44{
49};
50
51
52enum
53{
57};
58
59static GtkWidget *main_menu_item = NULL;
60static GtkWidget *main_menu = NULL;
61static GtkWidget *main_menu_submenu = NULL;
62static GtkWidget *menu_bulk_replace = NULL;
63static GtkWidget *sc_dialog = NULL;
64static GtkTreeStore *sc_store = NULL;
65static GtkTreeView *sc_tree = NULL;
66static GtkWidget *menu_htmltoggle = NULL;
67static gboolean plugin_active = FALSE;
68
69/* Configuration file */
70static gchar *config_file = NULL;
71
72const gchar *chars[][2] ={
73 { N_("HTML characters"), NULL },
74 { "\"", "&quot;" },
75 { "&", "&amp;" },
76 { "<", "&lt;" },
77 { ">", "&gt;" },
78
79 { N_("ISO 8859-1 characters"), NULL },
80 { " ", "&nbsp;" },
81 { "¡", "&iexcl;" },
82 { "¢", "&cent;" },
83 { "£", "&pound;" },
84 { "¤", "&curren;" },
85 { "¥", "&yen;" },
86 { "¦", "&brvbar;" },
87 { "§", "&sect;" },
88 { "¨", "&uml;" },
89 { "©", "&copy;" },
90 { "®", "&reg;" },
91 { "«", "&laquo;" },
92 { "»", "&raquo;" },
93 { "¬", "&not;" },
94 { " ", "&shy;" },
95 { "¯", "&macr;" },
96 { "°", "&deg;" },
97 { "±", "&plusmn;" },
98 { "¹", "&sup1;" },
99 { "²", "&sup2;" },
100 { "³", "&sup3;" },
101 { "¼", "&frac14;" },
102 { "½", "&frac12;" },
103 { "¾", "&frac34;" },
104 { "×", "&times;" },
105 { "÷", "&divide;" },
106 { "´", "&acute;" },
107 { "µ", "&micro;" },
108 { "¶", "&para;" },
109 { "·", "&middot;" },
110 { "¸", "&cedil;" },
111 { "ª", "&ordf;" },
112 { "º", "&ordm;" },
113 { "¿", "&iquest;" },
114 { "À", "&Agrave;" },
115 { "Á", "&Aacute;" },
116 { "Â", "&Acirc;" },
117 { "Ã", "&Atilde;" },
118 { "Ä", "&Auml;" },
119 { "Å", "&Aring;" },
120 { "Æ", "&AElig;" },
121 { "Ç", "&Ccedil;" },
122 { "È", "&Egrave;" },
123 { "É", "&Eacute;" },
124 { "Ê", "&Ecirc;" },
125 { "Ë", "&Euml;" },
126 { "Ì", "&Igrave;" },
127 { "Í", "&Iacute;" },
128 { "Î", "&Icirc;" },
129 { "Ï", "&Iuml;" },
130 { "Ð", "&ETH;" },
131 { "Ñ", "&Ntilde;" },
132 { "Ò", "&Ograve;" },
133 { "Ó", "&Oacute;" },
134 { "Ô", "&Ocirc;" },
135 { "Õ", "&Otilde;" },
136 { "Ö", "&Ouml;" },
137 { "Ø", "&Oslash;" },
138 { "Ù", "&Ugrave;" },
139 { "Ú", "&Uacute;" },
140 { "Û", "&Ucirc;" },
141 { "Ü", "&Uuml;" },
142 { "Ý", "&Yacute;" },
143 { "Þ", "&THORN;" },
144 { "ß", "&szlig;" },
145 { "à", "&agrave;" },
146 { "á", "&aacute;" },
147 { "â", "&acirc;" },
148 { "ã", "&atilde;" },
149 { "ä", "&auml;" },
150 { "å", "&aring;" },
151 { "æ", "&aelig;" },
152 { "ç", "&ccedil;" },
153 { "è", "&egrave;" },
154 { "é", "&eacute;" },
155 { "ê", "&ecirc;" },
156 { "ë", "&euml;" },
157 { "ì", "&igrave;" },
158 { "í", "&iacute;" },
159 { "î", "&icirc;" },
160 { "ï", "&iuml;" },
161 { "ð", "&eth;" },
162 { "ñ", "&ntilde;" },
163 { "ò", "&ograve;" },
164 { "ó", "&oacute;" },
165 { "ô", "&ocirc;" },
166 { "õ", "&otilde;" },
167 { "ö", "&ouml;" },
168 { "ø", "&oslash;" },
169 { "ù", "&ugrave;" },
170 { "ú", "&uacute;" },
171 { "û", "&ucirc;" },
172 { "ü", "&uuml;" },
173 { "ý", "&yacute;" },
174 { "þ", "&thorn;" },
175 { "ÿ", "&yuml;" },
176
177 { N_("Greek characters"), NULL },
178 { "Α", "&Alpha;" },
179 { "α", "&alpha;" },
180 { "Β", "&Beta;" },
181 { "β", "&beta;" },
182 { "Γ", "&Gamma;" },
183 { "γ", "&gamma;" },
184 { "Δ", "&Delta;" },
185 { "δ", "&Delta;" },
186 { "δ", "&delta;" },
187 { "Ε", "&Epsilon;" },
188 { "ε", "&epsilon;" },
189 { "Ζ", "&Zeta;" },
190 { "ζ", "&zeta;" },
191 { "Η", "&Eta;" },
192 { "η", "&eta;" },
193 { "Θ", "&Theta;" },
194 { "θ", "&theta;" },
195 { "Ι", "&Iota;" },
196 { "ι", "&iota;" },
197 { "Κ", "&Kappa;" },
198 { "κ", "&kappa;" },
199 { "Λ", "&Lambda;" },
200 { "λ", "&lambda;" },
201 { "Μ", "&Mu;" },
202 { "μ", "&mu;" },
203 { "Ν", "&Nu;" },
204 { "ν", "&nu;" },
205 { "Ξ", "&Xi;" },
206 { "ξ", "&xi;" },
207 { "Ο", "&Omicron;" },
208 { "ο", "&omicron;" },
209 { "Π", "&Pi;" },
210 { "π", "&pi;" },
211 { "Ρ", "&Rho;" },
212 { "ρ", "&rho;" },
213 { "Σ", "&Sigma;" },
214 { "ς", "&sigmaf;" },
215 { "σ", "&sigma;" },
216 { "Τ", "&Tau;" },
217 { "τ", "&tau;" },
218 { "Υ", "&Upsilon;" },
219 { "υ", "&upsilon;" },
220 { "Φ", "&Phi;" },
221 { "φ", "&phi;" },
222 { "Χ", "&Chi;" },
223 { "χ", "&chi;" },
224 { "Ψ", "&Psi;" },
225 { "ψ", "&psi;" },
226 { "Ω", "&Omega;" },
227 { "ω", "&omega;" },
228 { "ϑ", "&thetasym;" },
229 { "ϒ", "&upsih;" },
230 { "ϖ", "&piv;" },
231
232 { N_("Mathematical characters"), NULL },
233 { "∀", "&forall;" },
234 { "∂", "&part;" },
235 { "∃", "&exist;" },
236 { "∅", "&empty;" },
237 { "∇", "&nabla;" },
238 { "∈", "&isin;" },
239 { "∉", "&notin;" },
240 { "∋", "&ni;" },
241 { "∏", "&prod;" },
242 { "∑", "&sum;" },
243 { "−", "&minus;" },
244 { "∗", "&lowast;" },
245 { "√", "&radic;" },
246 { "∝", "&prop;" },
247 { "∞", "&infin;" },
248 { "∠", "&ang;" },
249 { "∧", "&and;" },
250 { "∨", "&or;" },
251 { "∩", "&cap;" },
252 { "∪", "&cup;" },
253 { "∫", "&int;" },
254 { "∴", "&there4;" },
255 { "∼", "&sim;" },
256 { "≅", "&cong;" },
257 { "≈", "&asymp;" },
258 { "≠", "&ne;" },
259 { "≡", "&equiv;" },
260 { "≤", "&le;" },
261 { "≥", "&ge;" },
262 { "⊂", "&sub;" },
263 { "⊃", "&sup;" },
264 { "⊄", "&nsub;" },
265 { "⊆", "&sube;" },
266 { "⊇", "&supe;" },
267 { "⊕", "&oplus;" },
268 { "⊗", "&otimes;" },
269 { "⊥", "&perp;" },
270 { "⋅", "&sdot;" },
271 { "◊", "&loz;" },
272
273 { N_("Technical characters"), NULL },
274 { "⌈", "&lceil;" },
275 { "⌉", "&rceil;" },
276 { "⌊", "&lfloor;" },
277 { "⌋", "&rfloor;" },
278 { "〈", "&lang;" },
279 { "〉", "&rang;" },
280
281 { N_("Arrow characters"), NULL },
282 { "←", "&larr;" },
283 { "↑", "&uarr;" },
284 { "→", "&rarr;" },
285 { "↓", "&darr;" },
286 { "↔", "&harr;" },
287 { "↵", "&crarr;" },
288 { "⇐", "&lArr;" },
289 { "⇑", "&uArr;" },
290 { "⇒", "&rArr;" },
291 { "⇓", "&dArr;" },
292 { "⇔", "&hArr;" },
293
294 { N_("Punctuation characters"), NULL },
295 { "–", "&ndash;" },
296 { "—", "&mdash;" },
297 { "‘", "&lsquo;" },
298 { "’", "&rsquo;" },
299 { "‚", "&sbquo;" },
300 { "“", "&ldquo;" },
301 { "”", "&rdquo;" },
302 { "„", "&bdquo;" },
303 { "†", "&dagger;" },
304 { "‡", "&Dagger;" },
305 { "…", "&hellip;" },
306 { "‰", "&permil;" },
307 { "‹", "&lsaquo;" },
308 { "›", "&rsaquo;" },
309
310 { N_("Miscellaneous characters"), NULL },
311 { "•", "&bull;" },
312 { "′", "&prime;" },
313 { "″", "&Prime;" },
314 { "‾", "&oline;" },
315 { "⁄", "&frasl;" },
316 { "℘", "&weierp;" },
317 { "ℑ", "&image;" },
318 { "ℜ", "&real;" },
319 { "™", "&trade;" },
320 { "€", "&euro;" },
321 { "ℵ", "&alefsym;" },
322 { "♠", "&spades;" },
323 { "♣", "&clubs;" },
324 { "♥", "&hearts;" },
325 { "♦", "&diams;" },
326 { "Œ", "&OElig;" },
327 { "œ", "&oelig;" },
328 { "Š", "&Scaron;" },
329 { "š", "&scaron;" },
330 { "Ÿ", "&Yuml;" },
331 { "ƒ", "&fnof;" },
332};
333
334static gboolean ht_editor_notify_cb(GObject *object, GeanyEditor *editor,
335 SCNotification *nt, gpointer data);
336
337
339{
340 { "editor-notify", (GCallback) &ht_editor_notify_cb, FALSE, NULL },
341 { NULL, NULL, FALSE, NULL }
342};
343
344
345/* Functions to toggle the status of plugin */
346static void set_status(gboolean new_status)
347{
348 if (plugin_active != new_status)
349 {
350 GKeyFile *config = g_key_file_new();
351 gchar *data;
352 gchar *config_dir = g_path_get_dirname(config_file);
353
354 plugin_active = new_status;
355
356 /* Now we save the new status into configuration file to
357 * remember next time */
358 g_key_file_set_boolean(config, "general", "replacement_on_typing_active",
360
361 if (!g_file_test(config_dir, G_FILE_TEST_IS_DIR)
362 && utils_mkdir(config_dir, TRUE) != 0)
363 {
364 dialogs_show_msgbox(GTK_MESSAGE_ERROR,
365 _("Plugin configuration directory could not be created."));
366 }
367 else
368 {
369 /* write config to file */
370 data = g_key_file_to_data(config, NULL, NULL);
372 g_free(data);
373 }
374 g_free(config_dir);
375 g_key_file_free(config);
376 }
377}
378
379
380static void toggle_status(G_GNUC_UNUSED GtkMenuItem * menuitem)
381{
382 if (plugin_active == TRUE)
383 set_status(FALSE);
384 else
385 set_status(TRUE);
386}
387
388
390 (GtkDialog *dialog, gint response, gpointer user_data);
391static void sc_on_tree_row_activated
392 (GtkTreeView *treeview, GtkTreePath *path, GtkTreeViewColumn *col, gpointer user_data);
393static void sc_fill_store(GtkTreeStore *store);
394static gboolean sc_insert(GtkTreeModel *model, GtkTreeIter *iter);
395
396
397/* Function takes over value of key which was pressed and returns
398 * HTML/SGML entity if any */
399static const gchar *get_entity(gchar *letter)
400{
401 guint i, len;
402
403 len = G_N_ELEMENTS(chars);
404
405 /* Ignore tags marking caracters as well as spaces*/
406 for (i = 7; i < len; i++)
407 {
408 if (utils_str_equal(chars[i][0], letter) &&
409 !utils_str_equal(" ", letter))
410 {
411 return chars[i][1];
412 }
413 }
414
415 /* if the char is not in the list */
416 return NULL;
417}
418
419
420static gboolean ht_editor_notify_cb(GObject *object, GeanyEditor *editor,
421 SCNotification *nt, gpointer data)
422{
423 gint lexer;
424
425 g_return_val_if_fail(editor != NULL, FALSE);
426
427 if (!plugin_active)
428 return FALSE;
429
430 lexer = sci_get_lexer(editor->sci);
431 if (lexer != SCLEX_HTML && lexer != SCLEX_XML)
432 return FALSE;
433
434 if (nt->nmhdr.code == SCN_CHARADDED)
435 {
436 gchar buf[7];
437 gint len;
438
439 len = g_unichar_to_utf8(nt->ch, buf);
440 if (len > 0)
441 {
442 const gchar *entity;
443 buf[len] = '\0';
444 entity = get_entity(buf);
445
446 if (entity != NULL)
447 {
448 gint pos = sci_get_current_position(editor->sci);
449
450 sci_set_selection_start(editor->sci, pos - len);
451 sci_set_selection_end(editor->sci, pos);
452
453 sci_replace_sel(editor->sci, entity);
454 }
455 }
456 }
457
458 return FALSE;
459}
460
461
462/* Called when keys were pressed */
463static void kbhtmltoggle_toggle(G_GNUC_UNUSED guint key_id)
464{
465 if (plugin_active == TRUE)
466 {
467 set_status(FALSE);
468 }
469 else
470 {
471 set_status(TRUE);
472 }
473}
474
475
477{
478 if (sc_dialog == NULL)
479 {
480 gint height;
481 GtkCellRenderer *renderer;
482 GtkTreeViewColumn *column;
483 GtkWidget *swin, *vbox, *label;
484
485 sc_dialog = gtk_dialog_new_with_buttons(
486 _("Special Characters"), GTK_WINDOW(geany->main_widgets->window),
487 GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
488 _("_Insert"), GTK_RESPONSE_OK, NULL);
489 vbox = ui_dialog_vbox_new(GTK_DIALOG(sc_dialog));
490 gtk_box_set_spacing(GTK_BOX(vbox), 6);
491 gtk_widget_set_name(sc_dialog, "GeanyDialog");
492
494 gtk_window_set_default_size(GTK_WINDOW(sc_dialog), height * 8 / 10, height);
495 gtk_dialog_set_default_response(GTK_DIALOG(sc_dialog), GTK_RESPONSE_CANCEL);
496
497 label = gtk_label_new(_("Choose a special character from the list below and double click on it or use the button to insert it at the current cursor position."));
498 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
499 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
500 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
501
502 sc_tree = GTK_TREE_VIEW(gtk_tree_view_new());
503
504 sc_store = gtk_tree_store_new(N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING);
505 gtk_tree_view_set_model(GTK_TREE_VIEW(sc_tree),
506 GTK_TREE_MODEL(sc_store));
507 g_object_unref(sc_store);
508
509 renderer = gtk_cell_renderer_text_new();
510 column = gtk_tree_view_column_new_with_attributes(
511 _("Character"), renderer, "text", COLUMN_CHARACTER, NULL);
512 gtk_tree_view_column_set_resizable(column, TRUE);
513 gtk_tree_view_append_column(GTK_TREE_VIEW(sc_tree), column);
514
515 renderer = gtk_cell_renderer_text_new();
516 column = gtk_tree_view_column_new_with_attributes(
517 _("HTML (name)"), renderer, "text", COLUMN_HTML_NAME, NULL);
518 gtk_tree_view_column_set_resizable(column, TRUE);
519 gtk_tree_view_append_column(GTK_TREE_VIEW(sc_tree), column);
520
521 swin = gtk_scrolled_window_new(NULL, NULL);
522 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(swin), GTK_POLICY_AUTOMATIC,
523 GTK_POLICY_AUTOMATIC);
524 gtk_container_add(GTK_CONTAINER(swin), GTK_WIDGET(sc_tree));
525 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(swin), GTK_SHADOW_IN);
526
527 gtk_box_pack_start(GTK_BOX(vbox), swin, TRUE, TRUE, 0);
528
529 g_signal_connect(sc_tree, "row-activated", G_CALLBACK(sc_on_tree_row_activated), NULL);
530
531 g_signal_connect(sc_dialog, "response",
533
534 g_signal_connect(sc_dialog, "delete-event", G_CALLBACK(gtk_widget_hide_on_delete), NULL);
535
537
538 /*gtk_tree_view_expand_all(special_characters_tree);*/
539 gtk_tree_view_set_search_column(sc_tree, COLUMN_HTML_NAME);
540 }
542}
543
544
545/* fill the tree model with data
546 ** TODO move this in a file and make it extendable for more data types */
547static void sc_fill_store(GtkTreeStore *store)
548{
549 GtkTreeIter iter;
550 GtkTreeIter *parent_iter = NULL;
551 guint i, len;
552
553 len = G_N_ELEMENTS(chars);
554 for (i = 0; i < len; i++)
555 {
556 if (chars[i][1] == NULL)
557 { /* add a category */
558 gtk_tree_store_append(store, &iter, NULL);
559 gtk_tree_store_set(store, &iter, COLUMN_CHARACTER, _(chars[i][0]), -1);
560 if (parent_iter != NULL) gtk_tree_iter_free(parent_iter);
561 parent_iter = gtk_tree_iter_copy(&iter);
562 }
563 else
564 { /* add child to parent_iter */
565 gtk_tree_store_append(store, &iter, parent_iter);
566 gtk_tree_store_set(store, &iter, COLUMN_CHARACTER, chars[i][0],
567 COLUMN_HTML_NAME, chars[i][1], -1);
568 }
569 }
570}
571
572
573/* just inserts the HTML_NAME coloumn of the selected row at current position
574 * returns only TRUE if a valid selection(i.e. no category) could be found */
575static gboolean sc_insert(GtkTreeModel *model, GtkTreeIter *iter)
576{
578 gboolean result = FALSE;
579
580 if (doc != NULL)
581 {
582 gchar *str;
584
585 gtk_tree_model_get(model, iter, COLUMN_HTML_NAME, &str, -1);
586 if (!EMPTY(str))
587 {
588 sci_insert_text(doc->editor->sci, pos, str);
589 g_free(str);
590 result = TRUE;
591 }
592 }
593 return result;
594}
595
596
598 gpointer user_data)
599{
600 if (response == GTK_RESPONSE_OK)
601 {
602 GtkTreeSelection *selection;
603 GtkTreeModel *model;
604 GtkTreeIter iter;
605
606 selection = gtk_tree_view_get_selection(sc_tree);
607
608 if (gtk_tree_selection_get_selected(selection, &model, &iter))
609 {
610 /* only hide dialog if selection was not a category */
611 if (sc_insert(model, &iter))
612 gtk_widget_hide(GTK_WIDGET(dialog));
613 }
614 }
615 else
616 gtk_widget_hide(GTK_WIDGET(dialog));
617}
618
619
620static void sc_on_tree_row_activated(GtkTreeView *treeview, GtkTreePath *path,
621 GtkTreeViewColumn *col, gpointer user_data)
622{
623 GtkTreeIter iter;
624 GtkTreeModel *model = GTK_TREE_MODEL(sc_store);
625
626 if (gtk_tree_model_get_iter(model, &iter, path))
627 {
628 /* only hide dialog if selection was not a category */
629 if (sc_insert(model, &iter))
630 gtk_widget_hide(sc_dialog);
631 else
632 { /* double click on a category to toggle the expand or collapse it */
633 if (gtk_tree_view_row_expanded(sc_tree, path))
634 gtk_tree_view_collapse_row(sc_tree, path);
635 else
636 gtk_tree_view_expand_row(sc_tree, path, FALSE);
637 }
638 }
639}
640
641
643{
644 GeanyDocument *doc = NULL;
645 doc = document_get_current();
646
647 if (doc != NULL && sci_has_selection(doc->editor->sci))
648 {
649 gsize selection_len;
650 gchar *selection;
651 GString *replacement = g_string_new(NULL);
652 gsize i;
653 gchar *new;
654 const gchar *entity = NULL;
655 gchar buf[7];
656 gint len;
657
658 selection = sci_get_selection_contents(doc->editor->sci);
659
660 selection_len = strlen(selection);
661 for (i = 0; i < selection_len; i++)
662 {
663 len = g_unichar_to_utf8(g_utf8_get_char(selection + i), buf);
664 i = (guint)len - 1 + i;
665
666 buf[len] = '\0';
667 entity = get_entity(buf);
668
669 if (entity != NULL)
670 {
671 replacement = g_string_append(replacement, entity);
672 }
673 else
674 {
675 replacement = g_string_append(replacement, buf);
676 }
677 }
678 new = g_string_free(replacement, FALSE);
679 sci_replace_sel(doc->editor->sci, new);
680 g_free(selection);
681 g_free(new);
682 }
683}
684
685
686/* Callback for special chars menu */
687static void
688item_activate(GtkMenuItem *menuitem, gpointer gdata)
689{
691}
692
693
694static void kb_activate(G_GNUC_UNUSED guint key_id)
695{
697}
698
699
700/* Callback for bulk replacement of selected text */
701static void
702replace_special_character_activated(GtkMenuItem *menuitem, gpointer gdata)
703{
705}
706
707
708static void kb_special_chars_replacement(G_GNUC_UNUSED guint key_id)
709{
711}
712
713
714static void init_configuration(void)
715{
716 GKeyFile *config = g_key_file_new();
717
718 /* loading configurations from file ...*/
719 config_file = g_strconcat(geany->app->configdir, G_DIR_SEPARATOR_S,
720 "plugins", G_DIR_SEPARATOR_S,
721 "htmchars", G_DIR_SEPARATOR_S, "general.conf", NULL);
722
723 /* ... and initialising options from config file */
724 g_key_file_load_from_file(config, config_file, G_KEY_FILE_NONE, NULL);
725
726 plugin_active = utils_get_setting_boolean(config, "general",
727 "replacement_on_typing_active", FALSE);
728}
729
730
731/* Called by Geany to initialise the plugin */
733{
734 GeanyKeyGroup *key_group;
735 GtkWidget *menu_item;
736 const gchar *menu_text = _("_Insert Special HTML Characters...");
737
738 /* First we catch the configuration and initialize them */
740
741 /* Add an item to the Tools menu for html chars dialog*/
742 menu_item = gtk_menu_item_new_with_mnemonic(menu_text);
743 gtk_widget_show(menu_item);
744 gtk_container_add(GTK_CONTAINER(geany->main_widgets->tools_menu), menu_item);
745 g_signal_connect(menu_item, "activate", G_CALLBACK(item_activate), NULL);
746
747 /* disable menu_item when there are no documents open */
748 ui_add_document_sensitive(menu_item);
749
750 /* Add menuitem for html replacement functions*/
751 main_menu = gtk_menu_item_new_with_mnemonic(_("_HTML Replacement"));
753 gtk_container_add(GTK_CONTAINER(geany->main_widgets->tools_menu), main_menu);
754
755 main_menu_submenu = gtk_menu_new();
756 gtk_menu_item_set_submenu(GTK_MENU_ITEM(main_menu), main_menu_submenu);
757
758 menu_htmltoggle = gtk_check_menu_item_new_with_mnemonic(_("_Auto-replace Special Characters"));
759 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM(menu_htmltoggle),
762
763 g_signal_connect((gpointer) menu_htmltoggle, "activate",
764 G_CALLBACK(toggle_status), NULL);
765
766 menu_bulk_replace = gtk_menu_item_new_with_mnemonic(
767 _("_Replace Characters in Selection"));
768 g_signal_connect((gpointer) menu_bulk_replace, "activate",
770
772
774 gtk_widget_show(menu_bulk_replace);
775 gtk_widget_show(menu_htmltoggle);
776
777 main_menu_item = menu_item;
778
779 /* setup keybindings */
780 key_group = plugin_set_key_group(geany_plugin, "html_chars", KB_COUNT, NULL);
782 kb_activate, 0, 0, "insert_html_chars",
783 _("Insert Special HTML Characters"), menu_item);
785 kb_special_chars_replacement, 0, 0, "replace_special_characters",
786 _("Replace special characters"), NULL);
788 kbhtmltoggle_toggle, 0, 0, "htmltoogle_toggle_plugin_status",
789 _("Toggle plugin status"), menu_htmltoggle);
790}
791
792
793/* Destroy widgets */
795{
796 gtk_widget_destroy(main_menu_item);
797 gtk_widget_destroy(main_menu);
798
799 if (sc_dialog != NULL)
800 gtk_widget_destroy(sc_dialog);
801
802 if (config_file != NULL)
803 g_free(config_file);
804}
Interface to the added lexer functions in the SciLexer version of the edit control.
#define SCLEX_HTML
Definition: SciLexer.h:21
#define SCLEX_XML
Definition: SciLexer.h:22
#define SCN_CHARADDED
Definition: Scintilla.h:1127
const gchar * label
Definition: build.c:2676
void dialogs_show_msgbox(GtkMessageType type, const gchar *text,...)
Shows a message box of the type type with text.
Definition: dialogs.c:729
GeanyDocument * document_get_current(void)
Finds the current document.
Definition: document.c:371
gint pos
Definition: editor.c:87
#define GEANY_DEFAULT_DIALOG_HEIGHT
Definition: geany.h:50
Single include for plugins.
static GtkWidget * main_menu_submenu
Definition: htmlchars.c:61
static void sc_on_tools_show_dialog_insert_special_chars_response(GtkDialog *dialog, gint response, gpointer user_data)
Definition: htmlchars.c:597
static GtkWidget * sc_dialog
Definition: htmlchars.c:63
static void init_configuration(void)
Definition: htmlchars.c:714
static void tools_show_dialog_insert_special_chars(void)
Definition: htmlchars.c:476
static const gchar * get_entity(gchar *letter)
Definition: htmlchars.c:399
static void sc_fill_store(GtkTreeStore *store)
Definition: htmlchars.c:547
static GtkTreeView * sc_tree
Definition: htmlchars.c:65
GeanyPlugin * geany_plugin
Definition: htmlchars.c:32
static void kb_special_chars_replacement(G_GNUC_UNUSED guint key_id)
Definition: htmlchars.c:708
static gchar * config_file
Definition: htmlchars.c:70
void plugin_cleanup(void)
Called before unloading the plugin.
Definition: htmlchars.c:794
PluginCallback plugin_callbacks[]
Definition: htmlchars.c:338
static gboolean plugin_active
Definition: htmlchars.c:67
static GtkWidget * menu_htmltoggle
Definition: htmlchars.c:66
static void replace_special_character_activated(GtkMenuItem *menuitem, gpointer gdata)
Definition: htmlchars.c:702
static void kbhtmltoggle_toggle(G_GNUC_UNUSED guint key_id)
Definition: htmlchars.c:463
static void replace_special_character(void)
Definition: htmlchars.c:642
static GtkWidget * main_menu
Definition: htmlchars.c:60
@ KB_REPLACE_HTML_ENTITIES
Definition: htmlchars.c:46
@ KB_INSERT_HTML_CHARS
Definition: htmlchars.c:45
@ KB_HTMLTOGGLE_ACTIVE
Definition: htmlchars.c:47
@ KB_COUNT
Definition: htmlchars.c:48
static GtkWidget * main_menu_item
Definition: htmlchars.c:59
static void toggle_status(G_GNUC_UNUSED GtkMenuItem *menuitem)
Definition: htmlchars.c:380
static void set_status(gboolean new_status)
Definition: htmlchars.c:346
void plugin_init(GeanyData *data)
Called after loading the plugin.
Definition: htmlchars.c:732
static GtkWidget * menu_bulk_replace
Definition: htmlchars.c:62
static GtkTreeStore * sc_store
Definition: htmlchars.c:64
@ COLUMN_CHARACTER
Definition: htmlchars.c:54
@ COLUMN_HTML_NAME
Definition: htmlchars.c:55
@ N_COLUMNS
Definition: htmlchars.c:56
GeanyData * geany_data
Definition: htmlchars.c:33
static void sc_on_tree_row_activated(GtkTreeView *treeview, GtkTreePath *path, GtkTreeViewColumn *col, gpointer user_data)
Definition: htmlchars.c:620
const gchar * chars[][2]
Definition: htmlchars.c:72
static void item_activate(GtkMenuItem *menuitem, gpointer gdata)
Definition: htmlchars.c:688
static void kb_activate(G_GNUC_UNUSED guint key_id)
Definition: htmlchars.c:694
static gboolean ht_editor_notify_cb(GObject *object, GeanyEditor *editor, SCNotification *nt, gpointer data)
Definition: htmlchars.c:420
static gboolean sc_insert(GtkTreeModel *model, GtkTreeIter *iter)
Definition: htmlchars.c:575
GeanyKeyBinding * keybindings_set_item(GeanyKeyGroup *group, gsize key_id, GeanyKeyCallback callback, guint key, GdkModifierType mod, const gchar *kf_name, const gchar *label, GtkWidget *menu_item)
<simplesect kind="geany:skip"></simplesect> Fills a GeanyKeyBinding struct item.
Definition: keybindings.c:171
#define GEANY_API_VERSION
The Application Programming Interface (API) version, incremented whenever any plugin data types are m...
Definition: plugindata.h:61
#define PLUGIN_SET_INFO(p_name, p_description, p_version, p_author)
Sets the plugin name and some other basic information about a plugin.
Definition: plugindata.h:117
#define PLUGIN_VERSION_CHECK(api_required)
Defines a function to check the plugin is safe to load.
Definition: plugindata.h:83
#define geany
Simple macro for geany_data that reduces typing.
Definition: plugindata.h:225
GeanyKeyGroup * plugin_set_key_group(GeanyPlugin *plugin, const gchar *section_name, gsize count, GeanyKeyGroupCallback callback)
<simplesect kind="geany:skip"></simplesect> Sets up or resizes a keybinding group for the plugin.
Definition: pluginutils.c:331
#define NULL
Definition: rbtree.h:150
gchar * sci_get_selection_contents(ScintillaObject *sci)
Gets selected text.
Definition: sciwrappers.c:778
gint sci_get_current_position(ScintillaObject *sci)
Gets the cursor position.
Definition: sciwrappers.c:507
void sci_set_selection_start(ScintillaObject *sci, gint position)
Sets the selection start position.
Definition: sciwrappers.c:565
void sci_replace_sel(ScintillaObject *sci, const gchar *text)
Replaces selection.
Definition: sciwrappers.c:646
gint sci_get_lexer(ScintillaObject *sci)
Gets the currently used lexer.
Definition: sciwrappers.c:667
gboolean sci_has_selection(ScintillaObject *sci)
Checks if there's a selection.
Definition: sciwrappers.c:920
void sci_insert_text(ScintillaObject *sci, gint pos, const gchar *text)
Inserts text.
Definition: sciwrappers.c:1133
void sci_set_selection_end(ScintillaObject *sci, gint position)
Sets the selection end position.
Definition: sciwrappers.c:575
GtkWidget * dialog
gtk_container_add(GTK_CONTAINER(dialog->vbox), check_button)
gtk_widget_show_all(dialog)
This contains pointers to global variables owned by Geany for plugins to use.
Definition: plugindata.h:167
Structure for representing an open tab with all its properties.
Definition: document.h:81
GeanyEditor * editor
The editor associated with the document.
Definition: document.h:98
Editor-owned fields for each document.
Definition: editor.h:150
ScintillaObject * sci
The Scintilla editor GtkWidget.
Definition: editor.h:152
Basic information for the plugin and identification.
Definition: plugindata.h:233
Callback array entry type used with the plugin_callbacks symbol.
Definition: plugindata.h:148
Sci_NotifyHeader nmhdr
Definition: Scintilla.h:1229
unsigned int code
Definition: Scintilla.h:1225
#define _(String)
Definition: support.h:42
#define N_(String)
Definition: support.h:43
void ui_add_document_sensitive(GtkWidget *widget)
Adds a widget to the list of widgets that should be set sensitive/insensitive when some documents are...
Definition: ui_utils.c:976
GtkWidget * ui_dialog_vbox_new(GtkDialog *dialog)
Makes a fixed border for dialogs without increasing the button box border.
Definition: ui_utils.c:1499
gint utils_write_file(const gchar *filename, const gchar *text)
Writes text into a file named filename.
Definition: utils.c:209
gboolean utils_get_setting_boolean(GKeyFile *config, const gchar *section, const gchar *key, const gboolean default_value)
Wraps g_key_file_get_boolean() to add a default value argument.
Definition: utils.c:836
gint utils_mkdir(const gchar *path, gboolean create_parent_dirs)
Creates a directory if it doesn't already exist.
Definition: utils.c:1359
gboolean utils_str_equal(const gchar *a, const gchar *b)
NULL-safe string comparison.
Definition: utils.c:599
#define EMPTY(ptr)
Returns TRUE if ptr is NULL or *ptr is FALSE.
Definition: utils.h:38