mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-30 21:24:14 +00:00
For Qt4.4 and up: Detach Buffer autosave into a new thread.
* Buffer: new clone() method. When this new autosave method is used the old autoSave() is not of course. * GuiView: clone the current document buffer and save it in a new thread. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@32512 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
a4c7e69d7a
commit
622e3b1e4d
@ -356,6 +356,17 @@ Buffer::~Buffer()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Buffer * Buffer::clone() const
|
||||||
|
{
|
||||||
|
Buffer * clone = new Buffer(fileName().absFilename(), false);
|
||||||
|
clone->d->file_fully_loaded = true;
|
||||||
|
clone->d->params = d->params;
|
||||||
|
clone->d->inset = static_cast<InsetText *>(d->inset->clone());
|
||||||
|
clone->d->inset->setBuffer(*clone);
|
||||||
|
return clone;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Buffer::changed() const
|
void Buffer::changed() const
|
||||||
{
|
{
|
||||||
if (d->wa_)
|
if (d->wa_)
|
||||||
|
@ -130,6 +130,9 @@ public:
|
|||||||
/// Destructor
|
/// Destructor
|
||||||
~Buffer();
|
~Buffer();
|
||||||
|
|
||||||
|
///
|
||||||
|
Buffer * clone() const;
|
||||||
|
|
||||||
/** High-level interface to buffer functionality.
|
/** High-level interface to buffer functionality.
|
||||||
This function parses a command string and executes it.
|
This function parses a command string and executes it.
|
||||||
*/
|
*/
|
||||||
|
@ -102,6 +102,13 @@
|
|||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QScrollBar>
|
#include <QScrollBar>
|
||||||
|
|
||||||
|
// QtConcurrent was introduced in Qt 4.4
|
||||||
|
#if (QT_VERSION >= 0x040400)
|
||||||
|
#include <QFuture>
|
||||||
|
#include <QFutureWatcher>
|
||||||
|
#include <QtConcurrentRun>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <boost/bind.hpp>
|
#include <boost/bind.hpp>
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
@ -290,6 +297,11 @@ public:
|
|||||||
|
|
||||||
///
|
///
|
||||||
TocModels toc_models_;
|
TocModels toc_models_;
|
||||||
|
|
||||||
|
#if (QT_VERSION >= 0x040400)
|
||||||
|
///
|
||||||
|
QFutureWatcher<bool> autosave_watcher_;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -350,6 +362,11 @@ GuiView::GuiView(int id)
|
|||||||
// clear session data if any.
|
// clear session data if any.
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
settings.remove("views");
|
settings.remove("views");
|
||||||
|
|
||||||
|
#if (QT_VERSION >= 0x040400)
|
||||||
|
connect(&d.autosave_watcher_, SIGNAL(finished()), this,
|
||||||
|
SLOT(autoSaveFinished()));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -359,6 +376,16 @@ GuiView::~GuiView()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void GuiView::autoSaveFinished()
|
||||||
|
{
|
||||||
|
#if (QT_VERSION >= 0x040400)
|
||||||
|
docstring const msg = d.autosave_watcher_.result()
|
||||||
|
? _("Automatic save done.") : _("Automatic save failed!");
|
||||||
|
message(msg);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void GuiView::saveLayout() const
|
void GuiView::saveLayout() const
|
||||||
{
|
{
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
@ -1195,12 +1222,39 @@ BufferView const * GuiView::currentBufferView() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static bool saveAndDestroyBuffer(Buffer * buffer, FileName const & fname)
|
||||||
|
{
|
||||||
|
bool failed = true;
|
||||||
|
FileName const tmp_ret = FileName::tempName("lyxauto");
|
||||||
|
if (!tmp_ret.empty()) {
|
||||||
|
if (buffer->writeFile(tmp_ret))
|
||||||
|
failed = !tmp_ret.moveTo(fname);
|
||||||
|
}
|
||||||
|
if (failed) {
|
||||||
|
// failed to write/rename tmp_ret so try writing direct
|
||||||
|
failed = buffer->writeFile(fname);
|
||||||
|
}
|
||||||
|
delete buffer;
|
||||||
|
return !failed;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void GuiView::autoSave()
|
void GuiView::autoSave()
|
||||||
{
|
{
|
||||||
LYXERR(Debug::INFO, "Running autoSave()");
|
LYXERR(Debug::INFO, "Running autoSave()");
|
||||||
|
|
||||||
if (documentBufferView())
|
Buffer * buffer = documentBufferView()
|
||||||
documentBufferView()->buffer().autoSave();
|
? &documentBufferView()->buffer() : 0;
|
||||||
|
if (!buffer)
|
||||||
|
return;
|
||||||
|
|
||||||
|
#if (QT_VERSION >= 0x040400)
|
||||||
|
QFuture<bool> f = QtConcurrent::run(saveAndDestroyBuffer, buffer->clone(),
|
||||||
|
buffer->getAutosaveFilename());
|
||||||
|
d.autosave_watcher_.setFuture(f);
|
||||||
|
#else
|
||||||
|
buffer->autoSave();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -180,6 +180,9 @@ private Q_SLOTS:
|
|||||||
void normalSizedIcons();
|
void normalSizedIcons();
|
||||||
void bigSizedIcons();
|
void bigSizedIcons();
|
||||||
|
|
||||||
|
/// For completion of Buffer autosave thread.
|
||||||
|
void autoSaveFinished();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// Open given child document in current buffer directory.
|
/// Open given child document in current buffer directory.
|
||||||
void openChildDocument(std::string const & filename);
|
void openChildDocument(std::string const & filename);
|
||||||
|
Loading…
Reference in New Issue
Block a user