Fixed bug in CodeFormatter; for partial formatting select complete <?php ... ?> range
authorkhartlage <khartlage>
Sat, 26 Jun 2004 17:05:11 +0000 (17:05 +0000)
committerkhartlage <khartlage>
Sat, 26 Jun 2004 17:05:11 +0000 (17:05 +0000)
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/formatter/CodeFormatter.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/java/JavaFormattingStrategy.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/JavaSourceViewer.java

index 7efbade..e4ec3cf 100644 (file)
@@ -15,14 +15,22 @@ import java.io.StringReader;
 import java.util.Hashtable;
 import java.util.Locale;
 import java.util.Map;
+
 import net.sourceforge.phpdt.core.ICodeFormatter;
 import net.sourceforge.phpdt.core.compiler.CharOperation;
 import net.sourceforge.phpdt.core.compiler.ITerminalSymbols;
 import net.sourceforge.phpdt.core.compiler.InvalidInputException;
 import net.sourceforge.phpdt.internal.compiler.ConfigurableOption;
 import net.sourceforge.phpdt.internal.compiler.parser.Scanner;
+import net.sourceforge.phpdt.internal.corext.codemanipulation.StubUtility;
+import net.sourceforge.phpdt.internal.corext.util.Strings;
 import net.sourceforge.phpdt.internal.formatter.impl.FormatterOptions;
 import net.sourceforge.phpdt.internal.formatter.impl.SplitLine;
+import net.sourceforge.phpdt.internal.ui.preferences.CodeFormatterPreferencePage;
+
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.formatter.IContentFormatterExtension;
+import org.eclipse.jface.text.formatter.IFormattingContext;
 /**
  * <h2>How to format a piece of code ?</h2>
  * <ul>
@@ -32,6 +40,7 @@ import net.sourceforge.phpdt.internal.formatter.impl.SplitLine;
  * </ul>
  */
 public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
+ // IContentFormatterExtension {
   public FormatterOptions options;
   /**
    * Represents a block in the <code>constructions</code> stack.
@@ -2536,4 +2545,5 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter {
   public void setInitialIndentationLevel(int newIndentationLevel) {
     this.initialIndentationLevel = currentLineIndentationLevel = indentationLevel = newIndentationLevel;
   }
+  
 }
\ No newline at end of file
index 264938e..56ba202 100644 (file)
@@ -1,6 +1,5 @@
 /*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved.
+ * (c) Copyright IBM Corp. 2000, 2001. All Rights Reserved.
  */
 package net.sourceforge.phpdt.internal.ui.text.java;
 
@@ -15,40 +14,44 @@ import org.eclipse.jface.text.formatter.IFormattingStrategy;
 import org.eclipse.jface.text.source.ISourceViewer;
 
 public class JavaFormattingStrategy implements IFormattingStrategy {
-       
-       private String fInitialIndentation;
-       private ISourceViewer fViewer;  
-
-       public JavaFormattingStrategy(ISourceViewer viewer) {
-               fViewer = viewer;
-       }
-       
-       /**
-        * @see IFormattingStrategy#formatterStarts(String)
-        */
-       public void formatterStarts(String initialIndentation) {
-               fInitialIndentation= initialIndentation;
-       }
-       
-       /**
-        * @see IFormattingStrategy#formatterStops()
-        */
-       public void formatterStops() {
-       }
-       
-       /**
-        * @see IFormattingStrategy#format(String, boolean, String, int[])
-        */
-       public String format(String content, boolean isLineStart, String indentation, int[] positions) {
-               ICodeFormatter formatter= ToolFactory.createCodeFormatter();
-               
-               IDocument doc= fViewer.getDocument();
-               String lineDelimiter= StubUtility.getLineDelimiterFor(doc);
-
-               int indent= 0;
-               if (fInitialIndentation != null) {
-                       indent= Strings.computeIndent(fInitialIndentation, CodeFormatterPreferencePage.getTabSize());
-               }
-               return formatter.format(content, indent, positions, lineDelimiter);
-       }       
+
+  private String fInitialIndentation;
+
+  private ISourceViewer fViewer;
+
+  public JavaFormattingStrategy(ISourceViewer viewer) {
+    fViewer = viewer;
+  }
+
+  /**
+   * @see IFormattingStrategy#formatterStarts(String)
+   */
+  public void formatterStarts(String initialIndentation) {
+    fInitialIndentation = initialIndentation;
+  }
+
+  /**
+   * @see IFormattingStrategy#formatterStops()
+   */
+  public void formatterStops() {
+  }
+
+  /**
+   * @see IFormattingStrategy#format(String, boolean, String, int[])
+   */
+  public String format(String content, boolean isLineStart, String indentation,
+      int[] positions) {
+    ICodeFormatter formatter = ToolFactory.createCodeFormatter();
+
+    IDocument doc = fViewer.getDocument();
+    String lineDelimiter = StubUtility.getLineDelimiterFor(doc);
+
+    int indent = 0;
+    if (fInitialIndentation != null) {
+      indent = Strings.computeIndent(fInitialIndentation,
+          CodeFormatterPreferencePage.getTabSize());
+    }
+
+    return formatter.format(content, indent, positions, lineDelimiter);
+  }
 }
\ No newline at end of file
index 2c2f4f4..e3e75ac 100644 (file)
@@ -38,7 +38,7 @@ import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
 
 
 public class JavaSourceViewer extends ProjectionViewer implements IPropertyChangeListener {
-
+    
        /** 
         * Text operation code for requesting the outline for the current input.
         */
@@ -134,6 +134,12 @@ public class JavaSourceViewer extends ProjectionViewer implements IPropertyChang
                        case SHOW_HIERARCHY:
 //                             fHierarchyPresenter.showInformation();
                                return; 
+                   case FORMAT:
+                     Point point = getSelectedRange();
+                     if (point.y==0) {
+                       setSelectedRange(0, getDocument().getLength());
+                     }
+                     break;
                }
                
                super.doOperation(operation);