package com.bkahlert.nebula.handlers;

import java.io.File;
import java.net.URL;
import java.util.concurrent.Callable;

import org.apache.commons.io.FileUtils;
import org.apache.log4j.Logger;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.browser.IWebBrowser;

import com.bkahlert.nebula.utils.ExecUtils;
import com.bkahlert.nebula.widgets.browser.Browser;

public class BrowserShowSourceHandler extends AbstractHandler {

	private static final Logger LOGGER = Logger
			.getLogger(BrowserShowSourceHandler.class);

	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {
		Control focusControl = Display.getCurrent().getFocusControl();
		if (focusControl instanceof org.eclipse.swt.browser.Browser) {
			org.eclipse.swt.browser.Browser swtBrowser = (org.eclipse.swt.browser.Browser) focusControl;
			if (swtBrowser.getParent() instanceof Browser) {
				final Browser browser = (Browser) swtBrowser.getParent();
				try {
					ExecUtils.nonUIAsyncExec(new Callable<Void>() {
						@Override
						public Void call() throws Exception {
							try {
								String html = browser.getHtml().get();
								File tmp = File.createTempFile("Browser",
										".html");
								tmp.deleteOnExit();
								FileUtils.write(tmp, html);
								IWebBrowser browser = PlatformUI.getWorkbench()
										.getBrowserSupport()
										.getExternalBrowser();
								browser.openURL(new URL("file://"
										+ tmp.getAbsolutePath()));
							} catch (Exception e) {
								LOGGER.error(e);
							}
							return null;
						}
					});
				} catch (Exception e) {
					LOGGER.error(e);
					return null;
				}
			}
		}
		return null;
	}
}

@@ -899,16 +899,147 @@
 trol();%0A
+%09%09if (!(focusControl instanceof org.eclipse.swt.browser.Browser)) %7B%0A%09%09%09focusControl = Display.getCurrent().getCursorControl();%0A%09%09%7D%0A
 %09%09if (fo

Support for source mode in for browser applications that don't have the focus (mouse position is used in this case).