Archive for October, 2009

Markup Language Enhancements in RSTA

Tuesday, October 13th, 2009

I decided to give the markup languages (XML, HTML, JSP and PHP) a little love  in RSyntaxTextArea.  Their syntax is so structured it should be easier to support more advanced features with them than with more abstract languages.

The first thing I did was “soften” the default color scheme used for markup languages.  Here’s how an HTML file looks out-of-the-box now:

Softer color scheme

Softer color scheme

Note that element names are now differentiated from attributes.  I may end up softening the string color as well, as that’s still a little obnoxious.

With things looking nicer, I decided to implement a new time-saving feature.  Now, typing “</” in an XML file will automatically complete the closing tag with the correct tag name.  e.g. typing:

<foo></

will type the following into the editor:

<foo></foo>

A welcome time-saver.  This feature can also be toggled on with HTML, JSP and PHP, but by default it is off, due to HTML often accepting unclosed tags such as <p>, <hr>, etc., which would mess up close-tag completions.

Going one step further from completing closing tags, I also used the AutoComplete library to add auto-completion for HTML, JSP and PHP.  The completion is very smart:

  • It only offers tag names as suggestions when you’re at the start of a tag (e.g. “<” or “<ht”).
  • If you’ve already typed a tag name, only the attributes valid for that tag will be offered as completion choices until the tag is closed.
  • No completion choices are offered if it doesn’t make sense (you’re in a comment, a string literal, in embedded JavaScript, etc.).
Auto-completing an HTML tag

Auto-completing an HTML tag

Intelligent attribute completion

Intelligent attribute completion

HTML/JSP/PHP code completion will definitely be integrated into the next RText release, but I’d like to figure out a way to release it alongside the standard AutoComplete library.  I don’t think it should be a part of the main library itself (why bloat the library with completion support for a language that might not be needed by all users?), but perhaps some kind of additional jar, that includes pre-built support for certain languages such as this?

If anybody would like to help filling in the gaps in the description for HTML tags and their attributes for this HTML code completion, get in contact with me.  I scraped some basic info off the web, but it’s really lacking.  You would of course receive credit for your input.

Breadcrumb Bar Nearly Done

Sunday, October 4th, 2009

The breadcrumb bar I blogged about earlier is nearly done.  I managed to mimic the behavior seen in Vista’s breadcrumb bars, clicking outside of the “button” area turns the breadcrumb bar into a text field for manually typing a file path.  Even better, it offers suggestions as you type!  Here’s how it’s looking in RText’s file chooser dialog:

Using the Breadcrumb Bar

Using the Breadcrumb Bar

Morphing into text field with autocomplete

Morphing into text field with autocomplete

This is much more powerful than the combo box with the directory hierarchy that was there previously.  Note that if too many folders are in a directory to be listed in a single menu, there are arrows at the top and bottom of the menu, allowing you to scroll through the entire list.  The menu also responds to the scroll wheel on the mouse.  I’ve seen this behavior on OS X, on a Macbook where screen space is limited (or you just don’t want a menu to get too long).

This component should honor RTL locales, as well as look good in all LookAndFeels (tested in all the standard ones, including Nimbus, which, as always, took a little work to get looking good).  As always, check it out from RText’s Subversion repository if you want to see how it is implemented.