04-08-2016 09:26 AM
LV 2013, Win7
I'm an old hand at LabVIEW, but fairly new at using menus.
I have a window, where the user opens a file and edits it, and can save it.
What is actually edited is an array of clusters, each cluster contains several items. The user adjusts the array index and changes things around to suit.
There is an EDIT menu in the window, with the usual CUT COPY PASTE items in it.
The FILE menu has a SAVE item, with a Ctrl-S shortcut.
This pic shows the code attached to the MENU ACTIVATION? event, called when the user clicks on the menu bar, or hits a shortcut combo.
Note the WORKAROUND section:
The comment explains the point of the DUMMY - the problem is that LabVIEW (improperly, IMO) fails to terminate editing on a control before handling a shortcut key. The value read is the old value before the START of editing. Unless I force the focus somewhere else, then the file saved does not necessarily include the changes made to the field.
The above workaround works to solve that problem - but it introduces another.
I discovered that the EDIT menu will not work (neither mouse nor keyboard shortcuts).
The reason is simple: the edit menu works on the currently FOCUSED control, and since I'm changing the focus AWAY from the text control to a boolean DUMMY, the edit menu doesn't apply, so it gets disabled.
So, how do I get out of this?
Do I have to set all the fields to UPDATE VALUE WHILE TYPING, and lose the workaround?
Do I have to search for the focus, switch it to the dummy, then switch it back before saving?
Blog for (mostly LabVIEW) programmers: Tips And Tricks
04-08-2016 09:40 AM
The UPDATE VALUE WHILE TYPING idea won't work in all cases.
If I have a NUMERIC field, and I select the value 12.34 and start typing: 56.78^S, I expect to see 56.78 stored in the file.
But the same basic issue shows up - LV does NOT end editing on the control, so what gets saved is the old value 12.34.
There is no UPDATE VALUE WHILE TYPING for numeric controls.
Blog for (mostly LabVIEW) programmers: Tips And Tricks
04-08-2016 09:44 AM
> The comment explains the point of the DUMMY - the problem is that LabVIEW (improperly, IMO) fails to terminate editing on a control before handling a shortcut key.
It's your user's job to commit the change by hit the Enter Key.
If they don't, then the old value will be used.
Alternative, if the control is a string, you can force the control to Update While Typing.
04-08-2016 09:51 AM - edited 04-08-2016 09:52 AM
Instead of a dummy button, you can give your user a real button with a boolean text "Finish Editing".
So your user know they have to hit the button to commit the changes.
04-08-2016 10:00 AM - edited 04-08-2016 10:00 AM
It's your user's job to commit the change by hit the Enter Key.
But there are a thousand ways to commit the change - Hit ENTER, Tab to another control, click on another control, click outside the control, switch to a different program, etc.
But using a shortcut key is not one of them.
If you open a notepad file and type ABCDE^S, you get a file with ABCDE in it, like you'd expect.
It seems unnatural here in this case.
Blog for (mostly LabVIEW) programmers: Tips And Tricks
04-08-2016 10:12 AM
> If you open a notepad file and type ABCDE^S, you get a file with ABCDE in it, like you'd expect.
That's similar to a string control with "Update While Typing".
04-08-2016 10:18 AM
That's similar to a string control with "Update While Typing".
I understand that. But there's no such option for numeric controls, combo boxes, maybe others.
Blog for (mostly LabVIEW) programmers: Tips And Tricks
04-08-2016 10:26 AM - edited 04-08-2016 10:36 AM
> If you open a notepad file and type ABCDE^S, you get a file with ABCDE in it, like you'd expect.
Not an good example.
That's similar to a string control with "Update While Typing".
04-08-2016 10:42 AM
Instead of dummy.KeyFocus at the menu activate event,
make a control.KeyFocus + dummy.KeyFocus when you process the menu selection.
04-08-2016 10:47 AM
Instead of dummy.KeyFocus at the menu activate event,
make a control.KeyFocus + dummy.KeyFocus when you process the menu selection.
But in the case of the EDIT menu (with APP_CUT, etc. tags), I don't process the menu selection - that's all behind the scenes and I don't have any code to handle it.
A Ctrl-X never gets to my code, (unless I install a MENU SELECTION (APP) handler, which I don't have now.
Blog for (mostly LabVIEW) programmers: Tips And Tricks