Completely removed MHL stuff
[midnight-commander.git] / edit / choosesyntax.c
blob78a7718c06854aeb544b089b0e8b314462c7b5d5
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.
19 #include <config.h>
21 #include "edit.h"
22 #include "../src/global.h"
23 #include "../src/wtools.h"
25 #define MAX_ENTRY_LEN 40
26 #define LIST_LINES 14
27 #define N_DFLT_ENTRIES 2
29 static int
30 pstrcmp(const void *p1, const void *p2)
32 return strcmp(*(char**)p1, *(char**)p2);
35 static int
36 exec_edit_syntax_dialog (const char **names) {
37 int i;
39 Listbox *syntaxlist = create_listbox_window (MAX_ENTRY_LEN, LIST_LINES,
40 _(" Choose syntax highlighting "), NULL);
41 LISTBOX_APPEND_TEXT (syntaxlist, 'A', _("< Auto >"), NULL);
42 LISTBOX_APPEND_TEXT (syntaxlist, 'R', _("< Reload Current Syntax >"), NULL);
44 for (i = 0; names[i]; i++) {
45 LISTBOX_APPEND_TEXT (syntaxlist, 0, names[i], NULL);
46 if (! option_auto_syntax && option_syntax_type &&
47 (strcmp (names[i], option_syntax_type) == 0))
48 listbox_select_by_number (syntaxlist->list, i + N_DFLT_ENTRIES);
51 return run_listbox (syntaxlist);
54 void
55 edit_syntax_dialog (void) {
56 char *old_syntax_type;
57 int old_auto_syntax, syntax;
58 char **names;
59 int i;
60 int force_reload = 0;
61 int count = 0;
63 names = (char**) g_malloc (sizeof (char*));
64 names[0] = NULL;
65 /* We fill the list of syntax files every time the editor is invoked.
66 Instead we could save the list to a file and update it once the syntax
67 file gets updated (either by testing or by explicit user command). */
68 edit_load_syntax (NULL, &names, NULL);
69 while (names[count++] != NULL);
70 qsort(names, count - 1, sizeof(char*), pstrcmp);
72 if ((syntax = exec_edit_syntax_dialog ((const char**) names)) < 0) {
73 for (i = 0; names[i]; i++) {
74 g_free (names[i]);
76 g_free (names);
77 return;
80 old_auto_syntax = option_auto_syntax;
81 old_syntax_type = g_strdup (option_syntax_type);
83 switch (syntax) {
84 case 0: /* auto syntax */
85 option_auto_syntax = 1;
86 break;
87 case 1: /* reload current syntax */
88 force_reload = 1;
89 break;
90 default:
91 option_auto_syntax = 0;
92 g_free (option_syntax_type);
93 option_syntax_type = g_strdup (names[syntax - N_DFLT_ENTRIES]);
96 /* Load or unload syntax rules if the option has changed */
97 if ((option_auto_syntax && !old_auto_syntax) || old_auto_syntax ||
98 (old_syntax_type && option_syntax_type &&
99 (strcmp (old_syntax_type, option_syntax_type) != 0)) ||
100 force_reload)
101 edit_load_syntax (wedit, NULL, option_syntax_type);
103 for (i = 0; names[i]; i++) {
104 g_free (names[i]);
106 g_free (names);
107 g_free (old_syntax_type);