/** * \file ControlExternal.C * Read the file COPYING * * \author Asger Alstrup * \author John Levon * \author Angus Leeming * * Full author contact details are available in file CREDITS */ #include #ifdef __GNUG__ #pragma implementation #endif #include "ControlExternal.h" #include "buffer.h" #include "BufferView.h" #include "gettext.h" #include "helper_funcs.h" #include "lyxrc.h" #include "support/filetools.h" #include using std::vector; ControlExternal::ControlExternal(LyXView & lv, Dialogs & d) : ControlInset(lv, d) {} InsetExternal::Params const ControlExternal::getParams(string const &) { return InsetExternal::Params(); } InsetExternal::Params const ControlExternal::getParams(InsetExternal const & inset) { return inset.params(); } void ControlExternal::applyParamsToInset() { inset()->setFromParams(params()); bufferview()->updateInset(inset(), true); } void ControlExternal::editExternal() { // fill the local, controller's copy of the Params struct with // the contents of the dialog's fields. view().apply(); // Create a local copy of the inset and initialise it with this // params struct. boost::scoped_ptr ie; ie.reset(static_cast(inset()->clone(*buffer()))); ie->setFromParams(params()); ie->editExternal(); } void ControlExternal::viewExternal() { view().apply(); boost::scoped_ptr ie; ie.reset(static_cast(inset()->clone(*buffer()))); ie->setFromParams(params()); ie->viewExternal(); } void ControlExternal::updateExternal() { view().apply(); boost::scoped_ptr ie; ie.reset(static_cast(inset()->clone(*buffer()))); ie->setFromParams(params()); ie->updateExternal(); } vector const ControlExternal::getTemplates() const { vector result; ExternalTemplateManager::Templates::const_iterator i1, i2; i1 = ExternalTemplateManager::get().getTemplates().begin(); i2 = ExternalTemplateManager::get().getTemplates().end(); for (; i1 != i2; ++i1) { result.push_back(i1->second.lyxName); } return result; } int ControlExternal::getTemplateNumber(string const & name) const { int i = 0; ExternalTemplateManager::Templates::const_iterator i1, i2; i1 = ExternalTemplateManager::get().getTemplates().begin(); i2 = ExternalTemplateManager::get().getTemplates().end(); for (; i1 != i2; ++i1) { if (i1->second.lyxName == name) return i; ++i; } // we can get here if a LyX document has a template not installed // on this machine. return -1; } ExternalTemplate ControlExternal::getTemplate(int i) const { ExternalTemplateManager::Templates::const_iterator i1; i1 = ExternalTemplateManager::get().getTemplates().begin(); for (int n = 1; n < i; ++n) ++i1; return i1->second; } string const ControlExternal::Browse(string const & input) const { string const title = _("Select external file"); string const bufpath = buffer()->filePath(); /// Determine the template file extension ExternalTemplate const & et = params().templ; string pattern = et.fileRegExp; if (pattern.empty()) pattern = "*"; // FIXME: a temporary hack until the FileDialog interface is updated pattern += "|"; std::pair dir1(N_("Documents|#o#O"), string(lyxrc.document_path)); return browseRelFile(&lv_, input, bufpath, title, pattern, dir1); }