Can any object do this...

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

Post Reply
bjb007
Posts: 313
Joined: Fri Dec 28, 2007 4:56 am

Can any object do this...

Post by bjb007 » Tue Jun 24, 2008 6:14 pm

I want to have a drop-down menu in which
the user can type his required filename prefix
for a particular project and be able to choose it
later without typing it in again.

Tried the standard objects and seem to only
be able to add items programmatically.

Could do of course but simpler if the user
can type in a field.

Any ideas?
Life is just a bowl of cherries.

malte
Posts: 1098
Joined: Thu Feb 23, 2006 8:34 pm
Contact:

Post by malte » Tue Jun 24, 2008 7:11 pm

How should the control know (and remeber between sessions) if you don't tell it to? you will need to write a little script to do that. I would suggest to use a combobox for that purpose.

All the best,

Malte

bjb007
Posts: 313
Joined: Fri Dec 28, 2007 4:56 am

Can any object do this...

Post by bjb007 » Wed Jun 25, 2008 5:30 pm

The comboBox seems to be the answer.
Will have to use an input field and a button
to add the item to the comboBox.

And is there a system variable which shows how
many items are already in the comboBox so that
a new one can be added in the next empty slot?

In the 2.8.1 docs under "comboBox" is the following:

"Using the text box at the top of the combo box, the
user can specify a state that is not in the menu's list
of states".

This statement isn't true for any comboBox I've used.
Have I missed something?
Life is just a bowl of cherries.

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Contact:

Post by Janschenkel » Wed Jun 25, 2008 10:24 pm

When you're using a combobox (not an optionmenu, where you don't have a real textbox to type into anyway), the user can type just about anything, unless you script to prevent this from happening.

As for adding new items at the end, you can just

Code: Select all

put return & theNewItem after button "MyMenuButton"
Hope this helped,

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

bjb007
Posts: 313
Joined: Fri Dec 28, 2007 4:56 am

Can any object do this...

Post by bjb007 » Thu Jun 26, 2008 12:07 am

Jan
Had some fun with comboBox.
Only one item can be typed in direct.
Any further items have to be put in
programmatically.

When the "second" item is put in the
first disappears.

So they all have to be put in by program
which means that I have to test before
adding the "cr" else there's a blank first
entry.

When it comes to removing entries
it seems that if I loop through them
only every second one is delete.

Don't expect users will want to do that
but would like to know how to reference
the visible one and delete it and no others.

----Also would like to know if there's a way to put
the cursor in the input field without figuring it
out from co-ordinates. Something along the
lines of "to field fldSomeName" would be
ideal!
----Found "focus" so "focus on field fldSomeName"
does the trick.
Life is just a bowl of cherries.

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Re: Can any object do this...

Post by SparkOut » Wed Jul 02, 2008 12:40 pm

bjb007 wrote:When it comes to removing entries
it seems that if I loop through them
only every second one is delete.
This is probably because you are looping from the start of the list and incrementing the pointer. When you delete the first item, then item 2 becomes item one, but your pointer is still set as 2. So the next delete will be the (current) item 2, which used to be item 3 until item 1 got deleted, and so on.
If you start the loop at the end and go down to the beginning with your pointer then the problem should be avoided.

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Re: Can any object do this...

Post by SparkOut » Thu Jul 03, 2008 10:40 am

bjb007 wrote:Had some fun with comboBox.
Only one item can be typed in direct.
Any further items have to be put in
programmatically.

When the "second" item is put in the
first disappears.

So they all have to be put in by program
which means that I have to test before
adding the "cr" else there's a blank first
entry.
You've probably already worked out what you can do and have an acceptable solution, but you don't need to put an input field and button to program the combo box. The following script in the combo box itself seems to work for me.

Code: Select all

on closeField
  local tText, tLabel
  put the text of me into tText
  put the label of me into tLabel
  put cr & tLabel after tText
  if line 1 of tText is empty then delete line 1 of tText
  sort tText --optional
  set the text of me to tText
  set the label of me to tLabel
end closeField

bjb007
Posts: 313
Joined: Fri Dec 28, 2007 4:56 am

Can any object do this...

Post by bjb007 » Thu Jul 03, 2008 12:49 pm

Thanks SparkOut.

That works a treat.

I wouldn't have figured that out
in a month of Sundays.
Life is just a bowl of cherries.

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Post by SparkOut » Thu Jul 03, 2008 1:47 pm

Glad it helped.

There is one caveat though - which is that if after entering a new item in the combo-box, the user clicks a button which does not have the traversalOn property set (ie the "Focus with keyboard" box is not checked, so that a user can click it with the mouse, but tabbing via the keyboard will not activate it) then the closeField event is not sent to the combo-box until after the button handlers have been executed and the focus goes to some other control. In this case it shouldn't matter too much, but it's worth being aware that the closeField event has that particular quirk.

You should also test that the string typed does not already match an item in the list too, in case the user was too lazy to click the button and find it was already there.

Post Reply