This source file includes following definitions.
- pstrcmp
- exec_edit_syntax_dialog
- edit_syntax_dialog
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 #include <config.h>
36
37 #include <stdlib.h>
38 #include <string.h>
39
40 #include "lib/global.h"
41 #include "lib/widget.h"
42
43 #include "edit-impl.h"
44 #include "editwidget.h"
45
46
47
48
49
50 #define MAX_ENTRY_LEN 40
51 #define LIST_LINES 14
52 #define N_DFLT_ENTRIES 2
53
54
55
56
57
58
59
60
61 static int
62 pstrcmp (const void *p1, const void *p2)
63 {
64 return strcmp (*(char *const *) p1, *(char *const *) p2);
65 }
66
67
68
69 static int
70 exec_edit_syntax_dialog (const GPtrArray * names, const char *current_syntax)
71 {
72 size_t i;
73 Listbox *syntaxlist;
74
75 syntaxlist = create_listbox_window (LIST_LINES, MAX_ENTRY_LEN,
76 _("Choose syntax highlighting"), NULL);
77 LISTBOX_APPEND_TEXT (syntaxlist, 'A', _("< Auto >"), NULL, FALSE);
78 LISTBOX_APPEND_TEXT (syntaxlist, 'R', _("< Reload Current Syntax >"), NULL, FALSE);
79
80 for (i = 0; i < names->len; i++)
81 {
82 const char *name;
83
84 name = g_ptr_array_index (names, i);
85 LISTBOX_APPEND_TEXT (syntaxlist, 0, name, NULL, FALSE);
86 if (current_syntax != NULL && strcmp (name, current_syntax) == 0)
87 listbox_select_entry (syntaxlist->list, i + N_DFLT_ENTRIES);
88 }
89
90 return run_listbox (syntaxlist);
91 }
92
93
94
95
96
97 void
98 edit_syntax_dialog (WEdit * edit)
99 {
100 GPtrArray *names;
101 int syntax;
102
103 names = g_ptr_array_new ();
104
105
106
107
108 edit_load_syntax (NULL, names, NULL);
109 g_ptr_array_sort (names, pstrcmp);
110
111 syntax = exec_edit_syntax_dialog (names, edit->syntax_type);
112 if (syntax >= 0)
113 {
114 gboolean force_reload = FALSE;
115 char *current_syntax;
116 gboolean old_auto_syntax;
117
118 current_syntax = g_strdup (edit->syntax_type);
119 old_auto_syntax = option_auto_syntax;
120
121 switch (syntax)
122 {
123 case 0:
124 option_auto_syntax = TRUE;
125 break;
126 case 1:
127 force_reload = TRUE;
128 break;
129 default:
130 option_auto_syntax = FALSE;
131 g_free (edit->syntax_type);
132 edit->syntax_type = g_strdup (g_ptr_array_index (names, syntax - N_DFLT_ENTRIES));
133 }
134
135
136 if (force_reload || (option_auto_syntax && !old_auto_syntax) || old_auto_syntax ||
137 (current_syntax != NULL && edit->syntax_type != NULL &&
138 strcmp (current_syntax, edit->syntax_type) != 0))
139 edit_load_syntax (edit, NULL, edit->syntax_type);
140
141 g_free (current_syntax);
142 }
143
144 g_ptr_array_foreach (names, (GFunc) g_free, NULL);
145 g_ptr_array_free (names, TRUE);
146 }
147
148