Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Double Click event handler for Tree View

Contributor ,
Jan 25, 2014 Jan 25, 2014

Hi,

So, according to the Object Model Viewer in ESTK...TreeView does not have an onDoubleClick event.  I'm wondering if this can be added in any way?  I've looked into the controlObj.addEventListener() functionality but it's unclear how to actually add the double click listener.  It says that both click and double click are the same event name and you differentiate between them by specifying a detail level, 1 being single click, 2 being double click.

          controlObj.addEventListener("click (detail = 2)", func);

It may be that if an element doesn't implement the event handler then it can never be added.  I did notice that I could add a "click" event handler to the TreeView which is not supposed to be implemented on the TreeView. 

Any thoughts on how to use TreeView.addEventListener to defined the double click event?  How would I send it the different "detail" value? 

Thanks!

TOPICS
Scripting
4.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jan 27, 2014 Jan 27, 2014

I've been trying to figure this out too. I can get single clicks, but no double clicks with event listeners for TreeView or ListBox. I could really use it too.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 28, 2014 Jan 28, 2014

Yeah, AE isn't great about click/double click event listeners.  I think if they were separate "types" when calling obj.addEventListener() there'd be no problem.  It's this eventType "click" with detail=1/2 for single/double.  Unfortunately I think the detail level mentioned in the doucmentation may not have been implemented.

I actually spent a few hours hacking together a little solution.  I'm still working out the bugs but should be able to share it in the next week or so.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jan 28, 2014 Jan 28, 2014

Hi.

I think the syntax to use for event listeners is more something like this:

controlObj.addEventListener("click", func);

function func(ev){

if (ev.detail===2) {}

else{};

return;

};

Still can't trigger a double click event on a listbox though (AE CS5.5).

Xavier.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 28, 2014 Jan 28, 2014

if double click is not working, you can try to schedule an event in 250ms (function A will be triggered), if another click happens in this time, do not call function A but function B.

you might want to use :

app.scheduleTask()

app.cancelTasK()

a variable to store the time of the last click.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 28, 2014 Jan 28, 2014

David, to speak to your needs for ListBox...in CS6, ListBox does implement an onDoubleClick event handler which worked fine for me.  TreeView, not yet.

UQg, I got that much as far as functionality from the documentation, but unfortunately ev.detail does not get set for the "click" event of either ListBox or TreeView.  It defaults to "0" for both single and double click.  So, it appears that no matter what, if you piggyback on the "click" event, it will always be a single click.

The soluation I came up with is in essence what chauffeurdevan mentioned...although I wrote my own setTimeout function since I wanted to be able to programmatically control some calls.

I'm going to bundle up my solution into a little tutorial and I'll post it back here.

Thanks for all the great feedback!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jan 28, 2014 Jan 28, 2014

@chauffeurdevan: Thanks for sharing the schedule/cancel task idea.

I had noticed too that the listbox click ev.detail was always 0 but really didnt think there could be a workaround.

Double clicking a listbox item is so much more natural than shift+click or whatever else.

Xavier.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jan 28, 2014 Jan 28, 2014

I must have been doing something wrong then. I was unable to get double clicks on listbox elements previously. I was coding in CC. I appreciate the solutions being given here too. Good stuff.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 28, 2014 Jan 28, 2014

Here's what I did for double click on a ListBox (worked in both CS6 and CC):

     element.onDoubleClick = function() { alert("double click!"); }

The way it handles selection is a little wonky too so you have to jump through some of those hoops too.  I've also found that dynamically created content, especially with TreeViews, can create some unexpected behavior with selection values.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jan 28, 2014 Jan 28, 2014

Well, crud, how was I not able to make that work previously. (smacking head) Just pulled up and old script and tried it out and sure enough it works. I'm able to get items and subItems from the listbox. That was stupid simple. Hahaha.

list.onDoubleClick = function(){alert(this.selection)};

list.onDoubleClick = function(){alert(this.selection.subItems)};

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 28, 2014 Jan 28, 2014

Ah, the world of software development...

Glad I could help!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 22, 2014 Aug 22, 2014

Well, this works in the case of "listbox", but it doesn't with "treeview" (May I be wrong? But I cannot get it to work)

Any Ideas for that case ?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Sep 02, 2014 Sep 02, 2014

I just drafted up a sample script demonstrating the available event handlers. You apply the handler to the treeview object and not the individual nodes/items:

{

  function test(thisObj){

  function test_buildUI(thisObj){

  var testPal = (thisObj instanceof Panel) ? thisObj : new Window("palette", "Treeview event handling testing", undefined, {resizeable:true});

  if (testPal != null){

  var testRes ="group{orientation:'column', alignment:['fill','fill'], alignChildren:['fill','fill'],\

  tree: TreeView{},\

  }"

  testPal.grp = testPal.add(testRes);

  var t1 = testPal.grp.tree.add("node", "Node 1");

  var t2 = t1.add("node", "Node 2");

  var t3 = t2.add("item", "Item 1");

  testPal.grp.tree.onChange = function(){alert(this.selection.text + " OnChange");};

  testPal.grp.tree.onDoubleClick = function(){alert(this.selection.text + " OnDoubleClick");};

  testPal.grp.tree.onCollapse = function(){alert(this.selection.text + " onCollapse");};

  testPal.grp.tree.onExpand = function(){alert(this.selection.text + " onExpand");};

  testPal.layout.layout(true);

  testPal.grp.minimumSize = testPal.grp.size;

  testPal.layout.resize();

  testPal.onResizing = testPal.onResize = function () {this.layout.resize();}

  return testPal;

  }

  }

  var testPalGUI = test_buildUI(thisObj);

  if (testPalGUI != null){

  if (testPalGUI instanceof Window){

  testPalGUI.center();

  testPalGUI.show();

  }

  }

  }

  test(this);

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 23, 2014 Sep 23, 2014

Looks ok, but TreeView onDoubleClick doesn't work in the enviroment of AfterEffects CS6.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 10, 2014 Dec 10, 2014
LATEST

PLEASE NOTE: This post is about using double click functionality in After Effects CS6. I do not use CC, so replies not relative to CS6 are not what I am looking for. I have posted before but people failed to read the post properly and I received information about the CC version. Thanks in advance.

I have also been trying to set up a double click function for a treeview selection. I cannot believe that this has proven so difficult. I have written a double click function (below) but while I can run scripts from Extendscript with the double click function, when I open after effects and run my UI, none of the double clicks work. Anyone know why this simple but effective handler is so contrived in CS6?

myOnDoubleClick = function(event)

                        {

                            if(event.detail ==  2)

                            {

                                var script = (event.target.selection.text);

                                if (event.target.selection.text  !==  "my AFX Scripts") {runSelectedScript(script); }

                                else if(event.target.selection.text  ===  "my AFX Scripts") {cantRunThis();  }

                            }

                        }             

                       myAFXScriptPanel.grp.groupOne.myMultiTreeView.addEventListener('click', myOnDoubleClick);

//END OF SCRIPT

runSelectedScript(script) is a function that takes the selected item text and concatenates it with a path and extension and then executes the script. As stated, works fine in Extendscript environment, but will not function in After Effects.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines