Skip to content

Commit

Permalink
Added ability to add tooltips to completions
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Ainsley committed Oct 12, 2014
1 parent efc6e93 commit 81dd362
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 14 deletions.
Expand Up @@ -59,6 +59,11 @@ public class AceCompletionSnippet extends AceCompletion {
* The score is the value assigned to the autocompletion option. Scores with a higher value will appear closer to the top. Items with an identical score are sorted alphbetically by caption in the drop down.
*/
private final int score;

/**
* The score is the value assigned to the autocompletion option. Scores with a higher value will appear closer to the top. Items with an identical score are sorted alphbetically by caption in the drop down.
*/
private final String tooltip;


/**
Expand All @@ -72,10 +77,11 @@ public class AceCompletionSnippet extends AceCompletion {
* @param meta "meta" means the category of the substitution (this appears right aligned on the dropdown list). This is freeform description and can contain anything but typically a very short category description (9 chars or less) such as "function" or "param" or "template".
* @param score The score is the value assigned to the autocompletion option. Scores with a higher value will appear closer to the top. Items with an identical score are sorted alphbetically by caption in the drop down.
*/
public AceCompletionSnippet(String caption, AceCompletionSnippetSegment[] snippetSegments, String meta, int score) {
public AceCompletionSnippet(String caption, AceCompletionSnippetSegment[] snippetSegments, String meta, String htmlTooltip, int score) {
this.caption = caption;
this.score = score;
this.meta = meta;
this.tooltip = htmlTooltip;

StringBuilder sb = new StringBuilder();

Expand Down Expand Up @@ -105,11 +111,12 @@ public AceCompletionSnippet(String caption, AceCompletionSnippetSegment[] snippe
* @param meta "meta" means the category of the substitution (this appears right aligned on the dropdown list). This is freeform description and can contain anything but typically a very short category description (9 chars or less) such as "function" or "param" or "template".
* @param score The score is the value assigned to the autocompletion option. Scores with a higher value will appear closer to the top. Items with an identical score are sorted alphbetically by caption in the drop down.
*/
public AceCompletionSnippet(String caption, String snippet, int score, String meta) {
public AceCompletionSnippet(String caption, String snippet, int score, String meta, String htmlTooltip) {
this.caption = caption;
this.score = score;
this.meta = meta;
this.snippet = snippet;
this.tooltip = htmlTooltip;
}


Expand All @@ -127,7 +134,8 @@ native JavaScriptObject toJsObject() /*-{
caption: this.@edu.ycp.cs.dh.acegwt.client.ace.AceCompletionSnippet::caption,
snippet: this.@edu.ycp.cs.dh.acegwt.client.ace.AceCompletionSnippet::snippet,
score: this.@edu.ycp.cs.dh.acegwt.client.ace.AceCompletionSnippet::score,
meta: this.@edu.ycp.cs.dh.acegwt.client.ace.AceCompletionSnippet::meta
meta: this.@edu.ycp.cs.dh.acegwt.client.ace.AceCompletionSnippet::meta,
aceGwtHtmlTooltip: this.@edu.ycp.cs.dh.acegwt.client.ace.AceCompletionSnippet::tooltip
};
}-*/;
}
46 changes: 40 additions & 6 deletions AceGWT/src/edu/ycp/cs/dh/acegwt/client/ace/AceCompletionValue.java
Expand Up @@ -53,6 +53,11 @@ public class AceCompletionValue extends AceCompletion {
*/
private final int score;

/**
* The score is the value assigned to the autocompletion option. Scores with a higher value will appear closer to the top. Items with an identical score are sorted alphbetically by caption in the drop down.
*/
private final String tooltip;

/**
* Constructor.
*
Expand All @@ -62,9 +67,27 @@ public class AceCompletionValue extends AceCompletion {
* @param score The score is the value assigned to the autocompletion option. Scores with a higher value will appear closer to the top. Items with an identical score are sorted alphbetically by caption in the drop down.
*/
public AceCompletionValue(String name, String value, String meta, int score) {
this.caption = name;
this.value = value;
this.meta = meta;
this.tooltip = null;
this.score = score;
}

/**
* Constructor.
*
* @param caption The caption of the completion (this is the left aligned autocompletion name on the left side of items in the dropdown box. If only a single completion is available in a context, then the caption will not be seen.
* @param value The text value of the completion. This does not need to be escaped.
* @param meta "meta" means the category of the substitution (this appears right aligned on the dropdown list). This is freeform description and can contain anything but typically a very short category description (9 chars or less) such as "function" or "param" or "template".
* @param tooltip "tooltip" is an escaped html tooltip to be displayed when the completion option is displayed, this can be null.
* @param score The score is the value assigned to the autocompletion option. Scores with a higher value will appear closer to the top. Items with an identical score are sorted alphbetically by caption in the drop down.
*/
public AceCompletionValue(String name, String value, String meta, String tooltip, int score) {
this.caption = name;
this.value = value;
this.score = score;
this.tooltip = tooltip;
this.meta = meta;
}

Expand All @@ -75,11 +98,22 @@ public AceCompletionValue(String name, String value, String meta, int score) {
* @return native JS object
*/
native JavaScriptObject toJsObject() /*-{
return {
caption: this.@edu.ycp.cs.dh.acegwt.client.ace.AceCompletionValue::caption,
value: this.@edu.ycp.cs.dh.acegwt.client.ace.AceCompletionValue::value,
score: this.@edu.ycp.cs.dh.acegwt.client.ace.AceCompletionValue::score,
meta: this.@edu.ycp.cs.dh.acegwt.client.ace.AceCompletionValue::meta
};
if (this.@edu.ycp.cs.dh.acegwt.client.ace.AceCompletionValue::tooltip != null) {
return {
caption: this.@edu.ycp.cs.dh.acegwt.client.ace.AceCompletionValue::caption,
value: this.@edu.ycp.cs.dh.acegwt.client.ace.AceCompletionValue::value,
score: this.@edu.ycp.cs.dh.acegwt.client.ace.AceCompletionValue::score,
meta: this.@edu.ycp.cs.dh.acegwt.client.ace.AceCompletionValue::meta,
aceGwtHtmlTooltip: this.@edu.ycp.cs.dh.acegwt.client.ace.AceCompletionSnippet::tooltip
};
} else {
return {
caption: this.@edu.ycp.cs.dh.acegwt.client.ace.AceCompletionValue::caption,
value: this.@edu.ycp.cs.dh.acegwt.client.ace.AceCompletionValue::value,
score: this.@edu.ycp.cs.dh.acegwt.client.ace.AceCompletionValue::score,
meta: this.@edu.ycp.cs.dh.acegwt.client.ace.AceCompletionValue::meta
};
}
}-*/;
}
18 changes: 13 additions & 5 deletions AceGWT/src/edu/ycp/cs/dh/acegwt/client/ace/AceEditor.java
Expand Up @@ -197,6 +197,7 @@ public native String getText() /*-{
return editor.getSession().getValue();
}-*/;


/**
* Set the complete text in the editor from a String.
*
Expand Down Expand Up @@ -252,12 +253,12 @@ private AceEditorCursorPosition getCursorPositionImpl(final double row, final do
public int getIndexFromPosition(AceEditorCursorPosition position) {
return getIndexFromPositionImpl(position.toJsObject());
}

private native int getIndexFromPositionImpl(JavaScriptObject jsPosition) /*-{
var editor = this.@edu.ycp.cs.dh.acegwt.client.ace.AceEditor::editor;
return editor.getSession().getDocument().positionToIndex(jsPosition);
}-*/;

/**
* Gets a document position from a supplied zero-based index.
*
Expand All @@ -273,7 +274,6 @@ public native AceEditorCursorPosition getPositionFromIndex(int index) /*-{
);
}-*/;


/**
* Set whether or not soft tabs should be used.
*
Expand Down Expand Up @@ -469,9 +469,11 @@ public native void setAutocompleteEnabled(boolean b) /*-{
*/
public native static void removeAllExistingCompleters() /*-{
var langTools = $wnd.ace.require("ace/ext/language_tools");
langTools.removeCompleters();
langTools.setCompleters([]);
}-*/;



/**
* Add an {@link AceCompletionProvider} to provide
* custom code completions.
Expand All @@ -495,12 +497,18 @@ public native static void addCompletionProvider(AceCompletionProvider provider)
prefix,
callbackWrapper
);
}
},
getDocTooltip: function(item) {
if ( (!item.docHTML) && item.aceGwtHtmlTooltip != null) {
item.docHTML = item.aceGwtHtmlTooltip;
}
}
};
langTools.addCompleter(completer);
}-*/;

private static AceCompletionCallback wrapCompletionCallback(JavaScriptObject jsCallback) {

return new AceCompletionCallbackImpl(jsCallback);
}
}

0 comments on commit 81dd362

Please sign in to comment.