<?xml version="1.0"?>

<?xml-stylesheet href="chrome://global/skin/global.css"?>

<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
        windowtype="Firebug:Detached"
        id="firebug"
        title="Firebug"
        width="800" height="600"
        persist="screenX,screenY,width,height,sizemode"
        onload="importFirebug()" onunload="" onclose="return exportFirebug();">

    <vbox flex="2" id="fbMainFrame" collapsed="false">
        <browser id="fbMainContainer" flex="2" src="" disablehistory="true" />
    </vbox>

    <keyset id="mainkeyset">
        <key oncommand="exportFirebug();window.close();" key='W' modifiers='accel'/>
        <key oncommand="doFirefoxCommand('Browser:Reload')" keycode='VK_F5'/>
        <key oncommand="doFirefoxCommand('Browser:Reload')" key='r' modifiers='accel'/>
        <key oncommand="doFirefoxCommand('Browser:ReloadSkipCache')" keycode='VK_F5' modifiers='accel'/>
        <key oncommand="doFirefoxCommand('Browser:ReloadSkipCache')" key='r' modifiers='accel,shift'/>
    </keyset>

    <script type="application/x-javascript" src="chrome://firebug/content/trace.js"/>

    <script type="application/x-javascript">
        doFirefoxCommand = function(id)
        {
            opener.Firebug.Firefox.getElementById(id).doCommand();
        }

        importFirebug = function()
        {
            FBTrace.sysout("firebug.xul; importFirebug");

            var Firebug = opener.Firebug, fbc = Firebug.chrome;
            if (fbc.inDetachedScope)
            {
                exportFirebug = null;
                return window.close();
            }

            fbc.inDetachedScope = true;
            fbc.waitingForDetach = false;

            fbc.originalBrowser = fbc.window.top.document.getElementById("fbMainContainer");
            fbc.swapBrowsers(
                fbc.originalBrowser,
                document.getElementById("fbMainContainer")
            );
            Firebug.setPlacement("detached");

            fbc.originalBrowser.contentWindow.onunload = function()
            {
                window.close();
            }

            fbc.onDetach();
            document.getElementById("fbMainContainer").focus();
        }

        exportFirebug = function()
        {
            FBTrace.sysout("firebug.xul; exportFirebug");

            exportFirebug = null;
            var Firebug = opener.Firebug, fbc = Firebug.chrome;

            fbc.originalBrowser.contentWindow.onunload = null;
            fbc.inDetachedScope = false;

            fbc.swapBrowsers(
                document.getElementById("fbMainContainer"),
                fbc.originalBrowser
            );
            Firebug.setPlacement("minimized");
            fbc.onUndetach();
        }
    </script>

</window>
