예제 #1
0
 /**
  * Constructor
  *
  * @param editor The editor on which this Add Include action should operate.
  */
 public AddIncludeAction(ITextEditor editor) {
   super(CEditorMessages.getBundleForConstructedKeys(), "AddInclude.", editor); // $NON-NLS-1$
   CUIPlugin.getDefault()
       .getWorkbench()
       .getHelpSystem()
       .setHelp(this, ICHelpContextIds.ADD_INCLUDE_ON_SELECTION_ACTION);
   final Shell shell = editor.getEditorSite().getShell();
   fAmbiguityResolver =
       new IElementSelector() {
         @SuppressWarnings("unchecked")
         @Override
         public <T> T selectElement(final Collection<T> elements) {
           final Object[] result = new Object[1];
           runInUIThread(
               new Runnable() {
                 @Override
                 public void run() {
                   ElementListSelectionDialog dialog =
                       new ElementListSelectionDialog(shell, new LabelProvider());
                   dialog.setElements(elements.toArray());
                   dialog.setTitle(CEditorMessages.AddInclude_label);
                   dialog.setMessage(CEditorMessages.AddInclude_description);
                   if (dialog.open() == Window.OK) result[0] = dialog.getFirstResult();
                 }
               });
           return (T) result[0];
         }
       };
 }
 @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);
   }
 }
예제 #3
0
 /** Adds a listener for problem marker changes. */
 public void addListener(IProblemChangedListener listener) {
   if (fListeners.isEmpty()) {
     CUIPlugin.getWorkspace().addResourceChangeListener(this);
     CUIPlugin.getDefault().getDocumentProvider().addGlobalAnnotationModelListener(this);
   }
   fListeners.add(listener);
 }
예제 #4
0
 /** Removes a <code>IProblemChangedListener</code>. */
 public void removeListener(IProblemChangedListener listener) {
   fListeners.remove(listener);
   if (fListeners.isEmpty()) {
     CUIPlugin.getWorkspace().removeResourceChangeListener(this);
     CUIPlugin.getDefault().getDocumentProvider().removeGlobalAnnotationModelListener(this);
   }
 }
예제 #5
0
 @Override
 public final void run() {
   if (saveRequired) {
     EclipseObjects.getActivePage().saveAllEditors(true);
     if (EclipseObjects.getActivePage().getDirtyEditors().length != 0) {
       return;
     }
   }
   if (fEditor != null) {
     ISelectionProvider provider = fEditor.getSelectionProvider();
     if (provider != null) {
       ISelection s = provider.getSelection();
       if (s instanceof ITextSelection) {
         IWorkingCopy wc =
             CUIPlugin.getDefault()
                 .getWorkingCopyManager()
                 .getWorkingCopy(fEditor.getEditorInput());
         if (wc != null) run(fEditor.getSite(), wc, (ITextSelection) s);
       }
     }
   } else if (fSite != null) {
     if (fElement != null) {
       run(fSite, fElement);
     }
   }
 }
  private Control createPreviewer(Composite parent) {
    IPreferenceStore generalTextStore = EditorsUI.getPreferenceStore();
    IPreferenceStore store =
        new ChainedPreferenceStore(new IPreferenceStore[] {getPreferenceStore(), generalTextStore});
    fPreviewViewer =
        new CSourceViewer(
            parent, null, null, false, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER, store);
    SimpleCSourceViewerConfiguration configuration =
        new SimpleCSourceViewerConfiguration(
            fColorManager, store, null, ICPartitions.C_PARTITIONING, false);
    fPreviewViewer.configure(configuration);
    Font font = JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT);
    fPreviewViewer.getTextWidget().setFont(font);
    CSourcePreviewerUpdater.registerPreviewer(fPreviewViewer, configuration, store);
    fPreviewViewer.setEditable(false);

    String content = loadPreviewContentFromFile("ColorSettingPreviewCode.txt"); // $NON-NLS-1$
    IDocument document = new Document(content);
    CUIPlugin.getDefault()
        .getTextTools()
        .setupCDocumentPartitioner(document, ICPartitions.C_PARTITIONING, null);
    fPreviewViewer.setDocument(document);

    installSemanticHighlighting();

    return fPreviewViewer.getControl();
  }
예제 #7
0
 /**
  * Returns the dialog settings object used to save state for this dialog.
  *
  * @return the dialog settings to be used
  */
 protected IDialogSettings getDialogSettings() {
   IDialogSettings allSettings = CUIPlugin.getDefault().getDialogSettings();
   IDialogSettings section = allSettings.getSection(fDialogSection);
   if (section == null) {
     section = allSettings.addNewSection(fDialogSection);
     writeDefaultSettings(section);
   }
   return section;
 }
예제 #8
0
 private boolean isWorkbenchReady() {
   IWorkbenchPage activePage = window.getActivePage();
   if (activePage == null) return false;
   IEditorPart editor = activePage.getActiveEditor();
   if (editor == null || editor.getEditorInput() == null) return false;
   IWorkingCopy wc =
       CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(editor.getEditorInput());
   if (wc == null) return false;
   project = wc.getCProject();
   file = (IFile) wc.getResource();
   return project != null && file != null;
 }
예제 #9
0
 /**
  * @param language
  * @param storage
  * @param textViewer
  */
 public CSourcePresentationCreator(ILanguage language, IStorage storage, ITextViewer textViewer) {
   if (language != null) {
     fViewer = textViewer;
     fPreferenceStore = CUIPlugin.getDefault().getCombinedPreferenceStore();
     final IColorManager colorManager = CDTUITools.getColorManager();
     fSourceViewerConfiguration =
         new CustomCSourceViewerConfiguration(colorManager, fPreferenceStore, language);
     setDocumentPartitioning(fSourceViewerConfiguration.getConfiguredDocumentPartitioning(null));
     initializeDamagerRepairer(storage, colorManager, fPreferenceStore);
     fPreferenceStore.addPropertyChangeListener(this);
   }
 }
  private void valueChanged(boolean on, boolean store) {
    setChecked(on);
    fTreeViewer.setSorter(on ? fSorter : null);

    String key =
        ACTION_NAME + ".tooltip" + (on ? ".on" : ".off"); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    setToolTipText(CUIPlugin.getResourceString(key));

    if (store) {
      CUIPlugin.getDefault().getDialogSettings().put(DIALOG_STORE_KEY, on);
    }
  }
  public LexicalSortingAction(TreeViewer treeViewer) {
    super(CUIPlugin.getResourceString(ACTION_NAME + ".label")); // $NON-NLS-1$

    setDescription(CUIPlugin.getResourceString(ACTION_NAME + ".description")); // $NON-NLS-1$
    setToolTipText(CUIPlugin.getResourceString(ACTION_NAME + ".tooltip")); // $NON-NLS-1$

    MakeUIImages.setImageDescriptors(
        this, MakeUIImages.T_TOOL, MakeUIImages.IMG_TOOLS_ALPHA_SORTING);

    fTreeViewer = treeViewer;
    fSorter = new LexicalCSorter();

    boolean checked = CUIPlugin.getDefault().getDialogSettings().getBoolean(DIALOG_STORE_KEY);
    valueChanged(checked, false);
  }
  @Override
  public void createControl(Composite parent) {
    PixelConverter converter = new PixelConverter(parent);

    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));

    LayoutUtil.doDefaultLayout(
        composite, new DialogField[] {fIncludeSymPathsList, fShowInheritedPaths}, true);
    LayoutUtil.setHorizontalGrabbing(fIncludeSymPathsList.getTreeControl(null), true);

    int buttonBarWidth = converter.convertWidthInCharsToPixels(24);
    fIncludeSymPathsList.setButtonsMinWidth(buttonBarWidth);
    setControl(composite);
    fIncludeSymPathsList.getTreeViewer().addFilter(fFilter);
    CUIPlugin.getDefault()
        .getWorkbench()
        .getHelpSystem()
        .setHelp(composite, ICHelpContextIds.PROJECT_INCLUDE_PATHS_SYMBOLS);
  }
  public CPElementLabelProvider(boolean showExported, boolean showParentInfo) {
    fNewLabel = CPathEntryMessages.CPElementLabelProvider_new;
    fCreateLabel = CPathEntryMessages.CPElementLabelProvider_willbecreated;
    fRegistry = CUIPlugin.getImageDescriptorRegistry();

    fLibIcon = CDTSharedImages.getImageDescriptor(CDTSharedImages.IMG_OBJS_ARCHIVE);
    fLibWSrcIcon = CDTSharedImages.getImageDescriptor(CDTSharedImages.IMG_OBJS_ARCHIVE);
    fIncludeIcon = CDTSharedImages.getImageDescriptor(CDTSharedImages.IMG_OBJS_INCLUDES_FOLDER);
    fQuoteIncludeIcon =
        CDTSharedImages.getImageDescriptor(CDTSharedImages.IMG_OBJS_QUOTE_INCLUDES_FOLDER);
    fIncludeFileIcon = CDTSharedImages.getImageDescriptor(CDTSharedImages.IMG_OBJS_TUNIT_HEADER);
    fMacroIcon = CDTSharedImages.getImageDescriptor(CDTSharedImages.IMG_OBJS_MACRO);
    fMacrosFileIcon = CDTSharedImages.getImageDescriptor(CDTSharedImages.IMG_OBJS_TUNIT_HEADER);
    fFolderImage = CDTSharedImages.getImageDescriptor(CDTSharedImages.IMG_OBJS_SOURCE_ROOT);
    fOutputImage = CDTSharedImages.getImageDescriptor(CDTSharedImages.IMG_OBJS_CONTAINER);
    fContainerImage = CDTSharedImages.getImageDescriptor(CDTSharedImages.IMG_OBJS_LIBRARY);

    IWorkbench workbench = CUIPlugin.getDefault().getWorkbench();

    fProjectImage =
        workbench.getSharedImages().getImageDescriptor(IDE.SharedImages.IMG_OBJ_PROJECT);
    bShowExported = showExported;
    bShowParentInfo = showParentInfo;
  }
예제 #14
0
 /** @deprecated, use {@link #getPreferenceStore()}, instead. */
 @Override
 @Deprecated
 public org.eclipse.core.runtime.Preferences getPreferences() {
   return CUIPlugin.getDefault().getPluginPreferences();
 }
예제 #15
0
 /**
  * Returns the translation unit of the given editor.
  *
  * @param editor The editor.
  * @return The translation unit.
  */
 private static ITranslationUnit getTranslationUnit(ITextEditor editor) {
   if (editor == null) {
     return null;
   }
   return CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(editor.getEditorInput());
 }
예제 #16
0
 @Override
 public IPreferenceStore getPreferenceStore() {
   return CUIPlugin.getDefault().getPreferenceStore();
 }
예제 #17
0
 /**
  * There are 2 ways to perform OK for CDT property pages. 1st (default): All pages use the same
  * editable copy of ICProjectDescription. When OK occurs, this object is simply set.
  *
  * <p>2nd: When OK occurs, each page must copy its data to new instance of ICProjectDescription,
  * like it occurs during Apply event. It allows to avoid collisions with other property pages,
  * which do not share ICProjectDescription instance. But some changes may be saved wrong if they
  * are affected by data from another property pages (Discovery options etc).
  *
  * <p>To enable 2nd mode, just create the following file:
  * <workspace>/.metadata/.plugins/org.eclipse.cdt.ui/apply_mode
  */
 @Override
 public boolean performOk() {
   File f = CUIPlugin.getDefault().getStateLocation().append("apply_mode").toFile(); // $NON-NLS-1$
   if (f.exists()) return performSave(SAVE_MODE_APPLYOK);
   return performSave(SAVE_MODE_OK);
 }
예제 #18
0
 public IncludeStylePreferencePage() {
   setPreferenceStore(CUIPlugin.getDefault().getPreferenceStore());
   // Only used when the page is shown programmatically.
   setTitle(PreferencesMessages.IncludeStylePreferencePage_title);
 }
예제 #19
0
  /**
   * Inspects the context of the compilation unit around <code>completionPosition</code> and feeds
   * the collector with proposals.
   *
   * @param viewer the text viewer
   * @param completionPosition the context position in the document of the text viewer
   * @param translationUnit the translation unit (may be <code>null</code>)
   */
  public void complete(
      ITextViewer viewer, int completionPosition, ITranslationUnit translationUnit) {
    if (!(fContextType instanceof TranslationUnitContextType)) return;

    IDocument document = viewer.getDocument();
    Point selection = viewer.getSelectedRange();
    boolean linesSelected = areLinesSelected(viewer);
    boolean showLineSelectionTemplates = linesSelected;
    boolean showWordSelectionTemplates = !linesSelected || isOnlyWordOnLine(viewer);
    if (linesSelected) {
      // adjust line selection to start at column 1 and end at line delimiter
      try {
        IRegion startLine = document.getLineInformationOfOffset(selection.x);
        IRegion endLine = document.getLineInformationOfOffset(selection.x + selection.y - 1);
        completionPosition = selection.x = startLine.getOffset();
        selection.y = endLine.getOffset() + endLine.getLength() - startLine.getOffset();
      } catch (BadLocationException exc) {
      }
    }
    Position position = new Position(completionPosition, selection.y);

    // remember selected text
    String selectedText = null;
    if (selection.y != 0) {
      try {
        selectedText = document.get(selection.x, selection.y);
        document.addPosition(position);
        fPositions.put(document, position);
      } catch (BadLocationException e) {
      }
    }

    TranslationUnitContext context =
        ((TranslationUnitContextType) fContextType)
            .createContext(document, position, translationUnit);
    context.setVariable("selection", selectedText); // $NON-NLS-1$
    int start = context.getStart();
    int end = context.getEnd();
    IRegion region = new Region(start, end - start);

    Template[] templates = CUIPlugin.getDefault().getTemplateStore().getTemplates();

    Image image = CDTSharedImages.getImage(CDTSharedImages.IMG_OBJS_TEMPLATE);
    if (selection.y == 0) {
      for (int i = 0; i != templates.length; i++)
        if (context.canEvaluate(templates[i]))
          fProposals.add(new CTemplateProposal(templates[i], context, region, image));

    } else {

      if (linesSelected || context.getKey().length() == 0) context.setForceEvaluation(true);

      for (int i = 0; i != templates.length; i++) {
        Template template = templates[i];
        if (context.canEvaluate(template)
            && template.getContextTypeId().equals(context.getContextType().getId())
            && ((showWordSelectionTemplates && template.getPattern().indexOf($_WORD_SELECTION) != -1
                || (showLineSelectionTemplates
                    && template.getPattern().indexOf($_LINE_SELECTION) != -1)))) {
          fProposals.add(new CTemplateProposal(templates[i], context, region, image));
        }
      }
    }
  }