ErrorStrip

Questions on using RSyntaxTextArea should go here.

Moderator: robert

ErrorStrip

Postby ralf » Tue Mar 27, 2012 1:17 pm

I'm wondering if there is any chance to set a notice in the ErrorStrip programmatically? I'd like to develop a regular expression editor where it's possible to jump from one match to another by clicking the notice in the ErrorStrip. I looked into the SpellChecker demo, where the ErrorStrip is used, but no notice markers are shown.
Any help or some example code would be appreciated.
ralf
 

Re: ErrorStrip

Postby robert » Sun Apr 15, 2012 4:49 am

Currently, to add items to the ErrorStrip, you must create an implementation of org.fife.ui.rsyntaxtextarea.parser.Parser (see also the AbstractParser base class in the same package) and add it to your RSTA via textArea.addParser(). Any ParserNotices that the Parser creates that are at or above the ErrorStrip's levelThreshold (defaults to ParserNotice.WARNING) will get an item added to the ErrorStrip.

Does this technique work for you? The idea is that registering a parser allows you to be notified when the editor's content has been modified, so you just care about doing the parsing, not figuring out when you need to parse.

I'll update ErrorStrip's Javadoc for the next release to better explain its relationship to Parsers and how to use it.

Let me know if you'd still prefer an API to manually add markers to the ErrorStrip and why the Parser API wouldn't work in your scenario.
User avatar
robert
 
Posts: 797
Joined: Sat May 10, 2008 5:16 pm

Re: ErrorStrip

Postby ralf » Wed Apr 25, 2012 2:40 pm

Thanks for the information. I implemented a small parser that subclasses AbstractParser and adds ErrorStrips to RSTA as follows:
Code: Select all
public ParseResult parse(RSyntaxDocument doc, String style) {
    ParseResult result = new DefaultParseResult(this);
    DefaultParserNotice notice = new DefaultParserNotice(this, "Match", iLine, pm.start(), pm.end() - pm.start());
    result.getNotices().add(notice);
}


There are some questions left:
- When is the parser called (only after a document has been changed)?
- Is there a possibility to call the parser programmatically?
- How can the ErrorStrip be cleared?
ralf
 

Re: ErrorStrip

Postby robert » Fri Apr 27, 2012 1:25 am

- When is the parser called (only after a document has been changed)?


Yes, it's called after any edit, after a short delay.

- Is there a possibility to call the parser programmatically?


Yes, but you have to either keep a reference to the Parser you want to re-run, or be able to identify it somehow. See the RSyntaxTextArea methods:

Code: Select all
int getParserCount();
Parser getParser(int index);
void forceReparsing(int parserIndex);
boolean forceReparsing(Parser parser);


The last two methods result in an immediate reparsing (no delay). That last method won't do anything if the Parser specified isn't actually installed on the text area.

- How can the ErrorStrip be cleared?


I don't think so, short of removing all Parsers (textArea.clearParsers()) and re-adding them. Would having a method to remove all notices in the ErrorStrip be useful? Would the next edit to the document re-add all of them, or are you looking for some sort of "don't show anything for now" flag?
User avatar
robert
 
Posts: 797
Joined: Sat May 10, 2008 5:16 pm

Re: ErrorStrip

Postby ralf » Mon May 07, 2012 7:35 am

Many thanks, "reparsing" was the trick. Everything works now as expected.
ralf
 


Return to Help

Who is online

Users browsing this forum: No registered users and 2 guests

cron