/* * @see IPainter#paint(int) */ public void paint(int reason) { if (fViewer == null) { return; } if (fViewer.getDocument() == null) { deactivate(false); return; } // initialization if (!fIsActive) { StyledText textWidget = fViewer.getTextWidget(); textWidget.addLineBackgroundListener(this); textWidget.addPaintListener(this); fPositionManager.managePosition(fCurrentLine); fIsActive = true; } // This forces redraw of the line highlight if (updateHighlightLine()) { // clear last line // Fix the background colors for tokens that didn't have the same as line! if (isOpaque() && !fLastLine.isDeleted() && fViewer instanceof ITextViewerExtension2) { ITextViewerExtension2 ext = (ITextViewerExtension2) fViewer; try { ext.invalidateTextPresentation(fLastLine.getOffset(), fLastLine.getLength()); } catch (Exception e) { IdeLog.logError(CommonEditorPlugin.getDefault(), e); } } drawHighlightLine(fLastLine); // draw new line drawHighlightLine(fCurrentLine); } }
static { IContentTypeTranslator c = CommonEditorPlugin.getDefault().getContentTypeTranslator(); c.addTranslation( new QualifiedContentType(ICoffeeConstants.CONTENT_TYPE_COFFEE), new QualifiedContentType(ICoffeeScopeConstants.TOPLEVEL)); c.addTranslation( new QualifiedContentType(HEREDOC), new QualifiedContentType(ICoffeeScopeConstants.STRING_HEREDOC_SINGLE)); c.addTranslation( new QualifiedContentType(DOUBLE_HEREDOC), new QualifiedContentType(ICoffeeScopeConstants.STRING_HEREDOC_DOUBLE)); c.addTranslation( new QualifiedContentType(STRING_SINGLE), new QualifiedContentType(ICoffeeScopeConstants.STRING_SINGLE)); c.addTranslation( new QualifiedContentType(STRING_DOUBLE), new QualifiedContentType(ICoffeeScopeConstants.STRING_DOUBLE)); c.addTranslation( new QualifiedContentType(COMMAND), new QualifiedContentType(ICoffeeScopeConstants.COMMAND)); c.addTranslation( new QualifiedContentType(MULTILINE_COMMENT), new QualifiedContentType(ICoffeeScopeConstants.COMMENT_BLOCK)); c.addTranslation( new QualifiedContentType(SINGLELINE_COMMENT), new QualifiedContentType(ICoffeeScopeConstants.COMMENT_LINE)); c.addTranslation( new QualifiedContentType(HEREGEX), new QualifiedContentType(ICoffeeScopeConstants.REGEXP)); c.addTranslation( new QualifiedContentType(REGEXP), new QualifiedContentType(ICoffeeScopeConstants.REGEXP)); }
/** * Process all metadata files via the metadata reader returned by createMetadataReader * * @param monitor * @param reader * @param resources */ private void loadMetadata(IProgressMonitor monitor, T reader, String... resources) { SubMonitor subMonitor = SubMonitor.convert(monitor, resources.length); for (String resource : resources) { URL url = FileLocator.find(this.getBundle(), new Path(resource), null); if (url != null) { InputStream stream = null; try { stream = url.openStream(); reader.loadXML(stream, url.toString()); } catch (Throwable t) { IdeLog.logError( CommonEditorPlugin.getDefault(), Messages.MetadataLoader_Error_Loading_Metadata + resource, t); } finally { if (stream != null) { try { stream.close(); } catch (IOException e) { } } } } subMonitor.worked(1); } subMonitor.done(); }
public static IPreferenceStore getChainedPreferenceStore() { return new ChainedPreferenceStore( new IPreferenceStore[] { CSSPlugin.getDefault().getPreferenceStore(), CommonEditorPlugin.getDefault().getPreferenceStore(), EditorsPlugin.getDefault().getPreferenceStore() }); }
static { IContentTypeTranslator c = CommonEditorPlugin.getDefault().getContentTypeTranslator(); c.addTranslation( new QualifiedContentType(ICSSConstants.CONTENT_TYPE_CSS), new QualifiedContentType(ICSSConstants.CSS_SCOPE)); c.addTranslation( new QualifiedContentType(MULTILINE_COMMENT), new QualifiedContentType(ICSSConstants.CSS_COMMENT_BLOCK_SCOPE)); c.addTranslation( new QualifiedContentType(STRING), new QualifiedContentType(ICSSConstants.CSS_STRING_SCOPE)); }
public void lineGetBackground(LineBackgroundEvent event) { if (fViewer == null) { return; } final StyledText textWidget = fViewer.getTextWidget(); if (textWidget == null) { return; } try { final int offset = event.lineOffset; IDocument document = fViewer.getDocument(); int line = document.getLineOfOffset(offset); final IRegion lineRegion = document.getLineInformation(line); // Handle fully opaque line highlight here. A modified approach from CursorLinePainter. if (fEnabled && isOpaque() && isCurrentLine(line)) { // draw current line drawCurrentLine(event, lineRegion); return; } // Not drawing an opaque line highlight, so we need to do our normal line coloring here. // This extends the bg color out for a given line based on it's end scope. String endOfLineScope = getScopeManager().getScopeAtOffset(document, lineRegion.getLength() + offset); String commonPrefix = getScope(document, line, endOfLineScope); TextAttribute at = getCurrentTheme().getTextAttribute(commonPrefix); // if we have no color we need to extend to end of line, but this used to be the highlight // line, force the // theme bg color if (at.getBackground() == null && isOpaque() && fLastLine.includes(offset)) { event.lineBackground = getColorManager().getColor(getCurrentTheme().getBackground()); } else { event.lineBackground = at.getBackground(); } } catch (BadLocationException e) { IdeLog.logError(CommonEditorPlugin.getDefault(), e); } }
/** * getDefault * * @return */ public static IDLSourceConfiguration getDefault() { if (instance == null) { IContentTypeTranslator c = CommonEditorPlugin.getDefault().getContentTypeTranslator(); c.addTranslation( new QualifiedContentType(IIDLConstants.CONTENT_TYPE_IDL), new QualifiedContentType("source.idl")); // $NON-NLS-1$ c.addTranslation( new QualifiedContentType(IDL_SINGLELINE_COMMENT), new QualifiedContentType("comment.line.double-slash.idl")); // $NON-NLS-1$ c.addTranslation( new QualifiedContentType(IDL_DOC_COMMENT), new QualifiedContentType("comment.block.documentation.idl")); // $NON-NLS-1$ c.addTranslation( new QualifiedContentType(IDL_MULTILINE_COMMENT), new QualifiedContentType("comment.block.idl")); // $NON-NLS-1$ instance = new IDLSourceConfiguration(); } return instance; }
protected IDocumentScopeManager getScopeManager() { return CommonEditorPlugin.getDefault().getDocumentScopeManager(); }
protected IContentTypeTranslator getContentTypeTranslator() { return CommonEditorPlugin.getDefault().getContentTypeTranslator(); }
protected void setUpStandardScopes() { manager = CommonEditorPlugin.getDefault().getDocumentScopeManager(); }
/** @see org.eclipse.swt.custom.VerifyKeyListener#verifyKey(org.eclipse.swt.events.VerifyEvent) */ public void verifyKey(VerifyEvent event) { // early pruning to slow down normal typing as little as possible if (!event.doit || !isAutoInsertEnabled() || !isAutoInsertCharacter(event.character)) { return; } IDocument document = textViewer.getDocument(); final Point selection = textViewer.getSelectedRange(); final int offset = selection.x; final int length = selection.y; try { String scope = getScopeAtOffset(document, offset); if (fgCommentSelector.matches(scope)) { return; } if (length > 0) { wrapSelection(event, document, offset, length); return; } // Don't auto-close if next char is a letter or digit if (document.getLength() > offset) { char nextChar = document.getChar(offset); if (Character.isJavaIdentifierPart(nextChar)) { return; } } // Don't auto-close if we have an open pair! if (isUnclosedPair( event, document, offset)) // We have an open string or pair, just insert the single // character, don't do anything special { return; } final char closingCharacter = getPeerCharacter(event.character); // If this is the start char and there's no unmatched close char, insert the close char if (unpairedClose(event.character, closingCharacter, document, offset)) { return; } final StringBuffer buffer = new StringBuffer(); buffer.append(event.character); buffer.append(closingCharacter); if (offset == document.getLength()) { String delim = null; if (document instanceof IDocumentExtension4) { delim = ((IDocumentExtension4) document).getDefaultLineDelimiter(); } if (delim == null) { delim = System.getProperty("line.separator", "\r\n"); // $NON-NLS-1$ //$NON-NLS-2$ } buffer.append(delim); } document.replace(offset, length, buffer.toString()); BracketLevel level = new BracketLevel(); fBracketLevelStack.push(level); LinkedPositionGroup group = new LinkedPositionGroup(); group.addPosition(new LinkedPosition(document, offset + 1, 0, LinkedPositionGroup.NO_STOP)); LinkedModeModel model = new LinkedModeModel(); model.addLinkingListener(this); model.addGroup(group); model.forceInstall(); // set up position tracking for our magic peers if (fBracketLevelStack.size() == 1) { document.addPositionCategory(CATEGORY); document.addPositionUpdater(fUpdater); } level.fFirstPosition = new Position(offset, 1); level.fSecondPosition = new Position(offset + 1, 1); document.addPosition(CATEGORY, level.fFirstPosition); document.addPosition(CATEGORY, level.fSecondPosition); level.fUI = new EditorLinkedModeUI(model, textViewer); level.fUI.setSimpleMode(true); level.fUI.setExitPolicy( new ExitPolicy( textViewer, closingCharacter, getEscapeCharacter(closingCharacter), fBracketLevelStack)); level.fUI.setExitPosition(textViewer, offset + 2, 0, Integer.MAX_VALUE); level.fUI.setCyclingMode(LinkedModeUI.CYCLE_NEVER); level.fUI.enter(); IRegion newSelection = level.fUI.getSelectedRegion(); textViewer.setSelectedRange(newSelection.getOffset(), newSelection.getLength()); event.doit = false; } catch (BadLocationException e) { CommonEditorPlugin.logError(e); } catch (BadPositionCategoryException e) { CommonEditorPlugin.logError(e); } }
protected String getScopeAtOffset(IDocument document, final int offset) throws BadLocationException { return CommonEditorPlugin.getDefault() .getDocumentScopeManager() .getScopeAtOffset(document, offset); }
/** EditorsPreferencePage */ public EditorsPreferencePage() { super(GRID); setPreferenceStore(CommonEditorPlugin.getDefault().getPreferenceStore()); setDescription(Messages.EditorsPreferencePage_PreferenceDescription); }