Owner of selectedChunk?

Trevor DeVore lists at mangomultimedia.com
Tue Nov 8 11:25:41 EST 2005


On Nov 8, 2005, at 12:08 AM, Scott Rossi wrote:
> With some text selected in a field in a top stack, is it possible to
> maintain focus on/selection of the text when clicking in a palette  
> that
> contains a text field?  I'm running into the problem of focus  
> shifting from
> the text field in top stack to the text field in the palette.

Right now you have to script around it.  It seems there should be a  
property of a stack that would return the name of the field that has  
focus for that stack.

Here is some code I use in a library stack for tracking the last  
active field of a stack.  I like to mark the field with a light grey  
background when it is suspended and restore the background to empty  
when the stack resumes.  This code also creates two getProps that  
return the selectedChunk and selectedField for a stack.  In order for  
the library to track fields in a stack you must set the uWindow 
["Name"] prop of the stack to some value.  Maybe this will help.


-- 
Trevor DeVore
Blue Mango Multimedia
trevor at mangomultimedia.com



local sWindowsA

/**
* When a stack is suspended we save the active field (if any) and  
hilite the
* text with a light grey.
*/
on suspendStack
	local tWindowName
	
	if the uWindow["Name"] of the owner of the target is not empty then
		put the uWindow["Name"] of this stack into tWindowName
		if selectedField() is not empty AND exists(long id of the owner of  
selectedField()) then
			put long id of the owner of selectedField() into tObj
			repeat while word 1 of tObj <> "stack"
				put the owner of tObj into tObj
			end repeat
			
			if the short name of tObj is the short name of the owner of the  
target then
				put selectedChunk() into sWindowsA[tWindowName,"activechunk"]
				
				if not the listBehavior of selectedField() then
					set the backgroundColor of selectedChunk() to "200,200,200"
					select empty
				end if
			end if
		else
			put empty into sWindowsA[tWindowName,"activechunk"]
		end if
	end if
	
	pass suspendStack
end suspendStack


on resumeStack
	local tWindowName
	
	if the uWindow["Name"] of the owner of the target is not empty then
		put the uWindow["Name"] of this stack into tWindowName
		
		if sWindowsA[tWindowName,"activechunk"]	is not empty then
			set the backgroundColor of sWindowsA[tWindowName,"activechunk"] to  
empty
			select sWindowsA[tWindowName,"activechunk"]
		end if
	end if

	pass resumeStack
end resumeStack


/**
* Returns the short name of the last active field of a stack.
*
*/
getProp uStackFocusedField
	local tWindowName
	
	if selectedField() is not empty AND exists(long id of the owner of  
selectedField()) then
		put long id of the owner of selectedField() into tObj
		repeat while word 1 of tObj <> "stack"
			put the owner of tObj into tObj
		end repeat
		
		if the short name of tObj is the short name of the target then
			return short name of selectedField()
		end if
	end if
	
	if the uWindow["Name"] of the target is not empty then
		put the uWindow["Name"] of the target into tWindowName
		if sWindowsA[tWindowName,"activechunk"] is not empty then
			get word -2 to -1 of sWindowsA[tWindowName,"activechunk"]
			return short name of it
		end if
	end if
	
	return empty
end uStackFocusedField


/**
* Returns the active chunk of a stack as returned by selectedChunk().
*
*/
getProp uStackFocusedChunk
	local tWindowName
	
	if selectedField() is not empty AND exists(long id of the owner of  
selectedField()) then
		put long id of the owner of selectedField() into tObj
		repeat while word 1 of tObj <> "stack"
			put the owner of tObj into tObj
		end repeat
		
		if the short name of tObj is the short name of the target then
			return selectedChunk()
		end if
	end if
	
	if the uWindow["Name"] of the target is not empty then
		put the uWindow["Name"] of the target into tWindowName
		if sWindowsA[tWindowName,"activechunk"] is not empty then
			return sWindowsA[tWindowName,"activechunk"]
		end if
	end if
	
	return empty
end uStackFocusedChunk





More information about the use-livecode mailing list