private void editorOpened(IEditorPart part) { if (part instanceof AbstractTextEditor) { AbstractTextEditor editor = (AbstractTextEditor) part; ApplyEditorConfig apply = applies.get(editor); if (apply == null) { try { apply = new ApplyEditorConfig(editor); apply.install(); applies.put(editor, apply); } catch (Exception e) { e.printStackTrace(); return; } } apply.applyConfig(); } }
public void findClass(String className){ setLinkToEditor(getEditor()); String resource = removeExt(getResource(getEditor()).getName()); String ext = getResource(getEditor()).getFileExtension(); String classNameToFind = (ext == null) ? className : className+"."+ext; if (!resource.equals(className)){ IContainer parent = getResource(getEditor()).getParent(); IResource file = parent.findMember(classNameToFind); try { setLinkToEditor((AbstractTextEditor)SootPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(new FileEditorInput((IFile)file), file.getName())); } catch (PartInitException e){ } } }
/** * Creates a new TexlipseAnnotationUpdater and adds itself to the TexEditor via * <code>addPostSelectionChangedListener</code> * @param editor The TexEditor */ public TexlipseAnnotationUpdater (AbstractTextEditor editor) { //Add this listener to the current editors IPostSelectionListener (lazy update) ((IPostSelectionProvider) editor.getSelectionProvider()).addPostSelectionChangedListener(this); fEditor = editor; fEnabled = TexlipsePlugin.getDefault().getPreferenceStore().getBoolean( TexlipseProperties.TEX_EDITOR_ANNOTATATIONS); //Add a PropertyChangeListener TexlipsePlugin.getDefault().getPreferenceStore().addPropertyChangeListener(new IPropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { String property = event.getProperty(); if (TexlipseProperties.TEX_EDITOR_ANNOTATATIONS.equals(property)) { boolean enabled = TexlipsePlugin.getDefault().getPreferenceStore().getBoolean( TexlipseProperties.TEX_EDITOR_ANNOTATATIONS); fEnabled = enabled; } } }); }
private void configurePreferenceKeys() { preferenceKeysForEnablement = new HashSet<>(); preferenceKeysForActivation = new HashSet<>(); // Global settings (master switch) preferenceKeysForEnablement .add(AbstractTextEditor.PREFERENCE_HYPERLINKS_ENABLED); preferenceKeysForActivation .add(AbstractTextEditor.PREFERENCE_HYPERLINK_KEY_MODIFIER); // All applicable individual hyperlink detectors settings. Map targets = configuration.getHyperlinkDetectorTargets(this); for (HyperlinkDetectorDescriptor desc : EditorsUI .getHyperlinkDetectorRegistry() .getHyperlinkDetectorDescriptors()) { if (targets.keySet().contains(desc.getTargetId())) { preferenceKeysForEnablement.add(desc.getId()); preferenceKeysForActivation.add(desc.getId() + HyperlinkDetectorDescriptor.STATE_MASK_POSTFIX); } } }
private IHyperlinkDetector[] getHyperlinkDetectors() { IHyperlinkDetector[] allDetectors; IHyperlinkDetector[] configuredDetectors = configuration .getHyperlinkDetectors(viewer); if (configuredDetectors == null || configuredDetectors.length == 0) { allDetectors = new IHyperlinkDetector[0]; } else if (preferenceStore.getBoolean(URL_HYPERLINK_DETECTOR_KEY) || !preferenceStore.getBoolean( AbstractTextEditor.PREFERENCE_HYPERLINKS_ENABLED)) { allDetectors = configuredDetectors; } else { allDetectors = new IHyperlinkDetector[configuredDetectors.length + 1]; System.arraycopy(configuredDetectors, 0, allDetectors, 0, configuredDetectors.length); // URLHyperlinkDetector can only detect hyperlinks at the start of // the range. We need one that can detect all hyperlinks in a given // region. allDetectors[configuredDetectors.length] = new MultiURLHyperlinkDetector(); } return allDetectors; }
/** * */ public static void initDefaults(IPreferenceStore aStore) { PreferenceConverter.setDefault(aStore, AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND, Display.getDefault().getSystemColor(SWT.COLOR_LIST_FOREGROUND).getRGB()); aStore.setDefault(AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT, true); PreferenceConverter.setDefault(aStore, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND, Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB()); aStore.setDefault(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT, true); PreferenceConverter.setDefault(aStore, IPreferencesConstants.COLOR_DEFAULT, RGB_DEFAULT); PreferenceConverter.setDefault(aStore, IPreferencesConstants.COLOR_TAG, RGB_DIRECTIVE); PreferenceConverter.setDefault(aStore, IPreferencesConstants.COLOR_SCRIPT, RGB_SCRIPT); PreferenceConverter.setDefault(aStore, IPreferencesConstants.COLOR_COMMENT, RGB_COMMENT); PreferenceConverter.setDefault(aStore, IPreferencesConstants.COLOR_DOC_COMMENT, RGB_DOC_COMMENT); PreferenceConverter.setDefault(aStore, IPreferencesConstants.COLOR_DIRECTIVE, RGB_DIRECTIVE); PreferenceConverter.setDefault(aStore, IPreferencesConstants.COLOR_STRING, RGB_STRING); PreferenceConverter.setDefault(aStore, IPreferencesConstants.COLOR_REFERENCE, RGB_REFERENCE); PreferenceConverter.setDefault(aStore, IPreferencesConstants.COLOR_STRING_REFERENCE, RGB_STRING_REFERENCE); PreferenceConverter.setDefault(aStore, IPreferencesConstants.COLOR_RGB_HTML_String, RGB_HTML_String); PreferenceConverter.setDefault(aStore, IPreferencesConstants.COLOR_RGB_HTML_ENDTAG, RGB_HTML_ENDTAG); PreferenceConverter.setDefault(aStore, IPreferencesConstants.COLOR_RGB_HTML_TAG, RGB_HTML_TAG); PreferenceConverter.setDefault(aStore, IPreferencesConstants.COLOR_RGB_HTML_ATTRIBUTE, RGB_HTML_ATTRIBUTE); }
/** * Set the FG, BG, selection and current line colors on our editors. * * @param theme */ private void setAptanaEditorColorsToMatchTheme(Theme theme) { IEclipsePreferences prefs = EclipseUtil.instanceScope().getNode("com.aptana.editor.common"); //$NON-NLS-1$ prefs.putBoolean(AbstractTextEditor.PREFERENCE_COLOR_SELECTION_FOREGROUND_SYSTEM_DEFAULT, false); prefs.put(AbstractTextEditor.PREFERENCE_COLOR_SELECTION_FOREGROUND, toString(theme.getForeground())); prefs.putBoolean(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT, false); prefs.put(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND, toString(theme.getBackground())); prefs.putBoolean(AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT, false); prefs.put(AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND, toString(theme.getForeground())); prefs.put(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE_COLOR, toString(theme.getLineHighlightAgainstBG())); try { prefs.flush(); } catch (BackingStoreException e) { IdeLog.logError(ThemePlugin.getDefault(), e); } }
public static ISourceViewer getSourceViewer(ITextEditor textEditor) { if (textEditor instanceof IThemeableEditor) { IThemeableEditor editor = (IThemeableEditor) textEditor; return editor.getISourceViewer(); } if (textEditor instanceof AbstractTextEditor) { try { Method m = AbstractTextEditor.class.getDeclaredMethod("getSourceViewer"); //$NON-NLS-1$ m.setAccessible(true); return (ISourceViewer) m.invoke(textEditor); } catch (Exception e) { // ignore } } return null; }
public void handlePreferenceStoreChanged(PropertyChangeEvent event) { if (event.getProperty().equals(IThemeManager.THEME_CHANGED)) { IThemeableEditor editor = this.fEditor.get(); overrideThemeColors(); if (editor != null) { editor.getISourceViewer().invalidateTextPresentation(); } } else if (event.getProperty().equals(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE)) { Object newValue = event.getNewValue(); if (newValue instanceof Boolean) { boolean on = (Boolean) newValue; fFullLineBackgroundPainter.setHighlightLineEnabled(on); } } else if (event.getProperty().equals(AbstractTextEditor.PREFERENCE_COLOR_SELECTION_BACKGROUND_SYSTEM_DEFAULT)) { overrideRulerColors(); } }
/** * Returns <code>null</code> if {@link SWT#COLOR_INFO_BACKGROUND} is visibly distinct from the * default Java source text color. Otherwise, returns the editor background color. * * @param display the display * @return an RGB or <code>null</code> * @since 3.6.1 */ public static RGB getVisibleBackgroundColor(Display display) { float[] infoBgHSB= display.getSystemColor(SWT.COLOR_INFO_BACKGROUND).getRGB().getHSB(); Color javaDefaultColor= JavaUI.getColorManager().getColor(IJavaColorConstants.JAVA_DEFAULT); RGB javaDefaultRGB= javaDefaultColor != null ? javaDefaultColor.getRGB() : new RGB(255, 255, 255); float[] javaDefaultHSB= javaDefaultRGB.getHSB(); if (Math.abs(infoBgHSB[2] - javaDefaultHSB[2]) < 0.5f) { // workaround for dark tooltip background color, see https://bugs.eclipse.org/309334 IPreferenceStore preferenceStore= JavaPlugin.getDefault().getCombinedPreferenceStore(); boolean useDefault= preferenceStore.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT); if (useDefault) return display.getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB(); return PreferenceConverter.getColor(preferenceStore, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND); } return null; }
@Override public void partActivated(IWorkbenchPartReference partRef) { IEditorPart part = partRef.getPage().getActiveEditor(); if (!(part instanceof AbstractTextEditor)) return; // log new active file IEditorInput input = part.getEditorInput(); if (input instanceof IURIEditorInput) { URI uri = ((IURIEditorInput)input).getURI(); if (uri != null && uri.getPath() != null) { String currentFile = uri.getPath(); long currentTime = System.currentTimeMillis() / 1000; if (!currentFile.equals(WakaTime.getDefault().lastFile) || WakaTime.getDefault().lastTime + WakaTime.FREQUENCY * 60 < currentTime) { WakaTime.sendHeartbeat(currentFile, WakaTime.getActiveProject(), false); WakaTime.getDefault().lastFile = currentFile; WakaTime.getDefault().lastTime = currentTime; } } } }
public static Color getEclipseEditorForeground( ) { ScopedPreferenceStore preferenceStore = new ScopedPreferenceStore( InstanceScope.INSTANCE, "org.eclipse.ui.editors" );//$NON-NLS-1$ Color color = null; if ( preferenceStore != null ) { color = preferenceStore.getBoolean( AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT ) ? null : createColor( preferenceStore, AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND, Display.getCurrent( ) ); } if ( color == null ) { color = Display.getDefault( ) .getSystemColor( SWT.COLOR_LIST_FOREGROUND ); } return color; }
public static Color getEclipseEditorBackground( ) { ScopedPreferenceStore preferenceStore = new ScopedPreferenceStore( InstanceScope.INSTANCE, "org.eclipse.ui.editors" );//$NON-NLS-1$ Color color = null; if ( preferenceStore != null ) { color = preferenceStore.getBoolean( AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT ) ? null : createColor( preferenceStore, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND, Display.getCurrent( ) ); } if ( color == null ) { color = Display.getDefault( ) .getSystemColor( SWT.COLOR_LIST_BACKGROUND ); } return color; }
@Override public void pageChanged(PageChangedEvent event) { Object selectedPage = event.getSelectedPage(); if (seenPages.contains(selectedPage)) return; seenPages.add(selectedPage); if (selectedPage instanceof AbstractTextEditor) { IEditorPart editorPart = (IEditorPart) selectedPage; IProject project = plugin.getProjectForEditor(editorPart.getEditorInput()); if (plugin.getIgnoreProjectsList().contains(project.getName())) return; ISourceViewer sourceViewer = (ISourceViewer) editorPart.getAdapter(ITextOperationTarget.class); sourceViewer.getDocument().addDocumentListener(new DocumentListener()); } }
private IRegion getRegion(IDocument document, ILineRange lineRange) throws BadLocationException { final int startLine = lineRange.getStartLine(); int offset = document.getLineOffset(startLine); final int numberOfLines = lineRange.getNumberOfLines(); if (numberOfLines < 1) { return new Region(offset, 0); } int endLine = startLine + numberOfLines - 1; int endOffset; boolean blockSelectionModeEnabled = false; try { blockSelectionModeEnabled = ((AbstractTextEditor) getTextEditor()).isBlockSelectionModeEnabled(); } catch (Throwable e) { //Ignore (not available before 3.5) } if (blockSelectionModeEnabled) { // in block selection mode, don't select the last delimiter as we count an empty selected line IRegion endLineInfo = document.getLineInformation(endLine); endOffset = endLineInfo.getOffset() + endLineInfo.getLength(); } else { endOffset = document.getLineOffset(endLine) + document.getLineLength(endLine); } return new Region(offset, endOffset - offset); }
/** * @see IPropertyChangeListener#propertyChange(PropertyChangeEvent) */ @Override public void propertyChange(PropertyChangeEvent event) { String property = event.getProperty(); if (JFaceResources.TEXT_FONT.equals(property)) { updateViewerFont(); } if (AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND.equals(property) || AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT.equals(property) || AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND.equals(property) || AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT.equals(property)) { updateViewerColors(); } if (affectsTextPresentation(event)) { invalidateTextPresentation(); } }
/** * Updates the given viewer's colors to match the preferences. */ public void updateViewerColors() { IPreferenceStore store = getPreferenceStore(); if (store != null) { StyledText styledText = getTextWidget(); if (styledText == null || styledText.isDisposed()) { return; } Color color = store.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT) ? null : createColor(store, AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND, styledText.getDisplay()); styledText.setForeground(color); if (getForegroundColor() != null) { getForegroundColor().dispose(); } setForegroundColor(color); color = store.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT) ? null : createColor(store, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND, styledText.getDisplay()); styledText.setBackground(color); if (getBackgroundColor() != null) { getBackgroundColor().dispose(); } setBackgroundColor(color); } }
/** * Relies on protected final method {@link AbstractTextEditor#getSourceViewer()}. */ private static ISourceViewer fromAbstractTextEditor(AbstractTextEditor editor) { try { Method getSourceViewerMethod = null; Class<?> clazz = editor.getClass(); while (clazz != null && getSourceViewerMethod == null) { if (clazz.equals(AbstractTextEditor.class)) { getSourceViewerMethod = clazz.getDeclaredMethod("getSourceViewer"); } else { clazz = clazz.getSuperclass(); } } if (getSourceViewerMethod == null) { throw new RuntimeException(); } getSourceViewerMethod.setAccessible(true); ISourceViewer result = (ISourceViewer) getSourceViewerMethod.invoke(editor); return result; } catch (Exception e) { logger.error("Failed to acquire ISourceViewer via reflection", e); return null; } }
/** * Returns <code>null</code> if {@link SWT#COLOR_INFO_BACKGROUND} is visibly distinct from the * default Java source text color. Otherwise, returns the editor background color. * * @param display the display * @return an RGB or <code>null</code> * @since 3.6.1 */ public static RGB getVisibleBackgroundColor(Display display) { float[] infoBgHSB= display.getSystemColor(SWT.COLOR_INFO_BACKGROUND).getRGB().getHSB(); RGB javaDefaultRGB = EditorSettings_Actual.CODE_DEFAULT_COLOR.getFieldValue().rgb; float[] javaDefaultHSB= javaDefaultRGB.getHSB(); if (Math.abs(infoBgHSB[2] - javaDefaultHSB[2]) < 0.5f) { // workaround for dark tooltip background color, see https://bugs.eclipse.org/309334 IPreferenceStore preferenceStore= LangUIPlugin.getInstance().getCombinedPreferenceStore(); boolean useDefault= preferenceStore.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT); if (useDefault) return display.getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB(); return PreferenceConverter.getColor(preferenceStore, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND); } return null; }
@Override protected void doConfigureViewer() { // ----------- foreground color -------------------- fForegroundColor = updateColorFromSetting(fForegroundColor, AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT, AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND); styledText.setForeground(fForegroundColor); // ---------- background color ---------------------- fBackgroundColor = updateColorFromSetting(fBackgroundColor, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND); styledText.setBackground(fBackgroundColor); // ----------- selection foreground color -------------------- fSelectionForegroundColor = updateColorFromSetting(fSelectionForegroundColor, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_FOREGROUND_DEFAULT_COLOR, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_FOREGROUND_COLOR); styledText.setSelectionForeground(fSelectionForegroundColor); // ---------- selection background color ---------------------- fSelectionBackgroundColor = updateColorFromSetting(fSelectionBackgroundColor, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_BACKGROUND_DEFAULT_COLOR, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_BACKGROUND_COLOR); styledText.setSelectionBackground(fSelectionBackgroundColor); }
/** * Navigue vers l'objet (ouvre un éditeur et met le focus sur la région). * * @param navigable Objet navigable. */ public static void navigateTo(Navigable navigable) { IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); FileRegion fileRegion = navigable.getFileRegion(); try { IEditorPart openEditor = IDE.openEditor(activePage, fileRegion.getFile()); AbstractTextEditor editor = (AbstractTextEditor) openEditor; editor.selectAndReveal(fileRegion.getOffset(), fileRegion.getLength()); } catch (PartInitException e) { ErrorUtils.handle(e); } }
@Override protected boolean run(IMarker marker, AbstractTextEditor editor, IDocument doc) { int start = marker.getAttribute(IMarker.CHAR_START, -1); int end = marker.getAttribute(IMarker.CHAR_END, -1); StyledText text = (StyledText) editor.getAdapter(Control.class); text.getDisplay().syncExec(() -> { MarkerUtils.applyEdits(doc, new ReplaceEdit(start, end - start, "")); }); return true; }
@Override protected boolean run(IMarker marker, AbstractTextEditor editor, IDocument doc) { String delimiter = ((IDocumentExtension4) doc).getDefaultLineDelimiter(); int offset = marker.getAttribute(IMarker.CHAR_END, -1); StyledText text = (StyledText) editor.getAdapter(Control.class); text.getDisplay().syncExec(() -> { MarkerUtils.applyEdits(doc, new ReplaceEdit(offset, 0, delimiter)); }); return true; }
@Override public void partActivated(IWorkbenchPart part) { if (part instanceof AbstractTextEditor) { AbstractTextEditor editor = (AbstractTextEditor) part; ApplyEditorConfig apply = applies.get(editor); if (apply != null) { apply.applyConfig(); } } }
private void editorClosed(IEditorPart part) { if (part instanceof AbstractTextEditor) { ApplyEditorConfig apply = applies.remove(part); if (apply != null) { apply.uninstall(); Assert.isTrue(null == applies.get(part), "An old ApplyEditorConfig is not un-installed on Text Editor instance"); } } }
private static void setPreferenceStoreOfTextEditor(ITextEditor textEditor, IPreferenceStore preferenceStore) throws Exception { Method m = AbstractTextEditor.class.getDeclaredMethod("setPreferenceStore", new Class[] { IPreferenceStore.class }); m.setAccessible(true); m.invoke(textEditor, preferenceStore); }
private static void setPreferenceStoreOfSourceViewerConfiguration(ITextEditor textEditor, IPreferenceStore preferenceStore) throws Exception { Field f = AbstractTextEditor.class.getDeclaredField("fConfiguration"); f.setAccessible(true); SourceViewerConfiguration oldConfig = (SourceViewerConfiguration) f.get(textEditor); if (oldConfig instanceof TextSourceViewerConfiguration) { Field f2 = TextSourceViewerConfiguration.class.getDeclaredField("fPreferenceStore"); f2.setAccessible(true); f2.set(oldConfig, preferenceStore); } }
protected String getAttributes(AbstractTextEditor editor) { JavaAttributesComputer jac = new JavaAttributesComputer(); SootAttributesHandler handler = jac.getAttributesHandler(editor); if (handler != null){ return handler.getJavaAttribute(getLineNum()); } else { return null; } }
private void clearPres(){ if (getEditorPart() == null) return; if (getEditorPart().getEditorInput() != null){ getDisplay().syncExec(new Runnable(){ public void run() { IRegion reg = ((AbstractTextEditor)getEditorPart()).getHighlightRange(); ((AbstractTextEditor)getEditorPart()).setInput(getEditorPart().getEditorInput()); if (reg != null){ ((AbstractTextEditor)getEditorPart()).setHighlightRange(reg.getOffset(), reg.getLength(), true); } }; }); } }
private static int getConfiguredDefaultMask() { int mask = computeStateMask(EditorsUI.getPreferenceStore().getString( AbstractTextEditor.PREFERENCE_HYPERLINK_KEY_MODIFIER)); if (mask == -1) { // Fallback mask = EditorsUI.getPreferenceStore().getInt( AbstractTextEditor.PREFERENCE_HYPERLINK_KEY_MODIFIER_MASK); } return mask; }
protected void setActionsActivated(boolean state) { Method method = null; try { method = AbstractTextEditor.class.getDeclaredMethod("setActionActivation", new Class[] { boolean.class }); //$NON-NLS-1$ method.setAccessible(true); method.invoke(this, new Object[] { Boolean.valueOf(state) }); } catch (Exception exception) { throw new WrappedException(exception); } }
private void setSourceViewer(ITextEditor editor, SourceViewer viewer) { Field field = null; try { field = AbstractTextEditor.class.getDeclaredField("fSourceViewer"); //$NON-NLS-1$ field.setAccessible(true); field.set(editor, viewer); } catch (Exception exception) { throw new WrappedException(exception); } }
/** * @see IActionDelegate#run(IAction) */ public void run(IAction action) { try { // get editor IEditorPart editorPart = VariantSyncPlugin.getDefault() .getWorkbench().getActiveWorkbenchWindow().getActivePage() .getActiveEditor(); if (editorPart instanceof AbstractTextEditor) { int offset = 0; int length = 0; String selectedText = null; IEditorSite iEditorSite = editorPart.getEditorSite(); if (iEditorSite != null) { // get selection provider ISelectionProvider selectionProvider = iEditorSite .getSelectionProvider(); if (selectionProvider != null) { ISelection iSelection = selectionProvider .getSelection(); // offset offset = ((ITextSelection) iSelection).getOffset(); if (!iSelection.isEmpty()) { selectedText = ((ITextSelection) iSelection) .getText(); // length length = ((ITextSelection) iSelection).getLength(); MessageDialog.openInformation(shell, "Do Something Menu", "Length: " + length + " Offset: " + offset + "\n" + "Content: " + selectedText); } } } } } catch (Exception e) { } }
private static GamaColor getDefaultBackground() { EditorsPlugin.getDefault().getPreferenceStore() .setValue(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT, false); final RGB rgb = PreferenceConverter.getColor(EditorsPlugin.getDefault().getPreferenceStore(), AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND); return new GamaColor(rgb.red, rgb.green, rgb.blue); }
protected void setGeneralEditorValues(Theme theme, IEclipsePreferences prefs, boolean revertToDefaults) { if (prefs == null) return; if (revertToDefaults) { prefs.remove(AbstractTextEditor.PREFERENCE_COLOR_SELECTION_BACKGROUND); prefs.remove(AbstractTextEditor.PREFERENCE_COLOR_SELECTION_FOREGROUND); prefs.remove(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND); prefs.remove(AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND); prefs.remove(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE_COLOR); } else { prefs.put(AbstractTextEditor.PREFERENCE_COLOR_SELECTION_BACKGROUND, StringConverter.asString(theme.getSelectionAgainstBG())); prefs.put(AbstractTextEditor.PREFERENCE_COLOR_SELECTION_FOREGROUND, StringConverter.asString(theme.getForeground())); prefs.put(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND, StringConverter.asString(theme.getBackground())); prefs.put(AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND, StringConverter.asString(theme.getForeground())); prefs.put(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE_COLOR, StringConverter.asString(theme.getLineHighlightAgainstBG())); } prefs.putBoolean(AbstractTextEditor.PREFERENCE_COLOR_SELECTION_FOREGROUND_SYSTEM_DEFAULT, revertToDefaults); prefs.putBoolean(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT, revertToDefaults); prefs.putBoolean(AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT, revertToDefaults); try { prefs.flush(); } catch (BackingStoreException e) { IdeLog.logError(ThemePlugin.getDefault(), e); } }
protected void overrideSelectionColor(AbstractTextEditor editor) { try { if (Class.forName("com.aptana.editor.common.extensions.IThemeableEditor").isInstance(editor)) // we already handle our own editors //$NON-NLS-1$ { return; } } catch (ClassNotFoundException e1) { // ignore } ISourceViewer sourceViewer = null; try { Method m = AbstractTextEditor.class.getDeclaredMethod("getSourceViewer"); //$NON-NLS-1$ m.setAccessible(true); sourceViewer = (ISourceViewer) m.invoke(editor); } catch (Exception e) { // ignore } if (sourceViewer == null || sourceViewer.getTextWidget() == null) { return; } ThemePlugin.getDefault().getControlThemerFactory().apply((Viewer) sourceViewer); }
protected void hijackEditor(IEditorPart part, boolean revertToDefaults) { if (applyToAllEditors()) { return; } // FIXME This doesn't work on CompareEditor! if (part instanceof AbstractTextEditor) { overrideSelectionColor((AbstractTextEditor) part); } }
@Override public void selectionChanged(IWorkbenchPart part, ISelection selection) { removePostSelectionListener(); if (selection instanceof ITextSelection && part instanceof AbstractTextEditor) { selection = new StructuredSelection(new AdaptableTextSelection(getViewer(), (ITextSelection) selection)); sourcePart = (AbstractTextEditor) part; ((IPostSelectionProvider) sourcePart.getSelectionProvider()) .addPostSelectionChangedListener(selectionChangedListener); sourcePart.getSite().getPage().addPartListener(partListener); } super.selectionChanged(part, selection); }
public void propertyChange(PropertyChangeEvent event) { String property = event.getProperty(); if (AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND.equals(property) || AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT.equals(property) || AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND.equals(property) || AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT.equals(property) || AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_FOREGROUND_COLOR.equals(property) || AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_FOREGROUND_DEFAULT_COLOR.equals(property) || AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_BACKGROUND_COLOR.equals(property) || AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_BACKGROUND_DEFAULT_COLOR.equals(property)) { initializeViewerColors(); } }