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.
15 #include "ControlExternal.h"
16 #include "funcrequest.h"
18 #include "helper_funcs.h"
21 #include "insets/insetexternal.h"
22 #include "insets/ExternalSupport.h"
23 #include "insets/ExternalTemplate.h"
26 namespace external = lyx::external;
32 ControlExternal::ControlExternal(Dialog & parent)
33 : Dialog::Controller(parent)
37 bool ControlExternal::initialiseParams(string const & data)
39 params_.reset(new InsetExternalParams);
40 InsetExternalMailer::string2params(data, kernel().buffer(), *params_);
45 void ControlExternal::clearParams()
51 void ControlExternal::dispatchParams()
53 string const lfun = InsetExternalMailer::params2string(params(),
55 kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun));
59 void ControlExternal::setParams(InsetExternalParams const & p)
61 BOOST_ASSERT(params_.get());
66 InsetExternalParams const & ControlExternal::params() const
68 BOOST_ASSERT(params_.get());
73 void ControlExternal::editExternal()
75 BOOST_ASSERT(params_.get());
77 dialog().view().apply();
79 InsetExternalMailer::params2string(params(), kernel().buffer());
80 kernel().dispatch(FuncRequest(LFUN_EXTERNAL_EDIT, lfun));
84 vector<string> const ControlExternal::getTemplates() const
86 vector<string> result;
88 external::TemplateManager::Templates::const_iterator i1, i2;
89 i1 = external::TemplateManager::get().getTemplates().begin();
90 i2 = external::TemplateManager::get().getTemplates().end();
92 for (; i1 != i2; ++i1) {
93 result.push_back(i1->second.lyxName);
99 int ControlExternal::getTemplateNumber(string const & name) const
101 external::TemplateManager::Templates::const_iterator i1, i2;
102 i1 = external::TemplateManager::get().getTemplates().begin();
103 i2 = external::TemplateManager::get().getTemplates().end();
104 for (int i = 0; i1 != i2; ++i1, ++i) {
105 if (i1->second.lyxName == name)
109 // we can get here if a LyX document has a template not installed
115 external::Template ControlExternal::getTemplate(int i) const
117 external::TemplateManager::Templates::const_iterator i1
118 = external::TemplateManager::get().getTemplates().begin();
126 string const ControlExternal::Browse(string const & input) const
128 string const title = _("Select external file");
130 string const bufpath = kernel().bufferFilepath();
132 /// Determine the template file extension
133 string pattern = "*";
134 external::Template const * const et_ptr =
135 external::getTemplatePtr(params());
137 pattern = et_ptr->fileRegExp;
139 // FIXME: a temporary hack until the FileDialog interface is updated
142 std::pair<string, string> dir1(N_("Documents|#o#O"),
143 string(lyxrc.document_path));
145 return browseRelFile(input, bufpath, title, pattern, false, dir1);