mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 13:18:28 +00:00
Call the Compare thread from the GuiCompare dialog.
Furthermore: - increase safety, - improve error handling, - minor cleanups, - set documents to read-only while running the thread. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@31736 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
18483e6362
commit
7227566e86
@ -524,7 +524,7 @@ string Buffer::logName(LogType * type) const
|
||||
}
|
||||
|
||||
|
||||
void Buffer::setReadonly(bool const flag)
|
||||
void Buffer::setReadonly(bool const flag) const
|
||||
{
|
||||
if (d->read_only != flag) {
|
||||
d->read_only = flag;
|
||||
|
@ -318,7 +318,7 @@ public:
|
||||
bool isReadonly() const;
|
||||
|
||||
/// Set buffer read-only flag
|
||||
void setReadonly(bool flag = true);
|
||||
void setReadonly(bool flag = true) const;
|
||||
|
||||
/// returns \c true if the buffer contains a LaTeX document
|
||||
bool isLatex() const;
|
||||
|
@ -55,8 +55,10 @@ Compare::Compare(Buffer const * new_buf, Buffer const * old_buf,
|
||||
|
||||
void Compare::run()
|
||||
{
|
||||
if (!dest_buffer || !new_buffer || !old_buffer)
|
||||
if (!dest_buffer || !new_buffer || !old_buffer) {
|
||||
error();
|
||||
return;
|
||||
}
|
||||
|
||||
// Copy the buffer params to the new buffer
|
||||
dest_buffer->params() = options_.settings_from_new
|
||||
@ -64,9 +66,9 @@ void Compare::run()
|
||||
|
||||
// do the real work
|
||||
if (!doCompare())
|
||||
return;
|
||||
|
||||
finished(pimpl_->abort_);
|
||||
error();
|
||||
else
|
||||
finished(pimpl_->abort_);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -82,7 +84,7 @@ void Compare::abort()
|
||||
|
||||
int Compare::doCompare()
|
||||
{
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -60,8 +60,11 @@ public:
|
||||
}
|
||||
|
||||
Q_SIGNALS:
|
||||
/// The thread has finished due to an error.
|
||||
void error() const;
|
||||
|
||||
/// The thread has finished. If the thread is cancelled
|
||||
/// by the user or due to an error \c aborted is true.
|
||||
/// by the user \c aborted is true.
|
||||
void finished(bool aborted) const;
|
||||
|
||||
/// Adds \c progress to the value of the progress bar in the dialog
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "BufferView.h"
|
||||
#include "BufferList.h"
|
||||
#include "buffer_funcs.h"
|
||||
#include "Compare.h"
|
||||
#include "FuncRequest.h"
|
||||
#include "GuiView.h"
|
||||
#include "LyXRC.h"
|
||||
@ -40,7 +41,7 @@ namespace frontend {
|
||||
|
||||
GuiCompare::GuiCompare(GuiView & lv)
|
||||
: GuiDialog(lv, "compare", qt_("Compare LyX files")),
|
||||
dest_buffer_(0)
|
||||
compare_(0), dest_buffer_(0), old_buffer_(0), new_buffer_(0)
|
||||
{
|
||||
setupUi(this);
|
||||
setModal(Qt::WindowModal);
|
||||
@ -71,6 +72,8 @@ GuiCompare::GuiCompare(GuiView & lv)
|
||||
|
||||
GuiCompare::~GuiCompare()
|
||||
{
|
||||
if (compare_)
|
||||
delete compare_;
|
||||
}
|
||||
|
||||
void GuiCompare::closeEvent(QCloseEvent *)
|
||||
@ -95,6 +98,9 @@ bool GuiCompare::isValid()
|
||||
|
||||
void GuiCompare::updateContents()
|
||||
{
|
||||
if (compare_ && compare_->isRunning())
|
||||
return;
|
||||
|
||||
QString restore_filename1 = newFileCB->currentText();
|
||||
QString restore_filename2 = oldFileCB->currentText();
|
||||
newFileCB->clear();
|
||||
@ -182,24 +188,45 @@ void GuiCompare::enableControls(bool enable) const
|
||||
}
|
||||
|
||||
|
||||
void GuiCompare::error()
|
||||
{
|
||||
Alert::error(_("Error"), _("Error while comparing documents."));
|
||||
window_title_ = windowTitle();
|
||||
finished(true);
|
||||
}
|
||||
|
||||
void GuiCompare::finished(bool aborted)
|
||||
{
|
||||
enableControls(true);
|
||||
if (old_buffer_)
|
||||
old_buffer_->setReadonly(false);
|
||||
if (new_buffer_)
|
||||
new_buffer_->setReadonly(false);
|
||||
|
||||
if (compare_) {
|
||||
delete compare_;
|
||||
compare_ = 0;
|
||||
}
|
||||
|
||||
if (aborted) {
|
||||
dest_buffer_->markClean();
|
||||
theBufferList().release(dest_buffer_);
|
||||
if (dest_buffer_) {
|
||||
dest_buffer_->markClean();
|
||||
theBufferList().release(dest_buffer_);
|
||||
}
|
||||
setWindowTitle(window_title_);
|
||||
progressBar->setValue(0);
|
||||
} else {
|
||||
hideView();
|
||||
bc().ok();
|
||||
dispatch(FuncRequest(LFUN_BUFFER_SWITCH, dest_buffer_->absFileName()));
|
||||
if (dest_buffer_) {
|
||||
dispatch(FuncRequest(LFUN_BUFFER_SWITCH,
|
||||
dest_buffer_->absFileName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void GuiCompare::nextIt(int val)
|
||||
void GuiCompare::progress(int val)
|
||||
{
|
||||
progressBar->setValue(progressBar->value() + val);
|
||||
}
|
||||
@ -214,18 +241,21 @@ void GuiCompare::progressMax(int max) const
|
||||
void GuiCompare::slotOK()
|
||||
{
|
||||
enableControls(false);
|
||||
if (!run()) {
|
||||
Alert::error(_("Error"),
|
||||
_("Unable to compare files."));
|
||||
finished(true);
|
||||
}
|
||||
if (!run())
|
||||
error();
|
||||
}
|
||||
|
||||
|
||||
void GuiCompare::slotCancel()
|
||||
{
|
||||
GuiDialog::slotClose();
|
||||
progressBar->setValue(0);
|
||||
if (compare_ && compare_->isRunning()) {
|
||||
window_title_ = windowTitle();
|
||||
setWindowTitle(window_title_ + " " + qt_("(cancelling)"));
|
||||
compare_->abort();
|
||||
} else {
|
||||
GuiDialog::slotClose();
|
||||
progressBar->setValue(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -256,10 +286,30 @@ int GuiCompare::run()
|
||||
// new buffer that will carry the output
|
||||
FileName initpath(lyxrc.document_path);
|
||||
dest_buffer_ = newUnnamedFile(initpath, to_utf8(_("differences")));
|
||||
|
||||
if (!new_buffer_ || !old_buffer_ || !dest_buffer_)
|
||||
return 0;
|
||||
|
||||
dest_buffer_->changed();
|
||||
dest_buffer_->markDirty();
|
||||
|
||||
return 0;
|
||||
// the comparison is done in a separate thread, so don't let
|
||||
// the user change the buffers
|
||||
old_buffer_->setReadonly(true);
|
||||
new_buffer_->setReadonly(true);
|
||||
|
||||
// get the options from the dialog
|
||||
CompareOptions options;
|
||||
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)));
|
||||
connect(compare_, SIGNAL(progress(int)), this, SLOT(progress(int)));
|
||||
connect(compare_, SIGNAL(progressMax(int)), this, SLOT(progressMax(int)));
|
||||
compare_->start(QThread::LowPriority);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
@ -16,6 +16,8 @@
|
||||
#include "ui_CompareUi.h"
|
||||
#include "qt_helpers.h"
|
||||
|
||||
#include "Compare.h"
|
||||
|
||||
namespace lyx {
|
||||
namespace frontend {
|
||||
|
||||
@ -43,10 +45,12 @@ private Q_SLOTS:
|
||||
///
|
||||
void selectOldFile();
|
||||
|
||||
///
|
||||
void error();
|
||||
///
|
||||
void finished(bool aborted);
|
||||
///
|
||||
void nextIt(int);
|
||||
void progress(int);
|
||||
///
|
||||
void progressMax(int) const;
|
||||
|
||||
@ -79,6 +83,9 @@ private:
|
||||
int run();
|
||||
|
||||
private:
|
||||
/// the object that will do the comparison
|
||||
Compare * compare_;
|
||||
|
||||
/// the buffer that will contain the result
|
||||
Buffer * dest_buffer_;
|
||||
/// the buffer that will contain the result
|
||||
|
Loading…
Reference in New Issue
Block a user