Add line-wrapping capability to the view source window. Bug 22022,

r=bzbarsky, sr=alecf
This commit is contained in:
bzbarsky%mit.edu 2001-09-12 20:16:32 +00:00
parent 13345e3c8b
commit 995b971f09
4 changed files with 56 additions and 0 deletions

View File

@ -142,6 +142,7 @@ pref("browser.forms.submit.backwards_compatible", true);
// view source
pref("view_source.syntax_highlight", true);
pref("view_source.wrap_long_lines", false);
// gfx widgets
pref("nglayout.widget.mode", 2);

View File

@ -64,6 +64,9 @@
<commandset id="globalEditMenuItems"/>
<commandset id="selectEditMenuItems"/>
<commandset id="clipboardEditMenuItems"/>
<commandset id="viewSourceMenuItems">
<command id="cmdWrapLongLines" oncommand="wrapLongLines()"/>
</commandset>
</commandset>
<stringbundleset id="stringbundleset">
@ -144,6 +147,7 @@
<!-- <menuitem accesskey="&pageInfoCmd.accesskey;" label="&pageInfoCmd.label;" key="key_viewInfo" observes="View:PageInfo"/>
<menuseparator id="file_moduleSeparator"/>-->
<menu id = "charsetMenu"/>
<menuitem id="menu_wrapLongLines" label="&menu_wrapLongLines.title;" type="checkbox" command="cmdWrapLongLines"/>
</menupopup>
</menu>

View File

@ -22,6 +22,16 @@
var gBrowser = null;
var appCore = null;
var gPrefs = null;
try {
var prefsService = Components.classes["@mozilla.org/preferences;1"];
if (prefsService)
prefsService = prefsService.getService();
if (prefsService)
var gPrefs = prefsService.QueryInterface(Components.interfaces.nsIPref);
} catch (ex) {
}
function onLoadViewSource()
{
@ -68,6 +78,18 @@ function viewSource(url)
var loadFlags = Components.interfaces.nsIWebNavigation.LOAD_FLAGS_NONE;
var viewSrcUrl = "view-source:" + url;
getBrowser().webNavigation.loadURI(viewSrcUrl, loadFlags);
//check the view_source.wrap_long_lines pref and set the menuitem's checked attribute accordingly
if (gPrefs){
try {
var wraplonglinesPrefValue = gPrefs.GetBoolPref("view_source.wrap_long_lines");
if (wraplonglinesPrefValue)
document.getElementById('menu_wrapLongLines').setAttribute("checked", "true");
} catch (ex) {
}
}
window._content.focus();
return true;
}
@ -84,3 +106,30 @@ function ViewSourceEditPage()
url = url.substring(12,url.length);
editPage(url,window, false);
}
//function to toggle long-line wrapping and set the view_source.wrap_long_lines
//pref to persist the last state
function wrapLongLines()
{
//get the first pre tag which surrounds the entire viewsource content
var myWrap = window._content.document.getElementById('viewsource');
if (myWrap.className == '')
myWrap.className = 'wrap';
else myWrap.className = '';
//since multiple viewsource windows are possible, another window could have
//affected the pref, so instead of determining the new pref value via the current
//pref value, we use myWrap.className
if (gPrefs){
try {
if (myWrap.className == ''){
gPrefs.SetBoolPref("view_source.wrap_long_lines", false);
}
else {
gPrefs.SetBoolPref("view_source.wrap_long_lines", true);
}
} catch (ex) {
}
}
}

View File

@ -7,3 +7,5 @@
<!-- LOCALIZATION NOTE (mainWindow.titlemodifierseperator) : DONT_TRANSLATE -->
<!ENTITY mainWindow.titlemodifierseperator " - ">
<!ENTITY mainWindow.preface "Source of: ">
<!ENTITY menu_wrapLongLines.title "Wrap Long Lines">