зеркало из https://github.com/mozilla/pjs.git
Bug 205872: domNode viewer should use one dialog for setting new/editing attributes, patch by Shawn Wilsher <comrade693@gmail.com>, r=timeless, sr=neil
This commit is contained in:
Родитель
ee26e6c071
Коммит
dcfe845dac
|
@ -51,7 +51,6 @@ var gPromptService;
|
|||
//////////// global constants ////////////////////
|
||||
|
||||
const kDOMViewCID = "@mozilla.org/inspector/dom-view;1";
|
||||
const kPromptServiceCID = "@mozilla.org/embedcomp/prompt-service;1";
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
|
@ -215,7 +214,8 @@ DOMNodeViewer.prototype =
|
|||
case "cmdEditDelete":
|
||||
return this.selectedAttribute != null;
|
||||
case "cmdEditEdit":
|
||||
return this.mAttrTree.view.selection.count == 1;
|
||||
return this.mAttrTree.currentIndex >= 0 &&
|
||||
this.mAttrTree.view.selection.count == 1;
|
||||
case "cmdEditNodeValue":
|
||||
// this function can be fired before the subject is set
|
||||
if (this.subject) {
|
||||
|
@ -376,43 +376,38 @@ cmdEditInsert.prototype =
|
|||
|
||||
promptFor: function()
|
||||
{
|
||||
if (!gPromptService) {
|
||||
gPromptService = XPCU.getService(kPromptServiceCID, "nsIPromptService");
|
||||
}
|
||||
|
||||
var attrName = { value: "" };
|
||||
var attrValue = { value: "" };
|
||||
var dummy = { value: false };
|
||||
|
||||
var bundle = viewer.pane.panelset.stringBundle;
|
||||
var msg = bundle.getString("enterAttrName.message");
|
||||
var title = bundle.getString("newAttribute.title");
|
||||
var doc = viewer.subject.ownerDocument;
|
||||
var out = { name: null, value: null, namespaceURI: null, accepted: false };
|
||||
|
||||
window.openDialog("chrome://inspector/content/viewers/domNode/domNodeDialog.xul",
|
||||
"insert", "chrome,modal,centerscreen", out, title, doc);
|
||||
|
||||
if (gPromptService.prompt(window, title, msg, attrName, null, dummy)) {
|
||||
msg = bundle.getString("enterAttrValue.message");
|
||||
if (gPromptService.prompt(window, title, msg, attrValue, null, dummy)) {
|
||||
this.subject = viewer.subject;
|
||||
this.subject.setAttribute(attrName.value, attrValue.value);
|
||||
this.attr = this.subject.getAttributeNode(attrName.value);
|
||||
if (out.accepted)
|
||||
this.subject.setAttributeNS(out.namespaceURI, out.name, out.value);
|
||||
|
||||
this.attr = this.subject.getAttributeNode(out.name);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
},
|
||||
|
||||
doCommand: function()
|
||||
{
|
||||
if (this.attr)
|
||||
this.subject.setAttribute(this.attr.nodeName, this.attr.nodeValue);
|
||||
else
|
||||
if (!this.attr)
|
||||
return this.promptFor();
|
||||
|
||||
this.subject.setAttributeNS(this.attr.namespaceURI,
|
||||
this.attr.nodeName,
|
||||
this.attr.nodeValue);
|
||||
return false;
|
||||
},
|
||||
|
||||
undoCommand: function()
|
||||
{
|
||||
if (this.attr && this.subject == viewer.subject)
|
||||
this.subject.removeAttribute(this.attr.nodeName, this.attr.nodeValue);
|
||||
this.subject.removeAttributeNS(this.attr.namepsaceURI,
|
||||
this.attr.localName);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -455,28 +450,44 @@ cmdEditEdit.prototype =
|
|||
attr: null,
|
||||
previousValue: null,
|
||||
newValue: null,
|
||||
previousNamespaceURI: null,
|
||||
newNamespaceURI: null,
|
||||
subject: null,
|
||||
|
||||
promptFor: function()
|
||||
{
|
||||
var attr = viewer.selectedAttribute.node;
|
||||
if (attr) {
|
||||
if (!gPromptService) {
|
||||
gPromptService = XPCU.getService(kPromptServiceCID, "nsIPromptService");
|
||||
}
|
||||
|
||||
var attrValue = { value: attr.nodeValue };
|
||||
var dummy = { value: false };
|
||||
|
||||
var bundle = viewer.pane.panelset.stringBundle;
|
||||
var msg = bundle.getString("enterAttrValue.message");
|
||||
var title = bundle.getString("editAttribute.title");
|
||||
var doc = attr.ownerDocument;
|
||||
var out = {
|
||||
name: attr.nodeName,
|
||||
value: attr.nodeValue,
|
||||
namespaceURI: attr.namespaceURI,
|
||||
accepted: false
|
||||
};
|
||||
|
||||
if (gPromptService.prompt(window, title, msg, attrValue, null, dummy)) {
|
||||
window.openDialog("chrome://inspector/content/viewers/domNode/domNodeDialog.xul",
|
||||
"edit", "chrome,modal,centerscreen", out, title, doc);
|
||||
|
||||
if (out.accepted) {
|
||||
this.subject = viewer.subject;
|
||||
this.newValue = attrValue.value;
|
||||
this.newValue = out.value;
|
||||
this.newNamespaceURI = out.namespaceURI;
|
||||
this.previousValue = attr.nodeValue;
|
||||
this.subject.setAttribute(attr.nodeName, attrValue.value);
|
||||
this.previousNamespaceURI = attr.namespaceURI;
|
||||
if (this.previousNamespaceURI == this.newNamespaceURI) {
|
||||
this.subject.setAttributeNS(this.previousNamespaceURI,
|
||||
attr.nodeName,
|
||||
out.value);
|
||||
} else {
|
||||
this.subject.removeAttributeNS(this.previousNamespaceURI,
|
||||
attr.localName);
|
||||
this.subject.setAttributeNS(out.namespaceURI,
|
||||
attr.nodeName,
|
||||
out.value);
|
||||
}
|
||||
this.attr = this.subject.getAttributeNode(attr.nodeName);
|
||||
return false;
|
||||
}
|
||||
|
@ -486,17 +497,32 @@ cmdEditEdit.prototype =
|
|||
|
||||
doCommand: function()
|
||||
{
|
||||
if (this.attr)
|
||||
this.subject.setAttribute(this.attr.nodeName, this.newValue);
|
||||
else
|
||||
if (!this.attr)
|
||||
return this.promptFor();
|
||||
|
||||
this.subject.removeAttributeNS(this.previousNamespaceURI,
|
||||
this.attr.localName);
|
||||
this.subject.setAttributeNS(this.newNamespaceURI,
|
||||
this.attr.nodeName,
|
||||
this.newValue);
|
||||
return false;
|
||||
},
|
||||
|
||||
undoCommand: function()
|
||||
{
|
||||
if (this.attr)
|
||||
this.subject.setAttribute(this.attr.nodeName, this.previousValue);
|
||||
if (this.attr) {
|
||||
if (this.previousNamespaceURI == this.newNamespaceURI) {
|
||||
this.subject.setAttributeNS(this.previousNamespaceURI,
|
||||
this.attr.nodeName,
|
||||
this.previousValue);
|
||||
} else {
|
||||
this.subject.removeAttributeNS(this.newNamespaceURI,
|
||||
this.attr.localName);
|
||||
this.subject.setAttributeNS(this.previousNamespaceURI,
|
||||
this.attr.nodeName,
|
||||
this.previousValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -0,0 +1,135 @@
|
|||
/* ***** 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 mozilla.org code for the DOM Inspector.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Shawn Wilsher <me@shawnwilsher.com>
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 2006
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* 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 ***** */
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//// Global Variables
|
||||
|
||||
var dialog;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//// Initialization/Destruction
|
||||
|
||||
window.addEventListener("load", DomNodeDialog_initialize, false);
|
||||
|
||||
function DomNodeDialog_initialize()
|
||||
{
|
||||
dialog = new DomNodeDialog();
|
||||
dialog.initialize();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//// class DomNodeDialog
|
||||
|
||||
function DomNodeDialog()
|
||||
{
|
||||
this.mData = window.arguments[0];
|
||||
this.mTitle = window.arguments[1];
|
||||
this.mDoc = window.arguments[2];
|
||||
|
||||
this.nodeName = document.getElementById("tx_nodeName");
|
||||
this.nodeValue = document.getElementById("tx_nodeValue");
|
||||
this.namespace = document.getElementById("tx_namespace");
|
||||
this.menulist = document.getElementById("ml_namespace");
|
||||
}
|
||||
|
||||
DomNodeDialog.prototype =
|
||||
{
|
||||
/**
|
||||
* This function initializes the content of the dialog.
|
||||
*/
|
||||
initialize: function initialize()
|
||||
{
|
||||
document.title = this.mTitle;
|
||||
var menuitems = this.menulist.firstChild.childNodes;
|
||||
var defaultNS = document.getElementById("mi_namespace");
|
||||
var customNS = document.getElementById("mi_custom");
|
||||
var accept = document.documentElement.getButton("accept");
|
||||
|
||||
accept.disabled = this.mData.name == null;
|
||||
this.nodeName.value = this.mData.name || "";
|
||||
this.nodeName.disabled = this.mData.name != null;
|
||||
this.nodeValue.value = this.mData.value || "";
|
||||
this.menulist.disabled = !this.enableNamespaces();
|
||||
defaultNS.value = this.mDoc.documentElement.namespaceURI;
|
||||
customNS.value = this.mData.namespaceURI;
|
||||
this.menulist.value = this.mData.namespaceURI;
|
||||
|
||||
this.toggleNamespace();
|
||||
},
|
||||
|
||||
/**
|
||||
* The function that is called on accept. Sets data.
|
||||
*/
|
||||
accept: function accept()
|
||||
{
|
||||
this.mData.name = this.nodeName.value;
|
||||
this.mData.value = this.nodeValue.value;
|
||||
this.mData.namespaceURI = this.namespace.value;
|
||||
this.mData.accepted = true;
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
* toggleNamespace toggles the namespace textbox based on the namespace menu.
|
||||
*/
|
||||
toggleNamespace: function toggleNamespace()
|
||||
{
|
||||
dialog.namespace.disabled = dialog.menulist.selectedItem.id != "mi_custom";
|
||||
dialog.namespace.value = dialog.menulist.value;
|
||||
},
|
||||
|
||||
/**
|
||||
* enableNamespaces determines if the document accepts namespaces or not
|
||||
*
|
||||
* @return True if the document can have namespaced attributes, false
|
||||
* otherwise.
|
||||
*/
|
||||
enableNamespaces: function enableNamespaces()
|
||||
{
|
||||
return this.mDoc.contentType != "text/html";
|
||||
},
|
||||
|
||||
/**
|
||||
* toggleAccept enables/disables the Accept button when there is/isn't an
|
||||
* attribute name.
|
||||
*/
|
||||
toggleAccept: function toggleAccept()
|
||||
{
|
||||
document.documentElement.getButton("accept").disabled =
|
||||
dialog.nodeName.value == "";
|
||||
}
|
||||
};
|
|
@ -0,0 +1,127 @@
|
|||
<?xml version="1.0"?>
|
||||
<!--
|
||||
/* ***** 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 mozilla.org code for the DOM Inspector.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Shawn Wilsher <me@shawnwilsher.com>
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 2006
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* 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 ***** */
|
||||
-->
|
||||
<!DOCTYPE dialog SYSTEM "chrome://inspector/locale/viewers/domNode.dtd">
|
||||
<?xml-stylesheet type="text/css"
|
||||
href="chrome://inspector/skin/viewers/domNode/domNode.css"?>
|
||||
|
||||
<dialog id="editInsertAttribute"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
buttons="accept,cancel"
|
||||
ondialogaccept="dialog.accept();">
|
||||
<script type="application/javascript"
|
||||
src="chrome://inspector/content/viewers/domNode/domNodeDialog.js"/>
|
||||
<grid flex="1">
|
||||
<columns>
|
||||
<column/>
|
||||
<column flex="1"/>
|
||||
</columns>
|
||||
<rows>
|
||||
<row align="center">
|
||||
<label value="&nodeName.label;" control="nodeName"/>
|
||||
<textbox id="tx_nodeName" oninput="dialog.toggleAccept();"/>
|
||||
</row>
|
||||
<row align="center">
|
||||
<label value="&nodeValue.label;" control="nodeValue"/>
|
||||
<textbox id="tx_nodeValue"/>
|
||||
</row>
|
||||
<row align="center">
|
||||
<label value="&namespaceURI.label;" control="namespaceURI"/>
|
||||
<menulist id="ml_namespace" oncommand="dialog.toggleNamespace();">
|
||||
<menupopup id="mp_namespaces">
|
||||
<!-- This must be first, and must have a the value attribute set to
|
||||
"" in order for it to work properly -->
|
||||
<menuitem label="&namespaceTitle.null.label;"
|
||||
id="mi_NullNS"
|
||||
value=""/>
|
||||
<menuitem label="&namespaceTitle.XMLNS.label;"
|
||||
id="mi_XMLNSNS"
|
||||
value="http://www.w3.org/2000/xmlns/"/>
|
||||
<menuitem label="&namespaceTitle.XML.label;"
|
||||
id="mi_XMLNS"
|
||||
value="http://www.w3.org/XML/1998/namespace"/>
|
||||
<menuitem label="&namespaceTitle.XHTML.label;"
|
||||
id="mi_XHTMLNS"
|
||||
value="http://www.w3.org/1999/xhtml"/>
|
||||
<menuitem label="&namespaceTitle.XLink.label;"
|
||||
id="mi_XLinkNS"
|
||||
value="http://www.w3.org/1999/xlink"/>
|
||||
<menuitem label="&namespaceTitle.XSLT.label;"
|
||||
id="mi_XSLTNS"
|
||||
value="http://www.w3.org/1999/XSL/Transform"/>
|
||||
<menuitem label="&namespaceTitle.XBL.label;"
|
||||
id="mi_XBLNS"
|
||||
value="http://www.mozilla.org/xbl"/>
|
||||
<menuitem label="&namespaceTitle.MathML.label;"
|
||||
id="mi_MathMLNS"
|
||||
value="http://www.w3.org/1998/Math/MathML"/>
|
||||
<menuitem label="&namespaceTitle.RDF.label;"
|
||||
id="mi_RDFNS"
|
||||
value="http://www.w3.org/1999/02/22-rdf-syntax-ns"/>
|
||||
<menuitem label="&namespaceTitle.XUL.label;"
|
||||
id="mi_XULNS"
|
||||
value="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"/>
|
||||
<menuitem label="&namespaceTitle.SVG.label;"
|
||||
id="mi_SVGNS"
|
||||
value="http://www.w3.org/2000/svg"/>
|
||||
<menuitem label="&namespaceTitle.XMLEvents.label;"
|
||||
id="mi_XMLEventsNS"
|
||||
value="http://www.w3.org/2001/xml-events"/>
|
||||
<menuitem label="&namespaceTitle.WAIRoles.label;"
|
||||
id="mi_WAIRolesNS"
|
||||
value="http://www.w3.org/2005/01/wai-rdf/GUIRoleTaxonomy"/>
|
||||
<menuitem label="&namespaceTitle.WAIProperties.label;"
|
||||
id="mi_WAIPropertiesNS"
|
||||
value="http://www.w3.org/2005/07/aaa"/>
|
||||
<!-- Value set onload -->
|
||||
<menuitem label="&namespaceTitle.default.label;"
|
||||
id="mi_namespace"/>
|
||||
<!-- Value set onload -->
|
||||
<menuitem label="&namespaceTitle.custom.label;"
|
||||
id="mi_custom"/>
|
||||
</menupopup>
|
||||
</menulist>
|
||||
</row>
|
||||
<row>
|
||||
<spacer/>
|
||||
<textbox id="tx_namespace"/>
|
||||
</row>
|
||||
</rows>
|
||||
</grid>
|
||||
</dialog>
|
|
@ -46,8 +46,6 @@ sidebar.title = DOM Inspector
|
|||
sidebarInstalled = The sidebar is installed.
|
||||
newAttribute.title = New Attribute
|
||||
editAttribute.title = Edit Attribute
|
||||
enterAttrName.message = Enter the attribute name:
|
||||
enterAttrValue.message = Enter the attribute value:
|
||||
findNodesDocumentEnd.message = End of document reached.
|
||||
findNodesDocumentEnd.title = Find Nodes
|
||||
#LOCALIZATION NOTE (root.title) label displayed for the tree head of the JavaScript Object tree
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
- the Initial Developer. All Rights Reserved.
|
||||
-
|
||||
- Contributor(s):
|
||||
- Shawn Wilsher <me@shawnwilsher.com>
|
||||
-
|
||||
- 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
|
||||
|
@ -39,3 +40,23 @@
|
|||
<!ENTITY nodeName.label "Node Name:">
|
||||
<!ENTITY namespaceURI.label "Namespace URI:">
|
||||
<!ENTITY nodeType.label "Node Type:">
|
||||
<!ENTITY nodeValue.label "Node Value:">
|
||||
|
||||
<!ENTITY namespaceTitle.null.label "null">
|
||||
<!ENTITY namespaceTitle.default.label "Document Default">
|
||||
|
||||
<!-- LOCALIZATION NOTE: DO NOT LOCALIZE These are generic Namespaces -->
|
||||
<!ENTITY namespaceTitle.XMLNS.label "XMLNS">
|
||||
<!ENTITY namespaceTitle.XML.label "XML">
|
||||
<!ENTITY namespaceTitle.XHTML.label "XHTML">
|
||||
<!ENTITY namespaceTitle.XLink.label "XLink">
|
||||
<!ENTITY namespaceTitle.XSLT.label "XSTL">
|
||||
<!ENTITY namespaceTitle.XBL.label "XBL">
|
||||
<!ENTITY namespaceTitle.MathML.label "MathML">
|
||||
<!ENTITY namespaceTitle.RDF.label "RDF">
|
||||
<!ENTITY namespaceTitle.XUL.label "XUL">
|
||||
<!ENTITY namespaceTitle.SVG.label "SVG">
|
||||
<!ENTITY namespaceTitle.XMLEvents.label "XML Events">
|
||||
<!ENTITY namespaceTitle.WAIRoles.label "WAI Roles">
|
||||
<!ENTITY namespaceTitle.WAIProperties.label "WAI Properties">
|
||||
<!ENTITY namespaceTitle.custom.label "Custom">
|
||||
|
|
Загрузка…
Ссылка в новой задаче