Author Topic: How to do a find_file from a macro with a selection as part of a search term  (Read 2700 times)


  • Community Member
  • Posts: 9
  • Hero Points: 0
HI all, 

I'm new to writing macros but want to be able to use a text selection as the basis for searching a specific directory tree (not always the same one, so I'd bind this functionality to different keys/commands for different areas).. then get a list returned that I can select from to open one or more files for edit. 

find_file() seems to be a hardcoded dialog that has its own history and its own working directory (I think)




  • Senior Community Member
  • Posts: 2533
  • Hero Points: 329
You can write an on_create event handler for the _find_file_form as shown below, where you can populate the controls however you like.

Did you know you can open up slickedit dialogs in design mode?  Bring up the find file dialog and press Ctrl+Shift+Space.  You can now inspect the names of the various controls (combo boxes, edit boxes etc) on the dialog.  You can even add your own controls if you want, though they tend to disappear when you do an upgrade.  While the form is in design mode, double click on the search button and select the button up event  - you'll be taken to the event handler for that button - the code is in the macro file findfile.e.

You don't need to modify the findfile.e module.  You can add the code below to a macro file of your own.  To get at the selected text I think you need to use the filter-get-string function as shown in the second piece of code below  - which is taken from the examples.e module in the slick macros folder.  You can probably also use the _get_sel_info function and _begin_select _end_select  and get_line functions.  See "selection functions" in the help.
If you need any more help, just ask.

Code: [Select]
defeventtab _find_file_form;

   _control _file_pattern;
   _file_pattern.p_text = "*.h";

_command void example2() name_info(','VSARG2_MARK|VSARG2_READ_ONLY|VSARG2_REQUIRES_EDITORCTL)
   _str msg='';
   if( !select_active() ) {
      msg="No active selection";

   // Initialize filtering. This will put us at the beginning of the
   // selection and save the position so we can call filter_restore_pos()
   // at the end.

   // Get the selected portion of the first selected line and store in
   // the 'text' variable.
   _str text='';
   typeless status=filter_get_string(text);
   // If you were processing a multi-line selection, then you would
   // call filter_get_string() to get the next line, checking status
   // as you go to know when you have reached the end of the selection.

   // Restore the original position of the cursor

   msg="Selection = ":+text;



  • Community Member
  • Posts: 9
  • Hero Points: 0
Thanks very much for the push in the right direction! I'll try it out.