public void Dispose() { if (this.m_FileFinder != null) { this.m_FileFinder.Dispose(); this.m_FileFinder = null; } if (this.m_GetOpenFilesThread != null) { this.m_GetOpenFilesThread.Dispose(); this.m_GetOpenFilesThread = null; } if (this.m_SolutionFiles != null) { this.m_SolutionFiles.Dispose(); this.m_SolutionFiles = null; } if (this.m_Settings != null) { this.m_Settings.Dispose(); this.m_Settings = null; } if (this.m_TextFinder != null) { this.m_TextFinder.Dispose(); this.m_TextFinder = null; } }
public int OnLinkClicked(int iField, int iLinkIndex) { TextFinder startFinder = delegate(string text, int startIndex) { return(text.IndexOf("@", startIndex)); }; TextFinder endFinder = delegate(string text, int startIndex) { return(text.IndexOf("@", startIndex + 1)); }; Span span = FindNthSpan(_comment, iLinkIndex, startFinder, endFinder); if (span != null) { IVsWebBrowsingService browser = _serviceProvider.GetService(typeof(SVsWebBrowsingService)) as IVsWebBrowsingService; IVsWindowFrame frame = null; int hr = browser.Navigate(_comment.Substring(span.Start + 1, span.Length - 2), 0, out frame); Debug.Assert(hr == VSConstants.S_OK, "Navigate did not return S_OK."); return(VSConstants.S_OK); } else { Debug.Assert(false, "Invalid link index sent to OnLinkClicked."); return(VSConstants.E_INVALIDARG); } }
static void Main(string[] args) { TextFinder tf = new TextFinder(@"D:\temp\test.txt"); tf.TextFound += new TextFoundEventHandler(tf_TextFoundEvent); tf.Execute("public"); Console.ReadLine(); }
public int FindWordInText(string textToFind, int atricleId) { Article article = articleDao.SelectById(atricleId); string text = article.Text; TextFinder finder = new TextFinder(); int occurancesInText = finder.FindTextOccurances(textToFind, text); return(occurancesInText); }
public static void Destroy() { FastFindToolWindowPane.m_DTE = null; FastFindToolWindowPane.m_SolutionFiles = null; FastFindToolWindowPane.m_FileFinder = null; FastFindToolWindowPane.m_TextFinder = null; FastFindToolWindowPane.m_GetOpenFilesThread = null; FastFindToolWindowPane.m_Settings = null; }
public static void Initialise(DTE dte, SolutionFiles solution_files, FileFinder file_finder, TextFinder text_finder, GetOpenFilesThread get_open_files_thread, Settings settings) { FastFindToolWindowPane.m_DTE = dte; FastFindToolWindowPane.m_SolutionFiles = solution_files; FastFindToolWindowPane.m_FileFinder = file_finder; FastFindToolWindowPane.m_TextFinder = text_finder; FastFindToolWindowPane.m_GetOpenFilesThread = get_open_files_thread; FastFindToolWindowPane.m_Settings = settings; }
private static IEnumerable <Span> FindSpans(string text, TextFinder startFinder, TextFinder endFinder) { int index = 0; for (Span span = FindSpan(text, index, startFinder, endFinder); span.Start >= 0; span = FindSpan(text, index, startFinder, endFinder)) { index = span.Start + span.Length; yield return(span); } }
//========================================================================================= public void Init(TextFinder finder, List <string> listSearch) { this.Finder = finder; this.ListSearch = listSearch; if (this.ListSearch == null || this.ListSearch.Count == 0) { return; } this.comboFind.Items.AddRange(listSearch.ToArray()); this.comboFind.SelectedIndex = 0; }
/// <summary> /// /// </summary> /// <param name="startFinder"></param> /// <param name="endFinder"></param> /// <returns></returns> /// <remarks> /// <c>startFinder(text, startIndex)</c> is used to find the beginning of the next span. /// If it returns a positive index, <c>endFinder(text, startFinder(text, startIndex))</c> /// is used to find the end of the span. <c>endFinder</c> should return the index of the /// last character in the span (not the first character after the span). /// </remarks> private static Span FindSpan(string text, int startIndex, TextFinder startFinder, TextFinder endFinder) { int start = startFinder(text, startIndex); if (start >= 0) { int end = endFinder(text, start); return(new Span(start, end - start + 1)); } else { return(new Span(-1, -1)); } }
public void Initialise(DTE dte, SolutionFiles solution_files, FileFinder file_finder, TextFinder text_finder, GetOpenFilesThread get_open_files_thread, OleMenuCommandService mcs, Settings settings) { this.m_DTE = dte; this.m_SolutionFiles = solution_files; this.m_FileFinder = file_finder; this.m_TextFinder = text_finder; this.m_GetOpenFilesThread = get_open_files_thread; this.m_Settings = settings; if (mcs != null) { CommandID menuCommandID = new CommandID(GuidList.guidVSAnythingCmdSet, 256); MenuCommand menuItem = new MenuCommand(new EventHandler(this.MenuItemCallback), menuCommandID); mcs.AddCommand(menuItem); } }
private static Span FindNthSpan(string text, int spanIndex, TextFinder startFinder, TextFinder endFinder) { foreach (Span span in FindSpans(text, startFinder, endFinder)) { if (spanIndex == 0) { return(span); } else { --spanIndex; } } return(null); }
public void ShowFind() { FindForm findForm = new FindForm(); if (this.Finder == null) { this.Finder = new TextFinder(this); } if (listSearch == null) { listSearch = new List <string>(); } findForm.Init(this.Finder, listSearch); findForm.Show(this); }
public MainWindow() { InitializeComponent(); searchingFile = false; baseDirectionInfo = "Contracts direction"; PC = new PathCollector(); TF = new TextFinder(); string dir = Directory.GetCurrentDirectory() + "/ContractsDirection.txt"; StreamReader SR = new StreamReader(dir); string str = SR.ReadLine(); SR.Close(); if (str.Contains(baseDirectionInfo)) { string s = str.Substring(21); PC.AddPath(s); } numberFields = new TextBox[10]; numberFields[0] = TextNumber1; numberFields[1] = TextNumber2; numberFields[2] = TextNumber3; numberFields[3] = TextNumber4; numberFields[4] = TextNumber5; numberFields[5] = TextNumber6; numberFields[6] = TextNumber7; numberFields[7] = TextNumber8; numberFields[8] = TextNumber9; numberFields[9] = TextNumber10; contractFields = new TextBox[10]; contractFields[0] = TextContract1; contractFields[1] = TextContract2; contractFields[2] = TextContract3; contractFields[3] = TextContract4; contractFields[4] = TextContract5; contractFields[5] = TextContract6; contractFields[6] = TextContract7; contractFields[7] = TextContract8; contractFields[8] = TextContract9; contractFields[9] = TextContract10; }
/// <summary> /// Finds http links in the given text and surrounds them with '@' so they will be treated /// as links by the task list. /// </summary> /// <param name="text"></param> /// <returns></returns> /// <remarks> /// In VS 2005, the task list has a bug which prevents links from being displayed properly /// unless they begin somewhere on the first line of a task cell. /// </remarks> private static string ParseLinks(string text) { TextFinder startFinder = delegate(string text2, int startIndex) { return(text2.IndexOf("http://", startIndex)); }; TextFinder endFinder = delegate(string text2, int startIndex) { if (startIndex > 0 && text2[startIndex - 1] == '"') { // This is a quoted URL, so look for the end-quote. int endQuote = text2.IndexOf('"', startIndex); if (endQuote >= 0) { return(endQuote); } else { return(text2.Length - 1); } } else { // It's not a quoted URL, so just end it on the next whitespace character. int nextWhitespace = text2.IndexOfAny(new char[] { ' ', '\t', '\n', '\r' }, startIndex); if (nextWhitespace == -1) { nextWhitespace = text2.Length; } // If the character before the whitespace is punctuation (as in a URL // which ends with a period that isn't actually part of it), don't // include the punctuation character. if (Char.IsPunctuation(text2[nextWhitespace - 1])) { --nextWhitespace; } return(nextWhitespace - 1); } }; StringBuilder result = new StringBuilder(); int previousSpanEnd = 0; foreach (Span linkSpan in FindSpans(text, startFinder, endFinder)) { if (linkSpan.Start > previousSpanEnd) { result.Append(text.Substring(previousSpanEnd, linkSpan.Start - (previousSpanEnd))); } result.Append('@'); result.Append(text.Substring(linkSpan.Start, linkSpan.Length)); result.Append('@'); previousSpanEnd = linkSpan.Start + linkSpan.Length; } if (previousSpanEnd < text.Length) { result.Append(text.Substring(previousSpanEnd)); } return(result.ToString()); }
private static Span FindNthSpan(string text, int spanIndex, TextFinder startFinder, TextFinder endFinder) { foreach (Span span in FindSpans(text, startFinder, endFinder)) { if (spanIndex == 0) { return span; } else { --spanIndex; } } return null; }
public FastFindForm(DTE dte, SolutionFiles solution_files, FileFinder file_finder, TextFinder text_finder, GetOpenFilesThread get_open_files_thread, Settings settings, string initial_text) { this.InitializeComponent(); this.m_Settings = settings; base.Size = settings.FastFindFormSize; SettingsDialogPage settings_page = VSAnythingPackage.Inst.GetSettingsDialogPage(); if (string.IsNullOrEmpty(initial_text) && settings_page.RememberLastFind && !string.IsNullOrEmpty(FastFindForm.m_LastFindText)) { initial_text = FastFindForm.m_LastFindText; } bool is_modal = true; this.m_FastFindControl = new FastFindControl(dte, solution_files, file_finder, text_finder, get_open_files_thread, settings, initial_text, FastFindForm.m_LastSelectedItem, is_modal); this.m_FastFindControl.Dock = DockStyle.Fill; this.m_FastFindControl.ControlWantsToClose += new FastFindControl.ControlWantsToCloseHandler(this.FastFindControlWantsToClose); base.Controls.Add(this.m_FastFindControl); this.m_FastFindControl.OnActivated(); }
internal FastFindControlWPFWrapper(DTE dte, SolutionFiles solution_files, FileFinder file_finder, TextFinder text_finder, GetOpenFilesThread get_open_files_thread, Settings settings, WindowPane window_pane_owner) { this.InitializeComponent(); this.m_DTE = dte; this.m_TabStopPanel.WpfHost = this.m_WindowsFormsHost; bool is_modal = false; this.m_FastFindControl = new FastFindControl(dte, solution_files, file_finder, text_finder, get_open_files_thread, settings, "", -1, is_modal); this.m_FastFindControl.ControlWantsToClose += onEscToCloseWindow; this.m_FastFindControl.Dock = DockStyle.Fill; this.m_TabStopPanel.Controls.Add(this.m_FastFindControl); }
private static IEnumerable<Span> FindSpans(string text, TextFinder startFinder, TextFinder endFinder) { int index = 0; for (Span span = FindSpan(text, index, startFinder, endFinder); span.Start >= 0; span = FindSpan(text, index, startFinder, endFinder)) { index = span.Start + span.Length; yield return span; } }
/// <remarks> /// <c>startFinder(text, startIndex)</c> is used to find the beginning of the next span. /// If it returns a positive index, <c>endFinder(text, startFinder(text, startIndex))</c> /// is used to find the end of the span. <c>endFinder</c> should return the index of the /// last character in the span (not the first character after the span). /// </remarks> private static Span FindSpan(string text, int startIndex, TextFinder startFinder, TextFinder endFinder) { int start = startFinder(text, startIndex); if (start >= 0) { int end = endFinder(text, start); return new Span(start, end - start + 1); } else { return new Span(-1, -1); } }
void CreateIndexBeforeTextFinderWithSearchTextOf(string searchText) { helper = new IndexBeforeTextFinderHelper(); textFinder = helper.CreateIndexBeforeTextFinder(searchText); }
protected override void Initialize() { base.Initialize(); try { Log.OpenFile(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\VSAnything\\VSAnything.log"); VSAnythingPackage.m_Inst = this; Log.WriteLine("----------------------------------------------------------"); Log.WriteLine("FastFind Initialise"); Log.WriteLine("FastFind Version: 4.8"); this.m_Settings.Read(); EnvDTE.DTE env_dte = (EnvDTE.DTE)base.GetService(typeof(SDTE)); string vs_version; try { vs_version = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName; } catch (Exception e) { vs_version = "Error getting VS version: " + e.Message; } Log.WriteLine("Visual Studio Version: " + vs_version); this.m_DTE = new DTE(env_dte); this.m_TextFinder = new TextFinder(); this.m_FileFinder = new FileFinder(this.m_Settings); this.m_FileFinder.SetSolutionFiles(new List <string>(this.m_Settings.SolutionFiles)); this.m_SolutionFiles = new SolutionFiles(this.m_DTE); this.m_GetOpenFilesThread = new GetOpenFilesThread(env_dte); this.m_SolutionFiles.SolutionFileListChanged += new SolutionFiles.SolutionFileListChangedHandler(this.SolutionFilesChanged); this.m_DocumentEvents = env_dte.Events.get_DocumentEvents(null); this.m_SolutionEvents = env_dte.Events.SolutionEvents; this.m_WindowEvents = env_dte.Events.get_WindowEvents(null); //mariotodo 改成下面那样,不知道对不对 //this.m_DocumentEvents.DocumentSaved += new _dispDocumentEvents_DocumentSavedEventHandler(this, (UIntPtr)System.Reflection.Emit.OpCodes.Ldftn(DocumentSaved)); //this.m_SolutionEvents.ProjectAdded += new _dispSolutionEvents_ProjectAddedEventHandler(this, (UIntPtr)ldftn(ProjectAddedOrRemoved)); //this.m_SolutionEvents.ProjectRemoved += new _dispSolutionEvents_ProjectRemovedEventHandler(this, (UIntPtr)ldftn(ProjectAddedOrRemoved)); //this.m_WindowEvents.WindowActivated += new _dispWindowEvents_WindowActivatedEventHandler(this, (UIntPtr)ldftn(WindowActivated)); this.m_DocumentEvents.DocumentSaved += new _dispDocumentEvents_DocumentSavedEventHandler(this.DocumentSaved); this.m_SolutionEvents.ProjectAdded += new _dispSolutionEvents_ProjectAddedEventHandler(this.ProjectAddedOrRemoved); this.m_SolutionEvents.ProjectRemoved += new _dispSolutionEvents_ProjectRemovedEventHandler(this.ProjectAddedOrRemoved); this.m_WindowEvents.WindowActivated += new _dispWindowEvents_WindowActivatedEventHandler(this.WindowActivated); FastFindToolWindowPane.Initialise(this.m_DTE, this.m_SolutionFiles, this.m_FileFinder, this.m_TextFinder, this.m_GetOpenFilesThread, this.m_Settings); OleMenuCommandService mcs = base.GetService(typeof(IMenuCommandService)) as OleMenuCommandService; this.m_FastFindCmd.Initialise(this.m_DTE, this.m_SolutionFiles, this.m_FileFinder, this.m_TextFinder, this.m_GetOpenFilesThread, mcs, this.m_Settings); this.m_FastFindWindowCmd.Initialise(this, this.m_DTE, mcs, this.m_Settings); this.m_SourceHeaderToggleCmd.Initialise(this.m_DTE, this.m_SolutionFiles, mcs); this.m_SettingsCmd.Initialise(mcs); this.m_Solution = (base.GetService(typeof(SVsSolution)) as IVsSolution2); if (this.m_Solution != null) { int ret = this.m_Solution.AdviseSolutionEvents(this, out this.m_SolutionEventsCookie); Log.WriteLine("AdviseSolutionEvents returned " + ret); } this.AddSolutionFileToSettings(); if (this.m_DTE.EnvDTE.Solution != null) { foreach (Project project in this.m_DTE.EnvDTE.Solution.Projects) { IVsHierarchy pHierarchy = null; if (this.m_Solution.GetProjectOfUniqueName(project.UniqueName, out pHierarchy) == 0 && pHierarchy != null) { this.AdviseHierarchyEvents(pHierarchy); } } } if (!this.m_Settings.ShownWelcomeForm) { new System.Threading.Thread(new ThreadStart(this.WelcomeThread)).Start(); } } catch (Exception arg_368_0) { Utils.LogException(arg_368_0); } }