Bug 1614235 - View source: fix line wrapping option, remove pointless menu items. r=mkmelin DONTBUILD
authorGeoff Lankow <geoff@darktrojan.net>
Wed, 19 Feb 2020 12:56:31 +1300
changeset 37392 231dc57f37045ab32c675e43a8058438d211129d
parent 37391 9fb8ea5699c1c8c1d97084a109b395df11a44d71
child 37393 228fc7494fb8fe326384b10edf58b529d260b19d
push id2566
push userclokep@gmail.com
push dateMon, 09 Mar 2020 19:20:31 +0000
treeherdercomm-beta@a352facfa0a4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkmelin
bugs1614235
Bug 1614235 - View source: fix line wrapping option, remove pointless menu items. r=mkmelin DONTBUILD
common/src/viewSource.js
common/src/viewSource.xhtml
--- a/common/src/viewSource.js
+++ b/common/src/viewSource.js
@@ -17,28 +17,42 @@ addEventListener("load", () => {
   gBrowser.addEventListener("DOMTitleChanged", () => {
     document.title =
       document.documentElement.getAttribute("titlepreface") +
       gBrowser.contentDocument.title +
       document.documentElement.getAttribute("titlemenuseparator") +
       document.documentElement.getAttribute("titlemodifier");
   });
 
+  if (Services.prefs.getBoolPref("view_source.wrap_long_lines", false)) {
+    document.getElementById("cmd_wrapLongLines").setAttribute("checked", "true");
+  }
+
   gViewSourceUtils.viewSourceInBrowser({
     ...window.arguments[0],
     viewSourceBrowser: gBrowser,
   });
 });
 
 var viewSourceChrome = {
   promptAndGoToLine() {
     let actor = gViewSourceUtils.getViewSourceActor(gBrowser.browsingContext);
     actor.manager.getActor("ViewSourcePage").promptAndGoToLine();
   },
 
+  toggleWrapping() {
+    let state = gBrowser.contentDocument.body.classList.toggle("wrap");
+    if (state) {
+      document.getElementById("cmd_wrapLongLines").setAttribute("checked", "true");
+    } else {
+      document.getElementById("cmd_wrapLongLines").removeAttribute("checked");
+    }
+    Services.prefs.setBoolPref("view_source.wrap_long_lines", state);
+  },
+
   /**
    * Called by clicks on a menu populated by CharsetMenu.jsm to
    * change the selected character set.
    *
    * @param event
    *        The click event on a character set menuitem.
    */
   onSetCharacterSet(event) {
@@ -92,17 +106,17 @@ var PrintPreviewListener = {
     return this._ppBrowser;
   },
 
   getSourceBrowser() {
     return gBrowser;
   },
 
   getNavToolbox() {
-    return document.getElementById("navigator-toolbox");
+    return document.getElementById("toolbar-placeholder");
   },
 
   onEnter() {
     let toolbox = document.getElementById("viewSource-toolbox");
     toolbox.hidden = true;
     gBrowser.collapsed = true;
   },
 
--- a/common/src/viewSource.xhtml
+++ b/common/src/viewSource.xhtml
@@ -62,19 +62,19 @@
   <command id="cmd_findPrevious"
            oncommand="document.getElementById('FindToolbar').onFindAgainCommand(true);"/>
 #ifdef XP_MACOSX
   <command id="cmd_findSelection"
            oncommand="document.getElementById('FindToolbar').onFindSelectionCommand();"/>
 #endif
   <command id="cmd_reload" oncommand="viewSourceChrome.reload();"/>
   <command id="cmd_goToLine" oncommand="viewSourceChrome.promptAndGoToLine();"/>
+  <command id="cmd_wrapLongLines" oncommand="viewSourceChrome.toggleWrapping();"/>
 #ifdef MOZ_SUITE
   <command id="cmd_highlightSyntax" oncommand="viewSourceChrome.toggleSyntaxHighlighting();"/>
-  <command id="cmd_wrapLongLines" oncommand="viewSourceChrome.toggleWrapping();"/>
   <command id="Browser:Back" oncommand="viewSourceChrome.goBack()" class="viewSourceNavigation"/>
   <command id="Browser:Forward" oncommand="viewSourceChrome.goForward()" class="viewSourceNavigation"/>
 #endif
   <command id="cmd_textZoomReduce" oncommand="ZoomManager.reduce();"/>
   <command id="cmd_textZoomEnlarge" oncommand="ZoomManager.enlarge();"/>
   <command id="cmd_textZoomReset" oncommand="ZoomManager.reset();"/>
 
 #includesubst @TOOLKIT_DIR@/content/editMenuKeys.inc.xhtml
@@ -142,48 +142,56 @@
               observes="viewSourceNavigation"/>
     <menuitem id="context-forward"
               label="&forwardCmd.label;"
               accesskey="&forwardCmd.accesskey;"
               command="Browser:Forward"
               observes="viewSourceNavigation"/>
     <menuseparator observes="viewSourceNavigation"/>
 #endif
-    <menuitem id="cMenu_findAgain"
-              label="&findAgainCmd.label;"
-              accesskey="&findAgainCmd.accesskey;"
-              command="cmd_findAgain"/>
-    <menuseparator/>
     <menuitem id="cMenu_copy"
               data-l10n-id="text-action-copy"
               command="cmd_copy"/>
+    <menuseparator/>
+#ifdef MOZ_SUITE
     <menuitem id="context-copyLink"
               label="&copyLinkCmd.label;"
               accesskey="&copyLinkCmd.accesskey;"
               oncommand="viewSourceChrome.onContextMenuCopyLinkOrEmail();"/>
     <menuitem id="context-copyEmail"
               label="&copyEmailCmd.label;"
               accesskey="&copyEmailCmd.accesskey;"
               oncommand="viewSourceChrome.onContextMenuCopyLinkOrEmail();"/>
     <menuseparator/>
+#endif
     <menuitem id="cMenu_selectAll"
               data-l10n-id="text-action-select-all"
               command="cmd_selectAll"/>
+    <menuseparator/>
+    <menuitem id="cMenu_find"
+              label="&findCmd.label;"
+              accesskey="&findCmd.accesskey;"
+              command="cmd_find"/>
+    <menuitem id="cMenu_findAgain"
+              label="&findAgainCmd.label;"
+              accesskey="&findAgainCmd.accesskey;"
+              command="cmd_findAgain"/>
   </menupopup>
 
   <!-- Menu -->
   <toolbox id="viewSource-toolbox">
     <toolbar type="menubar">
     <menubar id="viewSource-main-menubar">
 
       <menu id="menu_file" label="&fileMenu.label;" accesskey="&fileMenu.accesskey;">
         <menupopup id="menu_FilePopup">
           <menuitem key="key_savePage" command="cmd_savePage" id="menu_savePage"
                     label="&savePageCmd.label;" accesskey="&savePageCmd.accesskey;"
                     class="menuitem-iconic"/>
+          <menuseparator/>
           <menuitem command="cmd_pagesetup" id="menu_pageSetup"
                     label="&pageSetupCmd.label;" accesskey="&pageSetupCmd.accesskey;"/>
 #ifndef XP_MACOSX
           <menuitem command="cmd_printpreview" id="menu_printPreview"
                     label="&printPreviewCmd.label;" accesskey="&printPreviewCmd.accesskey;"
                     class="menuitem-iconic"/>
 #endif
           <menuitem key="key_print" command="cmd_print" id="menu_print"
@@ -194,47 +202,21 @@
                     label="&closeCmd.label;" accesskey="&closeCmd.accesskey;"
                     class="menuitem-iconic"/>
         </menupopup>
       </menu>
 
       <menu id="menu_edit" label="&editMenu.label;"
             accesskey="&editMenu.accesskey;">
         <menupopup id="editmenu-popup">
-          <menuitem id="menu_undo"
-                    data-l10n-id="text-action-undo"
-                    key="key_undo"
-                    command="cmd_undo"
-                    class="menuitem-iconic"/>
-          <menuitem id="menu_redo"
-                    data-l10n-id="text-action-redo"
-                    key="key_redo"
-                    command="cmd_redo"
-                    class="menuitem-iconic"/>
-          <menuseparator/>
-          <menuitem id="menu_cut"
-                    data-l10n-id="text-action-cut"
-                    key="key_cut"
-                    command="cmd_cut"
-                    class="menuitem-iconic"/>
           <menuitem id="menu_copy"
                     data-l10n-id="text-action-copy"
                     key="key_copy"
                     command="cmd_copy"
                     class="menuitem-iconic"/>
-          <menuitem id="menu_paste"
-                    data-l10n-id="text-action-paste"
-                    key="key_paste"
-                    command="cmd_paste"
-                    class="menuitem-iconic"/>
-          <menuitem id="menu_delete"
-                    data-l10n-id="text-action-delete"
-                    key="key_delete"
-                    command="cmd_delete"
-                    class="menuitem-iconic"/>
           <menuseparator/>
           <menuitem id="menu_selectAll"
                     data-l10n-id="text-action-select-all"
                     key="key_selectAll"
                     command="cmd_selectAll"/>
           <menuseparator/>
           <menuitem id="menu_find" label="&findCmd.label;"
                     key="key_find" accesskey="&findCmd.accesskey;"
@@ -271,20 +253,20 @@
           <!-- Charset Menu -->
           <menu id="charsetMenu"
                 data-l10n-id="menu-view-charset"
                 oncommand="viewSourceChrome.onSetCharacterSet(event);"
                 onpopupshowing="CharsetMenu.build(event.target);
                                 CharsetMenu.update(event.target, content.document.characterSet);">
             <menupopup/>
           </menu>
-#ifdef MOZ_SUITE
           <menuseparator/>
           <menuitem id="menu_wrapLongLines" type="checkbox" command="cmd_wrapLongLines"
                     label="&menu_wrapLongLines.title;" accesskey="&menu_wrapLongLines.accesskey;"/>
+#ifdef MOZ_SUITE
           <menuitem type="checkbox" id="menu_highlightSyntax" command="cmd_highlightSyntax"
                     label="&menu_highlightSyntax.label;" accesskey="&menu_highlightSyntax.accesskey;"/>
 #endif
         </menupopup>
       </menu>
 #ifndef MOZ_SUITE
       <menu id="helpMenu"
 #ifdef XP_WIN