2 Internal file viewer for the Midnight Commander
3 Function for paint dialogs
5 Copyright (C) 1994-2022
6 Free Software Foundation, Inc.
9 Miguel de Icaza, 1994, 1995, 1998
10 Janne Kukonlehto, 1994, 1995
12 Joseph M. Hinkle, 1996
15 Roland Illig <roland.illig@gmx.de>, 2004, 2005
16 Slava Zanko <slavazanko@google.com>, 2009
17 Andrew Borodin <aborodin@vmail.ru>, 2009-2022
18 Ilia Maslakov <il.smind@gmail.com>, 2009
20 This file is part of the Midnight Commander.
22 The Midnight Commander is free software: you can redistribute it
23 and/or modify it under the terms of the GNU General Public License as
24 published by the Free Software Foundation, either version 3 of the License,
25 or (at your option) any later version.
27 The Midnight Commander is distributed in the hope that it will be useful,
28 but WITHOUT ANY WARRANTY; without even the implied warranty of
29 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 GNU General Public License for more details.
32 You should have received a copy of the GNU General Public License
33 along with this program. If not, see <http://www.gnu.org/licenses/>.
39 #include <sys/types.h>
41 #include "lib/global.h"
42 #include "lib/search.h"
43 #include "lib/strutil.h"
44 #include "lib/widget.h"
46 #include "lib/charsets.h"
49 #include "src/history.h"
53 /*** global variables ****************************************************************************/
55 /*** file scope macro definitions ****************************************************************/
57 /*** file scope type declarations ****************************************************************/
59 /*** file scope variables ************************************************************************/
61 /*** file scope functions ************************************************************************/
62 /* --------------------------------------------------------------------------------------------- */
64 /* --------------------------------------------------------------------------------------------- */
65 /*** public functions ****************************************************************************/
66 /* --------------------------------------------------------------------------------------------- */
69 mcview_dialog_search (WView
* view
)
73 size_t num_of_types
= 0;
74 gchar
**list_of_types
;
76 list_of_types
= mc_search_get_types_strings_array (&num_of_types
);
79 quick_widget_t quick_widgets
[] = {
81 QUICK_LABELED_INPUT (N_("Enter search string:"), input_label_above
,
82 INPUT_LAST_TEXT
, MC_HISTORY_SHARED_SEARCH
, &exp
,
83 NULL
, FALSE
, FALSE
, INPUT_COMPLETE_NONE
),
84 QUICK_SEPARATOR (TRUE
),
86 QUICK_RADIO (num_of_types
, (const char **) list_of_types
,
87 (int *) &mcview_search_options
.type
, NULL
),
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
),
93 QUICK_CHECKBOX (N_("&All charsets"), &mcview_search_options
.all_codepages
, NULL
),
96 QUICK_BUTTONS_OK_CANCEL
,
101 WRect r
= { -1, -1, 0, 58 };
103 quick_dialog_t qdlg
= {
104 r
, N_("Search"), "[Input Line Keys]",
105 quick_widgets
, NULL
, NULL
108 qd_result
= quick_dialog (&qdlg
);
111 g_strfreev (list_of_types
);
113 if (qd_result
== B_CANCEL
|| exp
[0] == '\0')
123 tmp
= str_convert_to_input (exp
);
125 exp
= g_string_free (tmp
, FALSE
);
129 mcview_search_deinit (view
);
130 view
->last_search_string
= exp
;
132 return mcview_search_init (view
);
135 /* --------------------------------------------------------------------------------------------- */
138 mcview_dialog_goto (WView
* view
, off_t
* offset
)
142 MC_VIEW_GOTO_LINENUM
= 0,
143 MC_VIEW_GOTO_PERCENT
= 1,
144 MC_VIEW_GOTO_OFFSET_DEC
= 2,
145 MC_VIEW_GOTO_OFFSET_HEX
= 3
146 } mcview_goto_type_t
;
148 const char *mc_view_goto_str
[] = {
151 N_("&Decimal offset"),
152 N_("He&xadecimal offset")
155 static mcview_goto_type_t current_goto_type
= MC_VIEW_GOTO_LINENUM
;
162 num_of_types
= G_N_ELEMENTS (mc_view_goto_str
);
168 for (i
= 0; i
< num_of_types
; i
++)
169 mc_view_goto_str
[i
] = _(mc_view_goto_str
[i
]);
174 quick_widget_t quick_widgets
[] = {
176 QUICK_INPUT (INPUT_LAST_TEXT
, MC_HISTORY_VIEW_GOTO
, &exp
, NULL
,
177 FALSE
, FALSE
, INPUT_COMPLETE_NONE
),
178 QUICK_RADIO (num_of_types
, (const char **) mc_view_goto_str
, (int *) ¤t_goto_type
,
180 QUICK_BUTTONS_OK_CANCEL
,
185 WRect r
= { -1, -1, 0, 40 };
187 quick_dialog_t qdlg
= {
188 r
, N_("Goto"), "[Input Line Keys]",
189 quick_widgets
, NULL
, NULL
193 qd_result
= quick_dialog (&qdlg
);
198 /* check input line value */
199 res
= (qd_result
!= B_CANCEL
&& exp
[0] != '\0');
202 int base
= (current_goto_type
== MC_VIEW_GOTO_OFFSET_HEX
) ? 16 : 10;
206 addr
= (off_t
) g_ascii_strtoll (exp
, &error
, base
);
207 if ((*error
== '\0') && (addr
>= 0))
209 switch (current_goto_type
)
211 case MC_VIEW_GOTO_LINENUM
:
212 /* Line number entered by user is 1-based. */
215 mcview_coord_to_offset (view
, offset
, addr
, 0);
216 *offset
= mcview_bol (view
, *offset
, 0);
218 case MC_VIEW_GOTO_PERCENT
:
221 /* read all data from pipe to get real size */
222 if (view
->growbuf_in_use
)
223 mcview_growbuf_read_all_data (view
);
224 *offset
= addr
* mcview_get_filesize (view
) / 100;
225 if (!view
->mode_flags
.hex
)
226 *offset
= mcview_bol (view
, *offset
, 0);
228 case MC_VIEW_GOTO_OFFSET_DEC
:
229 case MC_VIEW_GOTO_OFFSET_HEX
:
230 if (!view
->mode_flags
.hex
)
232 if (view
->growbuf_in_use
)
233 mcview_growbuf_read_until (view
, addr
);
235 *offset
= mcview_bol (view
, addr
, 0);
239 /* read all data from pipe to get real size */
240 if (view
->growbuf_in_use
)
241 mcview_growbuf_read_all_data (view
);
244 addr
= mcview_get_filesize (view
);
260 /* --------------------------------------------------------------------------------------------- */