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"
17 #include "funcrequest.h"
19 #include "helper_funcs.h"
22 #include "support/LAssert.h"
28 ControlExternal::ControlExternal(Dialog & parent)
29 : Dialog::Controller(parent)
33 bool ControlExternal::initialiseParams(string const & data)
35 params_.reset(new InsetExternal::Params);
36 InsetExternalMailer::string2params(data, *params_);
41 void ControlExternal::clearParams()
47 void ControlExternal::dispatchParams()
49 string const lfun = InsetExternalMailer::params2string(params());
50 kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun));
54 void ControlExternal::setParams(InsetExternal::Params const & p)
56 lyx::Assert(params_.get());
61 InsetExternal::Params const & ControlExternal::params() const
63 lyx::Assert(params_.get());
68 void ControlExternal::editExternal()
70 lyx::Assert(params_.get());
72 dialog().view().apply();
74 inset.setParams(*params_, kernel().buffer()->filePath());
75 inset.cache(kernel().bufferview());
80 vector<string> const ControlExternal::getTemplates() const
82 vector<string> result;
84 ExternalTemplateManager::Templates::const_iterator i1, i2;
85 i1 = ExternalTemplateManager::get().getTemplates().begin();
86 i2 = ExternalTemplateManager::get().getTemplates().end();
88 for (; i1 != i2; ++i1) {
89 result.push_back(i1->second.lyxName);
95 int ControlExternal::getTemplateNumber(string const & name) const
97 ExternalTemplateManager::Templates::const_iterator i1, i2;
98 i1 = ExternalTemplateManager::get().getTemplates().begin();
99 i2 = ExternalTemplateManager::get().getTemplates().end();
100 for (int i = 0; i1 != i2; ++i1, ++i) {
101 if (i1->second.lyxName == name)
105 // we can get here if a LyX document has a template not installed
111 ExternalTemplate ControlExternal::getTemplate(int i) const
113 ExternalTemplateManager::Templates::const_iterator i1
114 = ExternalTemplateManager::get().getTemplates().begin();
122 string const ControlExternal::Browse(string const & input) const
124 string const title = _("Select external file");
126 string const bufpath = kernel().buffer()->filePath();
128 /// Determine the template file extension
129 ExternalTemplate const & et = params().templ;
130 string pattern = et.fileRegExp;
134 // FIXME: a temporary hack until the FileDialog interface is updated
137 std::pair<string, string> dir1(N_("Documents|#o#O"),
138 string(lyxrc.document_path));
140 return browseRelFile(input, bufpath, title, pattern, false, dir1);