/** * creates a new {@link TextStyle} instance and copies all the source fields */ public TextStyle copy() { return new TextStyle(this); }
protected TextAttribute createTextAttribute(String id, TextStyle defaultTextStyle) { TextStyle textStyle = new TextStyle(); preferencesAccessor.populateTextStyle(id, textStyle, defaultTextStyle); int style = textStyle.getStyle(); Font fontFromFontData = EditorUtils.fontFromFontData(textStyle.getFontData()); return new TextAttribute( EditorUtils.colorFromRGB(textStyle.getColor()), EditorUtils.colorFromRGB(textStyle.getBackgroundColor()), style, fontFromFontData); }
@Override public void applyStyles(TextStyle textStyle) { textStyle.strikeout = (xtextTextStyle.getStyle() & TextAttribute.STRIKETHROUGH) != 0; textStyle.underline = (xtextTextStyle.getStyle() & TextAttribute.UNDERLINE) != 0; if (xtextTextStyle.getFontData() == null && xtextTextStyle.getStyle() != org.eclipse.xtext.ui.editor.utils.TextStyle.DEFAULT_FONT_STYLE) { FontData fontData = new FontData(); fontData.setStyle(xtextTextStyle.getStyle()); xtextTextStyle.setFontData(fontData); } textStyle.font = fontFromFontData(xtextTextStyle.getFontData()); if (xtextTextStyle.getBackgroundColor() != null) textStyle.background = colorFromRGB(xtextTextStyle.getBackgroundColor()); textStyle.foreground = colorFromRGB(xtextTextStyle.getColor()); } }
@Override public IResource getLaunchableResource(IEditorPart editorpart) { final XtextEditor xtextEditor = EditorUtils.getXtextEditor(editorpart); if (xtextEditor != null) { return xtextEditor.getResource(); } return null; }
public Object execute(final ExecutionEvent event) throws ExecutionException { final XtextEditor xtextEditor = EditorUtils.getActiveXtextEditor(event); if (xtextEditor != null) { final IXtextDocument document = xtextEditor.getDocument(); document.readOnly(new IUnitOfWork.Void<XtextResource>() { @Override public void process(XtextResource state) throws Exception { final QuickOutlinePopup quickOutlinePopup = createPopup(xtextEditor.getEditorSite().getShell()); quickOutlinePopup.setEditor(xtextEditor); quickOutlinePopup.setInput(document); quickOutlinePopup.setEvent((Event) event.getTrigger()); quickOutlinePopup.open(); } }); } return null; }
public TextStyle punctuationTextStyle() { TextStyle textStyle = defaultTextStyle().copy(); return textStyle; }
public static Color colorFromRGB(RGB rgb) { if (rgb == null) return null; return colorFromString(StringConverter.asString(rgb)); }
protected void selectAndReveal(IEditorPart openEditor, final URI uri, final EReference crossReference, final int indexInList, final boolean select) { final XtextEditor xtextEditor = EditorUtils.getXtextEditor(openEditor); if (xtextEditor != null) { xtextEditor.getDocument().readOnly(new IUnitOfWork.Void<XtextResource>() { @Override public void process(XtextResource resource) throws Exception { if (resource != null) { EObject object = findEObjectByURI(uri, resource); if (object != null) { ITextRegion location = (crossReference != null) ? locationProvider .getSignificantTextRegion(object, crossReference, indexInList) : locationProvider.getSignificantTextRegion(object); if (select) { xtextEditor.selectAndReveal(location.getOffset(), location.getLength()); } else { xtextEditor.reveal(location.getOffset(), location.getLength()); } } } } }); } }
protected void refreshAttributes() { Collections.sort(highlightings, this); for (Triple<String, String, TextStyle> highlighting : highlightings) { preferenceStoreAccessor.populateTextStyle(highlighting.getFirst(), new TextStyle(), highlighting.getThird()); } }
@Override protected String getQualifiedName(ExecutionEvent event) { XtextEditor activeXtextEditor = EditorUtils.getActiveXtextEditor(event); if (activeXtextEditor == null) { return null; } final ITextSelection selection = getTextSelection(activeXtextEditor); return activeXtextEditor.getDocument().readOnly(new IUnitOfWork<String, XtextResource>() { public String exec(XtextResource xTextResource) throws Exception { EObject selectedElement = getSelectedName(selection, xTextResource); return getQualifiedName(selectedElement); } }); }
public TextStyle errorTextStyle() { TextStyle textStyle = defaultTextStyle().copy(); // textStyle.setColor(new RGB(255, 0, 0)); return textStyle; }
protected void selectAndReveal(IEditorPart openEditor, final URI uri, final EReference crossReference, final int indexInList, final boolean select) { final XtextEditor xtextEditor = EditorUtils.getXtextEditor(openEditor); if (xtextEditor != null) { if (uri.fragment() != null) { xtextEditor.getDocument().readOnly(new IUnitOfWork.Void<XtextResource>() { @Override public void process(XtextResource resource) throws Exception { if (resource != null) { EObject object = resource.getEObject(uri.fragment()); ITextRegion location = (crossReference != null) ? locationProvider.getSignificantTextRegion(object, crossReference, indexInList) : locationProvider.getSignificantTextRegion(object); if (select) { xtextEditor.selectAndReveal(location.getOffset(), location.getLength()); } else { xtextEditor.reveal(location.getOffset(), location.getLength()); } } } }); } } }
public Object execute(ExecutionEvent event) throws ExecutionException { try { XtextEditor editor = EditorUtils.getActiveXtextEditor(event); if (editor != null) { final ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection(); editor.getDocument().readOnly(new IUnitOfWork.Void<XtextResource>() { @Override public void process(XtextResource state) throws Exception { EObject target = eObjectAtOffsetHelper.resolveElementAt(state, selection.getOffset()); findReferences(target); } }); } } catch (Exception e) { LOG.error(Messages.FindReferencesHandler_3, e); } return null; }