mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	mobile/undo: consider undo-stack when checking for unsaved changes
In analogy to desktop, also consider the state of the undo-stack when testing for unsaved changes. This prevents us from missing changes. This adds duplicate code, which will be unified in the near future. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
		
							parent
							
								
									1f180552c9
								
							
						
					
					
						commit
						a6567a0070
					
				
					 1 changed files with 13 additions and 5 deletions
				
			
		| 
						 | 
					@ -170,6 +170,14 @@ void QMLManager::usbRescan()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern void (*uiNotificationCallback)(QString);
 | 
					extern void (*uiNotificationCallback)(QString);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Currently we have two markers for unsaved changes:
 | 
				
			||||||
 | 
					// 1) unsaved_changes() returns true for non-undoable changes.
 | 
				
			||||||
 | 
					// 2) Command::isClean() returns false for undoable changes.
 | 
				
			||||||
 | 
					static bool unsavedChanges()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return unsaved_changes() || !Command::isClean();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
QMLManager::QMLManager() : m_locationServiceEnabled(false),
 | 
					QMLManager::QMLManager() : m_locationServiceEnabled(false),
 | 
				
			||||||
	m_verboseEnabled(false),
 | 
						m_verboseEnabled(false),
 | 
				
			||||||
	m_diveListProcessing(false),
 | 
						m_diveListProcessing(false),
 | 
				
			||||||
| 
						 | 
					@ -310,7 +318,7 @@ void QMLManager::applicationStateChanged(Qt::ApplicationState state)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	stateText.prepend("AppState changed to ");
 | 
						stateText.prepend("AppState changed to ");
 | 
				
			||||||
	stateText.append(" with ");
 | 
						stateText.append(" with ");
 | 
				
			||||||
	stateText.append((unsaved_changes() ? QLatin1String("") : QLatin1String("no ")) + QLatin1String("unsaved changes"));
 | 
						stateText.append((unsavedChanges() ? QLatin1String("") : QLatin1String("no ")) + QLatin1String("unsaved changes"));
 | 
				
			||||||
	appendTextToLog(stateText);
 | 
						appendTextToLog(stateText);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (state == Qt::ApplicationActive && !m_initialized) {
 | 
						if (state == Qt::ApplicationActive && !m_initialized) {
 | 
				
			||||||
| 
						 | 
					@ -318,7 +326,7 @@ void QMLManager::applicationStateChanged(Qt::ApplicationState state)
 | 
				
			||||||
		finishSetup();
 | 
							finishSetup();
 | 
				
			||||||
		appInitialized();
 | 
							appInitialized();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if (state == Qt::ApplicationInactive && unsaved_changes()) {
 | 
						if (state == Qt::ApplicationInactive && unsavedChanges()) {
 | 
				
			||||||
		// saveChangesCloud ensures that we don't have two conflicting saves going on
 | 
							// saveChangesCloud ensures that we don't have two conflicting saves going on
 | 
				
			||||||
		appendTextToLog("trying to save data as user switched away from app");
 | 
							appendTextToLog("trying to save data as user switched away from app");
 | 
				
			||||||
		saveChangesCloud(false);
 | 
							saveChangesCloud(false);
 | 
				
			||||||
| 
						 | 
					@ -1307,7 +1315,7 @@ void QMLManager::openNoCloudRepo()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void QMLManager::saveChangesLocal()
 | 
					void QMLManager::saveChangesLocal()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if (unsaved_changes()) {
 | 
						if (unsavedChanges()) {
 | 
				
			||||||
		if (qPrefCloudStorage::cloud_verification_status() == qPrefCloudStorage::CS_NOCLOUD) {
 | 
							if (qPrefCloudStorage::cloud_verification_status() == qPrefCloudStorage::CS_NOCLOUD) {
 | 
				
			||||||
			if (empty_string(existing_filename)) {
 | 
								if (empty_string(existing_filename)) {
 | 
				
			||||||
				QString filename = nocloud_localstorage();
 | 
									QString filename = nocloud_localstorage();
 | 
				
			||||||
| 
						 | 
					@ -1340,7 +1348,7 @@ void QMLManager::saveChangesLocal()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void QMLManager::saveChangesCloud(bool forceRemoteSync)
 | 
					void QMLManager::saveChangesCloud(bool forceRemoteSync)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if (!unsaved_changes() && !forceRemoteSync) {
 | 
						if (!unsavedChanges() && !forceRemoteSync) {
 | 
				
			||||||
		appendTextToLog("asked to save changes but no unsaved changes");
 | 
							appendTextToLog("asked to save changes but no unsaved changes");
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -1726,7 +1734,7 @@ void QMLManager::screenChanged(QScreen *screen)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void QMLManager::quit()
 | 
					void QMLManager::quit()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if (unsaved_changes())
 | 
						if (unsavedChanges())
 | 
				
			||||||
		saveChangesCloud(false);
 | 
							saveChangesCloud(false);
 | 
				
			||||||
	QApplication::quit();
 | 
						QApplication::quit();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue