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 "insets/ExternalTemplate.h"
24 #include "support/LAssert.h"
27 using namespace lyx::support;
31 ControlExternal::ControlExternal(Dialog & parent)
32 : Dialog::Controller(parent)
36 bool ControlExternal::initialiseParams(string const & data)
38 params_.reset(new InsetExternal::Params);
39 InsetExternalMailer::string2params(data, *kernel().buffer(), *params_);
44 void ControlExternal::clearParams()
50 void ControlExternal::dispatchParams()
52 string const lfun = InsetExternalMailer::params2string(params(),
54 kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun));
58 void ControlExternal::setParams(InsetExternal::Params const & p)
60 Assert(params_.get());
65 InsetExternal::Params const & ControlExternal::params() const
67 Assert(params_.get());
72 void ControlExternal::editExternal()
74 Assert(params_.get());
76 dialog().view().apply();
78 InsetExternalMailer::params2string(params(), *kernel().buffer());
79 kernel().dispatch(FuncRequest(LFUN_EXTERNAL_EDIT, lfun));
83 vector<string> const ControlExternal::getTemplates() const
85 vector<string> result;
87 ExternalTemplateManager::Templates::const_iterator i1, i2;
88 i1 = ExternalTemplateManager::get().getTemplates().begin();
89 i2 = ExternalTemplateManager::get().getTemplates().end();
91 for (; i1 != i2; ++i1) {
92 result.push_back(i1->second.lyxName);
98 int ControlExternal::getTemplateNumber(string const & name) const
100 ExternalTemplateManager::Templates::const_iterator i1, i2;
101 i1 = ExternalTemplateManager::get().getTemplates().begin();
102 i2 = ExternalTemplateManager::get().getTemplates().end();
103 for (int i = 0; i1 != i2; ++i1, ++i) {
104 if (i1->second.lyxName == name)
108 // we can get here if a LyX document has a template not installed
114 ExternalTemplate ControlExternal::getTemplate(int i) const
116 ExternalTemplateManager::Templates::const_iterator i1
117 = ExternalTemplateManager::get().getTemplates().begin();
127 ExternalTemplate const * getTemplatePtr(InsetExternal::Params const & params)
129 ExternalTemplateManager & etm = ExternalTemplateManager::get();
130 ExternalTemplate const & templ = etm.getTemplateByName(params.templatename);
131 if (templ.lyxName.empty())
139 string const ControlExternal::Browse(string const & input) const
141 string const title = _("Select external file");
143 string const bufpath = kernel().bufferFilepath();
145 /// Determine the template file extension
146 string pattern = "*";
147 ExternalTemplate const * const et_ptr = getTemplatePtr(params());
149 pattern = et_ptr->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(input, bufpath, title, pattern, false, dir1);