1 /* User interface for syntax selection.
3 Copyright (C) 2005, 2006 Leonard den Ottolander <leonard den ottolander nl>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License version 2 as
7 published by the Free Software Foundation.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software Foundation,
16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "../src/global.h"
22 #include "../src/wtools.h"
24 #define MAX_ENTRY_LEN 40
26 #define N_DFLT_ENTRIES 2
29 pstrcmp(const void *p1
, const void *p2
)
31 return strcmp(*(char**)p1
, *(char**)p2
);
35 exec_edit_syntax_dialog (const char **names
) {
38 Listbox
*syntaxlist
= create_listbox_window (MAX_ENTRY_LEN
, LIST_LINES
,
39 _(" Choose syntax highlighting "), NULL
);
40 LISTBOX_APPEND_TEXT (syntaxlist
, 'A', _("< Auto >"), NULL
);
41 LISTBOX_APPEND_TEXT (syntaxlist
, 'R', _("< Reload Current Syntax >"), NULL
);
43 for (i
= 0; names
[i
]; i
++) {
44 LISTBOX_APPEND_TEXT (syntaxlist
, 0, names
[i
], NULL
);
45 if (! option_auto_syntax
&& option_syntax_type
&&
46 (strcmp (names
[i
], option_syntax_type
) == 0))
47 listbox_select_by_number (syntaxlist
->list
, i
+ N_DFLT_ENTRIES
);
50 return run_listbox (syntaxlist
);
54 edit_syntax_dialog (void) {
55 char *old_syntax_type
;
56 int old_auto_syntax
, syntax
;
62 names
= (char**) g_malloc (sizeof (char*));
64 /* We fill the list of syntax files every time the editor is invoked.
65 Instead we could save the list to a file and update it once the syntax
66 file gets updated (either by testing or by explicit user command). */
67 edit_load_syntax (NULL
, &names
, NULL
);
68 while (names
[count
++] != NULL
);
69 qsort(names
, count
- 1, sizeof(char*), pstrcmp
);
71 if ((syntax
= exec_edit_syntax_dialog ((const char**) names
)) < 0) {
72 for (i
= 0; names
[i
]; i
++) {
79 old_auto_syntax
= option_auto_syntax
;
80 old_syntax_type
= g_strdup (option_syntax_type
);
83 case 0: /* auto syntax */
84 option_auto_syntax
= 1;
86 case 1: /* reload current syntax */
90 option_auto_syntax
= 0;
91 g_free (option_syntax_type
);
92 option_syntax_type
= g_strdup (names
[syntax
- N_DFLT_ENTRIES
]);
95 /* Load or unload syntax rules if the option has changed */
96 if ((option_auto_syntax
&& !old_auto_syntax
) || old_auto_syntax
||
97 (old_syntax_type
&& option_syntax_type
&&
98 (strcmp (old_syntax_type
, option_syntax_type
) != 0)) ||
100 edit_load_syntax (wedit
, NULL
, option_syntax_type
);
102 for (i
= 0; names
[i
]; i
++) {
106 g_free (old_syntax_type
);