This source file includes following definitions.
- mcview_dialog_search
- mcview_dialog_goto
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
36 #include <config.h>
37
38 #include <stdlib.h>
39 #include <sys/types.h>
40
41 #include "lib/global.h"
42 #include "lib/search.h"
43 #include "lib/strutil.h"
44 #include "lib/widget.h"
45 #ifdef HAVE_CHARSET
46 # include "lib/charsets.h"
47 #endif
48
49 #include "src/history.h"
50
51 #include "internal.h"
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68 gboolean
69 mcview_dialog_search (WView *view)
70 {
71 char *exp = NULL;
72 int qd_result;
73 size_t num_of_types = 0;
74 gchar **list_of_types;
75
76 list_of_types = mc_search_get_types_strings_array (&num_of_types);
77
78 {
79 quick_widget_t quick_widgets[] = {
80
81 QUICK_LABELED_INPUT (N_ ("Enter search string:"), input_label_above, INPUT_LAST_TEXT,
82 MC_HISTORY_SHARED_SEARCH, &exp, NULL, FALSE, FALSE,
83 INPUT_COMPLETE_NONE),
84 QUICK_SEPARATOR (TRUE),
85 QUICK_START_COLUMNS,
86 QUICK_RADIO (num_of_types, (const char **) list_of_types,
87 (int *) &mcview_search_options.type, NULL),
88 QUICK_NEXT_COLUMN,
89 QUICK_CHECKBOX (N_ ("Cas&e sensitive"), &mcview_search_options.case_sens, NULL),
90 QUICK_CHECKBOX (N_ ("&Backwards"), &mcview_search_options.backwards, NULL),
91 QUICK_CHECKBOX (N_ ("&Whole words"), &mcview_search_options.whole_words, NULL),
92 #ifdef HAVE_CHARSET
93 QUICK_CHECKBOX (N_ ("&All charsets"), &mcview_search_options.all_codepages, NULL),
94 #endif
95 QUICK_STOP_COLUMNS,
96 QUICK_BUTTONS_OK_CANCEL,
97 QUICK_END,
98
99 };
100
101 WRect r = { -1, -1, 0, 58 };
102
103 quick_dialog_t qdlg = {
104 .rect = r,
105 .title = N_ ("Search"),
106 .help = "[Input Line Keys]",
107 .widgets = quick_widgets,
108 .callback = NULL,
109 .mouse_callback = NULL,
110 };
111
112 qd_result = quick_dialog (&qdlg);
113 }
114
115 g_strfreev (list_of_types);
116
117 if (qd_result == B_CANCEL || exp[0] == '\0')
118 {
119 g_free (exp);
120 return FALSE;
121 }
122
123 #ifdef HAVE_CHARSET
124 {
125 GString *tmp;
126
127 tmp = str_convert_to_input (exp);
128 g_free (exp);
129 if (tmp != NULL)
130 exp = g_string_free (tmp, FALSE);
131 else
132 exp = g_strdup ("");
133 }
134 #endif
135
136 mcview_search_deinit (view);
137 view->last_search_string = exp;
138
139 return mcview_search_init (view);
140 }
141
142
143
144 gboolean
145 mcview_dialog_goto (WView *view, off_t *offset)
146 {
147 typedef enum
148 {
149 MC_VIEW_GOTO_LINENUM = 0,
150 MC_VIEW_GOTO_PERCENT = 1,
151 MC_VIEW_GOTO_OFFSET_DEC = 2,
152 MC_VIEW_GOTO_OFFSET_HEX = 3
153 } mcview_goto_type_t;
154
155 const char *mc_view_goto_str[] = {
156 N_ ("&Line number"),
157 N_ ("Pe&rcents"),
158 N_ ("&Decimal offset"),
159 N_ ("He&xadecimal offset"),
160 };
161
162 static mcview_goto_type_t current_goto_type = MC_VIEW_GOTO_LINENUM;
163
164 size_t num_of_types;
165 char *exp = NULL;
166 int qd_result;
167 gboolean res;
168
169 num_of_types = G_N_ELEMENTS (mc_view_goto_str);
170
171 #ifdef ENABLE_NLS
172 {
173 size_t i;
174
175 for (i = 0; i < num_of_types; i++)
176 mc_view_goto_str[i] = _ (mc_view_goto_str[i]);
177 }
178 #endif
179
180 {
181 quick_widget_t quick_widgets[] = {
182 QUICK_INPUT (INPUT_LAST_TEXT, MC_HISTORY_VIEW_GOTO, &exp, NULL, FALSE, FALSE,
183 INPUT_COMPLETE_NONE),
184 QUICK_RADIO (num_of_types, (const char **) mc_view_goto_str, (int *) ¤t_goto_type,
185 NULL),
186 QUICK_BUTTONS_OK_CANCEL,
187 QUICK_END,
188 };
189
190 WRect r = { -1, -1, 0, 40 };
191
192 quick_dialog_t qdlg = {
193 .rect = r,
194 .title = N_ ("Goto"),
195 .help = "[Input Line Keys]",
196 .widgets = quick_widgets,
197 .callback = NULL,
198 .mouse_callback = NULL,
199 };
200
201
202 qd_result = quick_dialog (&qdlg);
203 }
204
205 *offset = -1;
206
207
208 res = (qd_result != B_CANCEL && exp[0] != '\0');
209 if (res)
210 {
211 int base = (current_goto_type == MC_VIEW_GOTO_OFFSET_HEX) ? 16 : 10;
212 off_t addr;
213 char *error;
214
215 addr = (off_t) g_ascii_strtoll (exp, &error, base);
216 if ((*error == '\0') && (addr >= 0))
217 {
218 switch (current_goto_type)
219 {
220 case MC_VIEW_GOTO_LINENUM:
221
222 if (addr > 0)
223 addr--;
224 mcview_coord_to_offset (view, offset, addr, 0);
225 *offset = mcview_bol (view, *offset, 0);
226 break;
227 case MC_VIEW_GOTO_PERCENT:
228 if (addr > 100)
229 addr = 100;
230
231 if (view->growbuf_in_use)
232 mcview_growbuf_read_all_data (view);
233 *offset = addr * mcview_get_filesize (view) / 100;
234 if (!view->mode_flags.hex)
235 *offset = mcview_bol (view, *offset, 0);
236 break;
237 case MC_VIEW_GOTO_OFFSET_DEC:
238 case MC_VIEW_GOTO_OFFSET_HEX:
239 if (!view->mode_flags.hex)
240 {
241 if (view->growbuf_in_use)
242 mcview_growbuf_read_until (view, addr);
243
244 *offset = mcview_bol (view, addr, 0);
245 }
246 else
247 {
248
249 if (view->growbuf_in_use)
250 mcview_growbuf_read_all_data (view);
251
252 *offset = addr;
253 addr = mcview_get_filesize (view);
254 if (*offset > addr)
255 *offset = addr;
256 }
257 break;
258 default:
259 *offset = 0;
260 break;
261 }
262 }
263 }
264
265 g_free (exp);
266 return res;
267 }
268
269