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.
20 * \brief Source: user %interface for syntax %selection
21 * \author Leonard den Ottolander
29 #include "lib/global.h"
30 #include "src/wtools.h"
32 #include "edit-impl.h"
34 #define MAX_ENTRY_LEN 40
36 #define N_DFLT_ENTRIES 2
39 pstrcmp(const void *p1
, const void *p2
)
41 return strcmp(*(char**)p1
, *(char**)p2
);
45 exec_edit_syntax_dialog (const char **names
) {
48 Listbox
*syntaxlist
= create_listbox_window (LIST_LINES
, MAX_ENTRY_LEN
,
49 _(" Choose syntax highlighting "), NULL
);
50 LISTBOX_APPEND_TEXT (syntaxlist
, 'A', _("< Auto >"), NULL
);
51 LISTBOX_APPEND_TEXT (syntaxlist
, 'R', _("< Reload Current Syntax >"), NULL
);
53 for (i
= 0; names
[i
]; i
++) {
54 LISTBOX_APPEND_TEXT (syntaxlist
, 0, names
[i
], NULL
);
55 if (! option_auto_syntax
&& option_syntax_type
56 && (strcmp (names
[i
], option_syntax_type
) == 0))
57 listbox_select_entry (syntaxlist
->list
, i
+ N_DFLT_ENTRIES
);
60 return run_listbox (syntaxlist
);
64 edit_syntax_dialog (void) {
65 char *old_syntax_type
;
66 int old_auto_syntax
, syntax
;
72 names
= (char**) g_malloc (sizeof (char*));
74 /* We fill the list of syntax files every time the editor is invoked.
75 Instead we could save the list to a file and update it once the syntax
76 file gets updated (either by testing or by explicit user command). */
77 edit_load_syntax (NULL
, &names
, NULL
);
78 while (names
[count
++] != NULL
);
79 qsort(names
, count
- 1, sizeof(char*), pstrcmp
);
81 if ((syntax
= exec_edit_syntax_dialog ((const char**) names
)) < 0) {
82 for (i
= 0; names
[i
]; i
++) {
89 old_auto_syntax
= option_auto_syntax
;
90 old_syntax_type
= g_strdup (option_syntax_type
);
93 case 0: /* auto syntax */
94 option_auto_syntax
= 1;
96 case 1: /* reload current syntax */
100 option_auto_syntax
= 0;
101 g_free (option_syntax_type
);
102 option_syntax_type
= g_strdup (names
[syntax
- N_DFLT_ENTRIES
]);
105 /* Load or unload syntax rules if the option has changed */
106 if ((option_auto_syntax
&& !old_auto_syntax
) || old_auto_syntax
||
107 (old_syntax_type
&& option_syntax_type
&&
108 (strcmp (old_syntax_type
, option_syntax_type
) != 0)) ||
110 edit_load_syntax (wedit
, NULL
, option_syntax_type
);
112 for (i
= 0; names
[i
]; i
++) {
116 g_free (old_syntax_type
);