Index: scribus/canvasmode_objimport.cpp =================================================================== --- scribus/canvasmode_objimport.cpp (revision 27798) +++ scribus/canvasmode_objimport.cpp (working copy) @@ -168,27 +168,51 @@ m->accept(); if ((m->button() == Qt::LeftButton) && m_mimeData) { + UndoManager* undoManager = UndoManager::instance(); UndoTransaction undoTransaction; if (m_trSettings && UndoManager::undoEnabled()) { - undoTransaction = UndoManager::instance()->beginTransaction(*m_trSettings); + undoTransaction = undoManager->beginTransaction(*m_trSettings); } + // Creating QDragEnterEvent outside of Qt is not recommended per docs :S QPointF dropPos = m_view->widget()->mapFromGlobal(m->globalPosition()); const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPosition()); QDropEvent dropEvent(dropPos, Qt::CopyAction|Qt::MoveAction, m_mimeData, m->buttons(), m->modifiers()); - m_view->contentsDropEvent(&dropEvent); - if (m_doc->m_Selection->count() > 0) + auto dropAndPosition = [&]() { - double gx, gy, gh, gw; - m_doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh); - m_doc->moveGroup(mousePointDoc.x() - gx, mousePointDoc.y() -gy); - } - // Commit undo transaction if necessary + m_view->contentsDropEvent(&dropEvent); + if (m_doc->m_Selection->count() > 0) + { + double gx, gy, gh, gw; + m_doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh); + m_doc->moveGroup(mousePointDoc.x() - gx, mousePointDoc.y() - gy); + } + }; + if (undoTransaction) { + const qsizetype oldDocItemCount = m_doc->Items->count(); + { + // Imported groups are assembled after their children are created. Do not + // record CREATE_ITEM states until the final top-level hierarchy exists. + UndoBlocker undoBlocker; + dropAndPosition(); + } + + for (qsizetype i = oldDocItemCount; i < m_doc->Items->count(); ++i) + { + PageItem* newItem = m_doc->Items->at(i); + auto *is = new ScItemState("Create PageItem"); + is->set("CREATE_ITEM"); + is->setItem(newItem); + const int pageIndex = (newItem->OwnPage > -1) ? newItem->OwnPage : 0; + undoManager->action(m_doc->Pages->at(pageIndex), is); + } undoTransaction.commit(); } + else + dropAndPosition(); // Return to normal mode m_view->requestMode(modeNormal); }