2 Internal file viewer for the Midnight Commander
3 Function for paint dialogs
5 Copyright (C) 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003,
6 2004, 2005, 2006, 2007, 2009, 2011
7 The Free Software Foundation, Inc.
10 Miguel de Icaza, 1994, 1995, 1998
11 Janne Kukonlehto, 1994, 1995
13 Joseph M. Hinkle, 1996
16 Roland Illig <roland.illig@gmx.de>, 2004, 2005
17 Slava Zanko <slavazanko@google.com>, 2009
18 Andrew Borodin <aborodin@vmail.ru>, 2009, 2012
19 Ilia Maslakov <il.smind@gmail.com>, 2009
21 This file is part of the Midnight Commander.
23 The Midnight Commander is free software: you can redistribute it
24 and/or modify it under the terms of the GNU General Public License as
25 published by the Free Software Foundation, either version 3 of the License,
26 or (at your option) any later version.
28 The Midnight Commander is distributed in the hope that it will be useful,
29 but WITHOUT ANY WARRANTY; without even the implied warranty of
30 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 GNU General Public License for more details.
33 You should have received a copy of the GNU General Public License
34 along with this program. If not, see <http://www.gnu.org/licenses/>.
40 #include <sys/types.h>
42 #include "lib/global.h"
43 #include "lib/search.h"
44 #include "lib/strutil.h"
45 #include "lib/widget.h"
47 #include "lib/charsets.h"
50 #include "src/history.h"
54 /*** global variables ****************************************************************************/
56 mcview_search_options_t mcview_search_options
= {
57 .type
= MC_SEARCH_T_NORMAL
,
61 .all_codepages
= FALSE
64 /*** file scope macro definitions ****************************************************************/
66 /*** file scope type declarations ****************************************************************/
68 /*** file scope variables ************************************************************************/
70 /*** file scope functions ************************************************************************/
71 /* --------------------------------------------------------------------------------------------- */
73 /* --------------------------------------------------------------------------------------------- */
74 /*** public functions ****************************************************************************/
75 /* --------------------------------------------------------------------------------------------- */
78 mcview_dialog_search (mcview_t
* view
)
83 gchar
**list_of_types
;
85 list_of_types
= mc_search_get_types_strings_array (&num_of_types
);
88 quick_widget_t quick_widgets
[] = {
90 QUICK_LABELED_INPUT (N_("Enter search string:"), input_label_above
,
91 INPUT_LAST_TEXT
, MC_HISTORY_SHARED_SEARCH
, &exp
,
92 NULL
, FALSE
, FALSE
, INPUT_COMPLETE_DEFAULT
),
93 QUICK_SEPARATOR (TRUE
),
95 QUICK_RADIO (num_of_types
, (const char **) list_of_types
,
96 (int *) &mcview_search_options
.type
, NULL
),
98 QUICK_CHECKBOX (N_("Cas&e sensitive"), &mcview_search_options
.case_sens
, NULL
),
99 QUICK_CHECKBOX (N_("&Backwards"), &mcview_search_options
.backwards
, NULL
),
100 QUICK_CHECKBOX (N_("&Whole words"), &mcview_search_options
.whole_words
, NULL
),
102 QUICK_CHECKBOX (N_("&All charsets"), &mcview_search_options
.all_codepages
, NULL
),
105 QUICK_BUTTONS_OK_CANCEL
,
110 quick_dialog_t qdlg
= {
112 N_("Search"), "[Input Line Keys]",
113 quick_widgets
, NULL
, NULL
116 qd_result
= quick_dialog (&qdlg
);
119 g_strfreev (list_of_types
);
121 if ((qd_result
== B_CANCEL
) || (exp
== NULL
) || (exp
[0] == '\0'))
131 tmp
= str_convert_to_input (exp
);
135 exp
= g_string_free (tmp
, FALSE
);
140 g_free (view
->last_search_string
);
141 view
->last_search_string
= exp
;
142 mcview_nroff_seq_free (&view
->search_nroff_seq
);
143 mc_search_free (view
->search
);
145 view
->search
= mc_search_new (view
->last_search_string
, -1);
146 view
->search_nroff_seq
= mcview_nroff_seq_new (view
);
147 if (view
->search
!= NULL
)
149 view
->search
->search_type
= mcview_search_options
.type
;
150 view
->search
->is_all_charsets
= mcview_search_options
.all_codepages
;
151 view
->search
->is_case_sensitive
= mcview_search_options
.case_sens
;
152 view
->search
->whole_words
= mcview_search_options
.whole_words
;
153 view
->search
->search_fn
= mcview_search_cmd_callback
;
154 view
->search
->update_fn
= mcview_search_update_cmd_callback
;
157 return (view
->search
!= NULL
);
160 /* --------------------------------------------------------------------------------------------- */
163 mcview_dialog_goto (mcview_t
* view
, off_t
* offset
)
167 MC_VIEW_GOTO_LINENUM
= 0,
168 MC_VIEW_GOTO_PERCENT
= 1,
169 MC_VIEW_GOTO_OFFSET_DEC
= 2,
170 MC_VIEW_GOTO_OFFSET_HEX
= 3
171 } mcview_goto_type_t
;
173 const char *mc_view_goto_str
[] = {
174 N_("&Line number (decimal)"),
176 N_("&Decimal offset"),
177 N_("He&xadecimal offset")
180 static mcview_goto_type_t current_goto_type
= MC_VIEW_GOTO_LINENUM
;
187 num_of_types
= G_N_ELEMENTS (mc_view_goto_str
);
193 for (i
= 0; i
< num_of_types
; i
++)
194 mc_view_goto_str
[i
] = _(mc_view_goto_str
[i
]);
199 quick_widget_t quick_widgets
[] = {
201 QUICK_INPUT (INPUT_LAST_TEXT
, MC_HISTORY_VIEW_GOTO
, &exp
, NULL
,
202 FALSE
, FALSE
, INPUT_COMPLETE_DEFAULT
),
203 QUICK_RADIO (num_of_types
, (const char **) mc_view_goto_str
, (int *) ¤t_goto_type
,
205 QUICK_BUTTONS_OK_CANCEL
,
210 quick_dialog_t qdlg
= {
212 N_("Goto"), "[Input Line Keys]",
213 quick_widgets
, NULL
, NULL
217 qd_result
= quick_dialog (&qdlg
);
222 /* check input line value */
223 res
= (qd_result
!= B_CANCEL
&& exp
!= NULL
&& exp
[0] != '\0');
226 int base
= (current_goto_type
== MC_VIEW_GOTO_OFFSET_HEX
) ? 16 : 10;
230 addr
= (off_t
) g_ascii_strtoll (exp
, &error
, base
);
231 if ((*error
== '\0') && (addr
>= 0))
233 switch (current_goto_type
)
235 case MC_VIEW_GOTO_LINENUM
:
236 mcview_coord_to_offset (view
, offset
, addr
, 0);
237 *offset
= mcview_bol (view
, *offset
, 0);
239 case MC_VIEW_GOTO_PERCENT
:
242 *offset
= addr
* mcview_get_filesize (view
) / 100;
244 *offset
= mcview_bol (view
, *offset
, 0);
246 case MC_VIEW_GOTO_OFFSET_DEC
:
247 case MC_VIEW_GOTO_OFFSET_HEX
:
250 *offset
= mcview_bol (view
, *offset
, 0);
253 addr
= mcview_get_filesize (view
);