Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 389212

Summary: Allow content assist plugins to provide styling for proposals
Product: [ECD] Orion Reporter: Andrew Eisenberg <andrew.eisenberg>
Component: EditorAssignee: Project Inbox <orion.editor-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: antonm, mamacdon, Silenio_Quarti, simon_kaegi, susan
Version: 0.5   
Target Milestone: 1.0 M2   
Hardware: PC   
OS: Mac OS X   
Whiteboard:

Description Andrew Eisenberg CLA 2012-09-11 00:12:05 EDT
We would like to allow content assistants to have the ability to style individual proposals.  This would greatly help in describing how the proposal was computed and which one is emphasized.

For example, constructors could be greyed out when not in a context of 'new'.

We may even want to provide the ability to include icons for each proposal.

I can think of several ways of doing this:

1. Allow content assist plugins to include html as part of the display string (disallowing obvious bad ones, like <script>).
2. Allow content assist plugins to set the css for the proposal (through a style tag or a class name)
3. Allow content assist plugins to set a list of css class names for the entire proposal
4. Allow content assist plugins to choose from a pre-set list of styles (eg- emphasized, deemphasize, ...).
 
Now comments on each of these:

1. Would be the easiest to implement and provide the plugin dev with the most flexibility. I particularly like the easy way to add multiple styles to a single proposal, but I am concerned that there are security risks involved.  Are there?  This would be html provided by a plugin, but is rendered in the core orion iframe.
2. This provides a little less flexibility but still can allow some nice looking proposals. However, I am still concerned about security risks (eg- could malicious proposals try to include bad background images???).  
3. Getting safer, but then orion needs to provide a fixed set of css class names that it allows.  Not very flexible.
4. Even less flexible, but very safe.

Any comments or suggestions of better ways to go?
Comment 1 Susan McCourt CLA 2012-09-11 11:31:19 EDT
(In reply to comment #0)
> Any comments or suggestions of better ways to go?

Great summary of the possibilities.  In the past, we've been very reticent to do #1 and #2 for security reasons.  Simon can comment further, he has been very strongly conservative on this.  I'm not clear on proposal #3 how the class names would get defined.  Would the plugin have to presume to use classes Orion already knows about?  If so then that's not really better than #4.

I like the idea of #4 but along with having semantic names for the kinds of styles, we could potentially expose those styles in the editor themes, so that end users would have some amount of control over how these proposals appeared.

cc'ing Simon and Anton, they might have thoughts on this...
Comment 2 Andrew Eisenberg CLA 2012-09-12 14:09:41 EDT
Thanks for the feedback, Susan.

One of the things that I wanted to do was to apply different styles to different parts of the proposal.  In the Java editor in Eclipse you can see that the declaring type is styled differently from the method/field name (for example).

This feature is less important to me, but going with #3 or #4 would not allow selective styling (and I agree that #3 and #4 are really the same thing).

As a first pass, I will hard-code a few content assist style classes.  And then we can think about selective styling.
Comment 3 Susan McCourt CLA 2012-09-13 16:42:08 EDT
Andrew, you probably already know this, but there is a similar concept in the outliner, where an outliner can give class info (but it just applies to the entire item).

http://wiki.eclipse.org/Orion/Documentation/Developer_Guide/Plugging_into_the_editor#orion.edit.outliner
Comment 4 Andrew Eisenberg CLA 2012-09-19 16:21:29 EDT
Commit is pushed.  Here is link:

http://git.eclipse.org/c/orion/org.eclipse.orion.client.git/commit/?id=58cfe48e3a97134204d7daddf9a89f6029587a6d

In the end, I went with the following styles:

    hr : not really a style, but designates that the proposal should be displayed as a <hr/> in the panel.  hr proposals cannot be selected using the up/down arrow keys.
    emphasis : display the proposal in bold
    noemphasis : displays proposal in grey with a colored background
    dfault : non-specified style.  Using dfault to avoid using a JS keyword

These styles correspond to new css classes in ide.css named proposal-hr, proposal-emphasis, proposal-noemphasis, proposal-default respectively.

Now, if you want to add a styling to your proposal object, simply do:

    proposal.style = emphasis

I am happy to change any of the existing styles or add new ones as needed.

I will update the docs to include the new changes here: http://wiki.eclipse.org/Orion/Documentation/Developer_Guide/Plugging_into_the_editor#orion.edit.contentAssist