/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- * * ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * * The contents of this file are subject to the Mozilla Public License Version * 1.1 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is The JavaScript Debugger. * * The Initial Developer of the Original Code is * Netscape Communications Corporation. * Portions created by the Initial Developer are Copyright (C) 1998 * the Initial Developer. All Rights Reserved. * * Contributor(s): * Robert Ginda, , original author * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), * in which case the provisions of the GPL or the LGPL are applicable instead * of those above. If you wish to allow use of your version of this file only * under the terms of either the GPL or the LGPL, and not to allow others to * use your version of this file under the terms of the MPL, indicate your * decision by deleting the provisions above and replace them with the notice * and other provisions required by the GPL or the LGPL. If you do not delete * the provisions above, a recipient may use your version of this file under * the terms of any one of the MPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */ const VMGR_VURL_SCHEME = "x-vloc:"; const VMGR_SCHEME_LEN = VMGR_VURL_SCHEME.length; const VMGR_HIDDEN = "hidden"; const VMGR_NEW = "new"; const VMGR_MAINWINDOW = "mainwindow"; const VMGR_GUTTER = "gutter"; const VMGR_VURL_HIDDEN = VMGR_VURL_SCHEME + "/" + VMGR_HIDDEN; const VMGR_VURL_NEW = VMGR_VURL_SCHEME + "/" + VMGR_NEW; const VMGR_VURL_MAINWINDOW = VMGR_VURL_SCHEME + "/" + VMGR_MAINWINDOW; const VMGR_VURL_GUTTER = VMGR_VURL_MAINWINDOW + "/gutter"; const VMGR_DEFAULT_CONTAINER = "initial-container"; var VMGR_GUTTER_CONTAINER = VMGR_VURL_MAINWINDOW + "?target=container&" + "id=" + VMGR_GUTTER + "&type=vertical"; function ViewManager(commandManager, mainWindow) { this.commandManager = commandManager; this.multiMoveDepth = 0; this.floaterSequence = 0; this.containerSequence = 0; this.dirtyContainers = new Object(); this.windows = new Object(); this.mainWindow = mainWindow; this.windows[VMGR_MAINWINDOW] = mainWindow; this.views = new Object(); } ViewManager.prototype.realizeViews = function vmgr_realizeviews (views) { for (var v in views) this.realizeView(views[v]); } ViewManager.prototype.realizeView = function vmgr_realizeview (view) { var entry; var key = view.viewId; this.views[key] = view; if ("init" in view && typeof view.init == "function") view.init(); var toggleName = "toggle-" + key; if (!(key in this.commandManager.commands)) { entry = [toggleName, "toggle-view " + key, CMD_CONSOLE]; if ("cmdary" in view) view.cmdary.unshift(entry); else view.cmdary = [entry]; } if ("cmdary" in view) { var commands = this.commandManager.defineCommands(view.cmdary); for (var i in this.windows) this.commandManager.installKeys (this.windows[i].document, commands); view.commands = commands; } if ("hooks" in view) this.commandManager.addHooks (view.hooks, key); } ViewManager.prototype.unrealizeViews = function vmgr_unrealizeviews (views) { for (var v in views) this.unrealizeView(views[v]); } ViewManager.prototype.unrealizeView = function vmgr_unrealizeview (view) { if ("commands" in view) this.commandManager.uninstallKeys(view.commands); if ("hooks" in view) this.commandManager.removeHooks (view.hooks, view.viewId); if ("destroy" in view && typeof view.destroy == "function") view.destroy(); delete this.views[view.viewId]; } ViewManager.prototype.startMultiMove = function vmrg_startmm() { ++this.multiMoveDepth; } ViewManager.prototype.endMultiMove = function vmrg_endmm() { --this.multiMoveDepth; ASSERT(this.multiMoveDepth >= 0, "mismatched multi move calls: " + this.multiMoveDepth); var container; if (!this.multiMoveDepth) { // close any empty windows that may have been left open during the // multi move. for (var w in this.windows) { if (w != VMGR_MAINWINDOW) { var window = this.windows[w]; container = window.document.getElementById(VMGR_DEFAULT_CONTAINER); if (container && container.viewCount == 0) window.close(); } } // deal with any single child tab containers too for (var viewId in this.views) { var view = this.views[viewId]; if ("currentContent" in view && view.currentContent) { container = view.currentContent.parentNode; if (container.getAttribute("type") == "tab" && container.viewCount == 1) { var parentLocation = this.computeLocation(container); container.viewCount = 0; this.moveView(parentLocation, viewId); container.parentNode.removeChild(container); } } } } } ViewManager.prototype.getWindowById = function vmgr_getwindow (windowId) { if (windowId in this.windows) return this.windows[windowId]; return null; } ViewManager.prototype.createWindow = function vmgr_createwindow (windowId, cb) { var viewManager = this; function onWindowLoaded (window) { var cm = viewManager.commandManager; cm.installKeys (window.document, cm.commands); if (typeof cb == "function") cb(window); }; if (!ASSERT(!(windowId in this.windows), "window " + windowId + " already exists")) { return null; } var win = openDialog ("chrome://venkman/content/venkman-floater.xul?id=" + encodeURIComponent(windowId), "_blank", "chrome,menubar,toolbar,resizable,dialog=no", onWindowLoaded); this.windows[windowId] = win; return win; } ViewManager.prototype.destroyWindows = function vmgr_destroywindows () { this.startMultiMove(); for (var w in this.windows) { if (w == VMGR_MAINWINDOW) this.destroyWindow(w); else this.windows[w].close(); } this.endMultiMove(); } ViewManager.prototype.destroyWindow = function vmgr_destroywindow (windowId) { if (!ASSERT(windowId in this.windows, "unknown window id")) return; var document = this.windows[windowId].document; for (var viewId in this.views) { try { var view = this.views[viewId]; if ("currentContent" in view && view.currentContent.ownerDocument == document) { this.moveViewURL(VMGR_VURL_HIDDEN, viewId); } } catch (ex) { dd ("caught exception while moving view ``" + ex + "''"); } } var container = document.getElementById (VMGR_DEFAULT_CONTAINER); var child = container.firstChild; while (child) { var next = child.nextSibling; container.removeChild (child); child = next; } if (windowId != VMGR_MAINWINDOW) delete this.windows[windowId]; } ViewManager.prototype.destroyContainer = function vmgr_destroycontainer (container) { content = container.firstChild; while (content) { if (content.hasAttribute("grout")) { content.parentNode.removeChild(content); } else { if (content.localName == "viewcontainer") { this.destroyContainer(content); } else { var viewId = content.getAttribute("id"); this.moveViewURL(VMGR_VURL_HIDDEN, viewId); } } content = container.firstChild; } container.parentNode.removeChild(container); } ViewManager.prototype.changeContainer = function vmgr_changecontainer (container, newType) { if (!ASSERT(newType != container.getAttribute("type"), "requested useless change, ``" + newType + "''")) { return; } this.hideContainer(container); container.setAttribute("type", newType); this.showContainer(container); this.groutContainer(container); } ViewManager.prototype.createContainer = function vmgr_createcontainer (parsedLocation, containerId, type) { if (!type) type = "vertical"; var parentContainer = this.getLocation(parsedLocation); if (!ASSERT(parentContainer, "location is hidden or does not exist")) return null; var document = parentContainer.ownerDocument; var container = document.createElement("viewcontainer"); container.setAttribute ("id", containerId); container.setAttribute ("flex", "1"); container.setAttribute ("type", type); if ("width" in parsedLocation) container.setAttribute ("width", parsedLocation.width); if ("height" in parsedLocation) container.setAttribute ("height", parsedLocation.height); container.setAttribute ("collapsed", "true"); var before; if ("before" in parsedLocation) before = getChildById(parentContainer, parsedLocation.before); parentContainer.insertBefore(container, before); this.groutContainer(parentContainer); return container; } /* * x-vloc:/[/][?