525
edits
| Line 65: | Line 65: | ||
= Creating Folders = | = Creating Folders = | ||
Normally, creating folders is no big hassle. You just use <code>PlacesCreateFolderTransaction</code>. For pasting, the <code>PlacesController</code> does something a little special. Since the user may be pasting in a nested folder structure, when it creates the set of CreateTransactions for the insert operation, there is a problem: the insertion is two-pass. The first pass generates a list of transactions for the insertion, and the second pass is the execution of the transactions using <code>doTransaction</code>. The problem is that all the CreateTransactions take the insertion container as a parameter to the constructor, but the folder the items are being inserted into hasn't been created yet for nested contents! | Normally, creating folders is no big hassle. You just use <code>PlacesCreateFolderTransaction</code>: | ||
<pre> | |||
var bms = | |||
Cc["@mozilla.org/browser/nav-bookmarks-service;1"]. | |||
getService(Ci.nsINavBookmarksService); | |||
var createTxn = | |||
new PlacesCreateFolderTransaction("Something", bms.toolbarRoot, -1); | |||
PlacesController.tm.doTransaction(createTxn); | |||
</pre> | |||
For pasting, the <code>PlacesController</code> does something a little special. Since the user may be pasting in a nested folder structure, when it creates the set of CreateTransactions for the insert operation, there is a problem: the insertion is two-pass. The first pass generates a list of transactions for the insertion, and the second pass is the execution of the transactions using <code>doTransaction</code>. The problem is that all the CreateTransactions take the insertion container as a parameter to the constructor, but the folder the items are being inserted into hasn't been created yet for nested contents! | |||
The solution is that on CreateTransactions, the <code>container</code> property is a public field, and that every pasted folder creates its own list of CreateTransactions to create child items. | The solution is that on CreateTransactions, the <code>container</code> property is a public field, and that every pasted folder creates its own list of CreateTransactions to create child items. | ||
edits