SlickEdit Community

SlickEdit Product Discussion => SlickEditĀ® => Slick-CĀ® Macro Programming => Topic started by: jporkkahtc on March 21, 2017, 09:19:43 PM

Title: Opening Find initialized
Post by: jporkkahtc 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.
Title: Re: Opening Find initialized
Post by: Graeme 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;
}
Title: Re: Opening Find initialized
Post by: jporkkahtc 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;
}