use of org.rstudio.studio.client.workbench.views.source.editors.text.status.StatusBarPopupRequest in project rstudio by rstudio.
the class TextEditingTarget method initStatusBar.
private void initStatusBar() {
statusBar_ = view_.getStatusBar();
docDisplay_.addCursorChangedHandler(new CursorChangedHandler() {
public void onCursorChanged(CursorChangedEvent event) {
updateStatusBarPosition();
if (docDisplay_.isScopeTreeReady(event.getPosition().getRow()))
updateCurrentScope();
}
});
updateStatusBarPosition();
updateStatusBarLanguage();
// build file type menu dynamically (so it can change according
// to whether e.g. knitr is installed)
statusBar_.getLanguage().addMouseDownHandler(new MouseDownHandler() {
@Override
public void onMouseDown(MouseDownEvent event) {
// build menu with all file types - also track whether we need
// to add the current type (may be the case for types which we
// support but don't want to expose on the menu -- e.g. Rmd
// files when knitr isn't installed)
boolean addCurrentType = true;
final StatusBarPopupMenu menu = new StatusBarPopupMenu();
TextFileType[] fileTypes = fileTypeCommands_.statusBarFileTypes();
for (TextFileType type : fileTypes) {
menu.addItem(createMenuItemForType(type));
if (addCurrentType && type.equals(fileType_))
addCurrentType = false;
}
// add the current type if isn't on the menu
if (addCurrentType)
menu.addItem(createMenuItemForType(fileType_));
// show the menu
menu.showRelativeToUpward((UIObject) statusBar_.getLanguage(), true);
}
});
statusBar_.getScope().addMouseDownHandler(new MouseDownHandler() {
public void onMouseDown(MouseDownEvent event) {
// Unlike the other status bar elements, the function outliner
// needs its menu built on demand
JsArray<Scope> tree = docDisplay_.getScopeTree();
final StatusBarPopupMenu menu = new StatusBarPopupMenu();
MenuItem defaultItem = null;
if (fileType_.isRpres()) {
String path = docUpdateSentinel_.getPath();
if (path != null) {
presentationHelper_.buildSlideMenu(docUpdateSentinel_.getPath(), dirtyState_.getValue(), TextEditingTarget.this, new CommandWithArg<StatusBarPopupRequest>() {
@Override
public void execute(StatusBarPopupRequest request) {
showStatusBarPopupMenu(request);
}
});
}
} else {
defaultItem = addFunctionsToMenu(menu, tree, "", docDisplay_.getCurrentScope(), true);
showStatusBarPopupMenu(new StatusBarPopupRequest(menu, defaultItem));
}
}
});
}
use of org.rstudio.studio.client.workbench.views.source.editors.text.status.StatusBarPopupRequest in project rstudio by rstudio.
the class TextEditingTargetPresentationHelper method buildSlideMenu.
public void buildSlideMenu(final String path, boolean isDirty, final EditingTarget editor, final CommandWithArg<StatusBarPopupRequest> onCompleted) {
// rpc response handler
SimpleRequestCallback<SlideNavigation> requestCallback = new SimpleRequestCallback<SlideNavigation>() {
@Override
public void onResponseReceived(SlideNavigation slideNavigation) {
// create the menu and make sure we have some slides to return
StatusBarPopupMenu menu = new StatusBarPopupMenu();
if (slideNavigation.getTotalSlides() == 0) {
onCompleted.execute(new StatusBarPopupRequest(menu, null));
return;
}
MenuItem defaultMenuItem = null;
int length = slideNavigation.getItems().length();
for (int i = 0; i < length; i++) {
SlideNavigationItem item = slideNavigation.getItems().get(i);
String title = item.getTitle();
if (StringUtil.isNullOrEmpty(title))
title = "(Untitled Slide)";
StringBuilder indentBuilder = new StringBuilder();
for (int level = 0; level < item.getIndent(); level++) indentBuilder.append(" ");
SafeHtmlBuilder labelBuilder = new SafeHtmlBuilder();
labelBuilder.appendHtmlConstant(indentBuilder.toString());
labelBuilder.appendEscaped(title);
final int targetSlide = i;
final MenuItem menuItem = new MenuItem(labelBuilder.toSafeHtml(), new Command() {
public void execute() {
navigateToSlide(editor, targetSlide);
}
});
menu.addItem(menuItem);
// see if this is the default menu item
if (defaultMenuItem == null && item.getLine() >= (docDisplay_.getSelectionStart().getRow())) {
defaultMenuItem = menuItem;
}
}
StatusBarPopupRequest request = new StatusBarPopupRequest(menu, defaultMenuItem);
onCompleted.execute(request);
}
};
// send code over the wire if we are dirty
if (isDirty) {
server_.getSlideNavigationForCode(docDisplay_.getCode(), FileSystemItem.createFile(path).getParentPathString(), requestCallback);
} else {
server_.getSlideNavigationForFile(path, requestCallback);
}
}
Aggregations