Author Topic: Opening Find initialized  (Read 496 times)

jporkkahtc

  • Senior Community Member
  • Posts: 1317
  • Hero Points: 97
  • Text
Opening Find initialized
« on: March 21, 2017, 09:19:43 pm »
Is there a macro way to open the Find dialog with specific settings?
I'd like to open Find in Replace mode, initialized with Search/Replace strings and in Perl Regex mode.

Graeme

  • Senior Community Member
  • Posts: 1948
  • Hero Points: 225
Re: Opening Find initialized
« Reply #1 on: March 22, 2017, 11:46:45 am »
Maybe something like this  (from xxutils.e).
By the way, did you know you can press Ctrl+Shift+space to open any slick c dialog in design mode.
[Edit - change tool-gui-find to tool-gui-replace]

Code: [Select]
_command int xsearch_cur_word() name_info(','VSARG2_READ_ONLY|VSARG2_REQUIRES_EDITORCTL|VSARG2_MARK)
{
   _str sw = get_search_cur_word();
   if (sw == '')
      return 0;

   int formid;
   if (isEclipsePlugin()) {
      show('-xy _tbfind_form');
      formid = _find_object('_tbfind_form._findstring');
      if (formid) {
         formid._set_focus();
      }
   } else {
      tool_gui_find();
      formid = activate_tool_window('_tbfind_form', true, '_findstring');
   }

   if (!formid) {
      return 0;
   }
   _control _findstring;
   formid._findstring.p_text = sw;
   formid._findstring._set_sel(1,length(sw)+1);
   return 1;
}
« Last Edit: March 22, 2017, 11:52:17 am by Graeme »

jporkkahtc

  • Senior Community Member
  • Posts: 1317
  • Hero Points: 97
  • Text
Re: Opening Find initialized
« Reply #2 on: March 22, 2017, 05:18:20 pm »
Thanks! Just what I needed.

I extended that code to fully initialize the replace.
It sets the find and replace strings, sets Perl RE and LookIn=CurrentBuffer.

I've attached the full code to the translator.
Select a block of text with the Find/Replace terms - one pair on each line.                                 
Run translateTerms.                                                                                         
It will open a find/replace dialog with the search strings initialized to do all the replacements.           
                                                                                                             
Example:                                                                                                     
    %windir%=C:\WINDOWS                                                                                     
    %ProgramData%=C:\ProgramData                                                                             
                                                                                                             
 This will replace "C:\Windows" with "%windir%" and "C:\ProgramData" with "%ProgramData%"                   


Code: [Select]
int gui_replace_init_re(_str findstr="", _str replacestr="")
{
   int formid;
   if (isEclipsePlugin()) {
      show('-xy _tbfind_form');
      formid = _find_object('_tbfind_form._findstring');
      if (formid) {
         formid._set_focus();
      }
   } else {
      tool_gui_replace();
      formid = activate_tool_window('_tbfind_form', true, '_findstring');
   }

   if (!formid) {
      return 0;
   }
   _control _findstring;
   _control _replacestring;
   _control _findre;
   _control _findre_type;
   _control _findbuffer;
   formid._findstring.p_text = findstr;
   formid._findstring._set_sel(1,length(findstr)+1);
   formid._replacestring.p_text = replacestr;
   formid._findre.p_value=1;
   formid._findre.call_event(formid._findre,LBUTTON_UP);
   formid._findbuffer.p_text = SEARCH_IN_CURRENT_BUFFER;
   formid._findre_type.p_text = RE_TYPE_PERL_STRING;
   formid._findre_type.call_event(formid._findre_type,LBUTTON_UP);
   return 1;
}