LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

renaming tree items

I have a TreeList Control in my GUI and my project manager wants me to be able to add either a context menu "rename" option, or a slow double left click rename option that works like windows's natural file/field renaming style, is there an EASY way to do this in CVI? or am I looking at some serious codemonkeyism...
0 Kudos
Message 1 of 12
(4,532 Views)
Hi Daniel,
 
I think the easiest way to do this is adding an item to the context menu, using the NewCtrlMenuItem function. In the callback function, specified in NewCtrlMenuItem, you can let the user enter a new name for the menu item, using the PromptPopup function...
0 Kudos
Message 2 of 12
(4,500 Views)
was afraid you would say that, my issue is that my project lead wants windows style field renaming, (slow double click inline renaming) but I'll have to tell him it's not happening.
0 Kudos
Message 3 of 12
(4,499 Views)

Hi Daniel,

I think there is a way to to this. You can edit a tree item's label by pressing the F2 button on your keyboard. If you would like to edit the label by slow double-clicking, you could emulate the F2 button using the FakeKeyStroke function. Only thing you need to do is monitor the time beween two callback functions with event set to EVENT_LEFT_CLICK. If you're stuck, just let me know and I might find the time to write you a piece of example code tomorrow...

 

 

0 Kudos
Message 4 of 12
(4,497 Views)
hmm, I understand what you're suggesting, but F2 seems to be non functional in the way you say...
0 Kudos
Message 5 of 12
(4,494 Views)

Hello,

I made you a small example. Check the attachment to this post. You should make sure that the item's ATTR_NO_EDIT_LABEL attribute is not set. Also, note that the left-click event in the callback function is swallowed after the F2 key stroke is simulated (function returns 1 instead of 0). If you don't swallow the event, the left-click is passed to the control after the callback function is finished, which immediately stops editing the label...

0 Kudos
Message 6 of 12
(4,460 Views)
Thank you, I will look over it shortly and look into integrating it into my code.
 
Update:
I am looking at it, the rename behavior is a tiny bit off as it expects you to select a node and then start the double click process so for renaming a new item, it's 3 clicks, along those same lines if you already have an item selected and didn't double click it, it should just take a single click anytime after the entry is selected, but I think I can work with this.  Also this demonstrated to me the useage of GetIndexFromPoint which was definately frustrating me in the past.  I don't totally understand "swallowing" but I'm sure I can figure it out, I've messed with it before but haven't really looked into it.
 
Once again thank you for the help, this IS the behavior I was looking for.


Message Edited by DanielGreen on 04-01-2008 10:17 AM
0 Kudos
Message 7 of 12
(4,435 Views)
Update:
 
I modified it a little bit, let me know what you think :-).
 
 
void CVICALLBACK DeferedTreeCallback (void *callbackData)
{
   CallCtrlCallback(PANEL, PANEL_TREE, EVENT_LEFT_CLICK, 0, 0, NULL);
}
int CVICALLBACK TreeCallback (int panel, int control, int event,
  void *callbackData, int eventData1, int eventData2) {
   
 static double t_click = 0.0;  // Timestamp of previous left-click action.
 double t_lap;      // Time elapsed since previous left-click item.
 static int last_index = -1;   // Previously left-clicked item index.
 int index;       // Currently left-clicked item index.
 int area;       // Should be the label area.
   
 switch (event) {
  case EVENT_LEFT_CLICK:
   
   // Check if clicked item is the same as the previously clicked item.
         area = 0;
   GetIndexFromPoint (panel, control, MakePoint (eventData2, eventData1), &index, &area, NULL);
   if (area != VAL_ITEM_LABEL_AREA) break;
   if (index != last_index){
    last_index = index;
    PostDeferredCall(DeferedTreeCallback, callbackData);
            break;
   }
   
   t_lap = Timer () - t_click;
   t_click = Timer();
         // Check the time elapsed since the previous left click.
   if (t_lap >= 1.0){
    FakeKeystroke (VAL_F2_VKEY);
    return 1; // Swallow the event!
   }
   break;
 }
0 Kudos
Message 8 of 12
(4,431 Views)

Just as an FYI....

You can call

SetCtrlAttribute(panel, control, ATTR_TREE_RUN_STATE, VAL_EDIT_STATE);

instead of

FakeKeystroke (VAL_F2_VKEY);

It has the same behaivior and I think it is a little cleaner.

- jared

0 Kudos
Message 9 of 12
(4,430 Views)
Very good to know, I've implemented this change and it works as intended, thank you everyone for your assistance on this... now if I can just figureout my CVIXMLSaveDocument formatting issue i'm good to go 😄
0 Kudos
Message 10 of 12
(4,428 Views)