Bug 1822224 - fix reorderering newsgroups by drag and drop. r=BenC

Differential Revision: https://phabricator.services.mozilla.com/D178613

--HG--
extra : rebase_source : 2f9979ec6cf745647385dd617577abc4474d890a
extra : amend_source : 9e9828afc2e853286e8934fa9f2bb3f1c84e0489
extra : absorb_source : 96231c324610eef78ae4b576e8426498e33c7b4d
This commit is contained in:
Magnus Melin 2023-05-23 19:23:07 +10:00
Родитель 8c829bdbfb
Коммит 5cf5b72b2f
3 изменённых файлов: 45 добавлений и 37 удалений

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

@ -2018,11 +2018,15 @@ var folderPane = {
}
let folder = MailServices.folderLookup.getFolderForURL(row.uri);
if (!folder || folder.isServer || folder.server.type == "nntp") {
// TODO: Fix NNTP group reordering and enable. Bug 1822224.
if (!folder || folder.isServer) {
event.preventDefault();
return;
}
if (folder.server.type == "nntp") {
event.dataTransfer.mozSetDataAt("text/x-moz-newsfolder", folder, 0);
event.dataTransfer.effectAllowed = "move";
return;
}
event.dataTransfer.mozSetDataAt("text/x-moz-folder", folder, 0);
event.dataTransfer.effectAllowed = "copyMove";
@ -2114,12 +2118,20 @@ var folderPane = {
}
}
event.dataTransfer.dropEffect = "copy";
} else {
return;
} else if (types.includes("text/x-moz-newsfolder")) {
let folder = event.dataTransfer
.mozGetDataAt("text/x-moz-newsfolder", 0)
.QueryInterface(Ci.nsIMsgFolder);
if (
targetFolder.isServer ||
targetFolder.server.type != "nntp" ||
folder == targetFolder ||
folder.server != targetFolder.server
) {
return;
}
event.dataTransfer.dropEffect = "move";
}
this._clearDropTarget();
row.classList.add("drop-target");
},
/**
@ -2230,6 +2242,19 @@ var folderPane = {
);
}
}
} else if (types.includes("text/x-moz-newsfolder")) {
let folder = event.dataTransfer
.mozGetDataAt("text/x-moz-newsfolder", 0)
.QueryInterface(Ci.nsIMsgFolder);
let mode = row.closest("li[data-mode]").dataset.mode;
let newsRoot = targetFolder.rootFolder.QueryInterface(
Ci.nsIMsgNewsFolder
);
newsRoot.reorderGroup(folder, targetFolder);
setTimeout(
() => (folderTree.selectedRow = this.getRowForFolder(folder, mode))
);
}
event.preventDefault();

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

@ -88,7 +88,7 @@ interface nsIMsgNewsFolder : nsISupports {
void forgetAuthenticationCredentials();
/// @}
void moveFolder(in nsIMsgFolder aNewsgroupToMove, in nsIMsgFolder aRefNewsgroup, in int32_t aOrientation);
void reorderGroup(in nsIMsgFolder aNewsgroupToMove, in nsIMsgFolder aRefNewsgroup);
nsIMsgFolder addNewsgroup(in AUTF8String newsgroupName, in ACString setStr);

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

@ -1159,11 +1159,8 @@ NS_IMETHODIMP nsMsgNewsFolder::ForgetAuthenticationCredentials() {
}
// change order of subfolders (newsgroups)
// aOrientation = -1 ... aNewsgroupToMove aRefNewsgroup ...
// aOrientation = 1 ... aRefNewsgroup aNewsgroupToMove ...
NS_IMETHODIMP nsMsgNewsFolder::MoveFolder(nsIMsgFolder* aNewsgroupToMove,
nsIMsgFolder* aRefNewsgroup,
int32_t aOrientation) {
NS_IMETHODIMP nsMsgNewsFolder::ReorderGroup(nsIMsgFolder* aNewsgroupToMove,
nsIMsgFolder* aRefNewsgroup) {
// if folders are identical do nothing
if (aNewsgroupToMove == aRefNewsgroup) return NS_OK;
@ -1181,34 +1178,20 @@ NS_IMETHODIMP nsMsgNewsFolder::MoveFolder(nsIMsgFolder* aNewsgroupToMove,
// aRefNewsgroup is no subfolder of this folder
return NS_ERROR_INVALID_ARG;
// set new index for NewsgroupToMove
uint32_t indexMin, indexMax;
if (indexNewsgroupToMove < indexRefNewsgroup) {
if (aOrientation < 0) indexRefNewsgroup--;
indexMin = indexNewsgroupToMove;
indexMax = indexRefNewsgroup;
} else {
if (aOrientation > 0) indexRefNewsgroup++;
indexMin = indexRefNewsgroup;
indexMax = indexNewsgroupToMove;
}
// Move NewsgroupToMove to new index and set new sort order.
// move NewsgroupToMove to new index and set new sort order
NotifyFolderRemoved(aNewsgroupToMove);
nsCOMPtr<nsIMsgFolder> newsgroup = mSubFolders[indexNewsgroupToMove];
if (indexNewsgroupToMove != indexRefNewsgroup) {
nsCOMPtr<nsIMsgFolder> newsgroup = mSubFolders[indexNewsgroupToMove];
mSubFolders.RemoveObjectAt(indexNewsgroupToMove);
mSubFolders.InsertObjectAt(newsgroup, indexRefNewsgroup);
mSubFolders.RemoveObjectAt(indexNewsgroupToMove);
// indexRefNewsgroup is already set up correctly.
mSubFolders.InsertObjectAt(newsgroup, indexRefNewsgroup);
}
for (uint32_t i = indexMin; i <= indexMax; i++)
for (uint32_t i = 0; i < mSubFolders.Length(); i++) {
mSubFolders[i]->SetSortOrder(kNewsSortOffset + i);
NotifyFolderAdded(aNewsgroupToMove);
nsAutoString name;
mSubFolders[i]->GetName(name);
NotifyFolderRemoved(mSubFolders[i]);
NotifyFolderAdded(mSubFolders[i]);
}
// write changes back to file
nsCOMPtr<nsINntpIncomingServer> nntpServer;