@Override
 public void apply(IDocument document) {
   try {
     ITranslationUnit unit = getTranslationUnit();
     IEditorPart part = null;
     if (unit.getResource().exists()) {
       boolean canEdit = performValidateEdit(unit);
       if (!canEdit) {
         return;
       }
       part = EditorUtility.isOpenInEditor(unit);
       if (part == null) {
         part = EditorUtility.openInEditor(unit);
         if (part != null) {
           document =
               CUIPlugin.getDefault().getDocumentProvider().getDocument(part.getEditorInput());
         }
       }
       IWorkbenchPage page = CUIPlugin.getActivePage();
       if (page != null && part != null) {
         page.bringToTop(part);
       }
       if (part != null) {
         part.setFocus();
       }
     }
     performChange(part, document);
   } catch (CoreException e) {
     ExceptionHandler.handle(
         e,
         CorrectionMessages.TUCorrectionProposal_error_title,
         CorrectionMessages.TUCorrectionProposal_error_message);
   }
 }
示例#2
0
  @Override
  protected void showMatch(Match match, int currentOffset, int currentLength, boolean activate)
      throws PartInitException {
    if (!(match instanceof CSearchMatch)) return;

    try {
      Object element = ((CSearchMatch) match).getElement();
      IIndexFileLocation ifl = ((CSearchElement) element).getLocation();
      IPath path = IndexLocationFactory.getPath(ifl);
      IEditorPart editor = EditorUtility.openInEditor(path, null, activate);
      if (editor instanceof ITextEditor) {
        ITextEditor textEditor = (ITextEditor) editor;
        textEditor.selectAndReveal(currentOffset, currentLength);
      }
    } catch (CoreException e) {
      CUIPlugin.log(e);
    }
  }