PlacesUtils.jsmにあるコンストラクタ
//纏め
PlacesAggregatedTransaction
//作成
PlacesCreateFolderTransaction
PlacesCreateBookmarkTransaction
PlacesCreateSeparatorTransaction
PlacesCreateLivemarkTransaction
//移動と削除
PlacesMoveItemTransaction
PlacesRemoveItemTransaction
//編集
PlacesEditItemTitleTransaction
PlacesEditBookmarkURITransaction
PlacesSetItemAnnotationTransaction
PlacesSetPageAnnotationTransaction
PlacesEditBookmarkKeywordTransaction
PlacesEditBookmarkPostDataTransaction
PlacesEditItemDateAddedTransaction
PlacesEditItemLastModifiedTransaction
//その他
PlacesSortFolderByNameTransaction
PlacesTagURITransaction
PlacesUntagURITransaction 

ブックマークの作成

var aURI, aParentId, aTitle, aKeyword, aDescription;
 
Cu.import("resource://gre/modules/PlacesUtils.jsm");
Cu.import("resource:///modules/PlacesUIUtils.jsm");
// ブックマークに付けるアノテーションのトランザクション
var childTxns = [];
var annoObj = { name  : PlacesUIUtils.DESCRIPTION_ANNO,
                value : aDescription };
var annoTxn = new PlacesSetItemAnnotationTransaction(-1, annoObj);
childTxns.push(annoTxn);
// ブックマーク作成のトランザクション
var txn = new PlacesCreateBookmarkTransaction(aURI, aParentId,
    PlacesUtils.bookmarks.DEFAULT_INDEX, aTitle, aKeyword, null, childTxns);
// 実行
PlacesUtils.transactionManager.doTransaction(txn); 
aURI は nsIURI

フォルダの作成(一緒にブックマークも)

var aTitle, aParentId (, aBmURI, aBmTitle);
 
Cu.import("resource://gre/modules/PlacesUtils.jsm");
// フォルダ内にブックマークも一緒に作成するなら
var childTxns = [];
var bmTxn = new PlacesCreateBookmarkTransaction(aBmURI, -1,
    PlacesUtils.bookmarks.DEFAULT_INDEX, aBmTitle);    // aKeywordやaDescriptionはここでは省略
childTxns.push(bmTxn);
// フォルダ作成のトランザクション
var txn = new PlacesCreateFolderTransaction(aTitle, aParentId,
    PlacesUtils.bookmarks.DEFAULT_INDEX, null, childTxns);
// 実行
PlacesUtils.transactionManager.doTransaction(txn); 

複数のトランザクションの纏め

var aTransactions;
 
Cu.import("resource://gre/modules/PlacesUtils.jsm");
var txn = new PlacesAggregatedTransaction("Create AggregatedTxn", aTransactions);
// 実行
PlacesUtils.transactionManager.doTransaction(txn); 
aTransactions は複数のトランザクションからなる配列

タグ:

+ タグ編集
  • タグ:

このサイトはreCAPTCHAによって保護されており、Googleの プライバシーポリシー利用規約 が適用されます。

最終更新:2015年08月04日 17:38