I don’t seem to find the right syntax to get text from edits:
These are placed
in a Box,
which is placed in the 1st Tab (out of 3)
of my TabView.
Here is my code:
on will select tab view item theObject tab view item tabViewItem
end will select tab view item
on clicked theObject
tell tab view item 1 of tab view 1 of window of theObject
set textToFind to contents of text field 1 of box 2 of tab view item 1 of tab view 1 of window 1
set textToWrite to contents of text field 2 of box 2 of tab view item 1 of tab view 1 of window 1
end tell
if (name of theObject is "btnGo") then
tell window "main"
display dialog textToFind
end tell
end if
end clicked
Not sure what to do of all this and whether the code should be in “on clicked theObject” (my action button) or in “on will select tab view”.
on will select tab view item. is used to make certain settings just before the tab changes
you have double referencing in your code.
The tell block contains a reference to the tab view item, so you have to omit it referencing the text fields
on clicked theObject
tell tab view item 1 of tab view 1 of window of theObject
set textToFind to contents of text field 1 of box 2
set textToWrite to contents of text field 2 of box 2
end tell
if (name of theObject is "btnGo") then
tell window "main"
display dialog textToFind
end tell
end if
end clicked
But how do I use conditions with tabs ?
Each tab will have a different function, so it needs to call a different part of my code. I would like it to look like this :
On clicked theObject
[b]If Tab1 is selected then [/b]
do this
do that
end if
[b]If Tab2 is selected then[/b]
do something else
do another thing
end if
And so on ...
End clicked
What is the syntax for that kind of condition? Havent found anything on that ?
No, a boolean value has only 2 states.
Try it this way
property currentTabLabel : ""
on selected tab view item theObject tab view item tabViewItem
set currentTabLabel to label of tabViewItem
end selected tab view item
on clicked theObject
if currentTabLabel is "firstItem" then
-- do something
else if currentTabLabel is "secondItem" then
-- do something else
else if currentTabLabel is "thirdItem" then
.
end if
end clicked
dont you think I can just use the “on will” handler instead, as stated here ?
for example, I force tab1 to display at opening, and then
on will select tab view item theObject tab view item tabViewItem
if name of tabViewItem = "tab1" then
set this and that
blah blah
end if
if name of tabViewItem = "tab2" then
do blah blah blah
do this & that
end if
if name of tabViewItem = "tab3" then
do blah blah blah
do this & that
end if
end will select tab view item
EDIT | Never mind, I’m just talking out of my A**, it cant work because I need to use “on click” for my button …
and I realized you cant have a handler inside a handler (or i havent found the way to do it!).
That depends on the purpose. If you want to make settings before the tab was changed,
for example preventing a particular tab from opening, use will select.
Otherwise use selected tab.
I tested the code and it worked perfectly, to preset the variable currentTabLabel to the current tab, I added in the will finish launching handler
set currentTabLabel to label of current tab view item of tab view 1 of window 1
Right, I just tried that and it somehow interferes with my code.
So I found a workaround: I added a button with the same name but a different ID for each tab, that way I can play with my code this way:
on clicked theObject
if name of theObject is "button1"
do this
end if
if name of theObject is "button2"
do that
end if
end clicked
It’s not exactly what I wanted to do because each button is located INSIDE the tabView, but it does its job, and it makes everything SO MUCH EASIER !
now I got it, you want to do actions depending on the change of the tab view item, not on a button,
then everything must be in the selected handler, not in the on clicked handler
on selected tab view item theObject tab view item tabViewItem
set currentTabLabel to (get label of tabViewItem)
if currentTabLabel is "firstItem" then
-- do something
else if currentTabLabel is "secondItem" then
-- do something else
else if currentTabLabel is "thirdItem" then
.
end if
end selected tab view item