This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
Summary: | Setting kit changes most active document | ||
---|---|---|---|
Product: | editor | Reporter: | Petr Hrebejk <phrebejk> |
Component: | -- Other -- | Assignee: | apireviews <apireviews> |
Status: | RESOLVED FIXED | ||
Severity: | blocker | CC: | dbalek, err, mmetelka, sandipchitale |
Priority: | P2 | Keywords: | API, API_REVIEW_FAST |
Version: | 6.x | ||
Hardware: | All | ||
OS: | All | ||
Issue Type: | DEFECT | Exception Reporter: | |
Attachments: | Diff of the EditorRegistry addition and its use in CompletionImpl |
Description
Petr Hrebejk
2007-05-03 13:24:19 UTC
Ok, I think can see the problem, its solution is probably not going to be that simple. First, please stop using JEP.setContentType (see http://editor.netbeans.org/doc/editor-kit-registry.html). The right way to go about that is basically JEP.setEditorKit(CloneableEditorSupport.getEditorKit("text/x-java")); The problem is that calling JEP.setEditorKit recreates and resets a document on the JEP, which in turn means that the Registry changes the active document. I'm not sure what the rules for code completion are, but perhaps it should stop using Registry and track only the real editors by using Utilities.actionsGlobalLookup().lookup(EditorCookie.class). Regarding the Registry, its API has never been properly defined and we should either deprecate it and stop using it, if we can cover all the existing usecases by something else (eg. U.aGL) or design something new that would cover them. There was a discussion about this going on on @nbdev some time ago. There is a usecase for word-matching to match a word in all the opened documents in a LRU manner. I see no way how to cover this by U.aGL(). I agree that the Registry should only react to focus changes. It would IMHO be much cleaner. I will attempt to do some rework to allow that. I'm already working on this. *** Issue 104406 has been marked as a duplicate of this issue. *** I've created a new EditorRegistry in editor/lib2's API. I've looked at the current usage of the old o.n.editor.Registry and it seems that it's only necessary to 1) Get currently focused and last focused text components. E.g. for code completion. 2) Get list of all registered text components in MRU order for word-match. 3) Allow explicit registrations of text components. We do not want to have all the JTextField etc. in the registry. The EditorRegistry contains JTextComponent lastFocusedComponent() - a registered component that had (or still has) focus. JTextComponent focusedComponent() - a lastFocusedComponent() if it still has focus or null otherwise. List<JTextComponent> componentList() - a list of all registered components in MRU-focused order. EditorRegistry fires PropertyChangeEvent for the following properties: "focusGained" - when a registered text component gets a focus (it gets moved to the head of the component list). "focusLost" - when a registered text component has lost a focus. Not all clients will react to this event. "focusedDocument" - when "document" property of registered and focused JTextComponent changes. The impl is IMHO simple and straightforward with tests coverage and logging. I had also considered updates to the old Registry but there are differences in working and firing so I've ended up with a new EditorRegistry class. BTW a nice side-effect is that there should be less firing that with the old Registry because e.g. the initial document switches in an JEditorPane: PlainDocument -> empty "right" document (e.g. JavaDocument) -> loaded JavaDocument is eliminated and there is just a single "focusGained" that comes after all that docs switching. I have rewritten a completion to use the new EditorRegistry and so the original problem is fixed by that. I would then rewrite the rest of the occurrences. Attaching diff. Created attachment 43170 [details]
Diff of the EditorRegistry addition and its use in CompletionImpl
Asking for fasttrack review. It's looking good, certainly much better that the old one :). Just a few small things. VS1: Make EditorRegistry final, with private constructor. VS2: Should not componentList return List<? extends JTextComponent> ? VS3: Does the register method have to be public? Who is supposed to call it? Note current discussion on dev@openide about this issue - is this going to make it for 6.0? ad VS1, VS2: obviously done, thanks. ad VS3: thanks to impl dep. editor lib->editor lib2 I can make it non-public since the only present client is BaseTextUI. We can possibly publicize later if other clients show up. Definitely planned for 6.0. I would like to commit sooner, possibly tomorrow. Fixed. Checking in libsrc/org/netbeans/editor/BaseTextUI.java; /cvs/editor/libsrc/org/netbeans/editor/BaseTextUI.java,v <-- BaseTextUI.java new revision: 1.87; previous revision: 1.86 done RCS file: /cvs/editor/lib2/src/org/netbeans/modules/editor/lib2/EditorApiPackageAccessor.java,v done Checking in lib2/src/org/netbeans/modules/editor/lib2/EditorApiPackageAccessor.java; /cvs/editor/lib2/src/org/netbeans/modules/editor/lib2/EditorApiPackageAccessor.java,v <-- EditorApiPackageAccessor.java initial revision: 1.1 done Checking in completion/nbproject/project.xml; /cvs/editor/completion/nbproject/project.xml,v <-- project.xml new revision: 1.5; previous revision: 1.4 done RCS file: /cvs/editor/lib2/src/org/netbeans/api/editor/EditorRegistry.java,v done Checking in lib2/src/org/netbeans/api/editor/EditorRegistry.java; /cvs/editor/lib2/src/org/netbeans/api/editor/EditorRegistry.java,v <-- EditorRegistry.java initial revision: 1.1 done Checking in lib2/nbproject/project.properties; /cvs/editor/lib2/nbproject/project.properties,v <-- project.properties new revision: 1.5; previous revision: 1.4 done Checking in lib2/nbproject/project.xml; /cvs/editor/lib2/nbproject/project.xml,v <-- project.xml new revision: 1.4; previous revision: 1.3 done RCS file: /cvs/editor/lib2/test/unit/src/org/netbeans/api/editor/EditorRegistryTest.java,v done Checking in lib2/test/unit/src/org/netbeans/api/editor/EditorRegistryTest.java; /cvs/editor/lib2/test/unit/src/org/netbeans/api/editor/EditorRegistryTest.java,v <-- EditorRegistryTest.java initial revision: 1.1 done Checking in completion/src/org/netbeans/modules/editor/completion/CompletionImpl.java; /cvs/editor/completion/src/org/netbeans/modules/editor/completion/CompletionImpl.java,v <-- CompletionImpl.java new revision: 1.71; previous revision: 1.70 done Checking in lib2/apichanges.xml; /cvs/editor/lib2/apichanges.xml,v <-- apichanges.xml new revision: 1.4; previous revision: 1.3 |