Bug 472343 (part 2) - Make Places views aware of batches.

r=dietrich sr=vlad a=blocking
This commit is contained in:
Marco Bonardo 2010-11-12 22:20:00 +01:00
Родитель 7f06b80894
Коммит 865d1cfcb3
5 изменённых файлов: 65 добавлений и 1 удалений

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

@ -567,6 +567,7 @@ PlacesViewBase.prototype = {
nodeLastModifiedChanged: function() { },
nodeKeywordChanged: function() { },
sortingChanged: function() { },
batching: function() { },
// Replaced by containerStateChanged.
containerOpened: function() { },
containerClosed: function() { },

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

@ -1012,6 +1012,24 @@ PlacesTreeView.prototype = {
}
},
_inBatchMode: false,
batching: function PTV__batching(aToggleMode) {
if (aToggleMode) {
this._inBatchMode = true;
if (this.selection) {
this.selection.selectEventsSuppressed = true;
}
this._tree.beginUpdateBatch();
}
else if (this._inBatchMode){
this._inBatchMode = false;
if (this.selection) {
this.selection.selectEventsSuppressed = false;
}
this._tree.endUpdateBatch();
}
},
get result() this._result,
set result(val) {
if (this._result) {

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

@ -460,7 +460,7 @@ interface nsINavHistoryQueryResultNode : nsINavHistoryContainerResultNode
* according to history and bookmark system events. Register this observer on a
* result using nsINavHistoryResult::addObserver.
*/
[scriptable, uuid(d746da3c-f698-48bc-ad73-2d428b23b0c6)]
[scriptable, uuid(9ea86387-6a30-4ee2-b70d-26fbb718902f)]
interface nsINavHistoryResultObserver : nsISupports
{
/**
@ -678,6 +678,17 @@ interface nsINavHistoryResultObserver : nsISupports
*/
void sortingChanged(in unsigned short sortingMode);
/**
* This is called to indicate that a batch operation is about to start or end.
* The observer could want to disable some events or updates during batches,
* since multiple operations are packed in a short time.
* For example treeviews could temporarily suppress select notifications.
*
* @param aToggleMode
* true if a batch is starting, false if it's ending.
*/
void batching(in boolean aToggleMode);
/**
* Called by the result when this observer is added.
*/

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

@ -4529,6 +4529,12 @@ nsNavHistoryResult::AddObserver(nsINavHistoryResultObserver* aObserver,
rv = aObserver->SetResult(this);
NS_ENSURE_SUCCESS(rv, rv);
// If we are batching, notify a fake batch start to the observers.
// Not doing so would then notify a not coupled batch end.
if (mBatchInProgress) {
NOTIFY_RESULT_OBSERVERS(this, Batching(PR_TRUE));
}
return NS_OK;
}
@ -4621,6 +4627,9 @@ nsNavHistoryResult::OnBeginUpdateBatch()
mBatchInProgress = PR_TRUE;
ENUMERATE_HISTORY_OBSERVERS(OnBeginUpdateBatch());
ENUMERATE_ALL_BOOKMARKS_OBSERVERS(OnBeginUpdateBatch());
NOTIFY_RESULT_OBSERVERS(this, Batching(PR_TRUE));
return NS_OK;
}
@ -4637,6 +4646,7 @@ nsNavHistoryResult::OnEndUpdateBatch()
// than enqueued. Thus set it just before handling refreshes.
mBatchInProgress = PR_FALSE;
NOTIFY_REFRESH_PARTICIPANTS();
NOTIFY_RESULT_OBSERVERS(this, Batching(PR_FALSE));
}
else {
NS_WARNING("EndUpdateBatch without a begin");

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

@ -74,6 +74,8 @@ var resultObserver = {
this.removedNode = node;
},
nodeAnnotationChanged: function() {},
newTitle: "",
nodeChangedByTitle: null,
nodeTitleChanged: function(node, newTitle) {
@ -117,6 +119,10 @@ var resultObserver = {
sortingChanged: function(sortingMode) {
this.sortingMode = sortingMode;
},
inBatchMode: false,
batching: function(aToggleMode) {
this.inBatchMode = aToggleMode;
},
result: null,
reset: function() {
this.insertedNode = null;
@ -181,6 +187,15 @@ function run_test() {
do_check_eq(resultObserver.sortingMode, options.SORT_BY_TITLE_ASCENDING);
do_check_eq(resultObserver.invalidatedContainer, result.root);
// nsINavHistoryResultObserver.batching
do_check_false(resultObserver.inBatchMode);
histsvc.runInBatchMode({
runBatched: function (aUserData) {
do_check_true(resultObserver.inBatchMode);
}
}, null);
do_check_false(resultObserver.inBatchMode);
// nsINavHistoryResultObserver.containerClosed
root.containerOpen = false;
do_check_eq(resultObserver.closedContainer, resultObserver.openedContainer);
@ -242,6 +257,15 @@ function run_test() {
do_check_eq(resultObserver.sortingMode, options.SORT_BY_TITLE_ASCENDING);
do_check_eq(resultObserver.invalidatedContainer, result.root);
// nsINavHistoryResultObserver.batching
do_check_false(resultObserver.inBatchMode);
bmsvc.runInBatchMode({
runBatched: function (aUserData) {
do_check_true(resultObserver.inBatchMode);
}
}, null);
do_check_false(resultObserver.inBatchMode);
// nsINavHistoryResultObserver.containerClosed
root.containerOpen = false;
do_check_eq(resultObserver.closedContainer, resultObserver.openedContainer);