Emergency-dialog options

Pavel Sanda sanda at lyx.org
Thu Apr 1 18:56:16 UTC 2021


On Thu, Mar 25, 2021 at 11:35:44AM +0100, Pavel Sanda wrote:
> I can see two possible reasons: 
> 1. Compare is using threads and there is some resource conflict (like writing to LYXERR or whatever)

When we disable multithreading, the crashes are gone.
The downside is that comparison can not be canceled while running.

Attached the final patch. If no objections are raised I'll commit.

Pavel
-------------- next part --------------
diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index fdce444aef..e848b0f69b 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -4694,7 +4694,7 @@ Buffer::ReadStatus Buffer::loadEmergency()
 		"%1$s exists.\n\nRecover emergency save?"), file);
 
 	int const load_emerg = Alert::prompt(_("Load emergency save?"), text,
-		0, 2, _("&Recover"), _("&Load Original"), _("&Cancel"));
+		0, 3, _("&Recover"), _("&Load Original"), _("&Only show difference"), _("&Cancel"));
 
 	switch (load_emerg)
 	{
@@ -4769,6 +4769,21 @@ Buffer::ReadStatus Buffer::loadEmergency()
 		return ReadOriginal;
 	}
 
+	case 2: {
+		string f1 = d->filename.absFileName();
+		string f2 = emergencyFile.absFileName();
+		if (loadThisLyXFile(d->filename) != ReadSuccess)
+			return ReadCancel;
+		string par = "compare run-blocking " + quoteName(f1) + " " + quoteName(f2);
+		LYXERR(Debug::FILES, par << "\n");
+		lyx::dispatch(FuncRequest(LFUN_DIALOG_SHOW, par));
+
+		//release the emergency buffer loaded by compare
+		Buffer * emerBuffer = theBufferList().getBuffer(emergencyFile);
+		if (emerBuffer) theBufferList().release(emerBuffer);
+
+		return ReadCancel; //Release the buffer of Original immediatelly
+	}
 	default:
 		break;
 	}
diff --git a/src/frontends/qt/GuiCompare.cpp b/src/frontends/qt/GuiCompare.cpp
index e48be86f22..7f6b00f44a 100644
--- a/src/frontends/qt/GuiCompare.cpp
+++ b/src/frontends/qt/GuiCompare.cpp
@@ -318,7 +318,13 @@ int GuiCompare::run(bool blocking_mode)
 		return 0;
 
 	dest_buffer_->changed(true);
-	dest_buffer_->markDirty();
+	if (blocking_mode)
+		//blocking mode is infinitive and we don't want diff autosave
+		//if user decides to kill ther running lyx instance
+		dest_buffer_->markClean();
+	else
+		dest_buffer_->markDirty();
+
 
 	// get the options from the dialog
 	CompareOptions options;
@@ -364,10 +370,14 @@ bool GuiCompare::initialiseParams(std::string const &par)
 				return false;
 			}
 
-			// Wait for the Compare function to process in a thread (2 minute timeout)
-			compare_->wait(120000);
+			// Wait for the Compare function to process in a thread
+			compare_->wait();
 
 			finished(false);
+			//Hiding dialog does not work as intended through finished routine, because showView
+			//is triggered after initialiseParams returns true. So we return false, warning will
+			//show on the terminal though.
+			return false;
 		}
 	}
 


More information about the lyx-devel mailing list