Hoping someone can help me with this little problem.
I’ve a data source hooked up to an NSTableView and have added several rows.
I’ve used the following to enable drag re-ordering support:
set allows reordering of table view "TableViewName" of scroll view "ScrollViewName" of window "WindowName" to true
This works great, but I can’t for the life of me figure out how to save the state of the reordered rows, as of course the data source remains in whatever order it was in, regardless of the reordering performed on the Table View.
Have you setup your data source to be sorted? If not try this.
tell dataSource -- Whatever the name of the data source you created is
make new data column at end of data columns with properties {name:"Column Name1", sort order:ascending, sort type:alphabetical, sort case sensitivity:case sensitive}
make new data column at end of data columns with properties {name:"Column Name2", sort order:ascending, sort type:alphabetical, sort case sensitivity:case sensitive}
set sorted to true
set sort column to data column "Column Name1"
end tell
Dallasbr: If I set the data source to be sorted, then you can no longer reorder the rows manually by dragging them into the desired order.
regulus6633: The contents seem to be blank. If I enable the data source to be sorted as Dallasbr suggests then this returns the data, but the as I say the rows can no longer be manually dragged into order.
Is there any way to save the order of rows if they are arranged by dragging?
I checked to see what would happen if I dragged the rows into a new order, then added a new row. Quitting and restarting the app I saw that the rows remained in the correct order.
When adding a new row I have a call to a method that saves the data rows, which evidently gets the values out in the order they are being displayed.
So I have put a call to this save method on the ‘should quit’ handler. My only remaining question really is whether there is a better handler to use? I’ve looked at the drag and drop handlers, and have tried a few of them out, but none of those seem to get called when a row is drag-sorted. Is there a handler that will get fired off when a row is dragged into a new position at all?
The only problem with just having this on the ‘should quit’ handler is that if the application is force quit or crashes in between the sorting of rows, the changes will be lost.
I don’t really want to put a regular save in an idle event either, any ideas?