View Single Post
Quote:
Originally Posted by Ken Case View Post
This has been fixed for the next sneaky peek build (which should be posted within half an hour).
From Ver 1.8 sneaky peek 77.56.0.133908 onwards the following simplified and marginally faster script will work from the OF toolbar, as well as from the OF script menu.

Code:
-- TOGGLE THE EXPANSION STATE OF TREES IN CONTENT AND/OR SIDEBAR PANELS
-- Works if launched from Scripts Menu, a script editor
-- or from the OF Toolbar in Ver 1.8 sneaky peek 77.56.0.133908 onwards 

property pblnToggleContent : true
property pblnToggleSidebar : true

property pstrContext : "context"

global gblnContentExpanded
global gblnSidebarExpanded

on run
	tell application id "OFOC"
		set oWin to front document window of default document
		
		-- OPTIONALLY TOGGLE CONTENT EXPANSION
		if pblnToggleContent then
			try
				set blnExpanded to not (gblnContentExpanded)
			on error
				set blnExpanded to false
			end try
			set refTrees to a reference to trees of content of oWin
			set expanded of refTrees to blnExpanded
			set gblnContentExpanded to blnExpanded
		end if
		
		-- OPTIONALLY TOGGLE SIDEBAR EXPANSION
		if pblnToggleSidebar then
			try
				set blnExpanded to not gblnSidebarExpanded
			on error
				set blnExpanded to false
			end try
			
			set oSidebar to sidebar of oWin
			set refLibrary to a reference to tree 2 of oSidebar
			if selected view mode identifier of oWin is not pstrContext then
				set refFolders to a reference to (trees of refLibrary where class of value is folder)
				set expanded of refFolders to blnExpanded
			else
				set refContexts to a reference to (trees of refLibrary where (class of value is context))
				-- There is an assymetry here (arguably a minor bug ?)
				-- Childless context trees can have their expanded property set to FALSE by script
				-- but not to TRUE ...
				if blnExpanded then
					set lstTrees to contents of refContexts
					repeat with oTree in lstTrees
						try
							set expanded of oTree to true
						end try
					end repeat
				else
					set expanded of refContexts to false
				end if
			end if
			
			set gblnSidebarExpanded to blnExpanded
		end if
	end tell
end run

Last edited by RobTrew; 2012-02-15 at 05:09 AM..