Пример #1
0
 @Override
 public void open() {
   try {
     DartUI.openInEditor(element);
   } catch (Throwable e) {
     DartToolsPlugin.log(e);
   }
 }
  @Override
  public ICompletionProposal[] computeQuickAssistProposals(
      IQuickAssistInvocationContext quickAssistContext) {
    ISourceViewer viewer = quickAssistContext.getSourceViewer();
    int documentOffset = quickAssistContext.getOffset();

    IEditorPart part = fAssistant.getEditor();

    CompilationUnit cu = DartUI.getWorkingCopyManager().getWorkingCopy(part.getEditorInput());
    IAnnotationModel model = DartUI.getDocumentProvider().getAnnotationModel(part.getEditorInput());

    AssistContext context = null;
    if (cu != null) {
      int length = viewer != null ? viewer.getSelectedRange().y : 0;
      context = new AssistContext(cu, viewer, part, documentOffset, length);
    }

    Annotation[] annotations = fAssistant.getAnnotationsAtOffset();

    fErrorMessage = null;

    ICompletionProposal[] res = null;
    if (model != null && context != null && annotations != null) {
      List<IDartCompletionProposal> proposals = Lists.newArrayList();
      IStatus status =
          collectProposals(
              context, model, annotations, true, !fAssistant.isUpdatedOffset(), proposals);
      res = proposals.toArray(new ICompletionProposal[proposals.size()]);
      if (!status.isOK()) {
        fErrorMessage = status.getMessage();
        DartToolsPlugin.log(status);
      }
    }

    if (res == null || res.length == 0) {
      return new ICompletionProposal[] {
        new ChangeCorrectionProposal(
            CorrectionMessages.NoCorrectionProposal_description, new NullChange(""), 0, null)
      }; //$NON-NLS-1$
    }
    if (res.length > 1) {
      Arrays.sort(res, new CompletionProposalComparator());
    }
    return res;
  }
 private void gotoSelectedElement() {
   Object selectedElement = getSelectedElement();
   if (selectedElement instanceof com.google.dart.engine.element.Element) {
     try {
       DartUI.openInEditor((com.google.dart.engine.element.Element) selectedElement);
     } catch (CoreException ex) {
       DartToolsPlugin.log(ex);
     }
     dispose();
   }
   if (selectedElement instanceof com.google.dart.server.generated.types.Element) {
     try {
       DartUI.openInEditor((com.google.dart.server.generated.types.Element) selectedElement, true);
     } catch (Exception ex) {
       DartToolsPlugin.log(ex);
     }
     dispose();
   }
 }
Пример #4
0
  private static IEditorPart openInEditor(IFile file, boolean activate) throws PartInitException {

    UIInstrumentationBuilder instrumentation =
        UIInstrumentation.builder("EditorUtility.openInEditor-IFile");
    try {

      if (file == null) {
        throwPartInitException(DartEditorMessages.EditorUtility_file_must_not_be_null);
      }

      instrumentation.data("FileName", file.getName());
      instrumentation.data("FilePath", file.getFullPath().toOSString());
      instrumentation.metric("activate", activate);

      IWorkbenchPage p = DartToolsPlugin.getActivePage();
      if (p == null) {
        throwPartInitException(DartEditorMessages.EditorUtility_no_active_WorkbenchPage);
      }

      IEditorDescriptor desc = IDE.getEditorDescriptor(file, true);

      String editorId = desc.getId();
      boolean isTooComplex = false;
      editorId = maybeSwapDefaultEditorDescriptor(editorId);
      if (DartUI.isTooComplexDartFile(file)) {
        isTooComplex = true;
        editorId = EditorsUI.DEFAULT_TEXT_EDITOR_ID;
      }

      IEditorPart editor = IDE.openEditor(p, file, editorId, activate);
      if (isTooComplex) {
        DartUI.showTooComplexDartFileWarning(editor);
      }
      initializeHighlightRange(editor);
      return editor;
    } catch (RuntimeException e) {
      instrumentation.metric("Exception", e.getClass().toString());
      instrumentation.data("Exception", e.toString());
      throw e;
    } finally {
      instrumentation.log();
    }
  }
Пример #5
0
  /**
   * Returns the given editor's input as Dart element.
   *
   * <p>To replace {@link #getEditorInputDartElement(IEditorPart, boolean)}
   *
   * @param editor the editor
   * @param primaryOnly if <code>true</code> only primary working copies will be returned
   * @return the given editor's input as Dart element or <code>null</code> if none
   */
  public static Element getEditorInputDartElement2(IEditorPart editor, boolean primaryOnly) {

    Assert.isNotNull(editor);

    IEditorInput editorInput = editor.getEditorInput();
    if (editorInput == null) {
      return null;
    }

    Element element = DartUI.getEditorInputDartElement2(editorInput);
    if (element != null || primaryOnly) {
      return element;
    }

    return null;
  }
 @Override
 public void run(IMarker marker) {
   try {
     IEditorPart part = EditorUtility.isOpenInEditor(unit);
     if (part == null) {
       part = DartUI.openInEditor(unit, true, false);
       if (part instanceof ITextEditor) {
         ((ITextEditor) part).selectAndReveal(offset, length);
       }
     }
     if (part != null) {
       IEditorInput input = part.getEditorInput();
       IDocument doc = getDocumentProvider().getDocument(input);
       proposal.apply(doc);
     }
   } catch (CoreException e) {
     DartToolsPlugin.log(e);
   }
 }
Пример #7
0
  /**
   * Opens a type selection dialog. If the user selects a type (and does not cancel), an editor is
   * opened on the selected type.
   *
   * @see org.eclipse.jface.action.Action#runWithEvent(org.eclipse.swt.widgets.Event)
   */
  @Override
  public void runWithEvent(Event e) {
    Shell parent = DartToolsPlugin.getActiveWorkbenchShell();
    if (!doCreateProjectFirstOnEmptyWorkspace(parent)) {
      return;
    }

    SelectionDialog dialog =
        new OpenTypeSelectionDialog(
            parent,
            true,
            PlatformUI.getWorkbench().getProgressService(),
            null,
            SEARCH_ELEMENT_KINDS);
    dialog.setTitle(DartUIMessages.OpenTypeAction_dialogTitle);
    dialog.setMessage(DartUIMessages.OpenTypeAction_dialogMessage);

    int result = dialog.open();
    if (result != IDialogConstants.OK_ID) {
      return;
    }

    Object[] types = dialog.getResult();
    if (types == null || types.length == 0) {
      return;
    }

    if (types.length == 1) {
      try {
        DartUI.openInEditor((Element) types[0], true, true);
      } catch (CoreException x) {
        ExceptionHandler.handle(
            x,
            DartUIMessages.OpenTypeAction_errorTitle,
            DartUIMessages.OpenTypeAction_errorMessage);
      }
      return;
    }

    final IWorkbenchPage workbenchPage = DartToolsPlugin.getActivePage();
    if (workbenchPage == null) {
      IStatus status =
          new Status(
              IStatus.ERROR,
              DartToolsPlugin.getPluginId(),
              DartUIMessages.OpenTypeAction_no_active_WorkbenchPage);
      ExceptionHandler.handle(
          status,
          DartUIMessages.OpenTypeAction_errorTitle,
          DartUIMessages.OpenTypeAction_errorMessage);
      return;
    }

    MultiStatus multiStatus =
        new MultiStatus(
            DartToolsPlugin.getPluginId(),
            DartStatusConstants.INTERNAL_ERROR,
            DartUIMessages.OpenTypeAction_multiStatusMessage,
            null);

    for (int i = 0; i < types.length; i++) {
      Type type = (Type) types[i];
      try {
        DartUI.openInEditor(type, true, true);
      } catch (CoreException x) {
        multiStatus.merge(x.getStatus());
      }
    }

    if (!multiStatus.isOK()) {
      ExceptionHandler.handle(
          multiStatus,
          DartUIMessages.OpenTypeAction_errorTitle,
          DartUIMessages.OpenTypeAction_errorMessage);
    }
  }
  public void testColorPrefs() throws Exception {
    IPreferenceStore store = PreferenceConstants.getPreferenceStore();
    PreferenceConstants.initializeDefaultValues(store);

    // openTestEditor("");
    fail("Open test editor");

    IPreferenceStore prefs = testEditor.getPreferences();
    Display display = testEditor.getViewer().getTextWidget().getDisplay();
    Color ebg = DartUI.getEditorBackground(prefs, display);
    Color efg = DartUI.getEditorForeground(prefs, display);
    Color esbg = DartUI.getEditorSelectionBackground(prefs, display);
    Color esfg = DartUI.getEditorSelectionForeground(prefs, display);
    assertNull(ebg);
    assertNull(efg);
    assertNull(esbg);
    assertNull(esfg);
    // simulate changing theme
    store.putValue("AbstractTextEditor.Color.Foreground.SystemDefault", "false");
    store.putValue("AbstractTextEditor.Color.Background.SystemDefault", "false");
    store.putValue("AbstractTextEditor.Color.SelectionBackground.SystemDefault", "false");
    store.putValue("AbstractTextEditor.Color.SelectionForeground.SystemDefault", "false");
    store.putValue("AbstractTextEditor.Color.Foreground", "0,0,0");
    store.putValue("AbstractTextEditor.Color.Background", "1,1,1");
    store.putValue("AbstractTextEditor.Color.SelectionForeground", "10,10,10");
    store.putValue("AbstractTextEditor.Color.SelectionBackground", "11,11,11");
    ebg = DartUI.getEditorBackground(prefs, display);
    efg = DartUI.getEditorForeground(prefs, display);
    esbg = DartUI.getEditorSelectionBackground(prefs, display);
    esfg = DartUI.getEditorSelectionForeground(prefs, display);
    assertNotNull(ebg);
    assertNotNull(efg);
    assertNotNull(esbg);
    assertNotNull(esfg);
    // simulate restoring defaults
    store.setToDefault("AbstractTextEditor.Color.Foreground.SystemDefault");
    store.setToDefault("AbstractTextEditor.Color.Background.SystemDefault");
    store.setToDefault("AbstractTextEditor.Color.SelectionBackground.SystemDefault");
    store.setToDefault("AbstractTextEditor.Color.SelectionForeground.SystemDefault");
    store.setToDefault("AbstractTextEditor.Color.Foreground");
    store.setToDefault("AbstractTextEditor.Color.Background");
    store.setToDefault("AbstractTextEditor.Color.SelectionForeground");
    store.setToDefault("AbstractTextEditor.Color.SelectionBackground");
    ebg = DartUI.getEditorBackground(prefs, display);
    efg = DartUI.getEditorForeground(prefs, display);
    esbg = DartUI.getEditorSelectionBackground(prefs, display);
    esfg = DartUI.getEditorSelectionForeground(prefs, display);
    assertNull(ebg);
    assertNull(efg);
    assertNull(esbg);
    assertNull(esfg);
  }
Пример #9
0
  public DartDocHelpContext(IContext context, Object[] elements) throws DartModelException {
    Assert.isNotNull(elements);
    if (context instanceof IContext2) {
      fTitle = ((IContext2) context).getTitle();
    }

    List<IHelpResource> helpResources = new ArrayList<IHelpResource>();

    String javadocSummary = null;
    for (int i = 0; i < elements.length; i++) {
      if (elements[i] instanceof DartElement) {
        DartElement element = (DartElement) elements[i];
        // if element isn't on the build path skip it
        if (!ActionUtil.isOnBuildPath(element)) {
          continue;
        }

        // Create Javadoc summary
        if (BUG_85719_FIXED) {
          if (javadocSummary == null) {
            javadocSummary = retrieveText(element);
            if (javadocSummary != null) {
              String elementLabel =
                  DartElementLabels.getTextLabel(element, DartElementLabels.ALL_DEFAULT);

              // FIXME: needs to be NLSed once the code becomes active
              javadocSummary =
                  "<b>DartDoc for "
                      + elementLabel
                      + ":</b><br>"
                      + javadocSummary; //$NON-NLS-1$//$NON-NLS-2$
            }
          } else {
            javadocSummary = ""; // no Javadoc summary for multiple selection //$NON-NLS-1$
          }
        }

        URL url = DartUI.getDartDocLocation(element, true);
        if (url == null || doesNotExist(url)) {
          DartX.todo();
          //          IPackageFragmentRoot root = DartModelUtil.getPackageFragmentRoot(element);
          //          if (root != null) {
          //            url = DartUI.getJSdocBaseLocation(element);
          //            if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
          //              element = element.getDartProject();
          //            } else {
          //              element = root;
          //            }
          //            url = DartUI.getJSdocLocation(element, false);
          //          }
        }
        if (url != null) {
          IHelpResource javaResource = new JavaUIHelpResource(element, getURLString(url));
          helpResources.add(javaResource);
        }
      }
    }

    // Add static help topics
    if (context != null) {
      IHelpResource[] resources = context.getRelatedTopics();
      if (resources != null) {
        for (int j = 0; j < resources.length; j++) {
          helpResources.add(resources[j]);
        }
      }
    }

    fHelpResources = helpResources.toArray(new IHelpResource[helpResources.size()]);

    if (context != null) {
      fText = context.getText();
    }

    if (BUG_85719_FIXED) {
      if (javadocSummary != null && javadocSummary.length() > 0) {
        if (fText != null) {
          fText = context.getText() + "<br><br>" + javadocSummary; // $NON-NLS-1$
        } else {
          fText = javadocSummary;
        }
      }
    }

    if (fText == null) {
      fText = ""; // $NON-NLS-1$
    }
  }