How to drop Popup Menus in a Data Grid on tab/return?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Contact:

Re: How to drop Popup Menus in a Data Grid on tab/return?

Post by trevordevore » Wed Sep 01, 2010 3:34 pm

That sounds reasonable. When trying to trap messages the first thing to check is which object has focus. I just posted a plugin that I use to monitor the focusedObject. This may help you in determining which object has focus and would thus receive messages. Here is the link:

A Plugin For Monitoring the focusedObject
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

MichaelBluejay
Posts: 235
Joined: Thu Jul 01, 2010 11:50 am

Re: How to drop Popup Menus in a Data Grid on tab/return?

Post by MichaelBluejay » Wed Sep 01, 2010 11:04 pm

Thank you very much. My next step is trying to trap the tabKey message when the Description field/column is open for editing. I installed the plugin and it tells me the focused name is field "DataGridFieldEditor". Since DataGrids impose their own interface over the table, I'm not sure where I'd locate that field. I tried adding a simple onTabKey handler to the field "_ColumnData_" which I accessed through the RowTemplate, but it doesn't fire when the field is open for editing and I press the Tab key. I also tried adding the handler to the column behavior script for the Description column, but it doesn't fire, either. I refreshed the data grid between attempts. Here is my script:

Code: Select all

on tabkey
   answer "tabkey test"
end tabkey
Where do I put this handler? Thank you very much for your help.

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Contact:

Re: How to drop Popup Menus in a Data Grid on tab/return?

Post by trevordevore » Wed Sep 01, 2010 11:16 pm

Look at this lesson on how to customize the field editor script. You can add your tabkey code to it.

http://lessons.runrev.com/spaces/lesson ... -Behavior-
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

MichaelBluejay
Posts: 235
Joined: Thu Jul 01, 2010 11:50 am

Re: How to drop Popup Menus in a Data Grid on tab/return?

Post by MichaelBluejay » Thu Sep 02, 2010 3:49 am

Thank you. I'm having hard time with this not just because the DataGrid terminology and interface is odd, but also because of inconsistent and unexpected behavior with RevStudio. Sometimes double-clicking won't open a field for editing. I can usually fix that by doing a Refresh Data Grid, but sometimes when I do that, all the data in the Data Grid disappears, and other times I start getting weird script errors that I never got before. Also, when I right-click the button that holds the behavior script from your last instruction and choose Edit Script, sometimes the mouse pointer turns into a wristwatch forever, and I have to Force Quit, losing my progress.

Anyway, following the page you referred me to, I'm now able to trap the TabKey. However, I can't get a tabstroke to drop the popup menu in the next column. That was something I had working a while back, but after Rev started throwing up various errors I deleted my old Data Grid Table and tried to reconstruct it, but I've been unable to get the menu drop working again. Here's my code:

Code: Select all

on tabKey
   put ColumnControlOfIndex("Account1", the dgIndex of me) into theColumnControl
   replace " of me" with empty in theColumnControl ## get rid of ' of me' reference
   put theColumnControl && the milliseconds
   if theColumnControl is not empty then
      ## assumes you used a group as your custom column template
      put the menuhistory of button 1 of theColumnControl into theSelectedLine
      ## click on the menu to display it
      answer the name of button 1 of theColumnControl
      click button 1 at the loc of button 1 of theColumnControl
   end if
   exit tabKey
   
   (default TabKey code is here, which I'm bypassing with the "exit" statement above for testing)
end tabKey
The "answer" command returns the proper name of the button I'm trying to click, "PopUp Menu", so Rev appears to have located the button correctly, but it's not dropping. What am I doing wrong?

By the way, earlier we were talking about whether MacOS sees keystrokes when a menu is dropped. I believe it does, because when I drop a menu in Safari and then press Tab, the next menu is dropped.

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Contact:

Re: How to drop Popup Menus in a Data Grid on tab/return?

Post by trevordevore » Thu Sep 02, 2010 2:22 pm

I'm having hard time with this not just because the DataGrid terminology and interface is odd
Not being a native control the Data Grid suffers from certain limitations inherent in the engine with regards to developer built custom controls. The major one is that a developer can't use the easy to ready/remember syntax that the language is known for. Instead it is limited by custom properties and functions/commands. This definitely adds to the learning curve on top of the fact that it is the only Rev control that uses behaviors and multi-dimensional arrays extensively.
inconsistent and unexpected behavior with RevStudio
There are some issues that lead to some of the behavior you are seeing.

One is a bug in the engine where script local variables are wiped out when you right-click on a control. This causes all of the data in the data grid to disappear because the data grid uses a script local variable. This is the cause behind the fields not opening and the data disappearing. It may also be the cause of the random errors you were seeing since your code might have been running and the expected data wasn't there. See this bug report: http://quality.runrev.com/qacenter/show_bug.cgi?id=8848. This bug has been fixed for the next release.

When the pointer turns into a wristwatch does the application actually freeze up? I've seen the cursor get locked in this state before but the IDE still worked as normal. If the IDE is locked up pressing COMMAND + . repeatedly can sometimes help.
Anyway, following the page you referred me to, I'm now able to trap the TabKey. However, I can't get a tabstroke to drop the popup menu in the next column.
Is this tabkey script in the field editor behavior? If so try using 'the dgTargetIndex of me' instead of 'the dgIndex of me'. The field editor isn't technically part of the row control of the field whose text you are editing so the dgIndex and the dgIndex of the dgDataControl won't work. A reference to the field whose contents are being edited is stored in the dgTargetField property of the field editor. The index is stored in the dgTargetIndex property and the key (or column name) is stored in the dgTargetKey property.

Also, try putting the long name of button 1 of theColumnControl rather than using the answer command so that execution doesn't stop and focus doesn't shift when the answer dialog appears. Let me know how that goes.
By the way, earlier we were talking about whether MacOS sees keystrokes when a menu is dropped
Well, the question is really whether or not Rev sees the keystrokes. OS X allows a use to enable control navigation via the tab key under System Preferences. Rev doesn't support this though.
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

MichaelBluejay
Posts: 235
Joined: Thu Jul 01, 2010 11:50 am

Re: How to drop Popup Menus in a Data Grid on tab/return?

Post by MichaelBluejay » Wed Sep 08, 2010 11:34 am

Thank you as usual for your expert answers. Slow as my progress has been, I would be at a complete standstill without your help.

I'm glad to hear that a future release might help with some of the problems I'm having.

Changing "dgIndex" to "dgTargetIndex" did the trick. (The tabkey handler is indeed in the field editor script.) Now the menu drops. So my next goal is to get the menu to drop only when a field in Column 4 is open and tab is pressed, rather than dropping the menu when a field in *any* column is open. I understand the general solution:

if (currently in column 4) then (do the code to drop the menu in column 5)
else if (currently in column 5) then (do the code to drop the menu in column 6)
else pass TabKey

But I don't know how to determine which column the active field is in. Believe it or not, I did look through the documentation, but I can't find it. I might have seen it but not known that what I was looking at was what I was looking for -- I have a really hard time following the docs. I presume the test is going to be something like "if the dgSomethingOrOther of me is 'Column 4'..." How do I do this test? Thanks again.

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Contact:

Re: How to drop Popup Menus in a Data Grid on tab/return?

Post by trevordevore » Wed Sep 08, 2010 3:21 pm

You're welcome.

Generally speaking you are looking for the dgColumn custom property of a row. It is defined in the lesson on template properties and messages:

http://lessons.runrev.com/spaces/lesson ... s-Messages

Searching for that specific term brings up a number of lessons:

http://lessons.runrev.com/spaces/lesson ... t=dgColumn

Now, since your code is executing in the custom behavior you created for the field editor then you can access the dgTargetKey of the field editor.

Code: Select all

put the dgTargetKey of me into theColumn
If you wanted to target the row itself from within the field editor behavior script you could do this:

Code: Select all

put the dgColumn of the dgDataControl of the dgTargetField of me
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

MichaelBluejay
Posts: 235
Joined: Thu Jul 01, 2010 11:50 am

Re: How to drop Popup Menus in a Data Grid on tab/return?

Post by MichaelBluejay » Wed Sep 08, 2010 5:13 pm

Thank you, "dgTargetKey of me" was just what I needed! I don't think I could have found that on my own. I couldn't find "dgTargetKey" with a Google search, or by searching the DataGrid PDF doc. Of course I didn't even know that that was I was supposed to be looking for anyway.

My data grid now has regular tab action between fields, except it properly drops the popup menu when tabbing to a field that has one. I was also able to have the tab key skip over a non-editable column by just repeating the DeleteFieldEditorAndOpenNext bit (i.e., executing it twice) when the user tries to tab to the non-editable column from the previous column.

Anyway, now that I think about it, my interface is a little non-standard. The way a popup menu works in Mac OS (or at least in Safari) is that when you tab to it, it gets a bold border around it, but the menu itself doesn't automatically drop. The menu doesn't actually drop until the user presses a key. I'm unable to get that behavior in Rev, even in a simple stack (without a data grid). I thought I could at least manually draw the border around the field through code, but the popup menu didn't respond to my attempts to change its border through commands in the message box. I assume this means such buttons can't be styled. I suppose I could show and hide a separate background graphic to make the menu button appear to be selected, even if that's a little cumbersome, but I'd still have the problem of how to get the menu to open when the user presses a key.

Is the standard Mac behavior for tabbing to focus a popup menu available in Rev somehow (like some property I need to set), and if not, can it be enabled through scripting? If I can't do either, then is it worth putting in a Feature Request for that ability?

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Contact:

Re: How to drop Popup Menus in a Data Grid on tab/return?

Post by trevordevore » Wed Sep 08, 2010 5:21 pm

I added a note to add the custom properties of the field editor to the docs.

Rev doesn't support navigating to menus like standard OS X controls. I don't know of a workaround for that. It is definitely worth adding a feature request.
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

MichaelBluejay
Posts: 235
Joined: Thu Jul 01, 2010 11:50 am

Re: How to drop Popup Menus in a Data Grid on tab/return?

Post by MichaelBluejay » Thu Sep 09, 2010 9:33 am

Thanks. Okay, I added a feature request to be able to tab to a popup/option menu, and drop it with a keystroke, as per a normal interface. Come to think of it, all my troubles so far have just been trying to get Rev to allow a basic, standard interface.

Case in point: In every other app a cell is opened for editing with a single click. In Rev I have to tinker around under the hood to get this normal behavior. And you'll never believe this, but I was actually able to figure out how to code that one on my own! That's got to be a first.

My next issue is that Column 3 of my table is read-only, so when I tab from Column 2 I want to go straight to Column 4. I found one way to do that, by simply repeating the "send DeleteFieldEditorAndOpenNext..." line (i.e., running it twice). That works, but it's inelegant, and the user can see Column 3 being open briefly. I tried putting "lock screen" before sending the DeleteField... message, but I can still see Column 3 open briefly.

My other idea was to try to just open the desired field directly, with something like

Code: Select all

EditFieldText the long id of theFieldIWantToOpen, the dgHilitedIndexes of the target, "Description"
The problem there is, how do I find the long id if the field I want to open?

Forgive me for asking, but could you tell me your role with the data grid component of Revolution? The company listed in your sig isn't Revolution. I thought maybe your company developed the data grid for Rev, since I think you referred to making bug fixes somewhere, but in a previous message you seemed to refer to some other developer. I guess what I'm getting at is, if this is your product, then I guess I don't feel quite as bad that I'm taking up so much of your time with my issues. Conversely, if you're an independent third party, then I know I've really been asking for quite a lot....

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Contact:

Re: How to drop Popup Menus in a Data Grid on tab/return?

Post by trevordevore » Mon Sep 13, 2010 1:33 pm

In every other app a cell is opened for editing with a single click
This may be true for the applications you use on a routine basis but it is not true across the board. It depends on the type of application. For instance, the MySQL database application I use, Sequel Pro, requires a double-click to edit a field. I find this to be desirable as I don't want to accidentally open a field for editing when clicking on a row.
My next issue is that Column 3 of my table is read-only
Just mark the column as not being editable and then DeleteFieldEditorAndOpenNext will skip over it for you automatically.

Code: Select all

set the dgColumnIsEditable["col 3"] of group "DataGrid" to false
http://lessons.runrev.com/spaces/lesson ... Properties
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Contact:

Re: How to drop Popup Menus in a Data Grid on tab/return?

Post by trevordevore » Mon Sep 13, 2010 1:34 pm

Forgive me for asking, but could you tell me your role with the data grid component of Revolution?
I wrote the data grid and RunRev licensed it.
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

MichaelBluejay
Posts: 235
Joined: Thu Jul 01, 2010 11:50 am

Re: How to drop Popup Menus in a Data Grid on tab/return?

Post by MichaelBluejay » Mon Sep 13, 2010 5:16 pm

Thank you, setting the column to non-editable did indeed fix the tabbing issue.

I was also able to get my next step working, getting the popup menu to be set to incoming data when the grid is populated. (The syntax appears to be a little different for a popup menu than for an option menu, which is what the example in the documentation used.) I was also able to set the value in the grid based on the menu selection.

Next up is what we talked about earlier: When I tab to a column that has a popup menu, I want to either "highlight" the menu if the cell already has a value (by showing a graphic around the popup menu button), or automatically drop the menu if it the cell doesn't have a value. I was able to figure out how to get the value of the cell so I know whether it's empty or not, and earlier we went over the mechanics of the menu drop, so most of this is done.

The only glitch here is that when I tab over to the new column, the old cell is still open. I used send "DeleteFieldEditorAndOpenNext" to the dgControl of me in 0 seconds in the tabkey handler of the Custom Field Editor script, before the code that auto-clicks on the popup menu, but the old cell is still open. I also tried just "DeleteFieldEditor" (without the "AndOpenNext" bit) but that didn't help. I thought that it might be a timing issue, so to test that I put "wait 1 second" between deleting the field editor and the auto-click on the popup menu, but that didn't help. I imagine you have an idea of what I'm doing wrong since you always have a quick answer.

Incidentally, the Data Grid is the reason I bought Revolution. I'm trying to build an accounting app, and for that I need tables, and there's no way I could do that with SuperCard.

Thanks for letting me know your role with the data grid component. May I ask, is supporting the data grid component on this forum part of your deal with the Revolution company, or are you providing help on a volunteer basis?

MichaelBluejay
Posts: 235
Joined: Thu Jul 01, 2010 11:50 am

Re: How to drop Popup Menus in a Data Grid on tab/return?

Post by MichaelBluejay » Tue Sep 21, 2010 1:37 pm

Hi Trevor, just checking in. Is the above something you're able to help me with?

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Contact:

Re: How to drop Popup Menus in a Data Grid on tab/return?

Post by trevordevore » Wed Sep 22, 2010 9:07 pm

The only glitch here is that when I tab over to the new column, the old cell is still open.
I'm not sure why the previous editing field would stick around but it is most likely related to the code that auto-clicks the popup menu since it appears that is the only other variable. Can you paste in the exact code you are using in your custom field editor script?
May I ask, is supporting the data grid component on this forum part of your deal with the Revolution company, or are you providing help on a volunteer basis?
At this point it is on a volunteer basis.
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

Post Reply