
/*---------------------------------------------------------
	If false is returned then the spawn menu is never created.
	This saves load times if your mod doesn't actually use the
	spawn menu for any reason.
---------------------------------------------------------*/
function GM:SpawnMenuEnabled()
	return true	
end


/*---------------------------------------------------------
  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


function GM:GetSpawnmenuTools( name )	
	return spawnmenu.GetToolMenu( name )
end


/*---------------------------------------------------------
	Don't hook or override this function.
	Search for function GM:PreReloadToolsMenu for info.
---------------------------------------------------------*/
function GM:AddGamemodeToolMenuTabs( )
	
	spawnmenu.AddToolTab( "Main", 			"#Tools" )
	spawnmenu.AddToolTab( "PostProcessing", "#Post_Processing" )
	spawnmenu.AddToolTab( "Utilities", 		"#Utilities" )
	spawnmenu.AddToolTab( "Options", 		"#Options" )

end

/*---------------------------------------------------------
  Backwards compatibility. Do Not Use!!!
---------------------------------------------------------*/
function GM:AddSTOOL( category, itemname, text, command, controls, cpanelfunction )
	self:AddToolmenuOption( "Main", category, itemname, text, command, controls, cpanelfunction )
end

local ModelIndex = {}
local ModelIndexTimer = CurTime()

local function BuildModelIndex( dir )

	// Add models from this folder
	local files = file.Find( "../" .. dir .. "*" )
	for k, v in pairs( files ) do
		
		if ( v:sub( -4, -1 ) == ".mdl" ) then
		
			// Filter out some of the un-usable crap
			if ( !v:find( "_gestures" ) && 
				!v:find( "_anim" ) && 
				!v:find( "_gst" ) && 
				!v:find( "_pst" ) && 
				!v:find( "_shd" ) && 
				!v:find( "_ss" ) && 
				!v:find( "_anm" ) ) then
			
				table.insert( ModelIndex, (dir .. v):lower() )
			
			end
			
		elseif ( v:sub( -4, -4 ) != '.' ) then
		
			//BuildModelIndex( dir..v.."/" )
			
			// Stagger the loading so we don't block.
			// This means that the data is inconsistent at first
			// but it's better than adding 5 seconds onto loadtime
			// or pausing for 5 seconds on the first search
			// or dumping all this to a text file and loading it
			ModelIndexTimer = ModelIndexTimer + 0.02
			timer.Simple( ModelIndexTimer - CurTime(), BuildModelIndex, ( dir..v.."/" ) )
			
		end
		
	end
	
end



/*---------------------------------------------------------
  Called by the toolgun to add a STOOL
---------------------------------------------------------*/
function GM:DoModelSearch( str )

	local ret = {}
	
	if ( #ModelIndex == 0 ) then
		ModelIndexTimer = CurTime()
		BuildModelIndex( "models/" )
	end

	if ( str:len() < 3 ) then
			
		table.insert( ret, "Enter at least 3 characters" )
	
	else

		str = str:lower()
		
		for k, v in pairs( ModelIndex ) do
		
			if ( v:find( str ) ) then
		
				table.insert( ret, v )
			
			end
		
		end
		
	end

	return ret

end

/*---------------------------------------------------------
  GetPropCategory
  This is called by the PropSelect VGui Control (lua/vgui/PropSelect.lua)
  You should be able to hook this to add new props to a specific category
---------------------------------------------------------*/
function GM:GetPropCategory( Category, Props )

	// if ( Category = "Wheels" ) then
	//		Props[ 'models/blahblah.mdl' ] = { // OPTIONAL CONVARS HERE // }
	// end

end

/*---------------------------------------------------------
	Add your custom tabs here.
---------------------------------------------------------*/
function GM:AddToolMenuTabs()

	//spawnmenu.AddToolTab( "test", "#Test Addon" )

end

/*---------------------------------------------------------
	Add categories to your tabs
---------------------------------------------------------*/
function GM:AddToolMenuCategories()

	spawnmenu.AddToolCategory( "Main", 	"Constraints", 	"#Constraints" )
	spawnmenu.AddToolCategory( "Main", 	"Construction", "#Construction" )
	spawnmenu.AddToolCategory( "Main", 	"Poser", 		"#Poser" )
	spawnmenu.AddToolCategory( "Main", 	"Render", 		"#Render" )

end	
