Author Topic: How disable the tree view redraws while modifying the tree items?  (Read 5157 times)

Ding Zhaojie

  • Senior Community Member
  • Posts: 194
  • Hero Points: 37
The Defs window in SlickEdit annoyed me for a long time. It always display the functions with arguments makes it is very hard to identify the function name in a glance. So I tried to add a filter function to remove the parameters in the Defs tree:
Code: [Select]
static void remove_parameters()
{
    int index = _TreeGetFirstChildIndex(TREE_ROOT_INDEX);
    while (index >= 0) {
        _TreeSetCaption(index, stranslate(_TreeGetCaption(index), '()', '\(?@\)', 'R'));
        index = _TreeGetNextIndex(index);
    }
}

And I call remove_parameters() in proctree.e: _UpdateCurrentTag() like this:
Code: [Select]
   if (NeedRefresh) {
      remove_parameters();
      _TreeRefresh(); //here!!!!!!!!!!!!!!!!!!!
   }

Seems it works, and I got the clear view I want. But the problem is: When I was typing, the Defs window keeps blinking. I tried to set the p_redraw to false, and tried to call the remove_parameters() just after the tag_tree_insert_context(), but none of them works.

So is there any way to disable the Defs tree redraw itself?

Lee

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1299
  • Hero Points: 130
Re: How disable the tree view redraws while modifying the tree items?
« Reply #1 on: July 20, 2009, 02:37:02 pm »
If you are making batch changes to a tree control, use _TreeBeginUpdate/_TreeEndUpdate around your changes.  That should defer any updates to the tree control until you issue the _TreeEndUpdate, and then you can issue a _TreeRefresh to force a redraw.

Ding Zhaojie

  • Senior Community Member
  • Posts: 194
  • Hero Points: 37
Re: How disable the tree view redraws while modifying the tree items?
« Reply #2 on: July 20, 2009, 02:45:02 pm »
If you are making batch changes to a tree control, use _TreeBeginUpdate/_TreeEndUpdate around your changes.  That should defer any updates to the tree control until you issue the _TreeEndUpdate, and then you can issue a _TreeRefresh to force a redraw.
I tried to add my remove_parameters() just before the _TreeEndUpdate() but the tree view still blinks.
Code: [Select]
     _TreeBeginUpdate(index,'','T');
      //_TreeDelete(index,'C');
      int force_leaf = (def_proc_tree_options&PROC_TREE_NO_STRUCTURE)? -1:1;
      if (force_leaf==1 && (def_proc_tree_options&PROC_TREE_AUTO_STRUCTURE)) {
         force_leaf=0;
      }
      tag_tree_insert_context(p_window_id, index, def_proctree_flags, 1, force_leaf, 0,
                              def_proc_tree_options&PROC_TREE_STATEMENTS);
      remove_parameters(); <<<<<<<<<<<<<<<
      _TreeEndUpdate(index);
« Last Edit: July 20, 2009, 02:52:30 pm by Ding Zhaojie »

Lee

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1299
  • Hero Points: 130
Re: How disable the tree view redraws while modifying the tree items?
« Reply #3 on: July 20, 2009, 03:18:39 pm »
Oh yeah, I should have read *all* of your original post.  _TreeBeginUpdate/_TreeEndUpdate is used to defer updates when adding/deleting items for the tree.   For captions, the tree node will have to be hidden in order to defer a repaint.   You can try something like this:

Code: [Select]
static void remove_parameters()
{
    _TreeSetInfo(TREE_ROOT_INDEX,0);  // hide all children of root
    int index = _TreeGetFirstChildIndex(TREE_ROOT_INDEX);
    while (index >= 0) {
        _TreeSetCaption(index, stranslate(_TreeGetCaption(index), '()', '\(?@\)', 'R'));
        index = _TreeGetNextIndex(index, 'H');  // 'H' return hidden nodes
    }
    _TreeSetInfo(TREE_ROOT_INDEX,1); // show all children
}

The drawback to this approach is that if there were any nodes hidden before this call, they will now be visible because of the show all children we do at the end.

Ding Zhaojie

  • Senior Community Member
  • Posts: 194
  • Hero Points: 37
Re: How disable the tree view redraws while modifying the tree items?
« Reply #4 on: July 21, 2009, 02:11:20 am »
Thanks, I tried your solution and the blinking problem resolved, but the Defs tree can not work correctly :(

But I found if I put the SortProcTree() before the _TreeEndUpdate(), the tree view would not blinking too often, looks much better.
Code: [Select]
     _TreeBeginUpdate(index,'','T');
      //_TreeDelete(index,'C');
      int force_leaf = (def_proc_tree_options&PROC_TREE_NO_STRUCTURE)? -1:1;
      if (force_leaf==1 && (def_proc_tree_options&PROC_TREE_AUTO_STRUCTURE)) {
         force_leaf=0;
      }

      tag_tree_insert_context(p_window_id, index, def_proctree_flags, 1, force_leaf, 0,
                              def_proc_tree_options&PROC_TREE_STATEMENTS);
      remove_parameters(); <<<<<<<<<<<<<<<<
      SortProcTree(index,def_proc_tree_options); <<<<<<<<<<<<<<<
      _TreeEndUpdate(index);
      // SortProcTree(index,def_proc_tree_options);

It is really strange, but it works.
« Last Edit: July 21, 2009, 02:15:33 am by Ding Zhaojie »