X-Git-Url: http://git.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPEclipseShowAction.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPEclipseShowAction.java index 7cd25dc..5018ac6 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPEclipseShowAction.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPEclipseShowAction.java @@ -30,117 +30,128 @@ import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IObjectActionDelegate; import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.jdt.internal.ui.actions.OpenBrowserUtil; + +import org.eclipse.ui.help.WorkbenchHelp; +import org.eclipse.help.IHelp; +//import org.eclipse.jdt.internal.ui.actions.OpenBrowserUtil; // import org.eclipse.help.ui.browser.LaunchURL; public class PHPEclipseShowAction implements IObjectActionDelegate { - private IWorkbenchPart workbenchPart; - /** - * Constructor for Action1. - */ - public PHPEclipseShowAction() { - super(); - } - - /** - * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart) - */ - public void setActivePart(IAction action, IWorkbenchPart targetPart) { - workbenchPart = targetPart; - } - - // public static void open(final URL url, final Shell shell, final String dialogTitle) { - // IHelp help= WorkbenchHelp.getHelpSupport(); - // if (help != null) { - // WorkbenchHelp.getHelpSupport().displayHelpResource(url.toExternalForm()); - // } else { - // showMessage(shell, dialogTitle, ActionMessages.getString("OpenBrowserUtil.help_not_available"), false); //$NON-NLS-1$ - // } - // } - - public void run(IAction action) { - ISelectionProvider selectionProvider = null; - selectionProvider = workbenchPart.getSite().getSelectionProvider(); - - StructuredSelection selection = null; - selection = (StructuredSelection) selectionProvider.getSelection(); - - IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore(); - - Shell shell = null; - Iterator iterator = null; - iterator = selection.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; - IPath path = file.getFullPath(); - // if (j2h==null) { - // shell = new Shell(); - // j2h = new Java2HTML(shell); - // } - - String fileName = file.getLocation().toString(); + private IWorkbenchPart workbenchPart; + /** + * Constructor for Action1. + */ + public PHPEclipseShowAction() { + super(); + } + + /** + * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart) + */ + public void setActivePart(IAction action, IWorkbenchPart targetPart) { + workbenchPart = targetPart; + } + + // public static void open(final URL url, final Shell shell, final String dialogTitle) { + // IHelp help= WorkbenchHelp.getHelpSupport(); + // if (help != null) { + // WorkbenchHelp.getHelpSupport().displayHelpResource(url.toExternalForm()); + // } else { + // showMessage(shell, dialogTitle, ActionMessages.getString("OpenBrowserUtil.help_not_available"), false); //$NON-NLS-1$ + // } + // } + + public void run(IAction action) { + ISelectionProvider selectionProvider = null; + selectionProvider = workbenchPart.getSite().getSelectionProvider(); + + StructuredSelection selection = null; + selection = (StructuredSelection) selectionProvider.getSelection(); + + IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore(); + + Shell shell = null; + Iterator iterator = null; + iterator = selection.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; + IPath path = file.getFullPath(); + // if (j2h==null) { + // shell = new Shell(); + // j2h = new Java2HTML(shell); + // } + + String fileName = file.getLocation().toString(); String lowerCaseFileName = fileName.toLowerCase(); - // fileName = "http://localhost"+fileName.replaceAll("c:", ""); - String documentRoot = store.getString(PHPeclipsePlugin.DOCUMENTROOT_PREF); + // fileName = "http://localhost"+fileName.replaceAll("c:", ""); + String documentRoot = store.getString(PHPeclipsePlugin.DOCUMENTROOT_PREF); documentRoot = documentRoot.replace('\\', '/'); documentRoot = documentRoot.toLowerCase(); MessageDialog.openInformation(shell, "lowerCaseFileName", "lowerCaseFileName: " + lowerCaseFileName); - - if ( lowerCaseFileName.startsWith(documentRoot) ) { + + if (lowerCaseFileName.startsWith(documentRoot)) { fileName = fileName.substring(documentRoot.length()); } else { MessageDialog.openInformation(shell, "Wrong DocumentRoot", "Adjust DocumentRoot: " + documentRoot); return; } - - fileName = store.getString(PHPeclipsePlugin.LOCALHOST_PREF) + fileName.replaceAll(documentRoot, ""); - - try { - if (store.getBoolean(PHPeclipsePlugin.USE_EXTERNAL_BROWSER_PREF)) { - String[] arguments = { fileName }; - MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.EXTERNAL_BROWSER_PREF)); - - Runtime runtime = Runtime.getRuntime(); - runtime.exec(form.format(arguments)); - // runtime.exec(store.getString(PHPeclipsePlugin.EXTERNAL_BROWSER_PREF) + " " + fileName); - // runtime.exec("command.com /c start iexplore " + fileName); - } else { - OpenBrowserUtil.open(new URL(fileName), shell, fileName); - } - } catch (MalformedURLException e) { - MessageDialog.openInformation(shell, "MalformedURLException: ", e.toString()); - } catch (IOException e) { - MessageDialog.openInformation(shell, "IOException", "Cannot show: " + fileName); - - } - - // MessageDialog.openInformation(shell, "PHPEclipse", "FileName - " + fileName); - // - // Runtime runtime = Runtime.getRuntime(); - // try { - // runtime.exec("command.com /c start iexplore "+fileName); - - // MessageDialog.openInformation(shell, "J2h Plug-in", "FileName - " + fileName); - // j2h.convert( fileName ); - } - } - } - } /** - * @see IActionDelegate#selectionChanged(IAction, ISelection) - */ - public void selectionChanged(IAction action, ISelection selection) { - } + fileName = store.getString(PHPeclipsePlugin.LOCALHOST_PREF) + fileName.replaceAll(documentRoot, ""); + + try { + if (store.getBoolean(PHPeclipsePlugin.USE_EXTERNAL_BROWSER_PREF)) { + String[] arguments = { fileName }; + MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.EXTERNAL_BROWSER_PREF)); + + Runtime runtime = Runtime.getRuntime(); + runtime.exec(form.format(arguments)); + // runtime.exec(store.getString(PHPeclipsePlugin.EXTERNAL_BROWSER_PREF) + " " + fileName); + // runtime.exec("command.com /c start iexplore " + fileName); + } else { + open(new URL(fileName), shell, fileName); + } + } catch (MalformedURLException e) { + MessageDialog.openInformation(shell, "MalformedURLException: ", e.toString()); + } catch (IOException e) { + MessageDialog.openInformation(shell, "IOException", "Cannot show: " + fileName); + + } + + // MessageDialog.openInformation(shell, "PHPEclipse", "FileName - " + fileName); + // + // Runtime runtime = Runtime.getRuntime(); + // try { + // runtime.exec("command.com /c start iexplore "+fileName); + + // MessageDialog.openInformation(shell, "J2h Plug-in", "FileName - " + fileName); + // j2h.convert( fileName ); + } + } + } + } /** + * @see IActionDelegate#selectionChanged(IAction, ISelection) + */ + public void selectionChanged(IAction action, ISelection selection) { + } + + public static void open(final URL url, final Shell shell, final String dialogTitle) { + IHelp help = WorkbenchHelp.getHelpSupport(); + if (help != null) { + WorkbenchHelp.getHelpSupport().displayHelpResource(url.toExternalForm()); + } else { + // showMessage(shell, dialogTitle, ActionMessages.getString("OpenBrowserUtil.help_not_available"), false); //$NON-NLS-1$ + } + } }