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();
73 string const lfun = InsetExternalMailer::params2string(params());
74 kernel().dispatch(FuncRequest(LFUN_EXTERNAL_EDIT, lfun));
78 vector<string> const ControlExternal::getTemplates() const
80 vector<string> result;
82 ExternalTemplateManager::Templates::const_iterator i1, i2;
83 i1 = ExternalTemplateManager::get().getTemplates().begin();
84 i2 = ExternalTemplateManager::get().getTemplates().end();
86 for (; i1 != i2; ++i1) {
87 result.push_back(i1->second.lyxName);
93 int ControlExternal::getTemplateNumber(string const & name) const
95 ExternalTemplateManager::Templates::const_iterator i1, i2;
96 i1 = ExternalTemplateManager::get().getTemplates().begin();
97 i2 = ExternalTemplateManager::get().getTemplates().end();
98 for (int i = 0; i1 != i2; ++i1, ++i) {
99 if (i1->second.lyxName == name)
103 // we can get here if a LyX document has a template not installed
109 ExternalTemplate ControlExternal::getTemplate(int i) const
111 ExternalTemplateManager::Templates::const_iterator i1
112 = ExternalTemplateManager::get().getTemplates().begin();
120 string const ControlExternal::Browse(string const & input) const
122 string const title = _("Select external file");
124 string const bufpath = kernel().buffer()->filePath();
126 /// Determine the template file extension
127 ExternalTemplate const & et = params().templ;
128 string pattern = et.fileRegExp;
132 // FIXME: a temporary hack until the FileDialog interface is updated
135 std::pair<string, string> dir1(N_("Documents|#o#O"),
136 string(lyxrc.document_path));
138 return browseRelFile(input, bufpath, title, pattern, false, dir1);