misc changes
authorkhartlage <khartlage>
Thu, 7 Nov 2002 19:19:24 +0000 (19:19 +0000)
committerkhartlage <khartlage>
Thu, 7 Nov 2002 19:19:24 +0000 (19:19 +0000)
28 files changed:
net.sourceforge.phpeclipse/.classpath
net.sourceforge.phpeclipse/build.xml [new file with mode: 0644]
net.sourceforge.phpeclipse/install.txt [new file with mode: 0644]
net.sourceforge.phpeclipse/phphelp.xml
net.sourceforge.phpeclipse/plugin.properties
net.sourceforge.phpeclipse/plugin.xml
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPeclipsePlugin.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPRestartApacheAction.java [new file with mode: 0644]
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPStartApacheAction.java [new file with mode: 0644]
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPStartMySQLAction.java [new file with mode: 0644]
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPStopApacheAction.java [new file with mode: 0644]
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPContentOutlinePage.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPDocumentProvider.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditorEnvironment.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditorMessages.properties
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPFunctionHelpResource.java [new file with mode: 0644]
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPSourceViewerConfiguration.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPTextHover.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/HTMLCodeScanner.java [new file with mode: 0644]
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/HTMLWordExtractor.java [new file with mode: 0644]
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPCodeScanner.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPCompletionProcessor.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPEditorMessages.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPPartitionScanner.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPWordExtractor.java [moved from net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPWordDetector.java with 98% similarity]
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/togglepresentation.gif [new file with mode: 0644]
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/util/HTMLWordDetector.java [new file with mode: 0644]

index 1ac08d6..bb58950 100644 (file)
@@ -10,7 +10,8 @@
     <classpathentry kind="var"
         path="ECLIPSE_HOME/plugins/org.eclipse.core.boot_2.0.0/boot.jar" sourcepath="_ORG_ECLIPSE_PLATFORM_SOURCE/org.eclipse.core.boot_2.0.0/bootsrc.zip"/>
     <classpathentry kind="var" path="JRE_LIB" rootpath="JRE_SRCROOT" sourcepath="JRE_SRC"/>
-    <classpathentry kind="var" path="ECLIPSE_HOME/plugins/org.eclipse.help_2.0.0/help.jar"/>
-    <classpathentry kind="var" path="ECLIPSE_HOME/plugins/org.eclipse.swt.win32_2.0.0/ws/win32/swt.jar"/>
+    <classpathentry kind="var"
+        path="ECLIPSE_HOME/plugins/org.eclipse.help_2.0.0/help.jar" sourcepath="ECLIPSE_HOME/plugins/org.eclipse.platform.source_2.0.0/src/org.eclipse.help_2.0.0/helpsrc.zip"/>
+    <classpathentry kind="lib" path="C:/eclipse/plugins/org.eclipse.swt.win32_2.0.0/ws/win32/swt.jar"/>
     <classpathentry kind="output" path="bin"/>
 </classpath>
diff --git a/net.sourceforge.phpeclipse/build.xml b/net.sourceforge.phpeclipse/build.xml
new file mode 100644 (file)
index 0000000..75914da
--- /dev/null
@@ -0,0 +1,115 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project name="net.sourceforge.phpeclipse" default="build.jars" basedir=".">
+
+       <property name="bootclasspath" value=""/>
+       <property name="ws" value="win32"/>
+       <property name="os" value="win32"/>
+       <property name="arch" value="x86"/>
+
+       <target name="init" depends="properties">
+               <property name="plugin" value="net.sourceforge.phpeclipse"/>
+               <property name="version.suffix" value="_1.0.2"/>
+               <property name="full.name" value="${plugin}${version.suffix}"/>
+               <property name="temp.folder" value="${basedir}/temp.folder"/>
+               <property name="plugin.destination" value="${basedir}"/>
+               <property name="build.result.folder" value="${basedir}"/>
+       </target>
+
+       <target name="properties" if="eclipse.running">
+               <property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>
+       </target>
+
+       <target name="build.update.jar" depends="init">
+               <delete dir="${temp.folder}"/>
+               <mkdir dir="${temp.folder}"/>
+               <antcall target="build.jars"/>
+               <antcall target="gather.bin.parts">
+                       <param name="destination.temp.folder" value="${temp.folder}/"/>
+               </antcall>
+               <zip zipfile="${plugin.destination}/${full.name}.jar" basedir="${temp.folder}/${full.name}" filesonly="false"/>
+               <delete dir="${temp.folder}"/>
+       </target>
+
+       <target name="gather.bin.parts" depends="init" if="destination.temp.folder">
+               <mkdir dir="${destination.temp.folder}/${full.name}"/>
+               <copy file="${build.result.folder}/phpeclipse.jar" todir="${destination.temp.folder}/${full.name}"/>
+       </target>
+
+       <target name="phpeclipse.jar" depends="init" unless="phpeclipse.jar">
+               <property name="destdir" value="${temp.folder}/phpeclipse.jar.bin"/>
+               <delete dir="${temp.folder}/phpeclipse.jar.bin"/>
+               <mkdir dir="${temp.folder}/phpeclipse.jar.bin"/>
+               <!-- compile the source code -->
+               <javac destdir="${temp.folder}/phpeclipse.jar.bin" failonerror="false" verbose="true" debug="on" includeAntRuntime="no" bootclasspath="${bootclasspath}" classpath="../../plugins/org.eclipse.core.resources.win32_2.0.0/resources.jar;PHPEclipse.jar;../../plugins/org.eclipse.swt_2.0.0/ws/${ws}/swt.jar;../../plugins/org.eclipse.core.boot_2.0.0/bin;../../plugins/org.eclipse.core.runtime_2.0.0/runtime.jar;../../plugins/org.eclipse.core.boot_2.0.0/boot.jar;../../plugins/org.eclipse.ui.win32_2.0.0/workbench.jar;../../plugins/org.eclipse.swt_2.0.0/bin;../../plugins/org.eclipse.core.resources_2.0.0/bin;../../plugins/org.eclipse.core.resources_2.0.0/resources.jar;../../plugins/org.eclipse.swt.win32_2.0.0/ws/${ws}/swt.jar;../../plugins/org.eclipse.help_2.0.0/bin;../../plugins/org.eclipse.ui_2.0.0/workbench.jar;../../plugins/org.eclipse.core.runtime_2.0.0/bin;../../plugins/org.eclipse.help_2.0.0/help.jar;../../plugins/org.eclipse.ui_2.0.0/bin;../../plugins/org.eclipse.ui.win32_2.0.0/workbenchwin32.jar">
+                       <src path="src/"/>
+               </javac>
+               <!-- copy necessary resources -->
+               <copy todir="${temp.folder}/phpeclipse.jar.bin">
+                       <fileset dir="src/" excludes="**/*.java"/>
+               </copy>
+               <mkdir dir="${build.result.folder}"/>
+               <jar jarfile="${build.result.folder}/phpeclipse.jar" basedir="${temp.folder}/phpeclipse.jar.bin"/>
+               <delete dir="${temp.folder}/phpeclipse.jar.bin"/>
+       </target>
+
+       <target name="phpeclipsesrc.zip" depends="init" unless="phpeclipsesrc.zip">
+               <mkdir dir="${build.result.folder}"/>
+               <zip zipfile="${build.result.folder}/phpeclipsesrc.zip" filesonly="false">
+                       <fileset dir="src/" includes="**/*.java"/>
+               </zip>
+       </target>
+
+       <target name="build.jars" depends="init">
+               <available property="phpeclipse.jar" file="${build.result.folder}/phpeclipse.jar"/>
+               <antcall target="phpeclipse.jar"/>
+       </target>
+
+       <target name="build.sources" depends="init">
+               <available property="phpeclipsesrc.zip" file="${build.result.folder}/phpeclipsesrc.zip"/>
+               <antcall target="phpeclipsesrc.zip"/>
+       </target>
+
+       <target name="build.zips" depends="init">
+       </target>
+
+       <target name="gather.sources" depends="init" if="destination.temp.folder">
+               <mkdir dir="${destination.temp.folder}/${full.name}"/>
+               <copy file="${build.result.folder}/phpeclipsesrc.zip" todir="${destination.temp.folder}/${full.name}"/>
+       </target>
+
+       <target name="gather.logs" depends="init" if="destination.temp.folder">
+               <mkdir dir="${destination.temp.folder}/${full.name}"/>
+               <copy file="${temp.folder}/phpeclipse.jar.bin.log" todir="${destination.temp.folder}/${full.name}"/>
+       </target>
+
+       <target name="clean" depends="init">
+               <delete file="${build.result.folder}/phpeclipse.jar"/>
+               <delete file="${build.result.folder}/phpeclipsesrc.zip"/>
+               <delete file="${plugin.destination}/${full.name}.jar"/>
+               <delete file="${plugin.destination}/${full.name}.zip"/>
+               <delete dir="${temp.folder}"/>
+       </target>
+
+       <target name="refresh" depends="init" if="eclipse.running">
+               <eclipse.refreshLocal resource="${plugin}" depth="infinite"/>
+       </target>
+
+       <target name="zip.plugin" depends="init">
+               <delete dir="${temp.folder}"/>
+               <mkdir dir="${temp.folder}"/>
+               <antcall target="build.jars"/>
+               <antcall target="build.sources"/>
+               <antcall target="gather.bin.parts">
+                       <param name="destination.temp.folder" value="${temp.folder}/"/>
+               </antcall>
+               <antcall target="gather.sources">
+                       <param name="destination.temp.folder" value="${temp.folder}/"/>
+               </antcall>
+               <delete>
+                       <fileset dir="${temp.folder}" includes="**/*.bin.log"/>
+               </delete>
+               <zip zipfile="${plugin.destination}/${full.name}.zip" basedir="${temp.folder}" filesonly="true"/>
+               <delete dir="${temp.folder}"/>
+       </target>
+
+</project>
diff --git a/net.sourceforge.phpeclipse/install.txt b/net.sourceforge.phpeclipse/install.txt
new file mode 100644 (file)
index 0000000..5a4aa23
--- /dev/null
@@ -0,0 +1,16 @@
+Installing the PHPEclipse plugin is quite straightforward :
+
+- Make sure you have Eclipse 2.0 properly setup or download it from www.eclipse.org 
+
+- Simply unzip the files in your eclipse plugins 
+  directory (<your path>\eclipse\plugins). 
+
+- (re)Start Eclipse. 
+
+- Open the "Resource Perspective" in the Eclipse IDE and add a file with a 
+  *.php, *.php3 or *.php4 extension to your source tree. 
+  With a right mouse click on the PHP file you should see the new menu entry 
+  "Open With->PHP Editor". 
+
+- For more Information go to the menu "Help->Help Contents" and 
+  open the "PHPEclipse Help" 
\ No newline at end of file
index 2b9a211..8e19278 100644 (file)
@@ -1,4 +1,5 @@
-<toc label="PHP Online Help" topic="doc/index.html">
+<toc label="PHPEclipse Help" topic="doc/phpeclipse/index.html">
+  <topic label="PHP Help Table of Contents" href="doc/index.html"/>
   <topic label="I. Getting Started" href="doc/getting-started.html"/>
   <topic label="II. Language Reference" href="doc/langref.html"/>
   <topic label="III. Features" href="doc/features.html"/>
index 7a8b7b1..5169f87 100644 (file)
@@ -9,3 +9,5 @@ providerName = EclipseProject.de
 #
 phpEditorName=PHP Editor
 phpFileExtension=php
+php3FileExtension=php3
+php4FileExtension=php4
index 98a1e91..b8fec77 100644 (file)
@@ -2,14 +2,14 @@
 <plugin
    id="net.sourceforge.phpeclipse"
    name="%pluginName"
-   version="1.0.1"
+   version="1.0.2"
    provider-name="%providerName"
    class="net.sourceforge.phpeclipse.PHPeclipsePlugin">
 
    <runtime>
-      <library name="PHPEclipse.jar"/>
+      <library name="phpeclipse.jar"/>
    </runtime>
-   <requires>s
+   <requires>
       <import plugin="org.eclipse.core.resources"/>
       <import plugin="org.eclipse.ui"/>
       <import plugin="org.eclipse.help"/>
       <editor
             name="%phpEditorName"
             icon="icons/obj16/java.gif"
-            extensions="php,php3,php4"
+            extensions="php"
+            contributorClass="net.sourceforge.phpeclipse.phpeditor.PHPActionContributor"
+            class="net.sourceforge.phpeclipse.phpeditor.PHPEditor"
+            id="net.sourceforge.phpeclipse.PHPEditor">
+      </editor>
+      <editor
+            name="%phpEditorName"
+            icon="icons/obj16/java.gif"
+            extensions="php3"
+            contributorClass="net.sourceforge.phpeclipse.phpeditor.PHPActionContributor"
+            class="net.sourceforge.phpeclipse.phpeditor.PHPEditor"
+            id="net.sourceforge.phpeclipse.PHPEditor">
+      </editor>
+      <editor
+            name="%phpEditorName"
+            icon="icons/obj16/java.gif"
+            extensions="php4"
             contributorClass="net.sourceforge.phpeclipse.phpeditor.PHPActionContributor"
             class="net.sourceforge.phpeclipse.phpeditor.PHPEditor"
             id="net.sourceforge.phpeclipse.PHPEditor">
             nameFilter="*.php"
             id="net.sourceforge.phpeclipse.actions.popupShowAction">
          <action
-               label="Open in Browser"
+               label="Open PHP Browser"
+               class="net.sourceforge.phpeclipse.actions.PHPEclipseShowAction"
+               menubarPath="additions"
+               id="net.sourceforge.phpeclipse.actions.showAction">
+         </action>
+      </objectContribution>
+            <objectContribution
+            objectClass="org.eclipse.core.resources.IFile"
+            nameFilter="*.php3"
+            id="net.sourceforge.phpeclipse.actions.popupShowAction">
+         <action
+               label="Open PHP Browser"
+               class="net.sourceforge.phpeclipse.actions.PHPEclipseShowAction"
+               menubarPath="additions"
+               id="net.sourceforge.phpeclipse.actions.showAction">
+         </action>
+      </objectContribution>
+            <objectContribution
+            objectClass="org.eclipse.core.resources.IFile"
+            nameFilter="*.php4"
+            id="net.sourceforge.phpeclipse.actions.popupShowAction">
+         <action
+               label="Open PHP Browser"
                class="net.sourceforge.phpeclipse.actions.PHPEclipseShowAction"
                menubarPath="additions"
                id="net.sourceforge.phpeclipse.actions.showAction">
             id="net.sourceforge.phpeclipse.phpeditor.PHPDocumentProvider">
       </provider>
    </extension>
+      <extension
+         point="org.eclipse.ui.documentProviders">
+      <provider
+            extensions="%php3FileExtension"
+            class="net.sourceforge.phpeclipse.phpeditor.PHPDocumentProvider"
+            id="net.sourceforge.phpeclipse.phpeditor.PHPDocumentProvider">
+      </provider>
+   </extension>
+      <extension
+         point="org.eclipse.ui.documentProviders">
+      <provider
+            extensions="%php4FileExtension"
+            class="net.sourceforge.phpeclipse.phpeditor.PHPDocumentProvider"
+            id="net.sourceforge.phpeclipse.phpeditor.PHPDocumentProvider">
+      </provider>
+   </extension>
    <extension point="org.eclipse.help.toc">
       <toc file="phphelp.xml" primary="true"/>
    </extension>
index 911cceb..20ede98 100644 (file)
@@ -14,10 +14,21 @@ package net.sourceforge.phpeclipse;
 import java.util.MissingResourceException;
 import java.util.ResourceBundle;
 
+import net.sourceforge.phpeclipse.phpeditor.PHPDocumentProvider;
 import org.eclipse.core.resources.IWorkspace;
 import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.IPluginDescriptor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.MultiStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+//import org.eclipse.jdt.internal.ui.JavaStatusConstants;
+//import org.eclipse.jdt.internal.ui.JavaUIMessages;
 import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
 import org.eclipse.ui.plugin.AbstractUIPlugin;
 
 /**
@@ -32,10 +43,18 @@ public class PHPeclipsePlugin extends AbstractUIPlugin {
        public static final String APACHE_START_PREF = "_apache_start";
        public static final String APACHE_STOP_PREF = "_apache_stop";
        public static final String APACHE_RESTART_PREF = "_apache_restart";
+  
+  /**
+   * The id of the PHP plugin (value <code>"net.sourceforge.phpeclipse"</code>).
+   */ 
+  public static final String ID_PLUGIN= "net.sourceforge.phpeclipse"; //$NON-NLS-1$
+  
        //The shared instance.
        private static PHPeclipsePlugin plugin;
        //Resource bundle.
        private ResourceBundle resourceBundle;
+  
+  private PHPDocumentProvider fCompilationUnitDocumentProvider;
        /**
        * The Java virtual machine that we are running on.  
        */
@@ -75,6 +94,13 @@ public class PHPeclipsePlugin extends AbstractUIPlugin {
                }
        }
 
+  // @TODO: refactor this into a better method name !
+  public PHPDocumentProvider getCompilationUnitDocumentProvider() {
+    if (fCompilationUnitDocumentProvider == null)
+      fCompilationUnitDocumentProvider= new PHPDocumentProvider();
+    return fCompilationUnitDocumentProvider;
+  }
+  
        public static void setJVM() {
                String osName = System.getProperty("os.name");
 
@@ -124,6 +150,52 @@ public class PHPeclipsePlugin extends AbstractUIPlugin {
        public static IWorkspace getWorkspace() {
                return ResourcesPlugin.getWorkspace();
        }
+  public static IWorkbenchPage getActivePage() {
+    return getDefault().getActivePage();
+  }
+  
+  public static IWorkbenchWindow getActiveWorkbenchWindow() {
+    return getDefault().getWorkbench().getActiveWorkbenchWindow();
+  }
+  
+  public static Shell getActiveWorkbenchShell() {
+    return getActiveWorkbenchWindow().getShell();
+  }
+  
+  public static String getPluginId() {
+    return getDefault().getDescriptor().getUniqueIdentifier();
+  }
+
+  public static void log(IStatus status) {
+    getDefault().getLog().log(status);
+  }
+  
+//  public static void logErrorMessage(String message) {
+//    log(new Status(IStatus.ERROR, getPluginId(), JavaStatusConstants.INTERNAL_ERROR, message, null));
+//  }
+//
+//  public static void logErrorStatus(String message, IStatus status) {
+//    if (status == null) {
+//      logErrorMessage(message);
+//      return; 
+//    }
+//    MultiStatus multi= new MultiStatus(getPluginId(), JavaStatusConstants.INTERNAL_ERROR, message, null);
+//    multi.add(status);
+//    log(multi);
+//  }
+//  
+//  public static void log(Throwable e) {
+//    log(new Status(IStatus.ERROR, getPluginId(), JavaStatusConstants.INTERNAL_ERROR, JavaUIMessages.getString("JavaPlugin.internal_error"), e)); //$NON-NLS-1$
+//  }
+  
+  public static boolean isDebug() {
+    return getDefault().isDebugging();
+  }
+  
+  static IPath getInstallLocation() {
+    return new Path(getDefault().getDescriptor().getInstallURL().getFile());
+  }
 
        /**
         * Returns the string from the plugin's resource bundle,
diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPRestartApacheAction.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPRestartApacheAction.java
new file mode 100644 (file)
index 0000000..a5c461e
--- /dev/null
@@ -0,0 +1,31 @@
+/**********************************************************************
+Copyright (c) 2000, 2002 IBM Corp. and others.
+All rights reserved. This program and the accompanying materials
+are made available under the terms of the Common Public License v1.0
+which accompanies this distribution, and is available at
+http://www.eclipse.org/legal/cpl-v10.html
+
+Contributors:
+    IBM Corporation - Initial implementation
+    Klaus Hartlage - www.eclipseproject.de
+**********************************************************************/
+package net.sourceforge.phpeclipse.actions;
+
+import java.io.IOException;
+import java.text.MessageFormat;
+
+import net.sourceforge.phpeclipse.PHPeclipsePlugin;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.IWorkbenchWindowActionDelegate;
+
+public class PHPRestartApacheAction extends PHPStartApacheAction {
+       public void run(IAction action) {
+               final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
+               execute(store.getString(PHPeclipsePlugin.APACHE_RESTART_PREF));
+       }
+}
diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPStartApacheAction.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPStartApacheAction.java
new file mode 100644 (file)
index 0000000..7f69883
--- /dev/null
@@ -0,0 +1,62 @@
+/**********************************************************************
+Copyright (c) 2000, 2002 IBM Corp. and others.
+All rights reserved. This program and the accompanying materials
+are made available under the terms of the Common Public License v1.0
+which accompanies this distribution, and is available at
+http://www.eclipse.org/legal/cpl-v10.html
+
+Contributors:
+    IBM Corporation - Initial implementation
+    Klaus Hartlage - www.eclipseproject.de
+**********************************************************************/
+package net.sourceforge.phpeclipse.actions;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.text.MessageFormat;
+
+import net.sourceforge.phpeclipse.PHPeclipsePlugin;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.IWorkbenchWindowActionDelegate;
+
+public class PHPStartApacheAction implements IWorkbenchWindowActionDelegate {
+       protected IWorkbenchWindow activeWindow = null;
+
+       public void run(IAction action) {
+               final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
+               String documentRoot = store.getString(PHPeclipsePlugin.DOCUMENTROOT_PREF);
+               // replace backslash with slash in the DocumentRoot under Windows
+               documentRoot = documentRoot.replace('\\', '/');
+               String[] arguments = { documentRoot };
+               MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.APACHE_START_PREF));
+               execute(form.format(arguments));
+       }
+
+       public void execute(String command) {
+//             MessageDialog.openInformation(activeWindow.getShell(), "Exec command: ", command);
+               try {
+                       Runtime runtime = Runtime.getRuntime();
+                       //      Process process = runtime.exec(new String[] { "c:\\apache\\apache.exe" });
+                       Process process = runtime.exec(command);
+               } catch (IOException e) {
+                       MessageDialog.openInformation(activeWindow.getShell(), "IOException: ", e.getMessage());
+               }
+       }
+
+       public void selectionChanged(IAction action, ISelection selection) {
+
+       }
+
+       public void init(IWorkbenchWindow window) {
+               this.activeWindow = window;
+       }
+
+       public void dispose() {
+
+       }
+}
diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPStartMySQLAction.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPStartMySQLAction.java
new file mode 100644 (file)
index 0000000..31c5586
--- /dev/null
@@ -0,0 +1,31 @@
+/**********************************************************************
+Copyright (c) 2000, 2002 IBM Corp. and others.
+All rights reserved. This program and the accompanying materials
+are made available under the terms of the Common Public License v1.0
+which accompanies this distribution, and is available at
+http://www.eclipse.org/legal/cpl-v10.html
+
+Contributors:
+    IBM Corporation - Initial implementation
+    Klaus Hartlage - www.eclipseproject.de
+**********************************************************************/
+package net.sourceforge.phpeclipse.actions;
+
+import java.io.IOException;
+import java.text.MessageFormat;
+
+import net.sourceforge.phpeclipse.PHPeclipsePlugin;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.IWorkbenchWindowActionDelegate;
+
+public class PHPStartMySQLAction extends PHPStartApacheAction {
+       public void run(IAction action) {
+               final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
+               execute(store.getString(PHPeclipsePlugin.MYSQL_PREF));
+       }
+}
diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPStopApacheAction.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPStopApacheAction.java
new file mode 100644 (file)
index 0000000..3711fcd
--- /dev/null
@@ -0,0 +1,31 @@
+/**********************************************************************
+Copyright (c) 2000, 2002 IBM Corp. and others.
+All rights reserved. This program and the accompanying materials
+are made available under the terms of the Common Public License v1.0
+which accompanies this distribution, and is available at
+http://www.eclipse.org/legal/cpl-v10.html
+
+Contributors:
+    IBM Corporation - Initial implementation
+    Klaus Hartlage - www.eclipseproject.de
+**********************************************************************/
+package net.sourceforge.phpeclipse.actions;
+
+import java.io.IOException;
+import java.text.MessageFormat;
+
+import net.sourceforge.phpeclipse.PHPeclipsePlugin;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.IWorkbenchWindowActionDelegate;
+
+public class PHPStopApacheAction extends PHPStartApacheAction {
+       public void run(IAction action) {
+               final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
+               execute(store.getString(PHPeclipsePlugin.APACHE_STOP_PREF));
+       }
+}
index dfc01fb..1bf4dbe 100644 (file)
@@ -12,13 +12,11 @@ Contributors:
     Klaus Hartlage - www.eclipseproject.de
 **********************************************************************/
 
-import java.text.MessageFormat;
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.List;
 
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-
 import org.eclipse.jface.text.BadLocationException;
 import org.eclipse.jface.text.BadPositionCategoryException;
 import org.eclipse.jface.text.DefaultPositionUpdater;
@@ -32,14 +30,15 @@ import org.eclipse.jface.viewers.LabelProvider;
 import org.eclipse.jface.viewers.SelectionChangedEvent;
 import org.eclipse.jface.viewers.TreeViewer;
 import org.eclipse.jface.viewers.Viewer;
-
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
 import org.eclipse.ui.texteditor.IDocumentProvider;
 import org.eclipse.ui.texteditor.ITextEditor;
 import org.eclipse.ui.views.contentoutline.ContentOutlinePage;
 
 /**
- * A content outline page which always represents the content of the
- * connected editor in 10 segments.
+ * A content outline page which always represents the functions of the
+ * connected PHPEditor.
  */
 public class PHPContentOutlinePage extends ContentOutlinePage {
 
@@ -59,6 +58,12 @@ public class PHPContentOutlinePage extends ContentOutlinePage {
       return name;
     }
   };
+  
+  protected static class SegmentComparator implements Comparator {
+    public int compare(Object o1, Object o2) {
+      return ((Segment)o1).name.compareToIgnoreCase(((Segment)o2).name);
+    }
+  }
 
   /**
    * Divides the editor's document into ten segments and provides elements for them.
@@ -68,6 +73,7 @@ public class PHPContentOutlinePage extends ContentOutlinePage {
     protected final static String SEGMENTS = "__php_segments"; //$NON-NLS-1$
     protected IPositionUpdater fPositionUpdater = new DefaultPositionUpdater(SEGMENTS);
     protected List fContent = new ArrayList(10);
+    protected List fVariables = new ArrayList(100);
 
     private String getIdentifier(String text, int firstIndex) {
       int i = firstIndex;
@@ -76,7 +82,9 @@ public class PHPContentOutlinePage extends ContentOutlinePage {
       StringBuffer identifier = new StringBuffer();
       while (i < textLength) {
         c = text.charAt(i++);
-        if (Character.isJavaIdentifierPart(c)) {
+        if (Character.isJavaIdentifierPart(c) || (c=='$')) {
+          identifier.append(c);
+        } else if ( (i==firstIndex+1) && (c=='$')) {
           identifier.append(c);
         } else {
           return identifier.toString();
@@ -189,9 +197,15 @@ public class PHPContentOutlinePage extends ContentOutlinePage {
             functionMode = true;
             i+=8;
           }
+        } else if (c == '$') {
+          // get the variable name
+          identifier = getIdentifier(text, i - 1);
+          fVariables.add( identifier );
         }
 
       }
+      Collections.sort(fContent, new SegmentComparator());
+      Collections.sort(fVariables);
 
       //                       for (int line = 0; line < lines; line += increment) {
       //
@@ -230,6 +244,7 @@ public class PHPContentOutlinePage extends ContentOutlinePage {
       }
 
       fContent.clear();
+      fVariables.clear();
 
       if (newInput != null) {
         IDocument document = fDocumentProvider.getDocument(newInput);
@@ -250,6 +265,10 @@ public class PHPContentOutlinePage extends ContentOutlinePage {
         fContent.clear();
         fContent = null;
       }
+            if (fVariables != null) {
+        fVariables.clear();
+        fVariables = null;
+      }
     }
 
     /*
@@ -266,6 +285,12 @@ public class PHPContentOutlinePage extends ContentOutlinePage {
       return fContent.toArray();
     }
 
+    /**
+     * returns all PHP variables
+     */
+    public Object[] getVariables() {
+      return fVariables.toArray();
+    }
     /*
      * @see ITreeContentProvider#hasChildren(Object)
      */
index 919bdd9..1c603b6 100644 (file)
@@ -26,41 +26,44 @@ import net.sourceforge.phpeclipse.phpeditor.php.PHPPartitionScanner;
 
 public class PHPDocumentProvider extends FileDocumentProvider {
 
-       // private final static String[] TYPES= new String[] { PHPPartitionScanner.PHP, PHPPartitionScanner.JAVA_DOC, PHPPartitionScanner.JAVA_MULTILINE_COMMENT };
-private final static String[] TYPES= new String[] { PHPPartitionScanner.PHP, PHPPartitionScanner.JAVA_MULTILINE_COMMENT };
+  // private final static String[] TYPES= new String[] { PHPPartitionScanner.PHP, PHPPartitionScanner.JAVA_DOC, PHPPartitionScanner.JAVA_MULTILINE_COMMENT };
+  private final static String[] TYPES = new String[] { 
+    PHPPartitionScanner.PHP,
+//    PHPPartitionScanner.HTML, 
+    PHPPartitionScanner.HTML_MULTILINE_COMMENT };
 
-       private static PHPPartitionScanner fgScanner= null;
+  private static PHPPartitionScanner fgScanner = null;
 
-       public PHPDocumentProvider() {
-               super();
-       }
-       
-       /* (non-Javadoc)
-        * Method declared on AbstractDocumentProvider
-        */
-        protected IDocument createDocument(Object element) throws CoreException {
-               IDocument document= super.createDocument(element);
-               if (document != null) {
-                       IDocumentPartitioner partitioner= createJavaPartitioner();
-                       document.setDocumentPartitioner(partitioner);
-                       partitioner.connect(document);
-               }
-               return document;
-       }
-       
-       /**
-        * Return a partitioner for .java files.
-        */
-        private IDocumentPartitioner createJavaPartitioner() {
-               return new DefaultPartitioner(getPHPPartitionScanner(), TYPES);
-       }
-       
-       /**
-        * Return a scanner for creating java partitions.
-        */
-        private PHPPartitionScanner getPHPPartitionScanner() {
-               if (fgScanner == null)
-                       fgScanner= new PHPPartitionScanner();
-               return fgScanner;
-       }
+  public PHPDocumentProvider() {
+    super();
+  }
+
+  /* (non-Javadoc)
+   * Method declared on AbstractDocumentProvider
+   */
+  protected IDocument createDocument(Object element) throws CoreException {
+    IDocument document = super.createDocument(element);
+    if (document != null) {
+      IDocumentPartitioner partitioner = createPHPPartitioner();
+      document.setDocumentPartitioner(partitioner);
+      partitioner.connect(document);
+    }
+    return document;
+  }
+
+  /**
+   * Return a partitioner for .php files.
+   */
+  private IDocumentPartitioner createPHPPartitioner() {
+    return new DefaultPartitioner(getPHPPartitionScanner(), TYPES);
+  }
+
+  /**
+   * Return a scanner for creating java partitions.
+   */
+  private PHPPartitionScanner getPHPPartitionScanner() {
+    if (fgScanner == null)
+      fgScanner = new PHPPartitionScanner();
+    return fgScanner;
+  }
 }
index df0c4cc..2608187 100644 (file)
@@ -11,7 +11,7 @@ Contributors:
     IBM Corporation - Initial implementation
     Klaus Hartlage - www.eclipseproject.de
 **********************************************************************/
-import net.sourceforge.phpeclipse.phpeditor.php.PHPWordDetector;
+import net.sourceforge.phpeclipse.phpeditor.php.PHPWordExtractor;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.help.IHelp;
@@ -168,7 +168,7 @@ public class PHPEditor extends TextEditor {
   }
   
   private String getFunctionName(IDocument doc, int pos) {
-    Point word = PHPWordDetector.findWord(doc, pos);
+    Point word = PHPWordExtractor.findWord(doc, pos);
     if (word != null) {
       try {
         return doc.get(word.x, word.y).replace('_', '-');
index 47760a9..f50c26d 100644 (file)
@@ -12,63 +12,70 @@ Contributors:
     Klaus Hartlage - www.eclipseproject.de
 **********************************************************************/
 
-import org.eclipse.jface.text.rules.RuleBasedScanner;
+import net.sourceforge.phpeclipse.phpeditor.php.HTMLCodeScanner;
 import net.sourceforge.phpeclipse.phpeditor.php.PHPCodeScanner;
-//import net.sourceforge.phpeclipse.phpeditor.html.JavaDocScanner;
+import net.sourceforge.phpeclipse.phpeditor.php.HTMLCodeScanner;
 import net.sourceforge.phpeclipse.phpeditor.util.PHPColorProvider;
+import org.eclipse.jface.text.rules.RuleBasedScanner;
 
-/** The JavaEditorEnvironment maintains singletons used by the java editor
- * examples.
+/** The PHPEditorEnvironment maintains singletons used by the php editor
  */
 public class PHPEditorEnvironment {
 
-       private static PHPColorProvider fgColorProvider;
-       private static PHPCodeScanner fgCodeScanner;
-       //private static JavaDocScanner fgDocScanner;
+  private static PHPColorProvider fgColorProvider;
+  private static PHPCodeScanner fgCodeScanner;
+  private static HTMLCodeScanner fgHTMLCodeScanner;
+  //private static JavaDocScanner fgDocScanner;
+
+  private static int fgRefCount = 0;
+
+  /**
+   * A connection has occured - initialize the receiver if it is the first activation.
+   */
+  public static void connect(Object client) {
+    if (++fgRefCount == 1) {
+      fgColorProvider = new PHPColorProvider();
+      fgCodeScanner = new PHPCodeScanner(fgColorProvider);
+      fgHTMLCodeScanner = new HTMLCodeScanner(fgColorProvider);
+      //               fgDocScanner= new JavaDocScanner(fgColorProvider);
+    }
+  }
+
+  /**
+   * A disconnection has occured - clear the receiver if it is the last deactivation.
+   */
+  public static void disconnect(Object client) {
+    if (--fgRefCount == 0) {
+      fgCodeScanner = null;
+      fgHTMLCodeScanner = null;
+      //                       fgDocScanner= null;
+      fgColorProvider.dispose();
+      fgColorProvider = null;
+    }
+  }
+
+  /**
+   * Returns the singleton scanner.
+   */
+  public static RuleBasedScanner getPHPCodeScanner() {
+    return fgCodeScanner;
+  }
+
+  public static RuleBasedScanner getHTMLCodeScanner() {
+    return fgHTMLCodeScanner;
+  }
 
-       private static int fgRefCount= 0;
+  /**
+   * Returns the singleton color provider.
+   */
+  public static PHPColorProvider getJavaColorProvider() {
+    return fgColorProvider;
+  }
 
-       /**
-        * A connection has occured - initialize the receiver if it is the first activation.
-        */
-       public static void connect(Object client) {
-               if (++fgRefCount == 1) {
-                       fgColorProvider= new PHPColorProvider();
-                       fgCodeScanner= new PHPCodeScanner(fgColorProvider);
-       //              fgDocScanner= new JavaDocScanner(fgColorProvider);
-               }
-       }
-       
-       /**
-        * A disconnection has occured - clear the receiver if it is the last deactivation.
-        */
-        public static void disconnect(Object client) {
-               if (--fgRefCount == 0) {
-                       fgCodeScanner= null;
-//                     fgDocScanner= null;
-                       fgColorProvider.dispose();
-                       fgColorProvider= null;
-               }
-       }
-       
-       /**
-        * Returns the singleton scanner.
-        */
-        public static RuleBasedScanner getPHPCodeScanner() {
-               return fgCodeScanner;
-       }
-       
-       /**
-        * Returns the singleton color provider.
-        */
-        public static PHPColorProvider getJavaColorProvider() {
-               return fgColorProvider;
-       }
-       
-       /**
-        * Returns the singleton document scanner.
-        */
-//      public static RuleBasedScanner getJavaDocScanner() {
-//             return fgDocScanner;
-//     }
+  /**
+   * Returns the singleton document scanner.
+   */
+  //    public static RuleBasedScanner getJavaDocScanner() {
+  //           return fgDocScanner;
+  //   }
 }
index e69de29..0ad7081 100644 (file)
@@ -0,0 +1,33 @@
+#############################################################
+#
+# (c) Copyright IBM Corp. 2000, 2001.
+# All Rights Reserved.
+#
+#############################################################
+
+## Actions ##
+
+ContentAssistProposal.label=Content Assist@Ctrl+SPACE
+ContentAssistProposal.tooltip=Content Assist
+ContentAssistProposal.image=
+ContentAssistProposal.description=Content Assist
+
+ContentAssistTip.label=Content Tip@Ctrl+SHIFT+SPACE
+ContentAssistTip.tooltip=Content Tip
+ContentAssistTip.image=
+ContentAssistTip.description=Content Tip
+
+TogglePresentation.label=Change Presentation
+TogglePresentation.tooltip=Enable/Disable Segmented Source Viewer
+TogglePresentation.image=togglepresentation.gif
+TogglePresentation.description=Enable/Disable Segmented Source Viewer
+
+OutlinePage.segment.title_pattern=position {0}
+
+AutoIndent.error.bad_location_1=JavaAutoIndentStrategy.getAutoIndentString: BadLocationException
+AutoIndent.error.bad_location_2=JavaAutoIndentStrategy.calcShiftBackReplace: BadLocationException
+
+CompletionProcessor.ContextInfo.display.pattern=proposal {0} at position {1}
+CompletionProcessor.ContextInfo.value.pattern=proposal {0} valid from {1} to {2}
+CompletionProcessor.Proposal.ContextInfo.pattern={0} valid 5 characters around insertion point
+CompletionProcessor.Proposal.hoverinfo.pattern=Java keyword: {0}
diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPFunctionHelpResource.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPFunctionHelpResource.java
new file mode 100644 (file)
index 0000000..e14fcdf
--- /dev/null
@@ -0,0 +1,36 @@
+/**********************************************************************
+Copyright (c) 2000, 2002 IBM Corp. and others.
+All rights reserved. This program and the accompanying materials
+are made available under the terms of the Common Public License v1.0
+which accompanies this distribution, and is available at
+http://www.eclipse.org/legal/cpl-v10.html
+
+Contributors:
+    IBM Corporation - Initial implementation
+    Klaus Hartlage - www.eclipseproject.de
+**********************************************************************/
+package net.sourceforge.phpeclipse.phpeditor;
+
+import org.eclipse.help.IHelpResource;
+
+/**
+ * Example implementation for an <code>ITextHover</code> 
+ * which hovers over PHP code.
+ */
+public class PHPFunctionHelpResource implements IHelpResource {
+
+  private String word;
+
+  public PHPFunctionHelpResource(String word) {
+    this.word = word;
+  }
+
+  public String getHref() {
+    return "/net.sourceforge.phpeclipse/doc/function." + word + ".html";
+  }
+
+  public String getLabel() {
+    return "PHP Context Help";
+  }
+
+}
\ No newline at end of file
index c6aaad9..abea8df 100644 (file)
@@ -11,7 +11,6 @@ Contributors:
 **********************************************************************/
 package net.sourceforge.phpeclipse.phpeditor;
 
-
 import java.util.List;
 
 import org.eclipse.swt.graphics.RGB;
@@ -45,123 +44,125 @@ import net.sourceforge.phpeclipse.phpeditor.util.PHPColorProvider;
  */
 public class PHPSourceViewerConfiguration extends SourceViewerConfiguration {
 
-       /**
-        * Single token scanner.
-        */
-       static class SingleTokenScanner extends BufferedRuleBasedScanner {
-               public SingleTokenScanner(TextAttribute attribute) {
-                       setDefaultReturnToken(new Token(attribute));
-               }
-       };
-
-       /**
-        * Default constructor.
-        */
-       public PHPSourceViewerConfiguration() {
-       }
-
-       /* (non-Javadoc)
-        * Method declared on SourceViewerConfiguration
-        */
-       public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
-               return new PHPAnnotationHover();
-       }
-
-       /* (non-Javadoc)
-        * Method declared on SourceViewerConfiguration
-        */
-       public IAutoIndentStrategy getAutoIndentStrategy(ISourceViewer sourceViewer, String contentType) {
-               return (IDocument.DEFAULT_CONTENT_TYPE.equals(contentType) ? new PHPAutoIndentStrategy() : new DefaultAutoIndentStrategy());
-       }
-
-       /* (non-Javadoc)
-        * Method declared on SourceViewerConfiguration
-        */
-       public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
-               return new String[] {
-                       IDocument.DEFAULT_CONTENT_TYPE,
-      PHPPartitionScanner.PHP,
-               //      PHPPartitionScanner.JAVA_DOC,
-                       PHPPartitionScanner.JAVA_MULTILINE_COMMENT };
-       }
-
-       /* (non-Javadoc)
-        * Method declared on SourceViewerConfiguration
-        */
-       public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
-
-               ContentAssistant assistant = new ContentAssistant();
-               assistant.setContentAssistProcessor(new PHPCompletionProcessor(), IDocument.DEFAULT_CONTENT_TYPE);
-       //      assistant.setContentAssistProcessor(new JavaDocCompletionProcessor(), PHPPartitionScanner.JAVA_DOC);
-
-               assistant.enableAutoActivation(true);
-               assistant.setAutoActivationDelay(500);
-               assistant.setProposalPopupOrientation(assistant.PROPOSAL_OVERLAY);
-               assistant.setContextInformationPopupOrientation(assistant.CONTEXT_INFO_ABOVE);
-               assistant.setContextInformationPopupBackground(PHPEditorEnvironment.getJavaColorProvider().getColor(new RGB(150, 150, 0)));
-
-               return assistant;
-       }
-
-       /* (non-Javadoc)
-        * Method declared on SourceViewerConfiguration
-        */
-       public String getDefaultPrefix(ISourceViewer sourceViewer, String contentType) {
-               return (IDocument.DEFAULT_CONTENT_TYPE.equals(contentType) ? "//" : null); //$NON-NLS-1$
-       }
-
-       /* (non-Javadoc)
-        * Method declared on SourceViewerConfiguration
-        */
-       public ITextDoubleClickStrategy getDoubleClickStrategy(ISourceViewer sourceViewer, String contentType) {
-               return new PHPDoubleClickSelector();
-       }
-
-       /* (non-Javadoc)
-        * Method declared on SourceViewerConfiguration
-        */
-       public String[] getIndentPrefixes(ISourceViewer sourceViewer, String contentType) {
-               return new String[] { "\t", "    " }; //$NON-NLS-1$ //$NON-NLS-2$
-       }
-
-       /* (non-Javadoc)
-        * Method declared on SourceViewerConfiguration
-        */
-       public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
-
-               PHPColorProvider provider = PHPEditorEnvironment.getJavaColorProvider();
-               PresentationReconciler reconciler = new PresentationReconciler();
-
-               DefaultDamagerRepairer dr = new DefaultDamagerRepairer(new SingleTokenScanner(new TextAttribute(provider.getColor(provider.HTML_DEFAULT))));
-               reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
-               reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
+  /**
+   * Single token scanner.
+   */
+  static class SingleTokenScanner extends BufferedRuleBasedScanner {
+    public SingleTokenScanner(TextAttribute attribute) {
+      setDefaultReturnToken(new Token(attribute));
+    }
+  };
+
+  /**
+   * Default constructor.
+   */
+  public PHPSourceViewerConfiguration() {
+  }
+
+  /* (non-Javadoc)
+   * Method declared on SourceViewerConfiguration
+   */
+  public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
+    return new PHPAnnotationHover();
+  }
+
+  /* (non-Javadoc)
+   * Method declared on SourceViewerConfiguration
+   */
+  public IAutoIndentStrategy getAutoIndentStrategy(ISourceViewer sourceViewer, String contentType) {
+    return (IDocument.DEFAULT_CONTENT_TYPE.equals(contentType) ? new PHPAutoIndentStrategy() : new DefaultAutoIndentStrategy());
+  }
+
+  /* (non-Javadoc)
+   * Method declared on SourceViewerConfiguration
+   */
+  public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
+    return new String[] { IDocument.DEFAULT_CONTENT_TYPE, PHPPartitionScanner.PHP,
+      //       PHPPartitionScanner.JAVA_DOC,
+      PHPPartitionScanner.HTML_MULTILINE_COMMENT };
+  }
+
+  /* (non-Javadoc)
+   * Method declared on SourceViewerConfiguration
+   */
+  public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
+
+    ContentAssistant assistant = new ContentAssistant();
+    // assistant.setContentAssistProcessor(new PHPCompletionProcessor(), IDocument.DEFAULT_CONTENT_TYPE);
+    assistant.setContentAssistProcessor(new PHPCompletionProcessor(), PHPPartitionScanner.PHP);
+
+    assistant.enableAutoActivation(true);
+    assistant.setAutoActivationDelay(500);
+    assistant.setProposalPopupOrientation(assistant.PROPOSAL_OVERLAY);
+    assistant.setContextInformationPopupOrientation(assistant.CONTEXT_INFO_ABOVE);
+    assistant.setContextInformationPopupBackground(PHPEditorEnvironment.getJavaColorProvider().getColor(new RGB(150, 150, 0)));
+
+    return assistant;
+  }
+
+  /* (non-Javadoc)
+   * Method declared on SourceViewerConfiguration
+   */
+  public String getDefaultPrefix(ISourceViewer sourceViewer, String contentType) {
+    return (IDocument.DEFAULT_CONTENT_TYPE.equals(contentType) ? "//" : null); //$NON-NLS-1$
+  }
+
+  /* (non-Javadoc)
+   * Method declared on SourceViewerConfiguration
+   */
+  public ITextDoubleClickStrategy getDoubleClickStrategy(ISourceViewer sourceViewer, String contentType) {
+    return new PHPDoubleClickSelector();
+  }
+
+  /* (non-Javadoc)
+   * Method declared on SourceViewerConfiguration
+   */
+  public String[] getIndentPrefixes(ISourceViewer sourceViewer, String contentType) {
+    return new String[] { "\t", "    " }; //$NON-NLS-1$ //$NON-NLS-2$
+  }
+
+  /* (non-Javadoc)
+   * Method declared on SourceViewerConfiguration
+   */
+  public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
+
+    PHPColorProvider provider = PHPEditorEnvironment.getJavaColorProvider();
+    PresentationReconciler reconciler = new PresentationReconciler();
+    
+    DefaultDamagerRepairer dr= new DefaultDamagerRepairer(PHPEditorEnvironment.getHTMLCodeScanner());
+    reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
+    reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
     
+//    dr = new DefaultDamagerRepairer(new SingleTokenScanner(new TextAttribute(provider.getColor(provider.HTML_DEFAULT))));
+//    reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
+//    reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
+
     dr = new DefaultDamagerRepairer(PHPEditorEnvironment.getPHPCodeScanner());
     reconciler.setDamager(dr, PHPPartitionScanner.PHP);
     reconciler.setRepairer(dr, PHPPartitionScanner.PHP);
-    
-//             dr = new DefaultDamagerRepairer(new SingleTokenScanner(new TextAttribute(provider.getColor(provider.JAVADOC_DEFAULT))));
-//             reconciler.setDamager(dr, PHPPartitionScanner.JAVA_DOC);
-//             reconciler.setRepairer(dr, PHPPartitionScanner.JAVA_DOC);
-
-               dr = new DefaultDamagerRepairer(new SingleTokenScanner(new TextAttribute(provider.getColor(provider.MULTI_LINE_COMMENT))));
-               reconciler.setDamager(dr, PHPPartitionScanner.JAVA_MULTILINE_COMMENT);
-               reconciler.setRepairer(dr, PHPPartitionScanner.JAVA_MULTILINE_COMMENT);
-
-               return reconciler;
-       }
-
-       /* (non-Javadoc)
-        * Method declared on SourceViewerConfiguration
-        */
-       public int getTabWidth(ISourceViewer sourceViewer) {
-               return 4;
-       }
-
-       /* (non-Javadoc)
-        * Method declared on SourceViewerConfiguration
-        */
-       public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) {
-               return new PHPTextHover();
-       }
+
+//    dr = new DefaultDamagerRepairer(PHPEditorEnvironment.getHTMLCodeScanner());
+//    reconciler.setDamager(dr, PHPPartitionScanner.HTML);
+//    reconciler.setRepairer(dr, PHPPartitionScanner.HTML);
+
+    dr = new DefaultDamagerRepairer(new SingleTokenScanner(new TextAttribute(provider.getColor(provider.MULTI_LINE_COMMENT))));
+    reconciler.setDamager(dr, PHPPartitionScanner.HTML_MULTILINE_COMMENT);
+    reconciler.setRepairer(dr, PHPPartitionScanner.HTML_MULTILINE_COMMENT);
+
+    return reconciler;
+  }
+
+  /* (non-Javadoc)
+   * Method declared on SourceViewerConfiguration
+   */
+  public int getTabWidth(ISourceViewer sourceViewer) {
+    return 4;
+  }
+
+  /* (non-Javadoc)
+   * Method declared on SourceViewerConfiguration
+   */
+  public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) {
+    return new PHPTextHover();
+  }
 }
index 3f8e79a..071cb9f 100644 (file)
@@ -11,41 +11,43 @@ Contributors:
 **********************************************************************/
 package net.sourceforge.phpeclipse.phpeditor;
 
-
-import org.eclipse.swt.graphics.Point;
+import net.sourceforge.phpeclipse.phpeditor.php.PHPWordExtractor;
 import org.eclipse.jface.text.BadLocationException;
 import org.eclipse.jface.text.IRegion;
 import org.eclipse.jface.text.ITextHover;
 import org.eclipse.jface.text.ITextViewer;
 import org.eclipse.jface.text.Region;
+import org.eclipse.swt.graphics.Point;
 
 /**
  * Example implementation for an <code>ITextHover</code> 
  * which hovers over PHP code.
  */
 public class PHPTextHover implements ITextHover {
+  private static PHPWordExtractor phpWordDetector = new PHPWordExtractor();
+  /* (non-Javadoc)
+   * Method declared on ITextHover
+   */
+  public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
+    if (hoverRegion != null) {
+      try {
+        if (hoverRegion.getLength() > -1) {
+          return textViewer.getDocument().get(hoverRegion.getOffset(), hoverRegion.getLength());
+        }
+      } catch (BadLocationException x) {
+      }
+    }
+    return "empty selection";
+  }
 
-       /* (non-Javadoc)
-        * Method declared on ITextHover
-        */
-       public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
-               if (hoverRegion != null) {
-                       try {
-                               if (hoverRegion.getLength() > -1)
-                                       return textViewer.getDocument().get(hoverRegion.getOffset(), hoverRegion.getLength());
-                       } catch (BadLocationException x) {
-                       }
-               }
-               return "empty selection";
-       }
-       
-       /* (non-Javadoc)
-        * Method declared on ITextHover
-        */
-       public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
-               Point selection= textViewer.getSelectedRange();
-               if (selection.x <= offset && offset < selection.x + selection.y)
-                       return new Region(selection.x, selection.y);
-               return new Region(offset, 0);
-       }
+  /* (non-Javadoc)
+   * Method declared on ITextHover
+   */
+  public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
+    Point selection = PHPWordExtractor.findWord(textViewer.getDocument(), offset);
+//  show the extracted word as a tooltip
+    if (selection!=null && selection.x <= offset && offset < selection.x + selection.y)
+      return new Region(selection.x, selection.y);
+    return new Region(offset, 0);
+  }
 }
diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/HTMLCodeScanner.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/HTMLCodeScanner.java
new file mode 100644 (file)
index 0000000..ccc6b92
--- /dev/null
@@ -0,0 +1,152 @@
+/**********************************************************************
+Copyright (c) 2000, 2002 IBM Corp. and others.
+All rights reserved. This program and the accompanying materials
+are made available under the terms of the Common Public License v1.0
+which accompanies this distribution, and is available at
+http://www.eclipse.org/legal/cpl-v10.html
+
+Contributors:
+    IBM Corporation - Initial implementation
+    Klaus Hartlage - www.eclipseproject.de
+**********************************************************************/
+package net.sourceforge.phpeclipse.phpeditor.php;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import net.sourceforge.phpeclipse.phpeditor.util.HTMLWordDetector;
+import net.sourceforge.phpeclipse.phpeditor.util.PHPColorProvider;
+import net.sourceforge.phpeclipse.phpeditor.util.PHPWhitespaceDetector;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.TextAttribute;
+import org.eclipse.jface.text.rules.ICharacterScanner;
+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.RuleBasedScanner;
+import org.eclipse.jface.text.rules.SingleLineRule;
+import org.eclipse.jface.text.rules.Token;
+import org.eclipse.jface.text.rules.WhitespaceRule;
+import org.eclipse.jface.text.rules.WordRule;
+
+/**
+ * A Java code scanner.
+ */
+public class HTMLCodeScanner extends RuleBasedScanner {
+
+  private static String[] fgKeywords = {
+  };
+
+  private static String[] fgTypes = {
+  };
+
+  private IToken keyword;
+
+  private class HTMLWordRule extends WordRule {
+    private StringBuffer fBuffer = new StringBuffer();
+
+    public HTMLWordRule(IWordDetector detector) {
+      super(detector, Token.UNDEFINED);
+    }
+
+    public HTMLWordRule(IWordDetector detector, IToken defaultToken) {
+      super(detector, defaultToken);
+    }
+
+    public IToken evaluate(ICharacterScanner scanner) {
+      int c = scanner.read();
+      boolean tagBegin = false;
+      if (fDetector.isWordStart((char) c)) {
+        if (c == '<') {
+          tagBegin = true;
+        }
+        if (fColumn == UNDEFINED || (fColumn == scanner.getColumn() - 1)) {
+
+          fBuffer.setLength(0);
+          do {
+            fBuffer.append((char) c);
+            c = scanner.read();
+            if (c == '>') {
+              fBuffer.append((char) c);
+              c = scanner.read();
+              break;
+            }
+            if (c == '/' && (fBuffer.length() > 2) ) {
+              break;
+            }
+          } while (c != scanner.EOF && fDetector.isWordPart((char) c));
+          scanner.unread();
+
+          if (tagBegin) {
+            return keyword;
+          }
+          IToken token = (IToken) fWords.get(fBuffer.toString());
+          if (token != null)
+            return token;
+
+          if (fDefaultToken.isUndefined())
+            unreadBuffer(scanner);
+
+          return fDefaultToken;
+        }
+      }
+
+      scanner.unread();
+      return Token.UNDEFINED;
+    }
+
+  }
+
+  //private static String[] fgConstants = { "__LINE__", "__FILE__", "true", "false" };
+  private TextAttribute fComment;
+  private TextAttribute fKeyword;
+  private TextAttribute fType;
+  private TextAttribute fString;
+  private PHPColorProvider fColorProvider;
+
+  /**
+   * Creates a Java code scanner
+   */
+  public HTMLCodeScanner(PHPColorProvider provider) {
+
+    keyword = new Token(new TextAttribute(provider.getColor(PHPColorProvider.KEYWORD)));
+    IToken type = new Token(new TextAttribute(provider.getColor(PHPColorProvider.TYPE)));
+    IToken string = new Token(new TextAttribute(provider.getColor(PHPColorProvider.STRING)));
+    IToken comment = new Token(new TextAttribute(provider.getColor(PHPColorProvider.SINGLE_LINE_COMMENT)));
+    IToken multi_comment = new Token(new TextAttribute(provider.getColor(PHPColorProvider.MULTI_LINE_COMMENT)));
+    IToken other = new Token(new TextAttribute(provider.getColor(PHPColorProvider.DEFAULT)));
+
+    //variable = new Token(new TextAttribute(provider.getColor(PHPColorProvider.VARIABLE)));
+
+    List rules = new ArrayList();
+
+    // Add rule for single line comments.
+    //rules.add(new EndOfLineRule("//", comment)); //$NON-NLS-1$
+    //rules.add(new EndOfLineRule("#", comment));
+
+    // Add rule for strings and character constants.
+    rules.add(new SingleLineRule("\"", "\"", string)); //$NON-NLS-2$ //$NON-NLS-1$
+    // rules.add(new SingleLineRule("'", "'", string, '\\')); //$NON-NLS-2$ //$NON-NLS-1$
+
+    // rules.add(new SingleLineRule("//", "//", php_comment));
+    // rules.add(new MultiLineRule("/*", "*/", multi_comment));
+
+    // Add generic whitespace rule.
+    rules.add(new WhitespaceRule(new PHPWhitespaceDetector()));
+
+    // Add word rule for keywords, types, and constants.
+    HTMLWordRule wordRule = new HTMLWordRule(new HTMLWordDetector(), other);
+    for (int i = 0; i < fgKeywords.length; i++)
+      wordRule.addWord(fgKeywords[i], keyword);
+    for (int i = 0; i < fgTypes.length; i++)
+      wordRule.addWord(fgTypes[i], type);
+    //   for (int i = 0; i < fgConstants.length; i++)
+    //     wordRule.addWord(fgConstants[i], type);
+    rules.add(wordRule);
+
+    IRule[] result = new IRule[rules.size()];
+    rules.toArray(result);
+    setRules(result);
+  }
+
+}
diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/HTMLWordExtractor.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/HTMLWordExtractor.java
new file mode 100644 (file)
index 0000000..a79d914
--- /dev/null
@@ -0,0 +1,86 @@
+/**********************************************************************
+Copyright (c) 2000, 2002 IBM Corp. and others.
+All rights reserved. This program and the accompanying materials
+are made available under the terms of the Common Public License v1.0
+which accompanies this distribution, and is available at
+http://www.eclipse.org/legal/cpl-v10.html
+
+Contributors:
+    IBM Corporation - Initial implementation
+    Klaus Hartlage - www.eclipseproject.de
+**********************************************************************/
+package net.sourceforge.phpeclipse.phpeditor.php;
+
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+
+/**
+ * Detects HTML words in documents.
+ */
+public class HTMLWordExtractor {
+
+  /**
+   * Find the location of the word at offset in document.
+   * @returns Point - x is the start position, y is the end position.
+   *   Return null if it is not found.
+   * @param document the document being searched.
+   * @param offset - the position to start searching from.
+   */
+  public static Point findWord(IDocument document, int offset) {
+
+    int start = -1;
+    int end = -1;
+
+    try {
+
+      int position = offset;
+      char character = ' ';
+
+      while (position >= 0) {
+        character = document.getChar(position);
+        if (!Character.isJavaIdentifierPart(character))
+          break;
+        --position;
+      }
+      if ((position > 0) && (character == '<')) {
+        --position;
+      }
+      if ((position > 1) && (character == '/')) {
+        character = document.getChar(position - 1);
+        if (character == '<') {
+          --position;
+          --position;
+        }
+      }
+      if (position==offset) {
+        return null; 
+      }
+
+      start = position;
+
+      position = offset;
+      int length = document.getLength();
+      character = ' ';
+
+      while (position < length) {
+        character = document.getChar(position);
+        if (!Character.isJavaIdentifierPart(character))
+          break;
+        ++position;
+      }
+      if ((position < length) && (character == '>')) {
+        ++position;
+      }
+      start++;
+      end = position;
+
+      if (end > start)
+        return new Point(start, end - start);
+
+    } catch (BadLocationException x) {
+    }
+
+    return null;
+  }
+}
index 9e75272..c763b3f 100644 (file)
@@ -73,7 +73,7 @@ public class PHPCodeScanner extends RuleBasedScanner {
                        "echo",
                        "var" };
 
-       private static String[] fgTypes =
+       public static String[] fgFunctionNames =
                {
                        "COM_invoke",
                        "COM_load",
@@ -2506,8 +2506,8 @@ public class PHPCodeScanner extends RuleBasedScanner {
                PHPWordRule wordRule = new PHPWordRule(new PHPWordDetector(), other);
                for (int i = 0; i < fgKeywords.length; i++)
                        wordRule.addWord(fgKeywords[i], keyword);
-               for (int i = 0; i < fgTypes.length; i++)
-                       wordRule.addWord(fgTypes[i], type);
+               for (int i = 0; i < fgFunctionNames.length; i++)
+                       wordRule.addWord(fgFunctionNames[i], type);
                for (int i = 0; i < fgConstants.length; i++)
                        wordRule.addWord(fgConstants[i], type);
                rules.add(wordRule);
index a9b88fc..57e4372 100644 (file)
@@ -12,7 +12,10 @@ Contributors:
 package net.sourceforge.phpeclipse.phpeditor.php;
 
 import java.text.MessageFormat;
+import java.util.ArrayList;
 
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
 import org.eclipse.jface.text.ITextViewer;
 import org.eclipse.jface.text.TextPresentation;
 import org.eclipse.jface.text.contentassist.CompletionProposal;
@@ -22,130 +25,176 @@ import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
 import org.eclipse.jface.text.contentassist.IContextInformation;
 import org.eclipse.jface.text.contentassist.IContextInformationPresenter;
 import org.eclipse.jface.text.contentassist.IContextInformationValidator;
+import org.eclipse.swt.graphics.Point;
 
 /**
  * Example PHP completion processor.
  */
 public class PHPCompletionProcessor implements IContentAssistProcessor {
 
-       /**
-        * Simple content assist tip closer. The tip is valid in a range
-        * of 5 characters around its popup location.
-        */
-       protected static class Validator implements IContextInformationValidator, IContextInformationPresenter {
-
-               protected int fInstallOffset;
-
-               /*
-                * @see IContextInformationValidator#isContextInformationValid(int)
-                */
-               public boolean isContextInformationValid(int offset) {
-                       return Math.abs(fInstallOffset - offset) < 5;
-               }
-
-               /*
-                * @see IContextInformationValidator#install(IContextInformation, ITextViewer, int)
-                */
-               public void install(IContextInformation info, ITextViewer viewer, int offset) {
-                       fInstallOffset = offset;
-               }
-
-               /*
-                * @see org.eclipse.jface.text.contentassist.IContextInformationPresenter#updatePresentation(int, TextPresentation)
-                */
-               public boolean updatePresentation(int documentPosition, TextPresentation presentation) {
-                       return false;
-               }
-       };
-
-       protected final static String[] fgProposals =
-               {
-                       "array",
-                       "break",
-                       "class",
-                       "continue",
-                       "do",
-                       "echo",
-                       "else",
-                       "elseif",
-                       "endfor",
-                       "endif",
-                       "for",
-                       "if",
-                       "while",
-                       "endwhile",
-                       "switch",
-                       "case",
-                       "endswitch",
-                       "return",
-                       "define",
-                       "include",
-                       "include_once",
-                       "require",
-                       "require_once",
-                       "function",
-                       "new",
-                       "old_function",
-                       "default",
-                       "global",
-                       "static",
-                       "foreach",
-                       "endforeach",
-                       "extends",
-                       "empty",
-                       "isset",
-                       "var" };
-      
-       protected IContextInformationValidator fValidator = new Validator();
-
-       /* (non-Javadoc)
-        * Method declared on IContentAssistProcessor
-        */
-       public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) {
-               ICompletionProposal[] result = new ICompletionProposal[fgProposals.length];
-               for (int i = 0; i < fgProposals.length; i++) {
-                       IContextInformation info = new ContextInformation(fgProposals[i], MessageFormat.format(PHPEditorMessages.getString("CompletionProcessor.Proposal.ContextInfo.pattern"), new Object[] { fgProposals[i] })); //$NON-NLS-1$
-                       result[i] = new CompletionProposal(fgProposals[i], documentOffset, 0, fgProposals[i].length(), null, fgProposals[i], info, MessageFormat.format(PHPEditorMessages.getString("CompletionProcessor.Proposal.hoverinfo.pattern"), new Object[] { fgProposals[i] })); //$NON-NLS-1$
-               }
-               return result;
-       }
-
-       /* (non-Javadoc)
-        * Method declared on IContentAssistProcessor
-        */
-       public IContextInformation[] computeContextInformation(ITextViewer viewer, int documentOffset) {
-               IContextInformation[] result = new IContextInformation[5];
-               for (int i = 0; i < result.length; i++)
-                       result[i] = new ContextInformation(MessageFormat.format(PHPEditorMessages.getString("CompletionProcessor.ContextInfo.display.pattern"), new Object[] { new Integer(i), new Integer(documentOffset)}), //$NON-NLS-1$
-                       MessageFormat.format(PHPEditorMessages.getString("CompletionProcessor.ContextInfo.value.pattern"), new Object[] { new Integer(i), new Integer(documentOffset - 5), new Integer(documentOffset + 5)})); //$NON-NLS-1$
-               return result;
-       }
-
-       /* (non-Javadoc)
-        * Method declared on IContentAssistProcessor
-        */
-       public char[] getCompletionProposalAutoActivationCharacters() {
-               return new char[] { '.', '(' };
-       }
-
-       /* (non-Javadoc)
-        * Method declared on IContentAssistProcessor
-        */
-       public char[] getContextInformationAutoActivationCharacters() {
-               return new char[] { '#' };
-       }
-
-       /* (non-Javadoc)
-        * Method declared on IContentAssistProcessor
-        */
-       public IContextInformationValidator getContextInformationValidator() {
-               return fValidator;
-       }
-
-       /* (non-Javadoc)
-        * Method declared on IContentAssistProcessor
-        */
-       public String getErrorMessage() {
-               return null;
-       }
+  /**
+   * Simple content assist tip closer. The tip is valid in a range
+   * of 5 characters around its popup location.
+   */
+  protected static class Validator implements IContextInformationValidator, IContextInformationPresenter {
+
+    protected int fInstallOffset;
+
+    /*
+     * @see IContextInformationValidator#isContextInformationValid(int)
+     */
+    public boolean isContextInformationValid(int offset) {
+      return Math.abs(fInstallOffset - offset) < 5;
+    }
+
+    /*
+     * @see IContextInformationValidator#install(IContextInformation, ITextViewer, int)
+     */
+    public void install(IContextInformation info, ITextViewer viewer, int offset) {
+      fInstallOffset = offset;
+    }
+
+    /*
+     * @see org.eclipse.jface.text.contentassist.IContextInformationPresenter#updatePresentation(int, TextPresentation)
+     */
+    public boolean updatePresentation(int documentPosition, TextPresentation presentation) {
+      return false;
+    }
+  };
+
+  protected final static String[] fgProposals = PHPCodeScanner.fgFunctionNames;
+  //    {
+  //      "array",
+  //      "break",
+  //      "class",
+  //      "continue",
+  //      "do",
+  //      "echo",
+  //      "else",
+  //      "elseif",
+  //      "endfor",
+  //      "endif",
+  //      "for",
+  //      "if",
+  //      "while",
+  //      "endwhile",
+  //      "switch",
+  //      "case",
+  //      "endswitch",
+  //      "return",
+  //      "define",
+  //      "include",
+  //      "include_once",
+  //      "require",
+  //      "require_once",
+  //      "function",
+  //      "new",
+  //      "old_function",
+  //      "default",
+  //      "global",
+  //      "static",
+  //      "foreach",
+  //      "endforeach",
+  //      "extends",
+  //      "empty",
+  //      "isset",
+  //      "var" };
+
+  protected IContextInformationValidator fValidator = new Validator();
+
+  /* (non-Javadoc)
+   * Method declared on IContentAssistProcessor
+   */
+  public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) {
+
+    //    ArrayList arrList = new ArrayList(5);
+    //    IDocument document = viewer.getDocument();
+    //    if (documentOffset > 0) {
+    //      try {
+    //        char character = document.getChar(documentOffset - 1);
+    //        Point point = PHPWordExtractor.findWord(document, documentOffset);
+    //        if (point != null) {
+    //          String word = document.get(point.x, point.y);
+    //          for (int i = 0; i < fgProposals.length; i++) {
+    //            if ((fgProposals[i].length() >= point.y) && fgProposals[i].substring(0, point.y).equals(word)) {
+    //              IContextInformation info = new ContextInformation(fgProposals[i], MessageFormat.format(PHPEditorMessages.getString("CompletionProcessor.Proposal.ContextInfo.pattern"), new Object[] { fgProposals[i] })); //$NON-NLS-1$
+    //              arrList.add(new CompletionProposal(fgProposals[i], documentOffset, 0, fgProposals[i].length(), null, fgProposals[i], info, MessageFormat.format(PHPEditorMessages.getString("CompletionProcessor.Proposal.hoverinfo.pattern"), new Object[] { fgProposals[i] }))); //$NON-NLS-1$
+    //            }
+    //          }
+    //          if (arrList.size() > 0) {
+    //            ICompletionProposal[] result = new ICompletionProposal[arrList.size()];
+    //            for (int i=0;i<arrList.size();i++) {
+    //              result[i] = (CompletionProposal) arrList.get(i);
+    //            }
+    //            return result;
+    //          }
+    //        }
+    //      } catch (BadLocationException e) {
+    //      }
+    //
+    //    }
+
+    //    if (documentOffset > 0) {
+    //      try {
+    //        char character = document.getChar(documentOffset - 1);
+    //        if (character=='$') {
+    //          
+    //        }
+    //        result = new ICompletionProposal[fgProposals.length];
+    //        for (int i = 0; i < fgProposals.length; i++) {
+    //          IContextInformation info = new ContextInformation(fgProposals[i], MessageFormat.format(PHPEditorMessages.getString("CompletionProcessor.Proposal.ContextInfo.pattern"), new Object[] { fgProposals[i] })); //$NON-NLS-1$
+    //          result[i] = new CompletionProposal(fgProposals[i], documentOffset, 0, fgProposals[i].length(), null, fgProposals[i], info, MessageFormat.format(PHPEditorMessages.getString("CompletionProcessor.Proposal.hoverinfo.pattern"), new Object[] { fgProposals[i] })); //$NON-NLS-1$
+    //        }
+    //      } catch (BadLocationException e) {
+    //      }
+    //
+    //    } else {
+    ICompletionProposal[] result = new ICompletionProposal[fgProposals.length];
+    for (int i = 0; i < fgProposals.length; i++) {
+      IContextInformation info = new ContextInformation(fgProposals[i], MessageFormat.format(PHPEditorMessages.getString("CompletionProcessor.Proposal.ContextInfo.pattern"), new Object[] { fgProposals[i] })); //$NON-NLS-1$
+      result[i] = new CompletionProposal(fgProposals[i], documentOffset, 0, fgProposals[i].length(), null, fgProposals[i], info, MessageFormat.format(PHPEditorMessages.getString("CompletionProcessor.Proposal.hoverinfo.pattern"), new Object[] { fgProposals[i] })); //$NON-NLS-1$
+    }
+
+    return result;
+  }
+
+  /* (non-Javadoc)
+   * Method declared on IContentAssistProcessor
+   */
+  public IContextInformation[] computeContextInformation(ITextViewer viewer, int documentOffset) {
+    IContextInformation[] result = new IContextInformation[5];
+    for (int i = 0; i < result.length; i++)
+      result[i] = new ContextInformation(MessageFormat.format(PHPEditorMessages.getString("CompletionProcessor.ContextInfo.display.pattern"), new Object[] { new Integer(i), new Integer(documentOffset)}), //$NON-NLS-1$
+      MessageFormat.format(PHPEditorMessages.getString("CompletionProcessor.ContextInfo.value.pattern"), new Object[] { new Integer(i), new Integer(documentOffset - 5), new Integer(documentOffset + 5)})); //$NON-NLS-1$
+    return result;
+  }
+
+  /* (non-Javadoc)
+   * Method declared on IContentAssistProcessor
+   */
+  public char[] getCompletionProposalAutoActivationCharacters() {
+    return new char[] { '$' };
+  }
+
+  /* (non-Javadoc)
+   * Method declared on IContentAssistProcessor
+   */
+  public char[] getContextInformationAutoActivationCharacters() {
+    return new char[] {
+    };
+  }
+
+  /* (non-Javadoc)
+   * Method declared on IContentAssistProcessor
+   */
+  public IContextInformationValidator getContextInformationValidator() {
+    return fValidator;
+  }
+
+  /* (non-Javadoc)
+   * Method declared on IContentAssistProcessor
+   */
+  public String getErrorMessage() {
+    return null;
+  }
 }
index f8970bf..d45fffc 100644 (file)
@@ -16,19 +16,21 @@ import java.util.ResourceBundle;
 
 public class PHPEditorMessages {
 
-       private static final String RESOURCE_BUNDLE = "org.eclipse.ui.examples.javaeditor.JavaEditorMessages"; //$NON-NLS-1$
+       private static final String RESOURCE_BUNDLE = "net.sourceforge.phpeclipse.phpeditor.PHPEditorMessages"; //$NON-NLS-1$
+
+//     private static ResourceBundle fgResourceBundle = null;
+  private static ResourceBundle fgResourceBundle= ResourceBundle.getBundle(RESOURCE_BUNDLE);
 
-       private static ResourceBundle fgResourceBundle = null;
        // ResourceBundle.getBundle(RESOURCE_BUNDLE);
 
        private PHPEditorMessages() {
-               if (fgResourceBundle == null) {
-                       try {
-                               fgResourceBundle = ResourceBundle.getBundle(RESOURCE_BUNDLE);
-                       } catch (MissingResourceException x) {
-                               fgResourceBundle = null;
-                       }
-               }
+//             if (fgResourceBundle == null) {
+//                     try {
+//                             fgResourceBundle = ResourceBundle.getBundle(RESOURCE_BUNDLE);
+//                     } catch (MissingResourceException x) {
+//                             fgResourceBundle = null;
+//                     }
+//             }
        }
 
        public static String getString(String key) {
index 43970cd..bebcc1f 100644 (file)
@@ -30,10 +30,20 @@ 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 HTML_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 final static String HTML = "__html";
+
+  public final static IToken php = new Token(PHP);
+//  public final static IToken html = new Token(HTML);
+  public final static IToken comment = new Token(HTML_MULTILINE_COMMENT);
+
+  protected final static char[] php0EndSequence = { '<', '?' };
+  protected final static char[] php1EndSequence = { '<', '?', 'p', 'h', 'p' };
+  protected final static char[] php2EndSequence = { '<', '?', 'P', 'H', 'P' };
   private StringBuffer test;
+
   public class PHPMultiLineRule extends MultiLineRule {
 
     public PHPMultiLineRule(String startSequence, String endSequence, IToken token) {
@@ -115,8 +125,287 @@ public class PHPPartitionScanner extends RuleBasedPartitionScanner {
         }
       }
       scanner.unread();
+      return false;
+    }
+  }
+
+//  public class HTMLMultiLineRule extends MultiLineRule {
+//
+//    public HTMLMultiLineRule(String startSequence, String endSequence, IToken token) {
+//      super(startSequence, endSequence, token);
+//    }
+//
+//    public HTMLMultiLineRule(String startSequence, String endSequence, IToken token, char escapeCharacter) {
+//      super(startSequence, endSequence, token, escapeCharacter);
+//    }
+//
+//    protected boolean endSequenceDetected(ICharacterScanner scanner) {
+//      int c;
+//
+//      char[][] delimiters = scanner.getLegalLineDelimiters();
+//      while ((c = scanner.read()) != ICharacterScanner.EOF) {
+//        if (c == '<') {
+//          //       scanner.unread();
+//          if (sequenceDetected(scanner, php2EndSequence, true)) {
+//            // <?PHP
+//            scanner.unread();
+//            scanner.unread();
+//            scanner.unread();
+//            scanner.unread();
+//            scanner.unread();
+//            return true;
+//          }
+//          if (sequenceDetected(scanner, php1EndSequence, true)) {
+//            // <?php
+//            scanner.unread();
+//            scanner.unread();
+//            scanner.unread();
+//            scanner.unread();
+//            scanner.unread();
+//            return true;
+//          }
+//          if (sequenceDetected(scanner, php0EndSequence, true)) {
+//            // <?
+//            scanner.unread();
+//            scanner.unread();
+//            return true;
+//          }
+//          //      scanner.read();
+//        }
+//
+//      }
+//      scanner.unread();
+//      return false;
+//    }
+//
+//    protected IToken doEvaluate(ICharacterScanner scanner, boolean resume) {
+//
+//      if (resume) {
+//
+//        if (endSequenceDetected(scanner))
+//          return fToken;
+//
+//      } else {
+//
+//        int c = scanner.read();
+//        //     if (c == fStartSequence[0]) {
+//        //       if (sequenceDetected(scanner, fStartSequence, false)) {
+//        if (endSequenceDetected(scanner))
+//          return fToken;
+//        //       }
+//        //     }
+//      }
+//
+//      scanner.unread();
+//      return Token.UNDEFINED;
+//    }
+//
+//    public IToken evaluate(ICharacterScanner scanner, boolean resume) {
+//      if (fColumn == UNDEFINED)
+//        return doEvaluate(scanner, resume);
+//
+//      int c = scanner.read();
+//      scanner.unread();
+//      //    if (c == fStartSequence[0])
+//      return (fColumn == scanner.getColumn() ? doEvaluate(scanner, resume) : Token.UNDEFINED);
+//      //    else
+//      //      return Token.UNDEFINED;
+//    }
+//  }
+
+  public class HTMLPatternRule implements IPredicateRule {
+
+    protected static final int UNDEFINED = -1;
+
+    /** The token to be returned on success */
+    protected IToken fToken;
+
+    /** The pattern's column constrain */
+    protected int fColumn = UNDEFINED;
+    /** The pattern's escape character */
+    protected char fEscapeCharacter;
+    /** Indicates whether end of line termines the pattern */
+    protected boolean fBreaksOnEOL;
+
+    /**
+     * Creates a rule for the given starting and ending sequence.
+     * When these sequences are detected the rule will return the specified token.
+     * Alternatively, the sequence can also be ended by the end of the line.
+     * Any character which follows the given escapeCharacter will be ignored.
+     *
+     * @param startSequence the pattern's start sequence
+     * @param endSequence the pattern's end sequence, <code>null</code> is a legal value
+     * @param token the token which will be returned on success
+     * @param escapeCharacter any character following this one will be ignored
+     * @param indicates whether the end of the line also termines the pattern
+     */
+    public HTMLPatternRule(IToken token) {
+      fToken = token;
+      fEscapeCharacter = (char)0;
+      fBreaksOnEOL = false;
+    }
+
+    /**
+     * Sets a column constraint for this rule. If set, the rule's token
+     * will only be returned if the pattern is detected starting at the 
+     * specified column. If the column is smaller then 0, the column
+     * constraint is considered removed.
+     *
+     * @param column the column in which the pattern starts
+     */
+    public void setColumnConstraint(int column) {
+      if (column < 0)
+        column = UNDEFINED;
+      fColumn = column;
+    }
+
+    /**
+     * Evaluates this rules without considering any column constraints.
+     *
+     * @param scanner the character scanner to be used
+     * @return the token resulting from this evaluation
+     */
+    protected IToken doEvaluate(ICharacterScanner scanner) {
+      return doEvaluate(scanner, false);
+    }
+
+    /**
+     * Evaluates this rules without considering any column constraints. Resumes
+     * detection, i.e. look sonly for the end sequence required by this rule if the
+     * <code>resume</code> flag is set.
+     *
+     * @param scanner the character scanner to be used
+     * @param resume <code>true</code> if detection should be resumed, <code>false</code> otherwise
+     * @return the token resulting from this evaluation
+     * @since 2.0
+     */
+    protected IToken doEvaluate(ICharacterScanner scanner, boolean resume) {
+
+      if (resume) {
+
+        if (endSequenceDetected(scanner))
+          return fToken;
+
+      } else {
+
+        int c = scanner.read();
+        //      if (c == fStartSequence[0]) {
+        //        if (sequenceDetected(scanner, fStartSequence, false)) {
+        if (endSequenceDetected(scanner))
+          return fToken;
+        //        }
+        //      }
+      }
+
+      scanner.unread();
+      return Token.UNDEFINED;
+    }
+
+    /*
+     * @see IRule#evaluate
+     */
+    public IToken evaluate(ICharacterScanner scanner) {
+      return evaluate(scanner, false);
+    }
+
+    /**
+     * Returns whether the end sequence was detected. As the pattern can be considered 
+     * ended by a line delimiter, the result of this method is <code>true</code> if the 
+     * rule breaks on the end  of the line, or if the EOF character is read.
+     *
+     * @param scanner the character scanner to be used
+     * @return <code>true</code> if the end sequence has been detected
+     */
+    protected boolean endSequenceDetected(ICharacterScanner scanner) {
+      int c;
+
+      char[][] delimiters = scanner.getLegalLineDelimiters();
+      while ((c = scanner.read()) != ICharacterScanner.EOF) {
+        if (c == '<') {
+          //       scanner.unread();
+          if (sequenceDetected(scanner, php2EndSequence, true)) {
+            // <?PHP
+            scanner.unread();
+            scanner.unread();
+            scanner.unread();
+            scanner.unread();
+            scanner.unread();
+            return true;
+          }
+          if (sequenceDetected(scanner, php1EndSequence, true)) {
+            // <?php
+            scanner.unread();
+            scanner.unread();
+            scanner.unread();
+            scanner.unread();
+            scanner.unread();
+            return true;
+          }
+          if (sequenceDetected(scanner, php0EndSequence, true)) {
+            // <?
+            scanner.unread();
+            scanner.unread();
+            return true;
+          }
+          //      scanner.read();
+        }
+
+      }
+      scanner.unread();
+      return false;
+    }
+
+    /**
+     * Returns whether the next characters to be read by the character scanner
+     * are an exact match with the given sequence. No escape characters are allowed 
+     * within the sequence. If specified the sequence is considered to be found
+     * when reading the EOF character.
+     *
+     * @param scanner the character scanner to be used
+     * @param sequence the sequence to be detected
+     * @param eofAllowed indicated whether EOF terminates the pattern
+     * @return <code>true</code> if the given sequence has been detected
+     */
+    protected boolean sequenceDetected(ICharacterScanner scanner, char[] sequence, boolean eofAllowed) {
+      for (int i = 1; i < sequence.length; i++) {
+        int c = scanner.read();
+        if (c == ICharacterScanner.EOF && eofAllowed) {
+          return true;
+        } else if (c != sequence[i]) {
+          // Non-matching character detected, rewind the scanner back to the start.
+          scanner.unread();
+          for (int j = i - 1; j > 0; j--)
+            scanner.unread();
+          return false;
+        }
+      }
+
       return true;
     }
+
+    /*
+     * @see IPredicateRule#evaluate(ICharacterScanner, boolean)
+     * @since 2.0
+     */
+    public IToken evaluate(ICharacterScanner scanner, boolean resume) {
+      if (fColumn == UNDEFINED)
+        return doEvaluate(scanner, resume);
+
+      int c = scanner.read();
+      scanner.unread();
+      //    if (c == fStartSequence[0])
+      return (fColumn == scanner.getColumn() ? doEvaluate(scanner, resume) : Token.UNDEFINED);
+      //    else
+      //      return Token.UNDEFINED;
+    }
+
+    /*
+     * @see IPredicateRule#getSuccessToken()
+     * @since 2.0
+     */
+    public IToken getSuccessToken() {
+      return fToken;
+    }
   }
   /**
    * Detector for empty comments.
@@ -172,9 +461,9 @@ public class PHPPartitionScanner extends RuleBasedPartitionScanner {
   public PHPPartitionScanner() {
     super();
 
-    //         IToken javaDoc= new Token(JAVA_DOC);
-    IToken comment = new Token(JAVA_MULTILINE_COMMENT);
-    IToken php = new Token(PHP);
+    //    IToken php = new Token(PHP);
+    //    IToken html = new Token(HTML);
+    //    IToken comment = new Token(HTML_MULTILINE_COMMENT);
 
     List rules = new ArrayList();
 
@@ -186,10 +475,12 @@ public class PHPPartitionScanner extends RuleBasedPartitionScanner {
     // rules.add(new SingleLineRule("'", "'", Token.UNDEFINED, '\\')); 
 
     // Add special case word rule.
-    rules.add(new WordPredicateRule(comment));
+//    rules.add(new WordPredicateRule(comment));
 
     // Add rules for multi-line comments and javadoc.
     //rules.add(new MultiLineRule("/**", "*/", javaDoc));
+    //  rules.add(new HTMLMultiLineRule("<", "<?", html));
+
     rules.add(new MultiLineRule("<!--", "-->", comment));
     rules.add(new PHPMultiLineRule("<?\r", "?>", php));
     rules.add(new PHPMultiLineRule("<?\n", "?>", php));
@@ -197,10 +488,67 @@ public class PHPPartitionScanner extends RuleBasedPartitionScanner {
     rules.add(new PHPMultiLineRule("<? ", "?>", php));
     rules.add(new PHPMultiLineRule("<?php", "?>", php));
     rules.add(new PHPMultiLineRule("<?PHP", "?>", php));
+
+//    rules.add(new HTMLPatternRule(html)); // "<", "<?",
     //Add rule for processing instructions
 
     IPredicateRule[] result = new IPredicateRule[rules.size()];
     rules.toArray(result);
     setPredicateRules(result);
+//    setDefaultReturnToken(html);
   }
+
+  //    public IToken nextToken() {
+  //      
+  //      if (fContentType == null || fRules == null)
+  //        return getNextToken();
+  //      
+  //      fTokenOffset= fOffset;
+  //      fColumn= UNDEFINED;
+  //      boolean resume= (fPartitionOffset < fOffset);
+  //          
+  //      IPredicateRule rule;
+  //      IToken token;
+  //      
+  //      for (int i= 0; i < fRules.length; i++) {
+  //        rule= (IPredicateRule) fRules[i];
+  //        token= rule.getSuccessToken();
+  //        if (fContentType.equals(token.getData())) {
+  //          if (resume)
+  //            fTokenOffset= fPartitionOffset;
+  //          token= rule.evaluate(this, resume);
+  //          if (!token.isUndefined()) {
+  //            fContentType= null;
+  //            return token;
+  //          }
+  //        }
+  //      }
+  //      
+  //      fContentType= null;
+  //      return getNextToken();
+  //    }
+  //    
+  //    public IToken getNextToken() {
+  //      
+  //      IToken token;
+  //      
+  //      while (true) {
+  //        
+  //        fTokenOffset= fOffset;
+  //        fColumn= UNDEFINED;
+  //        
+  //        if (fRules != null) {
+  //          for (int i= 0; i < fRules.length; i++) {
+  //            token= (fRules[i].evaluate(this));
+  //            if (!token.isUndefined())
+  //              return token;
+  //          }
+  //        }
+  //        
+  //        if (read() == EOF)
+  //          return Token.EOF;
+  //        else
+  //          return fDefaultReturnToken;
+  //      }
+  //    }
 }
diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/togglepresentation.gif b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/togglepresentation.gif
new file mode 100644 (file)
index 0000000..a0831f0
Binary files /dev/null and b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/togglepresentation.gif differ
diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/util/HTMLWordDetector.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/util/HTMLWordDetector.java
new file mode 100644 (file)
index 0000000..839c350
--- /dev/null
@@ -0,0 +1,34 @@
+/**********************************************************************
+Copyright (c) 2000, 2002 IBM Corp. and others.
+All rights reserved. This program and the accompanying materials
+are made available under the terms of the Common Public License v1.0
+which accompanies this distribution, and is available at
+http://www.eclipse.org/legal/cpl-v10.html
+
+Contributors:
+    IBM Corporation - Initial implementation
+    Klaus Hartlage - www.eclipseproject.de
+**********************************************************************/
+package net.sourceforge.phpeclipse.phpeditor.util;
+
+import org.eclipse.jface.text.rules.IWordDetector;
+
+/**
+ * A Java aware word detector.
+ */
+public class HTMLWordDetector implements IWordDetector {
+
+       /* (non-Javadoc)
+        * Method declared on IWordDetector.
+        */
+       public boolean isWordPart(char character) {
+               return Character.isJavaIdentifierPart(character)||(character=='/')||(character=='>');
+       }
+       
+       /* (non-Javadoc)
+        * Method declared on IWordDetector.
+        */
+       public boolean isWordStart(char character) {
+               return character=='<';
+       }
+}