public SearchPatternData tryErlangTextSelection(
     final SearchPatternData initData0, final IEditorPart activePart) throws ErlModelException {
   final AbstractErlangEditor erlangEditor = (AbstractErlangEditor) activePart;
   final IErlModule module = erlangEditor.getModule();
   SearchPatternData initData = initData0;
   if (module != null) {
     final ISelection ssel = erlangEditor.getSite().getSelectionProvider().getSelection();
     final ITextSelection textSel = (ITextSelection) ssel;
     final int offset = textSel.getOffset();
     OpenResult res;
     try {
       res =
           ErlangEngine.getInstance()
               .getService(OpenService.class)
               .open(
                   module.getScannerName(),
                   offset,
                   ErlangEngine.getInstance().getModelUtilService().getImportsAsList(module),
                   "",
                   ErlangEngine.getInstance().getModel().getPathVars());
     } catch (final RpcException e) {
       res = null;
     }
     ErlLogger.debug("searchPage(open) " + res);
     initData = determineInitValuesFrom(module, offset, res);
   }
   return initData;
 }
 /*
  * @see org.eclipse.jface.action.Action#run()
  */
 @Override
 public void run() {
   ErlBrowserInformationControlInput input = null;
   if (fInfoControl != null) {
     input = (ErlBrowserInformationControlInput) fInfoControl.getInput();
     fInfoControl.notifyDelayedInputChange(null);
     fInfoControl.dispose();
   } else if (edocView != null) {
     input = edocView.getInput();
   }
   if (input != null) {
     // TODO: add hover location to editor navigation history?
     try {
       final Object element = input.getInputElement();
       if (element instanceof IErlElement) {
         EditorUtility.openElementInEditor(element, true);
       } else if (element instanceof OpenResult) {
         final OpenResult or = (OpenResult) element;
         try {
           final AbstractErlangEditor editor = input.getEditor();
           new OpenUtils().openOpenResult(editor, editor.getModule(), -1, null, or, null);
         } catch (final Exception e) {
           ErlLogger.error(e);
         }
       }
     } catch (final PartInitException e) {
       ErlLogger.error(e);
     }
   }
 }
  protected void indentAfterNewLine(final IDocument d, final DocumentCommand c)
      throws BadLocationException {
    final int offset = c.offset;
    String txt = null;
    editor.reconcileNow();
    final IErlElement element = editor.getElementAt(offset, false);
    final IErlMember member = (IErlMember) element;
    if (member != null) {
      final int start = member.getSourceRange().getOffset();
      if (offset >= start) {
        txt = d.get(start, offset - start);
      }
    }
    if (txt == null) {
      txt = "";
    }
    final int lineN = d.getLineOfOffset(offset);
    final int lineOffset = d.getLineOffset(lineN);
    final int lineLength = d.getLineLength(lineN);
    final String oldLine = d.get(offset, lineLength + lineOffset - offset);
    try {
      final IRpcSite b = BackendCore.getBackendManager().getIdeBackend().getRpcSite();
      final int tabw = getTabWidthFromPreferences();

      final Map<String, String> prefs = new TreeMap<String, String>();
      IndentationPreferencePage.addKeysAndPrefs(prefs);
      SmartTypingPreferencePage.addAutoNLKeysAndPrefs(prefs);
      final boolean useTabs = getUseTabsFromPreferences();
      final IndentResult res =
          ErlideIndent.indentLine(b, oldLine, txt, c.text, tabw, useTabs, prefs);

      if (res.isAddNewLine()) {
        c.text += "\n";
      }
      c.text += res.getText();
      c.length += res.getRemoveNext();
    } catch (final Exception e) {
      ErlLogger.warn(e);
    }
  }
Beispiel #4
0
 /**
  * Tests if a CU is currently shown in an editor
  *
  * @return the IEditorPart if shown, null if element is not open in an editor
  */
 public static IEditorPart isOpenInEditor(final Object inputElement) {
   final Collection<IEditorPart> allErlangEditors = EditorUtility.getAllErlangEditors();
   for (final IEditorPart editorPart : allErlangEditors) {
     if (inputElement instanceof IErlElement) {
       final IErlElement element = (IErlElement) inputElement;
       final IErlModule module =
           ErlangEngine.getInstance().getModelUtilService().getModule(element);
       final AbstractErlangEditor editor = (AbstractErlangEditor) editorPart;
       if (module.equals(editor.getModule())) {
         return editorPart;
       }
     }
   }
   final IEditorInput input = getEditorInput(inputElement);
   if (input != null) {
     for (final IEditorPart editorPart : allErlangEditors) {
       if (editorPart.getEditorInput().equals(input)) {
         return editorPart;
       }
     }
   }
   return null;
 }
  @Override
  protected IInformationControl doCreateInformationControl(final Shell parent) {
    if (BrowserInformationControl.isAvailable(parent)) {
      final ToolBarManager tbm = new ToolBarManager(SWT.FLAT);

      final String font = JFaceResources.DIALOG_FONT;
      final BrowserInformationControl control = new BrowserInformationControl(parent, font, tbm);

      final PresenterControlCreator.BackAction backAction =
          new PresenterControlCreator.BackAction(control);
      backAction.setEnabled(false);
      tbm.add(backAction);
      final PresenterControlCreator.ForwardAction forwardAction =
          new PresenterControlCreator.ForwardAction(control);
      tbm.add(forwardAction);
      forwardAction.setEnabled(false);

      final PresenterControlCreator.ShowInEdocViewAction showInEdocViewAction =
          new PresenterControlCreator.ShowInEdocViewAction(control);
      tbm.add(showInEdocViewAction);
      final OpenDeclarationAction openDeclarationAction =
          new OpenDeclarationAction(control, editor);
      tbm.add(openDeclarationAction);

      final SimpleSelectionProvider selectionProvider = new SimpleSelectionProvider();
      final OpenEdocInExternalBrowserAction openEdocInExternalBrowserAction =
          new OpenEdocInExternalBrowserAction(editor.getSite(), null);
      openEdocInExternalBrowserAction.setSpecialSelectionProvider(selectionProvider);
      selectionProvider.addSelectionChangedListener(openEdocInExternalBrowserAction);
      final ImageDescriptor descriptor = ErlideImage.OBJS_EXTERNALBROWSER.getDescriptor();
      openEdocInExternalBrowserAction.setImageDescriptor(descriptor);
      openEdocInExternalBrowserAction.setDisabledImageDescriptor(descriptor);
      selectionProvider.setSelection(new StructuredSelection());
      tbm.add(openEdocInExternalBrowserAction);

      // OpenExternalBrowserAction openExternalJavadocAction = new
      // OpenExternalBrowserAction(
      // parent.getDisplay(), selectionProvider);
      // selectionProvider
      // .addSelectionChangedListener(openExternalJavadocAction);
      // selectionProvider.setSelection(new
      // StructuredSelection());
      // tbm.add(openExternalJavadocAction);

      final IInputChangedListener inputChangeListener =
          new IInputChangedListener() {
            @Override
            public void inputChanged(final Object newInput) {
              backAction.update();
              forwardAction.update();
              if (newInput == null) {
                selectionProvider.setSelection(new StructuredSelection());
              } else if (newInput instanceof BrowserInformationControlInput) {
                final BrowserInformationControlInput input =
                    (BrowserInformationControlInput) newInput;
                final Object inputElement = input.getInputElement();
                selectionProvider.setSelection(new StructuredSelection(inputElement));
                final boolean hasInputElement = inputElement != null;
                showInEdocViewAction.setEnabled(hasInputElement);
                openDeclarationAction.setEnabled(hasInputElement);
                openEdocInExternalBrowserAction.setInput(newInput);
                openEdocInExternalBrowserAction.setEnabled(hasInputElement);
              }
            }
          };
      control.addInputChangeListener(inputChangeListener);

      tbm.update(true);

      control.addLocationListener(new HandleEdocLinksLocationListener(control));

      return control;
    }
    return new DefaultInformationControl(
        parent, EditorsUI.getTooltipAffordanceString(), new ErlInformationPresenter(true));
  }