1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2001 The LyX Team.
8 * ======================================================
10 * \file ControlExternal.C
11 * \author Asger Alstrup
12 * \author John Levon, moz@compsoc.man.ac.uk
13 * \author Angus Leeming, a.leeming@ic.ac.uk
22 #pragma implementation
25 #include "BufferView.h"
26 #include "ButtonControllerBase.h"
27 #include "ControlExternal.h"
28 #include "ControlInset.tmpl"
34 #include "frontends/Alert.h"
36 #include "helper_funcs.h"
38 #include "support/filetools.h"
39 #include "support/lstrings.h"
44 ControlExternal::ControlExternal(LyXView & lv, Dialogs & d)
45 : ControlInset<InsetExternal, InsetExternal::Params>(lv, d)
47 d_.showExternal.connect(SigC::slot(this, &ControlExternal::showInset));
51 InsetExternal::Params const ControlExternal::getParams(string const &)
53 return InsetExternal::Params();
56 InsetExternal::Params const
57 ControlExternal::getParams(InsetExternal const & inset)
59 return inset.params();
63 void ControlExternal::applyParamsToInset()
65 inset()->setFromParams(params());
66 lv_.view()->updateInset(inset(), true);
69 void ControlExternal::editExternal()
71 // fill the local, controller's copy of the Params struct with
72 // the contents of the dialog's fields.
75 // Create a local copy of the inset and initialise it with this
77 boost::scoped_ptr<InsetExternal> ie;
78 ie.reset(static_cast<InsetExternal *>(inset()->clone(*lv_.buffer())));
79 ie->setFromParams(params());
84 void ControlExternal::viewExternal()
88 boost::scoped_ptr<InsetExternal> ie;
89 ie.reset(static_cast<InsetExternal *>(inset()->clone(*lv_.buffer())));
90 ie->setFromParams(params());
95 void ControlExternal::updateExternal()
99 boost::scoped_ptr<InsetExternal> ie;
100 ie.reset(static_cast<InsetExternal *>(inset()->clone(*lv_.buffer())));
101 ie->setFromParams(params());
103 ie->updateExternal();
106 vector<string> const ControlExternal::getTemplates() const
108 vector<string> result;
110 ExternalTemplateManager::Templates::const_iterator i1, i2;
111 i1 = ExternalTemplateManager::get().getTemplates().begin();
112 i2 = ExternalTemplateManager::get().getTemplates().end();
114 for (; i1 != i2; ++i1) {
115 result.push_back(i1->second.lyxName);
121 int ControlExternal::getTemplateNumber(string const & name) const
125 ExternalTemplateManager::Templates::const_iterator i1, i2;
126 i1 = ExternalTemplateManager::get().getTemplates().begin();
127 i2 = ExternalTemplateManager::get().getTemplates().end();
128 for (; i1 != i2; ++i1) {
129 if (i1->second.lyxName == name)
134 // we can get here if a LyX document has a template not installed
140 ExternalTemplate ControlExternal::getTemplate(int i) const
142 ExternalTemplateManager::Templates::const_iterator i1;
143 i1 = ExternalTemplateManager::get().getTemplates().begin();
144 for (int n = 1; n < i; ++n)
151 string const ControlExternal::Browse(string const & input) const
153 string const title = _("Select external file");
155 string const bufpath = lv_.buffer()->filePath();
157 /// Determine the template file extension
158 ExternalTemplate const & et = params().templ;
159 string pattern = et.fileRegExp;
163 // FIXME: a temporary hack until the FileDialog interface is updated
166 std::pair<string, string> dir1(N_("Documents|#o#O"),
167 string(lyxrc.document_path));
169 return browseRelFile(&lv_, input, bufpath, title, pattern, dir1);