4747
4848/*** global variables ****************************************************************************/
4949
50- /*** file scope macro definitions ****************************************************************/
51-
52- #define B_REPLACE_ALL (B_USER + 1)
53- #define B_REPLACE_ONE (B_USER + 2)
54- #define B_SKIP_REPLACE (B_USER + 3)
55-
56- /*** file scope type declarations ****************************************************************/
57-
58- typedef struct edit_search_options_t
59- {
60- mc_search_type_t type ;
61- gboolean case_sens ;
62- gboolean backwards ;
63- gboolean only_in_selection ;
64- gboolean whole_words ;
65- gboolean all_codepages ;
66- } edit_search_options_t ;
67-
68- /*** forward declarations (file scope functions) *************************************************/
69-
70- /*** file scope variables ************************************************************************/
71-
72- static edit_search_options_t edit_search_options = {
50+ edit_search_options_t edit_search_options = {
7351 .type = MC_SEARCH_T_NORMAL ,
7452 .case_sens = FALSE,
7553 .backwards = FALSE,
@@ -78,6 +56,21 @@ static edit_search_options_t edit_search_options = {
7856 .all_codepages = FALSE,
7957};
8058
59+ /*** file scope macro definitions ****************************************************************/
60+
61+ /*** file scope type declarations ****************************************************************/
62+
63+ /*** forward declarations (file scope functions) *************************************************/
64+
65+ MC_MOCKABLE void edit_dialog_replace_show (WEdit * edit , const char * search_default ,
66+ const char * replace_default , char * * search_text ,
67+ char * * replace_text );
68+
69+ MC_MOCKABLE int edit_dialog_replace_prompt_show (WEdit * edit , char * from_text , char * to_text ,
70+ int xpos , int ypos );
71+
72+ /*** file scope variables ************************************************************************/
73+
8174/* --------------------------------------------------------------------------------------------- */
8275/*** file scope functions ************************************************************************/
8376/* --------------------------------------------------------------------------------------------- */
@@ -165,136 +158,6 @@ edit_dialog_search_show (WEdit *edit)
165158
166159/* --------------------------------------------------------------------------------------------- */
167160
168- static void
169- edit_dialog_replace_show (WEdit * edit , const char * search_default , const char * replace_default ,
170- /*@out@ */ char * * search_text , /*@out@ */ char * * replace_text )
171- {
172- size_t num_of_types = 0 ;
173- gchar * * list_of_types ;
174-
175- if ((search_default == NULL ) || (* search_default == '\0' ))
176- search_default = INPUT_LAST_TEXT ;
177-
178- list_of_types = mc_search_get_types_strings_array (& num_of_types );
179-
180- {
181- quick_widget_t quick_widgets [] = {
182- // clang-format off
183- QUICK_LABELED_INPUT (N_ ("Enter search string:" ), input_label_above , search_default ,
184- MC_HISTORY_SHARED_SEARCH , search_text , NULL , FALSE, FALSE,
185- INPUT_COMPLETE_NONE ),
186- QUICK_LABELED_INPUT (N_ ("Enter replacement string:" ), input_label_above ,
187- replace_default , "replace" , replace_text , NULL , FALSE, FALSE,
188- INPUT_COMPLETE_NONE ),
189- QUICK_SEPARATOR (TRUE),
190- QUICK_START_COLUMNS ,
191- QUICK_RADIO (num_of_types , (const char * * ) list_of_types ,
192- (int * ) & edit_search_options .type , NULL ),
193- QUICK_NEXT_COLUMN ,
194- QUICK_CHECKBOX (N_ ("Cas&e sensitive" ), & edit_search_options .case_sens , NULL ),
195- QUICK_CHECKBOX (N_ ("&Backwards" ), & edit_search_options .backwards , NULL ),
196- QUICK_CHECKBOX (N_ ("In se&lection" ), & edit_search_options .only_in_selection , NULL ),
197- QUICK_CHECKBOX (N_ ("&Whole words" ), & edit_search_options .whole_words , NULL ),
198- #ifdef HAVE_CHARSET
199- QUICK_CHECKBOX (N_ ("&All charsets" ), & edit_search_options .all_codepages , NULL ),
200- #endif
201- QUICK_STOP_COLUMNS ,
202- QUICK_BUTTONS_OK_CANCEL ,
203- QUICK_END ,
204- // clang-format on
205- };
206-
207- WRect r = { -1 , -1 , 0 , 58 };
208-
209- quick_dialog_t qdlg = {
210- .rect = r ,
211- .title = N_ ("Replace" ),
212- .help = "[Input Line Keys]" ,
213- .widgets = quick_widgets ,
214- .callback = NULL ,
215- .mouse_callback = NULL ,
216- };
217-
218- if (quick_dialog (& qdlg ) != B_CANCEL )
219- edit -> replace_mode = 0 ;
220- else
221- {
222- * replace_text = NULL ;
223- * search_text = NULL ;
224- }
225- }
226-
227- g_strfreev (list_of_types );
228- }
229-
230- /* --------------------------------------------------------------------------------------------- */
231-
232- static int
233- edit_dialog_replace_prompt_show (WEdit * edit , char * from_text , char * to_text , int xpos , int ypos )
234- {
235- Widget * w = WIDGET (edit );
236-
237- // dialog size
238- int dlg_height = 10 ;
239- int dlg_width ;
240-
241- char tmp [BUF_MEDIUM ];
242- char * repl_from , * repl_to ;
243- int retval ;
244-
245- if (xpos == -1 )
246- xpos = w -> rect .x + edit_options .line_state_width + 1 ;
247- if (ypos == -1 )
248- ypos = w -> rect .y + w -> rect .lines / 2 ;
249- // Sometimes menu can hide replaced text. I don't like it
250- if ((edit -> curs_row >= ypos - 1 ) && (edit -> curs_row <= ypos + dlg_height - 1 ))
251- ypos -= dlg_height ;
252-
253- dlg_width = WIDGET (w -> owner )-> rect .cols - xpos - 1 ;
254-
255- g_snprintf (tmp , sizeof (tmp ), "\"%s\"" , from_text );
256- repl_from = g_strdup (str_trunc (tmp , dlg_width - 7 ));
257-
258- g_snprintf (tmp , sizeof (tmp ), "\"%s\"" , to_text );
259- repl_to = g_strdup (str_trunc (tmp , dlg_width - 7 ));
260-
261- {
262- quick_widget_t quick_widgets [] = {
263- // clang-format off
264- QUICK_LABEL (repl_from , NULL ),
265- QUICK_LABEL (N_ ("Replace with:" ), NULL ),
266- QUICK_LABEL (repl_to , NULL ),
267- QUICK_START_BUTTONS (TRUE, TRUE),
268- QUICK_BUTTON (N_ ("&Replace" ), B_ENTER , NULL , NULL ),
269- QUICK_BUTTON (N_ ("A&ll" ), B_REPLACE_ALL , NULL , NULL ),
270- QUICK_BUTTON (N_ ("&Skip" ), B_SKIP_REPLACE , NULL , NULL ),
271- QUICK_BUTTON (N_ ("&Cancel" ), B_CANCEL , NULL , NULL ),
272- QUICK_END ,
273- // clang-format on
274- };
275-
276- WRect r = { ypos , xpos , 0 , -1 };
277-
278- quick_dialog_t qdlg = {
279- .rect = r ,
280- .title = N_ ("Confirm replace" ),
281- .help = NULL ,
282- .widgets = quick_widgets ,
283- .callback = NULL ,
284- .mouse_callback = NULL ,
285- };
286-
287- retval = quick_dialog (& qdlg );
288- }
289-
290- g_free (repl_from );
291- g_free (repl_to );
292-
293- return retval ;
294- }
295-
296- /* --------------------------------------------------------------------------------------------- */
297-
298161/**
299162 * Get EOL symbol for searching.
300163 *
@@ -824,6 +687,136 @@ edit_search_cmd (WEdit *edit, gboolean again)
824687 }
825688}
826689
690+ /* --------------------------------------------------------------------------------------------- */
691+
692+ void
693+ edit_dialog_replace_show (WEdit * edit , const char * search_default , const char * replace_default ,
694+ /*@out@ */ char * * search_text , /*@out@ */ char * * replace_text )
695+ {
696+ size_t num_of_types = 0 ;
697+ gchar * * list_of_types ;
698+
699+ if ((search_default == NULL ) || (* search_default == '\0' ))
700+ search_default = INPUT_LAST_TEXT ;
701+
702+ list_of_types = mc_search_get_types_strings_array (& num_of_types );
703+
704+ {
705+ quick_widget_t quick_widgets [] = {
706+ // clang-format off
707+ QUICK_LABELED_INPUT (N_ ("Enter search string:" ), input_label_above , search_default ,
708+ MC_HISTORY_SHARED_SEARCH , search_text , NULL , FALSE, FALSE,
709+ INPUT_COMPLETE_NONE ),
710+ QUICK_LABELED_INPUT (N_ ("Enter replacement string:" ), input_label_above ,
711+ replace_default , "replace" , replace_text , NULL , FALSE, FALSE,
712+ INPUT_COMPLETE_NONE ),
713+ QUICK_SEPARATOR (TRUE),
714+ QUICK_START_COLUMNS ,
715+ QUICK_RADIO (num_of_types , (const char * * ) list_of_types ,
716+ (int * ) & edit_search_options .type , NULL ),
717+ QUICK_NEXT_COLUMN ,
718+ QUICK_CHECKBOX (N_ ("Cas&e sensitive" ), & edit_search_options .case_sens , NULL ),
719+ QUICK_CHECKBOX (N_ ("&Backwards" ), & edit_search_options .backwards , NULL ),
720+ QUICK_CHECKBOX (N_ ("In se&lection" ), & edit_search_options .only_in_selection , NULL ),
721+ QUICK_CHECKBOX (N_ ("&Whole words" ), & edit_search_options .whole_words , NULL ),
722+ #ifdef HAVE_CHARSET
723+ QUICK_CHECKBOX (N_ ("&All charsets" ), & edit_search_options .all_codepages , NULL ),
724+ #endif
725+ QUICK_STOP_COLUMNS ,
726+ QUICK_BUTTONS_OK_CANCEL ,
727+ QUICK_END ,
728+ // clang-format on
729+ };
730+
731+ WRect r = { -1 , -1 , 0 , 58 };
732+
733+ quick_dialog_t qdlg = {
734+ .rect = r ,
735+ .title = N_ ("Replace" ),
736+ .help = "[Input Line Keys]" ,
737+ .widgets = quick_widgets ,
738+ .callback = NULL ,
739+ .mouse_callback = NULL ,
740+ };
741+
742+ if (quick_dialog (& qdlg ) != B_CANCEL )
743+ edit -> replace_mode = 0 ;
744+ else
745+ {
746+ * replace_text = NULL ;
747+ * search_text = NULL ;
748+ }
749+ }
750+
751+ g_strfreev (list_of_types );
752+ }
753+
754+ /* --------------------------------------------------------------------------------------------- */
755+
756+ int
757+ edit_dialog_replace_prompt_show (WEdit * edit , char * from_text , char * to_text , int xpos , int ypos )
758+ {
759+ Widget * w = WIDGET (edit );
760+
761+ // dialog size
762+ int dlg_height = 10 ;
763+ int dlg_width ;
764+
765+ char tmp [BUF_MEDIUM ];
766+ char * repl_from , * repl_to ;
767+ int retval ;
768+
769+ if (xpos == -1 )
770+ xpos = w -> rect .x + edit_options .line_state_width + 1 ;
771+ if (ypos == -1 )
772+ ypos = w -> rect .y + w -> rect .lines / 2 ;
773+ // Sometimes menu can hide replaced text. I don't like it
774+ if ((edit -> curs_row >= ypos - 1 ) && (edit -> curs_row <= ypos + dlg_height - 1 ))
775+ ypos -= dlg_height ;
776+
777+ dlg_width = WIDGET (w -> owner )-> rect .cols - xpos - 1 ;
778+
779+ g_snprintf (tmp , sizeof (tmp ), "\"%s\"" , from_text );
780+ repl_from = g_strdup (str_trunc (tmp , dlg_width - 7 ));
781+
782+ g_snprintf (tmp , sizeof (tmp ), "\"%s\"" , to_text );
783+ repl_to = g_strdup (str_trunc (tmp , dlg_width - 7 ));
784+
785+ {
786+ quick_widget_t quick_widgets [] = {
787+ // clang-format off
788+ QUICK_LABEL (repl_from , NULL ),
789+ QUICK_LABEL (N_ ("Replace with:" ), NULL ),
790+ QUICK_LABEL (repl_to , NULL ),
791+ QUICK_START_BUTTONS (TRUE, TRUE),
792+ QUICK_BUTTON (N_ ("&Replace" ), B_ENTER , NULL , NULL ),
793+ QUICK_BUTTON (N_ ("A&ll" ), B_REPLACE_ALL , NULL , NULL ),
794+ QUICK_BUTTON (N_ ("&Skip" ), B_SKIP_REPLACE , NULL , NULL ),
795+ QUICK_BUTTON (N_ ("&Cancel" ), B_CANCEL , NULL , NULL ),
796+ QUICK_END ,
797+ // clang-format on
798+ };
799+
800+ WRect r = { ypos , xpos , 0 , -1 };
801+
802+ quick_dialog_t qdlg = {
803+ .rect = r ,
804+ .title = N_ ("Confirm replace" ),
805+ .help = NULL ,
806+ .widgets = quick_widgets ,
807+ .callback = NULL ,
808+ .mouse_callback = NULL ,
809+ };
810+
811+ retval = quick_dialog (& qdlg );
812+ }
813+
814+ g_free (repl_from );
815+ g_free (repl_to );
816+
817+ return retval ;
818+ }
819+
827820/* --------------------------------------------------------------------------------------------- */
828821/** call with edit = 0 before shutdown to close memory leaks */
829822
0 commit comments