File Coverage

lib/Kephra/Dialog/Search.pm
Criterion Covered Total %
statement 6 316 1.9
branch 0 66 0.0
condition 0 9 0.0
subroutine 2 42 4.7
pod n/a
total 8 433 1.8


line stmt bran cond sub pod time code
1             package Kephra::Dialog::Search;
2             our $VERSION = '0.27';
3            
4 1     1   1055 use strict;
  1         2  
  1         34  
5 1     1   5 use warnings;
  1         3  
  1         5263  
6            
7 0     0     sub _ID { 'search_dialog' }
8             my $ref;
9 0 0   0     sub _ref { $ref = ref $_[0] eq 'Wx::Dialog' ? $_[0] : $ref }
10             my $highlight_search; # set 1 if searchbar turns red
11             my $active;
12             my %color = (
13             norm_fore => Wx::Colour->new( 0x00, 0x00, 0x55 ),
14             norm_back => Wx::Colour->new( 0xff, 0xff, 0xff ),
15             alert_fore => Wx::Colour->new( 0xff, 0x33, 0x33 ),
16             alert_back => Wx::Colour->new( 0xff, 0xff, 0xff ),
17             );
18            
19             sub find { # call as find dialog
20 0     0     my $d = ready();
21 0           my $selection = Kephra::App::EditPanel::_ref()->GetSelectedText;
22 0 0 0       if ($selection and not $d->{selection_radio}->GetValue ) {
  0            
23 0           Kephra::Edit::Search::set_find_item( $selection );
24 0           $d->{find_input}->SetValue( $selection );
25             } else {$d->{find_input}->SetValue( Kephra::Edit::Search::get_find_item())}
26 0           $d->{replace_input}->SetValue( Kephra::Edit::Search::get_replace_item() );
27 0           Wx::Window::SetFocus( $d->{find_input} );
28             }
29            
30             sub replace { # call as replace dialog
31 0     0     my $d = ready();
32 0           my $selection = Kephra::App::EditPanel::_ref()->GetSelectedText;
33 0 0 0       if ( length $selection > 0 and not $d->{selection_radio}->GetValue ) {
34 0           Kephra::Edit::Search::set_replace_item( $selection );
35 0           $d->{replace_input}->SetValue( $selection );
36             } else {
37 0           $d->{replace_input}->SetValue(Kephra::Edit::Search::get_replace_item());
38             }
39 0           $d->{find_input}->SetValue( $selection );
40 0           Wx::Window::SetFocus( $d->{replace_input} );
41             }
42            
43             sub ready { # display find and replace dialog
44 0 0   0     if ( not $active ) {
45            
46             # prepare some internal var and for better handling
47 0           my $edit_panel = Kephra::App::EditPanel::_ref();
48 0           my $attr = Kephra::Edit::Search::_attributes();
49 0           my $dsettings = Kephra::API::settings()->{dialog}{search};
50 0           my $l18n = Kephra::API::localisation();
51 0           my $label = $l18n->{dialog}{search}{label};
52 0           my $hint = $l18n->{dialog}{search}{hint};
53 0           my @find_history = ();
54 0           my @replace_history = ();
55 0           my $d_style = &Wx::wxNO_FULL_REPAINT_ON_RESIZE | &Wx::wxSYSTEM_MENU |
56             &Wx::wxCAPTION | &Wx::wxMINIMIZE_BOX | &Wx::wxCLOSE_BOX;
57 0 0         $d_style |= &Wx::wxSTAY_ON_TOP if $Kephra::config{app}{window}{stay_on_top};
58 0 0         $dsettings->{position_x} = 10 if $dsettings->{position_x} < 0;
59 0 0         $dsettings->{position_y} = 10 if $dsettings->{position_y} < 0;
60 0 0         $dsettings->{width} = Wx::wxMSW() ? 436 : 496;
61 0 0         if ( Kephra::Edit::Search::_history()->{use} ) {
62 0           @find_history = @{ Kephra::Edit::Search::get_find_history() };
  0            
63 0           @replace_history = @{ Kephra::Edit::Search::get_replace_history() };
  0            
64             }
65            
66             # init search and replace dialog and release
67 0           Kephra::Edit::Search::_refresh_search_flags();
68 0           $active = 1;
69 0           $Kephra::temp{dialog}{active}++;
70 0           $highlight_search = 1;
71            
72             # make dialog window and main panel
73 0           my $d = Wx::Dialog->new(
74             Kephra::App::Window::_ref(), -1,
75             $l18n->{dialog}{search}{title},
76             [ $dsettings->{position_x}, $dsettings->{position_y} ],
77             [ -1 , 268 ], $d_style );
78 0           my $icon = Wx::Icon->new;
79 0           my $icon_bmp = Kephra::CommandList::get_cmd_property
80             ('view-dialog-find', 'icon');
81 0 0         $icon->CopyFromBitmap($icon_bmp) if ref $icon_bmp eq 'Wx::Bitmap';
82 0           $d->SetIcon($icon);
83 0 0         $d->SetTransparent(1 - int ($dsettings->{transparency} * 255))
84             if defined $dsettings->{transparency};
85 0           _ref($d);
86            
87             # input boxes with labels
88 0           $d->{find_label} = Wx::StaticText->new($d, -1, $label->{search_for} );
89 0           $d->{replace_label}= Wx::StaticText->new($d, -1, $label->{replace_with} );
90 0           $d->{find_input} = Wx::ComboBox->new
91             ($d, -1,'', [-1,-1], [334,-1], [@find_history], &Wx::wxTE_PROCESS_ENTER );
92 0           $d->{find_input}->SetDropTarget
93             ( Kephra::Edit::Search::InputTarget->new($d->{find_input}, 'find'));
94 0           $d->{replace_input} = Wx::ComboBox->new
95             ($d, -1, '', [-1,-1], [334,-1], [@replace_history], &Wx::wxTE_PROCESS_ENTER);
96 0           $d->{replace_input}->SetDropTarget
97             ( Kephra::Edit::Search::InputTarget->new($d->{replace_input}, 'replace'));
98 0           $d->{sep_line} = Wx::StaticLine->new(
99             $d, -1, [0,0], [420,1], &Wx::wxLI_HORIZONTAL,);
100            
101             # search attributes checkboxes
102 0           $d->{inc_box} = Wx::CheckBox->new($d, -1, $label->{incremental});
103 0           $d->{case_box} = Wx::CheckBox->new($d, -1, $label->{case});
104 0           $d->{begin_box}= Wx::CheckBox->new($d, -1, $label->{word_begin});
105 0           $d->{word_box} = Wx::CheckBox->new($d, -1, $label->{whole_word});
106 0           $d->{regex_box}= Wx::CheckBox->new($d, -1, $label->{regex});
107 0           $d->{wrap_box} = Wx::CheckBox->new($d, -1, $label->{auto_wrap});
108 0           $d->{inc_box} ->SetValue( $attr->{incremental} );
109 0           $d->{case_box} ->SetValue( $attr->{match_case} );
110 0           $d->{begin_box}->SetValue( $attr->{match_word_begin} );
111 0           $d->{word_box} ->SetValue( $attr->{match_whole_word} );
112 0           $d->{regex_box}->SetValue( $attr->{match_regex} );
113 0           $d->{wrap_box} ->SetValue( $attr->{auto_wrap} );
114            
115             # range radio group
116 0           my $range_box = Wx::StaticBox->new($d, -1, $label->{search_in},
117             [-1,-1], [-1,-1], &Wx::wxSIMPLE_BORDER | &Wx::wxRAISED_BORDER,
118             );
119 0           $d->{selection_radio}= Wx::RadioButton->new($d, -1, $label->{selection});
120 0           $d->{document_radio} = Wx::RadioButton->new($d, -1, $label->{document} );
121 0           $d->{all_open_radio} = Wx::RadioButton->new($d, -1, $label->{open_documents} );
122             ################### disable
123            
124             # buttons
125 0           my $bmp = \&Kephra::Config::icon_bitmap;
126 0           $d->{replace_back}=Wx::BitmapButton->new($d,-1,&$bmp('replace-previous.xpm'));
127 0           $d->{replace_fore}=Wx::BitmapButton->new($d,-1,&$bmp('replace-next.xpm'));
128 0           $d->{backward_button}=Wx::BitmapButton->new($d,-1,&$bmp('go-previous.xpm'));
129 0           $d->{foreward_button}=Wx::BitmapButton->new($d,-1,&$bmp('go-next.xpm'));
130 0           $d->{fast_back_button}=Wx::BitmapButton->new($d,-1,&$bmp('go-fast-backward.xpm'));
131 0           $d->{fast_fore_button}=Wx::BitmapButton->new($d,-1,&$bmp('go-fast-forward.xpm'));
132 0           $d->{first_button}=Wx::BitmapButton->new($d,-1,&$bmp('go-first.xpm'));
133 0           $d->{last_button}=Wx::BitmapButton->new($d,-1,&$bmp('go-last.xpm'));
134 0           $d->{search_button} = Wx::Button->new($d, -1, $label->{search} );
135 0           $d->{replace_button}= Wx::Button->new($d, -1, $label->{replace_all} );
136 0           $d->{confirm_button}= Wx::Button->new($d, -1, $label->{with_confirmation} );
137 0           $d->{close_button} = Wx::Button->new($d, -1, $l18n->{dialog}{general}{close} );
138            
139             #tooltips / hints
140 0 0         if ( $dsettings->{tooltips} ) {
141 0           $d->{foreward_button}->SetToolTip( $hint->{forward});
142 0           $d->{backward_button}->SetToolTip( $hint->{backward});
143 0           $d->{fast_fore_button}->SetToolTip( $hint->{fast_forward});
144 0           $d->{fast_back_button}->SetToolTip( $hint->{fast_backward});
145 0           $d->{first_button}->SetToolTip( $hint->{document_start});
146 0           $d->{last_button}->SetToolTip( $hint->{document_end});
147 0           $d->{replace_fore}->SetToolTip( $hint->{replace_forward});
148 0           $d->{replace_back}->SetToolTip( $hint->{replace_backward});
149 0           $d->{case_box}->SetToolTip( $hint->{match_case});
150 0           $d->{begin_box}->SetToolTip( $hint->{match_word_begin});
151 0           $d->{word_box}->SetToolTip( $hint->{match_whole_word});
152 0           $d->{regex_box}->SetToolTip( $hint->{match_regex});
153 0           $d->{wrap_box}->SetToolTip( $hint->{auto_wrap});
154 0           $d->{inc_box}->SetToolTip( $hint->{incremental});
155             }
156            
157             # eventhandling
158 0           Wx::Event::EVT_KEY_DOWN($d->{find_input}, \&find_input_keyfilter );
159 0           Wx::Event::EVT_KEY_DOWN($d->{replace_input}, \&replace_input_keyfilter );
160 0           Wx::Event::EVT_TEXT($d, $d->{find_input}, \&incremental_search );
161             Wx::Event::EVT_TEXT($d, $d->{replace_input}, sub {
162 0     0     my $input = $d->{replace_input};
163 0           my $pos = $input->GetInsertionPoint;
164 0           Kephra::Edit::Search::set_replace_item( $input->GetValue );
165 0           $input->SetInsertionPoint($pos);
166 0           });
167             Wx::Event::EVT_CHECKBOX($d, $d->{case_box}, sub {
168 0     0     $$attr{match_case} = $d->{case_box}->GetValue;
169 0           Kephra::Edit::Search::_refresh_search_flags();
170 0           } );
171             Wx::Event::EVT_CHECKBOX($d, $d->{begin_box}, sub {
172 0     0     $$attr{match_word_begin} = $d->{begin_box}->GetValue;
173 0           Kephra::Edit::Search::_refresh_search_flags();
174 0           } );
175             Wx::Event::EVT_CHECKBOX($d, $d->{word_box}, sub {
176 0     0     $$attr{match_whole_word} = $d->{word_box}->GetValue;
177 0           Kephra::Edit::Search::_refresh_search_flags();
178 0           } );
179             Wx::Event::EVT_CHECKBOX($d, $d->{regex_box}, sub {
180 0     0     $$attr{match_regex} = $d->{regex_box}->GetValue;
181 0           Kephra::Edit::Search::_refresh_search_flags();
182 0           } );
183             Wx::Event::EVT_CHECKBOX($d, $d->{wrap_box}, sub {
184 0     0     $$attr{auto_wrap} = $d->{wrap_box}->GetValue;
185 0           } );
186             Wx::Event::EVT_CHECKBOX($d, $d->{inc_box}, sub {
187 0     0     $$attr{incremental} = $d->{inc_box}->GetValue;
188 0           } );
189 0     0     Wx::Event::EVT_RADIOBUTTON($d, $d->{selection_radio},sub {$attr->{in} = 'selection'});
  0            
190 0     0     Wx::Event::EVT_RADIOBUTTON($d, $d->{document_radio}, sub {$attr->{in} = 'document'});
  0            
191 0     0     Wx::Event::EVT_RADIOBUTTON($d, $d->{all_open_radio}, sub {$attr->{in} = 'open_docs'});
  0            
192             Wx::Event::EVT_BUTTON($d, $d->{foreward_button}, sub {
193 0     0     &no_sel_range; Kephra::Edit::Search::find_next();
  0            
194 0           } );
195             Wx::Event::EVT_BUTTON($d, $d->{backward_button}, sub {
196 0     0     &no_sel_range; Kephra::Edit::Search::find_prev();
  0            
197 0           } );
198             Wx::Event::EVT_BUTTON($d, $d->{fast_fore_button}, sub {
199 0     0     &no_sel_range; Kephra::Edit::Search::fast_fore();
  0            
200 0           } );
201             Wx::Event::EVT_BUTTON($d, $d->{fast_back_button}, sub {
202 0     0     &no_sel_range; Kephra::Edit::Search::fast_back();
  0            
203 0           } );
204             Wx::Event::EVT_BUTTON($d, $d->{first_button}, sub {
205 0     0     &no_sel_range; Kephra::Edit::Search::find_first();
  0            
206 0           } );
207             Wx::Event::EVT_BUTTON($d, $d->{last_button}, sub {
208 0     0     &no_sel_range; Kephra::Edit::Search::find_last();
  0            
209 0           } );
210             Wx::Event::EVT_BUTTON($d, $d->{replace_fore}, sub {
211 0     0     &no_sel_range; Kephra::Edit::Search::replace_fore();
  0            
212 0           } );
213             Wx::Event::EVT_BUTTON($d, $d->{replace_back}, sub {
214 0     0     &no_sel_range; Kephra::Edit::Search::replace_back();
  0            
215 0           } );
216 0     0     Wx::Event::EVT_BUTTON($d, $d->{search_button}, sub{ &Kephra::Edit::Search::find_first } );
  0            
217 0     0     Wx::Event::EVT_BUTTON($d, $d->{replace_button}, sub{ &Kephra::Edit::Search::replace_all } );
  0            
218 0     0     Wx::Event::EVT_BUTTON($d, $d->{confirm_button}, sub{ &Kephra::Edit::Search::replace_confirm } );
  0            
219 0     0     Wx::Event::EVT_BUTTON($d, $d->{close_button}, sub{ shift->Close() } );
  0            
220            
221 0           Wx::Event::EVT_CLOSE( $d, \&quit_search_dialog );
222            
223            
224 0           my $ID = _ID();
225 0           my $add_call = \&Kephra::EventTable::add_call;
226            
227 0           &$add_call( 'find', $ID.'_color_refresh', \&colour_find_input, $ID);
228            
229             &$add_call( 'find.item.changed', $ID, sub {
230 0     0     $d->{find_input}->SetValue(Kephra::Edit::Search::get_find_item());
231 0           $d->{find_input}->SetInsertionPointEnd;
232 0           }, $ID);
233             &$add_call( 'replace.item.changed', $ID, sub {
234 0     0     $d->{replace_input}->SetValue(Kephra::Edit::Search::get_replace_item());
235 0           $d->{replace_input}->SetInsertionPointEnd;
236 0           }, $ID);
237            
238             Kephra::EventTable::add_call('find.item.history.changed', $ID, sub {
239 0     0     Kephra::App::_ref()->Yield();
240 0           my $cb = $d->{find_input};
241 0           $Kephra::temp{dialog}{search}{control} = 1;
242 0           $cb->Clear();
243 0           $cb->Append($_) for @{ Kephra::Edit::Search::get_find_history() };
  0            
244 0           $cb->SetValue( Kephra::Edit::Search::get_find_item() );
245 0           $cb->SetInsertionPointEnd;
246 0           $Kephra::temp{dialog}{search}{control} = 0;
247 0           }, $ID);
248             Kephra::EventTable::add_call('replace.item.history.changed', $ID, sub {
249 0     0     my $cb = $d->{replace_input};
250 0           $Kephra::temp{dialog}{search}{control} = 1;
251 0           $cb->Clear();
252 0           $cb->Append($_) for @{ Kephra::Edit::Search::get_replace_history() };
  0            
253 0           $cb->SetValue( Kephra::Edit::Search::get_replace_item() );
254 0           $cb->SetInsertionPointEnd;
255 0           $Kephra::temp{dialog}{search}{control} = 0;
256 0           }, $ID);
257            
258             # detecting and selecting search range
259             # if selection is just on one line
260 0 0         if ( $edit_panel->LineFromPosition( $edit_panel->GetSelectionStart )
    0          
261             != $edit_panel->LineFromPosition( $edit_panel->GetSelectionEnd ) ) {
262 0           $attr->{in} = 'selection';
263 0           $d->{selection_radio}->SetValue(1);
264             } elsif ( $attr->{in} eq 'open_docs' ) {
265 0           $d->{all_open_radio}->SetValue(1);
266             } else {
267 0           $attr->{in} = 'document';
268 0           $d->{document_radio}->SetValue(1);
269             }
270            
271             # assembling
272 0           my $aborder = 15;
273 0           my $option_sizer = Wx::BoxSizer->new(&Wx::wxVERTICAL);
274 0           $option_sizer->Add( $d->{inc_box}, 0, &Wx::wxTOP, 0 );
275 0           $option_sizer->Add( $d->{case_box}, 0, &Wx::wxTOP, $aborder );
276 0           $option_sizer->Add( $d->{begin_box}, 0, &Wx::wxTOP, 5 );
277 0           $option_sizer->Add( $d->{word_box}, 0, &Wx::wxTOP, 5 );
278 0           $option_sizer->Add( $d->{regex_box}, 0, &Wx::wxTOP, 5 );
279            
280 0           my $rbz = Wx::StaticBoxSizer->new( $range_box, &Wx::wxVERTICAL );
281 0           $rbz->Add( $d->{selection_radio}, 1, &Wx::wxTOP, 5 );
282 0           $rbz->Add( $d->{document_radio}, 1, &Wx::wxTOP, 5 );
283 0           $rbz->Add( $d->{all_open_radio}, 1, &Wx::wxTOP, 5 );
284 0           my $range_sizer = Wx::BoxSizer->new(&Wx::wxVERTICAL);
285 0           $range_sizer->Add( $d->{wrap_box}, 0, &Wx::wxTOP|&Wx::wxALIGN_CENTER_HORIZONTAL, 0 );
286 0           $range_sizer->Add( $rbz, 0, &Wx::wxGROW | &Wx::wxTOP, 10 );
287            
288 0           my $pad_grid = Wx::FlexGridSizer->new( 4, 2, 0 , 1 );
289 0           $pad_grid->Add( $d->{replace_back}, 0, &Wx::wxTOP|&Wx::wxBOTTOM, 10);
290 0           $pad_grid->Add( $d->{replace_fore}, 0, &Wx::wxTOP|&Wx::wxBOTTOM, 10);
291 0           $pad_grid->Add( $d->{backward_button}, 0, ,0);
292 0           $pad_grid->Add( $d->{foreward_button}, 0, ,0);
293 0           $pad_grid->Add( $d->{fast_back_button},0, ,0);
294 0           $pad_grid->Add( $d->{fast_fore_button},0, ,0);
295 0           $pad_grid->Add( $d->{first_button}, 0, ,0);
296 0           $pad_grid->Add( $d->{last_button}, 0, &Wx::wxRIGHT, $aborder);
297            
298 0           my $pads_sizer = Wx::BoxSizer->new(&Wx::wxHORIZONTAL);
299 0           $pads_sizer->Add( $option_sizer,0,&Wx::wxALIGN_LEFT ,0);
300 0           $pads_sizer->Add( $range_sizer ,1,&Wx::wxALIGN_CENTER|&Wx::wxLEFT|&Wx::wxRIGHT|&Wx::wxGROW ,20);
301 0           $pads_sizer->Add( $pad_grid ,0,&Wx::wxALIGN_RIGHT ,0);
302            
303 0           my $button_sizer = Wx::BoxSizer->new(&Wx::wxHORIZONTAL);
304 0           $button_sizer->Add( $d->{search_button}, 0, &Wx::wxLEFT, $aborder );
305 0           $button_sizer->Add( $d->{replace_button}, 0, &Wx::wxLEFT, 10 );
306 0           $button_sizer->Add( $d->{confirm_button}, 0, &Wx::wxLEFT, 10 );
307 0           $button_sizer->AddStretchSpacer;
308 0           $button_sizer->Add( $d->{close_button}, 0, &Wx::wxALIGN_RIGHT|&Wx::wxRIGHT, 15 );
309            
310 0           my $b_grid = Wx::FlexGridSizer->new( 3, 2, 10, 0 );
311 0           $b_grid->Add($d->{find_label}, 0, &Wx::wxLEFT | &Wx::wxRIGHT | &Wx::wxALIGN_CENTER_VERTICAL | &Wx::wxALIGN_RIGHT, 10);
312 0           $b_grid->Add($d->{find_input}, 1, &Wx::wxRIGHT, $aborder);
313 0           $b_grid->Add($d->{replace_label}, 0, &Wx::wxLEFT | &Wx::wxRIGHT | &Wx::wxALIGN_CENTER_VERTICAL | &Wx::wxALIGN_RIGHT, 10);
314 0           $b_grid->Add($d->{replace_input}, 1, &Wx::wxRIGHT, $aborder);
315 0           $b_grid->AddSpacer(5);
316 0           $b_grid->Add($pads_sizer, 1, &Wx::wxTOP|&Wx::wxGROW, 5);
317            
318 0           my $d_sizer = Wx::BoxSizer->new(&Wx::wxVERTICAL);
319 0           $d_sizer->Add($b_grid, 1, &Wx::wxTOP , $aborder);
320 0           $d_sizer->Add($d->{sep_line}, 0, &Wx::wxTOP | &Wx::wxALIGN_CENTER_HORIZONTAL | &Wx::wxGROW, 8);
321 0           $d_sizer->Add($button_sizer, 0, &Wx::wxTOP | &Wx::wxBOTTOM | &Wx::wxGROW , 9);
322            
323 0           $d->SetSizer($d_sizer);
324 0           $d->Fit();
325             #$d->SetAutoLayout(1);
326            
327             # go
328 0           $d->Show(1);
329 0           return $d;
330             } else {
331 0           my $d = _ref();
332 0           $d->Iconize(0);
333 0           $d->Raise;
334 0           return $d;
335             }
336             }
337            
338             # end of dialog constuction
339             ##########################
340             # dialog event functions
341            
342             # switch back from search in text selection to search in document
343             # because if once looked in selection the finding is selected and this
344             # settings makes no longer sense
345             sub no_sel_range {
346 0     0     my $dialog = _ref();
347 0 0         if ( $dialog->{selection_radio}->GetValue ) {
348 0           $dialog->{document_radio}->SetValue(1);
349 0           Kephra::Edit::Search::_attributes()->{in} = 'document';
350             }
351             #$dialog->Refresh; #$dialog->Layout();
352             }
353            
354            
355             # find input function
356             sub find_input_keyfilter {
357 0     0     my ( $input, $event ) = @_;
358 0           my $dialog = _ref();
359 0           my $wx_frame = $dialog->GetParent;
360 0           my $key_code = $event->GetKeyCode;
361 0 0         if ($key_code == &Wx::WXK_RETURN) {
    0          
    0          
362 0           no_sel_range();
363 0 0         if ($event->ControlDown){Kephra::Edit::Search::find_first(); $dialog->Close; }
  0 0          
  0            
  0            
364 0           elsif ($event->ShiftDown ){Kephra::Edit::Search::find_prev() }
365             else {Kephra::Edit::Search::find_next() }
366 0           return;
367             }
368 0           elsif ($key_code == &Wx::WXK_ESCAPE) { $dialog->Close }
369             elsif ($key_code == &Wx::WXK_TAB){
370 0 0         if ( $event->ShiftDown ) { $dialog->{close_button}->SetFocus }
  0            
371 0           else { $dialog->{replace_input}->SetFocus}
372             }
373 0           $event->Skip;
374             }
375            
376             sub colour_find_input {
377 0     0     my $input = _ref()->{find_input};
378 0           my $pos = $input->GetInsertionPoint;
379 0 0         my $found_something = Kephra::Edit::Search::_find_pos() > -1
380             ? 1 : 0;
381 0 0         return if $highlight_search eq $found_something;
382 0           $highlight_search = $found_something;
383 0 0         if ($found_something){
384 0           $input->SetForegroundColour( $color{norm_fore} );
385 0           $input->SetBackgroundColour( $color{norm_back} );
386             } else {
387 0           $input->SetForegroundColour( $color{alert_fore} );
388 0           $input->SetBackgroundColour( $color{alert_back} );
389             }
390 0           $input->SetInsertionPoint($pos);
391 0           $input->Refresh;
392             }
393            
394             sub incremental_search {
395 0 0 0 0     if ( Kephra::Edit::Search::_attributes()->{incremental}
396             and not $Kephra::temp{dialog}{search}{control} ) {
397 0           my $input = _ref()->{find_input};
398 0           Kephra::Edit::Search::set_find_item($input->GetValue);
399 0           Kephra::Edit::Search::first_increment();
400             }
401             }
402            
403             # replace input function
404             sub replace_input_keyfilter {
405 0     0     my ($input, $event) = @_;
406 0           my $dialog = _ref();
407 0           my $key_code = $event->GetKeyCode;
408 0 0         if ($key_code == &Wx::WXK_RETURN ) {
409 0 0         if ( $event->ControlDown ) {
    0          
410 0           Kephra::Edit::Search::replace_all();
411 0           $dialog->Close;
412 0           } elsif ( $event->AltDown ) { replace_confirm($dialog) }
413 0           else { Kephra::Edit::Search::replace_all() }
414             }
415 0 0         if ( $key_code == &Wx::WXK_ESCAPE) { $dialog->Close }
  0 0          
416             elsif ($key_code == &Wx::WXK_TAB){
417 0 0         if ( $event->ShiftDown ) { $dialog->{find_input}->SetFocus }
  0            
418 0           else { $dialog->{inc_box}->SetFocus }
419             }
420 0           $event->Skip;
421             }
422            
423 0     0     sub replace_all { Kephra::Edit::Search::replace_all() }
424 0     0     sub replace_confirm { Kephra::Edit::Search::replace_confirm() }
425 0 0   0     sub raise_if_active { _ref()->Raise if $active }
426            
427             sub quit_search_dialog {
428 0     0     my ( $win, $event ) = @_;
429 0           my $config = Kephra::API::settings()->{dialog}{search};
430 0 0         ($config->{position_x}, $config->{position_y} ) = $win->GetPositionXY
431             if $config->{save_position} == 1;
432            
433 0           $active = 0;
434 0           $Kephra::temp{dialog}{active}--;
435            
436 0           Kephra::EventTable::del_own_subscriptions( _ID() );
437            
438 0           $win->Destroy();
439             }
440             #######################
441             1;