From 1ef1b0fb72d28ba24ce24311bb6191b6c9d10f5f Mon Sep 17 00:00:00 2001 From: khartlage Date: Thu, 24 Oct 2002 16:04:31 +0000 Subject: [PATCH] Integrated PHP help files; Fixed some bugs --- net.sourceforge.phpeclipse/.classpath | 7 +- net.sourceforge.phpeclipse/phphelp.xml | 9 + net.sourceforge.phpeclipse/plugin.properties | 2 +- net.sourceforge.phpeclipse/plugin.xml | 98 +++--- .../phpeclipse/PHPEclipsePreferencePage.java | 68 +---- .../phpeclipse/actions/PHPEclipseShowAction.java | 211 +++++++------ .../actions/PHPEclipseShowContextHelp.java | 20 +- .../phpeclipse/phpeditor/PHPEditor.java | 233 +++++++------- .../phpeditor/php/PHPDoubleClickSelector.java | 2 +- .../phpeditor/php/PHPPartitionScanner.java | 349 ++++++++++---------- 10 files changed, 488 insertions(+), 511 deletions(-) create mode 100644 net.sourceforge.phpeclipse/phphelp.xml diff --git a/net.sourceforge.phpeclipse/.classpath b/net.sourceforge.phpeclipse/.classpath index b0ab4bd..1ac08d6 100644 --- a/net.sourceforge.phpeclipse/.classpath +++ b/net.sourceforge.phpeclipse/.classpath @@ -6,14 +6,11 @@ - - - + + diff --git a/net.sourceforge.phpeclipse/phphelp.xml b/net.sourceforge.phpeclipse/phphelp.xml new file mode 100644 index 0000000..2b9a211 --- /dev/null +++ b/net.sourceforge.phpeclipse/phphelp.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/net.sourceforge.phpeclipse/plugin.properties b/net.sourceforge.phpeclipse/plugin.properties index 708b293..7a8b7b1 100644 --- a/net.sourceforge.phpeclipse/plugin.properties +++ b/net.sourceforge.phpeclipse/plugin.properties @@ -7,5 +7,5 @@ providerName = EclipseProject.de # # Extension point names # -phpEditorName=Example Java Editor +phpEditorName=PHP Editor phpFileExtension=php diff --git a/net.sourceforge.phpeclipse/plugin.xml b/net.sourceforge.phpeclipse/plugin.xml index 1c3e6fa..b2b4aca 100644 --- a/net.sourceforge.phpeclipse/plugin.xml +++ b/net.sourceforge.phpeclipse/plugin.xml @@ -1,6 +1,6 @@ - + s - - + + + + id="net.sourceforge.phpeclipse.PHPActionSet"> - + label="PHP/Apache" + id="net.sourceforge.phpeclipse.PHPMenu"> + + + label="Restart Apache" + icon="icons/obj16/apache.gif" + tooltip="Restart Apache" + class="net.sourceforge.phpeclipse.actions.PHPRestartApacheAction" + menubarPath="net.sourceforge.phpeclipse.PHPMenu/phpeclipse" + toolbarPath="Normal" + start="true" + id="net.sourceforge.phpeclipse.actions.PHPRestartApacheAction"> + label="Stop Apache" + icon="icons/obj16/apache.gif" + tooltip="Stop Apache" + class="net.sourceforge.phpeclipse.actions.PHPStopApacheAction" + menubarPath="net.sourceforge.phpeclipse.PHPMenu/phpeclipse" + toolbarPath="Normal" + start="true" + id="net.sourceforge.phpeclipse.actions.PHPStopApacheAction"> - + label="Start Apache" + icon="icons/obj16/apache.gif" + tooltip="Start Apache" + class="net.sourceforge.phpeclipse.actions.PHPStartApacheAction" + menubarPath="net.sourceforge.phpeclipse.PHPMenu/phpeclipse" + toolbarPath="Normal" + start="true" + id="net.sourceforge.phpeclipse.actions.PHPStartApacheAction"> + + label="Start MySQL" + icon="icons/obj16/apache.gif" + tooltip="Start MySQL" + class="net.sourceforge.phpeclipse.actions.PHPStartMySQLAction" + menubarPath="net.sourceforge.phpeclipse.PHPMenu/phpeclipse" + toolbarPath="Normal" + start="true" + id="net.sourceforge.phpeclipse.actions.PHPStartMySQLAction"> @@ -94,8 +97,8 @@ id="net.sourceforge.phpeclipse.actions.showAction"> - - > - + --> @@ -122,5 +124,7 @@ id="net.sourceforge.phpeclipse.phpeditor.PHPDocumentProvider"> - + + + diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPEclipsePreferencePage.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPEclipsePreferencePage.java index 3d6fe05..b0c494c 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPEclipsePreferencePage.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPEclipsePreferencePage.java @@ -11,19 +11,11 @@ Contributors: **********************************************************************/ package net.sourceforge.phpeclipse; -import java.io.IOException; -import java.text.MessageFormat; - import org.eclipse.jface.preference.BooleanFieldEditor; import org.eclipse.jface.preference.DirectoryFieldEditor; import org.eclipse.jface.preference.FieldEditorPreferencePage; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.preference.StringFieldEditor; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; @@ -40,7 +32,6 @@ public class PHPEclipsePreferencePage extends FieldEditorPreferencePage implemen } protected void createFieldEditors() { - Shell shell = getShell(); final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore(); StringFieldEditor localhost = new StringFieldEditor(PHPeclipsePlugin.LOCALHOST_PREF, "&Localhost:", 60, getFieldEditorParent()); @@ -49,69 +40,26 @@ public class PHPEclipsePreferencePage extends FieldEditorPreferencePage implemen new DirectoryFieldEditor(PHPeclipsePlugin.DOCUMENTROOT_PREF, "&DocumentRoot:", getFieldEditorParent()); BooleanFieldEditor useExternalBrowser = - new BooleanFieldEditor(PHPeclipsePlugin.USE_EXTERNAL_BROWSER_PREF, "&Use External Browser", 60, getFieldEditorParent()); + new BooleanFieldEditor(PHPeclipsePlugin.USE_EXTERNAL_BROWSER_PREF, "&Use External Browser", getFieldEditorParent()); StringFieldEditor externalBrowser = new StringFieldEditor(PHPeclipsePlugin.EXTERNAL_BROWSER_PREF, "&External Browser command:", 60, getFieldEditorParent()); StringFieldEditor startMySQL = new StringFieldEditor(PHPeclipsePlugin.MYSQL_PREF, "&MySQL command:", 60, getFieldEditorParent()); -// Button button = new Button(shell, SWT.PUSH); -// button.setText("Start MySQL"); -// button.addSelectionListener(new SelectionAdapter() { -// public void widgetSelected(SelectionEvent e) { -// try { -// Runtime runtime = Runtime.getRuntime(); -// runtime.exec(store.getString(PHPeclipsePlugin.MYSQL_PREF)); -// } catch (IOException e1) { -// } -// } -// }); + StringFieldEditor startApache = new StringFieldEditor(PHPeclipsePlugin.APACHE_START_PREF, "Start &Apache command:", 60, getFieldEditorParent()); -// Button startButton = new Button(shell, SWT.PUSH); -// startButton.setText("Start Apache"); -// startButton.addSelectionListener(new SelectionAdapter() { -// public void widgetSelected(SelectionEvent e) { -// String[] arguments = { store.getString(PHPeclipsePlugin.DOCUMENTROOT_PREF)}; -// MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.APACHE_START_PREF)); -// -// try { -// Runtime runtime = Runtime.getRuntime(); -// runtime.exec(form.format(arguments)); -// } catch (IOException e2) { -// } -// } -// }); - - StringFieldEditor stopApache = + + + StringFieldEditor stopApache = new StringFieldEditor(PHPeclipsePlugin.APACHE_STOP_PREF, "&Stop Apache command:", 60, getFieldEditorParent()); - Button stopButton = new Button(shell, SWT.PUSH); - stopButton.setText("Stop Apache"); - stopButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - try { - Runtime runtime = Runtime.getRuntime(); - runtime.exec(store.getString(PHPeclipsePlugin.MYSQL_PREF)); - } catch (IOException e1) { - } - } - }); + StringFieldEditor restartApache = new StringFieldEditor(PHPeclipsePlugin.APACHE_RESTART_PREF, "&Restart Apache command:", 60, getFieldEditorParent()); - Button restartButton = new Button(shell, SWT.PUSH); - restartButton.setText("Restart Apache"); - restartButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - try { - Runtime runtime = Runtime.getRuntime(); - runtime.exec(store.getString(PHPeclipsePlugin.MYSQL_PREF)); - } catch (IOException e1) { - } - } - }); + addField(localhost); addField(documentRoot); @@ -119,7 +67,7 @@ public class PHPEclipsePreferencePage extends FieldEditorPreferencePage implemen addField(externalBrowser); addField(startMySQL); addField(startApache); -// add(startButton); + addField(stopApache); addField(restartApache); } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPEclipseShowAction.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPEclipseShowAction.java index 7cd25dc..5018ac6 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPEclipseShowAction.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPEclipseShowAction.java @@ -30,117 +30,128 @@ import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IObjectActionDelegate; import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.jdt.internal.ui.actions.OpenBrowserUtil; + +import org.eclipse.ui.help.WorkbenchHelp; +import org.eclipse.help.IHelp; +//import org.eclipse.jdt.internal.ui.actions.OpenBrowserUtil; // import org.eclipse.help.ui.browser.LaunchURL; public class PHPEclipseShowAction implements IObjectActionDelegate { - private IWorkbenchPart workbenchPart; - /** - * Constructor for Action1. - */ - public PHPEclipseShowAction() { - super(); - } - - /** - * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart) - */ - public void setActivePart(IAction action, IWorkbenchPart targetPart) { - workbenchPart = targetPart; - } - - // public static void open(final URL url, final Shell shell, final String dialogTitle) { - // IHelp help= WorkbenchHelp.getHelpSupport(); - // if (help != null) { - // WorkbenchHelp.getHelpSupport().displayHelpResource(url.toExternalForm()); - // } else { - // showMessage(shell, dialogTitle, ActionMessages.getString("OpenBrowserUtil.help_not_available"), false); //$NON-NLS-1$ - // } - // } - - public void run(IAction action) { - ISelectionProvider selectionProvider = null; - selectionProvider = workbenchPart.getSite().getSelectionProvider(); - - StructuredSelection selection = null; - selection = (StructuredSelection) selectionProvider.getSelection(); - - IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore(); - - Shell shell = null; - Iterator iterator = null; - iterator = selection.iterator(); - while (iterator.hasNext()) { - // obj => selected object in the view - Object obj = iterator.next(); - - // is it a resource - if (obj instanceof IResource) { - IResource resource = (IResource) obj; - - // check if it's a file resource - switch (resource.getType()) { - - case IResource.FILE : - // single file: - IFile file = (IFile) resource; - IPath path = file.getFullPath(); - // if (j2h==null) { - // shell = new Shell(); - // j2h = new Java2HTML(shell); - // } - - String fileName = file.getLocation().toString(); + private IWorkbenchPart workbenchPart; + /** + * Constructor for Action1. + */ + public PHPEclipseShowAction() { + super(); + } + + /** + * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart) + */ + public void setActivePart(IAction action, IWorkbenchPart targetPart) { + workbenchPart = targetPart; + } + + // public static void open(final URL url, final Shell shell, final String dialogTitle) { + // IHelp help= WorkbenchHelp.getHelpSupport(); + // if (help != null) { + // WorkbenchHelp.getHelpSupport().displayHelpResource(url.toExternalForm()); + // } else { + // showMessage(shell, dialogTitle, ActionMessages.getString("OpenBrowserUtil.help_not_available"), false); //$NON-NLS-1$ + // } + // } + + public void run(IAction action) { + ISelectionProvider selectionProvider = null; + selectionProvider = workbenchPart.getSite().getSelectionProvider(); + + StructuredSelection selection = null; + selection = (StructuredSelection) selectionProvider.getSelection(); + + IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore(); + + Shell shell = null; + Iterator iterator = null; + iterator = selection.iterator(); + while (iterator.hasNext()) { + // obj => selected object in the view + Object obj = iterator.next(); + + // is it a resource + if (obj instanceof IResource) { + IResource resource = (IResource) obj; + + // check if it's a file resource + switch (resource.getType()) { + + case IResource.FILE : + // single file: + IFile file = (IFile) resource; + IPath path = file.getFullPath(); + // if (j2h==null) { + // shell = new Shell(); + // j2h = new Java2HTML(shell); + // } + + String fileName = file.getLocation().toString(); String lowerCaseFileName = fileName.toLowerCase(); - // fileName = "http://localhost"+fileName.replaceAll("c:", ""); - String documentRoot = store.getString(PHPeclipsePlugin.DOCUMENTROOT_PREF); + // fileName = "http://localhost"+fileName.replaceAll("c:", ""); + String documentRoot = store.getString(PHPeclipsePlugin.DOCUMENTROOT_PREF); documentRoot = documentRoot.replace('\\', '/'); documentRoot = documentRoot.toLowerCase(); MessageDialog.openInformation(shell, "lowerCaseFileName", "lowerCaseFileName: " + lowerCaseFileName); - - if ( lowerCaseFileName.startsWith(documentRoot) ) { + + if (lowerCaseFileName.startsWith(documentRoot)) { fileName = fileName.substring(documentRoot.length()); } else { MessageDialog.openInformation(shell, "Wrong DocumentRoot", "Adjust DocumentRoot: " + documentRoot); return; } - - fileName = store.getString(PHPeclipsePlugin.LOCALHOST_PREF) + fileName.replaceAll(documentRoot, ""); - - try { - if (store.getBoolean(PHPeclipsePlugin.USE_EXTERNAL_BROWSER_PREF)) { - String[] arguments = { fileName }; - MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.EXTERNAL_BROWSER_PREF)); - - Runtime runtime = Runtime.getRuntime(); - runtime.exec(form.format(arguments)); - // runtime.exec(store.getString(PHPeclipsePlugin.EXTERNAL_BROWSER_PREF) + " " + fileName); - // runtime.exec("command.com /c start iexplore " + fileName); - } else { - OpenBrowserUtil.open(new URL(fileName), shell, fileName); - } - } catch (MalformedURLException e) { - MessageDialog.openInformation(shell, "MalformedURLException: ", e.toString()); - } catch (IOException e) { - MessageDialog.openInformation(shell, "IOException", "Cannot show: " + fileName); - - } - - // MessageDialog.openInformation(shell, "PHPEclipse", "FileName - " + fileName); - // - // Runtime runtime = Runtime.getRuntime(); - // try { - // runtime.exec("command.com /c start iexplore "+fileName); - - // MessageDialog.openInformation(shell, "J2h Plug-in", "FileName - " + fileName); - // j2h.convert( fileName ); - } - } - } - } /** - * @see IActionDelegate#selectionChanged(IAction, ISelection) - */ - public void selectionChanged(IAction action, ISelection selection) { - } + fileName = store.getString(PHPeclipsePlugin.LOCALHOST_PREF) + fileName.replaceAll(documentRoot, ""); + + try { + if (store.getBoolean(PHPeclipsePlugin.USE_EXTERNAL_BROWSER_PREF)) { + String[] arguments = { fileName }; + MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.EXTERNAL_BROWSER_PREF)); + + Runtime runtime = Runtime.getRuntime(); + runtime.exec(form.format(arguments)); + // runtime.exec(store.getString(PHPeclipsePlugin.EXTERNAL_BROWSER_PREF) + " " + fileName); + // runtime.exec("command.com /c start iexplore " + fileName); + } else { + open(new URL(fileName), shell, fileName); + } + } catch (MalformedURLException e) { + MessageDialog.openInformation(shell, "MalformedURLException: ", e.toString()); + } catch (IOException e) { + MessageDialog.openInformation(shell, "IOException", "Cannot show: " + fileName); + + } + + // MessageDialog.openInformation(shell, "PHPEclipse", "FileName - " + fileName); + // + // Runtime runtime = Runtime.getRuntime(); + // try { + // runtime.exec("command.com /c start iexplore "+fileName); + + // MessageDialog.openInformation(shell, "J2h Plug-in", "FileName - " + fileName); + // j2h.convert( fileName ); + } + } + } + } /** + * @see IActionDelegate#selectionChanged(IAction, ISelection) + */ + public void selectionChanged(IAction action, ISelection selection) { + } + + public static void open(final URL url, final Shell shell, final String dialogTitle) { + IHelp help = WorkbenchHelp.getHelpSupport(); + if (help != null) { + WorkbenchHelp.getHelpSupport().displayHelpResource(url.toExternalForm()); + } else { + // showMessage(shell, dialogTitle, ActionMessages.getString("OpenBrowserUtil.help_not_available"), false); //$NON-NLS-1$ + } + } } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPEclipseShowContextHelp.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPEclipseShowContextHelp.java index 9a638e2..2b5bd88 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPEclipseShowContextHelp.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPEclipseShowContextHelp.java @@ -14,34 +14,30 @@ package net.sourceforge.phpeclipse.actions; import org.eclipse.jface.action.IAction; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.ui.IEditorActionDelegate; -import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.actions.ActionDelegate; +import org.eclipse.ui.editors.text.TextEditor; import org.eclipse.ui.internal.EditorPluginAction; +import org.eclipse.ui.part.FileEditorInput; -public class PHPEclipseShowContextHelp - extends ActionDelegate - implements IEditorActionDelegate { - -private IEditorPart editor; +public class PHPEclipseShowContextHelp extends ActionDelegate implements IEditorActionDelegate { + + private TextEditor editor; /** * @see ActionDelegate#run(IAction) */ public void run(IAction action) { EditorPluginAction editorPluginAction = (EditorPluginAction) action; - IEditorInput input = editor.getEditorInput(); + FileEditorInput input = (FileEditorInput) editor.getEditorInput(); // Add your code here to perform the action - MessageDialog.openInformation( - editor.getSite().getShell(), - "Context Help: ", - input.toString()); + MessageDialog.openInformation(editor.getSite().getShell(), "Context Help: ", input.toString()); } /** * @see IEditorActionDelegate#setActiveEditor(IAction, IEditorPart) */ public void setActiveEditor(IAction action, IEditorPart targetEditor) { - this.editor = targetEditor; + this.editor = (TextEditor) targetEditor; } } 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 f32a1e8..470aa0f 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java @@ -11,7 +11,6 @@ Contributors: IBM Corporation - Initial implementation Klaus Hartlage - www.eclipseproject.de **********************************************************************/ -import java.util.ResourceBundle; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jface.action.MenuManager; @@ -27,114 +26,126 @@ import org.eclipse.ui.views.contentoutline.IContentOutlinePage; */ public class PHPEditor extends TextEditor { - /** The outline page */ - private PHPContentOutlinePage fOutlinePage; - - /** - * Default constructor. - */ - public PHPEditor() { - super(); - } - - /** The JavaEditor implementation of this - * AbstractTextEditor method extend the - * actions to add those specific to the receiver - */ - protected void createActions() { - super.createActions(); - setAction("ContentAssistProposal", new TextOperationAction(PHPEditorMessages.getResourceBundle(), "ContentAssistProposal.", this, ISourceViewer.CONTENTASSIST_PROPOSALS)); - setAction("ContentAssistTip", new TextOperationAction(PHPEditorMessages.getResourceBundle(), "ContentAssistTip.", this, ISourceViewer.CONTENTASSIST_CONTEXT_INFORMATION)); - } - - /** The JavaEditor implementation of this - * AbstractTextEditor method performs any extra - * disposal actions required by the java editor. - */ - public void dispose() { - PHPEditorEnvironment.disconnect(this); - if (fOutlinePage != null) - fOutlinePage.setInput(null); - super.dispose(); - } - - /** The JavaEditor implementation of this - * AbstractTextEditor method performs any extra - * revert behavior required by the java editor. - */ - public void doRevertToSaved() { - super.doRevertToSaved(); - if (fOutlinePage != null) - fOutlinePage.update(); - } - - /** The JavaEditor implementation of this - * AbstractTextEditor method performs any extra - * save behavior required by the java editor. - */ - public void doSave(IProgressMonitor monitor) { - super.doSave(monitor); - if (fOutlinePage != null) - fOutlinePage.update(); - } - - /** The JavaEditor implementation of this - * AbstractTextEditor method performs any extra - * save as behavior required by the java editor. - */ - public void doSaveAs() { - super.doSaveAs(); - if (fOutlinePage != null) - fOutlinePage.update(); - } - - /** The JavaEditor implementation of this - * AbstractTextEditor method performs sets the - * input of the outline page after AbstractTextEditor has set input. - */ - public void doSetInput(IEditorInput input) throws CoreException { - super.doSetInput(input); - if (fOutlinePage != null) - fOutlinePage.setInput(input); - } - - /** The JavaEditor implementation of this - * AbstractTextEditor method adds any - * JavaEditor specific entries. - */ - public void editorContextMenuAboutToShow(MenuManager menu) { - super.editorContextMenuAboutToShow(menu); - addAction(menu, "ContentAssistProposal"); //$NON-NLS-1$ - addAction(menu, "ContentAssistTip"); //$NON-NLS-1$ - } - - /** The JavaEditor implementation of this - * AbstractTextEditor method performs gets - * the java content outline page if request is for a an - * outline page. - */ - public Object getAdapter(Class required) { - if (IContentOutlinePage.class.equals(required)) { - if (fOutlinePage == null) { - fOutlinePage= new PHPContentOutlinePage(getDocumentProvider(), this); - if (getEditorInput() != null) - fOutlinePage.setInput(getEditorInput()); - } - return fOutlinePage; - } - return super.getAdapter(required); - } - - /* (non-Javadoc) - * Method declared on AbstractTextEditor - */ - protected void initializeEditor() { - - PHPEditorEnvironment.connect(this); - - setSourceViewerConfiguration(new PHPSourceViewerConfiguration()); - setRangeIndicator(new DefaultRangeIndicator()); - setEditorContextMenuId("#PHPEditorContext"); //$NON-NLS-1$ - setRulerContextMenuId("#PHPRulerContext"); //$NON-NLS-1$ - } + /** The outline page */ + private PHPContentOutlinePage fOutlinePage; + + /** + * Default constructor. + */ + public PHPEditor() { + super(); + } + + /** The JavaEditor implementation of this + * AbstractTextEditor method extend the + * actions to add those specific to the receiver + */ + protected void createActions() { + super.createActions(); + setAction( + "ContentAssistProposal", + new TextOperationAction( + PHPEditorMessages.getResourceBundle(), + "ContentAssistProposal.", + this, + ISourceViewer.CONTENTASSIST_PROPOSALS)); + setAction( + "ContentAssistTip", + new TextOperationAction( + PHPEditorMessages.getResourceBundle(), + "ContentAssistTip.", + this, + ISourceViewer.CONTENTASSIST_CONTEXT_INFORMATION)); + } + + /** The JavaEditor implementation of this + * AbstractTextEditor method performs any extra + * disposal actions required by the java editor. + */ + public void dispose() { + PHPEditorEnvironment.disconnect(this); + if (fOutlinePage != null) + fOutlinePage.setInput(null); + super.dispose(); + } + + /** The JavaEditor implementation of this + * AbstractTextEditor method performs any extra + * revert behavior required by the java editor. + */ + public void doRevertToSaved() { + super.doRevertToSaved(); + if (fOutlinePage != null) + fOutlinePage.update(); + } + + /** The JavaEditor implementation of this + * AbstractTextEditor method performs any extra + * save behavior required by the java editor. + */ + public void doSave(IProgressMonitor monitor) { + super.doSave(monitor); + if (fOutlinePage != null) + fOutlinePage.update(); + } + + /** The JavaEditor implementation of this + * AbstractTextEditor method performs any extra + * save as behavior required by the java editor. + */ + public void doSaveAs() { + super.doSaveAs(); + if (fOutlinePage != null) + fOutlinePage.update(); + } + + /** The JavaEditor implementation of this + * AbstractTextEditor method performs sets the + * input of the outline page after AbstractTextEditor has set input. + */ + public void doSetInput(IEditorInput input) throws CoreException { + super.doSetInput(input); + if (fOutlinePage != null) + fOutlinePage.setInput(input); + } + + /** The JavaEditor implementation of this + * AbstractTextEditor method adds any + * JavaEditor specific entries. + */ + public void editorContextMenuAboutToShow(MenuManager menu) { + super.editorContextMenuAboutToShow(menu); + addAction(menu, "ContentAssistProposal"); //$NON-NLS-1$ + addAction(menu, "ContentAssistTip"); //$NON-NLS-1$ + } + + /** The JavaEditor implementation of this + * AbstractTextEditor method performs gets + * the java content outline page if request is for a an + * outline page. + */ + public Object getAdapter(Class required) { + if (IContentOutlinePage.class.equals(required)) { + if (fOutlinePage == null) { + fOutlinePage = new PHPContentOutlinePage(getDocumentProvider(), this); + if (getEditorInput() != null) + fOutlinePage.setInput(getEditorInput()); + } + return fOutlinePage; + } + return super.getAdapter(required); + } + + /* (non-Javadoc) + * Method declared on AbstractTextEditor + */ + protected void initializeEditor() { + + PHPEditorEnvironment.connect(this); + + setSourceViewerConfiguration(new PHPSourceViewerConfiguration()); + setRangeIndicator(new DefaultRangeIndicator()); + setEditorContextMenuId("#PHPEditorContext"); //$NON-NLS-1$ + setRulerContextMenuId("#PHPRulerContext"); //$NON-NLS-1$ + } } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPDoubleClickSelector.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPDoubleClickSelector.java index a45a352..faa4b3c 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPDoubleClickSelector.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPDoubleClickSelector.java @@ -30,7 +30,7 @@ public class PHPDoubleClickSelector implements ITextDoubleClickStrategy { protected static char[] fgBrackets = { '{', '}', '(', ')', '[', ']', '"', '"' }; /* - * Create a JavaDoubleClickSelector. + * Create a PHPDoubleClickSelector. */ public PHPDoubleClickSelector() { super(); diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPPartitionScanner.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPPartitionScanner.java index 00ec730..43970cd 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPPartitionScanner.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPPartitionScanner.java @@ -11,18 +11,16 @@ Contributors: **********************************************************************/ package net.sourceforge.phpeclipse.phpeditor.php; +import java.io.CharArrayWriter; import java.util.ArrayList; import java.util.List; -import org.eclipse.jface.text.rules.EndOfLineRule; + import org.eclipse.jface.text.rules.ICharacterScanner; import org.eclipse.jface.text.rules.IPredicateRule; -import org.eclipse.jface.text.rules.IRule; import org.eclipse.jface.text.rules.IToken; import org.eclipse.jface.text.rules.IWordDetector; import org.eclipse.jface.text.rules.MultiLineRule; import org.eclipse.jface.text.rules.RuleBasedPartitionScanner; -import org.eclipse.jface.text.rules.RuleBasedScanner; -import org.eclipse.jface.text.rules.SingleLineRule; import org.eclipse.jface.text.rules.Token; import org.eclipse.jface.text.rules.WordRule; @@ -31,175 +29,178 @@ import org.eclipse.jface.text.rules.WordRule; */ public class PHPPartitionScanner extends RuleBasedPartitionScanner { - private final static String SKIP = "__skip"; //$NON-NLS-1$ - public final static String JAVA_MULTILINE_COMMENT = "__html_multiline_comment"; //$NON-NLS-1$ - // public final static String JAVA_DOC= "__java_javadoc"; //$NON-NLS-1$ - public final static String PHP = "__php"; - - public class PHPMultiLineRule extends MultiLineRule { - - public PHPMultiLineRule(String startSequence, String endSequence, IToken token) { - super(startSequence, endSequence, token); - } - - public PHPMultiLineRule(String startSequence, String endSequence, IToken token, char escapeCharacter) { - super(startSequence, endSequence, token, escapeCharacter); - } - - protected boolean endSequenceDetected(ICharacterScanner scanner) { - int c; - int c2; - - boolean lineCommentMode = false; - boolean multiLineCommentMode = false; - boolean stringMode = false; - - char[][] delimiters = scanner.getLegalLineDelimiters(); - while ((c = scanner.read()) != ICharacterScanner.EOF) { - if (c == '\n') { - lineCommentMode = false; - // read until end of line - } else if (c == '#') { - // read until end of line - lineCommentMode = true; - continue; - } else if (c == '/') { - c2 = scanner.read(); - if (c2 == '/') { - lineCommentMode = true; + private final static String SKIP = "__skip"; //$NON-NLS-1$ + public final static String JAVA_MULTILINE_COMMENT = "__html_multiline_comment"; //$NON-NLS-1$ + // public final static String JAVA_DOC= "__java_javadoc"; //$NON-NLS-1$ + public final static String PHP = "__php"; + private StringBuffer test; + public class PHPMultiLineRule extends MultiLineRule { + + public PHPMultiLineRule(String startSequence, String endSequence, IToken token) { + super(startSequence, endSequence, token); + } + + public PHPMultiLineRule(String startSequence, String endSequence, IToken token, char escapeCharacter) { + super(startSequence, endSequence, token, escapeCharacter); + } + + protected boolean endSequenceDetected(ICharacterScanner scanner) { + int c; + int c2; + + boolean lineCommentMode = false; + boolean multiLineCommentMode = false; + boolean stringMode = false; + + char[][] delimiters = scanner.getLegalLineDelimiters(); + while ((c = scanner.read()) != ICharacterScanner.EOF) { + if (lineCommentMode && (c == '\n')) { + lineCommentMode = false; + // read until end of line + } else if ((!stringMode) && (c == '#')) { + // read until end of line + lineCommentMode = true; + continue; + } else if ((!stringMode) && (!multiLineCommentMode) && (c == '/')) { + c2 = scanner.read(); + if (c2 == '/') { + lineCommentMode = true; + continue; + } else if (c2 == '*') { + multiLineCommentMode = true; + continue; + } else { + scanner.unread(); + } + } else if (c == '*' && multiLineCommentMode) { + c2 = scanner.read(); + if (c2 == '/') { + multiLineCommentMode = false; + continue; + } else { + scanner.unread(); + } + } else if (c == '\\' && stringMode) { + c2 = scanner.read(); + if (c2 == '"') { continue; - } else if(c2 == '*') { - multiLineCommentMode = true; - continue; - } else { - scanner.unread(); - } - } else if (c == '*' && multiLineCommentMode) { - c2 = scanner.read(); - if (c2 == '/') { - multiLineCommentMode = false; - continue; - } else { - scanner.unread(); - } - } else if (c == '\\' && stringMode) { - c2 = scanner.read(); - if (c2 == '"') { - continue; - } else { - scanner.unread(); - } - } else if (c == '"') { - if (stringMode) { - stringMode = false; - } else { - stringMode = true; - } - continue; - } - if (lineCommentMode || multiLineCommentMode || stringMode) { - continue; - } - - if (c == fEscapeCharacter) { - // Skip the escaped character. - scanner.read(); - } else if (fEndSequence.length > 0 && c == fEndSequence[0]) { - // Check if the specified end sequence has been found. - if (sequenceDetected(scanner, fEndSequence, true)) - return true; - } else if (fBreaksOnEOL) { - // Check for end of line since it can be used to terminate the pattern. - for (int i = 0; i < delimiters.length; i++) { - if (c == delimiters[i][0] && sequenceDetected(scanner, delimiters[i], false)) - return true; - } - } - } - scanner.unread(); - return true; - } - } - /** - * Detector for empty comments. - */ - static class EmptyCommentDetector implements IWordDetector { - - /* (non-Javadoc) - * Method declared on IWordDetector - */ - public boolean isWordStart(char c) { - return (c == '/'); - } - - /* (non-Javadoc) - * Method declared on IWordDetector - */ - public boolean isWordPart(char c) { - return (c == '*' || c == '/'); - } - }; - - /** - * - */ - static class WordPredicateRule extends WordRule implements IPredicateRule { - - private IToken fSuccessToken; - - public WordPredicateRule(IToken successToken) { - super(new EmptyCommentDetector()); - fSuccessToken = successToken; - addWord("/**/", fSuccessToken); - } - - /* - * @see org.eclipse.jface.text.rules.IPredicateRule#evaluate(ICharacterScanner, boolean) - */ - public IToken evaluate(ICharacterScanner scanner, boolean resume) { - return super.evaluate(scanner); - } - - /* - * @see org.eclipse.jface.text.rules.IPredicateRule#getSuccessToken() - */ - public IToken getSuccessToken() { - return fSuccessToken; - } - }; - - /** - * Creates the partitioner and sets up the appropriate rules. - */ - public PHPPartitionScanner() { - super(); - - // IToken javaDoc= new Token(JAVA_DOC); - IToken comment = new Token(JAVA_MULTILINE_COMMENT); - IToken php = new Token(PHP); - - List rules = new ArrayList(); - - // Add rule for single line comments. - // rules.add(new EndOfLineRule("//", Token.UNDEFINED)); - - // Add rule for strings and character constants. - // rules.add(new SingleLineRule("\"", "\"", Token.UNDEFINED, '\\')); - // rules.add(new SingleLineRule("'", "'", Token.UNDEFINED, '\\')); - - // Add special case word rule. - rules.add(new WordPredicateRule(comment)); - - // Add rules for multi-line comments and javadoc. - //rules.add(new MultiLineRule("/**", "*/", javaDoc)); - rules.add(new MultiLineRule("", comment)); - rules.add(new PHPMultiLineRule("", php)); - rules.add(new PHPMultiLineRule("", php)); - rules.add(new PHPMultiLineRule("", php)); - //Add rule for processing instructions - - IPredicateRule[] result = new IPredicateRule[rules.size()]; - rules.toArray(result); - setPredicateRules(result); - } + } else { + scanner.unread(); + } + } else if ((!lineCommentMode) && (!multiLineCommentMode) && (c == '"')) { + if (stringMode) { + stringMode = false; + } else { + stringMode = true; + } + continue; + } + if (lineCommentMode || multiLineCommentMode || stringMode) { + continue; + } + + if (c == fEscapeCharacter) { + // Skip the escaped character. + scanner.read(); + } else if (fEndSequence.length > 0 && c == fEndSequence[0]) { + // Check if the specified end sequence has been found. + if (sequenceDetected(scanner, fEndSequence, true)) + return true; + } else if (fBreaksOnEOL) { + // Check for end of line since it can be used to terminate the pattern. + for (int i = 0; i < delimiters.length; i++) { + if (c == delimiters[i][0] && sequenceDetected(scanner, delimiters[i], false)) + return true; + } + } + } + scanner.unread(); + return true; + } + } + /** + * Detector for empty comments. + */ + static class EmptyCommentDetector implements IWordDetector { + + /* (non-Javadoc) + * Method declared on IWordDetector + */ + public boolean isWordStart(char c) { + return (c == '/'); + } + + /* (non-Javadoc) + * Method declared on IWordDetector + */ + public boolean isWordPart(char c) { + return (c == '*' || c == '/'); + } + }; + + /** + * + */ + static class WordPredicateRule extends WordRule implements IPredicateRule { + + private IToken fSuccessToken; + + public WordPredicateRule(IToken successToken) { + super(new EmptyCommentDetector()); + fSuccessToken = successToken; + addWord("/**/", fSuccessToken); + } + + /* + * @see org.eclipse.jface.text.rules.IPredicateRule#evaluate(ICharacterScanner, boolean) + */ + public IToken evaluate(ICharacterScanner scanner, boolean resume) { + return super.evaluate(scanner); + } + + /* + * @see org.eclipse.jface.text.rules.IPredicateRule#getSuccessToken() + */ + public IToken getSuccessToken() { + return fSuccessToken; + } + }; + + /** + * Creates the partitioner and sets up the appropriate rules. + */ + public PHPPartitionScanner() { + super(); + + // IToken javaDoc= new Token(JAVA_DOC); + IToken comment = new Token(JAVA_MULTILINE_COMMENT); + IToken php = new Token(PHP); + + List rules = new ArrayList(); + + // Add rule for single line comments. + // rules.add(new EndOfLineRule("//", Token.UNDEFINED)); + + // Add rule for strings and character constants. + // rules.add(new SingleLineRule("\"", "\"", Token.UNDEFINED, '\\')); + // rules.add(new SingleLineRule("'", "'", Token.UNDEFINED, '\\')); + + // Add special case word rule. + rules.add(new WordPredicateRule(comment)); + + // Add rules for multi-line comments and javadoc. + //rules.add(new MultiLineRule("/**", "*/", javaDoc)); + rules.add(new MultiLineRule("", comment)); + rules.add(new PHPMultiLineRule("", php)); + rules.add(new PHPMultiLineRule("", php)); + rules.add(new PHPMultiLineRule("", php)); + rules.add(new PHPMultiLineRule("", php)); + rules.add(new PHPMultiLineRule("", php)); + rules.add(new PHPMultiLineRule("", php)); + //Add rule for processing instructions + + IPredicateRule[] result = new IPredicateRule[rules.size()]; + rules.toArray(result); + setPredicateRules(result); + } } -- 1.7.1