Author: yradtsevich
Date: 2012-01-18 10:57:06 -0500 (Wed, 18 Jan 2012)
New Revision: 37943
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/BrowserSim.java
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/Messages.java
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/messages.properties
Log:
https://issues.jboss.org/browse/JBIDE-10555 : Browsersim should have a "open in
default browser" action
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/BrowserSim.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/BrowserSim.java 2012-01-18
13:48:58 UTC (rev 37942)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/BrowserSim.java 2012-01-18
15:57:06 UTC (rev 37943)
@@ -10,6 +10,7 @@
******************************************************************************/
package org.jboss.tools.vpe.browsersim.ui;
+import java.awt.Desktop;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
@@ -120,13 +121,7 @@
try {
skin.createControls(display);
} catch (SWTError e) {
- System.err.println(Messages.BrowserSim_COULD_NOT_INSTANTIATE_WEBKIT_BROWSER +
e.getMessage());
-
- MessageBox messageBox = new MessageBox(new Shell(display), SWT.OK | SWT.ICON_ERROR);
- messageBox.setText("Error");
- messageBox.setMessage(Messages.BrowserSim_COULD_NOT_INSTANTIATE_WEBKIT_BROWSER +
e.getMessage());
- messageBox.open();
-
+ showErrorMessage(new Shell(display),
Messages.BrowserSim_COULD_NOT_INSTANTIATE_WEBKIT_BROWSER + e.getMessage());
display.dispose();
return;
}
@@ -265,8 +260,10 @@
});
}
- private void addFileMenuItems(Menu file) {
- MenuItem exit = new MenuItem(file, SWT.PUSH);
+ private void addFileMenuItems(Menu menu) {
+ addOpenInDefaultBrowserItem(menu);
+
+ MenuItem exit = new MenuItem(menu, SWT.PUSH);
exit.setText(Messages.BrowserSim_EXIT);
exit.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
@@ -293,6 +290,33 @@
});
}
+ public void addOpenInDefaultBrowserItem(Menu menu) {
+ if (Desktop.isDesktopSupported()) {
+ if (Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
+ MenuItem openInDefaultBrowser = new MenuItem(menu, SWT.PUSH);
+ openInDefaultBrowser.setText(Messages.BrowserSim_OPEN_IN_DEFAULT_BROWSER);
+ openInDefaultBrowser.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ try {
+ Desktop.getDesktop().browse(new URI(skin.getBrowser().getUrl()));
+ } catch (Exception e1) {
+ showErrorMessage(skin.getShell(),
Messages.BrowserSim_COULD_NOT_OPEN_DEFAULT_BROWSER + e1.getMessage());
+ }
+ }
+ });
+ }
+ }
+ }
+
+ private void showErrorMessage(Shell shell, String message) {
+ System.err.println(message);
+
+ MessageBox messageBox = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
+ messageBox.setText(Messages.BrowserSim_ERROR);
+ messageBox.setMessage(message);
+ messageBox.open();
+ }
+
private void addDevicesListForMenu(final DevicesList devicesList, Menu devicesMenu) {
List<Device> devices = devicesList.getDevices();
for (int i = 0; i < devices.size(); i++) {
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/Messages.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/Messages.java 2012-01-18
13:48:58 UTC (rev 37942)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/Messages.java 2012-01-18
15:57:06 UTC (rev 37943)
@@ -20,11 +20,13 @@
public static String BrowserSim_ADDRESS;
public static String BrowserSim_BROWSER_SIM;
public static String BrowserSim_COULD_NOT_INSTANTIATE_WEBKIT_BROWSER;
+ public static String BrowserSim_COULD_NOT_OPEN_DEFAULT_BROWSER;
public static String BrowserSim_DEVICES;
public static String BrowserSim_ERROR;
public static String BrowserSim_EXIT;
public static String BrowserSim_FILE;
public static String BrowserSim_MORE;
+ public static String BrowserSim_OPEN_IN_DEFAULT_BROWSER;
public static String BrowserSim_TURN_LEFT;
public static String BrowserSim_TURN_RIGHT;
public static String EditDeviceDialog_CANCEL;
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/messages.properties
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/messages.properties 2012-01-18
13:48:58 UTC (rev 37942)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/messages.properties 2012-01-18
15:57:06 UTC (rev 37943)
@@ -1,11 +1,13 @@
BrowserSim_ADDRESS=Address
BrowserSim_BROWSER_SIM=BrowserSim
-BrowserSim_COULD_NOT_INSTANTIATE_WEBKIT_BROWSER=Could not instantiate WebKit Browser:
+BrowserSim_COULD_NOT_INSTANTIATE_WEBKIT_BROWSER=Could not instantiate WebKit Browser:
+BrowserSim_COULD_NOT_OPEN_DEFAULT_BROWSER=Could not open default browser:
BrowserSim_DEVICES=Devices
BrowserSim_ERROR=Error
BrowserSim_EXIT=Exit
BrowserSim_FILE=File
BrowserSim_MORE=More...
+BrowserSim_OPEN_IN_DEFAULT_BROWSER=Open in default browser
BrowserSim_TURN_LEFT=Turn Left
BrowserSim_TURN_RIGHT=Turn Right
EditDeviceDialog_CANCEL=Cancel