Started with PHP/HTML Formatter menu => doesn't work right now
authorkhartlage <khartlage>
Wed, 19 Mar 2003 20:40:41 +0000 (20:40 +0000)
committerkhartlage <khartlage>
Wed, 19 Mar 2003 20:40:41 +0000 (20:40 +0000)
13 files changed:
net.sourceforge.phpeclipse/plugin.properties
net.sourceforge.phpeclipse/plugin.xml
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/preferences/EditTemplateDialog.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/preferences/TemplatePreferencePage.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/actions/PHPdtActionConstants.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPeclipsePlugin.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPActionContributor.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditorActionDefinitionIds.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPSourceViewerConfiguration.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/html/HTMLFormatter.java [new file with mode: 0644]
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/html/HTMLFormattingStrategy.java [new file with mode: 0644]
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/html/IHTMLConstants.java [new file with mode: 0644]

index 50f37d3..4cddf37 100644 (file)
@@ -54,6 +54,7 @@ CommentAction.label= Co&mment@Ctrl+/
 
 UncommentAction.label= &Uncomment@Ctrl+\\
 
+FormatAction.label= F&ormat@Ctrl+Shift+F
 ##########################################################################
 # Action Definitions
 ##########################################################################
@@ -67,3 +68,6 @@ ActionDefinition.comment.description= Turn the selected lines into PHP comments
 
 ActionDefinition.uncomment.name= Uncomment
 ActionDefinition.uncomment.description= Uncomment the selected PHP comment lines
+
+ActionDefinition.format.name= Format
+ActionDefinition.format.description= Format the source code
\ No newline at end of file
index 5d25fbb..ddafca2 100644 (file)
@@ -243,6 +243,13 @@ Temporarily replaced until errors can be ironed out...
                   name="editGroup">
             </separator>
          </menu>
+         <action 
+                       definitionId="net.sourceforge.phpeclipse.phpeditor.format"
+                       label="%FormatAction.label"
+                       retarget="true"
+                       menubarPath="net.sourceforge.phpeclipse.ui.source.menu/editGroup"
+                       id="net.sourceforge.phpeclipse.phpeditor.Format" >
+            </action>
          <action
                definitionId="net.sourceforge.phpeclipse.phpeditor.uncomment"
                label="%UncommentAction.label"
@@ -281,6 +288,11 @@ Temporarily replaced until errors can be ironed out...
             description="%ActionDefinition.uncomment.description"
             id="net.sourceforge.phpeclipse.phpeditor.Uncomment">
       </actionDefinition>
+       <actionDefinition
+           name= "%ActionDefinition.format.name"
+           description= "%ActionDefinition.format.description"
+               id="net.sourceforge.phpeclipse.phpeditor.Format">
+         </actionDefinition>
    </extension>
 <!--   <extension
          point="org.eclipse.ui.acceleratorSets">
@@ -638,6 +650,10 @@ Temporarily replaced until errors can be ironed out...
                key="Ctrl+\"
                id="net.sourceforge.phpeclipse.phpeditor.uncomment">
          </accelerator>
+         <accelerator 
+               key="Ctrl+Shift+F" 
+               id="net.sourceforge.phpeclipse.phpeditor.format">
+         </accelerator>
       </acceleratorSet>
       <acceleratorSet
             scopeId="org.eclipse.ui.textEditorScope"
@@ -656,6 +672,10 @@ Temporarily replaced until errors can be ironed out...
                key="Ctrl+\"
                id="net.sourceforge.phpeclipse.phpeditor.uncomment">
          </accelerator>
+         <accelerator 
+               key="Ctrl+Shift+F" 
+               id="net.sourceforge.phpeclipse.phpeditor.format">
+         </accelerator>
       </acceleratorSet>
       <acceleratorSet
             scopeId="org.eclipse.ui.textEditorScope"
index 0078f30..3458acd 100644 (file)
@@ -86,7 +86,7 @@ public class EditTemplateDialog extends StatusDialog {
 
        //      SimpleJavaSourceViewerConfiguration(JavaTextTools tools, ITextEditor editor, IContentAssistProcessor processor) {
                SimpleJavaSourceViewerConfiguration(IContentAssistProcessor processor) {        
-      super();
+      super(null);
                        fProcessor= processor;
                }
                
index 005aa5f..2fc70d4 100644 (file)
@@ -345,7 +345,7 @@ public class TemplatePreferencePage extends PreferencePage implements IWorkbench
     //         document.setDocumentPartitioner(partitioner);
     //         partitioner.connect(document);          
 
-    viewer.configure(new PHPSourceViewerConfiguration()); // (tools, null));
+    viewer.configure(new PHPSourceViewerConfiguration(null)); // (tools, null));
     viewer.setEditable(false);
     viewer.setDocument(document);
     viewer.getTextWidget().setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
index af602c4..0709883 100644 (file)
@@ -21,27 +21,33 @@ package net.sourceforge.phpdt.ui.actions;
  * @since 2.0
  */
 public class PHPdtActionConstants {
-       
-//     Edit menu
-
-       /**
-        * Edit menu: name of standard Code Assist global action
-        * (value <code>"org.phpeclipse.phpdt.ui.actions.ContentAssist"</code>).
-        */
-       public static final String CONTENT_ASSIST= "net.sourceforge.phpeclipse.phpeditor.ContentAssist"; //$NON-NLS-1$
-
-       // Source menu  
-       
-       /**
-        * Source menu: name of standard Comment global action
-        * (value <code>"net.sourceforge.phpdt.ui.actions.Comment"</code>).
-        */
-       public static final String COMMENT= "net.sourceforge.phpeclipse.phpeditor.Comment"; //$NON-NLS-1$
-       
-       /**
-        * Source menu: name of standard Uncomment global action
-        * (value <code>"net.sourceforge.phpdt.ui.actions.Uncomment"</code>).
-        */
-       public static final String UNCOMMENT= "net.sourceforge.phpeclipse.phpeditor.Uncomment"; //$NON-NLS-1$
-       
+
+  //   Edit menu
+
+  /**
+   * Edit menu: name of standard Code Assist global action
+   * (value <code>"org.phpeclipse.phpdt.ui.actions.ContentAssist"</code>).
+   */
+  public static final String CONTENT_ASSIST = "net.sourceforge.phpeclipse.phpeditor.ContentAssist"; //$NON-NLS-1$
+
+  // Source menu       
+
+  /**
+   * Source menu: name of standard Comment global action
+   * (value <code>"net.sourceforge.phpdt.ui.actions.Comment"</code>).
+   */
+  public static final String COMMENT = "net.sourceforge.phpeclipse.phpeditor.Comment"; //$NON-NLS-1$
+
+  /**
+   * Source menu: name of standard Uncomment global action
+   * (value <code>"net.sourceforge.phpdt.ui.actions.Uncomment"</code>).
+   */
+  public static final String UNCOMMENT = "net.sourceforge.phpeclipse.phpeditor.Uncomment"; //$NON-NLS-1$
+
+  /**
+   * Source menu: name of standard Format global action (value <code>"org.
+   * phpeclipse.phpdt.ui.actions.Format"</code>).
+   */
+  public static final String FORMAT = "net.sourceforge.phpeclipse.phpeditor.Format"; //$NON-NLS-1$
+
 }
index 1b89cad..7bfbf25 100644 (file)
@@ -103,6 +103,9 @@ public class PHPeclipsePlugin
 
   /** JVM constant for any other platform */
   private static final int OTHER = -1;
+  
+  /** General debug flag*/
+  public static final boolean DEBUG = false;
   /**
    * The constructor.
    */
@@ -228,6 +231,7 @@ public class PHPeclipsePlugin
   public static void log(Throwable e) {
     log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, "PHPeclipsePlugin.internalErrorOccurred", e)); //$NON-NLS-1$
   }
+  
   public static boolean isDebug() {
     return getDefault().isDebugging();
   }
index 7c6d220..587bc9d 100644 (file)
@@ -113,7 +113,8 @@ public class PHPActionContributor extends BasicTextEditorActionContributor   {
     IActionBars bars = getActionBars();
     bars.setGlobalActionHandler(PHPdtActionConstants.COMMENT, getAction(textEditor, "Comment"));
     bars.setGlobalActionHandler(PHPdtActionConstants.UNCOMMENT, getAction(textEditor, "Uncomment"));
-
+    bars.setGlobalActionHandler(PHPdtActionConstants.FORMAT, getAction(textEditor, "Format"));
+    
     if (part instanceof PHPEditor) {
       PHPEditor cuEditor= (PHPEditor)part;
       ActionGroup group= cuEditor.getActionGroup();
index 86ca2c9..479f880 100644 (file)
@@ -50,464 +50,458 @@ import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
  */
 public class PHPEditor extends TextEditor {
 
-       // protected PHPActionGroup fActionGroups;
-       /** The outline page */
-       private PHPContentOutlinePage fOutlinePage;
-       private IPreferenceStore phpPrefStore;
-
-       /** The line number ruler column */
-       private LineNumberRulerColumn fLineNumberRulerColumn;
-
-       protected CompositeActionGroup fActionGroups;
-       /** The standard action groups added to the menu */
-       private GenerateActionGroup fGenerateActionGroup;
-       private CompositeActionGroup fContextMenuGroup;
-       /**
-        * Default constructor.
-        */
-       public PHPEditor() {
-               super();
-               setRulerContextMenuId("#PHPRulerContext"); //$NON-NLS-1$
-       }
-//
-//     /**
-//      * @see IMember#getCompilationUnit()
-//      */
-//     public ICompilationUnit getCompilationUnit() {
-//             return this; 
-//     }
-//     /**
-//      * @see org.phpeclipse.phpdt.internal.compiler.env.ICompilationUnit#getContents()
-//      */
-//     public char[] getContents() {
-//             IDocument doc = this.getDocumentProvider().getDocument(this.getEditorInput());
-//     
-//             return doc.get().toCharArray();
-//     }
-
-       /**
-        * Returns this document's complete text.
-        *
-        * @return the document's complete text
-        */
-       public String get() {
-               IDocument doc = this.getDocumentProvider().getDocument(this.getEditorInput());
-               return doc.get();       
-       }
-       
-       /**
-        *  Returns the standard action group of this editor.
-        */
-       protected ActionGroup getActionGroup() {
-               return fActionGroups;
-       }
-
-       public PHPContentOutlinePage getfOutlinePage() {
-               return fOutlinePage;
-       }
-
-       /** The <code>PHPEditor</code> implementation of this 
-        * <code>AbstractTextEditor</code> method extend the 
-        * actions to add those specific to the receiver
-        */
-       protected void createActions() {
-               super.createActions();
-
-               Action action;
-               //    setAction(
-               //      "ContentAssistProposal",
-               //      new TextOperationAction(
-               //        PHPEditorMessages.getResourceBundle(),
-               //        "ContentAssistProposal.",
-               //        this,
-               //        ISourceViewer.CONTENTASSIST_PROPOSALS));
-               action = new ContentAssistAction(PHPEditorMessages.getResourceBundle(), "ContentAssistProposal.", this); //$NON-NLS-1$
-               action.setActionDefinitionId(
-                       PHPEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
-               setAction("ContentAssistProposal", action); //$NON-NLS-1$
-
-               //      System.out.println(action.getId());
-               //      System.out.println(action.getActionDefinitionId());
-
-               setAction(
-                       "ContentAssistTip",
-                       new TextOperationAction(
-                               PHPEditorMessages.getResourceBundle(),
-                               "ContentAssistTip.",
-                               this,
-                               ISourceViewer.CONTENTASSIST_CONTEXT_INFORMATION));
-
-               action =
-                       new TextOperationAction(
-                               PHPEditorMessages.getResourceBundle(),
-                               "Comment.",
-                               this,
-                               ITextOperationTarget.PREFIX);
-               action.setActionDefinitionId(PHPEditorActionDefinitionIds.COMMENT);
-               setAction("Comment", action);
-
-               //      System.out.println(action.getId());
-               //      System.out.println(action.getActionDefinitionId());
-
-               action =
-                       new TextOperationAction(
-                               PHPEditorMessages.getResourceBundle(),
-                               "Uncomment.",
-                               this,
-                               ITextOperationTarget.STRIP_PREFIX);
-               action.setActionDefinitionId(PHPEditorActionDefinitionIds.UNCOMMENT);
-               setAction("Uncomment", action);
-
-               //      System.out.println(action.getId());
-               //      System.out.println(action.getActionDefinitionId());
-
-               //  fActionGroups = new PHPActionGroup(this, ITextEditorActionConstants.GROUP_EDIT);
-
-               markAsStateDependentAction("Comment", true); //$NON-NLS-1$
-               markAsStateDependentAction("Uncomment", true); //$NON-NLS-1$
-
-               fGenerateActionGroup =
-                       new GenerateActionGroup(
-                               this,
-                               ITextEditorActionConstants.GROUP_EDIT);
-
-               fActionGroups =
-                       new CompositeActionGroup(
-                               new ActionGroup[] { fGenerateActionGroup });
-
-               // We have to keep the context menu group separate to have better control over positioning
-               fContextMenuGroup =
-                       new CompositeActionGroup(
-                               new ActionGroup[] { fGenerateActionGroup });
-               //      rg, 
-               //      new LocalHistoryActionGroup(this, ITextEditorActionConstants.GROUP_EDIT)});
-       }
-
-       /** The <code>PHPEditor</code> implementation of this 
-        * <code>AbstractTextEditor</code> method performs any extra 
-        * disposal actions required by the php editor.
-        */
-       public void dispose() {
-               PHPEditorEnvironment.disconnect(this);
-               if (fOutlinePage != null)
-                       fOutlinePage.setInput(null);
-
-               if (fActionGroups != null)
-                       fActionGroups.dispose();
-
-               super.dispose();
-       }
-
-       /** The <code>PHPEditor</code> implementation of this 
-        * <code>AbstractTextEditor</code> method performs any extra 
-        * revert behavior required by the php editor.
-        */
-       public void doRevertToSaved() {
-               super.doRevertToSaved();
-               if (fOutlinePage != null)
-                       fOutlinePage.update();
-       }
-
-       /** The <code>PHPEditor</code> implementation of this 
-        * <code>AbstractTextEditor</code> method performs any extra 
-        * save behavior required by the php editor.
-        */
-       public void doSave(IProgressMonitor monitor) {
-               super.doSave(monitor);
-               // compile or not, according to the user preferences
-               IPreferenceStore store = phpPrefStore;
-               if (store.getBoolean(PHPeclipsePlugin.PHP_PARSE_ON_SAVE)) {
-                       IAction a = PHPParserAction.getInstance();
-                       if (a != null)
-                               a.run();
-               }
-               if (fOutlinePage != null)
-                       fOutlinePage.update();
-       }
-
-       /** The <code>PHPEditor</code> implementation of this 
-        * <code>AbstractTextEditor</code> method performs any extra 
-        * save as behavior required by the php editor.
-        */
-       public void doSaveAs() {
-               super.doSaveAs();
-               if (fOutlinePage != null)
-                       fOutlinePage.update();
-       }
-
-       /** The <code>PHPEditor</code> implementation of this 
-        * <code>AbstractTextEditor</code> method performs sets the 
-        * input of the outline page after AbstractTextEditor has set input.
-        */
-       public void doSetInput(IEditorInput input) throws CoreException {
-               super.doSetInput(input);
-               if (fOutlinePage != null)
-                       fOutlinePage.setInput(input);
-       }
-
-       /** The <code>PHPEditor</code> implementation of this 
-        * <code>AbstractTextEditor</code> method adds any 
-        * PHPEditor specific entries.
-        */
-       public void editorContextMenuAboutToShow(MenuManager menu) {
-               super.editorContextMenuAboutToShow(menu);
-               //  addAction(menu, "ContentAssistProposal"); //$NON-NLS-1$
-               //  addAction(menu, "ContentAssistTip"); //$NON-NLS-1$
-
-               // fActionGroups.fillContextMenu(menu);
-
-               ActionContext context =
-                       new ActionContext(getSelectionProvider().getSelection());
-               fContextMenuGroup.setContext(context);
-               fContextMenuGroup.fillContextMenu(menu);
-               fContextMenuGroup.setContext(null);
-       }
-
-       protected void updateStateDependentActions() {
-               super.updateStateDependentActions();
-               fGenerateActionGroup.editorStateChanged();
-       }
-
-       /** The <code>PHPEditor</code> implementation of this 
-        * <code>AbstractTextEditor</code> method performs gets
-        * the java content outline page if request is for a an 
-        * outline page.
-        */
-       public Object getAdapter(Class required) {
-               if (IContentOutlinePage.class.equals(required)) {
-                       if (fOutlinePage == null) {
-                               fOutlinePage =
-                                       new PHPContentOutlinePage(getDocumentProvider(), this);
-                               if (getEditorInput() != null)
-                                       fOutlinePage.setInput(getEditorInput());
-                       }
-                       return fOutlinePage;
-               }
-               return super.getAdapter(required);
-       }
-
-       //  public void openContextHelp() {
-       //    IDocument doc = this.getDocumentProvider().getDocument(this.getEditorInput());
-       //    ITextSelection selection = (ITextSelection) this.getSelectionProvider().getSelection();
-       //    int pos = selection.getOffset();
-       //    String word = getFunctionName(doc, pos);
-       //    openContextHelp(word);
-       //  }
-       //
-       //  private void openContextHelp(String word) {
-       //    open(word);
-       //  }
-       //
-       //  public static void open(String word) {
-       //    IHelp help = WorkbenchHelp.getHelpSupport();
-       //    if (help != null) {
-       //      IHelpResource helpResource = new PHPFunctionHelpResource(word);
-       //      WorkbenchHelp.getHelpSupport().displayHelpResource(helpResource);
-       //    } else {
-       //      //   showMessage(shell, dialogTitle, ActionMessages.getString("Open help not available"), false); //$NON-NLS-1$
-       //    }
-       //  }
-
-//     private String getFunctionName(IDocument doc, int pos) {
-//             Point word = PHPWordExtractor.findWord(doc, pos);
-//             if (word != null) {
-//                     try {
-//                             return doc.get(word.x, word.y).replace('_', '-');
-//                     } catch (BadLocationException e) {
-//                     }
-//             }
-//             return "";
-//     }
-
-       /*
-          * @see AbstractTextEditor#handlePreferenceStoreChanged(PropertyChangeEvent)
-          */
-       protected void handlePreferenceStoreChanged(PropertyChangeEvent event) {
-
-               try {
-
-                       ISourceViewer sourceViewer = getSourceViewer();
-                       if (sourceViewer == null)
-                               return;
-
-                       String property = event.getProperty();
-
-                       //      if (JavaSourceViewerConfiguration.PREFERENCE_TAB_WIDTH.equals(property)) {
-                       //        Object value= event.getNewValue();
-                       //        if (value instanceof Integer) {
-                       //          sourceViewer.getTextWidget().setTabs(((Integer) value).intValue());
-                       //        } else if (value instanceof String) {
-                       //          sourceViewer.getTextWidget().setTabs(Integer.parseInt((String) value));
-                       //        }
-                       //        return;
-                       //      }
-
-                       if (IPreferenceConstants.LINE_NUMBER_RULER.equals(property)) {
-                               if (isLineNumberRulerVisible())
-                                       showLineNumberRuler();
-                               else
-                                       hideLineNumberRuler();
-                               return;
-                       }
-
-                       if (fLineNumberRulerColumn != null
-                               && (IPreferenceConstants.LINE_NUMBER_COLOR.equals(property)
-                                       || PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT.equals(property)
-                                       || PREFERENCE_COLOR_BACKGROUND.equals(property))) {
-
-                               initializeLineNumberRulerColumn(fLineNumberRulerColumn);
-                       }
-
-               } finally {
-                       super.handlePreferenceStoreChanged(event);
-               }
-       }
-       /**
-        * Shows the line number ruler column.
-        */
-       private void showLineNumberRuler() {
-               IVerticalRuler v = getVerticalRuler();
-               if (v instanceof CompositeRuler) {
-                       CompositeRuler c = (CompositeRuler) v;
-                       c.addDecorator(1, createLineNumberRulerColumn());
-               }
-       }
-
-       /**
-       * Return whether the line number ruler column should be 
-       * visible according to the preference store settings.
-       * @return <code>true</code> if the line numbers should be visible
-       */
-       private boolean isLineNumberRulerVisible() {
-               // IPreferenceStore store= getPreferenceStore();
-               return phpPrefStore.getBoolean(IPreferenceConstants.LINE_NUMBER_RULER);
-       }
-       /**
-        * Hides the line number ruler column.
-        */
-       private void hideLineNumberRuler() {
-               IVerticalRuler v = getVerticalRuler();
-               if (v instanceof CompositeRuler) {
-                       CompositeRuler c = (CompositeRuler) v;
-                       try {
-                               c.removeDecorator(1);
-                       } catch (Throwable e) {
-                       }
-               }
-       }
-
-       /**
-       * Initializes the given line number ruler column from the preference store.
-       * @param rulerColumn the ruler column to be initialized
-       */
-       protected void initializeLineNumberRulerColumn(LineNumberRulerColumn rulerColumn) {
-               //   JavaTextTools textTools= JavaPlugin.getDefault().getJavaTextTools();
-               PHPColorProvider manager = PHPEditorEnvironment.getPHPColorProvider();
-
-               if (phpPrefStore != null) {
-
-                       RGB rgb = null;
-                       // foreground color
-                       if (phpPrefStore
-                               .contains(IPreferenceConstants.LINE_NUMBER_COLOR)) {
-                               if (phpPrefStore
-                                       .isDefault(IPreferenceConstants.LINE_NUMBER_COLOR))
-                                       rgb =
-                                               PreferenceConverter.getDefaultColor(
-                                                       phpPrefStore,
-                                                       IPreferenceConstants.LINE_NUMBER_COLOR);
-                               else
-                                       rgb =
-                                               PreferenceConverter.getColor(
-                                                       phpPrefStore,
-                                                       IPreferenceConstants.LINE_NUMBER_COLOR);
-                       }
-                       rulerColumn.setForeground(manager.getColor(rgb));
-
-                       rgb = null;
-                       // background color
-                       if (!phpPrefStore
-                               .getBoolean(
-                                       IPreferenceConstants
-                                               .PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT)) {
-                               if (phpPrefStore
-                                       .contains(
-                                               IPreferenceConstants.PREFERENCE_COLOR_BACKGROUND)) {
-                                       if (phpPrefStore
-                                               .isDefault(
-                                                       IPreferenceConstants.PREFERENCE_COLOR_BACKGROUND))
-                                               rgb =
-                                                       PreferenceConverter.getDefaultColor(
-                                                               phpPrefStore,
-                                                               IPreferenceConstants
-                                                                       .PREFERENCE_COLOR_BACKGROUND);
-                                       else
-                                               rgb =
-                                                       PreferenceConverter.getColor(
-                                                               phpPrefStore,
-                                                               IPreferenceConstants
-                                                                       .PREFERENCE_COLOR_BACKGROUND);
-                               }
-                               rulerColumn.setBackground(manager.getColor(rgb));
-                       }
-
-               }
-       }
-
-       /**
-        * Creates a new line number ruler column that is appropriately initialized.
-        */
-       protected IVerticalRulerColumn createLineNumberRulerColumn() {
-               fLineNumberRulerColumn = new LineNumberRulerColumn();
-               initializeLineNumberRulerColumn(fLineNumberRulerColumn);
-               return fLineNumberRulerColumn;
-       }
-
-       /*
-        * @see AbstractTextEditor#createVerticalRuler()
-        */
-       protected IVerticalRuler createVerticalRuler() {
-               CompositeRuler ruler = new CompositeRuler();
-               ruler.addDecorator(0, new AnnotationRulerColumn(VERTICAL_RULER_WIDTH));
-               if (isLineNumberRulerVisible())
-                       ruler.addDecorator(1, createLineNumberRulerColumn());
-               return ruler;
-       }
-
-       /* (non-Javadoc)
-        * Method declared on AbstractTextEditor
-        */
-       protected void initializeEditor() {
-               PHPEditorEnvironment.connect(this);
-
-               setSourceViewerConfiguration(new PHPSourceViewerConfiguration());
-               setRangeIndicator(new DefaultRangeIndicator());
-               setEditorContextMenuId("#PHPEditorContext"); //$NON-NLS-1$
-               setRulerContextMenuId("#PHPRulerContext"); //$NON-NLS-1$
-               // setDocumentProvider(PHPeclipsePlugin.getCompilationUnitDocumentProvider());
-               phpPrefStore = PHPeclipsePlugin.getDefault().getPreferenceStore();
-
-               phpPrefStore.addPropertyChangeListener(new IPropertyChangeListener() {
-                       public void propertyChange(PropertyChangeEvent event) {
-                               PHPCodeScanner scanner =
-                                       PHPEditorEnvironment.getPHPCodeScanner();
-                               if (scanner != null) {
-                                       scanner.updateToken(
-                                               PHPEditorEnvironment.getPHPColorProvider());
-                               }
-                               if (getSourceViewer() != null) {
-                                       getSourceViewer().invalidateTextPresentation();
-                               }
-
-                               String property = event.getProperty();
-                               if (IPreferenceConstants.LINE_NUMBER_RULER.equals(property)) {
-                                       if (isLineNumberRulerVisible())
-                                               showLineNumberRuler();
-                                       else
-                                               hideLineNumberRuler();
-                                       return;
-                               }
-                       }
-               });
-       }
+  // protected PHPActionGroup fActionGroups;
+  /** The outline page */
+  private PHPContentOutlinePage fOutlinePage;
+  private IPreferenceStore phpPrefStore;
+
+  /** The line number ruler column */
+  private LineNumberRulerColumn fLineNumberRulerColumn;
+
+  protected CompositeActionGroup fActionGroups;
+  /** The standard action groups added to the menu */
+  private GenerateActionGroup fGenerateActionGroup;
+  private CompositeActionGroup fContextMenuGroup;
+  /**
+   * Default constructor.
+   */
+  public PHPEditor() {
+    super();
+    setRulerContextMenuId("#PHPRulerContext"); //$NON-NLS-1$
+  }
+  //
+  //   /**
+  //    * @see IMember#getCompilationUnit()
+  //    */
+  //   public ICompilationUnit getCompilationUnit() {
+  //           return this; 
+  //   }
+  //   /**
+  //    * @see org.phpeclipse.phpdt.internal.compiler.env.ICompilationUnit#getContents()
+  //    */
+  //   public char[] getContents() {
+  //           IDocument doc = this.getDocumentProvider().getDocument(this.getEditorInput());
+  //   
+  //           return doc.get().toCharArray();
+  //   }
+
+  /**
+   * Returns this document's complete text.
+   *
+   * @return the document's complete text
+   */
+  public String get() {
+    IDocument doc =
+      this.getDocumentProvider().getDocument(this.getEditorInput());
+    return doc.get();
+  }
+
+  /**
+   *  Returns the standard action group of this editor.
+   */
+  protected ActionGroup getActionGroup() {
+    return fActionGroups;
+  }
+
+  public PHPContentOutlinePage getfOutlinePage() {
+    return fOutlinePage;
+  }
+
+  /** The <code>PHPEditor</code> implementation of this 
+   * <code>AbstractTextEditor</code> method extend the 
+   * actions to add those specific to the receiver
+   */
+  protected void createActions() {
+    super.createActions();
+
+    Action action;
+    //    setAction(
+    //      "ContentAssistProposal",
+    //      new TextOperationAction(
+    //        PHPEditorMessages.getResourceBundle(),
+    //        "ContentAssistProposal.",
+    //        this,
+    //        ISourceViewer.CONTENTASSIST_PROPOSALS));
+    action = new ContentAssistAction(PHPEditorMessages.getResourceBundle(), "ContentAssistProposal.", this); //$NON-NLS-1$
+    action.setActionDefinitionId(
+      PHPEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
+    setAction("ContentAssistProposal", action); //$NON-NLS-1$
+
+    // System.out.println(action.getId());
+    // System.out.println(action.getActionDefinitionId());
+
+    setAction(
+      "ContentAssistTip",
+      new TextOperationAction(
+        PHPEditorMessages.getResourceBundle(),
+        "ContentAssistTip.",
+        this,
+        ISourceViewer.CONTENTASSIST_CONTEXT_INFORMATION));
+
+    action =
+      new TextOperationAction(
+        PHPEditorMessages.getResourceBundle(),
+        "Comment.",
+        this,
+        ITextOperationTarget.PREFIX);
+    action.setActionDefinitionId(PHPEditorActionDefinitionIds.COMMENT);
+    setAction("Comment", action);
+
+    // System.out.println(action.getId());
+    // System.out.println(action.getActionDefinitionId());
+
+    action =
+      new TextOperationAction(
+        PHPEditorMessages.getResourceBundle(),
+        "Uncomment.",
+        this,
+        ITextOperationTarget.STRIP_PREFIX);
+    action.setActionDefinitionId(PHPEditorActionDefinitionIds.UNCOMMENT);
+    setAction("Uncomment", action);
+
+    action = new TextOperationAction(
+        PHPEditorMessages.getResourceBundle(), "Format.", this, ISourceViewer.FORMAT); //$NON-NLS-1$
+    action.setActionDefinitionId(PHPEditorActionDefinitionIds.FORMAT);
+    setAction("Format", action); //$NON-NLS-1$
+    
+    // System.out.println(action.getId());
+    // System.out.println(action.getActionDefinitionId());
+
+    //  fActionGroups = new PHPActionGroup(this, ITextEditorActionConstants.GROUP_EDIT);
+
+    markAsStateDependentAction("Comment", true); //$NON-NLS-1$
+    markAsStateDependentAction("Uncomment", true); //$NON-NLS-1$
+    markAsStateDependentAction("Format", true); //$NON-NLS-1$
+    
+    fGenerateActionGroup =
+      new GenerateActionGroup(this, ITextEditorActionConstants.GROUP_EDIT);
+
+    fActionGroups =
+      new CompositeActionGroup(new ActionGroup[] { fGenerateActionGroup });
+
+    // We have to keep the context menu group separate to have better control over positioning
+    fContextMenuGroup =
+      new CompositeActionGroup(new ActionGroup[] { fGenerateActionGroup });
+    //      rg, 
+    //      new LocalHistoryActionGroup(this, ITextEditorActionConstants.GROUP_EDIT)});
+  }
+
+  /** The <code>PHPEditor</code> implementation of this 
+   * <code>AbstractTextEditor</code> method performs any extra 
+   * disposal actions required by the php editor.
+   */
+  public void dispose() {
+    PHPEditorEnvironment.disconnect(this);
+    if (fOutlinePage != null)
+      fOutlinePage.setInput(null);
+
+    if (fActionGroups != null)
+      fActionGroups.dispose();
+
+    super.dispose();
+  }
+
+  /** The <code>PHPEditor</code> implementation of this 
+   * <code>AbstractTextEditor</code> method performs any extra 
+   * revert behavior required by the php editor.
+   */
+  public void doRevertToSaved() {
+    super.doRevertToSaved();
+    if (fOutlinePage != null)
+      fOutlinePage.update();
+  }
+
+  /** The <code>PHPEditor</code> implementation of this 
+   * <code>AbstractTextEditor</code> method performs any extra 
+   * save behavior required by the php editor.
+   */
+  public void doSave(IProgressMonitor monitor) {
+    super.doSave(monitor);
+    // compile or not, according to the user preferences
+    IPreferenceStore store = phpPrefStore;
+    if (store.getBoolean(PHPeclipsePlugin.PHP_PARSE_ON_SAVE)) {
+      IAction a = PHPParserAction.getInstance();
+      if (a != null)
+        a.run();
+    }
+    if (fOutlinePage != null)
+      fOutlinePage.update();
+  }
+
+  /** The <code>PHPEditor</code> implementation of this 
+   * <code>AbstractTextEditor</code> method performs any extra 
+   * save as behavior required by the php editor.
+   */
+  public void doSaveAs() {
+    super.doSaveAs();
+    if (fOutlinePage != null)
+      fOutlinePage.update();
+  }
+
+  /** The <code>PHPEditor</code> implementation of this 
+   * <code>AbstractTextEditor</code> method performs sets the 
+   * input of the outline page after AbstractTextEditor has set input.
+   */
+  public void doSetInput(IEditorInput input) throws CoreException {
+    super.doSetInput(input);
+    if (fOutlinePage != null)
+      fOutlinePage.setInput(input);
+  }
+
+  /** The <code>PHPEditor</code> implementation of this 
+   * <code>AbstractTextEditor</code> method adds any 
+   * PHPEditor specific entries.
+   */
+  public void editorContextMenuAboutToShow(MenuManager menu) {
+    super.editorContextMenuAboutToShow(menu);
+    //  addAction(menu, "ContentAssistProposal"); //$NON-NLS-1$
+    //  addAction(menu, "ContentAssistTip"); //$NON-NLS-1$
+    addAction(menu, ITextEditorActionConstants.GROUP_EDIT, "Format"); //$NON-NLS-1$ 
+    
+    // fActionGroups.fillContextMenu(menu);
+    
+    ActionContext context =
+      new ActionContext(getSelectionProvider().getSelection());
+    fContextMenuGroup.setContext(context);
+    fContextMenuGroup.fillContextMenu(menu);
+    fContextMenuGroup.setContext(null);
+  }
+
+  protected void updateStateDependentActions() {
+    super.updateStateDependentActions();
+    fGenerateActionGroup.editorStateChanged();
+  }
+
+  /** The <code>PHPEditor</code> implementation of this 
+   * <code>AbstractTextEditor</code> method performs gets
+   * the java content outline page if request is for a an 
+   * outline page.
+   */
+  public Object getAdapter(Class required) {
+    if (IContentOutlinePage.class.equals(required)) {
+      if (fOutlinePage == null) {
+        fOutlinePage = new PHPContentOutlinePage(getDocumentProvider(), this);
+        if (getEditorInput() != null)
+          fOutlinePage.setInput(getEditorInput());
+      }
+      return fOutlinePage;
+    }
+    return super.getAdapter(required);
+  }
+
+  //  public void openContextHelp() {
+  //    IDocument doc = this.getDocumentProvider().getDocument(this.getEditorInput());
+  //    ITextSelection selection = (ITextSelection) this.getSelectionProvider().getSelection();
+  //    int pos = selection.getOffset();
+  //    String word = getFunctionName(doc, pos);
+  //    openContextHelp(word);
+  //  }
+  //
+  //  private void openContextHelp(String word) {
+  //    open(word);
+  //  }
+  //
+  //  public static void open(String word) {
+  //    IHelp help = WorkbenchHelp.getHelpSupport();
+  //    if (help != null) {
+  //      IHelpResource helpResource = new PHPFunctionHelpResource(word);
+  //      WorkbenchHelp.getHelpSupport().displayHelpResource(helpResource);
+  //    } else {
+  //      //   showMessage(shell, dialogTitle, ActionMessages.getString("Open help not available"), false); //$NON-NLS-1$
+  //    }
+  //  }
+
+  //   private String getFunctionName(IDocument doc, int pos) {
+  //           Point word = PHPWordExtractor.findWord(doc, pos);
+  //           if (word != null) {
+  //                   try {
+  //                           return doc.get(word.x, word.y).replace('_', '-');
+  //                   } catch (BadLocationException e) {
+  //                   }
+  //           }
+  //           return "";
+  //   }
+
+  /*
+     * @see AbstractTextEditor#handlePreferenceStoreChanged(PropertyChangeEvent)
+     */
+  protected void handlePreferenceStoreChanged(PropertyChangeEvent event) {
+
+    try {
+
+      ISourceViewer sourceViewer = getSourceViewer();
+      if (sourceViewer == null)
+        return;
+
+      String property = event.getProperty();
+
+      //      if (JavaSourceViewerConfiguration.PREFERENCE_TAB_WIDTH.equals(property)) {
+      //        Object value= event.getNewValue();
+      //        if (value instanceof Integer) {
+      //          sourceViewer.getTextWidget().setTabs(((Integer) value).intValue());
+      //        } else if (value instanceof String) {
+      //          sourceViewer.getTextWidget().setTabs(Integer.parseInt((String) value));
+      //        }
+      //        return;
+      //      }
+
+      if (IPreferenceConstants.LINE_NUMBER_RULER.equals(property)) {
+        if (isLineNumberRulerVisible())
+          showLineNumberRuler();
+        else
+          hideLineNumberRuler();
+        return;
+      }
+
+      if (fLineNumberRulerColumn != null
+        && (IPreferenceConstants.LINE_NUMBER_COLOR.equals(property)
+          || PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT.equals(property)
+          || PREFERENCE_COLOR_BACKGROUND.equals(property))) {
+
+        initializeLineNumberRulerColumn(fLineNumberRulerColumn);
+      }
+
+    } finally {
+      super.handlePreferenceStoreChanged(event);
+    }
+  }
+  /**
+   * Shows the line number ruler column.
+   */
+  private void showLineNumberRuler() {
+    IVerticalRuler v = getVerticalRuler();
+    if (v instanceof CompositeRuler) {
+      CompositeRuler c = (CompositeRuler) v;
+      c.addDecorator(1, createLineNumberRulerColumn());
+    }
+  }
+
+  /**
+  * Return whether the line number ruler column should be 
+  * visible according to the preference store settings.
+  * @return <code>true</code> if the line numbers should be visible
+  */
+  private boolean isLineNumberRulerVisible() {
+    // IPreferenceStore store= getPreferenceStore();
+    return phpPrefStore.getBoolean(IPreferenceConstants.LINE_NUMBER_RULER);
+  }
+  /**
+   * Hides the line number ruler column.
+   */
+  private void hideLineNumberRuler() {
+    IVerticalRuler v = getVerticalRuler();
+    if (v instanceof CompositeRuler) {
+      CompositeRuler c = (CompositeRuler) v;
+      try {
+        c.removeDecorator(1);
+      } catch (Throwable e) {
+      }
+    }
+  }
+
+  /**
+  * Initializes the given line number ruler column from the preference store.
+  * @param rulerColumn the ruler column to be initialized
+  */
+  protected void initializeLineNumberRulerColumn(LineNumberRulerColumn rulerColumn) {
+    //   JavaTextTools textTools= JavaPlugin.getDefault().getJavaTextTools();
+    PHPColorProvider manager = PHPEditorEnvironment.getPHPColorProvider();
+
+    if (phpPrefStore != null) {
+
+      RGB rgb = null;
+      // foreground color
+      if (phpPrefStore.contains(IPreferenceConstants.LINE_NUMBER_COLOR)) {
+        if (phpPrefStore.isDefault(IPreferenceConstants.LINE_NUMBER_COLOR))
+          rgb =
+            PreferenceConverter.getDefaultColor(
+              phpPrefStore,
+              IPreferenceConstants.LINE_NUMBER_COLOR);
+        else
+          rgb =
+            PreferenceConverter.getColor(
+              phpPrefStore,
+              IPreferenceConstants.LINE_NUMBER_COLOR);
+      }
+      rulerColumn.setForeground(manager.getColor(rgb));
+
+      rgb = null;
+      // background color
+      if (!phpPrefStore
+        .getBoolean(
+          IPreferenceConstants.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT)) {
+        if (phpPrefStore
+          .contains(IPreferenceConstants.PREFERENCE_COLOR_BACKGROUND)) {
+          if (phpPrefStore
+            .isDefault(IPreferenceConstants.PREFERENCE_COLOR_BACKGROUND))
+            rgb =
+              PreferenceConverter.getDefaultColor(
+                phpPrefStore,
+                IPreferenceConstants.PREFERENCE_COLOR_BACKGROUND);
+          else
+            rgb =
+              PreferenceConverter.getColor(
+                phpPrefStore,
+                IPreferenceConstants.PREFERENCE_COLOR_BACKGROUND);
+        }
+        rulerColumn.setBackground(manager.getColor(rgb));
+      }
+
+    }
+  }
+
+  /**
+   * Creates a new line number ruler column that is appropriately initialized.
+   */
+  protected IVerticalRulerColumn createLineNumberRulerColumn() {
+    fLineNumberRulerColumn = new LineNumberRulerColumn();
+    initializeLineNumberRulerColumn(fLineNumberRulerColumn);
+    return fLineNumberRulerColumn;
+  }
+
+  /*
+   * @see AbstractTextEditor#createVerticalRuler()
+   */
+  protected IVerticalRuler createVerticalRuler() {
+    CompositeRuler ruler = new CompositeRuler();
+    ruler.addDecorator(0, new AnnotationRulerColumn(VERTICAL_RULER_WIDTH));
+    if (isLineNumberRulerVisible())
+      ruler.addDecorator(1, createLineNumberRulerColumn());
+    return ruler;
+  }
+
+  /* (non-Javadoc)
+   * Method declared on AbstractTextEditor
+   */
+  protected void initializeEditor() {
+    PHPEditorEnvironment.connect(this);
+
+    setSourceViewerConfiguration(new PHPSourceViewerConfiguration(this));
+    setRangeIndicator(new DefaultRangeIndicator());
+    setEditorContextMenuId("#PHPEditorContext"); //$NON-NLS-1$
+    setRulerContextMenuId("#PHPRulerContext"); //$NON-NLS-1$
+    // setDocumentProvider(PHPeclipsePlugin.getCompilationUnitDocumentProvider());
+    phpPrefStore = PHPeclipsePlugin.getDefault().getPreferenceStore();
+
+    phpPrefStore.addPropertyChangeListener(new IPropertyChangeListener() {
+      public void propertyChange(PropertyChangeEvent event) {
+        PHPCodeScanner scanner = PHPEditorEnvironment.getPHPCodeScanner();
+        if (scanner != null) {
+          scanner.updateToken(PHPEditorEnvironment.getPHPColorProvider());
+        }
+        if (getSourceViewer() != null) {
+          getSourceViewer().invalidateTextPresentation();
+        }
+
+        String property = event.getProperty();
+        if (IPreferenceConstants.LINE_NUMBER_RULER.equals(property)) {
+          if (isLineNumberRulerVisible())
+            showLineNumberRuler();
+          else
+            hideLineNumberRuler();
+          return;
+        }
+      }
+    });
+  }
 }
index 9f769a9..2a236ab 100644 (file)
@@ -13,6 +13,11 @@ public interface PHPEditorActionDefinitionIds {
        public static final String UNCOMMENT =
                "net.sourceforge.phpeclipse.phpeditor.uncomment";
        
+  /**
+   * Action definition ID of the source -> format action 
+   */
+  public static final String FORMAT= "net.sourceforge.phpeclipse.phpeditor.format"; //$NON-NLS-1$
+
        /**
        * Action definition ID of the edit -> content assist proposal action (value
        * <code>"org.phpeclipse.phpdt.ui.edit.text.php.content.assist. proposals"
index 6f2c2f6..af8b262 100644 (file)
@@ -14,6 +14,7 @@ package net.sourceforge.phpeclipse.phpeditor;
 import java.util.Vector;
 
 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
+import net.sourceforge.phpeclipse.phpeditor.html.HTMLFormattingStrategy;
 import net.sourceforge.phpeclipse.phpeditor.php.HTMLCompletionProcessor;
 import net.sourceforge.phpeclipse.phpeditor.php.PHPAutoIndentStrategy;
 import net.sourceforge.phpeclipse.phpeditor.php.PHPCompletionProcessor;
@@ -30,10 +31,13 @@ import org.eclipse.jface.text.ITextHover;
 import org.eclipse.jface.text.TextAttribute;
 import org.eclipse.jface.text.contentassist.ContentAssistant;
 import org.eclipse.jface.text.contentassist.IContentAssistant;
+import org.eclipse.jface.text.formatter.ContentFormatter;
+import org.eclipse.jface.text.formatter.IContentFormatter;
 import org.eclipse.jface.text.presentation.IPresentationReconciler;
 import org.eclipse.jface.text.presentation.PresentationReconciler;
 import org.eclipse.jface.text.rules.BufferedRuleBasedScanner;
 import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
+import org.eclipse.jface.text.rules.DefaultPartitioner;
 import org.eclipse.jface.text.rules.Token;
 import org.eclipse.jface.text.source.IAnnotationHover;
 import org.eclipse.jface.text.source.ISourceViewer;
@@ -45,6 +49,12 @@ import org.eclipse.swt.graphics.RGB;
  */
 public class PHPSourceViewerConfiguration extends SourceViewerConfiguration {
 
+  public static final String HTML_DEFAULT = IDocument.DEFAULT_CONTENT_TYPE;
+  
+  private PHPEditor fEditor;
+  
+  private ContentFormatter fFormatter;
+  private HTMLFormattingStrategy fFormattingStrategy;
   /**
    * Single token scanner.
    */
@@ -57,9 +67,40 @@ public class PHPSourceViewerConfiguration extends SourceViewerConfiguration {
   /**
    * Default constructor.
    */
-  public PHPSourceViewerConfiguration() {
+  public PHPSourceViewerConfiguration(PHPEditor editor) {
+    fEditor = editor;
   }
 
+  /*
+   * @see SourceViewerConfiguration#getContentFormatter(ISourceViewer)
+   */
+  public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) {
+    if (fFormatter == null) {
+      fFormatter = new ContentFormatter();
+      fFormattingStrategy = new HTMLFormattingStrategy(this, sourceViewer);
+      fFormatter.setFormattingStrategy(fFormattingStrategy, HTML_DEFAULT);
+      fFormatter.enablePartitionAwareFormatting(false);
+      fFormatter.setPartitionManagingPositionCategories(getConfiguredContentTypes(null));
+    }
+    return fFormatter;
+  }
+  
+//  /**
+//   * Returns the names of the document position categories used by the document
+//   * partitioners created by this object to manage their partition information.
+//   * If the partitioners don't use document position categories, the returned
+//   * result is <code>null</code>.
+//   *
+//   * @return the partition managing position categories or <code>null</code> 
+//   *                         if there is none
+//   */
+//  private String[] getPartitionManagingPositionCategories() {
+//    return new String[] { DefaultPartitioner.CONTENT_TYPES_CATEGORY };
+//  } 
+  
+  public PHPEditor getEditor() {
+    return fEditor;
+  }
   /* (non-Javadoc)
    * Method declared on SourceViewerConfiguration
    */
diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/html/HTMLFormatter.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/html/HTMLFormatter.java
new file mode 100644 (file)
index 0000000..fcdb34a
--- /dev/null
@@ -0,0 +1,110 @@
+ package net.sourceforge.phpeclipse.phpeditor.html;
+
+import java.io.PrintWriter;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.util.HashSet;
+import java.util.Set;
+
+import net.sourceforge.phpeclipse.PHPeclipsePlugin;
+import net.sourceforge.phpeclipse.phpeditor.PHPEditor;
+import net.sourceforge.phpeclipse.phpeditor.PHPSourceViewerConfiguration;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jface.text.source.SourceViewer;
+
+/**
+ * Modified from the XMLFormatter.  Some tags in HTML do not indent.
+ * 
+ * @fixme The HTML parser cannot recognize < tag> as tag due to the extra space.
+ * 
+ * @author chrisl
+ */
+public class HTMLFormatter implements IHTMLConstants {
+
+       ////////////////////////////////////////////////////////////////////////
+
+       private static final String NAME = "HTMLFormatter";
+       private static final boolean TRACE = false;
+//     private static boolean VERBOSE = false;
+
+       private static Set fBLOCK_TAG_SET;
+       private static Set fSTART_TAG_SET;
+       static {
+               fBLOCK_TAG_SET = new HashSet();
+               for (int i = 0; i < BLOCK_TAGS.length; ++i)
+                       fBLOCK_TAG_SET.add(BLOCK_TAGS[i]);
+               //
+               fSTART_TAG_SET = new HashSet();
+               for (int i = 0; i < START_TAGS.length; ++i)
+                       fSTART_TAG_SET.add(START_TAGS[i]);
+       }
+
+       ////////////////////////////////////////////////////////////////////////
+
+       private PHPSourceViewerConfiguration fConfig;
+       private SourceViewer fViewer;
+       //
+       private PHPEditor fEditor;
+       private String fFilename;
+
+       ////////////////////////////////////////////////////////////////////////
+
+       /**
+        * Constructor for XMLFormatter.
+        */
+       public HTMLFormatter(PHPSourceViewerConfiguration cf, SourceViewer viewer) {
+               fConfig=cf;
+               fViewer = viewer;
+               //
+               fEditor = fConfig.getEditor();
+       }
+
+       ////////////////////////////////////////////////////////////////////////
+
+       /** 
+        * Formats the String <code>sourceString</code>,
+        * and returns a string containing the formatted version.
+        * 
+        * @param string the string to format
+        * @param indentationLevel the initial indentation level, used 
+        *      to shift left/right the entire source fragment. An initial indentation
+        *      level of zero has no effect.
+        * @param positions an array of positions to map. These are
+        *      character-based source positions inside the original source,
+        *     for which corresponding positions in the formatted source will
+        *     be computed (so as to relocate elements associated with the original
+        *     source). It updates the positions array with updated positions.
+        *     If set to <code>null</code>, then no positions are mapped.
+        * @param lineSeparator the line separator to use in formatted source,
+        *     if set to <code>null</code>, then the platform default one will be used.
+        * @return the formatted output string.
+        */
+       public String format(
+               String string,
+               int indentationLevel,
+               int[] positions,
+               String lineSeparator,
+               String inputname) {
+               StringWriter ret = new StringWriter(2048);
+               try {
+                       if (PHPeclipsePlugin.DEBUG) {
+                               System.err.println(NAME + ".format(): inputname=" + inputname);
+                       }
+//                     TidyHTMLParser parser = new TidyHTMLParser(new TidyConfiguration(fEditor, fViewer));
+//                     parser.setCompactFormat(
+//                             ((Boolean) fViewer.getData(IConstants.KEY_COMPACT_FORMAT)).booleanValue());
+//                     parser.parse(new StringReader(string), inputname, new PrintWriter(ret));
+//                     if (parser.getParseErrors() != 0) {
+//        PHPeclipsePlugin.log(IStatus.INFO, "Parse error");
+//                             return string;
+//                     }
+                       return ret.toString();
+               } catch (Exception e) {
+               //      PHPeclipsePlugin.error("Unknown parse error: "+e.getMessage(), null, fEditor.getEditorInput(), fViewer);
+      PHPeclipsePlugin.log(IStatus.ERROR, e.getMessage());
+                       return string;
+               }
+       }
+
+}
diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/html/HTMLFormattingStrategy.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/html/HTMLFormattingStrategy.java
new file mode 100644 (file)
index 0000000..3657c8e
--- /dev/null
@@ -0,0 +1,127 @@
+package net.sourceforge.phpeclipse.phpeditor.html;
+
+import net.sourceforge.phpeclipse.phpeditor.PHPSourceViewerConfiguration;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.formatter.IFormattingStrategy;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.text.source.SourceViewer;
+import org.eclipse.ui.editors.text.TextEditor;
+
+/**
+ * @author chrisl
+ *
+ * To change this generated comment edit the template variable "typecomment":
+ * Window>Preferences>Java>Templates.
+ * To enable and disable the creation of type comments go to
+ * Window>Preferences>Java>Code Generation.
+ */
+public class HTMLFormattingStrategy implements IFormattingStrategy, IHTMLConstants {
+
+       ////////////////////////////////////////////////////////////////////////
+
+       private PHPSourceViewerConfiguration fConfig;
+       private ISourceViewer fViewer;
+       //
+       private TextEditor fEditor;
+       private int fTabWidth;
+
+       ////////////////////////////////////////////////////////////////////////
+
+       public HTMLFormattingStrategy(PHPSourceViewerConfiguration cf, ISourceViewer viewer) {
+               fConfig = cf;
+               fViewer = viewer;
+               //
+               fEditor = fConfig.getEditor();
+               initPreferences();
+       }
+
+       public void initPreferences() {
+               fTabWidth=fConfig.getTabWidth(fViewer);
+       }
+       
+       ////////////////////////////////////////////////////////////////////////
+
+       /**
+        * @see IFormattingStrategy#formatterStarts(String)
+        */
+       public void formatterStarts(String 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) {
+               HTMLFormatter formatter = new HTMLFormatter(fConfig, (SourceViewer) fViewer);
+               IDocument doc = fViewer.getDocument();
+               String lineDelimiter = getLineDelimiterFor(doc);
+               int indent = 0;
+               if (indentation != null) {
+                       indent = computeIndent(indentation, fTabWidth);
+               }
+               return formatter.format(content, indent, positions, lineDelimiter, fEditor.getEditorInput().getName());
+       }
+
+       public static String getLineDelimiterFor(IDocument doc) {
+               // new for: 1GF5UU0: ITPJUI:WIN2000 - "Organize Imports" in java editor inserts lines in wrong format
+               String lineDelim = null;
+               try {
+                       lineDelim = doc.getLineDelimiter(0);
+               } catch (BadLocationException e) {
+               }
+               if (lineDelim == null) {
+                       String systemDelimiter = System.getProperty("line.separator", "\n"); //$NON-NLS-1$ //$NON-NLS-2$
+                       String[] lineDelims = doc.getLegalLineDelimiters();
+                       for (int i = 0; i < lineDelims.length; i++) {
+                               if (lineDelims[i].equals(systemDelimiter)) {
+                                       lineDelim = systemDelimiter;
+                                       break;
+                               }
+                       }
+                       if (lineDelim == null) {
+                               lineDelim = lineDelims.length > 0 ? lineDelims[0] : systemDelimiter;
+                       }
+               }
+               return lineDelim;
+       }
+
+       /**
+        * Returns the indent of the given string.
+        * 
+        * @param line the text line
+        * @param tabWidth the width of the '\t' character.
+        * 
+        * @see org.eclipse.jdt.internal.corext.util.Strings.computeIndent(String,int)
+        */
+       public static int computeIndent(String line, int tabWidth) {
+               int result = 0;
+               int blanks = 0;
+               int size = line.length();
+               for (int i = 0; i < size; i++) {
+                       char c = line.charAt(i);
+                       if (c == '\t') {
+                               result++;
+                               blanks = 0;
+                       } else if (Character.isSpaceChar(c)) {
+                               blanks++;
+                               if (blanks == tabWidth) {
+                                       result++;
+                                       blanks = 0;
+                               }
+                       } else {
+                               return result;
+                       }
+               }
+               return result;
+       }
+
+       ////////////////////////////////////////////////////////////////////////
+
+}
diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/html/IHTMLConstants.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/html/IHTMLConstants.java
new file mode 100644 (file)
index 0000000..96cc755
--- /dev/null
@@ -0,0 +1,163 @@
+package net.sourceforge.phpeclipse.phpeditor.html;
+
+
+/**
+ * @author chrisl
+ */
+public interface IHTMLConstants {
+
+       int NONE=0;
+       int TEXT=1;
+       int FOLDER=2;
+       int ANCHOR=3;
+       
+       /** 
+        * Tags that do not allow end tag.
+        * Required that tags that allow optional end tag should always have end tag.
+        */
+       String[] EMPTY_TAGS =
+               new String[] {
+                       "AREA",
+                       "BASE",
+                       "BASEFONT",
+                       "BR",
+                       "COL",
+                       "FRAME",
+                       "HR",
+                       "IMG",
+                       "INPUT",
+                       "ISINDEX",
+                       "LINK",
+                       "META",
+                       "PARAM",
+                       };
+
+       String[] START_TAGS =
+               new String[] {
+                       "A",
+                       "ADDRESS",
+                       "APPLET",
+                       "B",
+                       "BIG",
+                       "BLOCKQUOTE",
+                       "BODY",
+                       "CAPTION",
+                       "CENTER",
+                       "CITE",
+                       "CODE",
+                       "COL",
+                       "COLGROUP",
+                       "DD",
+                       "DFN",
+                       "DIR",
+                       "DIV",
+                       "DL",
+                       "DT",
+                       "EM",
+                       "FONT",
+                       "FORM",
+                       "FRAMESET",
+                       "H1",
+                       "H2",
+                       "H3",
+                       "H4",
+                       "H5",
+                       "H6",
+                       "HEAD",
+                       "HTML",
+                       "I",
+                       "KBD",
+                       "LI",
+                       "MAP",
+                       "MENU",
+                       "NOBR",
+                       "NOFRAMES",
+                       "OBJECT",
+                       "OL",
+                       "OPTION",
+                       "P",
+                       "PRE",
+                       "SAMP",
+                       "SCRIPT",
+                       "SELECT",
+                       "SMALL",
+                       "SPAN",
+                       "STRIKE",
+                       "S",
+                       "STRONG",
+                       "STYLE",
+                       "SUB",
+                       "SUP",
+                       "TABLE",
+                       "TD",
+                       "TEXTAREA",
+                       "TH",
+                       "TITLE",
+                       "TR",
+                       "TT",
+                       "U",
+                       "UL",
+                       "VAR",
+                       };
+
+       /** Line break before and after tag. */
+       String[] BLOCK_TAGS =
+               new String[] {
+                       "A",
+                       "APPLET",
+                       "AREA",
+                       "BASE",
+                       "BASEFONT",
+                       "BLOCKQUOTE",
+                       "BODY",
+                       "BR",
+                       "CAPTION",
+                       "CITE",
+                       "CODE",
+                       "DD",
+                       "DFN",
+                       "DIR",
+                       "DIV",
+                       "DL",
+                       "DT",
+                       "FORM",
+                       "FRAME",
+                       "FRAMESET",
+                       "H1",
+                       "H2",
+                       "H3",
+                       "H4",
+                       "H5",
+                       "H6",
+                       "HEAD",
+                       "HR",
+                       "HTML",
+                       "IMG",
+                       "INPUT",
+                       "ISINDEX",
+                       "LI",
+                       "LINK",
+                       "MAP",
+                       "MENU",
+                       "META",
+                       "NOBR",
+                       "NOFRAMES",
+                       "OBJECT",
+                       "OL",
+                       "OPTION",
+                       "P",
+                       "PARAM",
+                       "PRE",
+                       "SAMP",
+                       "SCRIPT",
+                       "SELECT",
+                       "STRIKE",
+                       "TABLE",
+                       "TD",
+                       "TEXTAREA",
+                       "TH",
+                       "TITLE",
+                       "TR",
+                       "UL",
+                       };
+}