
/*---------------------------------------------------------
  Called when spawnmenu is trying to be opened. 
   Return false to dissallow it.
---------------------------------------------------------*/
function GM:SpawnMenuOpen()

	GAMEMODE:SuppressHint( "OpeningMenu" )
	GAMEMODE:AddHint( "OpeningContext", 20 )

	return true	
end

/*---------------------------------------------------------
  Called when context menu is trying to be opened. 
   Return false to dissallow it.
---------------------------------------------------------*/
function GM:ContextMenuOpen()

	GAMEMODE:SuppressHint( "OpeningContext" )
	GAMEMODE:AddHint( "ContextClick", 20 )

	return true	
end

local STOOLMenu = {}

	// Note - I'm hardcoding these in so the order is the same as it is now to prevent the 'I can't find nothing' crew
	STOOLMenu["Constraints"] 	= { Text = "#Constraints" }
	STOOLMenu["Construction"] 	= {	Text = "#Construction" }
	STOOLMenu["Poser"]			= { Text = "#Poser" }
	STOOLMenu["Render"] 		= { Text = "#Render" }

/*---------------------------------------------------------
  Called From the engine to populate the Scripted Tool menu.
---------------------------------------------------------*/
function GM:PopulateSTOOLMenu()	

	local Out = {}
	
	// sort out stool menu, alphabetically
	local stools = {}
	for k, v in pairs( STOOLMenu ) do
		table.insert( stools, v )
	end
	table.sort( stools, function (a,b) return (a.Text < b.Text) end )
	
	for k, v in ipairs( stools ) do
	
		table.insert( Out, v )
		
		if ( v.Children ) then
		
			local SortChild = {}
			for k, v in pairs( v.Children ) do
				table.insert( SortChild, v )
			end
		
			table.sort( SortChild, function (a,b) return (a.Text < b.Text) end )
			
			for k, v in ipairs( SortChild ) do
				table.insert( Out, v )
			end
 			
		end
		
	
	end

	return Out
end


/*---------------------------------------------------------
  Called by the toolgun to add a STOOL
---------------------------------------------------------*/
function GM:AddSTOOL( category, itemname, text, command, controls, cpanelfunction )
	
	// No table found.. lets create one
	if ( !STOOLMenu[ category ] ) then
		STOOLMenu[ category ] = { Text = "#"..category } 	
	end
	
	local cat = STOOLMenu[ category ]
	cat.Children = cat.Children or {}
	
	cat.Children[ itemname ] = { ItemName = itemname, Text = text, Command = command, Controls = controls, CPanelFunction = cpanelfunction }

end
