mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
Fix issue in running compare from the command line
Because Compare uses threads, we need to make sure it is finished when a compare is executed from the command line. This was a problem for command sequences, because the next command would start running before the compare was done, and the buffer with differences was available. So this commit adds the "run-blocking" parameter when using LFUN_DIALOG_SHOW to run a Compare. When calling Compare with run-sync, the LFUN will wait for the compare worker thread to finish before returning and possibly running the next command.
This commit is contained in:
parent
3784d79882
commit
f457a32a13
@ -303,7 +303,7 @@ Buffer const * GuiCompare::bufferFromFileName(string const & file) const
|
||||
}
|
||||
|
||||
|
||||
int GuiCompare::run()
|
||||
int GuiCompare::run(bool blocking_mode)
|
||||
{
|
||||
progressBar->setValue(0);
|
||||
|
||||
@ -325,14 +325,21 @@ int GuiCompare::run()
|
||||
options.settings_from_new = newSettingsRB->isChecked();
|
||||
|
||||
// init the compare object and start it
|
||||
|
||||
compare_ = new Compare(new_buffer_, old_buffer_, dest_buffer_, options);
|
||||
|
||||
connect(compare_, SIGNAL(error()), this, SLOT(error()));
|
||||
connect(compare_, SIGNAL(finished(bool)), this, SLOT(finished(bool)));
|
||||
// Only connect the finished() method to the signal if we're *not* in blocking_mode
|
||||
// (i.e. we want to make it possible for caller to block for the results)
|
||||
if (! blocking_mode) {
|
||||
connect(compare_, SIGNAL(finished(bool)), this, SLOT(finished(bool)));
|
||||
}
|
||||
connect(compare_, SIGNAL(progress(int)), this, SLOT(progress(int)));
|
||||
connect(compare_, SIGNAL(progressMax(int)), this, SLOT(progressMax(int)));
|
||||
connect(compare_, SIGNAL(statusMessage(QString)),
|
||||
this, SLOT(setStatusMessage(QString)));
|
||||
compare_->start(QThread::LowPriority);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -340,10 +347,28 @@ bool GuiCompare::initialiseParams(std::string const &par)
|
||||
{
|
||||
//just for the sake of parsing arguments
|
||||
FuncRequest cmd(LFUN_UNKNOWN_ACTION, par);
|
||||
if (cmd.getArg(0) == "run") {
|
||||
if (cmd.getArg(0) == "run" || cmd.getArg(0) == "run-blocking") {
|
||||
oldFileCB->setEditText(toqstr(cmd.getArg(1)));
|
||||
newFileCB->setEditText(toqstr(cmd.getArg(2)));
|
||||
slotOK();
|
||||
|
||||
if (cmd.getArg(0) == "run" ) {
|
||||
// Run asynchronously
|
||||
slotOK();
|
||||
}
|
||||
else {
|
||||
// Run synchronously
|
||||
enableControls(false);
|
||||
|
||||
if (! run(true)) {
|
||||
error();
|
||||
return false;
|
||||
}
|
||||
|
||||
// Wait for the Compare function to process in a thread (2 minute timeout)
|
||||
compare_->wait(120000);
|
||||
|
||||
finished(false);
|
||||
}
|
||||
}
|
||||
|
||||
progressBar->setValue(0);
|
||||
|
@ -85,7 +85,8 @@ private:
|
||||
Buffer const * bufferFromFileName(std::string const & file) const;
|
||||
|
||||
/// create the compare object and run the comparison
|
||||
int run();
|
||||
/// if blocking_mode is true, run should execute so that the caller can block to wait for the results
|
||||
int run(bool blocking_mode = false);
|
||||
|
||||
private:
|
||||
/// the object that will do the comparison
|
||||
|
Loading…
Reference in New Issue
Block a user