Tabbed View - 'Assistant' example crashes, other examples won't work

hi. first post. i have tried searching forums for an answer but no luck.

using OSX 10.5.8, Xcode 3.1.3

first:

going through the Developer AppleScript Studio Examples, i found “Assistant”, which is very close to what i want to do in my project - a tabbed view that is activated by buttons. Build and Go works, BUT, if i try to view the applescript via the Xcode editor (which works with other examples), Xcode crashes. after many tries at finding out why, it won’t crash if i move the event handlers higher in the code - but then it won’t work. What i need is a good, working, editable example.

second:

no matter what i try, i can’t get tabbed views to work. i’ve tried many examples, from here, from elsewhere on the net, and can’t get them to work, either. this isn’t to say i can’t get anything to work, in fact, everything else i’ve tried works fine, just not tabbed views. does anyone have an example that runs and is editable in this current version of the system?

is it possible that something on my machine is keeping me from using tabbed views? why does Xcode crash if i try to view “Assistant”'s applescript? has something fundamental changed in the last version of xCode / AppleScript Studio?

Does anyone have a working example of buttons activating a hidden tabbed view they’d share?

many thanks! i’ve learned quite a bit from trolling this forum for the last few months, and hope to add to it soon.

kauaiguy

I tried the Assistant example project and it crashes on me too. When I was learning about tab views I wrote myself a test project to learn how to use them. I always appreciate somebody who tries to answer their problems themself before coming for help, and it’s obvious you have, so I’m happy to share that code with you.

To Use:
Just place a tab view in a window, add some tab view items to it, and hook the tab view up to the “awake from nib” handler in IB. Then add 2 buttons for next and previous tabs, hook them to the “on clicked” handler, and this code will work. Note how I named the buttons btnPreviousTab and btnNextTab… and the tab view is named tabView. My code makes it so if you have the last tab view item selected, and press the next button, that the first tab view item becomes selected. You can modify that if you need.

I hope it helps. :cool:

property objtabview : null

on clicked theObject
	set objName to name of theObject
	if objName is "btnPreviousTab" then
		goPreviousTab(objtabview)
	else if objName is "btnNextTab" then
		goNextTab(objtabview)
	end if
end clicked

on awake from nib theObject
	set objName to name of theObject
	if objName is "tabView" then
		set objtabview to theObject
	end if
end awake from nib



(*=========== SUBROUTINES =============*)
on goNextTab(theTabView)
	set nextTabIndex to currentTabIndex(theTabView) + 1
	if nextTabIndex > (totalTabCount(theTabView) - 1) then set nextTabIndex to 0
	call method "selectTabViewItemAtIndex:" of theTabView with parameter nextTabIndex
end goNextTab

on goPreviousTab(theTabView)
	set previousTabIndex to currentTabIndex(theTabView) - 1
	if previousTabIndex < 0 then set previousTabIndex to (totalTabCount(theTabView) - 1)
	call method "selectTabViewItemAtIndex:" of theTabView with parameter previousTabIndex
end goPreviousTab

on currentSelectedTabObject(theTabView)
	return (call method "selectedTabViewItem" of theTabView)
end currentSelectedTabObject

on currentTabIndex(theTabView)
	return (call method "indexOfTabViewItem:" of theTabView with parameter currentSelectedTabObject(theTabView))
end currentTabIndex

on totalTabCount(theTabView)
	return (call method "numberOfTabViewItems" of theTabView)
end totalTabCount

I just noticed you wanted to show/hide that tab view itself. Here’s a handler to do that…

on setHiddenTabView(theTabView, hiddenState)
	call method "setHidden:" of theTabView with parameter hiddenState
end setHiddenTabView

In your code you can use the following.
To show a tab view…
setHiddenTabView(objtabview, false)

To hide a tab view…
setHiddenTabView(objtabview, true)

thanks, Hank!

i’ll give it a try monday and let you know. we’ve got another tropical storm headed our way, so the weekend will be spent caching up supplies and battening down the hatches…

much, much, appreciated!

mahalo,

dale

good luck with the storm. hurricane season is coming here on the east coast soon… i know what you’re going through.

hank,

works exquisitely! i haven’t seen an example of tabbed views anywhere using “call method”, very nice, clean, and just what i needed.

one last question - this script, like a few others i’ve used since 3.1.3, causes a Applescript Error -1708 that appears sort of randomly while the code is running, but otherwise doesn’t affect the program. any idea what that is, and/or where i can find a list of errors of the type that only give a number and no other useful information?

and again, many thanks for the example.

looks like the next hurricane will miss us this time… it’s moving north. hope they miss you as well.

dale

I’m glad it worked! When I write my applescript code I use a lot of “call method” calls now. It took me awhile to figure out how to do it, but once I learned it’s so easy to just look at the documentation for the classes and find the appropriate objective-c methods and construct the call. Many things that aren’t readily available with the applescript language are available using “call method” and objective-c methods. And many times it’s less complicated too. I suggest you learn it if you are writing applescript applications. There’s some tutorials on this website to help you learn it, although trial and error were my best tools. Here’s some articles about them to get you started…
http://macscripter.net/viewtopic.php?pid=102187
http://macscripter.net/viewtopic.php?id=8257&start=15

Regarding your error, I uploaded a script to this website which you can use to find out what that error means. You can get the script here in the Code Exchange section.
http://macscripter.net/viewtopic.php?id=30109

Good luck. :slight_smile:

ah, very nice!

thanks for the links to the articles, and especially for that “little” gem that parses the applescript error code lists so nicely. that was a lot of work you did to make our lives easier. plus the coding there answers a lot of my parsing and string manipulation questions as well.

much appreciated. mahalo,

dale

ps. still can’t find what handler is missing, but i suspect it’s a problem lin 3.1.3. i’ve had the idle routine randomly stop working too, though running in an older version of xcode it does fine. again, thanks!

your error code translating script told me that a handler was missing, and i found it by poking around - missing “launched”… all is well with the world now!

Here’s an answer to the core issue- XCode has a bug in 3.x where if you put a “Script blahblah… end blahblah” then try to put another function like “on doStuff… end doStuff” after it, it will always crash the editor in XCode. I believe this has been discussed in another thread before and I also posted a bug report about it.

The solution is to put the “Script blahblah” as the last function in a script, and all other handlers must come before that.
As to why the code won’t work after you move them, well I’m not sure on that.

Hopefully in SnowLeopard it’ll be fixed fully.