Search in sources :

Example 6 with PositionCallback

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

the class ManipulatorManager method showManipulatorPopup.

private void showManipulatorPopup() {
    // show it if necessary
    if (!manipulatorPopup_.isShowing()) {
        // state of the manipulator existing below the workbench
        if (plotsSurface_.getOffsetHeight() == 0)
            return;
        manipulatorPopup_.recordPreviouslyFocusedElement();
        manipulatorPopup_.setPopupPositionAndShow(new PositionCallback() {

            @Override
            public void setPosition(int offsetWidth, int offsetHeight) {
                // position the manipulator to the right if necessary
                int xPos = plotsSurface_.getAbsoluteLeft() - offsetWidth + 20;
                if (xPos < 0) {
                    xPos = plotsSurface_.getAbsoluteLeft() + plotsSurface_.getOffsetWidth() - 20;
                }
                manipulatorPopup_.setPopupPosition(xPos, plotsSurface_.getAbsoluteTop() - 6);
                manipulatorPopup_.focusFirstControl();
            }
        });
    }
}
Also used : PositionCallback(com.google.gwt.user.client.ui.PopupPanel.PositionCallback)

Example 7 with PositionCallback

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

the class DiagnosticsBackgroundPopup method showPopup.

private void showPopup(String text, Range range) {
    hidePopup();
    popup_ = new DiagnosticsPopupPanel(text, range);
    final Rectangle coords = editor_.toScreenCoordinates(range);
    popup_.setTitle("Diagnostics");
    popup_.setPopupPositionAndShow(new PositionCallback() {

        @Override
        public void setPosition(int offsetWidth, int offsetHeight) {
            popup_.setPopupPosition(coords.getRight() + 10, coords.getBottom());
        }
    });
}
Also used : PositionCallback(com.google.gwt.user.client.ui.PopupPanel.PositionCallback) Rectangle(org.rstudio.core.client.Rectangle)

Example 8 with PositionCallback

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

the class ToolbarButton method addMenuHandlers.

private void addMenuHandlers(final ToolbarPopupMenu popupMenu, final boolean rightAlign) {
    menu_ = popupMenu;
    /*
       * We want clicks on this button to toggle the visibility of the menu,
       * as well as having the menu auto-hide itself as it normally does.
       * It's necessary to manually track the visibility (menuShowing) because
       * in the case where the menu is showing, clicking on this button first
       * causes the menu to auto-hide and then our mouseDown handler is called
       * (so we can't rely on menu.isShowing(), it'll always be false by the
       * time you get into the mousedown handler).
       */
    final boolean[] menuShowing = new boolean[1];
    addMouseDownHandler(new MouseDownHandler() {

        public void onMouseDown(MouseDownEvent event) {
            event.preventDefault();
            event.stopPropagation();
            addStyleName(styles_.toolbarButtonPushed());
            // Some menus are rebuilt on every invocation. Ask the menu for 
            // the most up-to-date version before proceeding.
            popupMenu.getDynamicPopupMenu(new ToolbarPopupMenu.DynamicPopupMenuCallback() {

                @Override
                public void onPopupMenu(final ToolbarPopupMenu menu) {
                    if (menuShowing[0]) {
                        removeStyleName(styles_.toolbarButtonPushed());
                        menu.hide();
                    } else {
                        if (rightAlign) {
                            menu.setPopupPositionAndShow(new PositionCallback() {

                                @Override
                                public void setPosition(int offsetWidth, int offsetHeight) {
                                    menu.setPopupPosition((rightImageWidget_ != null ? rightImageWidget_.getAbsoluteLeft() : leftImageWidget_.getAbsoluteLeft()) + 20 - offsetWidth, ToolbarButton.this.getAbsoluteTop() + ToolbarButton.this.getOffsetHeight());
                                }
                            });
                        } else {
                            menu.showRelativeTo(ToolbarButton.this);
                        }
                        menuShowing[0] = true;
                    }
                }
            });
        }
    });
    popupMenu.addCloseHandler(new CloseHandler<PopupPanel>() {

        public void onClose(CloseEvent<PopupPanel> popupPanelCloseEvent) {
            removeStyleName(styles_.toolbarButtonPushed());
            Scheduler.get().scheduleDeferred(new ScheduledCommand() {

                public void execute() {
                    menuShowing[0] = false;
                }
            });
        }
    });
}
Also used : PositionCallback(com.google.gwt.user.client.ui.PopupPanel.PositionCallback) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) PopupPanel(com.google.gwt.user.client.ui.PopupPanel)

Example 9 with PositionCallback

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

the class FilesPane method showDataImportFileChoice.

@Override
public void showDataImportFileChoice(FileSystemItem file, Command onView, Command onImport) {
    final ToolbarPopupMenu menu = new ToolbarPopupMenu();
    String editLabel = AppCommand.formatMenuLabel(commands_.renameFile().getImageResource(), "View File", null);
    String importLabel = AppCommand.formatMenuLabel(new ImageResource2x(StandardIcons.INSTANCE.import_dataset2x()), "Import Dataset...", null);
    menu.addItem(new MenuItem(editLabel, true, onView));
    menu.addItem(new MenuItem(importLabel, true, onImport));
    menu.setPopupPositionAndShow(new PositionCallback() {

        @Override
        public void setPosition(int offsetWidth, int offsetHeight) {
            Event event = Event.getCurrentEvent();
            PopupPositioner.setPopupPosition(menu, event.getClientX(), event.getClientY());
        }
    });
}
Also used : ToolbarPopupMenu(org.rstudio.core.client.widget.ToolbarPopupMenu) PositionCallback(com.google.gwt.user.client.ui.PopupPanel.PositionCallback) ImageResource2x(org.rstudio.core.client.resources.ImageResource2x) Event(com.google.gwt.user.client.Event) MenuItem(com.google.gwt.user.client.ui.MenuItem)

Example 10 with PositionCallback

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

the class FilesPane method showHtmlFileChoice.

@Override
public void showHtmlFileChoice(FileSystemItem file, Command onEdit, Command onBrowse) {
    final ToolbarPopupMenu menu = new ToolbarPopupMenu();
    String editLabel = AppCommand.formatMenuLabel(commands_.renameFile().getImageResource(), "Open in Editor", null);
    String openLabel = AppCommand.formatMenuLabel(commands_.openHtmlExternal().getImageResource(), "View in Web Browser", null);
    menu.addItem(new MenuItem(editLabel, true, onEdit));
    menu.addItem(new MenuItem(openLabel, true, onBrowse));
    menu.setPopupPositionAndShow(new PositionCallback() {

        @Override
        public void setPosition(int offsetWidth, int offsetHeight) {
            Event event = Event.getCurrentEvent();
            PopupPositioner.setPopupPosition(menu, event.getClientX(), event.getClientY());
        }
    });
}
Also used : ToolbarPopupMenu(org.rstudio.core.client.widget.ToolbarPopupMenu) PositionCallback(com.google.gwt.user.client.ui.PopupPanel.PositionCallback) Event(com.google.gwt.user.client.Event) MenuItem(com.google.gwt.user.client.ui.MenuItem)

Aggregations

PositionCallback (com.google.gwt.user.client.ui.PopupPanel.PositionCallback)14 ToolbarPopupMenu (org.rstudio.core.client.widget.ToolbarPopupMenu)6 PopupPanel (com.google.gwt.user.client.ui.PopupPanel)4 Event (com.google.gwt.user.client.Event)3 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)2 MenuItem (com.google.gwt.user.client.ui.MenuItem)2 Rectangle (org.rstudio.core.client.Rectangle)2 ImageResource2x (org.rstudio.core.client.resources.ImageResource2x)2 FocusEvent (com.google.gwt.event.dom.client.FocusEvent)1 Command (com.google.gwt.user.client.Command)1 EventListener (com.google.gwt.user.client.EventListener)1 AppCommand (org.rstudio.core.client.command.AppCommand)1 Commands (org.rstudio.studio.client.workbench.commands.Commands)1