Bug 1415877 - Rework PlacesControllerDragHelper#onDrop and PlacesController#paste to make the transaction handling parts similar. r=mak

MozReview-Commit-ID: BInw5oT0Ja5

--HG--
extra : rebase_source : ff7d351f4bb251a0bb75670704f806102114394c
This commit is contained in:
Mark Banner 2017-11-08 12:02:30 +00:00
Родитель a518974a10
Коммит b71430bdda
1 изменённых файлов: 80 добавлений и 56 удалений

Просмотреть файл

@ -1314,12 +1314,11 @@ PlacesController.prototype = {
let itemsToSelect = []; let itemsToSelect = [];
if (PlacesUIUtils.useAsyncTransactions) { if (PlacesUIUtils.useAsyncTransactions) {
let transactions = [];
if (ip.isTag) { if (ip.isTag) {
let urls = items.filter(item => "uri" in item).map(item => Services.io.newURI(item.uri)); let urls = items.filter(item => "uri" in item).map(item => Services.io.newURI(item.uri));
await PlacesTransactions.Tag({ urls, tag: ip.tagName }).transact(); transactions.push(PlacesTransactions.Tag({ urls, tag: ip.tagName }));
} else { } else {
let transactions = [];
let insertionIndex = await ip.getIndex(); let insertionIndex = await ip.getIndex();
let doCopy = action == "copy"; let doCopy = action == "copy";
let newTransactions = await getTransactionsForTransferItems( let newTransactions = await getTransactionsForTransferItems(
@ -1327,7 +1326,7 @@ PlacesController.prototype = {
if (newTransactions.length) { if (newTransactions.length) {
transactions = [...transactions, ...newTransactions]; transactions = [...transactions, ...newTransactions];
} }
}
// Note: this._view may be a view or the tree element. // Note: this._view may be a view or the tree element.
let resultForBatching = getResultForBatching(this._view); let resultForBatching = getResultForBatching(this._view);
@ -1340,7 +1339,6 @@ PlacesController.prototype = {
} }
}); });
}); });
}
} else { } else {
let transactions = []; let transactions = [];
let insertionIndex = await ip.getIndex(); let insertionIndex = await ip.getIndex();
@ -1648,21 +1646,27 @@ var PlacesControllerDragHelper = {
dtItems.push({flavor, data}); dtItems.push({flavor, data});
} }
if (PlacesUIUtils.useAsyncTransactions) {
let nodes = [];
// TODO: When sync transactions are removed, merge the for loop here into the
// one above.
for (let {flavor, data} of dtItems) { for (let {flavor, data} of dtItems) {
let nodes;
if (flavor != TAB_DROP_TYPE) { if (flavor != TAB_DROP_TYPE) {
nodes = PlacesUtils.unwrapNodes(data, flavor); nodes = [...nodes, ...PlacesUtils.unwrapNodes(data, flavor)];
} else if (data instanceof XULElement && data.localName == "tab" && } else if (data instanceof XULElement && data.localName == "tab" &&
data.ownerGlobal.isChromeWindow) { data.ownerGlobal.isChromeWindow) {
let uri = data.linkedBrowser.currentURI; let uri = data.linkedBrowser.currentURI;
let spec = uri ? uri.spec : "about:blank"; let spec = uri ? uri.spec : "about:blank";
nodes = [{ uri: spec, nodes.push({
uri: spec,
title: data.label, title: data.label,
type: PlacesUtils.TYPE_X_MOZ_URL}]; type: PlacesUtils.TYPE_X_MOZ_URL
} else });
} else {
throw new Error("bogus data was passed as a tab"); throw new Error("bogus data was passed as a tab");
}
}
if (PlacesUIUtils.useAsyncTransactions) {
// If dragging over a tag container we should tag the item. // If dragging over a tag container we should tag the item.
if (insertionPoint.isTag) { if (insertionPoint.isTag) {
let urls = nodes.filter(item => "uri" in item).map(item => item.uri); let urls = nodes.filter(item => "uri" in item).map(item => item.uri);
@ -1675,7 +1679,33 @@ var PlacesControllerDragHelper = {
transactions = [...transactions, ...newTransactions]; transactions = [...transactions, ...newTransactions];
} }
} }
// Check if we actually have something to add, if we don't it probably wasn't
// valid, or it was moving to the same location, so just ignore it.
if (!transactions.length) {
return;
}
let resultForBatching = getResultForBatching(view);
await PlacesUIUtils.batchUpdatesForNode(resultForBatching,
transactions.length, async () => {
await PlacesTransactions.batch(transactions);
});
} else { } else {
for (let {flavor, data} of dtItems) {
let nodes;
if (flavor != TAB_DROP_TYPE) {
nodes = PlacesUtils.unwrapNodes(data, flavor);
} else if (data instanceof XULElement && data.localName == "tab" &&
data.ownerGlobal.isChromeWindow) {
let uri = data.linkedBrowser.currentURI;
let spec = uri ? uri.spec : "about:blank";
nodes = [{ uri: spec,
title: data.label,
type: PlacesUtils.TYPE_X_MOZ_URL}];
} else {
throw new Error("bogus data was passed as a tab");
}
let movedCount = 0; let movedCount = 0;
for (let unwrapped of nodes) { for (let unwrapped of nodes) {
let index = await insertionPoint.getIndex(); let index = await insertionPoint.getIndex();
@ -1718,23 +1748,17 @@ var PlacesControllerDragHelper = {
index, doCopy)); index, doCopy));
} }
} }
}
}
// Check if we actually have something to add, if we don't it probably wasn't // Check if we actually have something to add, if we don't it probably wasn't
// valid, or it was moving to the same location, so just ignore it. // valid, or it was moving to the same location, so just ignore it.
if (!transactions.length) { if (!transactions.length) {
return; return;
} }
if (PlacesUIUtils.useAsyncTransactions) {
let resultForBatching = getResultForBatching(view);
await PlacesUIUtils.batchUpdatesForNode(resultForBatching,
transactions.length, async () => {
await PlacesTransactions.batch(transactions);
});
} else {
let txn = new PlacesAggregatedTransaction("DropItems", transactions); let txn = new PlacesAggregatedTransaction("DropItems", transactions);
PlacesUtils.transactionManager.doTransaction(txn); PlacesUtils.transactionManager.doTransaction(txn);
} }
}
}, },
/** /**