Ejemplo n.º 1
0
        //_____________________________________________________________________________________________________________________________________________________________
        private void cTvFunctions_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            LogHelper.Add("cTvFunctions_MouseDoubleClick");
            TreeViewItem item = (TreeViewItem)((TreeView)sender).SelectedItem;

            if (item == null)
            {
                return;
            }
            cFunction tag = item.Tag as cFunction;

            if (tag == null)  // doubleclick in file node
            {
                if (item.GetType().Name != "FileTreeViewItem")
                {
                    return;
                }
                try {
                    hostObject.CurrentPowerShellTab.Files.SetSelectedFile(hostObject.CurrentPowerShellTab.Files.Where(file => Path.GetFileName(file.FullPath).iEquals(item.Header.ToString())).FirstOrDefault());
                    hostObject.CurrentPowerShellTab.Files.SelectedFile.Editor.SelectCaretLine();
                }
                catch (Exception ex) { LogHelper.AddException(ex, "cTvFunctions_MouseDoubleClick", "selected file"); }
            }
            else  // doubleclick in function node
            {
                try {
                    hostObject.CurrentPowerShellTab.Files.SetSelectedFile(hostObject.CurrentPowerShellTab.Files.Where(file => file.FullPath.iEquals(tag.FullName)).FirstOrDefault());
                    hostObject.CurrentPowerShellTab.Files.SelectedFile.Editor.SetCaretPosition(tag.Line, tag.Position);
                    hostObject.CurrentPowerShellTab.Files.SelectedFile.Editor.Select(tag.Line, tag.Position, tag.Line, tag.Position + tag.Name.Length);
                }
                catch (Exception ex) { LogHelper.AddException(ex, "cTvFunctions_MouseDoubleClick", "selected function"); }
            }
        }
Ejemplo n.º 2
0
        //_____________________________________________________________________________________________________________________________________________________________
        private int AddItemToList(TreeViewItem scriptItem, cFunction functionDefinition)
        {
            TreeViewItem treeViewItem = new TreeViewItem();

            treeViewItem.Header = CreateChildNode(functionDefinition);
            treeViewItem.Tag    = functionDefinition;
            scriptItem.Items.Add(treeViewItem);
            return(1);
        }
Ejemplo n.º 3
0
        //_____________________________________________________________________________________________________________________________________________________________
        public bool GoToDefinition()
        {
            LogHelper.Add("GoToDefinition");
            try {
                ISEEditor editor              = hostObject.CurrentPowerShellTab.Files.SelectedFile.Editor;
                string    currentFile         = hostObject.CurrentPowerShellTab.Files.SelectedFile.FullPath;
                string    caretLineText       = editor.CaretLineText;
                Tuple <string, int, int> pos  = new Tuple <string, int, int>(currentFile, editor.CaretLine, editor.CaretColumn);
                List <PSToken>           list = PSParser.Tokenize(caretLineText, out Collection <PSParseError> errors).Where(t => (t.Type == PSTokenType.Command || t.Type == PSTokenType.Member) && t.StartColumn <= editor.CaretColumn && t.EndColumn >= editor.CaretColumn).ToList();

                List <cFunction> functions = mProjects.Project.Functions.GetFunctionByFileAndName(currentFile, list[0].Content);
                if (functions.Count == 0)
                {
                    functions = mProjects.Project.Functions.GetFunctionByName(list[0].Content);
                }
                if (functions.Count == 0)
                {
                    return(false);
                }

                cFunction function = GetSelectedFileName(functions, currentFile, editor);

                ISEFile file = hostObject.CurrentPowerShellTab.Files.Where(x => x.FullPath.iEquals(function.FullName)).FirstOrDefault();
                if (file != null)
                {
                    hostObject.CurrentPowerShellTab.Files.SetSelectedFile(file);
                }
                else
                {
                    try { hostObject.CurrentPowerShellTab.Files.Add(function.FullName); }
                    catch (Exception ex) { LogHelper.AddException(ex, "GoToDefinition", null); return(false); }
                }
                hostObject.CurrentPowerShellTab.Files.SelectedFile.Editor.SetCaretPosition(functions[0].Line, 1);
                hostObject.CurrentPowerShellTab.Files.SelectedFile.Editor.Select(function.Line, function.Position, function.Line, function.Position + function.Name.Length);
                BackList.Push(pos);
                return(true);
            }
            catch (Exception ex) { LogHelper.AddException(ex, "GoToDefinition", null); return(false); }
        }
Ejemplo n.º 4
0
        //_____________________________________________________________________________________________________________________________________________________________
        private object CreateChildNode(cFunction f)
        {
            LogHelper.Add($"CreateChildNode({f.SerializedString})");
            DockPanel dp = new DockPanel()
            {
                HorizontalAlignment = HorizontalAlignment.Left, LastChildFill = true
            };

            DockPanel.SetDock(dp, Dock.Right);
            TextBlock txt = new TextBlock()
            {
                Background = Brushes.Transparent, HorizontalAlignment = HorizontalAlignment.Left, Foreground = Brushes.Black, Text = cGroupTypes.IsChecked == true ? f.ShortAlias : f.Alias
            };
            TextBlock elip = new TextBlock()
            {
                Background = Brushes.Transparent, HorizontalAlignment = HorizontalAlignment.Left, Foreground = Brushes.Gray, Text = $" / {f.Line}"
            };

            DockPanel.SetDock(elip, Dock.Right);
            dp.Children.Add(elip);
            dp.Children.Add(txt);
            return(dp);
        }