Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
data source and table view help please
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

data source and table view help please



Hi
the following is my adaptation of the table sort example in the AS
Studio examples
I am attempting to populate a single column table with the names of all
the files on the desktop
.............. not surprisingly, it doesn't work
It seems like a simple task, I think I am missing the point somewhere
any suggestions would be appreciated

thank you

Peter

(* ==== Properties ==== *)
property prefsFolder : ""
property tableData : {}

(* ==== Event Handlers ==== *)

-- The "awake from nib" event handler is attached to the table view. It
will be called when the table view is loaded from the nib. It's a good
place to create our data source and set up the data columns.
--
on awake from nib theObject
tell application "Finder"
set prefsFolder to (home as text) & "Desktop:"
set tableData to name of (every file in folder prefsFolder) as list
end tell
-- Create the data source
tell window of theObject
set theDataSource to make new data source at end of data sources with
properties {name:"names"}

-- Create each of the data columns, including the sort information
for each column
make new data column at end of data columns of theDataSource with
properties {name:"name", sort order:ascending, sort type:alphabetical,
sort case sensitivity:case sensitive}

-- Make this a sorted data source
set sorted of theDataSource to true

-- Set the "name" data column as the sort column
set sort column of theDataSource to data column "name" of
theDataSource

-- Set the data source of the table view to the new data source
set data source of theObject to theDataSource

-- Add the table data (using the new "append" command)
append theDataSource with tableData
end tell
end awake from nib


-- The "launched" event handler is attached to the application object
("File's Owner of MainMenu.nib"). It is called towards the end of the
startup sequence.
--
on launched theObject

-- Show the main window
show window "main"

end launched


-- The "column clicked" event handler is called when the user clicks on
a table column in the table view. We will use this handler to change
the sort column of the data source as well as the sort order.
--
on column clicked theObject table column tableColumn
-- Get the data source of the table view
set theDataSource to data source of theObject

-- Get the identifier of the clicked table column
set theColumnIdentifier to identifier of tableColumn

-- Get the current sort column of the data source
set theSortColumn to sort column of theDataSource

-- If the current sort column is not the same as the clicked column
then switch the sort column
if (name of theSortColumn) is not equal to theColumnIdentifier then
set the sort column of theDataSource to data column
theColumnIdentifier of theDataSource
else
-- Otherwise change the sort order
if sort order of theSortColumn is ascending then
set sort order of theSortColumn to descending
else
set sort order of theSortColumn to ascending
end if
end if

-- We need to update the table view (so it will be redrawn)
update theObject
end column clicked
_______________________________________________
applescript-studio mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-studio
Do not post admin requests to the list. They will be ignored.



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.