Re: [Graymail] How to implement editor-fold in netbeans editor
Andreas Stefik <[email protected]>
| Newsgroups | gmane.comp.java.netbeans.modules.openide.devel |
|---|---|
| Message-ID | <CABiHOJkgr+h6UJZ8sQwu33+6vLs8d5Qc-7ZrxxkevCvZzx2oKQ@mail.gmail.com> |
There are many ways to skin a cat. With code folding, I prefer the approach Geertjan used in the python module, as I find it easier to understand. First, you make a structure scanner: https://github.com/GeertjanWielenga/Python4NetBeans/blob/master/PythonEditor/src/org/netbeans/modules/python/editor/PythonLanguage.java https://github.com/GeertjanWielenga/Python4NetBeans/blob/master/PythonEditor/src/org/netbeans/modules/python/editor/PythonStructureScanner.java Then, you implement your structure items: https://github.com/GeertjanWielenga/Python4NetBeans/blob/master/PythonEditor/src/org/netbeans/modules/python/editor/PythonStructureItem.java The benefit is that you get code folding AND navigator support, plus a couple other minor UI features here and there, all of which integrate really nicely. I've done it the fold manager based approach as well, but to my eyes nowadays, I tend to prefer this one. Here's how we do it on Quorum 4 nowadays (which isn't out yet), for good or ill: https://bitbucket.org/stefika/quorum-language/src/4c258a2018e86dced227c804537bf1415652965d/IDE/Sodbeans/Quorum/src/org/quorum/language/QuorumStructureScanner.java?at=hints&fileviewer=file-view-default Then you need a fold type provider: https://bitbucket.org/stefika/quorum-language/src/4c258a2018e86dced227c804537bf1415652965d/IDE/Sodbeans/Quorum/src/org/quorum/language/QuorumFoldTypeProvider.java?at=hints&fileviewer=file-view-default Make sure you don't miss that annotation. @MimeRegistration(mimeType = "text/x-quorum", service = FoldTypeProvider.class, position = 1000) Anyway, like I said, there are lots of ways to do this. Just thought I would provide a different approach, if you weren't aware of it. Stefik On Fri, Mar 11, 2016 at 2:58 PM, Svata Dedic <[email protected]> wrote: > You don't need to implement the FoldManager yourself; there's a stock > implementation which recognizes <editor-fold> pseudo-tags in comment > tokens for you. > > You need to register for your MIME type > (Editors/text/x-whatever/FoldManager) something like: > > <file name="CustomFoldManager.instance"> > <attr name="instanceOf" > stringvalue="org.netbeans.spi.editor.fold.FoldManagerFactory"/> > <attr name="instanceCreate" > > methodvalue="org.netbeans.api.editor.fold.FoldingSupport.userFoldManagerFactory"/> > </file> > > If primaryCategory() of comment token IDs produced by your lexer start > with "comment", you're set up. Otherwise you need to pass "tokenId" > attribute to the instance with your comment's primaryCategory prefix. > > -S. > > Dne 10.3.2016 v 17:20 Volodymyr napsal(a): > > Thanks for your answer. > > > > I have the FoldManager implemented, but cannot figure out this exact > > folding. I suppose I have to implement two new tokens two match the > > opening and closing of <editor-fold>. But which type FoldType it has to > > be, USER? It looks really great in Java Editor, I want it to look the > > same)). > > > > Thanks. > > > > 10 березня 2016, 16:29:19, від "Ingleby, Graeme" > > <[email protected] <mailto:[email protected]>>: > > > > There is a section in this tutorial that shows how to create folds > > for comments, maybe this will help: > > > > > > > > > https://platform.netbeans.org/tutorials/nbm-javacc-parser.html#fold-feature > > > > > > > > > > > > *From:*Volodymyr [mailto:[email protected]] > > *Sent:* Thursday, March 10, 2016 8:20 AM > > *To:* NetBeans support > > *Subject:* [Graymail] [platform-dev] How to implement editor-fold in > > netbeans editor > > > > > > > > Hello, > > > > There is a great functionality in NetBeans, editor-fold, but I > > cannot figure out how to implement its support for my custom > > language. Does anybody know? > > > > Thanks. > > > > // <editor-fold defaultstate="collapsed" desc=" My methods "> > > // </editor-fold> > > > > Regards, > > Volodymyr. > > > >