Re: Emergency-dialog options

2021-04-01 Thread José Abílio Matos
On Thursday, April 1, 2021 7:56:16 PM WEST Pavel Sanda wrote:
> 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

Please do, this is one area that I like in LyX.
Thank you for your work on this specific issue that it is always hard to 
tackle. :-)

-- 
José Abílio


-- 
lyx-devel mailing list
lyx-devel@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-devel


Re: Emergency-dialog options

2021-04-01 Thread Pavel Sanda
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
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, _(""), _(" Original"), _(""));
+   0, 3, _(""), _(" Original"), _(" show 
difference"), _(""));
 
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 )
return false;
}
 
-   // Wait for the Compare function to process in a thread 
(2 minute timeout)
-   compare_->wait(12);
+   // 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;
}
}
 
-- 
lyx-devel mailing list
lyx-devel@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-devel