use of com.google.gwt.user.client.ui.MenuItem in project rstudio by rstudio.
the class SlideNavigationPresenter method onSlideNavigationChanged.
@Override
public void onSlideNavigationChanged(SlideNavigationChangedEvent event) {
slideNavigation_ = event.getNavigation();
SlideNavigationMenu navigationMenu = view_.getNavigationMenu();
navigationMenu.clear();
if (slideNavigation_ != null) {
JsArray<SlideNavigationItem> items = slideNavigation_.getItems();
for (int i = 0; i < items.length(); i++) {
// get slide
final SlideNavigationItem item = items.get(i);
// build html
SafeHtmlBuilder menuHtml = new SafeHtmlBuilder();
for (int j = 0; j < item.getIndent(); j++) menuHtml.appendHtmlConstant(" ");
menuHtml.appendEscaped(item.getTitle());
navigationMenu.addItem(new MenuItem(menuHtml.toSafeHtml(), new Command() {
@Override
public void execute() {
view_.navigate(item.getIndex());
}
}));
}
navigationMenu.setVisible(true);
navigationMenu.setDropDownVisible(slideNavigation_.getItems().length() > 1);
} else {
navigationMenu.setVisible(false);
}
}
use of com.google.gwt.user.client.ui.MenuItem in project rstudio by rstudio.
the class MarkerSetsToolbarButton method updateAvailableMarkerSets.
public void updateAvailableMarkerSets(String[] sets) {
ToolbarPopupMenu menu = getMenu();
menu.clearItems();
for (final String set : sets) {
// command for selection
Scheduler.ScheduledCommand cmd = new Scheduler.ScheduledCommand() {
@Override
public void execute() {
ValueChangeEvent.fire(MarkerSetsToolbarButton.this, set);
}
};
SafeHtml menuHTML = new SafeHtmlBuilder().appendHtmlConstant(set).toSafeHtml();
menu.addItem(new MenuItem(menuHTML, cmd));
}
}
use of com.google.gwt.user.client.ui.MenuItem in project rstudio by rstudio.
the class ToolbarLinkMenu method clearLinks.
public void clearLinks() {
menu_.clearItems();
for (MenuItem mi : pre_) menu_.addItem(mi);
if (pre_.length > 0)
menu_.addSeparator();
if (post_.length > 0)
menu_.addSeparator();
for (MenuItem mi : post_) menu_.addItem(mi);
links_.clear();
}
use of com.google.gwt.user.client.ui.MenuItem in project rstudio by rstudio.
the class ProjectPopupMenu method rebuildMenu.
private void rebuildMenu(final JsArray<SharedProjectDetails> sharedProjects, DynamicPopupMenuCallback callback) {
// clean out existing entries
clearItems();
boolean hasSharedProjects = sharedProjects != null && sharedProjects.length() > 0;
int maxMruEntries = MAX_MRU_ENTRIES;
// shared projects are always shown, and count against the MRU limit
if (hasSharedProjects)
maxMruEntries -= Math.min(sharedProjects.length(), MAX_SHARED_PROJECTS);
addItem(commands_.newProject().createMenuItem(false));
// ensure the menu doesn't get too narrow
addSeparator(225);
addItem(commands_.openProject().createMenuItem(false));
if (Desktop.isDesktop())
addItem(commands_.openProjectInNewWindow().createMenuItem(false));
addItem(commands_.closeProject().createMenuItem(false));
addSeparator();
addItem(commands_.shareProject().createMenuItem(false));
if (hasSharedProjects)
addSeparator("Recent Projects");
else
addSeparator();
// add as many MRU items as is appropriate for our screen size and number
// of shared projects
AppCommand[] mruCommands = new AppCommand[] { commands_.projectMru0(), commands_.projectMru1(), commands_.projectMru2(), commands_.projectMru3(), commands_.projectMru4(), commands_.projectMru5(), commands_.projectMru6(), commands_.projectMru7(), commands_.projectMru8(), commands_.projectMru9(), commands_.projectMru10(), commands_.projectMru11(), commands_.projectMru12(), commands_.projectMru13(), commands_.projectMru14() };
for (int i = 0; i < Math.min(maxMruEntries, mruCommands.length); i++) {
addItem(mruCommands[i].createMenuItem(false));
}
// show shared projects if enabled
if (hasSharedProjects) {
addSeparator("Shared with Me");
for (int i = 0; i < Math.min(sharedProjects.length(), MAX_SHARED_PROJECTS); i++) {
final SharedProjectDetails details = sharedProjects.get(i);
String menuHtml = AppCommand.formatMenuLabel(null, details.getName(), false, null, commands_.openHtmlExternal().getImageResource(), ProjectMRUList.NEW_SESSION_DESC);
addItem(new MenuItem(menuHtml, true, new Scheduler.ScheduledCommand() {
@Override
public void execute() {
ProjectMRUList.openProjectFromMru(events_, details.getProjectFile());
}
}));
}
// displayed, offer a link
if (sharedProjects.length() > MAX_SHARED_PROJECTS) {
addItem(commands_.openSharedProject().createMenuItem(false));
}
}
addSeparator();
addItem(commands_.clearRecentProjects().createMenuItem(false));
addSeparator();
addItem(commands_.projectOptions().createMenuItem(false));
callback.onPopupMenu(this);
}
use of com.google.gwt.user.client.ui.MenuItem 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));
}
}
});
}
Aggregations