Commit cd24ad31 authored by Albert Astals Cid's avatar Albert Astals Cid Committed by Albert Astals Cid

Implement missing todo in Document::swapBackingFileArchive

And extend tests to include archive files
parent 946d54fb
This diff is collapsed.
......@@ -4466,9 +4466,57 @@ bool Document::swapBackingFileArchive( const QString &newFileName, const QUrl &
qCDebug(OkularCoreDebug) << "Swapping backing file to" << tempFileName;
QVector< Page * > newPagesVector;
if (genIt->generator->swapBackingFile( tempFileName, newPagesVector ))
Generator::SwapBackingFileResult result = genIt->generator->swapBackingFile( tempFileName, newPagesVector );
if (result != Generator::SwapBackingFileError)
{
// TODO Do the same we do in the other swapBackingFile call
QLinkedList< ObjectRect* > rectsToDelete;
QLinkedList< Annotation* > annotationsToDelete;
QSet< PagePrivate* > pagePrivatesToDelete;
if (result == Generator::SwapBackingFileReloadInternalData)
{
// Here we need to replace everything that the old generator
// had created with what the new one has without making it look like
// we have actually closed and opened the file again
// Simple sanity check
if (newPagesVector.count() != d->m_pagesVector.count())
return false;
// Update the undo stack contents
for (int i = 0; i < d->m_undoStack->count(); ++i)
{
// Trust me on the const_cast ^_^
QUndoCommand *uc = const_cast<QUndoCommand *>( d->m_undoStack->command( i ) );
if (OkularUndoCommand *ouc = dynamic_cast<OkularUndoCommand*>( uc )) ouc->refreshInternalPageReferences( newPagesVector );
else
{
qWarning() << "Unhandled undo command" << uc;
}
}
for (int i = 0; i < d->m_pagesVector.count(); ++i)
{
// switch the PagePrivate* from newPage to oldPage
// this way everyone still holding Page* doesn't get
// disturbed by it
Page *oldPage = d->m_pagesVector[i];
Page *newPage = newPagesVector[i];
newPage->d->adoptGeneratedContents(oldPage->d);
pagePrivatesToDelete << oldPage->d;
oldPage->d = newPage->d;
oldPage->d->m_page = oldPage;
oldPage->d->m_doc = d;
newPage->d = nullptr;
annotationsToDelete << oldPage->m_annotations;
rectsToDelete << oldPage->m_rects;
oldPage->m_annotations = newPage->m_annotations;
oldPage->m_rects = newPage->m_rects;
}
qDeleteAll( newPagesVector );
}
delete d->m_archiveData;
d->m_archiveData = newArchive;
......@@ -4476,7 +4524,23 @@ bool Document::swapBackingFileArchive( const QString &newFileName, const QUrl &
d->m_docFileName = tempFileName;
d->updateMetadataXmlNameAndDocSize();
d->m_bookmarkManager->setUrl( d->m_url );
if ( d->m_synctex_scanner )
{
synctex_scanner_free( d->m_synctex_scanner );
d->m_synctex_scanner = synctex_scanner_new_with_output_file( QFile::encodeName( newFileName ).constData(), nullptr, 1);
if ( !d->m_synctex_scanner && QFile::exists(newFileName + QLatin1String( "sync" ) ) )
{
d->loadSyncFile(newFileName);
}
}
foreachObserver( notifySetup( d->m_pagesVector, DocumentObserver::UrlChanged ) );
qDeleteAll( annotationsToDelete );
qDeleteAll( rectsToDelete );
qDeleteAll( pagePrivatesToDelete );
return true;
}
else
......
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