Bug 109481: Easy way to pick open pages (as opposed to open windows), patch by Jason Barnabe (np) <jason_barnabe@fastmail.fm>, r=timeless, sr=neil

This commit is contained in:
gavin%gavinsharp.com 2005-12-30 13:52:56 +00:00
parent dbc0c7bc6f
commit 0419f9d180
6 changed files with 153 additions and 41 deletions

View File

@ -20,6 +20,7 @@
<command id="cmdShowPrefsDialog" oncommand="inspector.showPrefsDialog()"/>
<command id="cmdToggleBrowser" oncommand="inspector.toggleBrowser(true)"/>
<command id="cmdToggleChrome" oncommand="inspector.toggleChrome()"/>
<command id="cmdEditUndo" global="true" oncommand="inspector.doViewerCommand('cmdEditUndo');"/>
<command id="cmdEditRedo" global="true" oncommand="inspector.doViewerCommand('cmdEditRedo');"/>

View File

@ -20,6 +20,7 @@
*
* Contributor(s):
* Joe Hewitt <hewitt@netscape.com> (original author)
* Jason Barnabe <jason_barnabe@fastmail.fm>
*
* 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
@ -48,10 +49,11 @@ var inspector;
const kSearchRegURL = "resource:///res/inspector/search-registry.rdf";
const kWindowDataSourceCID = "@mozilla.org/rdf/datasource;1?name=window-mediator";
const kClipboardHelperCID = "@mozilla.org/widget/clipboardhelper;1";
const kPromptServiceCID = "@mozilla.org/embedcomp/prompt-service;1";
const nsIWebNavigation = Components.interfaces.nsIWebNavigation;
const nsIDocShellTreeItem = Components.interfaces.nsIDocShellTreeItem;
const nsIDocShell = Components.interfaces.nsIDocShell;
//////////////////////////////////////////////////
@ -122,6 +124,11 @@ InspectorApp.prototype =
this.mPanelSet.addObserver("panelsetready", this, false);
this.mPanelSet.initialize();
this.mInspectDocumentMenu = document.getElementById("listDocuments-popup");
document.getElementById("cmdToggleChrome").setAttribute("checked",
PrefUtils.getPref("inspector.showChrome"));
if (aURI) {
this.gotoURL(aURI);
}
@ -207,6 +214,17 @@ InspectorApp.prototype =
cmd.setAttribute("checked", aValue);
},
/**
* Toggles inspector.showChrome
*/
toggleChrome: function()
{
var newValue = !PrefUtils.getPref("inspector.showChrome");
PrefUtils.setPref("inspector.showChrome", newValue);
var cmd = document.getElementById("cmdToggleChrome");
cmd.setAttribute("checked", newValue);
},
toggleSearch: function(aToggleSplitter)
{
this.setSearch(!this.mShowSearch, aToggleSplitter);
@ -351,27 +369,122 @@ InspectorApp.prototype =
}
},
goToWindow: function(aMenuitem)
/**
* Creates the submenu for Inspect Document
*/
showInspectDocumentList: function()
{
this.setTargetWindowById(aMenuitem.id);
const XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
var showChrome = PrefUtils.getPref("inspector.showChrome");
var ww = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
var windows = ww.getXULWindowEnumerator(null);
var contentDocs = [];
var chromeDocs = [];
while (windows.hasMoreElements()) {
try {
// Get the window's main docshell
var windowDocShell = windows.getNext()
.QueryInterface(Components.interfaces.nsIXULWindow).docShell;
// Put the window's documents into the appropriate arrays
this.appendContainedDocuments(contentDocs, windowDocShell,
nsIDocShellTreeItem.typeContent);
if (showChrome) {
this.appendContainedDocuments(chromeDocs, windowDocShell,
nsIDocShellTreeItem.typeChrome);
}
}
catch (ex) {
// We've failed with this window somehow, but we're catching the error so the
// others will still work
dump(ex + "\n");
}
}
// Now add what we found to the menu
var docNumber = 0;
for (var i = 0; i < contentDocs.length; i++) {
this.addInspectDocumentMenuItem(contentDocs[i], ++docNumber);
}
if (showChrome) {
// Put a seperator in if there were content docs
if (contentDocs.length > 0) {
this.mInspectDocumentMenu.appendChild(document.createElementNS(XULNS, "menuseparator"));
}
for (var i = 0; i < chromeDocs.length; i++) {
this.addInspectDocumentMenuItem(chromeDocs[i], ++docNumber);
}
} else {
// If we're not showing chrome, there's a possibility there are no documents
// at all.
if (contentDocs.length == 0) {
var noneMenuItem = document.createElementNS(XULNS, "menuitem");
noneMenuItem.setAttribute("label", this.mPanelSet.stringBundle
.getString("inspectWindow.noDocuments.message"));
noneMenuItem.setAttribute("disabled", true);
this.mInspectDocumentMenu.appendChild(noneMenuItem);
}
}
},
setTargetWindowById: function(aResId)
/**
* Appends to the array the documents contained in docShell (including the passed
* docShell itself).
*
* @param array the array to append to
* @param docShell the docshell to look for documents in
* @param type one of the types defined in nsIDocShellTreeItem
*/
appendContainedDocuments: function(array, docShell, type)
{
var windowManager = XPCU.getService(kWindowDataSourceCID, "nsIWindowDataSource");
var win = windowManager.getWindowForResource(aResId);
// Load all the window's content docShells
var containedDocShells = docShell.getDocShellEnumerator(type,
nsIDocShell.ENUMERATE_FORWARDS);
while (containedDocShells.hasMoreElements()) {
try {
// Get the corresponding document for this docshell
var childDoc = containedDocShells.getNext().QueryInterface(nsIDocShell)
.contentViewer.DOMDocument;
if (win) {
this.setTargetWindow(win);
this.setBrowser(false, true);
} else {
var bundle = this.mPanelSet.stringBundle;
var msg = bundle.getString("inspectWindow.error.message");
var title = bundle.getString("inspectWindow.error.title");
this.mPromptService.alert(window, title, msg);
// Ignore the DOM Insector's browser docshell if it's not being used
if (docShell.contentViewer.DOMDocument.location.href != document.location.href ||
childDoc.location.href != "about:blank") {
array.push(childDoc);
}
}
catch (ex) {
// We've failed with this document somehow, but we're catching the error so
// the others will still work
dump(ex + "\n");
}
}
},
/**
* Creates a menu item for Inspect Document.
*
* @param doc document related to this menu item
* @param docNumber the position of the document
*/
addInspectDocumentMenuItem: function(doc, docNumber)
{
const XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
var menuItem = document.createElementNS(XULNS, "menuitem");
menuItem.doc = doc;
// Use the URL if there's no title
var title = doc.title || doc.location.href;
// The first ten items get numeric access keys
if (docNumber < 10) {
menuItem.setAttribute("label", docNumber + " " + title);
menuItem.setAttribute("accesskey", docNumber);
} else {
menuItem.setAttribute("label", title);
}
this.mInspectDocumentMenu.appendChild(menuItem);
},
setTargetWindow: function(aWindow)
{
this.setTargetDocument(aWindow.document);

View File

@ -27,16 +27,10 @@
</popupset>
<menupopup id="menu_FilePopup">
<menu oncommand="inspector.goToWindow(event.target);"
id="mnWindowsFile" label="&mnWindows.label;" accesskey="&mnWindows.accesskey;"
datasources="rdf:window-mediator" ref="NC:WindowMediatorRoot">
<template>
<rule>
<menupopup>
<menuitem uri="rdf:*" label="&NC-rdf;KeyIndex &NC-rdf;Name" accesskey="&NC-rdf;KeyIndex"/>
</menupopup>
</rule>
</template>
<menu oncommand="inspector.setTargetDocument(event.target.doc);" id="mnInspectDocumentFile" label="&mnInspectDocument.label;"
accesskey="&mnInspectDocument.accesskey;">
<menupopup id="listDocuments-popup" onpopupshowing="inspector.showInspectDocumentList()"
onpopuphiding="inspector.emptyChildren(this);"/>
</menu>
<menuitem label="&cmdShowOpenURLDialog.label;" accesskey="&cmdShowOpenURLDialog.accesskey;"
observes="cmdShowOpenURLDialog"/>
@ -68,8 +62,10 @@
-->
</menupopup>
<menupopup id="mppView" >
<menupopup id="mppView">
<menuitem class="menuitem-iconic" type="checkbox" label="&cmdToggleBrowser.label;" observes="cmdToggleBrowser"/>
<menuitem class="menuitem-iconic" type="checkbox" label="&cmdToggleChrome.label;" observes="cmdToggleChrome"
accesskey="&cmdToggleChrome.accesskey;"/>
<!--
<menuitem class="menuitem-iconic" type="checkbox" label="&cmdToggleSearch.label;" observes="cmdToggleSearch"/>
-->

View File

@ -43,4 +43,4 @@ pref("inspector.blink.speed", 100);
pref("inspector.blink.invert", false);
pref("inspector.dom.showAnon", true);
pref("inspector.dom.showWhitespaceNodes", true);
pref("inspector.showChrome", false);

View File

@ -11,42 +11,45 @@
<!-- MAIN MENU ITEMS -->
<!ENTITY mnFile.label "File">
<!ENTITY mnWindows.label "Inspect a Window">
<!ENTITY mnWindows.accesskey "w">
<!ENTITY mnFile.accesskey "f">
<!ENTITY mnFile.accesskey "F">
<!ENTITY mnInspectDocument.label "Inspect Document">
<!ENTITY mnInspectDocument.accesskey "D">
<!ENTITY cmdShowOpenURLDialog.label "Inspect a URL...">
<!ENTITY cmdShowOpenURLDialog.accesskey "u">
<!ENTITY cmdShowOpenURLDialog.accesskey "U">
<!ENTITY cmdClose.label "Close">
<!ENTITY cmdClose.accesskey "c">
<!ENTITY cmdClose.accesskey "C">
<!ENTITY cmdExit.label "Exit">
<!ENTITY cmdExit.accesskey "x">
<!ENTITY mnEdit.label "Edit">
<!ENTITY mnEdit.accesskey "e">
<!ENTITY mnEdit.accesskey "E">
<!ENTITY cmdUndo.label "Undo">
<!ENTITY cmdUndo.accesskey "u">
<!ENTITY cmdUndo.accesskey "U">
<!ENTITY cmdRedo.label "Redo">
<!ENTITY cmdRedo.accesskey "r">
<!ENTITY cmdRedo.accesskey "R">
<!ENTITY cmdCut.label "Cut">
<!ENTITY cmdCut.accesskey "t">
<!ENTITY cmdCopy.label "Copy">
<!ENTITY cmdCopy.accesskey "c">
<!ENTITY cmdCopy.accesskey "C">
<!ENTITY cmdPaste.label "Paste">
<!ENTITY cmdPaste.accesskey "p">
<!ENTITY cmdPaste.accesskey "P">
<!ENTITY cmdDelete.label "Delete">
<!ENTITY cmdDelete.accesskey "d">
<!ENTITY cmdDelete.accesskey "D">
<!ENTITY mnSearch.label "Search">
<!ENTITY mnSearch.accesskey "s">
<!ENTITY mnSearch.accesskey "S">
<!ENTITY mnSearchPlugins.label "Extensions">
<!ENTITY mnSearchPlugins.accesskey "e">
<!ENTITY mnSearchPlugins.accesskey "E">
<!ENTITY cmdRunSearch.label "Run...">
<!ENTITY cmdRunSearch.accesskey "r">
<!ENTITY cmdRunSearch.accesskey "R">
<!ENTITY mnView.label "View">
<!ENTITY mnView.accesskey "v">
<!ENTITY cmdToggleBrowser.label "Browser">
<!ENTITY cmdToggleSearch.label "Search Results">
<!ENTITY cmdToggleChrome.label "Chrome">
<!ENTITY cmdToggleChrome.accesskey "C">
<!ENTITY cmdViewSearchItem.label "View...">
<!ENTITY cmdEditSearchItem.label "Edit...">

View File

@ -37,8 +37,7 @@
inspectURL.title = Inspect URL
inspectURL.message = Enter a URL:
inspectWindow.error.message = Unable to switch to the requested window.
inspectWindow.error.title = Inspect Window Error
inspectWindow.noDocuments.message = (None)
styleRuleNewProperty.title = New Style Rule
styleRuleEditProperty.title = Edit Style Rule
styleRulePropertyValue.message = Enter the property value: