2 Internal file viewer for the Midnight Commander
3 Function for paint dialogs
5 Copyright (C) 1994-2016
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, 2012
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 mcview_search_options_t mcview_search_options
= {
56 .type
= MC_SEARCH_T_NORMAL
,
60 .all_codepages
= FALSE
63 /*** file scope macro definitions ****************************************************************/
65 /*** file scope type declarations ****************************************************************/
67 /*** file scope variables ************************************************************************/
69 /*** file scope functions ************************************************************************/
70 /* --------------------------------------------------------------------------------------------- */
72 /* --------------------------------------------------------------------------------------------- */
73 /*** public functions ****************************************************************************/
74 /* --------------------------------------------------------------------------------------------- */
77 mcview_dialog_search (WView
* view
)
82 gchar
**list_of_types
;
84 list_of_types
= mc_search_get_types_strings_array (&num_of_types
);
87 quick_widget_t quick_widgets
[] = {
89 QUICK_LABELED_INPUT (N_("Enter search string:"), input_label_above
,
90 INPUT_LAST_TEXT
, MC_HISTORY_SHARED_SEARCH
, &exp
,
91 NULL
, FALSE
, FALSE
, INPUT_COMPLETE_NONE
),
92 QUICK_SEPARATOR (TRUE
),
94 QUICK_RADIO (num_of_types
, (const char **) list_of_types
,
95 (int *) &mcview_search_options
.type
, NULL
),
97 QUICK_CHECKBOX (N_("Cas&e sensitive"), &mcview_search_options
.case_sens
, NULL
),
98 QUICK_CHECKBOX (N_("&Backwards"), &mcview_search_options
.backwards
, NULL
),
99 QUICK_CHECKBOX (N_("&Whole words"), &mcview_search_options
.whole_words
, NULL
),
101 QUICK_CHECKBOX (N_("&All charsets"), &mcview_search_options
.all_codepages
, NULL
),
104 QUICK_BUTTONS_OK_CANCEL
,
109 quick_dialog_t qdlg
= {
111 N_("Search"), "[Input Line Keys]",
112 quick_widgets
, NULL
, NULL
115 qd_result
= quick_dialog (&qdlg
);
118 g_strfreev (list_of_types
);
120 if ((qd_result
== B_CANCEL
) || (exp
== NULL
) || (exp
[0] == '\0'))
130 tmp
= str_convert_to_input (exp
);
134 exp
= g_string_free (tmp
, FALSE
);
139 g_free (view
->last_search_string
);
140 view
->last_search_string
= exp
;
141 mcview_nroff_seq_free (&view
->search_nroff_seq
);
142 mc_search_free (view
->search
);
145 view
->search
= mc_search_new (view
->last_search_string
, cp_source
);
147 view
->search
= mc_search_new (view
->last_search_string
, NULL
);
149 view
->search_nroff_seq
= mcview_nroff_seq_new (view
);
150 if (view
->search
!= NULL
)
152 view
->search
->search_type
= mcview_search_options
.type
;
154 view
->search
->is_all_charsets
= mcview_search_options
.all_codepages
;
156 view
->search
->is_case_sensitive
= mcview_search_options
.case_sens
;
157 view
->search
->whole_words
= mcview_search_options
.whole_words
;
158 view
->search
->search_fn
= mcview_search_cmd_callback
;
159 view
->search
->update_fn
= mcview_search_update_cmd_callback
;
162 return (view
->search
!= NULL
);
165 /* --------------------------------------------------------------------------------------------- */
168 mcview_dialog_goto (WView
* view
, off_t
* offset
)
172 MC_VIEW_GOTO_LINENUM
= 0,
173 MC_VIEW_GOTO_PERCENT
= 1,
174 MC_VIEW_GOTO_OFFSET_DEC
= 2,
175 MC_VIEW_GOTO_OFFSET_HEX
= 3
176 } mcview_goto_type_t
;
178 const char *mc_view_goto_str
[] = {
181 N_("&Decimal offset"),
182 N_("He&xadecimal offset")
185 static mcview_goto_type_t current_goto_type
= MC_VIEW_GOTO_LINENUM
;
192 num_of_types
= G_N_ELEMENTS (mc_view_goto_str
);
198 for (i
= 0; i
< num_of_types
; i
++)
199 mc_view_goto_str
[i
] = _(mc_view_goto_str
[i
]);
204 quick_widget_t quick_widgets
[] = {
206 QUICK_INPUT (INPUT_LAST_TEXT
, MC_HISTORY_VIEW_GOTO
, &exp
, NULL
,
207 FALSE
, FALSE
, INPUT_COMPLETE_NONE
),
208 QUICK_RADIO (num_of_types
, (const char **) mc_view_goto_str
, (int *) ¤t_goto_type
,
210 QUICK_BUTTONS_OK_CANCEL
,
215 quick_dialog_t qdlg
= {
217 N_("Goto"), "[Input Line Keys]",
218 quick_widgets
, NULL
, NULL
222 qd_result
= quick_dialog (&qdlg
);
227 /* check input line value */
228 res
= (qd_result
!= B_CANCEL
&& exp
!= NULL
&& exp
[0] != '\0');
231 int base
= (current_goto_type
== MC_VIEW_GOTO_OFFSET_HEX
) ? 16 : 10;
235 addr
= (off_t
) g_ascii_strtoll (exp
, &error
, base
);
236 if ((*error
== '\0') && (addr
>= 0))
238 switch (current_goto_type
)
240 case MC_VIEW_GOTO_LINENUM
:
241 /* Line number entered by user is 1-based. */
244 mcview_coord_to_offset (view
, offset
, addr
, 0);
245 *offset
= mcview_bol (view
, *offset
, 0);
247 case MC_VIEW_GOTO_PERCENT
:
250 *offset
= addr
* mcview_get_filesize (view
) / 100;
252 *offset
= mcview_bol (view
, *offset
, 0);
254 case MC_VIEW_GOTO_OFFSET_DEC
:
255 case MC_VIEW_GOTO_OFFSET_HEX
:
258 *offset
= mcview_bol (view
, *offset
, 0);
261 addr
= mcview_get_filesize (view
);