Home » Eclipse Projects » Eclipse Platform » My plugin TextEditor is never created
My plugin TextEditor is never created [message #530856] |
Sat, 01 May 2010 22:44 |
Clark Messages: 21 Registered: April 2010 |
Junior Member |
|
|
I have a plugin that implements a syntax highlighting text editor for a small programming language. In the debugger, I can open a file with my file extension and observe my partitioner and partition scanner being created, the partitioner is connected to the document, the input file is scanned and properly divided into the specified partitions (comments, strings, and everything else is the default partition for code). When it is finished, the source program is displayed in what looks like a default TextEditor. Breakpoints in my extension of TextEditor were never hit, including in the constructor. Hence, my syntax highlighting is never invoked, etc.
The extension in my plugin.xml is as follows:
<extension
point="org.eclipse.ui.editors">
<editor
name="T Language Editor"
extensions="t"
icon="icons/sample.gif"
contributorClass="org.eclipse.ui.texteditor.BasicTextEditorActionContributor"
class="com.acme.t.editors.TEditor"
id="com.acme.t.editors.TEditor"/>
</extension>
In the com.acme.t.editors package is the file TEditor.java, with the class definition and constructor:
public class TEditor extends TextEditor {
private ColorCache colorCache;
private TEditConfiguration editConfiguration;
public TEditor()
{
super();
IPreferenceStore preferences = Activator.getDefault().getPreferenceStore();
colorCache = new ColorCache();
editConfiguration = new TEditConfiguration(colorCache, this, preferences);
setSourceViewerConfiguration(editConfiguration);
setDocumentProvider(new TDocumentProvider());
// enable standard vertical ruler
setRangeIndicator(new DefaultRangeIndicator());
}
Any ideas why my TEditor() constructor is never reached in the debugger? Does anyone know where I should set a breakpoint in Eclipse code to see it create the TextEditor that it is creating?
Thanks for any help.
|
|
|
Re: My plugin TextEditor is never created [message #531057 is a reply to message #530856] |
Mon, 03 May 2010 14:28 |
|
Are you sure it's trying to open your editor? Does anything change if
you choose your editor from the file's Open With... context menu?
--
Nitin Dahyabhai
Eclipse WTP Source Editing and JSDT
IBM Rational
_
Nitin Dahyabhai
Eclipse Web Tools Platform
|
|
| | | | | |
Re: My plugin TextEditor is never created [message #531743 is a reply to message #531297] |
Thu, 06 May 2010 01:51 |
Clark Messages: 21 Registered: April 2010 |
Junior Member |
|
|
I have been setting breakpoints earlier and earlier in the Eclipse code. I keep seeing the editorId String "org.eclipse.ui.editors.DefaultTextEditor" passed as arguments, so I keep going back to an earlier spot.
Now, I am in org.eclipse.ui.internal.ReopenEditorMenu.java. The last method is called open() and looks like this:
private void open(EditorHistoryItem item) {
IWorkbenchPage page = window.getActivePage();
if (page != null) {
try {
String itemName = item.getName();
if (!item.isRestored()) {
item.restoreState();
}
IEditorInput input = item.getInput();
IEditorDescriptor desc = item.getDescriptor();
if (input == null || desc == null) {
String title = WorkbenchMessages.OpenRecent_errorTitle;
String msg = NLS.bind(WorkbenchMessages.OpenRecent_unableToOpen, itemName );
MessageDialog.openWarning(window.getShell(), title, msg);
history.remove(item);
} else {
page.openEditor(input, desc.getId());
}
} catch (PartInitException e2) {
String title = WorkbenchMessages.OpenRecent_errorTitle;
MessageDialog.openWarning(window.getShell(), title, e2
.getMessage());
history.remove(item);
}
}
}
The 5th line of code:
String itemName = item.getName();
produces the name of the input source text file I just opened, "foo.t"
The 10th line of code:
IEditorDescriptor desc = item.getDescriptor();
produces a descriptor for the file foo.t, which already has the org.eclipse.ui.editors.DefaultTextEditor class filled in, with null for the editor name, etc.
So, despite the plugin.xml editor extension point that I showed earlier in this thread, Eclipse has associated my file with the default editor VERY early in the process.
If anyone knows where in the Eclipse code it would associate this file name with an editor descriptor, I will set breakpoints there. Otherwise, I will keep trying to trace backwards on my own.
Thanks.
|
|
| | | |
Re: My plugin TextEditor is never created [message #531907 is a reply to message #531884] |
Thu, 06 May 2010 13:59 |
Clark Messages: 21 Registered: April 2010 |
Junior Member |
|
|
Thanks for the reply.
I tried a new file with my file extension, and I get the same behavior. Very early in Eclipse code, it has decided to associate the DefaultTextEditor with my file.
I open the files using File->Open File. When I do this, it eventually opens my partitioner, which is also associated with the file extension. But this is after the point in time when it should have opened an editor for the same file extension.
The code you posted is a great idea, but where do I put it? My plug-in is really just an editor and a partitioner, with a document provider. As far as I know, my plug-in is not executing until I do the File->File Open, at which point Eclipse will create my partitioner due to the file extension. Should I have the user invoke the plug-in, then have it prompt for a file name, and then open the file using the code you provided?
I am not familiar with the code structure for a plug-in that gets invoked by the user. This is my first plug-in, and it has only been invoked by Eclipse due to the file open event.
Thanks for any advice.
|
|
| | | |
Re: My plugin TextEditor is never created [message #532164 is a reply to message #531999] |
Fri, 07 May 2010 11:45 |
Clark Messages: 21 Registered: April 2010 |
Junior Member |
|
|
I have made some progress using the code you posted. I modified it to permit opening a file from a FileDialog. I am successfully opening files and creating my editor and passing the file to the editor. I can see the file being partitioned (as was always the case) and the file opens in a window.
Problem: Still no syntax highlighting. I can see my presentation reconciler being created, and three damager-repairers being created and attached to it (for my three partitions: comments, strings, and code (default)). But the scanners are apparently never used. In the scanner classes, I overrode the nextToken() methods to do nothing but call super.nextToken() just so I could set breakpoints and see if the nextToken() method (of RuleBasedScanner) is ever called. It is not. Who is supposed to be calling the scanners in the presentation reconciler to scan the partitions?
Here is the setup of my presentation reconciler:
public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
if (reconciler == null) {
reconciler = new PresentationReconciler();
reconciler.setDocumentPartitioning(TPartitions.T_PARTITION_TYPE);
DefaultDamagerRepairer dr;
// DefaultDamagerRepairer implements both IPresentationDamager, IPresentationRepairer
// IPresentationDamager::getDamageRegion does not scan, just
// returns the intersection of document event, and partition region
// IPresentationRepairer::createPresentation scans
// gets each token, and sets text attributes according to token
// We need to cover all the content types from FastTPartitionScanner
// Comments have uniform color
commentScanner = new TColoredScanner(colorCache, new RGB(0, 192, 0), SWT.NORMAL);
dr = new DefaultDamagerRepairer(commentScanner);
reconciler.setDamager(dr, TPartitions.T_COMMENT);
reconciler.setRepairer(dr, TPartitions.T_COMMENT);
// Strings have uniform color
stringScanner = new TColoredScanner(colorCache, new RGB(0, 0, 192), SWT.NORMAL);
dr = new DefaultDamagerRepairer(stringScanner);
reconciler.setDamager(dr, TPartitions.T_STRING);
reconciler.setRepairer(dr, TPartitions.T_STRING);
// Default content is code, we need syntax highlighting
codeScanner = new TCodeScanner(colorCache);
dr = new DefaultDamagerRepairer(codeScanner);
reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
}
return reconciler;
}
Note the comment (code was imitated from the PyDev project): the createPresentation() method in the repairer is the one that will use my scanners to do the syntax highlighting. However, breakpoints indicate that we never hit createPresentation(). I think this is because of the original problem: Eclipse is not calling my code due to the extension points set up in my plugin.xml. Rather, my editor is now being created in my own code that handles the new command.
As a result, I am thinking of calling the repairer's createPresentation() method directly from my partition scanner. The partition scanner IS called by Eclipse every time a single character of the file is changed during editing. I think I have to force the calling of my syntax highlighting scanners via IPresentationReconciler::createPresentation() because Eclipse does not invoke my editor via my editor extension point.
Not sure how I will ever get beyond this work-around approach, however. Any feedback is appreciated.
|
|
| | |
Goto Forum:
Current Time: Mon Sep 23 13:53:19 GMT 2024
Powered by FUDForum. Page generated in 0.04865 seconds
|