From 0f94e5e3733547cd2632c734df7417e935ba0d8d Mon Sep 17 00:00:00 2001 From: jsurfer Date: Fri, 3 Sep 2004 19:59:48 +0000 Subject: [PATCH] misc changes --- .../phpeclipse/ui/IPreferenceConstants.java | 1 + .../src/net/sourceforge/phpeclipse/ui/WebUI.java | 3 +- .../ui/editor/ShowExternalPreviewAction.java | 18 +- .../preferences/PHPPreferencesMessages.properties | 33 +--- .../preferences/PHPPreviewProjectPreferences.java | 3 + .../phpdt/internal/ui/util/PHPFileUtil.java | 244 ++++++-------------- 6 files changed, 88 insertions(+), 214 deletions(-) diff --git a/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/IPreferenceConstants.java b/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/IPreferenceConstants.java index 9a3a210..dcc49d1 100644 --- a/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/IPreferenceConstants.java +++ b/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/IPreferenceConstants.java @@ -10,4 +10,5 @@ public interface IPreferenceConstants { public static final String PHP_AUTO_PREVIEW_DEFAULT = "_auto_preview"; public static final String PHP_BRING_TO_TOP_PREVIEW_DEFAULT = "_bring_to_top_preview"; public static final String PHP_SHOW_HTML_FILES_LOCAL = "_show_html_files_local"; + public static final String PHP_SHOW_XML_FILES_LOCAL = "_show_xml_files_local"; } diff --git a/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/WebUI.java b/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/WebUI.java index dfb8a52..b45dc5f 100644 --- a/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/WebUI.java +++ b/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/WebUI.java @@ -8,7 +8,7 @@ * Contributors: * Christopher Lenz - initial implementation * - * $Id: WebUI.java,v 1.2 2004-09-03 17:30:32 jsurfer Exp $ + * $Id: WebUI.java,v 1.3 2004-09-03 19:58:36 jsurfer Exp $ */ package net.sourceforge.phpeclipse.ui; @@ -155,6 +155,7 @@ public class WebUI extends AbstractUIPlugin implements IPreferenceConstants { store.setDefault(PHP_AUTO_PREVIEW_DEFAULT, "true"); store.setDefault(PHP_BRING_TO_TOP_PREVIEW_DEFAULT, "true"); store.setDefault(PHP_SHOW_HTML_FILES_LOCAL, "true"); + store.setDefault(PHP_SHOW_XML_FILES_LOCAL, "false"); } /* * @see AbstractUIPlugin#initializeImageRegistry(ImageRegistry) diff --git a/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/editor/ShowExternalPreviewAction.java b/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/editor/ShowExternalPreviewAction.java index 6bcfc33..776e992 100644 --- a/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/editor/ShowExternalPreviewAction.java +++ b/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/editor/ShowExternalPreviewAction.java @@ -28,8 +28,11 @@ import org.eclipse.ui.texteditor.TextEditorAction; */ public class ShowExternalPreviewAction extends TextEditorAction { public final static int XML_TYPE = 1; + public final static int HTML_TYPE = 2; + public final static int SMARTY_TYPE = 3; + public final static int PHP_TYPE = 4; private static ShowExternalPreviewAction instance = new ShowExternalPreviewAction(); @@ -63,14 +66,16 @@ public class ShowExternalPreviewAction extends TextEditorAction { boolean autoPreview = Util.getPreviewBooleanValue(previewFile, IPreferenceConstants.PHP_AUTO_PREVIEW_DEFAULT); boolean bringToTopPreview = Util.getPreviewBooleanValue(previewFile, IPreferenceConstants.PHP_BRING_TO_TOP_PREVIEW_DEFAULT); boolean showHTMLFilesLocal = Util.getPreviewBooleanValue(previewFile, IPreferenceConstants.PHP_SHOW_HTML_FILES_LOCAL); - boolean isHTMLFileName = "xml".equals(extension) - || "html".equals(extension) - || "htm".equals(extension) - || "xhtml".equals(extension); + boolean showXMLFilesLocal = Util.getPreviewBooleanValue(previewFile, IPreferenceConstants.PHP_SHOW_XML_FILES_LOCAL); + boolean isHTMLFileName = "html".equals(extension) || "htm".equals(extension) || "xhtml".equals(extension); + boolean isXMLFileName = "xml".equals(extension) || "xsd".equals(extension) || "dtd".equals(extension); + if (autoPreview) { String localhostURL; if (showHTMLFilesLocal && isHTMLFileName) { localhostURL = previewFile.getLocation().toString(); + } else if (showXMLFilesLocal && isXMLFileName) { + localhostURL = previewFile.getLocation().toString(); } else if ((localhostURL = getLocalhostURL(null, previewFile)) == null) { return; } @@ -112,8 +117,9 @@ public class ShowExternalPreviewAction extends TextEditorAction { page.bringToTop(part); } } - ((BrowserView) part).refresh(); - + if (part != null) { + ((BrowserView) part).refresh(); + } } catch (Exception e) { // PHPeclipsePlugin.log(e); } diff --git a/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/preferences/PHPPreferencesMessages.properties b/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/preferences/PHPPreferencesMessages.properties index b13bd34..fb7e05c 100644 --- a/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/preferences/PHPPreferencesMessages.properties +++ b/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/preferences/PHPPreferencesMessages.properties @@ -24,6 +24,7 @@ PHPMiscProjectPreferences.obfuscator=Obfuscator directory: PHPPreviewProjectPreferences.auto_preview=Refresh PHP browser view when opening editor PHPPreviewProjectPreferences.bring_to_top_preview=Show PHP browser view when opening editor PHPPreviewProjectPreferences.show_html_files_local=Show HTML files as local resources (no 'http://' url) +PHPPreviewProjectPreferences.show_xml_files_local=Show XML files as local resources (no 'http://' url) ######################################### # Preference Pages @@ -54,34 +55,6 @@ PHPBasePreferencePage.parsers.external=External PHPBasePreferencePage.parsers.internal=Internal PHPBasePreferencePage.parsers.extcommand=Parser command PHPBasePreferencePage.parsers.choose=Choose PHP Parser + -PHPEditorSyntaxPreferencePage.description:PHP Editor Preferences -PHPEditorSyntaxPreferencePage.background:Background settings -PHPEditorSyntaxPreferencePage.foreground:Foreground settings -PHPEditorSyntaxPreferencePage.syntax:Syntax highlighting -PHPEditorSyntaxPreferencePage.color:Colour -PHPEditorSyntaxPreferencePage.bold:Bold -PHPEditorSyntaxPreferencePage.italic:Italic -PHPEditorSyntaxPreferencePage.underline:Underline -PHPEditorSyntaxPreferencePage.multiLineComment=Multi-line comment -PHPEditorSyntaxPreferencePage.singleLineComment=Single-line comment -PHPEditorSyntaxPreferencePage.tags=PHP Tags -PHPEditorSyntaxPreferencePage.keywords=Keywords -PHPEditorSyntaxPreferencePage.variables=Variables -PHPEditorSyntaxPreferencePage.types=Types -PHPEditorSyntaxPreferencePage.functions=Functions -PHPEditorSyntaxPreferencePage.constants=Constants -PHPEditorSyntaxPreferencePage.strings=Strings -PHPEditorSyntaxPreferencePage.others=Others -PHPEditorSyntaxPreferencePage.syntaxdialog=Custom PHP Syntax File: -PHPEditorSyntaxPreferencePage.browse=Browse.. -PHPEditorSyntaxPreferencePage.textfont=Text font - -PHPLanguagePreferencePage.description=PHP Editor Language -PHPLanguagePreferencePage.preflingo=PHP Language Preference -PHPLanguagePreferencePage.choose=Choose Language -PHPLanguagePreferencePage.english=English -PHPLanguagePreferencePage.german=German -PHPLanguagePreferencePage.french=French -PHPLanguagePreferencePage.spanish=Spanish -PHPLanguagePreferencePage.japanese=Japanese \ No newline at end of file + \ No newline at end of file diff --git a/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/preferences/PHPPreviewProjectPreferences.java b/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/preferences/PHPPreviewProjectPreferences.java index b85e6d4..f3c9be6 100644 --- a/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/preferences/PHPPreviewProjectPreferences.java +++ b/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/preferences/PHPPreviewProjectPreferences.java @@ -45,6 +45,9 @@ public class PHPPreviewProjectPreferences extends FieldEditorOverlayPage addField(new BooleanFieldEditor( IPreferenceConstants.PHP_SHOW_HTML_FILES_LOCAL, PHPPreferencesMessages .getString("PHPPreviewProjectPreferences.show_html_files_local"), composite)); + addField(new BooleanFieldEditor( + IPreferenceConstants.PHP_SHOW_XML_FILES_LOCAL, PHPPreferencesMessages + .getString("PHPPreviewProjectPreferences.show_xml_files_local"), composite)); //if (!isPropertyPage)) { // //} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/util/PHPFileUtil.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/util/PHPFileUtil.java index 8073298..177438d 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/util/PHPFileUtil.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/util/PHPFileUtil.java @@ -4,6 +4,9 @@ */ package net.sourceforge.phpdt.internal.ui.util; +import net.sourceforge.phpeclipse.ui.IPreferenceConstants; +import net.sourceforge.phpeclipse.ui.overlaypages.Util; + import org.eclipse.core.resources.IFile; /** @@ -11,211 +14,98 @@ import org.eclipse.core.resources.IFile; * */ public class PHPFileUtil { - public final static char[] SUFFIX_php = ".php".toCharArray(); //$NON-NLS-1$ - public final static char[] SUFFIX_PHP = ".PHP".toCharArray(); //$NON-NLS-1$ - public final static char[] SUFFIX_php3 = ".php3".toCharArray(); //$NON-NLS-1$ - public final static char[] SUFFIX_PHP3 = ".PHP3".toCharArray(); //$NON-NLS-1$ - public final static char[] SUFFIX_php4 = ".php4".toCharArray(); //$NON-NLS-1$ - public final static char[] SUFFIX_PHP4 = ".PHP4".toCharArray(); //$NON-NLS-1$ - public final static char[] SUFFIX_php5 = ".php5".toCharArray(); //$NON-NLS-1$ - public final static char[] SUFFIX_PHP5 = ".PHP5".toCharArray(); //$NON-NLS-1$ - public final static char[] SUFFIX_phtml = ".phtml".toCharArray(); //$NON-NLS-1$ - public final static char[] SUFFIX_PHTML = ".PHTML".toCharArray(); //$NON-NLS-1$ - public final static char[] SUFFIX_module = ".module".toCharArray(); //$NON-NLS-1$ - public final static char[] SUFFIX_MODULE = ".MODULE".toCharArray(); //$NON-NLS-1$ + public final static String[] PHP_EXTENSIONS = { + "php", + "php3", + "php4", + "php5", + "phtml", + "module", // drupal + "inc", + "class" + }; + public final static String[] HTML_EXTENSIONS = { + "html", + "htm", + "xhtml" + }; + public final static String[] SMARTY_EXTENSIONS = { + "tpl" + }; - public final static char[] SUFFIX_inc = ".inc".toCharArray(); //$NON-NLS-1$ - public final static char[] SUFFIX_INC = ".INC".toCharArray(); //$NON-NLS-1$ - public final static char[] SUFFIX_html = ".html".toCharArray(); //$NON-NLS-1$ - public final static char[] SUFFIX_HTML = ".HTML".toCharArray(); //$NON-NLS-1$ - public final static char[] SUFFIX_tpl = ".tpl".toCharArray(); //$NON-NLS-1$ - public final static char[] SUFFIX_TPL = ".TPL".toCharArray(); //$NON-NLS-1$ - public static boolean isPHPFile(IFile file) { String extension = file.getFileExtension(); return isPHPFileName(file.getLocation().toString()); } - /** - * Returns true iff str.toLowerCase().endsWith(".php") - * implementation is not creating extra strings. - */ - public final static boolean isPHPFileName(String name) { - return isPHP_FileName(name) || - isPHP3_FileName(name) || - isPHP4_FileName(name) || - isPHP5_FileName(name) || - isModule_FileName(name) || - isPHTML_FileName(name) || - isINC_FileName(name); - } + public final static String getFileExtension(String name) { + int index = name.lastIndexOf('.'); + if (index == -1) + return null; + if (index == (name.length() - 1)) + return null; //$NON-NLS-1$ + return name.substring(index + 1); +} /** * Returns true iff str.toLowerCase().endsWith(".php") * implementation is not creating extra strings. */ - private final static boolean isPHP_FileName(String name) { - int nameLength = name == null ? 0 : name.length(); - int suffixLength = SUFFIX_PHP.length; - if (nameLength < suffixLength) - return false; - - for (int i = 0, offset = nameLength - suffixLength; i < suffixLength; i++) { - char c = name.charAt(offset + i); - if (c != SUFFIX_php[i] && c != SUFFIX_PHP[i]) - return false; - } - return true; - } - - /** - * Returns true iff str.toLowerCase().endsWith(".php3") - * implementation is not creating extra strings. - */ - private final static boolean isPHP3_FileName(String name) { - int nameLength = name == null ? 0 : name.length(); - int suffixLength = SUFFIX_PHP3.length; - if (nameLength < suffixLength) - return false; - - for (int i = 0, offset = nameLength - suffixLength; i < suffixLength; i++) { - char c = name.charAt(offset + i); - if (c != SUFFIX_php3[i] && c != SUFFIX_PHP3[i]) - return false; - } - return true; - } - - /** - * Returns true iff str.toLowerCase().endsWith(".php4") - * implementation is not creating extra strings. - */ - private final static boolean isPHP4_FileName(String name) { - int nameLength = name == null ? 0 : name.length(); - int suffixLength = SUFFIX_PHP4.length; - if (nameLength < suffixLength) - return false; - - for (int i = 0, offset = nameLength - suffixLength; i < suffixLength; i++) { - char c = name.charAt(offset + i); - if (c != SUFFIX_php4[i] && c != SUFFIX_PHP4[i]) - return false; - } - return true; - } - - /** - * Returns true iff str.toLowerCase().endsWith(".php5") - * implementation is not creating extra strings. - */ - private final static boolean isPHP5_FileName(String name) { - int nameLength = name == null ? 0 : name.length(); - int suffixLength = SUFFIX_PHP5.length; - if (nameLength < suffixLength) - return false; - - for (int i = 0, offset = nameLength - suffixLength; i < suffixLength; i++) { - char c = name.charAt(offset + i); - if (c != SUFFIX_php5[i] && c != SUFFIX_PHP5[i]) - return false; - } - return true; - } - /** - * Returns true iff str.toLowerCase().endsWith(".module") - * implementation is not creating extra strings. - */ - private final static boolean isModule_FileName(String name) { - int nameLength = name == null ? 0 : name.length(); - int suffixLength = SUFFIX_MODULE.length; - if (nameLength < suffixLength) + public final static boolean isPHPFileName(String name) { + String extension = getFileExtension(name).toLowerCase(); + if (extension==null) { return false; - - for (int i = 0, offset = nameLength - suffixLength; i < suffixLength; i++) { - char c = name.charAt(offset + i); - if (c != SUFFIX_module[i] && c != SUFFIX_MODULE[i]) - return false; } - return true; - } - /** - * Returns true iff str.toLowerCase().endsWith(".phtml") - * implementation is not creating extra strings. - */ - private final static boolean isPHTML_FileName(String name) { - int nameLength = name == null ? 0 : name.length(); - int suffixLength = SUFFIX_PHTML.length; - if (nameLength < suffixLength) - return false; - - for (int i = 0, offset = nameLength - suffixLength; i < suffixLength; i++) { - char c = name.charAt(offset + i); - if (c != SUFFIX_phtml[i] && c != SUFFIX_PHTML[i]) - return false; - } - return true; - } - - /** - * Returns true iff str.toLowerCase().endsWith(".inc") - * implementation is not creating extra strings. - */ - private final static boolean isINC_FileName(String name) { - int nameLength = name == null ? 0 : name.length(); - int suffixLength = SUFFIX_INC.length; - if (nameLength < suffixLength) - return false; - - for (int i = 0, offset = nameLength - suffixLength; i < suffixLength; i++) { - char c = name.charAt(offset + i); - if (c != SUFFIX_inc[i] && c != SUFFIX_INC[i]) - return false; + for (int i=0;i