#include "NativeBuilderEmbed.h" #include "NativeBuilderDocumentEmbed.h" #include "./../docbuilder_p.h" #include "../../common/Directory.h" JSSmart CBuilderEmbed::OpenFile(JSSmart sPath, JSSmart sParams) { std::wstring Path = sPath->toStringW(); std::wstring Params = sParams->toStringW(); // Since we now use snapshots, and we can't always determine which editor is needed // (since the code may be BEFORE opening the file). And if the opening came from // builderJS.OpenFile - in this case we skip reopening. NSDoctRenderer::CDocBuilder_Private* pPrivate = GetPrivate(); if (pPrivate->m_pWorker->IsSimpleJSInstance()) pPrivate->m_bIsOpenedFromSimpleJS = true; int ret = m_pBuilder->OpenFile(Path.c_str(), Params.c_str()); if (pPrivate->m_pWorker->IsSimpleJSInstance()) { JSSmart current = CJSContext::GetCurrent(); current->runScript("throw 0;"); } return CJSContext::createInt(ret); } JSSmart CBuilderEmbed::CreateFile(JSSmart type) { int nFormat = AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCX; if (type->isString()) nFormat = NSDoctRenderer::GetFormatByTexExtention(type->toStringW()); else nFormat = type->toInt32(); // Since we now use snapshots, and we can't always determine which editor is needed // (since the code may be BEFORE opening the file). And if the opening came from // builderJS.OpenFile - in this case we skip reopening. NSDoctRenderer::CDocBuilder_Private* pPrivate = GetPrivate(); if (pPrivate->m_pWorker->IsSimpleJSInstance()) pPrivate->m_bIsOpenedFromSimpleJS = true; bool ret = m_pBuilder->CreateFile(nFormat); if (pPrivate->m_pWorker->IsSimpleJSInstance()) { JSSmart current = CJSContext::GetCurrent(); current->runScript("throw 0;"); } return CJSContext::createBool(ret); } JSSmart CBuilderEmbed::SetTmpFolder(JSSmart path) { std::wstring sPath = path->toStringW(); m_pBuilder->SetTmpFolder(sPath.c_str()); return NULL; } JSSmart CBuilderEmbed::SaveFile(JSSmart type, JSSmart path, JSSmart params) { int nFormat = AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCX; if (type->isString()) nFormat = NSDoctRenderer::GetFormatByTexExtention(type->toStringW()); else nFormat = type->toInt32(); std::wstring sPath = path->toStringW(); std::wstring sParams = params->toStringW(); int ret = GetPrivate()->SaveFile(nFormat, sPath.c_str(), sParams.empty() ? NULL : sParams.c_str(), false); return CJSContext::createInt(ret); } JSSmart CBuilderEmbed::CloseFile() { std::cout << "Warning: use builderJS.CloseFile(); separately!"; m_pBuilder->GetPrivate()->CloseFile(false); return NULL; } JSSmart CBuilderEmbed::OpenTmpFile(JSSmart path, JSSmart params) { std::wstring sPath = path->toStringW(); std::wstring sParams = params->toStringW(); JSSmart oBuilderTmpDoc = CJSContext::createEmbedObject("CBuilderDocumentEmbed"); CBuilderDocumentEmbed* pBuilderTmpDocNative = static_cast(oBuilderTmpDoc->getNative()); pBuilderTmpDocNative->m_pBuilder = m_pBuilder; pBuilderTmpDocNative->SetExternalize(true); pBuilderTmpDocNative->_OpenFile(sPath, sParams); return oBuilderTmpDoc->toValue(); }