X-Git-Url: http://secure.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java index 701ebf9..16072a2 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java @@ -18,6 +18,7 @@ import net.sourceforge.phpdt.internal.ui.actions.CompositeActionGroup; import net.sourceforge.phpdt.internal.ui.text.HTMLTextPresenter; import net.sourceforge.phpdt.internal.ui.text.PHPPairMatcher; import net.sourceforge.phpdt.internal.ui.viewsupport.IViewPartInputProvider; +import net.sourceforge.phpdt.ui.IContextMenuConstants; import net.sourceforge.phpdt.ui.PreferenceConstants; import net.sourceforge.phpdt.ui.actions.GenerateActionGroup; import net.sourceforge.phpdt.ui.actions.GotoMatchingBracketAction; @@ -30,8 +31,9 @@ import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.IAction; +import org.eclipse.jface.action.GroupMarker; import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.action.Separator; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.preference.PreferenceConverter; import org.eclipse.jface.text.BadLocationException; @@ -65,9 +67,6 @@ import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.IViewPart; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.PartInitException; import org.eclipse.ui.actions.ActionContext; import org.eclipse.ui.actions.ActionGroup; import org.eclipse.ui.texteditor.ContentAssistAction; @@ -81,18 +80,23 @@ import org.eclipse.ui.views.contentoutline.IContentOutlinePage; /** * PHP specific text editor. */ -public class PHPEditor extends StatusTextEditor implements IViewPartInputProvider { // extends TextEditor { +public class PHPEditor + extends StatusTextEditor + implements IViewPartInputProvider { // extends TextEditor { /** Preference key for showing the line number ruler */ - private final static String LINE_NUMBER_RULER = PreferenceConstants.EDITOR_LINE_NUMBER_RULER; + private final static String LINE_NUMBER_RULER = + PreferenceConstants.EDITOR_LINE_NUMBER_RULER; /** Preference key for the foreground color of the line numbers */ - private final static String LINE_NUMBER_COLOR = PreferenceConstants.EDITOR_LINE_NUMBER_RULER_COLOR; + private final static String LINE_NUMBER_COLOR = + PreferenceConstants.EDITOR_LINE_NUMBER_RULER_COLOR; /** Preference key for the link color */ - private final static String LINK_COLOR = PreferenceConstants.EDITOR_LINK_COLOR; + private final static String LINK_COLOR = + PreferenceConstants.EDITOR_LINK_COLOR; // protected PHPActionGroup fActionGroups; /** The outline page */ - private PHPContentOutlinePage fOutlinePage; + private AbstractContentOutlinePage fOutlinePage; // protected PHPSyntaxParserThread fValidationThread = null; @@ -105,8 +109,8 @@ public class PHPEditor extends StatusTextEditor implements IViewPartInputProvide protected CompositeActionGroup fActionGroups; /** The standard action groups added to the menu */ - private GenerateActionGroup fGenerateActionGroup; - private CompositeActionGroup fContextMenuGroup; + protected GenerateActionGroup fGenerateActionGroup; + protected CompositeActionGroup fContextMenuGroup; /** The information presenter. */ private InformationPresenter fInformationPresenter; @@ -117,7 +121,8 @@ public class PHPEditor extends StatusTextEditor implements IViewPartInputProvide public PHPEditor() { super(); JavaTextTools textTools = PHPeclipsePlugin.getDefault().getJavaTextTools(); - setSourceViewerConfiguration(new PHPSourceViewerConfiguration(textTools, this)); + setSourceViewerConfiguration( + new PHPSourceViewerConfiguration(textTools, this)); setRangeIndicator(new DefaultRangeIndicator()); setPreferenceStore(PHPeclipsePlugin.getDefault().getPreferenceStore()); @@ -153,22 +158,32 @@ public class PHPEditor extends StatusTextEditor implements IViewPartInputProvide String t = types[i]; - int[] stateMasks = configuration.getConfiguredTextHoverStateMasks(getSourceViewer(), t); + int[] stateMasks = + configuration.getConfiguredTextHoverStateMasks(getSourceViewer(), t); ISourceViewer sourceViewer = getSourceViewer(); if (sourceViewer instanceof ITextViewerExtension2) { if (stateMasks != null) { for (int j = 0; j < stateMasks.length; j++) { int stateMask = stateMasks[j]; - ITextHover textHover = configuration.getTextHover(sourceViewer, t, stateMask); - ((ITextViewerExtension2) sourceViewer).setTextHover(textHover, t, stateMask); + ITextHover textHover = + configuration.getTextHover(sourceViewer, t, stateMask); + ((ITextViewerExtension2) sourceViewer).setTextHover( + textHover, + t, + stateMask); } } else { ITextHover textHover = configuration.getTextHover(sourceViewer, t); - ((ITextViewerExtension2) sourceViewer).setTextHover(textHover, t, ITextViewerExtension2.DEFAULT_HOVER_STATE_MASK); + ((ITextViewerExtension2) sourceViewer).setTextHover( + textHover, + t, + ITextViewerExtension2.DEFAULT_HOVER_STATE_MASK); } } else - sourceViewer.setTextHover(configuration.getTextHover(sourceViewer, t), t); + sourceViewer.setTextHover( + configuration.getTextHover(sourceViewer, t), + t); } } @@ -186,11 +201,16 @@ public class PHPEditor extends StatusTextEditor implements IViewPartInputProvide public void createPartControl(Composite parent) { super.createPartControl(parent); - IInformationControlCreator informationControlCreator = new IInformationControlCreator() { + IInformationControlCreator informationControlCreator = + new IInformationControlCreator() { public IInformationControl createInformationControl(Shell parent) { boolean cutDown = false; int style = cutDown ? SWT.NONE : (SWT.V_SCROLL | SWT.H_SCROLL); - return new DefaultInformationControl(parent, SWT.RESIZE, style, new HTMLTextPresenter(cutDown)); + return new DefaultInformationControl( + parent, + SWT.RESIZE, + style, + new HTMLTextPresenter(cutDown)); } }; @@ -205,7 +225,8 @@ public class PHPEditor extends StatusTextEditor implements IViewPartInputProvide * @return the document's complete text */ public String get() { - IDocument doc = this.getDocumentProvider().getDocument(this.getEditorInput()); + IDocument doc = + this.getDocumentProvider().getDocument(this.getEditorInput()); return doc.get(); } @@ -216,7 +237,7 @@ public class PHPEditor extends StatusTextEditor implements IViewPartInputProvide return fActionGroups; } - public PHPContentOutlinePage getfOutlinePage() { + public AbstractContentOutlinePage getfOutlinePage() { return fOutlinePage; } @@ -228,16 +249,6 @@ public class PHPEditor extends StatusTextEditor implements IViewPartInputProvide super.createActions(); Action action; - // setAction( - // "ContentAssistProposal", - // new TextOperationAction( - // PHPEditorMessages.getResourceBundle(), - // "ContentAssistProposal.", - // this, - // ISourceViewer.CONTENTASSIST_PROPOSALS)); - action = new ContentAssistAction(PHPEditorMessages.getResourceBundle(), "ContentAssistProposal.", this); //$NON-NLS-1$ - action.setActionDefinitionId(PHPEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS); - setAction("ContentAssistProposal", action); //$NON-NLS-1$ setAction( "ContentAssistTip", @@ -247,33 +258,46 @@ public class PHPEditor extends StatusTextEditor implements IViewPartInputProvide this, ISourceViewer.CONTENTASSIST_CONTEXT_INFORMATION)); - action = new TextOperationAction(PHPEditorMessages.getResourceBundle(), "Comment.", this, ITextOperationTarget.PREFIX); + action = new ContentAssistAction(PHPEditorMessages.getResourceBundle(), "ContentAssistProposal.", this); //$NON-NLS-1$ + action.setActionDefinitionId( + PHPEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS); + setAction("ContentAssistProposal", action); //$NON-NLS-1$ + markAsStateDependentAction("ContentAssistProposal", true); //$NON-NLS-1$ + // WorkbenchHelp.setHelp(action, IJavaHelpContextIds.CONTENT_ASSIST_ACTION); + + action = new TextOperationAction(PHPEditorMessages.getResourceBundle(), "Comment.", this, ITextOperationTarget.PREFIX); //$NON-NLS-1$ action.setActionDefinitionId(PHPEditorActionDefinitionIds.COMMENT); - setAction("Comment", action); + setAction("Comment", action); //$NON-NLS-1$ + markAsStateDependentAction("Comment", true); //$NON-NLS-1$ + // WorkbenchHelp.setHelp(action, IJavaHelpContextIds.COMMENT_ACTION); - action = new TextOperationAction(PHPEditorMessages.getResourceBundle(), "Uncomment.", this, ITextOperationTarget.STRIP_PREFIX); + action = new TextOperationAction(PHPEditorMessages.getResourceBundle(), "Uncomment.", this, ITextOperationTarget.STRIP_PREFIX); //$NON-NLS-1$ action.setActionDefinitionId(PHPEditorActionDefinitionIds.UNCOMMENT); - setAction("Uncomment", action); + setAction("Uncomment", action); //$NON-NLS-1$ + markAsStateDependentAction("Uncomment", true); //$NON-NLS-1$ + // WorkbenchHelp.setHelp(action, IJavaHelpContextIds.UNCOMMENT_ACTION); action = new TextOperationAction(PHPEditorMessages.getResourceBundle(), "Format.", this, ISourceViewer.FORMAT); //$NON-NLS-1$ action.setActionDefinitionId(PHPEditorActionDefinitionIds.FORMAT); setAction("Format", action); //$NON-NLS-1$ - - markAsStateDependentAction("ContentAssistProposal", true); //$NON-NLS-1$ - markAsStateDependentAction("Comment", true); //$NON-NLS-1$ - markAsStateDependentAction("Uncomment", true); //$NON-NLS-1$ markAsStateDependentAction("Format", true); //$NON-NLS-1$ + markAsSelectionDependentAction("Format", true); //$NON-NLS-1$ + // WorkbenchHelp.setHelp(action, IJavaHelpContextIds.FORMAT_ACTION); action = new GotoMatchingBracketAction(this); - action.setActionDefinitionId(PHPEditorActionDefinitionIds.GOTO_MATCHING_BRACKET); + action.setActionDefinitionId( + PHPEditorActionDefinitionIds.GOTO_MATCHING_BRACKET); setAction(GotoMatchingBracketAction.GOTO_MATCHING_BRACKET, action); - fGenerateActionGroup = new GenerateActionGroup(this, ITextEditorActionConstants.GROUP_EDIT); + fGenerateActionGroup = + new GenerateActionGroup(this, ITextEditorActionConstants.GROUP_EDIT); - fActionGroups = new CompositeActionGroup(new ActionGroup[] { fGenerateActionGroup }); + fActionGroups = + new CompositeActionGroup(new ActionGroup[] { fGenerateActionGroup }); // We have to keep the context menu group separate to have better control over positioning - fContextMenuGroup = new CompositeActionGroup(new ActionGroup[] { fGenerateActionGroup }); + fContextMenuGroup = + new CompositeActionGroup(new ActionGroup[] { fGenerateActionGroup }); // rg, // new LocalHistoryActionGroup(this, ITextEditorActionConstants.GROUP_EDIT)}); @@ -321,16 +345,19 @@ public class PHPEditor extends StatusTextEditor implements IViewPartInputProvide super.doSave(monitor); // compile or not, according to the user preferences IPreferenceStore store = getPreferenceStore(); // fPHPPrefStore; - if (store.getBoolean(PHPeclipsePlugin.PHP_PARSE_ON_SAVE)) { - IAction a = PHPParserAction.getInstance(); - if (a != null) - a.run(); - } -// if (SWT.getPlatform().equals("win32")) { -// IAction a = ShowExternalPreviewAction.getInstance(); -// if (a != null) -// a.run(); -// } + + // the parse on save was changed to the eclipse "builders" concept + // if (store.getBoolean(PHPeclipsePlugin.PHP_PARSE_ON_SAVE)) { + // IAction a = PHPParserAction.getInstance(); + // if (a != null) + // a.run(); + // } + + // if (SWT.getPlatform().equals("win32")) { + // IAction a = ShowExternalPreviewAction.getInstance(); + // if (a != null) + // a.run(); + // } if (fOutlinePage != null) fOutlinePage.update(); } @@ -368,13 +395,25 @@ public class PHPEditor extends StatusTextEditor implements IViewPartInputProvide */ public void editorContextMenuAboutToShow(MenuManager menu) { super.editorContextMenuAboutToShow(menu); - - addAction(menu, ITextEditorActionConstants.GROUP_EDIT, "Format"); //$NON-NLS-1$ - - ActionContext context = new ActionContext(getSelectionProvider().getSelection()); + menu.appendToGroup( + ITextEditorActionConstants.GROUP_UNDO, + new Separator(IContextMenuConstants.GROUP_OPEN)); + menu.insertAfter( + IContextMenuConstants.GROUP_OPEN, + new GroupMarker(IContextMenuConstants.GROUP_SHOW)); + + ActionContext context = + new ActionContext(getSelectionProvider().getSelection()); fContextMenuGroup.setContext(context); fContextMenuGroup.fillContextMenu(menu); fContextMenuGroup.setContext(null); + // addAction(menu, ITextEditorActionConstants.GROUP_EDIT, "Format"); //$NON-NLS-1$ + // + // ActionContext context = + // new ActionContext(getSelectionProvider().getSelection()); + // fContextMenuGroup.setContext(context); + // fContextMenuGroup.fillContextMenu(menu); + // fContextMenuGroup.setContext(null); } protected void updateStateDependentActions() { @@ -450,7 +489,8 @@ public class PHPEditor extends StatusTextEditor implements IViewPartInputProvide if (value instanceof Integer) { sourceViewer.getTextWidget().setTabs(((Integer) value).intValue()); } else if (value instanceof String) { - sourceViewer.getTextWidget().setTabs(Integer.parseInt((String) value)); + sourceViewer.getTextWidget().setTabs( + Integer.parseInt((String) value)); } return; } @@ -595,9 +635,13 @@ public class PHPEditor extends StatusTextEditor implements IViewPartInputProvide if (!store.getBoolean(PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT)) { if (store.contains(PREFERENCE_COLOR_BACKGROUND)) { if (store.isDefault(PREFERENCE_COLOR_BACKGROUND)) - rgb = PreferenceConverter.getDefaultColor(store, PREFERENCE_COLOR_BACKGROUND); + rgb = + PreferenceConverter.getDefaultColor( + store, + PREFERENCE_COLOR_BACKGROUND); else - rgb = PreferenceConverter.getColor(store, PREFERENCE_COLOR_BACKGROUND); + rgb = + PreferenceConverter.getColor(store, PREFERENCE_COLOR_BACKGROUND); } } rulerColumn.setBackground(manager.getColor(rgb)); @@ -683,12 +727,15 @@ public class PHPEditor extends StatusTextEditor implements IViewPartInputProvide return false; } - private static boolean isSurroundedByBrackets(IDocument document, int offset) { + private static boolean isSurroundedByBrackets( + IDocument document, + int offset) { if (offset == 0 || offset == document.getLength()) return false; try { - return isBracket(document.getChar(offset - 1)) && isBracket(document.getChar(offset)); + return isBracket(document.getChar(offset - 1)) + && isBracket(document.getChar(offset)); } catch (BadLocationException e) { return false; @@ -735,7 +782,8 @@ public class PHPEditor extends StatusTextEditor implements IViewPartInputProvide return; int anchor = fBracketMatcher.getAnchor(); - int targetOffset = (PHPPairMatcher.RIGHT == anchor) ? offset : offset + length - 1; + int targetOffset = + (PHPPairMatcher.RIGHT == anchor) ? offset : offset + length - 1; boolean visible = false; if (sourceViewer instanceof ITextViewerExtension3) { @@ -743,7 +791,9 @@ public class PHPEditor extends StatusTextEditor implements IViewPartInputProvide visible = (extension.modelOffset2WidgetOffset(targetOffset) > -1); } else { IRegion visibleRegion = sourceViewer.getVisibleRegion(); - visible = (targetOffset >= visibleRegion.getOffset() && targetOffset < visibleRegion.getOffset() + visibleRegion.getLength()); + visible = + (targetOffset >= visibleRegion.getOffset() + && targetOffset < visibleRegion.getOffset() + visibleRegion.getLength()); } if (!visible) { @@ -763,7 +813,8 @@ public class PHPEditor extends StatusTextEditor implements IViewPartInputProvide * @param msg message to be set */ protected void setStatusLineErrorMessage(String msg) { - IEditorStatusLine statusLine = (IEditorStatusLine) getAdapter(IEditorStatusLine.class); + IEditorStatusLine statusLine = + (IEditorStatusLine) getAdapter(IEditorStatusLine.class); if (statusLine != null) statusLine.setMessage(true, msg, null); } @@ -777,14 +828,18 @@ public class PHPEditor extends StatusTextEditor implements IViewPartInputProvide * @return the line's bidi segmentation * @throws BadLocationException in case lineOffset is not valid in document */ - public static int[] getBidiLineSegments(IDocument document, int lineOffset) throws BadLocationException { + public static int[] getBidiLineSegments(IDocument document, int lineOffset) + throws BadLocationException { IRegion line = document.getLineInformationOfOffset(lineOffset); - ITypedRegion[] linePartitioning = document.computePartitioning(lineOffset, line.getLength()); + ITypedRegion[] linePartitioning = + document.computePartitioning(lineOffset, line.getLength()); List segmentation = new ArrayList(); for (int i = 0; i < linePartitioning.length; i++) { - if (IPHPPartitionScannerConstants.PHP_STRING.equals(linePartitioning[i].getType())) + if (IPHPPartitionScannerConstants + .PHP_STRING + .equals(linePartitioning[i].getType())) segmentation.add(linePartitioning[i]); } @@ -844,7 +899,10 @@ public class PHPEditor extends StatusTextEditor implements IViewPartInputProvide /* * @see AbstractTextEditor#createSourceViewer(Composite, IVerticalRuler, int) */ - protected final ISourceViewer createSourceViewer(Composite parent, IVerticalRuler ruler, int styles) { + protected final ISourceViewer createSourceViewer( + Composite parent, + IVerticalRuler ruler, + int styles) { ISourceViewer viewer = createJavaSourceViewer(parent, ruler, styles); StyledText text = viewer.getTextWidget(); text.addBidiSegmentListener(new BidiSegmentListener() { @@ -859,7 +917,10 @@ public class PHPEditor extends StatusTextEditor implements IViewPartInputProvide /* * @see AbstractTextEditor#createSourceViewer(Composite, IVerticalRuler, int) */ - protected ISourceViewer createJavaSourceViewer(Composite parent, IVerticalRuler ruler, int styles) { + protected ISourceViewer createJavaSourceViewer( + Composite parent, + IVerticalRuler ruler, + int styles) { return super.createSourceViewer(parent, ruler, styles); }