Page 1 of 3
Please add a way to Name my own Controls
Posted: Wed Jul 27, 2011 12:25 am
by BarrySumpter
If I add a Button its name is Button.
If I add another Button is name is Button.
Can you please add a way where I can name my first button automatically as
btnButton1
and when I add another button its name is:
btnButton2
And if I copy a button say
copy btnAdd
and paste
I'd like the option to automatically add the button with the name
btnAdd2
etc. for all controls
Re: Please add a way to Name my own Controls
Posted: Wed Jul 27, 2011 1:30 pm
by splash21
Hi, Barry - I needed a break from what I was working on, so here's a start. It's a tiny plugin - just open the stack. There's one button to start and stop the functionality which is to rename newly created controls by adding an index value to the name. The code is in the 'FrontScript' button - which is hidden, so access it through the application browser.
To test: load the stack, press 'Start' , drag some controls on to a new stack, check the names.
HTH
John.
Re: Please add a way to Name my own Controls
Posted: Wed Jul 27, 2011 3:22 pm
by Klaus
Hi Barry,
as John already indicated, if the IDE does not support it, roll your own
Check Johns script ( esp. button "FrontScript" of cd 1), very informative (it catches the "new object" message!) and utterly smart
Best
Klaus
Re: Please add a way to Name my own Controls
Posted: Wed Jul 27, 2011 11:55 pm
by BarrySumpter
Brilliant!
John Craig rocks!
Not only did John offer a solution he offered a fully functioning project I can update myself.
Now thats the kind of support from fellow LiveCoders that keeps me coming back.
And Now I can see the code. Well Commented and all. Well Done!
I'll be looking for a way to change the standard "Button" to btnCommand1" and its Label to "Button 1" etc
It's so much easier to read in the applications browser.
And maybe save preferneces? etc.
I just had a flash. There are NO control arrays are there? cmdButton(1) and cmdButton(2) etc?
Surely I would have come accross them if there were.
I've had me coffee this morning so I'm rocketing off to another day of LiveCodeing.
Re: Please add a way to Name my own Controls
Posted: Thu Jul 28, 2011 12:28 am
by BarrySumpter
Too easy to update - much appreciated.
Is there a way to manage the name of the Stack itself and the cards?
Also is there something about debug tracing with these message traps?
The degugger keeps exiting.
----
Re: Please add a way to Name my own Controls
Posted: Thu Jul 28, 2011 1:56 am
by BarrySumpter
Strange. No consistancey here.
The tools Palette yellow popup tool tip is different than the controls Short Name.
Is there a way to identify/differentiate between
Text Entry Field and Scrolling field
by using the Tools Palettes popup label perhaps?
Otherwise it looks like both are a Field
and the width of 100 fpr a Text Entry Field seems to be the only way to differentiate.
Well, that I can find so far.
Can't seem to trap the datagrid either.
Its acting very strange.
Don't know what to do with a ctrl drag n drop to copy.
And I havn't tried a copyNpaste yet.
But this wil certainly do.
My updates so far. Running out of energy. So may return later with more updates.:
Code: Select all
-- renameLastControlWithIndex
# Hook to rename newly created controls with an index
# By John Craig
# 2011-07-27
#
#
#
# Renames newly created controls: Button 1, Button 2, Radio 1, Radio 2, etc...
# Names are based on the new controls default name
# Any previously renamed controls such as 'MyButton' are ignored
# messages to intercept
on newGroup
renameLastControlWithIndex
pass newGroup
end newGroup
on newButton
renameLastControlWithIndex
pass newButton
end newButton
on newField
renameLastControlWithIndex
pass newField
end newField
on newGraphic
renameLastControlWithIndex
pass newGraphic
end newGraphic
on newImage
renameLastControlWithIndex
pass newImage
end newImage
on newPlayer
renameLastControlWithIndex
pass newPlayer
end newPlayer
on newScrollbar
renameLastControlWithIndex
pass newScrollbar
end newScrollbar
# rename a newly created control with an index value
command renameLastControlWithIndex
# create a reference to the new control
put the long id of the last control of this card into tControlId
# the new name will be the existing name + an index
put the short name of tControlId into tNewName
-- Barry's Preferences as of: 2011 07 28 0930
-- Just getting started ... More updated needed to for other controls
-- I've removed the && which gives us an extra space so I don't have to surround my field names in "s
-- i.e. put xxx into field chk1 instead of put xxx into field "check 1"
if tNewName begins with "Button" then
set the Label of tControlId to tNewName
Replace "Button" with "cmd" in tNewName
end if
if tNewName begins with "Check" then
set the Label of tControlId to tNewName
Replace "Check" with "chk" in tNewName
end if
if tNewName begins with "Radio" then
set the Label of tControlId to tNewName
Replace "Radio" with "rdo" in tNewName
end if
if tNewName begins with "Tab Menu" then
set the Label of tControlId to tNewName
Replace "Tab Menu" with "tab" in tNewName
end if
if tNewName begins with "Label Field" then
Replace " Field" with "" in tNewName
set the text of tControlId to tNewName
Replace "Label Field" with "lbl" in tNewName
end if
if tNewName begins with "Field" then
if the Width of tControlID = 100 then
-- this is a Text Field
Replace "Field" with "txt" in tNewName
else
if the Width of tControlID = 102 then
-- this is a Text Field
Replace "Field" with "lbx" in tNewName
else
-- this is a Scrolling List Field
Replace "Field" with "lst" in tNewName
end if
end if
end if
if tNewName begins with "Table Field" then
Replace "Table Field" with "tbl" in tNewName
end if
if tNewName begins with "Scrolling List Field" then
Replace "Scrolling List Field" with "scl" in tNewName
end if
-- if tNewName begins with "DataGrid" then
-- Replace "DataGrid" with "dgd" in tNewName
-- end if
if tNewName begins with "Option Menu" then
set the Label of tControlId to "ListBox"
Replace "Option Menu" with "lbx" in tNewName
end if
if tNewName begins with "Pulldown Menu" then
set the Label of tControlId to "PullDownMenu"
Replace "Pulldown Menu" with "PullDownMenu" in tNewName
end if
if tNewName begins with "ComboBox Menu" then
-- set the Label of tControlId to tNewName
Replace "ComboBox Menu" with "cbo" in tNewName
end if
if tNewName begins with "PopUp Menu" then
set the Label of tControlId to "PopUpMenu"
Replace "PopUp Menu" with "PopUpMenu" in tNewName
end if
if tNewName begins with "Progress Scrollbar" then
-- set the Label of tControlId to "ProgressScrollbar"
Replace "Progress Scrollbar" with "ProgressBar" in tNewName
end if
if tNewName begins with "Scrollbar" then
if the Style of tControlID = "scale" then
--set the Label of tControlId to "Slider"
Replace "Scrollbar" with "slider" in tNewName
else
if the Style of tControlID = "scrollbar" then
if the width of tControlID = 15 then -- Little Arrows
--set the Label of tControlId to "Slider"
Replace "Scrollbar" with "LittleScrollBar" in tNewName
else
-- Replace "Scrollbar" with "LittleScrollBar" in tNewName
end if
end if
else
if the Style of tControlID = "Little Arrows" then
--set the Label of tControlId to "Slider"
Replace "Scrollbar" with "LittleScrollBar" in tNewName
end if
end if
end if
# we will add the highest control index found + 1 to the control name
put 0 into tMaxIndex
# loop over each control on the card
put the number of controls of this card into tTotal
repeat with i = 1 to tTotal
# get the name of the control only
put the short name of control i of this card into tName
# is the control name the same as the new control?
if tName begins with tNewName then
# do we have a numeric index on the control name?
if matchText(tName, "([[:digit:]]+)$", tIndex) then
# is the index higher than the current high value?
if tIndex > tMaxIndex then
put tIndex into tMaxIndex
end if
end if
end if
end repeat
# rename the new control
set the name of tControlId to tNewName & (tMaxIndex + 1)
--if the Label is among the lines of the propertyNames of tControlID then
--set the Label of tControlId to the Label of tControlId & (tMaxIndex + 1)
--end if
try
set the Label of tControlId to the Label of tControlId & (tMaxIndex + 1)
catch tErr
put "Error on" && the short name of tControlId && ": " && tErr
end try
end renameLastControlWithIndex
Re: Please add a way to Name my own Controls
Posted: Tue Aug 02, 2011 11:04 am
by BarrySumpter
And can't trap the NewSubStack.
Nor can I find a way to identify a SubStack while its being created.
Any suggestions?
Re: Please add a way to Name my own Controls
Posted: Tue Aug 02, 2011 12:43 pm
by splash21
Hi, Barry - glad you liked the example
Try the following;
Code: Select all
on newStack
send "newStackHandler" to this stack in 1 tick
end newStack
on newStackHandler
put "stack = " & the short name of this stack & LF & "main = " & the mainstack of this stack
end newStackHandler
If you watch the message box as you create a new mainstack and a new substack, you'll see that you can identify them and then tweak them to your requirements.
Have fun!
John.
Re: Please add a way to Name my own Controls
Posted: Tue Aug 02, 2011 12:52 pm
by BarrySumpter
Hi John,
Stack Name is easy
Stack SUB names can't be identified differently than a Stack Name.
As in the Name and the SubStackName are the same until ON NewStack exits.
oops. Yeah, OK.
I get it now.
newStackHandler
Re: Please add a way to defaultName my own stacks on Save as ...
Posted: Sun Aug 07, 2011 11:09 pm
by BarrySumpter
Havn't inplemented newStackHandler as yet but shall soon.
Along these same lines can I trap the File | Save as ... ?
At the moment the Save as ... command defaults to
Untitled 1.livecode
I'd like it to default to my current Stack Name.
i.e. Shelll7.livecode
i.e. MasterOfTheUnivers 2011 08 07 1700.livecode
Then I can either change it slightly myself by hand to:
Shell8.livecode
or
MasterOfTheUnivers 2011 08 08 0800.livecode
or with script - identify that I am using a yyyy mm dd hhmm format
and updated the save as name up to the minute, etc.
Now off to research DataGrids this week.
Re: Please add a way to Name my own Controls
Posted: Tue Aug 30, 2011 11:39 pm
by BarrySumpter
Hi again John.
Dude!
Love your work!
Code: Select all
-- renameLastControlWithIndex
# Hook to rename newly created controls with an index
# By John Craig
# 2011-07-27
#
#
#
# Renames newly created controls: Button 1, Button 2, Radio 1, Radio 2, etc...
# Names are based on the new controls default name
# Any previously renamed controls such as 'MyButton' are ignored
# messages to intercept
on newStack
send "newStackHandler" to this stack in 1 tick
pass newStack
end newStack
on newSubStack
put revLoadedStacks("application") into LoadedStacks
end newSubStack
on newStackHandler
-- put "stack = " & the short name of this stack & LF & "main = " & the mainstack of this stack
put revLoadedStacks("application") into LoadedStacks
put the last line of LoadedStacks into theLastStackName
-- go stack stack last
-- put the long id of the last control of this card into tControlId
-- put the name of stack theLastStackName into theLastStackName2
local MainStackName
put the short Name of stack theLastStackName into MainStackName
local MainStackParent
put the MainStack of stack theLastStackName into MainStackParent
if MainStackName =MainStackParent then -- this is a mainStack
set the name of stack theLastStackName to "stkMainStack"
put "stkMainStack" into theLastStackName
else
set the name of stack theLastStackName to "subStack"
put "subStack" into theLastStackName
end if
put theLastStackName into tNewName
-- renameLastStackWithIndex
# we will add the highest control index found + 1 to the control name
put 0 into tMaxIndex
# loop over each stack name
put the number of Lines in LoadedStacks into tTotal
repeat with i = 1 to tTotal
# get the name of the control only
put the line(i) of LoadedStacks into tName
# is the control name the same as the new control?
if tName begins with tNewName then
# do we have a numeric index on the control name?
if matchText(tName, "([[:digit:]]+)$", tIndex) then
# is the index higher than the current high value?
if tIndex > tMaxIndex then
put tIndex into tMaxIndex
end if
end if
end if
end repeat
set the name of stack theLastStackName to theLastStackName & (tMaxIndex + 1)
put theLastStackName & (tMaxIndex + 1) into theLastStackName
-- answer revLoadedStacks("application")
put the MainStack of stack theLastStackName into NewMainStackParent
end newStackHandler
on newGroup
renameLastControlWithIndex
pass newGroup
end newGroup
on newButton
renameLastControlWithIndex
pass newButton
end newButton
on newField
renameLastControlWithIndex
pass newField
end newField
on newGraphic
renameLastControlWithIndex
pass newGraphic
end newGraphic
on newImage
renameLastControlWithIndex
pass newImage
end newImage
on newPlayer
renameLastControlWithIndex
pass newPlayer
end newPlayer
on newScrollbar
renameLastControlWithIndex
pass newScrollbar
end newScrollbar
# rename a newly created control with an index value
command renameLastControlWithIndex
# create a reference to the new control
put the long id of the last control of this card into tControlId
# the new name will be the existing name + an index
put the short name of tControlId into tNewName
-- Barry's Preferences as of: 2011 07 28 0930
-- Just getting started ... More updated needed to for other controls
-- I've removed the && which gives us an extra space so I don't have to surround my field names in "s
-- i.e. put xxx into field chk1 instead of put xxx into field "check 1"
if tNewName begins with "Button" then
set the Label of tControlId to tNewName
Replace "Button" with "cmd" in tNewName
end if
if tNewName begins with "Check" then
set the Label of tControlId to tNewName
Replace "Check" with "chk" in tNewName
end if
if tNewName begins with "Radio" then
set the Label of tControlId to tNewName
Replace "Radio" with "rdo" in tNewName
end if
if tNewName begins with "Tab Menu" then
set the Label of tControlId to tNewName
Replace "Tab Menu" with "tab" in tNewName
end if
if tNewName begins with "Label Field" then
Replace " Field" with "" in tNewName
set the text of tControlId to "Label-" --tNewName
Replace "Label Field" with "lbl" in tNewName
end if
if tNewName begins with "Field" then
if the Width of tControlID = 100 then
-- this is a Text Field
Replace "Field" with "txt" in tNewName
else
if the Width of tControlID = 102 then
-- this is a Text Field
Replace "Field" with "lbx" in tNewName
else
-- this is a Scrolling List Field
Replace "Field" with "lst" in tNewName
end if
end if
end if
if tNewName begins with "Table Field" then
Replace "Table Field" with "tbl" in tNewName
end if
if tNewName begins with "Scrolling List Field" then
Replace "Scrolling List Field" with "scl" in tNewName
end if
-- if tNewName begins with "DataGrid" then
-- Replace "DataGrid" with "dgd" in tNewName
-- end if
if tNewName begins with "Option Menu" then
set the Label of tControlId to "ListBox"
Replace "Option Menu" with "lbx" in tNewName
end if
if tNewName begins with "Pulldown Menu" then
set the Label of tControlId to "PullDownMenu"
Replace "Pulldown Menu" with "PullDownMenu" in tNewName
end if
if tNewName begins with "ComboBox Menu" then
-- set the Label of tControlId to tNewName
Replace "ComboBox Menu" with "cbo" in tNewName
end if
if tNewName begins with "PopUp Menu" then
set the Label of tControlId to "PopUpMenu"
Replace "PopUp Menu" with "PopUpMenu" in tNewName
end if
if tNewName begins with "Progress Scrollbar" then
-- set the Label of tControlId to "ProgressScrollbar"
Replace "Progress Scrollbar" with "ProgressBar" in tNewName
end if
if tNewName begins with "Scrollbar" then
if the Style of tControlID = "scale" then
--set the Label of tControlId to "Slider"
Replace "Scrollbar" with "slider" in tNewName
else
if the Style of tControlID = "scrollbar" then
if the width of tControlID = 15 then -- Little Arrows
--set the Label of tControlId to "Slider"
Replace "Scrollbar" with "LittleScrollBar" in tNewName
else
-- Replace "Scrollbar" with "LittleScrollBar" in tNewName
end if
end if
else
if the Style of tControlID = "Little Arrows" then
--set the Label of tControlId to "Slider"
Replace "Scrollbar" with "LittleScrollBar" in tNewName
end if
end if
end if
# we will add the highest control index found + 1 to the control name
put 0 into tMaxIndex
# loop over each control on the card
put the number of controls of this card into tTotal
repeat with i = 1 to tTotal
# get the name of the control only
put the short name of control i of this card into tName
# is the control name the same as the new control?
if tName begins with tNewName then
# do we have a numeric index on the control name?
if matchText(tName, "([[:digit:]]+)$", tIndex) then
# is the index higher than the current high value?
if tIndex > tMaxIndex then
put tIndex into tMaxIndex
end if
end if
end if
end repeat
# rename the new control
-- answer "Name:" && tNewName && tMaxIndex
set the name of tControlId to tNewName & (tMaxIndex + 1)
--if the Label is among the lines of the propertyNames of tControlID then
--set the Label of tControlId to the Label of tControlId & (tMaxIndex + 1)
--end if
if tNewName begins with "Label" then
try
set the text of tControlId to the short Name of tControlId & ":"
catch tErr
end try
else
try
-- answer "Label:" && Label of tControlId && tMaxIndex
set the Label of tControlId to the Label of tControlId & (tMaxIndex + 1)
catch tErr
try
set the text of tControlId to the Label of tControlId & (tMaxIndex + 1)
catch tErr
put "Error on" && the short name of tControlId && ": " && tErr
end try
end try
end if
end renameLastControlWithIndex
P.S. I'd still like to trap the:
File | Save as ...
as mentioned in a previous post on this thread.
Any further help would be greatly appreciated.
Thanks in Advance.
Re: Please add a way to Name my own Controls
Posted: Wed Aug 31, 2011 12:07 am
by BarrySumpter
I'd like to add the following to this brilliant plugin:
Toolbar option For 'Save as Standalone'
http://forums.runrev.com/phpBB2/viewtop ... f=6&t=8746
and the:
set the raisewindows to true in Preferences or Dev Menu?
http://forums.runrev.com/viewtopic.php?f=6&t=8873
But can't seem to add a button to the stack for either.
No prob if this is intentional and if author would prefer to leave it that way.
Just want to build on what is alreay there if I can.
Can anyone explain this code I found behind the start/stop button named "Active"?
I don't know what the uActive is and Google search found nothing.
Ithought it might be a Custom Property but can't seem to find where it's being defined.
Code: Select all
on mouseUp
if the uActive of this card then
remove the script of button "FrontScript" from front
set the uActive of this card to false
set the label of btn "Active" to "Start"
else
insert the script of button "FrontScript" into front
set the uActive of this card to true
set the label of btn "Active" to "Stop"
end if
end mouseUp
I'd be happy to start this thread somewhere more appropriate.
But this is getting super interesting and I'd like to keep the thread together.
Any help would be greatly appreciated.
Thanks in advance.
Re: Please add a way to Name my own Controls
Posted: Fri Sep 02, 2011 2:34 pm
by sturgis
The uActive in this case is just a property that was set to track state, either true or false. A user created property, not a livecode property.
All it does is provide a boolean check so that the the mouseup can determine whether or not to poke the script from button "frontscript" into the front of the message path. If the property uActive is true then remove the script from the front, otherwise put the script there, and set the button label appropriately.
I don't know if you've read
http://www.fourthworld.com/embassy/arti ... _path.html yet, but if not its really worth it. Makes getting a handle on the message path MUCH less murky than it otherwise might be.
Re: Please add a way to Name my own Controls
Posted: Fri Sep 02, 2011 10:35 pm
by BarrySumpter
Hi Sturgis,
Many thanks for that.
I was getting "the uActive" custom property confused with a built in property.
Looks like "the uActive" gets created as a custom property on the fly. Cool.
And I'm still learning where to find the actual scripts.
Sometimes the scripts seems to be hidding from me in different ways. LOL.
I've been able to successfully implement this into my own PlugIn. Very Cool.
I wouldn't have had a clue where to start nor what to do if it wasn't for the help from these contributions.
Thanks again.
You guys rock!
Re: Please add a way to Name my own Controls
Posted: Thu Sep 15, 2011 5:46 am
by BarrySumpter
OK, next is those would be nice to have on my revBGS addin:
Show Application Browser / Hide App Browser
Save
Open
WHen LC 4.6.4 loads - it loads my revBGS just to the bottom right of the LC command bar and my DGH palette just next to my revBGS.
Is there a way to set these to the top right corner of my screen?
Any help or hints would be greatly appreciated.
As always will post my results so others may take advantage.
Is there a resource that would discuss these matters in detail,
so I don't have to bother you good people?