private ShortcutManager() {
    keyBuffer_ = new KeySequence();
    keyTimer_ =
        new Timer() {
          @Override
          public void run() {
            keyBuffer_.clear();
          }
        };

    // Defer injection because the ShortcutManager is constructed
    // very eagerly (to allow for codegen stuff in ShortcutsEmitter
    // to work)
    Scheduler.get()
        .scheduleDeferred(
            new ScheduledCommand() {
              @Override
              public void execute() {
                RStudioGinjector.INSTANCE.injectMembers(ShortcutManager.this);
                events_.addHandler(
                    AceKeyboardActivityEvent.TYPE,
                    new AceKeyboardActivityEvent.Handler() {
                      @Override
                      public void onAceKeyboardActivity(AceKeyboardActivityEvent event) {
                        if (!event.isChainEvent()) keyBuffer_.clear();
                      }
                    });
              }
            });

    // NOTE: Because this class is used as a singleton and is never
    // destroyed it's not necessary to manage lifetime of this event handler
    Event.addNativePreviewHandler(this);
    addPostViewHandler();
  }
Example #2
0
  /** Register or unregister the handlers used by {@link PopupPanel}. */
  private void updateHandlers() {
    // Remove any existing handlers.
    if (nativePreviewHandlerRegistration != null) {
      nativePreviewHandlerRegistration.removeHandler();
      nativePreviewHandlerRegistration = null;
    }
    if (historyHandlerRegistration != null) {
      historyHandlerRegistration.removeHandler();
      historyHandlerRegistration = null;
    }

    // Create handlers if showing.
    if (showing) {
      nativePreviewHandlerRegistration =
          Event.addNativePreviewHandler(
              new NativePreviewHandler() {
                public void onPreviewNativeEvent(NativePreviewEvent event) {
                  previewNativeEvent(event);
                }
              });
      historyHandlerRegistration =
          History.addValueChangeHandler(
              new ValueChangeHandler<String>() {
                public void onValueChange(ValueChangeEvent<String> event) {
                  if (autoHideOnHistoryEvents) {
                    hide();
                  }
                }
              });
    }
  }
Example #3
0
  public MouseTracker() {
    Event.addNativePreviewHandler(
        new NativePreviewHandler() {
          @Override
          public void onPreviewNativeEvent(NativePreviewEvent preview) {
            if ((preview.getTypeInt() & Event.MOUSEEVENTS) == 0) return;

            NativeEvent event = preview.getNativeEvent();
            lastMouseX_ = event.getClientX();
            lastMouseY_ = event.getClientY();
          }
        });
  }
  @Override
  protected void onLoad() {
    super.onLoad();

    globalKeyHandlerRegistration =
        Event.addNativePreviewHandler(
            new GlobalKeyEventHandler() {
              @Override
              protected void onKeyPress(char ch) {
                onKey(ch);
              }
            });
  }
  private ShortcutManager() {
    keyBuffer_ = new KeySequence();
    keyTimer_ =
        new Timer() {
          @Override
          public void run() {
            resetKeyBuffer();
          }
        };

    Scheduler.get()
        .scheduleDeferred(
            new ScheduledCommand() {
              @Override
              public void execute() {
                RStudioGinjector.INSTANCE.injectMembers(ShortcutManager.this);
              }
            });

    Event.addNativePreviewHandler(this);
  }
  private static void setupKeyboardShortcuts() {
    Event.addNativePreviewHandler(
        new Event.NativePreviewHandler() {

          @Override
          public void onPreviewNativeEvent(NativePreviewEvent preview) {
            final NativeEvent event = preview.getNativeEvent();
            if (event == null) return;
            String eventType = event.getType();
            if (eventType == null) return;
            if (!eventType.equalsIgnoreCase("keydown")) {
              return;
            }

            final int keycode = event.getKeyCode();
            final boolean ctrl = event.getCtrlKey();
            final boolean shift = event.getShiftKey();
            final boolean alt = event.getAltKey();

            if (alt && !hasAlt) {
              return;
            }
            if (ctrl && !hasCtrl) {
              return;
            }
            if (shift && !hasShift) {
              return;
            }
            if (!codes.contains(keycode)) {
              return;
            }

            if (handleKeycode(keycode, alt, ctrl, shift)) {
              preview.cancel();
            }
          }
        });
  }
Example #7
0
  /**
   * Adds the preview handler.
   *
   * <p>
   */
  protected void onFocusTimeBox() {

    m_previewRegistration = Event.addNativePreviewHandler(m_previewHandler);
  }
  public void onModuleLoad() {

    // Listener CodeMirror
    // TODO Erreur JSNI avec FireFox
    CodeMirrorEditorWrapper.addOnChangeHandler(this);
    CodeMirrorEditorWrapper.setFileOpened("");

    // get Divs
    RootPanel buttonBar = RootPanel.get("buttonBar");
    RootPanel editor = RootPanel.get("editor");
    systemFileRoot = RootPanel.get("fileSystem");

    // add editor's content
    Grid gridEditor = new Grid(1, 1);

    // textArea Display codeMirror's stuff
    textAreaCodeShow = new HTML();
    textAreaCodeShow.setStyleName("textAreaCodeShow");

    gridEditor.setWidget(0, 0, textAreaCodeShow);

    editor.add(gridEditor);

    // add buttonBar's Content
    Grid grid = new Grid(2, 2);
    buttonBar.add(grid);
    buttonBar.setStyleName("buttonBarGrid");

    Label labelError = new Label();
    labelError.setVisible(false);
    labelError.setStyleName("labelError");

    login = new StringBuilder();
    password = new StringBuilder();

    toolStripMenu = new ToolStripMenu();
    formOpen = new FormOpen(labelError, toolStripMenu, this, systemFileRoot, login, password);
    formNew = new FormNew(labelError, toolStripMenu, this, systemFileRoot, login, password);

    toolStripMenu.setIHMCodeMirror(this);
    toolStripMenu.setFormNew(formNew);
    toolStripMenu.setFormOpen(formOpen);

    grid.setWidget(0, 0, toolStripMenu);
    grid.setWidget(1, 0, labelError);

    // shortcut keyboard for fun ~~ different behaviour between browser
    HandlerRegistration logHandler =
        Event.addNativePreviewHandler(
            new NativePreviewHandler() {

              @Override
              public void onPreviewNativeEvent(NativePreviewEvent event) {
                ne = event.getNativeEvent();

                if (ne.getType().equals("keydown")
                    && ne.getCtrlKey()
                    && (ne.getKeyCode() == 'n' || ne.getKeyCode() == 'N')) {
                  ne.preventDefault();
                  Scheduler.get()
                      .scheduleDeferred(
                          new ScheduledCommand() {
                            @Override
                            public void execute() {
                              if (formNew.isVisible()) {
                                formNew.hide();
                              } else {
                                formNew.show();
                              }
                            }
                          });
                } else if (ne.getType().equals("keydown")
                    && ne.getCtrlKey()
                    && (ne.getKeyCode() == 'o' || ne.getKeyCode() == 'O')) {
                  ne.preventDefault();
                  Scheduler.get()
                      .scheduleDeferred(
                          new ScheduledCommand() {
                            @Override
                            public void execute() {
                              if (formOpen.isVisible()) {
                                formOpen.hide();
                              } else {
                                formOpen.show();
                              }
                            }
                          });
                } else if (ne.getType().equals("keydown")
                    && ne.getCtrlKey()
                    && (ne.getKeyCode() == 's' || ne.getKeyCode() == 'S')) {
                  ne.preventDefault();

                  Scheduler.get()
                      .scheduleDeferred(
                          new ScheduledCommand() {
                            @Override
                            public void execute() {
                              if (!toolStripMenu.getBtnSave().isDisabled()) {
                                // fonction to call for saving
                                pushContentEditorToRepo();
                              }
                            }
                          });
                }
              }
            });

    // Auto-Save
    int savePeriod = 5000000;
    Scheduler.get()
        .scheduleFixedDelay(
            new RepeatingCommand() {
              @Override
              public boolean execute() {
                if (!toolStripMenu.getBtnSave().isDisabled()) {
                  // fonction to call for saving
                  pushContentEditorToRepo();
                }
                return true;
              }
            },
            savePeriod);
  }
Example #9
0
 private void addTabBlockHandlers() {
   if (topBlockerRegistration == null) {
     topBlockerRegistration = Event.addNativePreviewHandler(topEventBlocker);
     bottomBlockerRegistration = Event.addNativePreviewHandler(bottomEventBlocker);
   }
 }
 public PageContent() {
   super();
   Event.addNativePreviewHandler(this);
   EventBus.getInstance().addHandler(AbstractPageEvent.TYPE, this);
 }
Example #11
0
  protected void afterShow() {
    hidden = false;

    // layout early to render window's content for size calcs
    if (!layoutExecuted || isLayoutNeeded()) {
      layout();
    }

    if (restorePos != null) {
      setPosition(restorePos.x, restorePos.y);
      if (restoreSize != null) {
        setSize(restoreSize.width, restoreSize.height);
      }
    }
    if (restoreWindowScrolling != null) {
      com.google.gwt.dom.client.Document.get().enableScrolling(false);
    }

    int h = getHeight();
    int w = getWidth();
    if (h < minHeight && w < minWidth) {
      setSize(minWidth, minHeight);
    } else if (h < minHeight) {
      setHeight(minHeight);
    } else if (w < minWidth) {
      setWidth(minWidth);
    }

    // not positioned, then center
    if (!positioned) {
      el().center(true);
    }

    el().updateZIndex(0);
    if (modal) {
      modalPreview =
          Event.addNativePreviewHandler(
              new NativePreviewHandler() {
                public void onPreviewNativeEvent(NativePreviewEvent event) {
                  if (Element.is(event.getNativeEvent().getEventTarget())) {
                    Element target = (Element) Element.as(event.getNativeEvent().getEventTarget());

                    String tag = target.getTagName();
                    // ignore html and body because of frames
                    if (!resizing
                        && !dragging
                        && !tag.equalsIgnoreCase("html")
                        && !tag.equalsIgnoreCase("body")
                        && event.getTypeInt() != Event.ONLOAD
                        && manager.getActive() == Window.this
                        && (modalPanel == null
                            || (modalPanel != null
                                && !modalPanel.getElement().isOrHasChild(target)))
                        && !Window.this.getElement().isOrHasChild(target)
                        && fly(target).findParent(".x-ignore", -1) == null) {
                      ArrayList<Component> col =
                          new ArrayList<Component>(ComponentManager.get().getAll());
                      for (Component c : col) {
                        if (c instanceof TriggerField<?>) {
                          triggerBlur((TriggerField<?>) c);
                        } else if (c instanceof Menu) {
                          ((Menu) c).hide(true);
                        }
                      }
                      Window.this.focus();
                    }
                  }
                }

                private native void triggerBlur(TriggerField<?> field) /*-{
    [email protected]::triggerBlur(Lcom/extjs/gxt/ui/client/event/ComponentEvent;)(null);
  }-*/;
              });
    }

    // missing cursor workaround
    if (GXT.isGecko) {
      El e = el().selectNode(".x-window-bwrap");
      if (e != null) {
        e.dom.getStyle().setProperty("overflow", "auto");
        e.dom.getStyle().setProperty("position", "static");
      }
    }

    eventPreview.add();

    if (maximized) {
      maximize();
    }
    removeStyleName(HideMode.VISIBILITY.value());

    if (GXT.isAriaEnabled()) {
      Accessibility.setState(getElement(), "aria-hidden", "false");
    }

    fireEvent(Events.Show, new WindowEvent(this));
    toFront();
  }