1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 02:06:01 +02:00

Add position trackers for workspace external files.

This commit is contained in:
Markus Schorn 2006-07-04 11:39:07 +00:00
parent a4e5148925
commit 7aecc5731f
3 changed files with 42 additions and 8 deletions

View file

@ -12,9 +12,10 @@
package org.eclipse.cdt.core;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IPath;
/**
* An interface to manage the position tracking that allows for mapping character
* An interface to manage the position tracking. It allows for mapping character
* offsets from a file previously stored on disk to the current offset.
*/
public interface IPositionTrackerManager {
@ -24,7 +25,19 @@ public interface IPositionTrackerManager {
*
* @param file a file for which the position adapter is requested.
* @param timestamp identifies the version of the file stored on disk.
* @return the requested position adapter or <code>null</code>.
* @return the requested position converter or <code>null</code>.
*/
IPositionConverter findPositionConverter(IFile file, long timestamp);
public IPositionConverter findPositionConverter(IFile file, long timestamp);
/**
* Returns the position tracker suitable for mapping character offsets of the
* given external file/timestamp to the current version of it. <p>
* The method can be used for resources by supplying the <b>full path</b>. However,
* it does not work if you supply the location of a resource.
*
* @param externalLocationOrFullPath an external location for which the position adapter is requested.
* @param timestamp identifies the version of the file stored on disk.
* @return the requested position converter or <code>null</code>.
*/
public IPositionConverter findPositionConverter(IPath fullPathOrExternalLocation, long timestamp);
}

View file

@ -168,6 +168,9 @@ public class PositionTrackerManager implements IPositionTrackerManager, IFileBuf
}
}
/**
* {@inheritDoc}
*/
public synchronized IPositionConverter findPositionConverter(IFile file, long timestamp) {
PositionTrackerChain chain= (PositionTrackerChain) fPositionTrackerMap.get(file.getFullPath());
if (chain != null) {
@ -175,4 +178,15 @@ public class PositionTrackerManager implements IPositionTrackerManager, IFileBuf
}
return null;
}
/**
* {@inheritDoc}
*/
public synchronized IPositionConverter findPositionConverter(IPath externalLocation, long timestamp) {
PositionTrackerChain chain= (PositionTrackerChain) fPositionTrackerMap.get(externalLocation);
if (chain != null) {
return chain.findTrackerAt(timestamp);
}
return null;
}
}

View file

@ -672,16 +672,13 @@ public class IBViewPart extends ViewPart
IBFile ibf= node.getDirectiveFile();
if (ibf != null) {
IEditorPart editor= null;
Position pos= new Position(node.getDirectiveCharacterOffset(),
node.getDirectiveName().length() + 2);
IPath filebufferKey= null;
IFile f= ibf.getResource();
if (f != null) {
fLastNavigationNode= node;
IPositionConverter converter= CCorePlugin.getPositionTrackerManager().findPositionConverter(f, node.getTimestamp());
pos= converter.historicToActual(pos);
try {
editor= IDE.openEditor(page, f, false);
filebufferKey= f.getFullPath();
} catch (PartInitException e) {
CUIPlugin.getDefault().log(e);
}
@ -694,6 +691,7 @@ public class IBViewPart extends ViewPart
try {
IEditorDescriptor descriptor = IDE.getEditorDescriptor(location.lastSegment());
editor= IDE.openEditor(page, ei, descriptor.getId(), false);
filebufferKey= location;
} catch (PartInitException e) {
CUIPlugin.getDefault().log(e);
}
@ -701,6 +699,15 @@ public class IBViewPart extends ViewPart
}
if (editor instanceof ITextEditor) {
ITextEditor te= (ITextEditor) editor;
Position pos= new Position(node.getDirectiveCharacterOffset(),
node.getDirectiveName().length() + 2);
if (filebufferKey != null) {
IPositionConverter pc= CCorePlugin.getPositionTrackerManager().findPositionConverter(filebufferKey, node.getTimestamp());
if (pc != null) {
pos= pc.historicToActual(pos);
}
}
te.selectAndReveal(pos.getOffset(), pos.getLength());
}
}