1 package net.sourceforge.phpeclipse.phpeditor;
3 /**********************************************************************
4 Copyright (c) 2000, 2002 IBM Corp. and others.
5 All rights reserved. This program and the accompanying materials
6 are made available under the terms of the Common Public License v1.0
7 which accompanies this distribution, and is available at
8 http://www.eclipse.org/legal/cpl-v10.html
11 IBM Corporation - Initial implementation
12 Klaus Hartlage - www.eclipseproject.de
13 **********************************************************************/
14 import java.util.ArrayList;
15 import java.util.List;
17 import net.sourceforge.phpdt.internal.ui.actions.CompositeActionGroup;
18 import net.sourceforge.phpdt.internal.ui.text.HTMLTextPresenter;
19 import net.sourceforge.phpdt.internal.ui.text.JavaColorManager;
20 import net.sourceforge.phpdt.internal.ui.text.PHPPairMatcher;
21 import net.sourceforge.phpdt.internal.ui.viewsupport.IViewPartInputProvider;
22 import net.sourceforge.phpdt.ui.actions.GenerateActionGroup;
23 import net.sourceforge.phpdt.ui.actions.GotoMatchingBracketAction;
24 import net.sourceforge.phpdt.ui.text.JavaTextTools;
25 import net.sourceforge.phpeclipse.IPreferenceConstants;
26 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
27 import net.sourceforge.phpeclipse.phpeditor.php.IPHPPartitionScannerConstants;
28 import net.sourceforge.phpeclipse.phpeditor.php.PHPCodeScanner;
30 import org.eclipse.core.resources.IResource;
31 import org.eclipse.core.runtime.CoreException;
32 import org.eclipse.core.runtime.IProgressMonitor;
33 import org.eclipse.jface.action.Action;
34 import org.eclipse.jface.action.IAction;
35 import org.eclipse.jface.action.MenuManager;
36 import org.eclipse.jface.preference.IPreferenceStore;
37 import org.eclipse.jface.preference.PreferenceConverter;
38 import org.eclipse.jface.text.BadLocationException;
39 import org.eclipse.jface.text.DefaultInformationControl;
40 import org.eclipse.jface.text.IDocument;
41 import org.eclipse.jface.text.IInformationControl;
42 import org.eclipse.jface.text.IInformationControlCreator;
43 import org.eclipse.jface.text.IRegion;
44 import org.eclipse.jface.text.ITextOperationTarget;
45 import org.eclipse.jface.text.ITextViewer;
46 import org.eclipse.jface.text.ITextViewerExtension3;
47 import org.eclipse.jface.text.ITypedRegion;
48 import org.eclipse.jface.text.Region;
49 import org.eclipse.jface.text.information.InformationPresenter;
50 import org.eclipse.jface.text.source.AnnotationRulerColumn;
51 import org.eclipse.jface.text.source.CompositeRuler;
52 import org.eclipse.jface.text.source.ISourceViewer;
53 import org.eclipse.jface.text.source.IVerticalRuler;
54 import org.eclipse.jface.text.source.IVerticalRulerColumn;
55 import org.eclipse.jface.text.source.LineNumberRulerColumn;
56 import org.eclipse.jface.util.IPropertyChangeListener;
57 import org.eclipse.jface.util.PropertyChangeEvent;
58 import org.eclipse.swt.SWT;
59 import org.eclipse.swt.custom.BidiSegmentEvent;
60 import org.eclipse.swt.custom.BidiSegmentListener;
61 import org.eclipse.swt.custom.StyledText;
62 import org.eclipse.swt.graphics.Point;
63 import org.eclipse.swt.graphics.RGB;
64 import org.eclipse.swt.widgets.Composite;
65 import org.eclipse.swt.widgets.Shell;
66 import org.eclipse.ui.IEditorInput;
67 import org.eclipse.ui.actions.ActionContext;
68 import org.eclipse.ui.actions.ActionGroup;
69 import org.eclipse.ui.texteditor.ContentAssistAction;
70 import org.eclipse.ui.texteditor.DefaultRangeIndicator;
71 import org.eclipse.ui.texteditor.IDocumentProvider;
72 import org.eclipse.ui.texteditor.IEditorStatusLine;
73 import org.eclipse.ui.texteditor.ITextEditorActionConstants;
74 import org.eclipse.ui.texteditor.StatusTextEditor;
75 import org.eclipse.ui.texteditor.TextOperationAction;
76 import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
78 * PHP specific text editor.
80 public class PHPEditor
81 extends StatusTextEditor
82 implements IViewPartInputProvider { // extends TextEditor {
84 // protected PHPActionGroup fActionGroups;
85 /** The outline page */
86 private PHPContentOutlinePage fOutlinePage;
88 // protected PHPSyntaxParserThread fValidationThread = null;
90 // private IPreferenceStore fPHPPrefStore;
92 /** The editor's bracket matcher */
93 private PHPPairMatcher fBracketMatcher;
94 /** The line number ruler column */
95 private LineNumberRulerColumn fLineNumberRulerColumn;
97 protected CompositeActionGroup fActionGroups;
98 /** The standard action groups added to the menu */
99 private GenerateActionGroup fGenerateActionGroup;
100 private CompositeActionGroup fContextMenuGroup;
102 /** The information presenter. */
103 private InformationPresenter fInformationPresenter;
106 * Default constructor.
110 JavaTextTools textTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
111 setSourceViewerConfiguration(
112 new PHPSourceViewerConfiguration(textTools, this));
113 setRangeIndicator(new DefaultRangeIndicator());
114 setPreferenceStore(PHPeclipsePlugin.getDefault().getPreferenceStore());
116 // if (PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE))
117 // fUpdater= new OutlinePageSelectionUpdater();
123 // * @see IMember#getCompilationUnit()
125 // public ICompilationUnit getCompilationUnit() {
129 // * @see org.phpeclipse.phpdt.internal.compiler.env.ICompilationUnit#getContents()
131 // public char[] getContents() {
132 // IDocument doc = this.getDocumentProvider().getDocument(this.getEditorInput());
134 // return doc.get().toCharArray();
138 * @see net.sourceforge.phpdt.internal.ui.viewsupport.IViewPartInputProvider#getViewPartInput()
140 public Object getViewPartInput() {
141 return getEditorInput().getAdapter(IResource.class);
145 * @see org.eclipse.ui.IWorkbenchPart#createPartControl(org.eclipse.swt.
148 public void createPartControl(Composite parent) {
149 super.createPartControl(parent);
151 IInformationControlCreator informationControlCreator =
152 new IInformationControlCreator() {
153 public IInformationControl createInformationControl(Shell parent) {
154 boolean cutDown = false;
155 int style = cutDown ? SWT.NONE : (SWT.V_SCROLL | SWT.H_SCROLL);
156 return new DefaultInformationControl(
160 new HTMLTextPresenter(cutDown));
164 fInformationPresenter = new InformationPresenter(informationControlCreator);
165 fInformationPresenter.setSizeConstraints(60, 10, true, true);
166 fInformationPresenter.install(getSourceViewer());
170 * Returns this document's complete text.
172 * @return the document's complete text
174 public String get() {
176 this.getDocumentProvider().getDocument(this.getEditorInput());
181 * Returns the standard action group of this editor.
183 protected ActionGroup getActionGroup() {
184 return fActionGroups;
187 public PHPContentOutlinePage getfOutlinePage() {
191 /** The <code>PHPEditor</code> implementation of this
192 * <code>AbstractTextEditor</code> method extend the
193 * actions to add those specific to the receiver
195 protected void createActions() {
196 super.createActions();
200 // "ContentAssistProposal",
201 // new TextOperationAction(
202 // PHPEditorMessages.getResourceBundle(),
203 // "ContentAssistProposal.",
205 // ISourceViewer.CONTENTASSIST_PROPOSALS));
206 action = new ContentAssistAction(PHPEditorMessages.getResourceBundle(), "ContentAssistProposal.", this); //$NON-NLS-1$
207 action.setActionDefinitionId(
208 PHPEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
209 setAction("ContentAssistProposal", action); //$NON-NLS-1$
213 new TextOperationAction(
214 PHPEditorMessages.getResourceBundle(),
217 ISourceViewer.CONTENTASSIST_CONTEXT_INFORMATION));
220 new TextOperationAction(
221 PHPEditorMessages.getResourceBundle(),
224 ITextOperationTarget.PREFIX);
225 action.setActionDefinitionId(PHPEditorActionDefinitionIds.COMMENT);
226 setAction("Comment", action);
229 new TextOperationAction(
230 PHPEditorMessages.getResourceBundle(),
233 ITextOperationTarget.STRIP_PREFIX);
234 action.setActionDefinitionId(PHPEditorActionDefinitionIds.UNCOMMENT);
235 setAction("Uncomment", action);
237 action = new TextOperationAction(PHPEditorMessages.getResourceBundle(), "Format.", this, ISourceViewer.FORMAT); //$NON-NLS-1$
238 action.setActionDefinitionId(PHPEditorActionDefinitionIds.FORMAT);
239 setAction("Format", action); //$NON-NLS-1$
241 markAsStateDependentAction("ContentAssistProposal", true); //$NON-NLS-1$
242 markAsStateDependentAction("Comment", true); //$NON-NLS-1$
243 markAsStateDependentAction("Uncomment", true); //$NON-NLS-1$
244 markAsStateDependentAction("Format", true); //$NON-NLS-1$
246 action = new GotoMatchingBracketAction(this);
247 action.setActionDefinitionId(
248 PHPEditorActionDefinitionIds.GOTO_MATCHING_BRACKET);
249 setAction(GotoMatchingBracketAction.GOTO_MATCHING_BRACKET, action);
251 fGenerateActionGroup =
252 new GenerateActionGroup(this, ITextEditorActionConstants.GROUP_EDIT);
255 new CompositeActionGroup(new ActionGroup[] { fGenerateActionGroup });
257 // We have to keep the context menu group separate to have better control over positioning
259 new CompositeActionGroup(new ActionGroup[] { fGenerateActionGroup });
261 // new LocalHistoryActionGroup(this, ITextEditorActionConstants.GROUP_EDIT)});
263 // if (fValidationThread == null) {
264 // fValidationThread =
265 // new PHPSyntaxParserThread(this, getSourceViewer());
268 // fValidationThread.start();
271 // fValidationThread.setText(getSourceViewer().getTextWidget().getText());
274 /** The <code>PHPEditor</code> implementation of this
275 * <code>AbstractTextEditor</code> method performs any extra
276 * disposal actions required by the php editor.
278 public void dispose() {
279 PHPEditorEnvironment.disconnect(this);
280 if (fOutlinePage != null)
281 fOutlinePage.setInput(null);
283 if (fActionGroups != null)
284 fActionGroups.dispose();
289 /** The <code>PHPEditor</code> implementation of this
290 * <code>AbstractTextEditor</code> method performs any extra
291 * revert behavior required by the php editor.
293 public void doRevertToSaved() {
294 super.doRevertToSaved();
295 if (fOutlinePage != null)
296 fOutlinePage.update();
299 /** The <code>PHPEditor</code> implementation of this
300 * <code>AbstractTextEditor</code> method performs any extra
301 * save behavior required by the php editor.
303 public void doSave(IProgressMonitor monitor) {
304 super.doSave(monitor);
305 // compile or not, according to the user preferences
306 IPreferenceStore store = getPreferenceStore(); // fPHPPrefStore;
307 if (store.getBoolean(PHPeclipsePlugin.PHP_PARSE_ON_SAVE)) {
308 IAction a = PHPParserAction.getInstance();
312 if (fOutlinePage != null)
313 fOutlinePage.update();
316 /** The <code>PHPEditor</code> implementation of this
317 * <code>AbstractTextEditor</code> method performs any extra
318 * save as behavior required by the php editor.
320 public void doSaveAs() {
322 if (fOutlinePage != null)
323 fOutlinePage.update();
326 /** The <code>PHPEditor</code> implementation of this
327 * <code>AbstractTextEditor</code> method performs sets the
328 * input of the outline page after AbstractTextEditor has set input.
330 protected void doSetInput(IEditorInput input) throws CoreException {
331 super.doSetInput(input);
332 if (fOutlinePage != null)
333 fOutlinePage.setInput(input);
337 * @see org.phpeclipse.phpdt.internal.ui.viewsupport.IViewPartInputProvider#getViewPartInput()
339 // public Object getViewPartInput() {
340 // return getEditorInput().getAdapter(IFile.class);
343 /** The <code>PHPEditor</code> implementation of this
344 * <code>AbstractTextEditor</code> method adds any
345 * PHPEditor specific entries.
347 public void editorContextMenuAboutToShow(MenuManager menu) {
348 super.editorContextMenuAboutToShow(menu);
350 addAction(menu, ITextEditorActionConstants.GROUP_EDIT, "Format"); //$NON-NLS-1$
352 ActionContext context =
353 new ActionContext(getSelectionProvider().getSelection());
354 fContextMenuGroup.setContext(context);
355 fContextMenuGroup.fillContextMenu(menu);
356 fContextMenuGroup.setContext(null);
359 protected void updateStateDependentActions() {
360 super.updateStateDependentActions();
361 fGenerateActionGroup.editorStateChanged();
364 /** The <code>PHPEditor</code> implementation of this
365 * <code>AbstractTextEditor</code> method performs gets
366 * the java content outline page if request is for a an
369 public Object getAdapter(Class required) {
370 if (IContentOutlinePage.class.equals(required)) {
371 if (fOutlinePage == null) {
372 fOutlinePage = new PHPContentOutlinePage(getDocumentProvider(), this);
373 if (getEditorInput() != null)
374 fOutlinePage.setInput(getEditorInput());
378 return super.getAdapter(required);
381 // public void openContextHelp() {
382 // IDocument doc = this.getDocumentProvider().getDocument(this.getEditorInput());
383 // ITextSelection selection = (ITextSelection) this.getSelectionProvider().getSelection();
384 // int pos = selection.getOffset();
385 // String word = getFunctionName(doc, pos);
386 // openContextHelp(word);
389 // private void openContextHelp(String word) {
393 // public static void open(String word) {
394 // IHelp help = WorkbenchHelp.getHelpSupport();
395 // if (help != null) {
396 // IHelpResource helpResource = new PHPFunctionHelpResource(word);
397 // WorkbenchHelp.getHelpSupport().displayHelpResource(helpResource);
399 // // showMessage(shell, dialogTitle, ActionMessages.getString("Open help not available"), false); //$NON-NLS-1$
403 // private String getFunctionName(IDocument doc, int pos) {
404 // Point word = PHPWordExtractor.findWord(doc, pos);
405 // if (word != null) {
407 // return doc.get(word.x, word.y).replace('_', '-');
408 // } catch (BadLocationException e) {
415 * @see AbstractTextEditor#handlePreferenceStoreChanged(PropertyChangeEvent)
417 protected void handlePreferenceStoreChanged(PropertyChangeEvent event) {
421 ISourceViewer sourceViewer = getSourceViewer();
422 if (sourceViewer == null)
425 String property = event.getProperty();
427 // if (JavaSourceViewerConfiguration.PREFERENCE_TAB_WIDTH.equals(property)) {
428 // Object value= event.getNewValue();
429 // if (value instanceof Integer) {
430 // sourceViewer.getTextWidget().setTabs(((Integer) value).intValue());
431 // } else if (value instanceof String) {
432 // sourceViewer.getTextWidget().setTabs(Integer.parseInt((String) value));
437 if (IPreferenceConstants.LINE_NUMBER_RULER.equals(property)) {
438 if (isLineNumberRulerVisible())
439 showLineNumberRuler();
441 hideLineNumberRuler();
445 if (fLineNumberRulerColumn != null
446 && (IPreferenceConstants.LINE_NUMBER_COLOR.equals(property)
447 || PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT.equals(property)
448 || PREFERENCE_COLOR_BACKGROUND.equals(property))) {
450 initializeLineNumberRulerColumn(fLineNumberRulerColumn);
454 super.handlePreferenceStoreChanged(event);
458 * Shows the line number ruler column.
460 private void showLineNumberRuler() {
461 IVerticalRuler v = getVerticalRuler();
462 if (v instanceof CompositeRuler) {
463 CompositeRuler c = (CompositeRuler) v;
464 c.addDecorator(1, createLineNumberRulerColumn());
469 * Return whether the line number ruler column should be
470 * visible according to the preference store settings.
471 * @return <code>true</code> if the line numbers should be visible
473 private boolean isLineNumberRulerVisible() {
474 // IPreferenceStore store= getPreferenceStore();
475 return getPreferenceStore().getBoolean(
476 IPreferenceConstants.LINE_NUMBER_RULER);
479 * Hides the line number ruler column.
481 private void hideLineNumberRuler() {
482 IVerticalRuler v = getVerticalRuler();
483 if (v instanceof CompositeRuler) {
484 CompositeRuler c = (CompositeRuler) v;
486 c.removeDecorator(1);
487 } catch (Throwable e) {
493 * Initializes the given line number ruler column from the preference store.
494 * @param rulerColumn the ruler column to be initialized
496 protected void initializeLineNumberRulerColumn(LineNumberRulerColumn rulerColumn) {
497 JavaTextTools textTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
498 // PHPColorProvider manager = PHPEditorEnvironment.getPHPColorProvider();
499 JavaColorManager manager = textTools.getColorManager();
501 IPreferenceStore store = getPreferenceStore();
506 if (store.contains(IPreferenceConstants.LINE_NUMBER_COLOR)) {
507 if (store.isDefault(IPreferenceConstants.LINE_NUMBER_COLOR))
509 PreferenceConverter.getDefaultColor(
511 IPreferenceConstants.LINE_NUMBER_COLOR);
514 PreferenceConverter.getColor(
516 IPreferenceConstants.LINE_NUMBER_COLOR);
518 rulerColumn.setForeground(manager.getColor(rgb));
524 IPreferenceConstants.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT)) {
525 if (store.contains(IPreferenceConstants.PREFERENCE_COLOR_BACKGROUND)) {
527 .isDefault(IPreferenceConstants.PREFERENCE_COLOR_BACKGROUND))
529 PreferenceConverter.getDefaultColor(
531 IPreferenceConstants.PREFERENCE_COLOR_BACKGROUND);
534 PreferenceConverter.getColor(
536 IPreferenceConstants.PREFERENCE_COLOR_BACKGROUND);
538 rulerColumn.setBackground(manager.getColor(rgb));
545 * Creates a new line number ruler column that is appropriately initialized.
547 protected IVerticalRulerColumn createLineNumberRulerColumn() {
548 fLineNumberRulerColumn = new LineNumberRulerColumn();
549 initializeLineNumberRulerColumn(fLineNumberRulerColumn);
550 return fLineNumberRulerColumn;
554 * @see AbstractTextEditor#createVerticalRuler()
556 protected IVerticalRuler createVerticalRuler() {
557 CompositeRuler ruler = new CompositeRuler();
558 ruler.addDecorator(0, new AnnotationRulerColumn(VERTICAL_RULER_WIDTH));
559 if (isLineNumberRulerVisible())
560 ruler.addDecorator(1, createLineNumberRulerColumn());
565 * Method declared on TextEditor
567 protected void initializeEditor() {
568 IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
569 PHPEditorEnvironment.connect(this);
571 setEditorContextMenuId("#PHPEditorContext"); //$NON-NLS-1$
572 setRulerContextMenuId("#PHPRulerContext"); //$NON-NLS-1$
573 // setDocumentProvider(PHPeclipsePlugin.getCompilationUnitDocumentProvider());
575 store.addPropertyChangeListener(new IPropertyChangeListener() {
576 public void propertyChange(PropertyChangeEvent event) {
577 PHPCodeScanner scanner = PHPEditorEnvironment.getPHPCodeScanner();
578 if (scanner != null) {
579 scanner.updateToken(PHPEditorEnvironment.getPHPColorProvider());
581 if (getSourceViewer() != null) {
582 getSourceViewer().invalidateTextPresentation();
585 String property = event.getProperty();
586 if (IPreferenceConstants.LINE_NUMBER_RULER.equals(property)) {
587 if (isLineNumberRulerVisible())
588 showLineNumberRuler();
590 hideLineNumberRuler();
597 private static IRegion getSignedSelection(ITextViewer viewer) {
599 StyledText text = viewer.getTextWidget();
600 int caretOffset = text.getCaretOffset();
601 Point selection = text.getSelection();
605 if (caretOffset == selection.x) {
606 offset = selection.y;
607 length = selection.x - selection.y;
611 offset = selection.x;
612 length = selection.y - selection.x;
615 return new Region(offset, length);
618 private final static char[] BRACKETS = { '{', '}', '(', ')', '[', ']' };
620 private static boolean isBracket(char character) {
621 for (int i = 0; i != BRACKETS.length; ++i)
622 if (character == BRACKETS[i])
627 private static boolean isSurroundedByBrackets(
630 if (offset == 0 || offset == document.getLength())
634 return isBracket(document.getChar(offset - 1))
635 && isBracket(document.getChar(offset));
637 } catch (BadLocationException e) {
642 * Jumps to the matching bracket.
644 public void gotoMatchingBracket() {
646 if (fBracketMatcher == null)
647 fBracketMatcher = new PHPPairMatcher(BRACKETS);
649 ISourceViewer sourceViewer = getSourceViewer();
650 IDocument document = sourceViewer.getDocument();
651 if (document == null)
654 IRegion selection = getSignedSelection(sourceViewer);
656 int selectionLength = Math.abs(selection.getLength());
657 if (selectionLength > 1) {
658 setStatusLineErrorMessage(PHPEditorMessages.getString("GotoMatchingBracket.error.invalidSelection")); //$NON-NLS-1$
659 sourceViewer.getTextWidget().getDisplay().beep();
664 int sourceCaretOffset = selection.getOffset() + selection.getLength();
665 if (isSurroundedByBrackets(document, sourceCaretOffset))
666 sourceCaretOffset -= selection.getLength();
668 IRegion region = fBracketMatcher.match(document, sourceCaretOffset);
669 if (region == null) {
670 setStatusLineErrorMessage(PHPEditorMessages.getString("GotoMatchingBracket.error.noMatchingBracket")); //$NON-NLS-1$
671 sourceViewer.getTextWidget().getDisplay().beep();
675 int offset = region.getOffset();
676 int length = region.getLength();
681 int anchor = fBracketMatcher.getAnchor();
683 (PHPPairMatcher.RIGHT == anchor) ? offset : offset + length - 1;
685 boolean visible = false;
686 if (sourceViewer instanceof ITextViewerExtension3) {
687 ITextViewerExtension3 extension = (ITextViewerExtension3) sourceViewer;
688 visible = (extension.modelOffset2WidgetOffset(targetOffset) > -1);
690 IRegion visibleRegion = sourceViewer.getVisibleRegion();
692 (targetOffset >= visibleRegion.getOffset()
693 && targetOffset < visibleRegion.getOffset() + visibleRegion.getLength());
697 setStatusLineErrorMessage(PHPEditorMessages.getString("GotoMatchingBracket.error.bracketOutsideSelectedElement")); //$NON-NLS-1$
698 sourceViewer.getTextWidget().getDisplay().beep();
702 if (selection.getLength() < 0)
703 targetOffset -= selection.getLength();
705 sourceViewer.setSelectedRange(targetOffset, selection.getLength());
706 sourceViewer.revealRange(targetOffset, selection.getLength());
709 * Ses the given message as error message to this editor's status line.
710 * @param msg message to be set
712 protected void setStatusLineErrorMessage(String msg) {
713 IEditorStatusLine statusLine =
714 (IEditorStatusLine) getAdapter(IEditorStatusLine.class);
715 if (statusLine != null)
716 statusLine.setMessage(true, msg, null);
720 * Returns a segmentation of the line of the given document appropriate for bidi rendering.
721 * The default implementation returns only the string literals of a php code line as segments.
723 * @param document the document
724 * @param lineOffset the offset of the line
725 * @return the line's bidi segmentation
726 * @throws BadLocationException in case lineOffset is not valid in document
728 public static int[] getBidiLineSegments(IDocument document, int lineOffset) throws BadLocationException {
730 IRegion line= document.getLineInformationOfOffset(lineOffset);
731 ITypedRegion[] linePartitioning= document.computePartitioning(lineOffset, line.getLength());
733 List segmentation= new ArrayList();
734 for (int i= 0; i < linePartitioning.length; i++) {
735 if (IPHPPartitionScannerConstants.PHP_STRING.equals(linePartitioning[i].getType()))
736 segmentation.add(linePartitioning[i]);
740 if (segmentation.size() == 0)
743 int size= segmentation.size();
744 int[] segments= new int[size * 2 + 1];
747 for (int i= 0; i < size; i++) {
748 ITypedRegion segment= (ITypedRegion) segmentation.get(i);
753 int offset= segment.getOffset() - lineOffset;
754 if (offset > segments[j - 1])
755 segments[j++]= offset;
757 if (offset + segment.getLength() >= line.getLength())
760 segments[j++]= offset + segment.getLength();
763 if (j < segments.length) {
764 int[] result= new int[j];
765 System.arraycopy(segments, 0, result, 0, j);
772 * Returns a segmentation of the given line appropriate for bidi rendering. The default
773 * implementation returns only the string literals of a php code line as segments.
775 * @param lineOffset the offset of the line
776 * @param line the content of the line
777 * @return the line's bidi segmentation
779 protected int[] getBidiLineSegments(int lineOffset, String line) {
780 IDocumentProvider provider = getDocumentProvider();
781 if (provider != null && line != null && line.length() > 0) {
782 IDocument document = provider.getDocument(getEditorInput());
783 if (document != null)
785 return getBidiLineSegments(document, lineOffset);
786 } catch (BadLocationException x) {
794 * @see AbstractTextEditor#createSourceViewer(Composite, IVerticalRuler, int)
796 protected final ISourceViewer createSourceViewer(
798 IVerticalRuler ruler,
800 ISourceViewer viewer = createJavaSourceViewer(parent, ruler, styles);
801 StyledText text = viewer.getTextWidget();
802 text.addBidiSegmentListener(new BidiSegmentListener() {
803 public void lineGetSegments(BidiSegmentEvent event) {
804 event.segments = getBidiLineSegments(event.lineOffset, event.lineText);
807 // JavaUIHelp.setHelp(this, text, IJavaHelpContextIds.JAVA_EDITOR);
812 * @see AbstractTextEditor#createSourceViewer(Composite, IVerticalRuler, int)
814 protected ISourceViewer createJavaSourceViewer(
816 IVerticalRuler ruler,
818 return super.createSourceViewer(parent, ruler, styles);