Search in sources :

Example 1 with StatusBarPopupMenu

use of org.rstudio.studio.client.workbench.views.source.editors.text.status.StatusBarPopupMenu 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)

Example 2 with StatusBarPopupMenu

use of org.rstudio.studio.client.workbench.views.source.editors.text.status.StatusBarPopupMenu in project rstudio by rstudio.

the class TextEditingTarget method showStatusBarPopupMenu.

private void showStatusBarPopupMenu(StatusBarPopupRequest popupRequest) {
    final StatusBarPopupMenu menu = popupRequest.getMenu();
    MenuItem defaultItem = popupRequest.getDefaultMenuItem();
    if (defaultItem != null) {
        menu.selectItem(defaultItem);
        Scheduler.get().scheduleFinally(new RepeatingCommand() {

            public boolean execute() {
                menu.ensureSelectedIsVisible();
                return false;
            }
        });
    }
    menu.showRelativeToUpward((UIObject) statusBar_.getScope(), false);
}
Also used : StatusBarPopupMenu(org.rstudio.studio.client.workbench.views.source.editors.text.status.StatusBarPopupMenu) RepeatingCommand(com.google.gwt.core.client.Scheduler.RepeatingCommand) MenuItem(com.google.gwt.user.client.ui.MenuItem)

Example 3 with StatusBarPopupMenu

use of org.rstudio.studio.client.workbench.views.source.editors.text.status.StatusBarPopupMenu 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("&nbsp;&nbsp;");
                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);
    }
}
Also used : ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) Command(com.google.gwt.user.client.Command) StatusBarPopupMenu(org.rstudio.studio.client.workbench.views.source.editors.text.status.StatusBarPopupMenu) StatusBarPopupRequest(org.rstudio.studio.client.workbench.views.source.editors.text.status.StatusBarPopupRequest) MenuItem(com.google.gwt.user.client.ui.MenuItem) SlideNavigation(org.rstudio.studio.client.common.presentation.model.SlideNavigation) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder) SlideNavigationItem(org.rstudio.studio.client.common.presentation.model.SlideNavigationItem) SimpleRequestCallback(org.rstudio.studio.client.common.SimpleRequestCallback)

Aggregations

MenuItem (com.google.gwt.user.client.ui.MenuItem)3 StatusBarPopupMenu (org.rstudio.studio.client.workbench.views.source.editors.text.status.StatusBarPopupMenu)3 StatusBarPopupRequest (org.rstudio.studio.client.workbench.views.source.editors.text.status.StatusBarPopupRequest)2 JsArray (com.google.gwt.core.client.JsArray)1 JsArrayString (com.google.gwt.core.client.JsArrayString)1 RepeatingCommand (com.google.gwt.core.client.Scheduler.RepeatingCommand)1 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)1 SafeHtmlBuilder (com.google.gwt.safehtml.shared.SafeHtmlBuilder)1 Command (com.google.gwt.user.client.Command)1 UIObject (com.google.gwt.user.client.ui.UIObject)1 SimpleRequestCallback (org.rstudio.studio.client.common.SimpleRequestCallback)1 TextFileType (org.rstudio.studio.client.common.filetypes.TextFileType)1 SlideNavigation (org.rstudio.studio.client.common.presentation.model.SlideNavigation)1 SlideNavigationItem (org.rstudio.studio.client.common.presentation.model.SlideNavigationItem)1