+ implement auto-save function for documents
This commit is contained in:
@@ -31,6 +31,7 @@
|
||||
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Sequencer.h>
|
||||
#include <Base/Writer.h>
|
||||
#include <Base/Interpreter.h>
|
||||
#include <App/Application.h>
|
||||
#include <App/Document.h>
|
||||
@@ -229,3 +230,41 @@ void DocumentTestThread::run()
|
||||
dp.recompute();
|
||||
op.execute(Callable<SandboxObject,&SandboxObject::resetValue>(obj));
|
||||
}
|
||||
|
||||
|
||||
DocumentSaverThread::DocumentSaverThread(App::Document* doc, QObject* parent)
|
||||
: QThread(parent), doc(doc)
|
||||
{
|
||||
}
|
||||
|
||||
DocumentSaverThread::~DocumentSaverThread()
|
||||
{
|
||||
}
|
||||
|
||||
void DocumentSaverThread::run()
|
||||
{
|
||||
std::string uuid = Base::Uuid::createUuid();
|
||||
std::string fn = doc->TransientDir.getValue();
|
||||
fn += "/";
|
||||
fn += uuid;
|
||||
fn += ".autosave";
|
||||
Base::FileInfo tmp(fn);
|
||||
|
||||
// open extra scope to close ZipWriter properly
|
||||
{
|
||||
Base::ofstream file(tmp, std::ios::out | std::ios::binary);
|
||||
Base::ZipWriter writer(file);
|
||||
|
||||
writer.setComment("FreeCAD Document");
|
||||
writer.setLevel(0);
|
||||
writer.putNextEntry("Document.xml");
|
||||
|
||||
doc->Save(writer);
|
||||
|
||||
// Special handling for Gui document.
|
||||
doc->signalSaveDocument(writer);
|
||||
|
||||
// write additional files
|
||||
writer.writeFiles();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,6 +113,19 @@ protected:
|
||||
void run();
|
||||
};
|
||||
|
||||
class SandboxAppExport DocumentSaverThread : public QThread
|
||||
{
|
||||
public:
|
||||
DocumentSaverThread(App::Document* doc, QObject* parent=0);
|
||||
~DocumentSaverThread();
|
||||
|
||||
protected:
|
||||
void run();
|
||||
|
||||
private:
|
||||
App::Document* doc;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // SANDBOX_DOCUMENTTHREAD_H
|
||||
|
||||
@@ -130,6 +130,34 @@ void CmdSandboxDocumentTestThread::activated(int iMsg)
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
|
||||
DEF_STD_CMD_A(CmdSandboxDocumentSaveThread);
|
||||
|
||||
CmdSandboxDocumentSaveThread::CmdSandboxDocumentSaveThread()
|
||||
:Command("Sandbox_SaveThread")
|
||||
{
|
||||
sAppModule = "Sandbox";
|
||||
sGroup = QT_TR_NOOP("Sandbox");
|
||||
sMenuText = QT_TR_NOOP("Save thread");
|
||||
sToolTipText = QT_TR_NOOP("Sandbox save function");
|
||||
sWhatsThis = QT_TR_NOOP("Sandbox save function");
|
||||
sStatusTip = QT_TR_NOOP("Sandbox save function");
|
||||
}
|
||||
|
||||
void CmdSandboxDocumentSaveThread::activated(int iMsg)
|
||||
{
|
||||
App::Document* doc = App::GetApplication().getActiveDocument();
|
||||
Sandbox::DocumentSaverThread* dt = new Sandbox::DocumentSaverThread(doc);
|
||||
QObject::connect(dt, SIGNAL(finished()), dt, SLOT(deleteLater()));
|
||||
dt->start();
|
||||
}
|
||||
|
||||
bool CmdSandboxDocumentSaveThread::isActive()
|
||||
{
|
||||
return App::GetApplication().getActiveDocument() != 0;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
|
||||
DEF_STD_CMD(CmdSandboxDocThreadWithSeq);
|
||||
|
||||
CmdSandboxDocThreadWithSeq::CmdSandboxDocThreadWithSeq()
|
||||
@@ -1410,6 +1438,7 @@ void CreateSandboxCommands(void)
|
||||
Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager();
|
||||
rcCmdMgr.addCommand(new CmdSandboxDocumentThread());
|
||||
rcCmdMgr.addCommand(new CmdSandboxDocumentTestThread());
|
||||
rcCmdMgr.addCommand(new CmdSandboxDocumentSaveThread());
|
||||
rcCmdMgr.addCommand(new CmdSandboxDocThreadWithSeq());
|
||||
rcCmdMgr.addCommand(new CmdSandboxDocThreadBusy());
|
||||
rcCmdMgr.addCommand(new CmdSandboxDocumentNoThread());
|
||||
|
||||
@@ -84,7 +84,8 @@ Gui::MenuItem* Workbench::setupMenuBar() const
|
||||
*threads << "Sandbox_PythonLockThread" << "Sandbox_NolockPython"
|
||||
<< "Sandbox_PyQtThread" << "Sandbox_PythonThread" << "Sandbox_PythonMainThread";
|
||||
test->setCommand("Threads");
|
||||
*test << "Sandbox_Thread" << "Sandbox_TestThread" << "Sandbox_WorkerThread" << "Sandbox_SeqThread"
|
||||
*test << "Sandbox_Thread" << "Sandbox_TestThread" << "Sandbox_SaveThread"
|
||||
<< "Sandbox_WorkerThread" << "Sandbox_SeqThread"
|
||||
<< "Sandbox_BlockThread" << "Sandbox_NoThread" << threads << "Separator"
|
||||
<< "Sandbox_Dialog" << "Sandbox_FileDialog";
|
||||
Gui::MenuItem* misc = new Gui::MenuItem;
|
||||
|
||||
Reference in New Issue
Block a user