Choose from list dialog using AsObjC

Hi, all.

I am trying to show Choose from list dialog using AsObjC. But my code doesn’t work. What I do wrong?


use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions
property arguments : missing value

if my NSThread's isMainThread() as boolean then
	my performTextView:arguments
else
	my performSelectorOnMainThread:"chooseFromListDialog:" withObject:arguments waitUntilDone:true
end if
end run


on chooseFromListDialog:arguments
	
	-- create and show window
	set windowSize to current application's NSMakeRect(0, 0, 700, 600)
	set winStyle to (current application's NSWindowStyleMaskTitled as integer) + (current application's NSWindowStyleMaskClosable as integer)
	set theWindow to current application's NSWindow's alloc()'s initWithContentRect:windowSize styleMask:winStyle backing:2 defer:yes
	set windowController to current application's NSWindowController's alloc()'s initWithWindow:theWindow
	windowController's |window|'s |center|()
	windowController's |window|'s makeKeyAndOrderFront:me
	
	-- create scroll view
	set theScrollView to current application's NSScrollView's alloc()'s initWithFrame:windowSize
	(theScrollView's setHasVerticalScroller:yes)
	
	-- add scroll view to window
	theWindow's contentView()'s addSubview:theScrollView
	
	-- create table view
	set theTableView to current application's NSTextView's alloc()'s initWithFrame:windowSize
	set rowName to current application's NSString's stringWithString:"Row1"
	set row1 to (current application's NSTableRow's alloc())'s initWithIdentifier:rowName
	set rowName to current application's NSString's stringWithString:"Row2"
	set row2 to (current application's NSTableRow's alloc())'s initWithIdentifier:rowName
	(row1's setHeight:20)
	(row2's setHeight:20)
	(theTableView's addTableRow:row1)
	(theTableView's addTableRow:row2)
	-- (theTableView's setDelegate:me)
	-- (theTableView's setDataSource:me)
	-- (theTableView's reloadData())
	
	-- add table to scroll view
	(theScrollView's setDocumentView:theTableView)
	
	
end chooseFromListDialog:

thanks, but I need NSTableView example…

Check out the table examples on Takaaki’s site:

http://piyocast.com/as/archives/tag/nstableview

Thanks, Shane, for the advice. This is exactly what I need.

I want to build a choose from list dialog with the option to select multiple non-sequential list items. I’m not sure yet if I can do it. But the examples you indicated are very informative.

To learn AsObjC better and to make advanced choose from list dialogs for myself :smiley: