2 * \file ControlExternal.C
3 * Read the file COPYING
5 * \author Asger Alstrup
7 * \author Angus Leeming
9 * Full author contact details are available in file CREDITS
15 #pragma implementation
18 #include "ControlExternal.h"
20 #include "BufferView.h"
22 #include "helper_funcs.h"
24 #include "support/filetools.h"
30 ControlExternal::ControlExternal(LyXView & lv, Dialogs & d)
31 : ControlInset<InsetExternal, InsetExternal::Params>(lv, d)
35 InsetExternal::Params const ControlExternal::getParams(string const &)
37 return InsetExternal::Params();
40 InsetExternal::Params const
41 ControlExternal::getParams(InsetExternal const & inset)
43 return inset.params();
47 void ControlExternal::applyParamsToInset()
49 inset()->setFromParams(params());
50 bufferview()->updateInset(inset(), true);
53 void ControlExternal::editExternal()
55 // fill the local, controller's copy of the Params struct with
56 // the contents of the dialog's fields.
59 // Create a local copy of the inset and initialise it with this
61 boost::scoped_ptr<InsetExternal> ie;
62 ie.reset(static_cast<InsetExternal *>(inset()->clone(*buffer())));
63 ie->setFromParams(params());
68 void ControlExternal::viewExternal()
72 boost::scoped_ptr<InsetExternal> ie;
73 ie.reset(static_cast<InsetExternal *>(inset()->clone(*buffer())));
74 ie->setFromParams(params());
79 void ControlExternal::updateExternal()
83 boost::scoped_ptr<InsetExternal> ie;
84 ie.reset(static_cast<InsetExternal *>(inset()->clone(*buffer())));
85 ie->setFromParams(params());
90 vector<string> const ControlExternal::getTemplates() const
92 vector<string> result;
94 ExternalTemplateManager::Templates::const_iterator i1, i2;
95 i1 = ExternalTemplateManager::get().getTemplates().begin();
96 i2 = ExternalTemplateManager::get().getTemplates().end();
98 for (; i1 != i2; ++i1) {
99 result.push_back(i1->second.lyxName);
105 int ControlExternal::getTemplateNumber(string const & name) const
109 ExternalTemplateManager::Templates::const_iterator i1, i2;
110 i1 = ExternalTemplateManager::get().getTemplates().begin();
111 i2 = ExternalTemplateManager::get().getTemplates().end();
112 for (; i1 != i2; ++i1) {
113 if (i1->second.lyxName == name)
118 // we can get here if a LyX document has a template not installed
124 ExternalTemplate ControlExternal::getTemplate(int i) const
126 ExternalTemplateManager::Templates::const_iterator i1;
127 i1 = ExternalTemplateManager::get().getTemplates().begin();
128 for (int n = 1; n < i; ++n)
135 string const ControlExternal::Browse(string const & input) const
137 string const title = _("Select external file");
139 string const bufpath = buffer()->filePath();
141 /// Determine the template file extension
142 ExternalTemplate const & et = params().templ;
143 string pattern = et.fileRegExp;
147 // FIXME: a temporary hack until the FileDialog interface is updated
150 std::pair<string, string> dir1(N_("Documents|#o#O"),
151 string(lyxrc.document_path));
153 return browseRelFile(&lv_, input, bufpath, title, pattern, dir1);