private void InsertMarkDownTag(string MarkdownTag, bool PreAndPostSpace, bool Single) { string s; if (PreAndPostSpace) { s = " "; } else { s = ""; } ISEEditor editor = this.markdownHelper.CurrentFile.Editor; int line = editor.CaretLine; int col = editor.CaretColumn; if (!Single) { editor.InsertText(MarkdownTag + s + "text" + s + MarkdownTag); editor.Select(line, col + String.Format("{0}{1}", MarkdownTag, s).Length, line, col + String.Format("{0}{1}", MarkdownTag, s).Length + 4); } else { editor.InsertText(MarkdownTag); } }
public FunctionExplorer() { InitializeComponent(); var iseWindow = Application.Current.MainWindow; FieldInfo tabControlField = iseWindow.GetType().GetField("runspaceTabControl", BindingFlags.Instance | BindingFlags.NonPublic); RunspaceTabControl tabControl = (RunspaceTabControl)tabControlField.GetValue(iseWindow); PowerShellTabCollection tabCollection = tabControl.ItemsSource as PowerShellTabCollection; ISEFile file = tabCollection.SelectedPowerShellTab.Files.SelectedFile; ISEEditor editor = file.Editor; var mainMenuField = iseWindow.GetType().GetField("mainMenu", BindingFlags.Instance | BindingFlags.NonPublic); var mainMenu = (Menu)mainMenuField.GetValue(iseWindow); var newItem = new MenuItem(); newItem.Header = "Open Solution"; //((MenuItem)mainMenu.Items[0]).Items.Add(newItem); ((MenuItem)mainMenu.Items[0]).Items.Insert(2, newItem); var x = hostObject; fileManager.Add(functionsFileName); fileManager.Add(openFilesFileName); fileManager.Add(breakPointsFileName); fileManager.Add(debugLogfileName); AppDomain.CurrentDomain.DomainUnload += CurrentDomain_ProcessExit; AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit; AppDomain.CurrentDomain.FirstChanceException += CurrentDomain_FirstChanceException; try { sw = new System.IO.StreamWriter(fileManager.Get(debugLogfileName).FullName, true); } catch { } statusBarMessage = (System.Windows.Controls.Primitives.StatusBarItem) this.stbBottom.Items[1]; statusBarContent = (System.Windows.Controls.Primitives.StatusBarItem) this.stbBottom.Items[0]; timer = new DispatcherTimer(); timer.Tick += new EventHandler(timer_Tick); updateTimer = new DispatcherTimer(); updateTimer.Tick += new EventHandler(updateTimer_Tick); txtUpdateInterval_LostFocus(null, null); //start the timer with the value set in the form }
//_____________________________________________________________________________________________________________________________________________________________ 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); } }
//_____________________________________________________________________________________________________________________________________________________________ public void GetReferences() { LogHelper.Add("GetReferences"); ISEEditor editor = hostObject.CurrentPowerShellTab.Files.SelectedFile.Editor; string caretLineText = editor.CaretLineText; string currentFile = hostObject.CurrentPowerShellTab.Files.SelectedFile.FullPath; 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.StartColumn <= editor.CaretColumn && t.EndColumn >= editor.CaretColumn).ToList(); if (list.Count == 0) { list = PSParser.Tokenize(caretLineText, out errors).Where(t => t.Type == PSTokenType.CommandParameter && t.StartColumn <= editor.CaretColumn && t.EndColumn >= editor.CaretColumn).ToList(); } if (list.Count == 0) { list = PSParser.Tokenize(caretLineText, out errors).Where(t => t.Type == PSTokenType.CommandArgument && t.StartColumn <= editor.CaretColumn && t.EndColumn >= editor.CaretColumn).ToList(); } if (list.Count == 0) { list = PSParser.Tokenize(caretLineText, out errors).Where(t => t.StartColumn <= editor.CaretColumn && t.EndColumn >= editor.CaretColumn).ToList(); } if (list.Count == 0) { return; } PSToken tkn = list[0]; List <cScriptLocation> lst = GetAllReferenceLocations(tkn); string title = $"{tkn.Content} ({tkn.Type}) [{lst.Count}]"; if (tkn.Type == PSTokenType.String) // if tkn is a string with less than 2 results, try to searh into the string for additional tokens { PSToken tknsubstr = Token.GetPSTokenInLocation(caretLineText, tkn, editor.CaretColumn); if (tknsubstr != null) { List <cScriptLocation> lstsubstr = GetAllReferenceLocations(tknsubstr); if (lstsubstr.Count > 0) { lst.AddRange(lstsubstr);// is string found more tokens replace the list with the new result title += $" / {tknsubstr.Content} ({tknsubstr.Type}) [{lstsubstr.Count}]"; } } } if (lst.Count == 0) { return; } using (frmReferences f = new frmReferences()) { f.Locations = lst; f.SelectDefaultLocation(Path.GetFileName(currentFile), editor.CaretLine); f.Command = $"References {title}"; f.ShowDialog(new WindowWrapper(WindowWrapper.GetSafeHandle())); if (!f.ReferenceSelected) { return; } cScriptLocation l = f.SelectedLocation; try { hostObject.CurrentPowerShellTab.Files.SetSelectedFile(hostObject.CurrentPowerShellTab.Files.Where(file => Path.GetFileName(file.FullPath).iEquals(l.fileName)).FirstOrDefault()); hostObject.CurrentPowerShellTab.Files.SelectedFile.Editor.SetCaretPosition(l.line, l.position); hostObject.CurrentPowerShellTab.Files.SelectedFile.Editor.Select(l.line, l.position, l.line, l.position + l.word.Length); BackList.Push(pos); } catch (Exception ex) { LogHelper.AddException(ex, "GetReferences", null); } } }
//_____________________________________________________________________________________________________________________________________________________________ private cFunction GetSelectedFileName(List <cFunction> functions, string currentFile, ISEEditor editor) { if (functions.Count == 1) { return(functions[0]); } List <cScriptLocation> locations = mProjects.Project.Functions.GetScriptLocations(functions); using (frmReferences f = new frmReferences()) { f.Locations = locations; f.SelectDefaultLocation(Path.GetFileName(currentFile), editor.CaretLine); f.Command = "Found more than one candidate. Select one of them."; f.ShowDialog(new WindowWrapper(WindowWrapper.GetSafeHandle())); if (!f.ReferenceSelected) { return(null); } return(functions.Where(func => func.FullName == f.SelectedLocation.fileName && func.Line == f.SelectedLocation.line).FirstOrDefault()); } }