Author Topic: Macro code after events  (Read 4615 times)

rod_gomz

  • Community Member
  • Posts: 80
  • Hero Points: 1
Macro code after events
« on: April 16, 2009, 04:13:34 PM »
I'm just learning how Slickedit uses events. There is clipboard inheritance. There is inheritance order 1 and order 2. My issue that I have is that I like to hide my toolbars and have all the real estate dedicated to the code.

My screen looks like this:


As I investigated how the macro for gui_find worked I noticed that it is asynchronous. What I want to do is to toggle_search after a search command. That way the search results don't hide. I couldn't figure out how to do it with events and eventually end it up with a polling solution.
Code: [Select]
int thetimer;

void returned(){

   int obj2 = _find_formobj("_tbfind_form");
   if (obj2==0 || (obj2!=0 && obj2.p_visible==0)) {
      toggle_search();
      _kill_timer(thetimer);
   }


}


_command void my_gui_find() name_info(',')
{

   gui_find();
   thetimer = _set_timer(1000, returned);


}

I basically mapped my macro to ctrl+f and invoke gui_find. I then start a timer that polls every second for the presence of the find form.

The above works. But would it be possible to do it another way, i.e to extend the code for the event handler without modifying Slick's code? Maybe by using events? If this is not possible with the current setup, how hard would it be to add features to SlickC?

Rodrigo Gomez

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: Macro code after events
« Reply #1 on: April 16, 2009, 06:20:12 PM »
Do you mean that you start a search, the Search Results form slides out, and then auto-hides again?
This is a long-standing bug -- it's not supposed to lose focus.
This bug affects References and Search Results, and possibly other toolbars.
You'll notice that sometimes they stay visible, but often they don't.

I took a half-hearted stab at tracking this down a few months ago, but got interrupted by other stuff and never got back to it.

rod_gomz

  • Community Member
  • Posts: 80
  • Hero Points: 1
Re: Macro code after events
« Reply #2 on: April 16, 2009, 06:46:07 PM »
Do you mean that you start a search
Yes.
the Search Results form slides out
Yes
and then auto-hides again?
Yes.

I thought this was wanted behaiviour. Well, with my macro, it will be toggle and it won't hide. What I don't like about it is that it runs off a timer (polling). Somehow if this can be done cleverly using events (inheritance?).

Graeme

  • Senior Community Member
  • Posts: 2796
  • Hero Points: 347
Re: Macro code after events
« Reply #3 on: April 17, 2009, 11:15:31 AM »
I also tried to solve this problem without much success.

Did you know you can do a "foreground search" instead of the "asynchronous" search you mentioned.  See the "foreground search" checkbox in the find form.  On my machine, the search results window stays visible instead of disappearing with foreground search selected.  Unfortunately, the focus doesn't seem to be anywhere visible after the foreground search but if you're wanting to use the mouse instead of the keyboard to scroll through search results, it might be ok.

Clipboard inheritance won't help but you can always modify the code for the event handlers in tbfind.e - such as _find_btn.lbutton_up() or _tbfind_form.on_destroy().  Modifying the on_destroy function to activate the search results window effectively hung the editor so it's kind of trial and error and your timer solution is nicer from that point of view.

You can also output search results to an editor window and use the preview toolbar to view the code.

Graeme

rod_gomz

  • Community Member
  • Posts: 80
  • Hero Points: 1
Re: Macro code after events
« Reply #4 on: April 17, 2009, 03:19:38 PM »
I need to figure out how this foreground seach works. I just learned about it.

Also, I just noticed a problem with my code. Here is a better version:

Code: [Select]
int thetimer;
int find_form_deleted = 0;

void returned(){

   int obj2 = _find_formobj("_tbfind_form");
   if ((obj2==0 || (obj2!=0 && obj2.p_visible==0)) && find_form_deleted==0) {
      find_form_deleted=1;
      return;
   }
   if (find_form_deleted==1) {

      if(_tbIsAutoHidden('_tbsearch_form')){
         toggle_search();
      }
      _kill_timer(thetimer);
      return;

   }

}


_command void my_gui_find() name_info(',')
{
 
   gui_find();

   find_form_deleted=0;
   thetimer = _set_timer(500, returned);


}

Now the variable find_form_deleted will be set right after the search form is deleted and will wait an additional 500ms. Also, I've guarded the toggle_search with:

Code: [Select]
if(_tbIsAutoHidden('_tbsearch_form')){
         toggle_search();
      }

Rodrigo Gomez

rod_gomz

  • Community Member
  • Posts: 80
  • Hero Points: 1
Re: Macro code after events
« Reply #5 on: April 17, 2009, 03:22:26 PM »
If your mouse if over the search results, then the above code won't trigger the toggle_search because of the guarding code:

Code: [Select]
if(_tbIsAutoHidden('_tbsearch_form')){
         toggle_search();
      }

This is because the _tbIsAutoHidden will return false if the search form is visible.

Rodrigo Gomez