Author Topic: Create macro that focuses on "Find symbol" and modifies the "look in" option  (Read 5922 times)

noam

  • Junior Community Member
  • Posts: 8
  • Hero Points: 0
Hi,
I would like to create a macro that puts the focus on the "Find symbol" window and changes the "look in" option to "<Current File>".
Could someone help please?
Thanks in advance,
Noam
« Last Edit: September 28, 2014, 10:45:57 AM by noam »

Graeme

  • Senior Community Member
  • Posts: 2812
  • Hero Points: 347
I did a similar thing here
http://community.slickedit.com/index.php/topic,3403.0.html

If you want the "search for" box to be empty you need to uncomment the two commented lines.

Code: [Select]
_command void find_symbol_word_at_cursor() name_info(','VSARG2_REQUIRES_EDITORCTL|VSARG2_CMDLINE)
{
   int xx;
   _control ctl_search_for;
   _str s = cur_word(xx);
   int wid = activate_toolbar('_tbfind_symbol_form', 'ctl_search_for', true);
   wid.ctl_search_for.p_text = s;
   wid.ctl_search_for._set_sel(1,length(s)+1);
}
 
 
_command void find_symbol_in_current_file() name_info(','VSARG2_REQUIRES_EDITORCTL|VSARG2_CMDLINE)
{
   int xx;
   _control ctl_search_for;
   _control ctl_lookin;
   int wid = activate_toolbar('_tbfind_symbol_form', 'ctl_search_for', true);
   wid.ctl_lookin.p_text = '<Current File>';
   //wid.ctl_search_for.p_text = '';
   //wid.ctl_search_for._set_sel(1,1);
}

Graeme

  • Senior Community Member
  • Posts: 2812
  • Hero Points: 347
oops, forgot to say how to load it.  Put the stuff below into a file e..g mymacros.e, plus the code I already posted, then load it using the load module command on the macro menu.

Code: [Select]
#include "slick.sh"

#pragma option(strictsemicolons,on)
#pragma option(strict,on)
#pragma option(autodecl,off)
#pragma option(strictparens,on)


noam

  • Junior Community Member
  • Posts: 8
  • Hero Points: 0
Thanks, it works!
« Last Edit: September 28, 2014, 11:54:33 AM by noam »

Graeme

  • Senior Community Member
  • Posts: 2812
  • Hero Points: 347
At some point (perhaps in V19) you might need to call activate_tool_window instead of activate_toolbar

Code: [Select]
       

#include "slick.sh"

#pragma option(strictsemicolons,on)
#pragma option(strict,on)
#pragma option(autodecl,off)
#pragma option(strictparens,on)


_command void find_symbol_word_at_cursor() name_info(','VSARG2_REQUIRES_EDITORCTL|VSARG2_CMDLINE)
{
   int xx;
   _control ctl_search_for;
   _str s = cur_word(xx);
   int wid = activate_tool_window('_tbfind_symbol_form', true, 'ctl_search_for');
   wid.ctl_search_for.p_text = s;
   wid.ctl_search_for._set_sel(1,length(s)+1);
}
 
 
_command void find_symbol_in_current_file() name_info(','VSARG2_REQUIRES_EDITORCTL|VSARG2_CMDLINE)
{
   int xx;
   _control ctl_search_for;
   _control ctl_lookin;
   int wid = activate_tool_window('_tbfind_symbol_form', true, 'ctl_search_for');
   wid.ctl_lookin.p_text = '<Current File>';
   //wid.ctl_search_for.p_text = '';
   //wid.ctl_search_for._set_sel(1,1);
}
 
 

asandler

  • Senior Community Member
  • Posts: 303
  • Hero Points: 27
I am trying this on v19.
It complains about line: wid.ctl_lookin.p_text = '<Current File>';
The error is: Control 'ctl-lookin' must be declared or cannot be a member of non-struct/union/class type.

Actually I think the way wid defined confuses me. It's an int, but then you attempt to access its members. It does work on v18.

Graeme

  • Senior Community Member
  • Posts: 2812
  • Hero Points: 347
It works for me with no error.  Maybe the call to activate_tool_window is failing for you.  Try this

   int wid = activate_tool_window('_tbfind_symbol_form', true, 'ctl_search_for');
   if (wid)
      wid.ctl_lookin.p_text = '<Current File>';

Does activate_find_symbol bring up the find symbol window?
What platform are you on?  I'm testing with V19.0.0.14 - what version are you?

asandler

  • Senior Community Member
  • Posts: 303
  • Hero Points: 27
Yes, activate-find-symbol works as expected. I am on v19.0.0.14. Adding if statement doesn't help - kind of makes sense because it fails to compile. I checked wid value - 204, not 0. It seems to have problem accessing ctl_lookin sub-field of wid.

asandler

  • Senior Community Member
  • Posts: 303
  • Hero Points: 27
Oh. I think I got it. I needed definition of _control ctl_lookin to make it work.
So eventually it looks like this:
Code: [Select]
_command void find_symbol_in_current_file() name_info(','VSARG2_REQUIRES_EDITORCTL|VSARG2_CMDLINE)
{
   _control ctl_lookin;
   int wid = activate_tool_window('_tbfind_symbol_form', true, 'ctl_search_for');
   wid.ctl_lookin.p_text = '<Current File>';
}
« Last Edit: November 13, 2014, 02:37:51 PM by asandler »