B2G/gecko/browser/components/places/src/PlacesUIUtils.jsm
/**
   * Gets a transaction for copying (recursively nesting to include children)
   * a folder (or container) and its contents from one folder to another.
   *
   * @param   aData
   *          Unwrapped dropped folder data - Obj containing folder and children
   * @param   aContainer
   *          The container we are copying into
   * @param   aIndex
   *          The index in the destination container to insert the new items
   * @return A nsITransaction object that will perform the copy.
   *
   * @note Since a copy creates a completely new item, only some internal
   *       annotations are synced from the old one.
   * @see this._copyableAnnotations for the list of copyable annotations.
   */
Gets a transaction for copying (recursively nesting to include children)
a folder (or container) and its contents from one folder to another.

@param   aData
Unwrapped dropped folder data - Obj containing folder and children
@param   aContainer
The container we are copying into
@param   aIndex
The index in the destination container to insert the new items
@return A nsITransaction object that will perform the copy.

@note Since a copy creates a completely new item, only some internal
annotations are synced from the old one.
@see this._copyableAnnotations for the list of copyable annotations.
Gets a transaction for copying ( recursively nesting to include children ) a folder ( or container ) and its contents from one folder to another . @param aData Unwrapped dropped folder data - Obj containing folder and children @param aContainer The container we are copying into @param aIndex The index in the destination container to insert the new items @return A nsITransaction object that will perform the copy . @note Since a copy creates a completely new item only some internal annotations are synced from the old one . @see this . _copyableAnnotations for the list of copyable annotations .
function PUIU__getFolderCopyTransaction(aData, aContainer, aIndex)
  {
    function getChildItemsTransactions(aChildren)
    {
      let transactions = [];
      let index = aIndex;
      aChildren.forEach(function (node, i) {
        if (aIndex != PlacesUtils.bookmarks.DEFAULT_INDEX) {
          index = i;
        }
        if (node.type == PlacesUtils.TYPE_X_MOZ_PLACE_CONTAINER) {
          if (node.livemark && node.annos) {
            transactions.push(
              PlacesUIUtils._getLivemarkCopyTransaction(node, aContainer, index)
            );
          }
          else {
            transactions.push(
              PlacesUIUtils._getFolderCopyTransaction(node, aContainer, index)
            );
          }
        }
        else if (node.type == PlacesUtils.TYPE_X_MOZ_PLACE_SEPARATOR) {
          transactions.push(new PlacesCreateSeparatorTransaction(-1, index));
        }
        else if (node.type == PlacesUtils.TYPE_X_MOZ_PLACE) {
          transactions.push(
            PlacesUIUtils._getURIItemCopyTransaction(node, -1, index)
          );
        }
        else {
          throw new Error("Unexpected item under a bookmarks folder");
        }
      });
      return transactions;
    }
    if (aContainer == PlacesUtils.tagsFolderId) { 
      let transactions = [];
      if (aData.children) {
        aData.children.forEach(function(aChild) {
          transactions.push(
            new PlacesTagURITransaction(PlacesUtils._uri(aChild.uri),
                                        [aData.title])
          );
        });
      }
      return new PlacesAggregatedTransaction("addTags", transactions);
    }
    if (aData.livemark && aData.annos) { 
      return this._getLivemarkCopyTransaction(aData, aContainer, aIndex);
    }
    let transactions = getChildItemsTransactions(aData.children);
    if (aData.dateAdded) {
      transactions.push(
        new PlacesEditItemDateAddedTransaction(null, aData.dateAdded)
      );
    }
    if (aData.lastModified) {
      transactions.push(
        new PlacesEditItemLastModifiedTransaction(null, aData.lastModified)
      );
    }
    let annos = [];
    if (aData.annos) {
      annos = aData.annos.filter(function (aAnno) {
        return this._copyableAnnotations.indexOf(aAnno.name) != -1;
      }, this);
    }
    return new PlacesCreateFolderTransaction(aData.title, aContainer, aIndex,
                                             annos, transactions);
  }
function PUIU__getFolderCopyTransaction ( aData , aContainer , aIndex ) { function getChildItemsTransactions ( aChildren ) { let transactions = [ ] ; let index = aIndex ; aChildren . forEach ( function ( node , i ) { if ( aIndex != PlacesUtils . bookmarks . DEFAULT_INDEX ) { index = i ; } if ( node . type == PlacesUtils . TYPE_X_MOZ_PLACE_CONTAINER ) { if ( node . livemark && node . annos ) { transactions . push ( PlacesUIUtils . _getLivemarkCopyTransaction ( node , aContainer , index ) ) ; } else { transactions . push ( PlacesUIUtils . _getFolderCopyTransaction ( node , aContainer , index ) ) ; } } else if ( node . type == PlacesUtils . TYPE_X_MOZ_PLACE_SEPARATOR ) { transactions . push ( new PlacesCreateSeparatorTransaction ( - 1 , index ) ) ; } else if ( node . type == PlacesUtils . TYPE_X_MOZ_PLACE ) { transactions . push ( PlacesUIUtils . _getURIItemCopyTransaction ( node , - 1 , index ) ) ; } else { throw new Error ( "Unexpected item under a bookmarks folder" ) ; } } ) ; return transactions ; } if ( aContainer == PlacesUtils . tagsFolderId ) { let transactions = [ ] ; if ( aData . children ) { aData . children . forEach ( function ( aChild ) { transactions . push ( new PlacesTagURITransaction ( PlacesUtils . _uri ( aChild . uri ) , [ aData . title ] ) ) ; } ) ; } return new PlacesAggregatedTransaction ( "addTags" , transactions ) ; } if ( aData . livemark && aData . annos ) { return this . _getLivemarkCopyTransaction ( aData , aContainer , aIndex ) ; } let transactions = getChildItemsTransactions ( aData . children ) ; if ( aData . dateAdded ) { transactions . push ( new PlacesEditItemDateAddedTransaction ( null , aData . dateAdded ) ) ; } if ( aData . lastModified ) { transactions . push ( new PlacesEditItemLastModifiedTransaction ( null , aData . lastModified ) ) ; } let annos = [ ] ; if ( aData . annos ) { annos = aData . annos . filter ( function ( aAnno ) { return this . _copyableAnnotations . indexOf ( aAnno . name ) != - 1 ; } , this ) ; } return new PlacesCreateFolderTransaction ( aData . title , aContainer , aIndex , annos , transactions ) ; }
Gets a transaction for copying (recursively nesting to include children)
 a folder (or container) and its contents from one folder to another.
Gets a transaction for copying ( recursively nesting to include children ) a folder ( or container ) and its contents from one folder to another .
// Make sure that items are given the correct index, this will be // passed by the transaction manager to the backend for the insertion. // Insertion behaves differently for DEFAULT_INDEX (append). // Copying a tag folder. // Copying a livemark.