Commit ae76d6f3 authored by David Faure's avatar David Faure
Browse files

Fix DnD crash for more cases (moving N bookmarks into subfolder or parent folder)

Solution: copy all selected bookmarks first, then delete them all
(at their possibly updated address).

BUG: 287038
FIXED-IN: 4.11.3
parent 5abe7a70
......@@ -516,37 +516,26 @@ KEBMacroCommand* CmdGen::itemsMoved(KBookmarkModel* model, const QList<KBookmark
const QString &newAddress, bool copy) {
KEBMacroCommand *mcmd = new KEBMacroCommand(copy ? i18nc("(qtundo-format)", "Copy Items")
: i18nc("(qtundo-format)", "Move Items"));
QList<KBookmark>::const_iterator it, end;
it = items.constBegin();
end = items.constEnd();
QString bkInsertAddr = newAddress;
for (; it != end; ++it) {
if (copy) {
CreateCommand *cmd = new CreateCommand(model,
foreach (const KBookmark &bk, items) {
CreateCommand *cmd = new CreateCommand(model,
bkInsertAddr,
KBookmark((*it).internalElement()
.cloneNode(true).toElement()),
(*it).text(), mcmd);
//cmd->redo();
bkInsertAddr = cmd->finalAddress(); // TODO is this correct without the redo()?
} else /* if (move) */ {
const QString oldAddress = (*it).address();
if (bkInsertAddr.startsWith(oldAddress))
continue; // trying to insert a parent into one of its children, ignore :)
KBookmark(bk.internalElement().cloneNode(true).toElement()),
bk.text(), mcmd);
bkInsertAddr = KBookmark::nextAddress(bkInsertAddr);
}
MoveCommand *cmd = new MoveCommand(model, oldAddress, bkInsertAddr,
(*it).text(), mcmd);
//cmd->redo();
mcmd->redo();
QStringList addresses;
foreach (const KBookmark &bk, items) {
addresses.append(bk.address());
}
mcmd->undo();
bkInsertAddr = cmd->finalAddress(); // TODO is this correct without the redo()?
if (!copy) { // move
foreach (const QString &address, addresses) {
new DeleteCommand(model, address, false, mcmd);
}
bkInsertAddr = KBookmark::nextAddress(bkInsertAddr);
}
return mcmd;
......
......@@ -166,15 +166,19 @@ private Q_SLOTS:
QCOMPARE(BookmarkLister::addressList(m_bookmarkManager), QStringList() << "/0/" << "/0/0" << "/0/1" << "/1/");
QCOMPARE(m_model->rowCount(m_rootIndex), 2);
QModelIndex firstIndex = m_model->indexForBookmark(m_bookmarkManager->findByAddress("/0/0"));
kdeIndex = m_model->indexForBookmark(m_bookmarkManager->findByAddress("/0/1"));
mimeData = m_model->mimeData(QModelIndexList() << firstIndex << kdeIndex);
QModelIndex folder2Index = m_model->indexForBookmark(m_bookmarkManager->findByAddress("/1"));
ok = m_model->dropMimeData(mimeData, Qt::MoveAction, -1, 0, folder2Index);
QVERIFY(ok);
moveTwoBookmarks("/0/0", "/0/1", "/1");
QCOMPARE(BookmarkLister::addressList(m_bookmarkManager), QStringList() << "/0/" << "/1/" << "/1/0" << "/1/1");
QCOMPARE(BookmarkLister::urlList(m_bookmarkManager), QStringList() << kde << first);
delete mimeData;
// Move bookmarks from /1 into subfolder /1/2 (which will become /1/0)
m_cmdHistory->addCommand(new CreateCommand(m_model, "/1/2", "subfolder", "subfolder", true));
QCOMPARE(BookmarkLister::addressList(m_bookmarkManager), QStringList() << "/0/" << "/1/" << "/1/0" << "/1/1" << "/1/2/");
moveTwoBookmarks("/1/0", "/1/1", "/1/2");
QCOMPARE(BookmarkLister::addressList(m_bookmarkManager), QStringList() << "/0/" << "/1/" << "/1/0/" << "/1/0/0" << "/1/0/1");
// Move them up again
moveTwoBookmarks("/1/0/0", "/1/0/1", "/1");
QCOMPARE(BookmarkLister::addressList(m_bookmarkManager), QStringList() << "/0/" << "/1/" << "/1/0" << "/1/1" << "/1/2/");
undoAll();
}
......@@ -210,6 +214,16 @@ private Q_SLOTS:
}
private:
void moveTwoBookmarks(const QString &src1, const QString &src2, const QString &dest)
{
const QModelIndex firstIndex = m_model->indexForBookmark(m_bookmarkManager->findByAddress(src1));
const QModelIndex secondIndex = m_model->indexForBookmark(m_bookmarkManager->findByAddress(src2));
QMimeData *mimeData = m_model->mimeData(QModelIndexList() << firstIndex << secondIndex);
QModelIndex folder2Index = m_model->indexForBookmark(m_bookmarkManager->findByAddress(dest));
QVERIFY(m_model->dropMimeData(mimeData, Qt::MoveAction, -1, 0, folder2Index));
delete mimeData;
}
void undoAll()
{
QAction* undoAction = m_collection.action(KStandardAction::name(KStandardAction::Undo));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment