Exemple #1
0
 /**
  * Eclipse hack. Disables/enabled all key bindings in specified site's part. Works only if host
  * editor is extender of AbstractTextEditor Uses reflection because setActionActivation is private
  * method TODO: find better way to disable key bindings or prioritize event handling to widgets
  *
  * @param partSite workbench part site
  * @param enable enable or disable
  */
 @Deprecated
 public static void enableHostEditorKeyBindings(IWorkbenchPartSite partSite, boolean enable) {
   IWorkbenchPart part = partSite.getPart();
   if (part instanceof AbstractTextEditor) {
     AbstractTextEditor hostEditor = (AbstractTextEditor) part;
     if (hostEditor instanceof BaseTextEditor) {
       StyledText textWidget = ((BaseTextEditor) hostEditor).getTextViewer().getTextWidget();
       if (textWidget == null || textWidget.isDisposed()) {
         return;
       }
     }
     try {
       Method activatorMethod =
           AbstractTextEditor.class.getDeclaredMethod("setActionActivation", Boolean.TYPE);
       activatorMethod.setAccessible(true);
       activatorMethod.invoke(hostEditor, enable);
     } catch (Throwable e) {
       if (e instanceof InvocationTargetException) {
         e = ((InvocationTargetException) e).getTargetException();
       }
       log.warn("Can't disable text editor action activations", e);
     }
     // hostEditor.getEditorSite().getActionBarContributor().setActiveEditor(hostEditor);
   }
 }
Exemple #2
0
  public static void enableHostEditorKeyBindingsSupport(
      final IWorkbenchPartSite partSite, Control control) {
    if (!(partSite.getPart() instanceof AbstractTextEditor)) {
      return;
    }

    final boolean[] activated = new boolean[] {false};
    control.addFocusListener(
        new FocusListener() {
          @Override
          public void focusGained(FocusEvent e) {
            if (!activated[0]) {
              UIUtils.enableHostEditorKeyBindings(partSite, false);
              activated[0] = true;
            }
          }

          @Override
          public void focusLost(FocusEvent e) {
            if (activated[0]) {
              UIUtils.enableHostEditorKeyBindings(partSite, true);
              activated[0] = false;
            }
          }
        });
    control.addDisposeListener(
        new DisposeListener() {
          @Override
          public void widgetDisposed(DisposeEvent e) {
            if (activated[0]) {
              UIUtils.enableHostEditorKeyBindings(partSite, true);
              activated[0] = false;
            }
          }
        });
  }