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 "graphics/GraphicsCache.h"
23 #include "graphics/GraphicsCacheItem.h"
24 #include "graphics/GraphicsImage.h"
26 #include "insets/insetexternal.h"
27 #include "insets/ExternalSupport.h"
28 #include "insets/ExternalTemplate.h"
30 #include "support/filefilterlist.h"
31 #include "support/filetools.h"
32 #include "support/convert.h"
40 using support::FileFilterList;
41 using support::makeAbsPath;
42 using support::readBB_from_PSFile;
47 ControlExternal::ControlExternal(Dialog & parent)
48 : Dialog::Controller(parent),
53 bool ControlExternal::initialiseParams(string const & data)
55 params_.reset(new InsetExternalParams);
56 InsetExternalMailer::string2params(data, kernel().buffer(), *params_);
61 void ControlExternal::clearParams()
67 void ControlExternal::dispatchParams()
69 string const lfun = InsetExternalMailer::params2string(params(),
72 kernel().dispatch(FuncRequest(getLfun(), lfun));
76 void ControlExternal::setParams(InsetExternalParams const & p)
78 BOOST_ASSERT(params_.get());
83 InsetExternalParams const & ControlExternal::params() const
85 BOOST_ASSERT(params_.get());
90 void ControlExternal::editExternal()
92 BOOST_ASSERT(params_.get());
94 dialog().view().apply();
96 InsetExternalMailer::params2string(params(), kernel().buffer());
97 kernel().dispatch(FuncRequest(LFUN_EXTERNAL_EDIT, lfun));
101 vector<string> const ControlExternal::getTemplates() const
103 vector<string> result;
105 external::TemplateManager::Templates::const_iterator i1, i2;
106 i1 = external::TemplateManager::get().getTemplates().begin();
107 i2 = external::TemplateManager::get().getTemplates().end();
109 for (; i1 != i2; ++i1) {
110 result.push_back(i1->second.lyxName);
116 int ControlExternal::getTemplateNumber(string const & name) const
118 external::TemplateManager::Templates::const_iterator i1, i2;
119 i1 = external::TemplateManager::get().getTemplates().begin();
120 i2 = external::TemplateManager::get().getTemplates().end();
121 for (int i = 0; i1 != i2; ++i1, ++i) {
122 if (i1->second.lyxName == name)
126 // we can get here if a LyX document has a template not installed
132 external::Template ControlExternal::getTemplate(int i) const
134 external::TemplateManager::Templates::const_iterator i1
135 = external::TemplateManager::get().getTemplates().begin();
144 ControlExternal::getTemplateFilters(string const & template_name) const
146 /// Determine the template file extension
147 external::TemplateManager const & etm =
148 external::TemplateManager::get();
149 external::Template const * const et_ptr =
150 etm.getTemplateByName(template_name);
153 return et_ptr->fileRegExp;
159 string const ControlExternal::browse(string const & input,
160 string const & template_name) const
162 string const title = _("Select external file");
164 string const bufpath = kernel().bufferFilepath();
165 FileFilterList const filter =
166 FileFilterList(getTemplateFilters(template_name));
168 std::pair<string, string> dir1(N_("Documents|#o#O"),
169 string(lyxrc.document_path));
171 return browseRelFile(input, bufpath, title, filter, false, dir1);
175 string const ControlExternal::readBB(string const & file)
177 string const abs_file =
178 makeAbsPath(file, kernel().bufferFilepath());
180 // try to get it from the file, if possible. Zipped files are
181 // unzipped in the readBB_from_PSFile-Function
182 string const bb = readBB_from_PSFile(abs_file);
186 // we don't, so ask the Graphics Cache if it has loaded the file
190 graphics::Cache & gc = graphics::Cache::get();
191 if (gc.inCache(abs_file)) {
192 graphics::Image const * image = gc.item(abs_file)->image();
195 width = image->getWidth();
196 height = image->getHeight();
200 return ("0 0 " + convert<string>(width) + ' ' + convert<string>(height));
203 } // namespace frontend
210 RotationDataType origins_array[] = {
211 RotationData::DEFAULT,
212 RotationData::TOPLEFT,
213 RotationData::BOTTOMLEFT,
214 RotationData::BASELINELEFT,
215 RotationData::CENTER,
216 RotationData::TOPCENTER,
217 RotationData::BOTTOMCENTER,
218 RotationData::BASELINECENTER,
219 RotationData::TOPRIGHT,
220 RotationData::BOTTOMRIGHT,
221 RotationData::BASELINERIGHT
225 size_type const origins_array_size =
226 sizeof(origins_array) / sizeof(origins_array[0]);
228 vector<RotationDataType> const
229 origins(origins_array, origins_array + origins_array_size);
231 // These are the strings, corresponding to the above, that the GUI should
232 // use. Note that they can/should be translated.
233 char const * const origin_gui_strs[] = {
235 N_("Top left"), N_("Bottom left"), N_("Baseline left"),
236 N_("Center"), N_("Top center"), N_("Bottom center"), N_("Baseline center"),
237 N_("Top right"), N_("Bottom right"), N_("Baseline right")
243 vector<RotationDataType> const & all_origins()
248 string const origin_gui_str(size_type i)
250 return _(origin_gui_strs[i]);
253 } // namespace external