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

Bug 516461: use file contents to determine content type when debugging

Change-Id: I019db17522ba7eb7df979943d69df0041562eb94
This commit is contained in:
Jonah Graham 2017-05-11 13:28:28 +01:00
parent cea32dfe7b
commit d3ecfbd4f1

View file

@ -25,6 +25,7 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.CCorePreferenceConstants; import org.eclipse.cdt.core.CCorePreferenceConstants;
import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.debug.internal.core.sourcelookup.CSourceNotFoundElement; import org.eclipse.cdt.debug.internal.core.sourcelookup.CSourceNotFoundElement;
import org.eclipse.cdt.debug.internal.ui.CDebugUIUtils;
import org.eclipse.cdt.debug.internal.ui.sourcelookup.CSourceNotFoundEditorInput; import org.eclipse.cdt.debug.internal.ui.sourcelookup.CSourceNotFoundEditorInput;
import org.eclipse.cdt.debug.ui.ICDebugUIConstants; import org.eclipse.cdt.debug.ui.ICDebugUIConstants;
import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor; import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor;
@ -237,14 +238,15 @@ public class DsfSourceDisplayAdapter implements ISourceDisplay, ISteppingControl
editorId = presentation.getEditorId(editorInput, sourceElement); editorId = presentation.getEditorId(editorInput, sourceElement);
} }
} else if (sourceElement instanceof IFile) { } else if (sourceElement instanceof IFile) {
editorId = getEditorIdForFilename(((IFile) sourceElement).getName()); IFile file = (IFile) sourceElement;
editorInput = new FileEditorInput((IFile) sourceElement); editorId = getEditorIdForFile(file);
editorInput = new FileEditorInput(file);
} else if (sourceElement instanceof ITranslationUnit) { } else if (sourceElement instanceof ITranslationUnit) {
try { try {
URI uriLocation = ((ITranslationUnit) sourceElement).getLocationURI(); URI uriLocation = ((ITranslationUnit) sourceElement).getLocationURI();
IFileStore fileStore = EFS.getStore(uriLocation); IFileStore fileStore = EFS.getStore(uriLocation);
editorInput = new FileStoreEditorInput(fileStore); editorInput = new FileStoreEditorInput(fileStore);
editorId = getEditorIdForFilename(fileStore.getName()); editorId = getEditorIdForFileStore(fileStore);
} catch (CoreException e) { } catch (CoreException e) {
editorInput = new CSourceNotFoundEditorInput(new CSourceNotFoundElement(dmc, editorInput = new CSourceNotFoundEditorInput(new CSourceNotFoundElement(dmc,
fSourceLookup.getLaunchConfiguration(), fFrameData.fFile)); fSourceLookup.getLaunchConfiguration(), fFrameData.fFile));
@ -254,7 +256,7 @@ public class DsfSourceDisplayAdapter implements ISourceDisplay, ISteppingControl
File file = ((LocalFileStorage) sourceElement).getFile(); File file = ((LocalFileStorage) sourceElement).getFile();
IFileStore fileStore = EFS.getLocalFileSystem().fromLocalFile(file); IFileStore fileStore = EFS.getLocalFileSystem().fromLocalFile(file);
editorInput = new FileStoreEditorInput(fileStore); editorInput = new FileStoreEditorInput(fileStore);
editorId = getEditorIdForFilename(file.getName()); editorId = getEditorIdForFileStore(fileStore); // NOT RIGHT?
} }
} }
result.setEditorInput(editorInput); result.setEditorInput(editorInput);
@ -264,15 +266,24 @@ public class DsfSourceDisplayAdapter implements ISourceDisplay, ISteppingControl
return result; return result;
} }
private String getEditorIdForFilename(String filename) { private String getEditorIdForFile(IFile file) {
try { try {
IEditorDescriptor descriptor = IDE.getEditorDescriptor(filename); IEditorDescriptor descriptor = IDE.getEditorDescriptor(file);
return descriptor.getId(); return descriptor.getId();
} catch (PartInitException exc) { } catch (PartInitException exc) {
DsfUIPlugin.log(exc); DsfUIPlugin.log(exc);
} }
return "org.eclipse.ui.DefaultTextEditor"; //$NON-NLS-1$ return "org.eclipse.ui.DefaultTextEditor"; //$NON-NLS-1$
} }
private String getEditorIdForFileStore(IFileStore fileStore) {
try {
return CDebugUIUtils.getEditorId(fileStore);
} catch (PartInitException exc) {
DsfUIPlugin.log(exc);
}
return "org.eclipse.ui.DefaultTextEditor"; //$NON-NLS-1$
}
} }
/** /**