Search in sources :

Example 1 with MenuItem

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("&nbsp;&nbsp;&nbsp;");
            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);
    }
}
Also used : Command(com.google.gwt.user.client.Command) MenuItem(com.google.gwt.user.client.ui.MenuItem) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder) SlideNavigationItem(org.rstudio.studio.client.common.presentation.model.SlideNavigationItem)

Example 2 with MenuItem

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));
    }
}
Also used : ToolbarPopupMenu(org.rstudio.core.client.widget.ToolbarPopupMenu) ScrollableToolbarPopupMenu(org.rstudio.core.client.widget.ScrollableToolbarPopupMenu) Scheduler(com.google.gwt.core.client.Scheduler) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) MenuItem(com.google.gwt.user.client.ui.MenuItem) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder)

Example 3 with MenuItem

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();
}
Also used : MenuItem(com.google.gwt.user.client.ui.MenuItem)

Example 4 with MenuItem

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);
}
Also used : AppCommand(org.rstudio.core.client.command.AppCommand) SharedProjectDetails(org.rstudio.studio.client.projects.model.SharedProjectDetails) MenuItem(com.google.gwt.user.client.ui.MenuItem)

Example 5 with MenuItem

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));
            }
        }
    });
}
Also used : UIObject(com.google.gwt.user.client.ui.UIObject) JsArray(com.google.gwt.core.client.JsArray) StatusBarPopupMenu(org.rstudio.studio.client.workbench.views.source.editors.text.status.StatusBarPopupMenu) MenuItem(com.google.gwt.user.client.ui.MenuItem) JsArrayString(com.google.gwt.core.client.JsArrayString) TextFileType(org.rstudio.studio.client.common.filetypes.TextFileType) StatusBarPopupRequest(org.rstudio.studio.client.workbench.views.source.editors.text.status.StatusBarPopupRequest)

Aggregations

MenuItem (com.google.gwt.user.client.ui.MenuItem)24 Command (com.google.gwt.user.client.Command)8 SafeHtmlBuilder (com.google.gwt.safehtml.shared.SafeHtmlBuilder)7 AppCommand (org.rstudio.core.client.command.AppCommand)7 MenuBar (com.google.gwt.user.client.ui.MenuBar)5 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)4 Test (org.junit.Test)4 JsArrayString (com.google.gwt.core.client.JsArrayString)3 RepeatingCommand (com.google.gwt.core.client.Scheduler.RepeatingCommand)3 ToolbarPopupMenu (org.rstudio.core.client.widget.ToolbarPopupMenu)3 StatusBarPopupMenu (org.rstudio.studio.client.workbench.views.source.editors.text.status.StatusBarPopupMenu)3 Scheduler (com.google.gwt.core.client.Scheduler)2 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)2 Event (com.google.gwt.user.client.Event)2 PositionCallback (com.google.gwt.user.client.ui.PopupPanel.PositionCallback)2 SlideNavigationItem (org.rstudio.studio.client.common.presentation.model.SlideNavigationItem)2 StatusBarPopupRequest (org.rstudio.studio.client.workbench.views.source.editors.text.status.StatusBarPopupRequest)2 JsArray (com.google.gwt.core.client.JsArray)1 Label (com.google.gwt.user.client.ui.Label)1 UIObject (com.google.gwt.user.client.ui.UIObject)1