use of org.rstudio.studio.client.workbench.views.source.model.CppCompletion in project rstudio by rstudio.
the class CppCompletionPopupMenu method setCompletions.
public void setCompletions(JsArray<CppCompletion> completions, CommandWithArg<CppCompletion> onSelected) {
// save completions and selectable state
completions_ = completions;
onSelected_ = onSelected;
// clear existing items
updatingMenu_ = true;
menuBar_.clearItems();
// add items (remember first item for programmatic selection)
MenuItem firstItem = null;
for (int i = 0; i < completions.length(); i++) {
final CppCompletion completion = completions.get(i);
SafeHtmlBuilder sb = new SafeHtmlBuilder();
SafeHtmlUtil.appendImage(sb, RES.styles().itemImage(), completion.getIcon());
SafeHtmlUtil.appendSpan(sb, RES.styles().itemName(), completion.getTypedText());
MenuItem menuItem = new MenuItem(sb.toSafeHtml(), new ScheduledCommand() {
@Override
public void execute() {
docDisplay_.setFocus(true);
if (isSelectable())
onSelected_.execute(completion);
}
});
menuItem.addStyleName(RES.styles().itemMenu());
FontSizer.applyNormalFontSize(menuItem);
addItem(menuItem);
if (i == 0)
firstItem = menuItem;
}
updatingMenu_ = false;
// select first item
if (isSelectable() && (firstItem != null))
selectItem(firstItem);
if (completions.length() > 0) {
showMenu();
} else {
setVisible(false);
if (toolTip_ != null)
toolTip_.setVisible(false);
}
}
use of org.rstudio.studio.client.workbench.views.source.model.CppCompletion in project rstudio by rstudio.
the class CppCompletionRequest method updateUI.
public void updateUI(boolean autoAccept) {
if (invalidationToken_.isInvalid())
return;
// the request completes)
if (completions_ == null)
return;
// discover text already entered
String userTypedText = getUserTypedText();
// build list of entries (filter on text already entered)
JsArray<CppCompletion> filtered = JsArray.createArray().cast();
for (int i = 0; i < completions_.length(); i++) {
CppCompletion completion = completions_.get(i);
String typedText = completion.getTypedText();
if ((userTypedText.length() == 0) || typedText.startsWith(userTypedText)) {
// compiler generated assignments, etc.
if (completionPosition_.getScope() == CompletionPosition.Scope.Member) {
if (completion.getType() == CppCompletion.VARIABLE || (completion.getType() == CppCompletion.FUNCTION && !typedText.startsWith("operator="))) {
filtered.push(completion);
}
} else {
filtered.push(completion);
}
}
}
// add in snippets if they are enabled and this is a global scope
if (uiPrefs_.enableSnippets().getValue() && (completionPosition_.getScope() == CompletionPosition.Scope.Global)) {
ArrayList<String> snippets = snippets_.getAvailableSnippets();
for (String snippet : snippets) if (snippet.startsWith(userTypedText)) {
String content = snippets_.getSnippet(snippet).getContent();
content = content.replace("\t", " ");
filtered.unshift(CppCompletion.createSnippetCompletion(snippet, content));
}
}
// check for no hits on explicit request
if ((filtered.length() == 0) && explicit_) {
showCompletionPopup("(No matches)");
} else // check for auto-accept
if ((filtered.length() == 1) && autoAccept && explicit_) {
applyValue(filtered.get(0));
} else // check for one completion that's already present
if (filtered.length() == 1 && filtered.get(0).getTypedText() == getUserTypedText() && filtered.get(0).getType() != CppCompletion.SNIPPET) {
terminate();
} else {
showCompletionPopup(filtered);
}
}
Aggregations