From: khartlage Date: Fri, 7 Feb 2003 19:17:17 +0000 (+0000) Subject: misc changes X-Git-Url: http://git.phpeclipse.com misc changes --- diff --git a/archive/net.sourceforge.phpeclipse.jtidy/plugin.properties b/archive/net.sourceforge.phpeclipse.jtidy/plugin.properties new file mode 100644 index 0000000..ea2a242 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.jtidy/plugin.properties @@ -0,0 +1,5 @@ +######################################### +# +######################################### +pluginName=PHPEclipse HTML Jtidy +providerName=EclipseProject.de diff --git a/archive/net.sourceforge.phpeclipse.jtidy/plugin.xml b/archive/net.sourceforge.phpeclipse.jtidy/plugin.xml index 18d5609..7efbd1d 100644 --- a/archive/net.sourceforge.phpeclipse.jtidy/plugin.xml +++ b/archive/net.sourceforge.phpeclipse.jtidy/plugin.xml @@ -1,9 +1,9 @@ @@ -17,8 +17,8 @@ - + + + + + + + + + + + id="net.sourceforge.phpdt.tidy.filepopups"> - - + 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; + } } diff --git a/archive/net.sourceforge.phpeclipse.jtidy/src/net/sourceforge/phpdt/tidy/actions/AbstractJTidyEditorAction.java b/archive/net.sourceforge.phpeclipse.jtidy/src/net/sourceforge/phpdt/tidy/actions/AbstractJTidyEditorAction.java index 4525157..f6dd3fd 100644 --- a/archive/net.sourceforge.phpeclipse.jtidy/src/net/sourceforge/phpdt/tidy/actions/AbstractJTidyEditorAction.java +++ b/archive/net.sourceforge.phpeclipse.jtidy/src/net/sourceforge/phpdt/tidy/actions/AbstractJTidyEditorAction.java @@ -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; +//} }