public void GoToDefinition(GotoDefinitionArgs args)
 {
     if (args.AbsoluteFilePath.ToLower() == args.CurrentOpenFilePath.ToLower())
     {
         _gotoDefinitionArgs = args;
         GotoDefinition_ScrollToLine();
     }
     else
     {
         // Open the correct file in the text editor and starting a timer
         // to let the file be loaded before scrolling to line number.
         MyContext.OpenFileInTab(args.AbsoluteFilePath);
         _gotoDefinitionArgs = args;
         DispatcherTimer dispatcherTimer = new DispatcherTimer();
         dispatcherTimer.Tick    += new EventHandler(GotoDefinition_ScrollToLine);
         dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 50);
         dispatcherTimer.Start();
     }
 }
        public HotKeyF12(MainWindow sender, TextEditor textEditor, KeyEventArgs e)
            : base(sender, textEditor)
        {
            string selectedWord = textEditor.SelectedText;

            if (string.IsNullOrWhiteSpace(selectedWord) || IsRunning)
            {
                return;
            }
            IsRunning = true;


            string definedVariableFilePath = null;
            string currentFilePath         = null;
            int    lineNumber = -1;

            string selectedFullname = selectedWord;
            string lineBeforeWord   = MainWindow.GetLineReadBackwards(textEditor.Text, textEditor.SelectionStart);
            string namespaceName    = MainWindow.GetCurrentNamespaceName(textEditor.Text, textEditor.SelectionStart);
            var    usings           = MainWindow.GetCurrentUsings(textEditor.Text, textEditor.SelectionStart);

            // Get the full name of this word
            if (lineBeforeWord.EndsWith("."))
            {
                while (lineBeforeWord.EndsWith("."))
                {
                    string beforeDot = MainWindow.GetWordBeforeDotReadBackwards(lineBeforeWord, lineBeforeWord.Length - 1);
                    lineBeforeWord   = lineBeforeWord.Remove(lineBeforeWord.IndexOf(beforeDot));
                    selectedFullname = beforeDot + "." + selectedFullname;
                }
            }


            TabViewModel currentTab = textEditor.DataContext as TabViewModel;

            if (currentTab != null)
            {
                currentFilePath = currentTab.AbsoluteFilePathName;
            }
            bool isSqx = (currentFilePath.EndsWith(".sqx", true, null)) ? true : false;


            // If this is not a method/property (no '.' before this word)
            // Serach for it in the private/public variable lists.
            if (selectedFullname == selectedWord)
            {
                // Check if the selected word is a declared PRIVATE variable.
                GlobalContextVariable privateVariable = GetDeclaredVariableFromWord(selectedWord, MyContext.DeclaredPrivateVariables);
                if (privateVariable != null)
                {
                    definedVariableFilePath = privateVariable.FileName;
                    lineNumber = privateVariable.DeclaredAtLineNumber;
                    //GoToDefinition();
                    //return;
                    // TODO: Only check private variables if it's:
                    //              _base
                    //              _self
                }

                // Check if the selected word is a declared PUBLIC variable.
                GlobalContextVariable publicVariable = GetDeclaredVariableFromWord(selectedWord, MyContext.DeclaredPublicVariables);
                if (publicVariable != null)
                {
                    var args = new GotoDefinitionArgs(publicVariable.FileName, publicVariable.DeclaredAtLineNumber);
                    args.CurrentOpenFilePath = currentFilePath;
                    GoToDefinition(args);
                    return;
                }
            }

            ObjectInfo objectInfo = null;
            // This is a Custom Type (there's a '.' before this word, or this is the class itself.)
            // If the first word before dot is a private variable
            string firstWord = selectedWord;

            if (selectedFullname.Contains("."))
            {
                firstWord = selectedFullname.Substring(0, selectedFullname.IndexOf("."));
            }

            GlobalContextVariable firstWordPrivateVariable = GetDeclaredVariableFromWord(firstWord, MyContext.DeclaredPrivateVariables);

            if (firstWordPrivateVariable != null && !string.IsNullOrWhiteSpace(firstWordPrivateVariable.TypeName))
            {
                objectInfo = MyContext.DeclaredTypes.FirstOrDefault(c => c.FullName.ToLower() == firstWordPrivateVariable.TypeName.ToLower()) as ObjectInfo;

                if (objectInfo != null)
                {
                    var args = FindChildInClass(objectInfo, selectedWord);
                    if (args != null)
                    {
                        args.CurrentOpenFilePath = currentFilePath;
                        GoToDefinition(args);
                        return;
                    }
                }
            }

            // If this is a static method/property or class
            // Then the first word is a class or enum.
            TypeInfo typeInfo;
            var      typeInfos = MainWindow.GetPossibleTypes(namespaceName, MyContext.DeclaredTypes, usings);

            typeInfo = typeInfos.FirstOrDefault(i => i.Name == firstWord);

            if (typeInfo == null)
            {
                typeInfo = typeInfos.FirstOrDefault(i => i.FullName == selectedFullname);
            }

            if (typeInfo != null)
            {
                if (typeInfo.Name == selectedWord)
                {
                    // The selected word is this Class or Enum type.
                    var args = new GotoDefinitionArgs(typeInfo.FileName, typeInfo.LineNumber);
                    args.CurrentOpenFilePath = currentFilePath;
                    GoToDefinition(args);
                    return;
                }
                else
                {
                    // The selected word is a CHILD to this class/enum.
                    var args = FindChildInClass(typeInfo, selectedWord);
                    if (args != null)
                    {
                        args.CurrentOpenFilePath = currentFilePath;
                        GoToDefinition(args);
                        return;
                    }
                }
            }
        }