Commit a7d4222b authored by annie.sullivan%gmail.com's avatar annie.sullivan%gmail.com
Browse files

Adds menuitem for Open In Tabs.

Reorganizes code so that command/click handlers for toolbar/menu bindings can be attached by overlays.
r=ben@mozilla.org bug=327034
parent 18a82468
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -439,13 +439,18 @@
#else
  <menu id="bookmarksMenu" 
        label="&bookmarksMenu.label;" accesskey="&bookmarksMenu.accesskey;">
    <menupopup id="bookmarksMenuPopup" type="places" context="placesContext">
    <menupopup id="bookmarksMenuPopup"
               type="places"
               context="placesContext"
               openInTabs="children"
               oncommand="BookmarksMenu.onCommand(event);"
               onclick="BookmarksMenu.onClick(event);">
      <menuitem label="&addCurPageAsCmd.label;" 
                command="Browser:AddBookmarkAs" key="addBookmarkAsKb"/>
      <!-- XXXben - this should move to the end of the list -->
      <menuseparator builder="start"/>
      <menuseparator builder="end"/>
      <menuitem label="&manBookmarksCmd.label;" 
                command="Browser:ShowBookmarks" key="manBookmarkKb"/>
      <menuseparator builder="start"/>
    </menupopup>
  </menu>
#endif
+82 −0
Original line number Diff line number Diff line
@@ -6974,5 +6974,87 @@ var HistoryMenu = {
  },
};

/*
 * Functions for the Bookmarks Menu
 */
var BookmarksMenu = {
  /*
   * Handler for when an item in the bookmarks menu is clicked.
   * If the click is a middle-click, opens the item in a new tab
   * and closes the menu.  (Left-clicks are handled by the command handler)
   * @param event DOMEvent for the click
   */
  onClick: function BM_onClick(event) {
    if (event.button == 1) {
      PlacesController.mouseLoadURI(event);
      // Menus selected with middle click must be closed manually.
      var node = event.target;
      while (node && 
             (node.localName == "menu" || 
              node.localName == "menupopup")) {
        if (node.localName == "menupopup")
          node.hidePopup();
        
        node = node.parentNode;
      }
    }
  },
  
  /*
   * Handler for command event for an item in the bookmarks menu.
   * Opens the item.
   * @param event DOMEvent for the command
   */
  onCommand: function BM_onCommand(event) {
    PlacesController.mouseLoadURI(event);
  }
};

/*
 * Functions for the Bookmarks Toolbar
 */
var BookmarksToolbar = {  
  /*
   * Handler for click event for an item in the bookmarks toolbar.
   * Menus and submenus from the folder buttons bubble up to this handler.
   * Only handle middle-click; left-click is handled in the onCommand function.
   * When items are middle-clicked, open them in tabs.
   * If the click came through a menu, close the menu.
   * @param event DOMEvent for the click
   */
  onClick: function BT_onClick(event) {
    // Only handle middle-clicks.
    if (event.button != 1)
      return;
    
    PlacesController.openLinksInTabs();
    
    // If this event bubbled up from a menu or menuitem,
    // close the menus.
    if (event.target.localName == "menu" ||
        event.target.localName == "menuitem") {
      var node = event.target;
      while (node && 
             (node.localName == "menu" || 
              node.localName == "menupopup")) {
        if (node.localName == "menupopup")
          node.hidePopup();
        
        node = node.parentNode;
      }
    }
  },
  
  /*
   * Handler for command event for an item in the bookmarks toolbar.
   * Menus and submenus from the folder buttons bubble up to this handler.
   * Opens the item.
   * @param event DOMEvent for the command
   */
  onCommand: function BM_onCommand(event) {
    PlacesController.mouseLoadURI(event);
  }
};

#endif
+4 −1
Original line number Diff line number Diff line
@@ -273,7 +273,10 @@
      <toolbarbutton id="bookmarksBarShowPlaces"
                     oncommand="PlacesBrowserShim.showHistory()"/>
      <toolbaritem flex="1" id="personal-bookmarks" title="&bookmarksItem.title;">
         <hbox id="bookmarksBarContent" flex="1" context="placesContext"/>
         <hbox id="bookmarksBarContent" flex="1"
               context="placesContext"
               onclick="BookmarksToolbar.onClick(event);"
               oncommand="BookmarksToolbar.onCommand(event);"/>
      </toolbaritem>
      <toolbarbutton id="places-bookmark" 
                     label="&location.status.not_bookmarked;" 
+6 −1
Original line number Diff line number Diff line
  <commandset id="placesCommands" 
              commandupdater="true" events="focus,select,mousedown,click" 
              commandupdater="true" events="focus,select,mousedown,click,keypress" 
              oncommandupdate="PlacesController.onCommandUpdate()">
    <command id="placesCmd_find" label="&cmd.find.label;" accesskey="&cmd.find.accesskey;"
             oncommand="PlacesSearchBox.focus();"/>
@@ -45,8 +45,13 @@
    <commandset type="link">
    </commandset>
    <commandset type="container" readonly="true">
      <!-- The open:tabs command gets enabled/disabled based on the current 
           selection, and is used in the context menu for a node.  
           The open:tabsEnabled is always enabled, and is shown in bookmarks menus. -->
      <command id="placesCmd_open:tabs" label="&cmd.open_tabs.label;" accesskey="&cmd.open_tabs.accesskey;"
               oncommand="PlacesController.openLinksInTabs();"/>
      <command id="placesCmd_open:tabsEnabled" label="&cmd.open_tabs.label;" accesskey="&cmd.open_tabs.accesskey;"
               oncommand="PlacesController.openLinksInTabs();"/>
      <command id="placesCmd_groupby:site" 
               label="&cmd.groupby_site.label;" accesskey="&cmd.groupby_site.accesskey;"
               oncommand="PlacesController.groupBySite();"/>
+14 −1
Original line number Diff line number Diff line
@@ -632,6 +632,7 @@ var PlacesController = {
      this.nodeIsFolder(this._activeView.selectedNode);
    this._setEnabled("placesCmd_open:tabs", 
      singleFolderSelected || !hasSingleSelection);
    this._setEnabled("placesCmd_open:tabsEnabled", true); // Always on
    
    // Some views, like menupopups, destroy their result as they hide, but they
    // are still the "last-active" view. Don't barf. 
@@ -799,6 +800,8 @@ var PlacesController = {
    var node = this._activeView.selectedNode;
    if (this._activeView.hasSingleSelection && this.nodeIsFolder(node)) {
      asFolder(node);
      var wasOpen = node.containerOpen;
      node.containerOpen = true;
      var cc = node.childCount;
      for (var i = 0; i < cc; ++i) {
        var childNode = node.getChild(i);
@@ -806,6 +809,7 @@ var PlacesController = {
          this._activeView.browserWindow.openNewTabWith(childNode.uri,
              null, null);
      }
      node.containerOpen = wasOpen;
    }
    else {
      var nodes = this._activeView.getSelectionNodes();
@@ -1065,8 +1069,11 @@ var PlacesController = {
    var parent = node.parent;
    if (!parent || !this.nodeIsContainer(parent))
      return -1;
    var cc = asContainer(parent).childCount;
    var wasOpen = parent.containerOpen;
    parent.containerOpen = true;
    var cc = parent.childCount;
    for (var i = 0; i < cc && asContainer(parent).getChild(i) != node; ++i);
    parent.containerOpen = wasOpen;
    return i < cc ? i : -1;
  },
  
@@ -1195,6 +1202,8 @@ var PlacesController = {
    
      // Get the folder's children
      var kids = self.getFolderContents(folderId, false, false);
      var wasOpen = kids.containerOpen;
      kids.containerOpen = true;
      var cc = kids.childCount;
      for (var i = 0; i < cc; ++i) {
        var node = kids.getChild(i);
@@ -1206,6 +1215,7 @@ var PlacesController = {
                                                         index));
        }
      }
      kids.containerOpen = wasOpen;
    }
    createTransactions(data.folderId, container, index);
    return new PlacesAggregateTransaction("FolderCopy", transactions);
@@ -1800,6 +1810,9 @@ PlacesRemoveFolderTransaction.prototype = {
   */
  _saveFolderContents: function PRFT__saveFolderContents(id, parent) {
    var contents = PlacesController.getFolderContents(id, false, false);
    // Container open status doesn't need to be reset to what it was before
    // because it's being deleted.
    contents.containerOpen = true;
    for (var i = contents.childCount - 1; i >= 0; --i) {
      var child = contents.getChild(i);
      var obj = null;
Loading