Search in sources :

Example 6 with MenuItem

use of com.google.gwt.user.client.ui.MenuItem in project rstudio by rstudio.

the class DocsMenu method setDocs.

public void setDocs(ImageResource[] icons, String[] names, String[] paths) {
    clearItems();
    names_.clear();
    menuItems_.clear();
    // de-duplicate names
    names = deduplicate(names, paths);
    assert icons.length == names.length && names.length == paths.length;
    if (icons.length == 0) {
        addItem(new DisabledMenuItem("(No documents)"));
    }
    for (int i = 0; i < icons.length; i++) {
        String label = AppCommand.formatMenuLabel(icons[i], names[i] + "   ", null);
        final int tabIndex = i;
        MenuItem item = addItem(label, true, new Command() {

            public void execute() {
                if (panel_ != null)
                    panel_.hide(false);
                events_.fireEvent(new SwitchToDocEvent(tabIndex));
            }
        });
        item.setTitle(paths[i]);
        names_.add(names[i]);
        menuItems_.add(item);
    }
}
Also used : DisabledMenuItem(org.rstudio.core.client.command.DisabledMenuItem) AppCommand(org.rstudio.core.client.command.AppCommand) Command(com.google.gwt.user.client.Command) SwitchToDocEvent(org.rstudio.studio.client.workbench.views.source.events.SwitchToDocEvent) MenuItem(com.google.gwt.user.client.ui.MenuItem) DisabledMenuItem(org.rstudio.core.client.command.DisabledMenuItem)

Example 7 with MenuItem

use of com.google.gwt.user.client.ui.MenuItem 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);
    }
}
Also used : ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) MenuItem(com.google.gwt.user.client.ui.MenuItem) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder) CppCompletion(org.rstudio.studio.client.workbench.views.source.model.CppCompletion)

Example 8 with MenuItem

use of com.google.gwt.user.client.ui.MenuItem in project rstudio by rstudio.

the class HistoryBranchToolbarButton method onBeforePopulateMenu.

@Override
protected void onBeforePopulateMenu(ToolbarPopupMenu rootMenu) {
    String label = "(all branches)";
    rootMenu.addItem(new MenuItem(label, new SwitchBranchCommand(label, "--all")));
}
Also used : MenuItem(com.google.gwt.user.client.ui.MenuItem)

Example 9 with MenuItem

use of com.google.gwt.user.client.ui.MenuItem in project rstudio by rstudio.

the class BranchToolbarButton method populateMenu.

private void populateMenu(final ToolbarPopupMenu menu, final Map<String, List<String>> branchMap) {
    MapUtil.forEach(branchMap, new MapUtil.ForEachCommand<String, List<String>>() {

        @Override
        public void execute(final String caption, final List<String> branches) {
            // place commonly-used branches at the top
            Collections.sort(branches, new Comparator<String>() {

                private final String[] specialBranches_ = new String[] { "master", "develop", "trunk" };

                @Override
                public int compare(String o1, String o2) {
                    for (String specialBranch : specialBranches_) {
                        if (o1.endsWith(specialBranch))
                            return -1;
                        else if (o2.endsWith(specialBranch))
                            return 1;
                    }
                    return o1.compareToIgnoreCase(o2);
                }
            });
            menu.addSeparator(new CustomMenuItemSeparator() {

                @Override
                public Widget createMainWidget() {
                    String branchLabel = caption.equals(LOCAL_BRANCHES) ? LOCAL_BRANCHES : "(Remote: " + caption + ")";
                    Label label = new Label(branchLabel);
                    label.addStyleName(ThemeStyles.INSTANCE.menuSubheader());
                    label.getElement().getStyle().setPaddingLeft(2, Unit.PX);
                    return label;
                }
            });
            menu.addSeparator();
            for (String branch : branches) {
                // skip detached branches
                if (branch.contains("HEAD detached at"))
                    continue;
                // skip HEAD branches
                if (branch.contains("HEAD ->"))
                    continue;
                // construct branch label without remotes prefix
                final String branchLabel = branch.replaceAll("^remotes/" + caption + "/", "");
                final String branchValue = branch.replaceAll("\\s+\\-\\>.*", "");
                menu.addItem(new MenuItem(branchLabel, new SwitchBranchCommand(branchLabel, branchValue)));
            }
        }
    });
}
Also used : CustomMenuItemSeparator(org.rstudio.core.client.widget.CustomMenuItemSeparator) MapUtil(org.rstudio.core.client.MapUtil) Label(com.google.gwt.user.client.ui.Label) ArrayList(java.util.ArrayList) List(java.util.List) MenuItem(com.google.gwt.user.client.ui.MenuItem) JsArrayString(com.google.gwt.core.client.JsArrayString) Comparator(java.util.Comparator)

Example 10 with MenuItem

use of com.google.gwt.user.client.ui.MenuItem in project rstudio by rstudio.

the class TerminalPopupMenu method getDynamicPopupMenu.

@Override
public void getDynamicPopupMenu(final DynamicPopupMenuCallback callback) {
    // clean out existing entries
    clearItems();
    addItem(commands_.newTerminal().createMenuItem(false));
    addSeparator();
    if (terminals_.terminalCount() > 0) {
        for (final String handle : terminals_) {
            Scheduler.ScheduledCommand cmd = new Scheduler.ScheduledCommand() {

                @Override
                public void execute() {
                    eventBus_.fireEvent(new SwitchToTerminalEvent(handle));
                }
            };
            String caption = trimCaption(terminals_.getCaption(handle));
            if (caption == null) {
                continue;
            }
            // visual indicator that terminal has processes running
            caption = addBusyIndicator(caption, terminals_.getHasSubprocs(handle));
            String menuHtml = AppCommand.formatMenuLabel(null, /*icon*/
            caption, /*label*/
            false, /*html*/
            null, /*shortcut*/
            null, /*rightImage*/
            null);
            /*rightImageDesc*/
            addItem(new MenuItem(menuHtml, true, cmd));
        }
        addSeparator();
        addItem(commands_.renameTerminal().createMenuItem(false));
        addItem(commands_.clearTerminalScrollbackBuffer().createMenuItem(false));
        addSeparator();
        addItem(commands_.previousTerminal().createMenuItem(false));
        addItem(commands_.nextTerminal().createMenuItem(false));
        addSeparator();
        addItem(commands_.closeTerminal().createMenuItem(false));
    }
    callback.onPopupMenu(this);
}
Also used : SwitchToTerminalEvent(org.rstudio.studio.client.workbench.views.terminal.events.SwitchToTerminalEvent) Scheduler(com.google.gwt.core.client.Scheduler) MenuItem(com.google.gwt.user.client.ui.MenuItem)

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