Beispiel #1
0
        static void ReportResult(ISearchProgressMonitor monitor, IEntity result)
        {
            string filename = result.Region.FileName;

            if (string.IsNullOrEmpty(filename))
            {
                return;
            }

            var textFile = TextFileProvider.Instance.GetTextEditorData(filename);
            var start    = textFile.LocationToOffset(result.Region.Begin);

            textFile.SearchRequest.SearchPattern = result.Name;
            var sr = textFile.SearchForward(start);

            if (sr != null)
            {
                start = sr.Offset;
            }

            if (textFile.Parent == null)
            {
                textFile.Dispose();
            }

            monitor.ReportResult(new MemberReference(result, result.Region, start, result.Name.Length));
        }
		void FindDerivedThread (object state)
		{
			monitor = IdeApp.Workbench.ProgressMonitors.GetSearchProgressMonitor (true, true);
			using (monitor) {
				IType cls = (IType) item;
				if (cls == null) return;
				
				CodeRefactorer cr = IdeApp.Workspace.GetCodeRefactorer (IdeApp.ProjectOperations.CurrentSelectedSolution);
				foreach (IType sub in cr.FindDerivedClasses (cls)) {
					if (!sub.Location.IsEmpty) {
						IEditableTextFile textFile = cr.TextFileProvider.GetEditableTextFile (sub.CompilationUnit.FileName);
						if (textFile == null) 
							textFile = new TextFile (sub.CompilationUnit.FileName);
						int position = textFile.GetPositionFromLineColumn (sub.Location.Line, sub.Location.Column);
						monitor.ReportResult (new MonoDevelop.Ide.FindInFiles.SearchResult (new FileProvider (sub.CompilationUnit.FileName, sub.SourceProject as Project), position, 0));
					}
				}
			}
		}
		public void GoToDeclaration ()
		{
			if (item is CompoundType) {
				CompoundType compoundType = (CompoundType)item;
				monitor = IdeApp.Workbench.ProgressMonitors.GetSearchProgressMonitor (true, true);
				using (monitor) {
					foreach (IType part in compoundType.Parts) {
						FileProvider provider = new FileProvider (part.CompilationUnit.FileName);
						Mono.TextEditor.Document doc = new Mono.TextEditor.Document ();
						System.IO.TextReader textReader = provider.Open ();
						doc.Text = textReader.ReadToEnd ();
						textReader.Close ();
						int position = doc.LocationToOffset (part.Location.Line, part.Location.Column);
						while (position + part.Name.Length < doc.Length) {
							if (doc.GetTextAt (position, part.Name.Length) == part.Name)
								break;
							position++;
						}
						monitor.ReportResult (new MonoDevelop.Ide.FindInFiles.SearchResult (provider, position, part.Name.Length));
					}
					
				}
				
				return;
			}
			IdeApp.ProjectOperations.JumpToDeclaration (item);
		}
        void SearchReplace(string replacePattern)
        {
            if (find != null && find.IsRunning)
            {
                if (!MessageService.Confirm(GettextCatalog.GetString("There is a search already in progress. Do you want to stop it?"), AlertButton.Stop))
                {
                    return;
                }
                lock (searchesInProgress) {
                    foreach (IProgressMonitor mon in searchesInProgress)
                    {
                        mon.AsyncOperation.Cancel();
                    }
                    searchesInProgress.Clear();
                }
            }

            Scope scope = GetScope();

            if (scope == null)
            {
                return;
            }

            ISearchProgressMonitor searchMonitor = IdeApp.Workbench.ProgressMonitors.GetSearchProgressMonitor(true);

            lock (searchesInProgress)
                searchesInProgress.Add(searchMonitor);
            UpdateStopButton();
            find = new FindReplace();

            string        pattern = comboboxentryFind.Entry.Text;
            FilterOptions options = GetFilterOptions();

            searchMonitor.ReportStatus(scope.GetDescription(options, pattern, null));

            if (!find.ValidatePattern(options, pattern))
            {
                MessageService.ShowError(GettextCatalog.GetString("Search pattern is invalid"));
                return;
            }

            if (replacePattern != null && !find.ValidatePattern(options, replacePattern))
            {
                MessageService.ShowError(GettextCatalog.GetString("Replace pattern is invalid"));
                return;
            }

            DispatchService.BackgroundDispatch(delegate {
                DateTime timer      = DateTime.Now;
                string errorMessage = null;

                try {
                    List <SearchResult> results = new List <SearchResult> ();
                    foreach (SearchResult result in find.FindAll(scope, searchMonitor, pattern, replacePattern, options))
                    {
                        if (searchMonitor.IsCancelRequested)
                        {
                            return;
                        }
                        results.Add(result);
                        if (results.Count > 10)
                        {
                            Application.Invoke(delegate {
                                results.ForEach(r => searchMonitor.ReportResult(r));
                                results.Clear();
                            });
                        }
                    }
                    Application.Invoke(delegate {
                        results.ForEach(r => searchMonitor.ReportResult(r));
                        results.Clear();
                    });
                } catch (Exception ex) {
                    errorMessage = ex.Message;
                    LoggingService.LogError("Error while search", ex);
                }

                string message;
                if (errorMessage != null)
                {
                    message = GettextCatalog.GetString("The search could not be finished: {0}", errorMessage);
                    searchMonitor.ReportError(message, null);
                }
                else if (searchMonitor.IsCancelRequested)
                {
                    message = GettextCatalog.GetString("Search cancelled.");
                    searchMonitor.ReportWarning(message);
                }
                else
                {
                    string matches = string.Format(GettextCatalog.GetPluralString("{0} match found", "{0} matches found", find.FoundMatchesCount), find.FoundMatchesCount);
                    string files   = string.Format(GettextCatalog.GetPluralString("in {0} file.", "in {0} files.", find.SearchedFilesCount), find.SearchedFilesCount);
                    message        = GettextCatalog.GetString("Search completed.") + Environment.NewLine + matches + " " + files;
                    searchMonitor.ReportSuccess(message);
                }
                searchMonitor.ReportStatus(message);
                searchMonitor.Log.WriteLine(GettextCatalog.GetString("Search time: {0} seconds."), (DateTime.Now - timer).TotalSeconds);
                searchMonitor.Dispose();
                lock (searchesInProgress)
                    searchesInProgress.Remove(searchMonitor);
                UpdateStopButton();
            });
        }
		static void ReportResult (ISearchProgressMonitor monitor, IEntity result)
		{
			string filename = result.Region.FileName;
			if (string.IsNullOrEmpty (filename))
				return;

			var textFile = TextFileProvider.Instance.GetTextEditorData (filename);
			var start = textFile.LocationToOffset (result.Region.Begin);
			textFile.SearchRequest.SearchPattern = result.Name;
			var sr = textFile.SearchForward (start);
			if (sr != null)
				start = sr.Offset;

			if (textFile.Parent == null)
				textFile.Dispose ();

			monitor.ReportResult (new MemberReference (result, result.Region, start, result.Name.Length));
		}