From 727994dc39b49ec3014860576a9e9199a6d07f6e Mon Sep 17 00:00:00 2001 From: Bogdan Gheorghe Date: Wed, 21 Apr 2004 18:57:40 +0000 Subject: [PATCH] Fix for external search markers --- core/org.eclipse.cdt.ui/ChangeLog | 3 + .../internal/ui/search/CSearchResultPage.java | 9 +-- .../ui/search/NewSearchResultCollector.java | 59 +++++++++++++++++-- 3 files changed, 62 insertions(+), 9 deletions(-) diff --git a/core/org.eclipse.cdt.ui/ChangeLog b/core/org.eclipse.cdt.ui/ChangeLog index cb29fcb5726..e13d300198c 100644 --- a/core/org.eclipse.cdt.ui/ChangeLog +++ b/core/org.eclipse.cdt.ui/ChangeLog @@ -1,3 +1,6 @@ +2004-04-21 Bogdan Gheorghe + Fixed external markers not working with new Search UI problem. + 2004-04-21 Alain Magloire Disable the PathEntry property page. diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchResultPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchResultPage.java index ce34a5347fb..0941a268975 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchResultPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/CSearchResultPage.java @@ -58,10 +58,11 @@ public class CSearchResultPage extends AbstractTextSearchViewPage { } else if (element instanceof IFile) { editor= IDE.openEditor(CUIPlugin.getActivePage(), (IFile) element, false); } else if (element instanceof BasicSearchMatch){ - BasicSearchMatch x = (BasicSearchMatch) element; - editor = IDE.openEditor(CUIPlugin.getActivePage(), (IFile) x.resource, false); - showWithMarker(editor, (IFile) x.resource, currentOffset, currentLength); - } + BasicSearchMatch searchMatch = (BasicSearchMatch) element; + if (searchMatch.resource != null){ + editor = IDE.openEditor(CUIPlugin.getActivePage(), (IFile) searchMatch.resource, false); + showWithMarker(editor, (IFile) searchMatch.resource, currentOffset, currentLength); + }} if (editor instanceof ITextEditor) { ITextEditor textEditor= (ITextEditor) editor; textEditor.selectAndReveal(currentOffset, currentLength); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/NewSearchResultCollector.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/NewSearchResultCollector.java index d1f7bd4577b..b628c44a1d6 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/NewSearchResultCollector.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/NewSearchResultCollector.java @@ -11,14 +11,19 @@ package org.eclipse.cdt.internal.ui.search; +import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate; +import org.eclipse.cdt.core.search.BasicSearchMatch; import org.eclipse.cdt.core.search.BasicSearchResultCollector; import org.eclipse.cdt.core.search.IMatch; +import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.search.ui.text.Match; public class NewSearchResultCollector extends BasicSearchResultCollector { @@ -56,17 +61,61 @@ public class NewSearchResultCollector extends BasicSearchResultCollector { * @see org.eclipse.cdt.core.search.ICSearchResultCollector#acceptMatch(org.eclipse.cdt.core.search.IMatch) */ public boolean acceptMatch(IMatch match) throws CoreException { + + BasicSearchMatch searchMatch = (BasicSearchMatch) match; - if (super.acceptMatch(match)){ + if( !super.acceptMatch( match ) ) + return false; + + if( searchMatch.resource == null && + searchMatch.path == null) + return false; + + if (searchMatch.resource != null){ fMatchCount++; int start = match.getStartOffset(); int end = match.getEndOffset(); fSearch.addMatch(new Match(match,start,end-start)); return true; } - + else { + //Check to see if external markers are enabled + IPreferenceStore store = CUIPlugin.getDefault().getPreferenceStore(); + if (store.getBoolean(CSearchPage.EXTERNALMATCH_ENABLED)){ + //Create Link in referring file's project + IPath refLocation = searchMatch.getReferenceLocation(); + IFile refFile = CCorePlugin.getWorkspace().getRoot().getFileForLocation(refLocation); + IProject refProject = refFile.getProject(); + IPath externalMatchLocation = searchMatch.getLocation(); + IFile linksFile = refProject.getFile(externalMatchLocation.lastSegment()); + //Delete links file to keep up to date with latest prefs + if (linksFile.exists()) + linksFile.delete(true,null); + + //Check to see if the file already exists - create if doesn't, mark team private + if (!linksFile.exists()){ + linksFile.createLink(externalMatchLocation,IResource.NONE,null); + int number = store.getInt(CSearchPage.EXTERNALMATCH_VISIBLE); + if (number==0){ + linksFile.setDerived(true); + } + else{ + linksFile.setTeamPrivateMember(true); + } + + } + searchMatch.resource = linksFile; + fMatchCount++; + int start = match.getStartOffset(); + int end = match.getEndOffset(); + fSearch.addMatch(new Match(match,start,end-start)); + return true; + } + } + return false; + } - - + + }