2 * \file ControlExternal.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Asger Alstrup
8 * \author Angus Leeming
10 * Full author contact details are available in file CREDITS
16 #pragma implementation
19 #include "ControlExternal.h"
21 #include "BufferView.h"
23 #include "helper_funcs.h"
25 #include "support/filetools.h"
32 ControlExternal::ControlExternal(LyXView & lv, Dialogs & d)
33 : ControlInset<InsetExternal, InsetExternal::Params>(lv, d)
37 InsetExternal::Params const ControlExternal::getParams(string const &)
39 return InsetExternal::Params();
43 InsetExternal::Params const
44 ControlExternal::getParams(InsetExternal const & inset)
46 return inset.params();
50 void ControlExternal::applyParamsToInset()
52 inset()->setFromParams(params());
53 bufferview()->updateInset(inset(), true);
57 void ControlExternal::editExternal()
59 // fill the local, controller's copy of the Params struct with
60 // the contents of the dialog's fields.
63 // Create a local copy of the inset and initialise it with this
65 boost::scoped_ptr<InsetExternal> ie;
66 ie.reset(static_cast<InsetExternal *>(inset()->clone(*buffer())));
67 ie->setFromParams(params());
73 void ControlExternal::viewExternal()
77 boost::scoped_ptr<InsetExternal> ie;
78 ie.reset(static_cast<InsetExternal *>(inset()->clone(*buffer())));
79 ie->setFromParams(params());
85 void ControlExternal::updateExternal()
89 boost::scoped_ptr<InsetExternal> ie;
90 ie.reset(static_cast<InsetExternal *>(inset()->clone(*buffer())));
91 ie->setFromParams(params());
97 vector<string> const ControlExternal::getTemplates() const
99 vector<string> result;
101 ExternalTemplateManager::Templates::const_iterator i1, i2;
102 i1 = ExternalTemplateManager::get().getTemplates().begin();
103 i2 = ExternalTemplateManager::get().getTemplates().end();
105 for (; i1 != i2; ++i1) {
106 result.push_back(i1->second.lyxName);
112 int ControlExternal::getTemplateNumber(string const & name) const
114 ExternalTemplateManager::Templates::const_iterator i1, i2;
115 i1 = ExternalTemplateManager::get().getTemplates().begin();
116 i2 = ExternalTemplateManager::get().getTemplates().end();
117 for (int i = 0; i1 != i2; ++i1, ++i) {
118 if (i1->second.lyxName == name)
122 // we can get here if a LyX document has a template not installed
128 ExternalTemplate ControlExternal::getTemplate(int i) const
130 ExternalTemplateManager::Templates::const_iterator i1
131 = ExternalTemplateManager::get().getTemplates().begin();
139 string const ControlExternal::Browse(string const & input) const
141 string const title = _("Select external file");
143 string const bufpath = buffer()->filePath();
145 /// Determine the template file extension
146 ExternalTemplate const & et = params().templ;
147 string pattern = et.fileRegExp;
151 // FIXME: a temporary hack until the FileDialog interface is updated
154 std::pair<string, string> dir1(N_("Documents|#o#O"),
155 string(lyxrc.document_path));
157 return browseRelFile(&lv_, input, bufpath, title, pattern, false, dir1);