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
19 #pragma implementation
22 #include "BufferView.h"
23 #include "ButtonControllerBase.h"
24 #include "ControlExternal.h"
25 #include "ControlInset.tmpl"
28 #include "frontends/LyXView.h"
31 #include "frontends/Alert.h"
33 #include "helper_funcs.h"
35 #include "support/filetools.h"
36 #include "support/lstrings.h"
38 #include <boost/scoped_ptr.hpp>
46 ControlExternal::ControlExternal(LyXView & lv, Dialogs & d)
47 : ControlInset<InsetExternal, InsetExternal::Params>(lv, d)
49 d_.showExternal.connect(SigC::slot(this, &ControlExternal::showInset));
53 InsetExternal::Params const ControlExternal::getParams(string const &)
55 return InsetExternal::Params();
58 InsetExternal::Params const
59 ControlExternal::getParams(InsetExternal const & inset)
61 return inset.params();
65 void ControlExternal::applyParamsToInset()
67 inset()->setFromParams(params());
68 lv_.view()->updateInset(inset(), true);
71 void ControlExternal::editExternal()
73 // fill the local, controller's copy of the Params struct with
74 // the contents of the dialog's fields.
77 // Create a local copy of the inset and initialise it with this
79 boost::scoped_ptr<InsetExternal> ie;
80 ie.reset(static_cast<InsetExternal *>(inset()->clone(*lv_.buffer())));
81 ie->setFromParams(params());
86 void ControlExternal::viewExternal()
90 boost::scoped_ptr<InsetExternal> ie;
91 ie.reset(static_cast<InsetExternal *>(inset()->clone(*lv_.buffer())));
92 ie->setFromParams(params());
97 void ControlExternal::updateExternal()
101 boost::scoped_ptr<InsetExternal> ie;
102 ie.reset(static_cast<InsetExternal *>(inset()->clone(*lv_.buffer())));
103 ie->setFromParams(params());
105 ie->updateExternal();
108 vector<string> const ControlExternal::getTemplates() const
110 vector<string> result;
112 ExternalTemplateManager::Templates::const_iterator i1, i2;
113 i1 = ExternalTemplateManager::get().getTemplates().begin();
114 i2 = ExternalTemplateManager::get().getTemplates().end();
116 for (; i1 != i2; ++i1) {
117 result.push_back(i1->second.lyxName);
123 int ControlExternal::getTemplateNumber(string const & name) const
127 ExternalTemplateManager::Templates::const_iterator i1, i2;
128 i1 = ExternalTemplateManager::get().getTemplates().begin();
129 i2 = ExternalTemplateManager::get().getTemplates().end();
130 for (; i1 != i2; ++i1) {
131 if (i1->second.lyxName == name)
136 // we can get here if a LyX document has a template not installed
142 ExternalTemplate ControlExternal::getTemplate(int i) const
144 ExternalTemplateManager::Templates::const_iterator i1;
145 i1 = ExternalTemplateManager::get().getTemplates().begin();
146 for (int n = 1; n < i; ++n)
153 string const ControlExternal::Browse(string const & input) const
155 string const title = _("Select external file");
157 string const bufpath = lv_.buffer()->filePath();
159 /// Determine the template file extension
160 ExternalTemplate const & et = params().templ;
161 string pattern = et.fileRegExp;
165 // FIXME: a temporary hack until the FileDialog interface is updated
168 std::pair<string, string> dir1(N_("Documents|#o#O"),
169 string(lyxrc.document_path));
171 return browseRelFile(&lv_, input, bufpath, title, pattern, dir1);