X-Git-Url: http://secure.phpeclipse.com

diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPDocumentProvider.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPDocumentProvider.java
index 919bdd9..2fa0115 100644
--- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPDocumentProvider.java
+++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPDocumentProvider.java
@@ -12,55 +12,134 @@ Contributors:
     Klaus Hartlage - www.eclipseproject.de
 **********************************************************************/
 
+import net.sourceforge.phpeclipse.phpeditor.php.IPHPPartitionScannerConstants;
+import net.sourceforge.phpeclipse.phpeditor.php.PHPPartitionScanner;
+
+import org.eclipse.core.resources.IFile;
 import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.text.DefaultLineTracker;
 import org.eclipse.jface.text.IDocument;
 import org.eclipse.jface.text.IDocumentPartitioner;
+import org.eclipse.jface.text.ILineTracker;
 import org.eclipse.jface.text.rules.DefaultPartitioner;
-import org.eclipse.jface.text.rules.RuleBasedPartitioner;
 import org.eclipse.ui.editors.text.FileDocumentProvider;
-import net.sourceforge.phpeclipse.phpeditor.php.PHPPartitionScanner;
+import org.eclipse.ui.part.FileEditorInput;
 
 /** 
- * The JavaDocumentProvider provides the IDocuments used by java editors.
+ * The PHPDocumentProvider provides the IDocuments used by java editors.
  */
 
 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 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;
-	}
+  // private final static String[] TYPES= new String[] { PHPPartitionScanner.PHP, PHPPartitionScanner.JAVA_DOC, PHPPartitionScanner.JAVA_MULTILINE_COMMENT };
+  private final static String[] TYPES =
+    new String[] {
+      IPHPPartitionScannerConstants.PHP,
+      IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT,
+      IPHPPartitionScannerConstants.HTML,
+      IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT,
+      IPHPPartitionScannerConstants.JAVASCRIPT,
+      IPHPPartitionScannerConstants.CSS };
+
+  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) {
+      //  int fileType = 0; // PHP 
+      IDocumentPartitioner partitioner = null;
+      if (element instanceof FileEditorInput) {
+        IFile file = (IFile) ((FileEditorInput) element).getAdapter(IFile.class);
+        String filename = file.getLocation().toString();
+        String extension = filename.substring(filename.lastIndexOf("."), filename.length());
+     //   System.out.println(extension);
+        if (extension.equalsIgnoreCase(".html") || extension.equalsIgnoreCase(".htm")) {
+          // html
+          partitioner = createHTMLPartitioner();
+        } else if (extension.equalsIgnoreCase(".xml")) {
+          // xml
+          partitioner = createXMLPartitioner();
+        } else if (extension.equalsIgnoreCase(".js")) {
+          // javascript
+          partitioner = createJavaScriptPartitioner();
+        } else if (extension.equalsIgnoreCase(".css")) {
+          // cascading style sheets
+          partitioner = createCSSPartitioner();
+        } else if (extension.equalsIgnoreCase(".tpl")) {
+          // smarty ?
+          partitioner = createSmartyPartitioner();
+        } else if (extension.equalsIgnoreCase(".inc")) {
+          // php include files ?
+          partitioner = createIncludePartitioner();
+        }
+      }
+
+      if (partitioner == null) {
+        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 partitioner for .html files.
+   */
+  private IDocumentPartitioner createHTMLPartitioner() {
+    return new DefaultPartitioner(getPHPPartitionScanner(), TYPES);
+  }
+
+  private IDocumentPartitioner createXMLPartitioner() {
+    return new DefaultPartitioner(getPHPPartitionScanner(), TYPES);
+  }
+
+  private IDocumentPartitioner createJavaScriptPartitioner() {
+    return new DefaultPartitioner(getPHPPartitionScanner(), TYPES);
+  }
+
+  private IDocumentPartitioner createCSSPartitioner() {
+    return new DefaultPartitioner(getPHPPartitionScanner(), TYPES);
+  }
+
+  private IDocumentPartitioner createSmartyPartitioner() {
+    return new DefaultPartitioner(getPHPPartitionScanner(), TYPES);
+  }
+
+  private IDocumentPartitioner createIncludePartitioner() {
+    return new DefaultPartitioner(getPHPPartitionScanner(), TYPES);
+  }
+  /**
+   * Return a scanner for creating php partitions.
+   */
+  private PHPPartitionScanner getPHPPartitionScanner() {
+    if (fgScanner == null)
+      fgScanner = new PHPPartitionScanner();
+    return fgScanner;
+  }
+
+  /**
+   * Creates a line tracker working with the same line delimiters as the document
+   * of the given element. Assumes the element to be managed by this document provider.
+   * 
+   * @param element the element serving as blue print
+   * @return a line tracker based on the same line delimiters as the element's document
+   */
+  public ILineTracker createLineTracker(Object element) {
+    return new DefaultLineTracker();
+  }
 }