misc changes
authorkhartlage <khartlage>
Fri, 7 Feb 2003 19:17:17 +0000 (19:17 +0000)
committerkhartlage <khartlage>
Fri, 7 Feb 2003 19:17:17 +0000 (19:17 +0000)
archive/net.sourceforge.phpeclipse.jtidy/plugin.properties [new file with mode: 0644]
archive/net.sourceforge.phpeclipse.jtidy/plugin.xml
archive/net.sourceforge.phpeclipse.jtidy/src/net/sourceforge/phpdt/tidy/actions/AbstractJTidyAction.java
archive/net.sourceforge.phpeclipse.jtidy/src/net/sourceforge/phpdt/tidy/actions/AbstractJTidyEditorAction.java

diff --git a/archive/net.sourceforge.phpeclipse.jtidy/plugin.properties b/archive/net.sourceforge.phpeclipse.jtidy/plugin.properties
new file mode 100644 (file)
index 0000000..ea2a242
--- /dev/null
@@ -0,0 +1,5 @@
+#########################################
+#
+#########################################
+pluginName=PHPEclipse HTML Jtidy  
+providerName=EclipseProject.de
index 18d5609..7efbd1d 100644 (file)
@@ -1,9 +1,9 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <plugin
    id="net.sourceforge.phpdt.tidy"
-   name="Jtidy Plug-in"
-   version="1.0.1"
-   provider-name="Jan Schulz"
+   name="%pluginName"
+   version="1.0.2"
+   provider-name="%providerName"
    class="net.sourceforge.phpdt.tidy.JtidyPlugin">
 
    <runtime>
@@ -17,8 +17,8 @@
 
    <extension
          point="org.eclipse.ui.popupMenus">
-         <viewerContribution
-         id="net.sourceforge.phpdt.tidy.EditorPopUp"
+      <viewerContribution
+         id="net.sourceforge.phpdt.tidy.editorpopup"
          targetID="#TextEditorContext">
          <menu
                label="JTidy"
                id="net.sourceforge.phpdt.tidy.FormatEditorAction">
          </action>
       </viewerContribution>
+      <viewerContribution
+            targetID="#PHPEditorContext"
+            id="net.sourceforge.phpdt.tidy.editorpopup">
+         <menu
+               label="JTidy"
+               path="additions"
+               id="net.sourceforge.phpdt.tidy.menu2">
+            <separator
+                  name="group1">
+            </separator>
+         </menu>
+         <action
+               label="Check Markup"
+               class="net.sourceforge.phpdt.tidy.actions.ParseWithJTidyEditorAction"
+               menubarPath="net.sourceforge.phpdt.tidy.menu2/group1"
+               
+               id="net.sourceforge.phpdt.tidy.ParseEditorAction">
+         </action>
+         <action
+               label="Format"
+               class="net.sourceforge.phpdt.tidy.actions.FormatWithJTidyEditorAction"
+               menubarPath="net.sourceforge.phpdt.tidy.menu2/group1"
+              
+               id="net.sourceforge.phpdt.tidy.FormatEditorAction">
+         </action>
+      </viewerContribution> 
       <objectContribution
             objectClass="org.eclipse.core.resources.IFile"
             nameFilter="*.htm*"
-            id="net.sourceforge.phpdt.tidy.contribution1">
+            id="net.sourceforge.phpdt.tidy.filepopups">
          <menu
                label="JTidy"
                path="additions"
@@ -71,9 +97,7 @@
          </action>
       </objectContribution>
    </extension>
-   <extension
-         point="org.eclipse.ui.popupMenus">
-   </extension>
+
     <extension
          point="org.eclipse.ui.preferencePages">
           <page
index b288394..8ca2cae 100644 (file)
@@ -20,194 +20,200 @@ import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.texteditor.ITextEditor; 
+import org.eclipse.ui.editors.text.TextEditor;
+import org.eclipse.ui.texteditor.ITextEditor;
 
 /**
  * @author jan
  * @since 13.01.2003
  */
 public abstract class AbstractJTidyAction {
-       private ITextEditor fTextEditor = null;
-       private IStructuredSelection fSelection = null;
-
-       /**
-        * Parses the given stream with a Tidy Instance, which belongs to this
-        * IFile. Problems will be marked on this file.
-        * @param in
-        * @param file
-        * @return InputStream
-        */
-       protected byte[] parseStreamOfFile(InputStream in, IFile file) {
-               deleteTidyMarker(file);
-               ByteArrayOutputStream out = new ByteArrayOutputStream();
-               JtidyPlugin.getTidyInstance(file).parse(file, in, out);
-               return out.toByteArray();
-
-       }
-
-       /**
-        * Deletes all JTidy Marker of this File
-        * 
-        * @param file
-        */
-       protected void deleteTidyMarker(IFile file) {
-               try {
-                       IMarker[] markers = file.findMarkers(null, false, IResource.DEPTH_ZERO);
-                       for (int i = 0; i < markers.length; i++) {
-                               IMarker marker = markers[i];
-                               if (marker.getAttribute(JtidyPlugin.MARKER_NAME) != null) {
-                                       marker.delete();
-                               }
-                       }
-               } catch (CoreException e) {
-                       //LOGGING
-               }
-       }
-
-       /**
-        * Parses the Document with Tidy.
-        */
-       protected void parseDocument(boolean writeBack) throws ParseFailedException {
-               IDocument doku = fTextEditor.getDocumentProvider().getDocument(fTextEditor.getEditorInput());
-               assertNotNull(doku);
-               String content = doku.get();
-               IFile file = (IFile) fTextEditor.getEditorInput().getAdapter(IFile.class);
-               assertNotNull(file);
-               byte[] ret = parseStreamOfFile(new ByteArrayInputStream(content.getBytes()), file);
-               if (writeBack) {
-                       if (ret.length != 0) {
-                               String cleanedContent = new String(ret);
-                               doku.set(cleanedContent);
-                       } else {
-                               displayError(
-                                       "Formatting skipped",
-                                       "This document has errors that must be fixed before using HTML Tidy to generate a tidied up version.");
-                       }
-
-               }
-       }
-
-       /**
-        * Throws a ParseFailedException, if the given obj is null
-        * 
-        * @param obj
-        * @throws ParseFailedException
-        */
-       protected void assertNotNull(Object obj) throws ParseFailedException {
-               if (obj == null) {
-                       throw new ParseFailedException("A expected 'non-null' Value was null");
-               }
-       }
-
-       /**
-        * Updates the enable state of the parent action
-        * @param action
-        */
-       protected void updateParent(IAction action) {
-               action.setEnabled(fTextEditor != null || fSelection != null);
-       }
-
-       /**
-        * Parses all Files in the given selection...
-        */
-       protected void parseSelection(boolean writeBack) {
-               Iterator iterator = null;
-               iterator = fSelection.iterator();
-               while (iterator.hasNext()) {
-                       //  obj => selected object in the view
-                       Object obj = iterator.next();
-
-                       // is it a resource
-                       if (obj instanceof IResource) {
-                               IResource resource = (IResource) obj;
-
-                               // check if it's a file resource
-                               switch (resource.getType()) {
-
-                                       case IResource.FILE :
-                                               // single file:
-                                               IFile file = (IFile) resource;
-
-                                               InputStream in;
-                                               try {
-                                                       in = file.getContents();
-                                                       byte[] ret = parseStreamOfFile(in, file);
-
-                                                       if (writeBack) {
-                                                               if (ret.length != 0) {
-                                                                       InputStream source = new ByteArrayInputStream(ret);
-                                                                       file.setContents(source, IFile.KEEP_HISTORY, null);
-
-                                                               } else {
-                                                                       displayError(
-                                                                               "Formatting skipped",
-                                                                               "This document has errors that must be fixed before using HTML Tidy to generate a tidied up version.");
-                                                               }
-                                                       }
-                                               } catch (CoreException e) {
-                                               }
-                               }
-                       }
-               }
-       }
-       /**
-        * Method error.
-        * @param string
-        * @param string1
-        */
-       private void error(String lable, String message) {
-
-               // TODO:
-       }
-
-       /**
-                * Opens an error dialog to display the given message.
-                *
-                * @param message the error message to show
-                */
-       private void displayError(final String lable, final String message) {
-               final Shell parentShell = getShell();
-               parentShell.getDisplay().syncExec(new Runnable() {
-                       public void run() {
-                               MessageDialog.openError(parentShell, lable, message);
-                       }
-               });
-       }
-       /**
-        * Method getShell.
-        * @return Shell
-        */
-       protected abstract Shell getShell();
-
-       /**
-        * Updates the Selection: if the given selection is of type
-        * IStruckturedSelection, fSection is set to this, otehrwise the field is
-        * set to null.
-        * @param sel
-        */
-       protected void updateSelection(ISelection sel) {
-               if (sel instanceof IStructuredSelection) {
-                       fSelection = (IStructuredSelection) sel;
-                       // REVISIT: further determination of types?
-               } else {
-                       fSelection = null;
-               }
-       }
-
-       /**
-        * If the given WorkbenchPart is of type ITextEditor, fTextEditor is set to
-        * this value, otherwise to null
-        * 
-        */
-       protected void updateEditor(IEditorPart part) {
-               if (part instanceof ITextEditor) {
-                       fTextEditor = (ITextEditor) part;
-               } else {
-                       fTextEditor = null;
-               }
-       }
-
-       protected IEditorPart getEditor() {
-               return fTextEditor;
-       }
+  private ITextEditor fTextEditor = null;
+  private IStructuredSelection fSelection = null;
+
+  /**
+   * Parses the given stream with a Tidy Instance, which belongs to this
+   * IFile. Problems will be marked on this file.
+   * @param in
+   * @param file
+   * @return InputStream
+   */
+  protected byte[] parseStreamOfFile(InputStream in, IFile file) {
+    deleteTidyMarker(file);
+    ByteArrayOutputStream out = new ByteArrayOutputStream();
+    JtidyPlugin.getTidyInstance(file).parse(file, in, out);
+    return out.toByteArray();
+
+  }
+
+  /**
+   * Deletes all JTidy Marker of this File
+   * 
+   * @param file
+   */
+  protected void deleteTidyMarker(IFile file) {
+    try {
+      IMarker[] markers = file.findMarkers(null, false, IResource.DEPTH_ZERO);
+      for (int i = 0; i < markers.length; i++) {
+        IMarker marker = markers[i];
+        if (marker.getAttribute(JtidyPlugin.MARKER_NAME) != null) {
+          marker.delete();
+        }
+      }
+    } catch (CoreException e) {
+      //LOGGING
+    }
+  }
+
+  /**
+   * Parses the Document with Tidy.
+   */
+  protected void parseDocument(boolean writeBack) throws ParseFailedException {
+    IDocument doku = fTextEditor.getDocumentProvider().getDocument(fTextEditor.getEditorInput());
+    assertNotNull(doku);
+    String content = doku.get();
+    IFile file = (IFile) fTextEditor.getEditorInput().getAdapter(IFile.class);
+    assertNotNull(file);
+    byte[] ret = parseStreamOfFile(new ByteArrayInputStream(content.getBytes()), file);
+    if (writeBack) {
+      if (ret.length != 0) {
+        String cleanedContent = new String(ret);
+        doku.set(cleanedContent);
+      } else {
+        displayError(
+          "Formatting skipped",
+          "This document has errors that must be fixed before using HTML Tidy to generate a tidied up version.");
+      }
+
+    }
+  }
+
+  /**
+   * Throws a ParseFailedException, if the given obj is null
+   * 
+   * @param obj
+   * @throws ParseFailedException
+   */
+  protected void assertNotNull(Object obj) throws ParseFailedException {
+    if (obj == null) {
+      throw new ParseFailedException("A expected 'non-null' Value was null");
+    }
+  }
+
+  /**
+   * Updates the enable state of the parent action
+   * @param action
+   */
+  protected void updateParent(IAction action) {
+    action.setEnabled(fTextEditor != null || fSelection != null);
+  }
+
+  /**
+   * Parses all Files in the given selection...
+   */
+  protected void parseSelection(boolean writeBack) {
+    Iterator iterator = null;
+    iterator = fSelection.iterator();
+    while (iterator.hasNext()) {
+      //  obj => selected object in the view
+      Object obj = iterator.next();
+
+      // is it a resource
+      if (obj instanceof IResource) {
+        IResource resource = (IResource) obj;
+
+        // check if it's a file resource
+        switch (resource.getType()) {
+
+          case IResource.FILE :
+            // single file:
+            IFile file = (IFile) resource;
+
+            InputStream in;
+            try {
+              in = file.getContents();
+              byte[] ret = parseStreamOfFile(in, file);
+
+              if (writeBack) {
+                if (ret.length != 0) {
+                  InputStream source = new ByteArrayInputStream(ret);
+                  file.setContents(source, IFile.KEEP_HISTORY, null);
+
+                } else {
+                  displayError(
+                    "Formatting skipped",
+                    "This document has errors that must be fixed before using HTML Tidy to generate a tidied up version.");
+                }
+              }
+            } catch (CoreException e) {
+            }
+        }
+      }
+    }
+  }
+  /**
+   * Method error.
+   * @param string
+   * @param string1
+   */
+  private void error(String lable, String message) {
+
+    // TODO:
+  }
+
+  /**
+        * Opens an error dialog to display the given message.
+        *
+        * @param message the error message to show
+        */
+  private void displayError(final String title, final String message) {
+    MessageDialog.openError(null, title, message);
+//    final Shell parentShell = getShell();
+//    parentShell.getDisplay().syncExec(new Runnable() {
+//      public void run() {
+//        MessageDialog.openError(parentShell, lable, message);
+//      }
+//    });
+  }
+//  /**
+//   * Method getShell.
+//   * @return Shell
+//   */
+//  protected abstract Shell getShell();
+
+  /**
+   * Updates the Selection: if the given selection is of type
+   * IStruckturedSelection, fSection is set to this, otehrwise the field is
+   * set to null.
+   * @param sel
+   */
+  protected void updateSelection(ISelection sel) {
+    if (sel instanceof IStructuredSelection) {
+      fSelection = (IStructuredSelection) sel;
+      // REVISIT: further determination of types?
+    } else {
+      fSelection = null;
+    }
+  }
+
+  /**
+   * If the given WorkbenchPart is of type ITextEditor, fTextEditor is set to
+   * this value, otherwise to null
+   * 
+   */
+  protected void updateEditor(IEditorPart part) {
+    if (part instanceof ITextEditor) {
+      fTextEditor = (ITextEditor) part;
+    } else {
+      if (part instanceof TextEditor) {
+        fTextEditor = (TextEditor) part;
+      } else {
+        fTextEditor = null;
+      }
+    }
+  }
+
+  protected IEditorPart getEditor() {
+    return fTextEditor;
+  }
 }
index 4525157..f6dd3fd 100644 (file)
@@ -14,14 +14,14 @@ import org.eclipse.ui.IEditorPart;
  * @since 13.01.2003
  */
 public abstract class AbstractJTidyEditorAction extends AbstractJTidyAction implements IEditorActionDelegate {
-       Shell fShell;
+//     Shell fShell;
        /* (non-Javadoc)
         * @see org.eclipse.ui.IEditorActionDelegate#setActiveEditor(org.eclipse.jface.action.IAction, org.eclipse.ui.IEditorPart)
         */
        public void setActiveEditor(IAction action, IEditorPart targetEditor) {
-               if (fShell == null) {
-                       fShell = targetEditor.getSite().getShell();
-               }
+//             if (fShell == null) {
+//                     fShell = targetEditor.getSite().getShell();
+//             }
                updateEditor(targetEditor);
 
                updateParent(action);
@@ -38,11 +38,11 @@ public abstract class AbstractJTidyEditorAction extends AbstractJTidyAction impl
        public void selectionChanged(IAction action, ISelection selection) {
                // Noo need to get a selection...
        }
- /* (non-Javadoc)
- * @see net.sourceforge.phpdt.tidy.actions.AbstractJTidyAction#getShell()
- */
-protected Shell getShell() {
-       return fShell;
-}
+// /* (non-Javadoc)
+// * @see net.sourceforge.phpdt.tidy.actions.AbstractJTidyAction#getShell()
+// */
+//protected Shell getShell() {
+//     return fShell;
+//}
 
 }