зеркало из https://github.com/mozilla/pjs.git
Bug 72494 - DOM Inspector needs save option. r=timeless, sr=neil
This commit is contained in:
Родитель
ced7d5c422
Коммит
ecaa4be8e5
|
@ -15,6 +15,7 @@
|
|||
oncommand="inspector.gotoTypedURL()"/>
|
||||
|
||||
<command id="cmdShowOpenURLDialog" oncommand="inspector.showOpenURLDialog()"/>
|
||||
<command id="cmdSave" oncommand="inspector.save();"/>
|
||||
<command id="cmdClose" oncommand="inspector.exit();"/>
|
||||
|
||||
<command id="cmdShowPrefsDialog" oncommand="inspector.showPrefsDialog()"/>
|
||||
|
|
|
@ -50,9 +50,15 @@ var inspector;
|
|||
|
||||
const kClipboardHelperCID = "@mozilla.org/widget/clipboardhelper;1";
|
||||
const kPromptServiceCID = "@mozilla.org/embedcomp/prompt-service;1";
|
||||
const kFOStreamCID = "@mozilla.org/network/file-output-stream;1";
|
||||
const kEncoderCIDbase = "@mozilla.org/layout/documentEncoder;1?type=";
|
||||
const kSerializerCID = "@mozilla.org/xmlextras/xmlserializer;1";
|
||||
const nsIWebNavigation = Components.interfaces.nsIWebNavigation;
|
||||
const nsIDocShellTreeItem = Components.interfaces.nsIDocShellTreeItem;
|
||||
const nsIDocShell = Components.interfaces.nsIDocShell;
|
||||
const nsIFileOutputStream = Components.interfaces.nsIFileOutputStream;
|
||||
const nsIDocumentEncoder = Components.interfaces.nsIDocumentEncoder;
|
||||
const nsIDOMSerializer = Components.interfaces.nsIDOMSerializer;
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
|
@ -180,6 +186,8 @@ InspectorApp.prototype =
|
|||
document.title = docTitle + " - " +
|
||||
document.documentElement.getAttribute("title");
|
||||
}
|
||||
|
||||
this.updateCommand("cmdSave");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -188,6 +196,22 @@ InspectorApp.prototype =
|
|||
////////////////////////////////////////////////////////////////////////////
|
||||
//// UI Commands
|
||||
|
||||
updateCommand: function inspector_updateCommand(aCommand)
|
||||
{
|
||||
var command = document.getElementById(aCommand);
|
||||
|
||||
var disabled = false;
|
||||
switch (aCommand) {
|
||||
case "cmdSave":
|
||||
var doc = this.mDocPanel.subject;
|
||||
disabled = !((kEncoderCIDbase + doc.contentType) in Components.classes ||
|
||||
(kSerializerCID in Components.classes));
|
||||
break;
|
||||
}
|
||||
|
||||
command.setAttribute("disabled", disabled);
|
||||
},
|
||||
|
||||
doViewerCommand: function(aCommand)
|
||||
{
|
||||
this.mPanelSet.execCommand(aCommand);
|
||||
|
@ -234,6 +258,50 @@ InspectorApp.prototype =
|
|||
splitter.close();
|
||||
},
|
||||
|
||||
/**
|
||||
* Saves the current document state in the inspector.
|
||||
*/
|
||||
save: function save()
|
||||
{
|
||||
var picker = Components.classes["@mozilla.org/filepicker;1"]
|
||||
.createInstance(nsIFilePicker);
|
||||
var title = document.getElementById("mi-save").label;
|
||||
picker.init(window, title, picker.modeSave)
|
||||
picker.appendFilters(picker.filterHTML | picker.filterXML |
|
||||
picker.filterXUL);
|
||||
if (picker.show() == picker.returnCancel)
|
||||
return;
|
||||
|
||||
var fos = Components.classes[kFOStreamCID]
|
||||
.createInstance(nsIFileOutputStream);
|
||||
const flags = 0x02 | 0x08 | 0x20; // write, create, truncate
|
||||
|
||||
var doc = this.mDocPanel.subject;
|
||||
if ((kEncoderCIDbase + doc.contentType) in Components.classes) {
|
||||
// first we try to use the document encoder for that content type. If
|
||||
// that fails, we move on to the xml serializer.
|
||||
var encoder = Components.classes[kEncoderCIDbase + doc.contentType]
|
||||
.createInstance(nsIDocumentEncoder);
|
||||
encoder.init(doc, doc.contentType, encoder.OutputRaw);
|
||||
encoder.setCharset(doc.characterSet);
|
||||
fos.init(picker.file, flags, 0666, 0);
|
||||
try {
|
||||
encoder.encodeToStream(fos);
|
||||
} finally {
|
||||
fos.close();
|
||||
}
|
||||
} else {
|
||||
var serializer = Components.classes[kSerializerCID]
|
||||
.createInstance(nsIDOMSerializer);
|
||||
fos.init(picker.file, flags, 0666, 0);
|
||||
try {
|
||||
serializer.serializeToStream(doc, fos);
|
||||
} finally {
|
||||
fos.close();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
exit: function()
|
||||
{
|
||||
window.close();
|
||||
|
|
|
@ -76,6 +76,8 @@
|
|||
<commandset id="baseMenuCommandSet"/>
|
||||
|
||||
<keyset id="tasksKeys">
|
||||
<key id="key_saveInspector" key="&saveCmd.key;" command="cmdSave"
|
||||
modifiers="accel"/>
|
||||
<key id="key_closeInspector" key="&closeCmd.key;" command="cmdClose"
|
||||
modifiers="accel"/>
|
||||
<key id="key_quit"/>
|
||||
|
|
|
@ -28,6 +28,9 @@
|
|||
<menuitem label="&cmdShowOpenURLDialog.label;" accesskey="&cmdShowOpenURLDialog.accesskey;"
|
||||
observes="cmdShowOpenURLDialog"/>
|
||||
<menuseparator/>
|
||||
<menuitem label="&cmdSave.label;" accesskey="&cmdSave.accesskey;"
|
||||
observes="cmdSave" key="key_saveInspector" id="mi-save"/>
|
||||
<menuseparator/>
|
||||
<menuitem label="&cmdClose.label;" accesskey="&cmdClose.accesskey;"
|
||||
observes="cmdClose" key="key_closeInspector"/>
|
||||
</menupopup>
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
<!ENTITY mnInspectChromeDocument.accesskey "H">
|
||||
<!ENTITY cmdShowOpenURLDialog.label "Inspect a URL...">
|
||||
<!ENTITY cmdShowOpenURLDialog.accesskey "U">
|
||||
<!ENTITY cmdSave.label "Save DOM As...">
|
||||
<!ENTITY cmdSave.accesskey "S">
|
||||
<!ENTITY cmdClose.label "Close">
|
||||
<!ENTITY cmdClose.accesskey "C">
|
||||
<!ENTITY cmdExit.label "Exit">
|
||||
|
@ -62,4 +64,5 @@
|
|||
|
||||
<!ENTITY inspectNewWindow.label "Inspect in New Window">
|
||||
|
||||
<!ENTITY saveCmd.key "S">
|
||||
<!ENTITY closeCmd.key "W">
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
<!ENTITY mnInspectChromeDocument.accesskey "a">
|
||||
<!ENTITY cmdShowOpenURLDialog.label "Zbadaj URL...">
|
||||
<!ENTITY cmdShowOpenURLDialog.accesskey "u">
|
||||
<!ENTITY cmdSave.label "Zapisz DOM jako...">
|
||||
<!ENTITY cmdSave.accesskey "s">
|
||||
<!ENTITY cmdClose.label "Zamknij">
|
||||
<!ENTITY cmdClose.accesskey "Z">
|
||||
<!ENTITY cmdExit.label "Zakończ">
|
||||
|
@ -61,4 +63,5 @@
|
|||
|
||||
<!ENTITY inspectNewWindow.label "Zbadaj w nowym oknie">
|
||||
|
||||
<!ENTITY saveCmd.key "S">
|
||||
<!ENTITY closeCmd.key "W">
|
||||
|
|
Загрузка…
Ссылка в новой задаче