Esempio n. 1
0
 /*
  * (non-Javadoc) Method declared on SelectionDispatchAction.
  */
 @Override
 public void run(final ITextSelection selection) {
   final ErlangEditor editor = (ErlangEditor) getSite().getPage().getActiveEditor();
   editor.reconcileNow();
   final IErlModule module = editor.getModule();
   if (module == null) {
     return;
   }
   final Backend b = ErlangCore.getBackendManager().getIdeBackend();
   final int offset = selection.getOffset();
   try {
     final IErlProject erlProject = module.getErlProject();
     final IErlModel model = ErlangCore.getModel();
     final OpenResult res =
         ErlideOpen.open(
             b,
             ErlangToolkit.createScannerModuleName(module),
             offset,
             ErlModelUtils.getImportsAsList(module),
             model.getExternalModules(erlProject),
             model.getPathVars());
     ErlLogger.debug("open " + res);
     openOpenResult(editor, module, b, offset, erlProject, res);
   } catch (final Exception e) {
     ErlLogger.warn(e);
   }
 }
 /**
  * Selects the given range on the editor.
  *
  * @param newOffset the selection offset
  * @param newLength the selection range
  */
 protected void selectAndReveal(final int newOffset, final int newLength) {
   final ITextEditor editor = getTextEditor();
   if (editor instanceof ErlangEditor) {
     final ErlangEditor erlEditor = (ErlangEditor) editor;
     erlEditor.selectAndReveal(newOffset, newLength);
   } else {
     // this is too intrusive, but will never get called anyway
     getTextEditor().selectAndReveal(newOffset, newLength);
   }
 }
Esempio n. 3
0
 public OpenAction(final ErlangEditor erlangEditor) {
   super(erlangEditor.getSite());
   setText(ActionMessages.OpenAction_open_declaration_label);
   setToolTipText(ActionMessages.OpenAction_tooltip);
   setDescription(ActionMessages.OpenAction_description);
   PlatformUI.getWorkbench().getHelpSystem().setHelp(this, "erl.open");
 }
Esempio n. 4
0
  /*
   * Method declared on SelectionChangedAction.
   */
  @Override
  public void run(final ITextSelection selection) {
    // if (!ActionUtil.isProcessable(fEditor)) {
    // return;
    // }
    IErlModule module = fEditor.getModule();
    if (module == null) {
      return;
    }
    final Backend b = ErlangCore.getBackendManager().getIdeBackend();
    final ISelection sel = getSelection();
    final ITextSelection textSel = (ITextSelection) sel;
    final int offset = textSel.getOffset();
    try {
      String scannerModuleName = ErlangToolkit.createScannerModuleName(module);
      final OpenResult res =
          ErlideOpen.open(b, scannerModuleName, offset, "", ErlangCore.getModel().getPathVars());
      ErlLogger.debug("open " + res);

      // final String title =
      // "SearchMessages.SearchElementSelectionDialog_title";
      // final String message =
      // "SearchMessages.SearchElementSelectionDialog_message";

      if (res.isExternalCall()) {
        performNewSearch(SearchUtil.getRefFromOpenRes(res));
      }
    } catch (final Exception e) {
      // final String title = "SearchMessages.Search_Error_search_title";
      // final String message = "SearchMessages.Search_Error_codeResolve";
      // ExceptionHandler.handle(e, getShell(), title, message);
      ErlLogger.debug(e);
    }
  }
Esempio n. 5
0
 /** Selects a Erlang Element in an editor */
 public static boolean revealInEditor(final IEditorPart part, final IErlElement element) {
   if (element != null && part instanceof ErlangEditor) {
     ((ErlangEditor) part).setSelection(element);
     return true;
   }
   return false;
 }
Esempio n. 6
0
 /*
  * (non-Javadoc)
  *
  * @see org.eclipse.jface.action.Action#run()
  */
 @Override
 public void run() {
   final IErlModule module = erlangEditor.getModule();
   if (module == null) {
     return;
   }
   for (String suffix : suffixes) {
     final String cacheFileOSPath =
         ErlangPlugin.getDefault()
             .getStateLocation()
             .append(ErlangToolkit.createScannerModuleName(module) + suffix)
             .toOSString();
     final File cacheFile = new File(cacheFileOSPath);
     cacheFile.delete();
   }
   erlangEditor.resetAndCacheScannerAndParser();
 }
Esempio n. 7
0
 @Override
 public void initialReconcile() {
   fModule = fEditor != null ? fEditor.getModule() : null;
   ErlLogger.debug("## initial reconcile " + (fModule != null ? fModule.getName() : ""));
   if (fModule != null) {
     fModule.initialReconcile();
   }
   // notify(new OtpErlangAtom("initialReconcile"));
 }
 @Override
 public void launch(final IEditorPart editor, final String mode) {
   ErlLogger.debug("** Launch :: " + editor.getTitle());
   if (editor instanceof ErlangEditor) {
     final ErlangEditor erlangEditor = (ErlangEditor) editor;
     final IErlModule module = erlangEditor.getModule();
     if (module != null) {
       final IErlProject project = ModelUtils.getProject(module);
       if (project != null) {
         try {
           doLaunch(mode, Lists.newArrayList(project));
         } catch (final CoreException e) {
           final IWorkbench workbench = PlatformUI.getWorkbench();
           final Shell shell = workbench.getActiveWorkbenchWindow().getShell();
           MessageDialog.openError(shell, "Error", e.getStatus().getMessage());
         }
       }
     }
   }
 }
Esempio n. 9
0
 public static void openOpenResult(
     final ErlangEditor editor,
     final IErlModule module,
     final Backend backend,
     final int offset,
     final IErlProject erlProject,
     final OpenResult res)
     throws CoreException, ErlModelException, PartInitException, BadLocationException,
         OtpErlangRangeException, BackendException {
   final IErlModel model = ErlangCore.getModel();
   final IProject project = erlProject == null ? null : erlProject.getProject();
   final IErlElement element = editor.getElementAt(offset, true);
   IErlElement foundElement = null;
   ISourceRange foundSourceRange = null;
   final boolean checkAllProjects = NavigationPreferencePage.getCheckAllProjects();
   if (res.isExternalCall()) {
     foundElement = findExternalCallOrType(module, res, project, element, checkAllProjects);
   } else if (res.isInclude()) {
     foundElement = findInclude(module, erlProject, res, model, project);
   } else if (res.isLocalCall()) {
     foundElement =
         findLocalCall(module, backend, erlProject, res, project, element, checkAllProjects);
   } else if (res.isVariable() && element instanceof ISourceReference) {
     final ISourceReference sref = (ISourceReference) element;
     final ISourceRange range = sref.getSourceRange();
     final String elementText = editor.getDocument().get(range.getOffset(), range.getLength());
     foundSourceRange = ErlModelUtils.findVariable(backend, range, res.getName(), elementText);
   } else if (res.isRecord() || res.isMacro()) {
     final IErlElement.Kind kind =
         res.isMacro() ? IErlElement.Kind.MACRO_DEF : IErlElement.Kind.RECORD_DEF;
     foundElement =
         ErlModelUtils.findPreprocessorDef(
             backend, project, module, res.getName(), kind, model.getExternalIncludes(erlProject));
   }
   if (foundElement != null) {
     ErlModelUtils.openElement(foundElement);
   } else if (foundSourceRange != null) {
     ErlModelUtils.openSourceRange(module, foundSourceRange);
   }
 }
 /**
  * Provide the text selection that is needed to execute the command. Default implementation,
  * extend to Erlang elements selected.
  *
  * @param document text {@link IDocument}
  * @param selection selection affected by command (extended by extendSelection)
  * @return new {@link ITextSelection} with all text up to selection
  */
 protected ITextSelection getTextSelection(
     final IDocument document, final ITextSelection selection) {
   if (getTextEditor() instanceof ErlangEditor) {
     final ErlangEditor erlangEditor = (ErlangEditor) getTextEditor();
     final IErlModule module = erlangEditor.getModule();
     if (module != null) {
       final int offset1 = selection.getOffset(), offset2 = offset1 + selection.getLength();
       try {
         final IErlElement e1 = module.getElementAt(offset1);
         final IErlElement e2 = module.getElementAt(offset2);
         if (e1 instanceof ISourceReference) {
           final ISourceReference ref1 = (ISourceReference) e1;
           final ISourceRange r1 = ref1.getSourceRange();
           if (e1 == e2) {
             return extendSelectionToWholeLines(
                 document, new TextSelection(document, r1.getOffset(), r1.getLength()));
           } else if (e2 == null) {
             return extendSelectionToWholeLines(
                 document,
                 new TextSelection(
                     document,
                     r1.getOffset(),
                     selection.getLength() + selection.getOffset() - r1.getOffset()));
           } else if (e2 instanceof ISourceReference) {
             final ISourceReference ref2 = (ISourceReference) e2;
             final ISourceRange r2 = ref2.getSourceRange();
             return extendSelectionToWholeLines(
                 document,
                 new TextSelection(
                     document, r1.getOffset(), r2.getOffset() - r1.getOffset() + r2.getLength()));
           }
         }
       } catch (final ErlModelException e) {
       }
     }
   }
   return extendSelectionToWholeLines(document, selection);
 }
Esempio n. 11
0
 FindAction(final ErlangEditor editor) {
   this(editor.getEditorSite());
   fEditor = editor;
   setEnabled(true); // FIXME kolla selection, sno grejer fr�n open
   // kanske...
 }