private void GoToDefinition(string structName, string memberName)
{
ScriptToken found = null;
Script foundInScript = null;
List<Script> scriptsToSearch = new List<Script>();
scriptsToSearch.AddRange(_agsEditor.GetAllScriptHeaders());
scriptsToSearch.Add(_script);
foreach (Script script in scriptsToSearch)
{
found = FindTokenInScript(script, structName, memberName);
foundInScript = script;
if ((found != null) && (script.IsHeader))
{
// Always prefer the definition in the main script to
// the import in the header
Script mainScript = _agsEditor.CurrentGame.RootScriptFolder.FindMatchingScriptOrHeader(script);
if (mainScript != null)
{
if (!mainScript.AutoCompleteData.Populated)
{
AutoComplete.ConstructCache(mainScript);
}
ScriptToken foundInScriptBody = FindTokenInScript(mainScript, structName, memberName);
if (foundInScriptBody != null)
{
found = foundInScriptBody;
foundInScript = mainScript;
}
}
}
if (found != null)
{
break;
}
}
if ((found == null) && (structName == null))
{
found = FindTokenAsLocalVariable(memberName, false);
}
if (found != null)
{
if (foundInScript.FileName == AGSEditor.BUILT_IN_HEADER_FILE_NAME)
{
Factory.GUIController.LaunchHelpForKeyword(_goToDefinition);
}
else if (foundInScript.FileName == Tasks.AUTO_GENERATED_HEADER_NAME)
{
Factory.GUIController.ShowMessage("This variable is internally defined by AGS and probably corresponds to an in-game entity such as a Character or Inventory Item.", MessageBoxIcon.Information);
}
else if (foundInScript.FileName == GlobalVariablesComponent.GLOBAL_VARS_HEADER_FILE_NAME)
{
IGlobalVariablesController globalVariables = (IGlobalVariablesController)Factory.ComponentController.FindComponentThatImplementsInterface(typeof(IGlobalVariablesController));
globalVariables.SelectGlobalVariable(_goToDefinition);
}
else
{
Factory.GUIController.ZoomToFile(foundInScript.FileName, ZoomToFileZoomType.ZoomToCharacterPosition, found.StartsAtCharacterIndex);
}
}
}