Author Topic: A little modification to tags.e (Added tag preview)  (Read 14925 times)

Ding Zhaojie

  • Senior Community Member
  • Posts: 194
  • Hero Points: 37
A little modification to tags.e (Added tag preview)
« on: September 25, 2006, 03:44:35 AM »
In SourceInsight, when multiple symbol locations found while performing "Jump to Definition". A symbol list with preview field will be shown and it is very convenience to choose the symbol because you can preview them. (See pic 1)

But Slickedit does not have the preview field. When you selecting tags, it is very hard to choose the right one if there are many tags listed without a preview. So I added a callback function to capture the selected item in list and show it in the Symbol Window. (See pic 2)

1. Open tags.e
2. Find the tag_select_match() function
3. Insert this callback function before it:
Code: [Select]
defeventtab _select_tree_form;
/**
 * Callback routine handles the select_tree dialog events.
 * It shows the selected tag preview in the symbol window.
 *
 * @param reason
 * @param user_data
 * @param info
 *
 * @return _str
 *
 * @author Ding Zhaojie
 */
static _str tag_select_callback(int reason, typeless user_data, typeless info=null)
{
   switch (reason) {
   case SL_ONINITFIRST:
   case SL_ONSELECT:
      if (info != null) {
         _nocheck _control ctl_tree;
         struct VS_TAG_BROWSE_INFO cm;
         typeless temp;

         _str caption = ctl_tree._TreeGetCaption(info);
         parse caption with cm.member_name "\t" caption;
         if (cm.member_name != '') {
            parse caption with cm.file_name "\t" caption;
            parse caption with temp "\t" caption;
            cm.flags = 0;
            cm.class_name = '';
            cm.type_name = '';
            cm.line_no = temp;
            cb_refresh_output_tab(cm, 1);
         }
      }
      break;
   }
   return '';
}
4. Register the callback function: In tag_select_match() find the "match_id = select_tree" line, you will see "null, null, null". Change the second "null" to "tag_select_callback".
5. Reload tags.e.

Have fun :)

stxl

  • Community Member
  • Posts: 7
  • Hero Points: 0
Re: A little modification to tags.e (Added tag preview)
« Reply #1 on: September 25, 2006, 05:50:58 AM »
Thanks!

hs2

  • Senior Community Member
  • Posts: 2761
  • Hero Points: 292
Re: A little modification to tags.e (Added tag preview)
« Reply #2 on: September 25, 2006, 10:14:29 AM »
This is a really good improvement Ding [thumb-up] !
Should be merged into the product.

HS2

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 6823
  • Hero Points: 526
Re: A little modification to tags.e (Added tag preview)
« Reply #3 on: September 25, 2006, 02:07:58 PM »
Nice!  Works for me.  Dennis will be back tomorrow.  I'll have him check this one over.  As long as this code is safe and doesn't conflict with anything new Dennis is working on, I don't see any reason why we can ship this in the next release.

alex

  • Community Member
  • Posts: 64
  • Hero Points: 6
Re: A little modification to tags.e (Added tag preview)
« Reply #4 on: September 26, 2006, 06:50:31 PM »
Very cool.  If this goes in the product, I think it would be nice to have an option to have it toggle the symbol window on and then off again just for use by this rather than require that the symbol window be open already.  I usually have it closed, so I added toggle_symbol() calls before and after the select_tree call.  There's probably a nicer way of doing that, though.

Dennis

  • Senior Community Member
  • Posts: 3954
  • Hero Points: 515
Re: A little modification to tags.e (Added tag preview)
« Reply #5 on: September 26, 2006, 09:47:09 PM »
Nice catch.  I had intended to do that, but I must have forgotten.  This functionality will be in 12.0.  Note that the shipping version will use a timer so that you can scroll through items quickly, and will allow the symbol window to peep out for five seconds if it is auto-hidden.  It will not activate the symbol window if it is completely undocked (there are good reasons not to do this, focus issues, etc.).

alex

  • Community Member
  • Posts: 64
  • Hero Points: 6
Re: A little modification to tags.e (Added tag preview)
« Reply #6 on: September 27, 2006, 01:29:55 PM »
By the way, before I try to write one, is there already a function that lets you bring up a symbol in a given source file in the symbol window already?  For instance, I'd like to just have the cursor over a symbol and hit, say, ctrl-S, and have it bring up the symbol window with the current symbol used.

Dennis

  • Senior Community Member
  • Posts: 3954
  • Hero Points: 515
Re: A little modification to tags.e (Added tag preview)
« Reply #7 on: September 27, 2006, 02:15:42 PM »
Sure, no problem.

Code: [Select]
_command void preview_tag(VS_TAG_BROWSE_INFO cm=null)
               name_info(TAG_ARG','VSARG2_EDITORCTL|VSARG2_REQUIRES_MDI)
{
   orig_autohide_delay := def_toolbar_autohide_delay;
   def_toolbar_autohide_delay=5000;
   activate_toolbar("_tbtagwin_form","ctltagname",false);
   def_toolbar_autohide_delay=orig_autohide_delay;
   if (cm==null) {
      _UpdateTagWindow(true);
   } else {
      cb_refresh_output_tab(cm,true,true);
   }
}

RobFreundlich

  • Community Member
  • Posts: 47
  • Hero Points: 2
Re: A little modification to tags.e (Added tag preview)
« Reply #8 on: October 05, 2006, 12:50:14 PM »
Very cool.  If this goes in the product, I think it would be nice to have an option to have it toggle the symbol window on and then off again just for use by this rather than require that the symbol window be open already.  I usually have it closed, so I added toggle_symbol() calls before and after the select_tree call.  There's probably a nicer way of doing that, though.

I tried this, and had problems with it if the symbol window used auto-hide.  Specifically, the code that causes the symbol toolbar's window to become visible seems to clear the list of tag matches.  I narrowed it down to this line in _tbAutoShow() from tbautohide.e:

Code: [Select]
   // CHANGE_AUTO_SHOW event to let tool window know it is about to be shown.
   // This gives the tool window a chance to look pretty for the user.
   wid.call_event(CHANGE_AUTO_SHOW,wid,ON_CHANGE,'w');

Right before that line, calling tag_get_match_info() for a specific match_id fills the cm structure with data, but right after it, the same call leaves cm empty.

So what I did instead of a simple toggle_symbol() before and after select_tree is to put this before select_tree:

Code: [Select]
      int wid = _tbIsVisible('_tbtagwin_form');

      if (wid == 0) {
         tag_push_matches();
         toggle_symbol();
         tag_pop_matches();
      }

I originally had this after it:

Code: [Select]
    if (wid == 0) {
         toggle_symbol();
    }

But it doesn't seem necessary since the auto-hide feature will make the symbol toolbar's window hide anyway.

Wanderer

  • Senior Community Member
  • Posts: 557
  • Hero Points: 23
Re: A little modification to tags.e (Added tag preview)
« Reply #9 on: October 05, 2006, 01:30:09 PM »
Sure, no problem.

Code: [Select]
_command void preview_tag(VS_TAG_BROWSE_INFO cm=null)
               name_info(TAG_ARG','VSARG2_EDITORCTL|VSARG2_REQUIRES_MDI)
{
   orig_autohide_delay := def_toolbar_autohide_delay;
   def_toolbar_autohide_delay=5000;
   activate_toolbar("_tbtagwin_form","ctltagname",false);
   def_toolbar_autohide_delay=orig_autohide_delay;
   if (cm==null) {
      _UpdateTagWindow(true);
   } else {
      cb_refresh_output_tab(cm,true,true);
   }
}

When I try to load this (SlickEdit 11.0.2, WinXP), I get an error: "Expecting ')'", with the cursor on the 'cm' param.
(I added #include "slick.sh" to the .e file.)
« Last Edit: October 05, 2006, 01:32:04 PM by Wanderer »

Dan

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2896
  • Hero Points: 153
Re: A little modification to tags.e (Added tag preview)
« Reply #10 on: October 05, 2006, 03:38:54 PM »
That is actually defined in tagsdb.sh.  Try this one:
Code: [Select]
#include "tagsdb.sh"
#include "slick.sh"
_command void preview_tag(VS_TAG_BROWSE_INFO cm=null) name_info(TAG_ARG','VSARG2_EDITORCTL|VSARG2_REQUIRES_MDI)
{
   int orig_autohide_delay = def_toolbar_autohide_delay;
   def_toolbar_autohide_delay=5000;
   activate_toolbar("_tbtagwin_form","ctltagname",false);
   def_toolbar_autohide_delay=orig_autohide_delay;
   if (cm==null) {
      _UpdateTagWindow(true);
   } else {
      cb_refresh_output_tab(cm,true,true);
   }
}

at5dapa1

  • Senior Community Member
  • Posts: 282
  • Hero Points: 24
Re: A little modification to tags.e (Added tag preview)
« Reply #11 on: October 19, 2006, 07:06:50 AM »
Very cool.  If this goes in the product, I think it would be nice to have an option to have it toggle the symbol window on and then off again just for use by this rather than require that the symbol window be open already.  I usually have it closed, so I added toggle_symbol() calls before and after the select_tree call.  There's probably a nicer way of doing that, though.

Hi,
1. instead of toggle_symbol before and after, maybe is better activate_symbol before only? Because in case the symbol is already open, toggle_symbol will close it.

2. If the symbol window is floating (see attached), it doesn't get updated when I'm clicking in the "Select a tag" dialog! Anybody can help? Thanks.

at5dapa1

  • Senior Community Member
  • Posts: 282
  • Hero Points: 24
Re: A little modification to tags.e (Added tag preview)
« Reply #12 on: October 24, 2006, 06:53:20 AM »
Hi,
I found the problem. I had to modify the cb_refresh_output_tab function from cbroweser.e.
If the parameter of _GetTagwinWID is set to false, then will be also working in my case, when the Symbol tab is not contained by the Output toolbar.
Daniel