X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt%2FGuiCompare.cpp;h=e485ec0a548c6de028a6ae5ed6952dfcfd8a84b4;hb=5cb80b867f4a59c3253487652ba74a29ad5b3f0f;hp=d282df95263ae6c568d7e05ef026113ed7f65928;hpb=c293be56bd12c5dc46e5cedd2828e33918fccef7;p=lyx.git diff --git a/src/frontends/qt/GuiCompare.cpp b/src/frontends/qt/GuiCompare.cpp index d282df9526..e485ec0a54 100644 --- a/src/frontends/qt/GuiCompare.cpp +++ b/src/frontends/qt/GuiCompare.cpp @@ -12,10 +12,13 @@ #include "GuiCompare.h" +#include "GuiApplication.h" + #include "Buffer.h" #include "BufferView.h" #include "BufferList.h" #include "buffer_funcs.h" +#include "ColorCache.h" #include "Compare.h" #include "FuncRequest.h" #include "GuiView.h" @@ -244,7 +247,7 @@ void GuiCompare::progressMax(int max) const } -void GuiCompare::setStatusMessage(QString msg) +void GuiCompare::setStatusMessage(QString const & msg) { statusBar->showMessage(msg); } @@ -303,7 +306,7 @@ Buffer const * GuiCompare::bufferFromFileName(string const & file) const } -int GuiCompare::run() +int GuiCompare::run(bool blocking_mode) { progressBar->setValue(0); @@ -318,21 +321,35 @@ int GuiCompare::run() 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; options.settings_from_new = newSettingsRB->isChecked(); + options.author = authorCO->currentIndex(); // 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,21 +357,54 @@ 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 + 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; + } } progressBar->setValue(0); progressBar->setEnabled(false); progressBar->setMaximum(1); + // If empty fill the author combobox with the current and the comparison + // author and their respective colors + if (authorCO->count() == 0) { + authorCO->clear(); + QPixmap colorIcon(32, 32); + colorIcon.fill(guiApp->colorCache().get( + Color(Color_changedtext_workarea_author1))); + authorCO->addItem(colorIcon, qt_("Current Author")); + colorIcon.fill(guiApp->colorCache().get( + Color(Color_changedtext_workarea_comparison))); + authorCO->addItem(colorIcon, qt_("Document Comparison")); + } + return true; } -Dialog * createGuiCompare(GuiView & lv) { return new GuiCompare(lv); } - } // namespace frontend } // namespace lyx