Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 21028432 authored by Albert Astals Cid's avatar Albert Astals Cid

Use the undo stack to set the modified bit

This way it's much easier to track whether we are modified or not
parent 8e80a4f5
......@@ -2124,6 +2124,7 @@ Document::Document( QWidget *widget )
connect( SettingsCore::self(), SIGNAL(configChanged()), this, SLOT(_o_configChanged()) );
connect(d->m_undoStack, &QUndoStack::canUndoChanged, this, &Document::canUndoChanged);
connect(d->m_undoStack, &QUndoStack::canRedoChanged, this, &Document::canRedoChanged);
connect(d->m_undoStack, &QUndoStack::cleanChanged, this, &Document::undoHistoryCleanChanged);
qRegisterMetaType<Okular::FontInfo>();
}
......@@ -3212,24 +3213,11 @@ void Document::requestTextPage( uint page )
void DocumentPrivate::notifyAnnotationChanges( int page )
{
int flags = DocumentObserver::Annotations;
// Unless we're still loading initial annotations from metadata, the user
// now needs to save or annotation changes will be lost
if ( m_metadataLoadingCompleted )
flags |= DocumentObserver::NeedSaveAs;
foreachObserverD( notifyPageChanged( page, flags ) );
foreachObserverD( notifyPageChanged( page, DocumentObserver::Annotations ) );
}
void DocumentPrivate::notifyFormChanges( int page )
void DocumentPrivate::notifyFormChanges( int /*page*/ )
{
// Unless we're still loading initial form contents from metadata, the user
// now needs to save or form changes will be lost
if ( !m_metadataLoadingCompleted )
return;
foreachObserverD( notifyPageChanged( page, DocumentObserver::NeedSaveAs ) );
}
void Document::addPageAnnotation( int page, Annotation * annotation )
......@@ -4474,6 +4462,14 @@ bool Document::swapBackingFileArchive( const QString &newFileName, const QUrl &u
return success;
}
void Document::setHistoryClean( bool clean )
{
if ( clean )
d->m_undoStack->setClean();
else
d->m_undoStack->resetClean();
}
bool Document::canSaveChanges() const
{
if ( !d->m_generator )
......
......@@ -772,6 +772,13 @@ class OKULARCORE_EXPORT Document : public QObject
*/
bool swapBackingFileArchive( const QString &newFileName, const QUrl &url );
/**
* Sets the history to be clean
*
* @since 1.3
*/
void setHistoryClean( bool clean );
/**
* Saving capabilities. Their availability varies according to the
* underlying generator and/or the document type.
......@@ -1129,6 +1136,12 @@ class OKULARCORE_EXPORT Document : public QObject
*/
void canRedoChanged( bool redoAvailable );
/**
* This signal is emmitted whenever the undo history is clean (i.e. the same status the last time it was saved)
* @since 1.3
*/
void undoHistoryCleanChanged( bool clean );
/**
* This signal is emitted whenever an rendition action is triggered and the UI should process it.
*
......
......@@ -45,7 +45,7 @@ class OKULARCORE_EXPORT DocumentObserver
TextSelection = 8, ///< Text selection has been changed
Annotations = 16, ///< Annotations have been changed
BoundingBox = 32, ///< Bounding boxes have been changed
NeedSaveAs = 64 ///< Set when "Save" is needed or annotation/form changes will be lost @since 0.15 (KDE 4.9)
NeedSaveAs = 64 ///< Set when "Save" is needed or annotation/form changes will be lost @since 0.15 (KDE 4.9) @deprecated
};
/**
......
......@@ -389,6 +389,13 @@ m_cliPresentation(false), m_cliPrint(false), m_embedMode(detectEmbedMode(parentW
connect( m_document, &Document::openUrl, this, &Part::openUrlFromDocument );
connect( m_document->bookmarkManager(), &BookmarkManager::openUrl, this, &Part::openUrlFromBookmarks );
connect( m_document, &Document::close, this, &Part::close );
connect( m_document, &Document::undoHistoryCleanChanged, this,
[this](bool clean)
{
setModified( !clean );
setWindowTitleFromDocument();
}
);
if ( parent && parent->metaObject()->indexOfSlot( QMetaObject::normalizedSignature( "slotQuit()" ).constData() ) != -1 )
connect( m_document, SIGNAL(quit()), parent, SLOT(slotQuit()) );
......@@ -1198,12 +1205,6 @@ void Part::notifyViewportChanged( bool /*smoothMove*/ )
void Part::notifyPageChanged( int page, int flags )
{
if ( flags & Okular::DocumentObserver::NeedSaveAs )
{
setModified();
setWindowTitleFromDocument();
}
if ( !(flags & Okular::DocumentObserver::Bookmark ) )
return;
......@@ -1729,8 +1730,6 @@ bool Part::closeUrl(bool promptToSave)
return true; // pretend it worked
}
setModified( false );
if (!m_temporaryLocalFile.isNull() && m_temporaryLocalFile != localFilePath())
{
QFile::remove( m_temporaryLocalFile );
......@@ -2636,8 +2635,8 @@ bool Part::saveAs( const QUrl & saveUrl, SaveAsFlags flags )
return false;
}
setModified( false );
setWindowTitleFromDocument();
m_document->setHistoryClean( true );
if ( m_document->isDocdataMigrationNeeded() )
m_document->docdataMigrationDone();
......@@ -2652,8 +2651,7 @@ bool Part::saveAs( const QUrl & saveUrl, SaveAsFlags flags )
{
if ( setModifiedAfterSave )
{
setModified();
setWindowTitleFromDocument();
m_document->setHistoryClean( false );
}
}
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