]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiExternal.cpp
Use <cstdint> instead of <boost/cstdint.hpp>
[lyx.git] / src / frontends / qt4 / GuiExternal.cpp
1 /**
2  * \file GuiExternal.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  * \author Angus Leeming
8  * \author Asger Alstrup
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #include <config.h>
14
15 #include "GuiExternal.h"
16
17 #include "Buffer.h"
18 #include "FuncRequest.h"
19 #include "support/gettext.h"
20 #include "Length.h"
21 #include "LyXRC.h"
22
23 #include "insets/ExternalSupport.h"
24 #include "insets/ExternalTemplate.h"
25 #include "insets/InsetExternal.h"
26
27 #include "graphics/epstools.h"
28 #include "graphics/GraphicsCache.h"
29 #include "graphics/GraphicsCacheItem.h"
30 #include "graphics/GraphicsImage.h"
31
32 #include "support/convert.h"
33 #include "support/filetools.h"
34 #include "support/lstrings.h"
35 #include "support/lyxlib.h"
36 #include "support/os.h"
37
38 #include "LengthCombo.h"
39 #include "qt_helpers.h"
40 #include "Validator.h"
41
42 #include <QCheckBox>
43 #include <QGroupBox>
44 #include <QLineEdit>
45 #include <QPushButton>
46 #include <QTabWidget>
47 #include <QTextBrowser>
48
49 using namespace std;
50 using namespace lyx::support;
51
52 namespace lyx {
53 namespace frontend {
54
55 using namespace external;
56
57 namespace {
58
59 RotationDataType origins[] = {
60         RotationData::DEFAULT,
61         RotationData::TOPLEFT,
62         RotationData::BOTTOMLEFT,
63         RotationData::BASELINELEFT,
64         RotationData::CENTER,
65         RotationData::TOPCENTER,
66         RotationData::BOTTOMCENTER,
67         RotationData::BASELINECENTER,
68         RotationData::TOPRIGHT,
69         RotationData::BOTTOMRIGHT,
70         RotationData::BASELINERIGHT
71 };
72
73
74 // These are the strings, corresponding to the above, that the GUI should
75 // use. Note that they can/should be translated.
76 char const * const origin_gui_strs[] = {
77         N_("Default"),
78         N_("Top left"), N_("Bottom left"), N_("Baseline left"),
79         N_("Center"), N_("Top center"), N_("Bottom center"), N_("Baseline center"),
80         N_("Top right"), N_("Bottom right"), N_("Baseline right")
81 };
82
83 } // namespace
84
85
86 GuiExternal::GuiExternal(GuiView & lv)
87         : GuiDialog(lv, "external", qt_("External Material")), bbChanged_(false)
88 {
89         setupUi(this);
90
91         connect(buttonBox, SIGNAL(clicked(QAbstractButton *)),
92                         this, SLOT(slotButtonBox(QAbstractButton *)));
93
94         /*
95         connect(displayGB, SIGNAL(toggled(bool)),
96                 displayscaleED, SLOT(setEnabled(bool)));
97                 */
98         connect(originCO, SIGNAL(activated(int)),
99                 this, SLOT(change_adaptor()));
100         connect(aspectratioCB, SIGNAL(stateChanged(int)),
101                 this, SLOT(change_adaptor()));
102         connect(browsePB, SIGNAL(clicked()),
103                 this, SLOT(browseClicked()));
104         connect(externalCO, SIGNAL(activated(QString)),
105                 this, SLOT(templateChanged()));
106         connect(extraED, SIGNAL(textChanged(QString)),
107                 this, SLOT(extraChanged(QString)));
108         connect(extraFormatCO, SIGNAL(activated(QString)),
109                 this, SLOT(formatChanged(QString)));
110         connect(widthUnitCO, SIGNAL(activated(int)),
111                 this, SLOT(widthUnitChanged()));
112         connect(heightUnitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)),
113                 this, SLOT(change_adaptor()));
114         connect(displayGB, SIGNAL(toggled(bool)),
115                 this, SLOT(change_adaptor()));
116         connect(displayscaleED, SIGNAL(textChanged(QString)),
117                 this, SLOT(change_adaptor()));
118         connect(angleED, SIGNAL(textChanged(QString)),
119                 this, SLOT(change_adaptor()));
120         connect(widthED, SIGNAL(textChanged(QString)),
121                 this, SLOT(sizeChanged()));
122         connect(heightED, SIGNAL(textChanged(QString)),
123                 this, SLOT(sizeChanged()));
124         connect(fileED, SIGNAL(textChanged(QString)),
125                 this, SLOT(change_adaptor()));
126         connect(clipCB, SIGNAL(stateChanged(int)),
127                 this, SLOT(change_adaptor()));
128         connect(getbbPB, SIGNAL(clicked()), this, SLOT(getbbClicked()));
129         connect(xrED, SIGNAL(textChanged(QString)), this, SLOT(bbChanged()));
130         connect(ytED, SIGNAL(textChanged(QString)), this, SLOT(bbChanged()));
131         connect(xlED, SIGNAL(textChanged(QString)), this, SLOT(bbChanged()));
132         connect(ybED, SIGNAL(textChanged(QString)), this, SLOT(bbChanged()));
133         connect(xrUnitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)),
134                 this, SLOT(bbChanged()));
135         connect(ytUnitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)),
136                 this, SLOT(bbChanged()));
137         connect(xlUnitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)),
138                 this, SLOT(bbChanged()));
139         connect(ybUnitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)),
140                 this, SLOT(bbChanged()));
141         connect(draftCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
142
143         QIntValidator * validator = new QIntValidator(displayscaleED);
144         validator->setBottom(1);
145         displayscaleED->setValidator(validator);
146
147         angleED->setValidator(new QDoubleValidator(-360, 360, 2, angleED));
148
149         xlED->setValidator(unsignedLengthValidator(xlED));
150         ybED->setValidator(unsignedLengthValidator(ybED));
151         xrED->setValidator(unsignedLengthValidator(xrED));
152         ytED->setValidator(unsignedLengthValidator(ytED));
153
154         widthED->setValidator(unsignedLengthValidator(widthED));
155         heightED->setValidator(unsignedLengthValidator(heightED));
156
157         setFocusProxy(fileED);
158
159         bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
160
161         bc().setOK(buttonBox->button(QDialogButtonBox::Ok));
162         bc().setApply(buttonBox->button(QDialogButtonBox::Apply));
163         bc().setCancel(buttonBox->button(QDialogButtonBox::Cancel));
164
165         bc().addReadOnly(fileED);
166         bc().addReadOnly(browsePB);
167         bc().addReadOnly(externalCO);
168         bc().addReadOnly(draftCB);
169         bc().addReadOnly(displayscaleED);
170         bc().addReadOnly(displayGB);
171         bc().addReadOnly(angleED);
172         bc().addReadOnly(originCO);
173         bc().addReadOnly(heightUnitCO);
174         bc().addReadOnly(heightED);
175         bc().addReadOnly(aspectratioCB);
176         bc().addReadOnly(widthUnitCO);
177         bc().addReadOnly(widthED);
178         bc().addReadOnly(clipCB);
179         bc().addReadOnly(getbbPB);
180         bc().addReadOnly(ytED);
181         bc().addReadOnly(xlED);
182         bc().addReadOnly(xrED);
183         bc().addReadOnly(ybED);
184         bc().addReadOnly(ytUnitCO);
185         bc().addReadOnly(xlUnitCO);
186         bc().addReadOnly(xrUnitCO);
187         bc().addReadOnly(ybUnitCO);
188         bc().addReadOnly(extraFormatCO);
189         bc().addReadOnly(extraED);
190
191         bc().addCheckedLineEdit(angleED, angleLA);
192         bc().addCheckedLineEdit(displayscaleED, scaleLA);
193         bc().addCheckedLineEdit(heightED, heightLA);
194         bc().addCheckedLineEdit(widthED, widthLA);
195         bc().addCheckedLineEdit(xlED, lbLA);
196         bc().addCheckedLineEdit(ybED, lbLA);
197         bc().addCheckedLineEdit(xrED, rtLA);
198         bc().addCheckedLineEdit(ytED, rtLA);
199         bc().addCheckedLineEdit(fileED, fileLA);
200
201         external::TemplateManager::Templates::const_iterator i1, i2;
202         i1 = external::TemplateManager::get().getTemplates().begin();
203         i2 = external::TemplateManager::get().getTemplates().end();
204         QMap<QString, QString> localizedTemplates;
205         for (; i1 != i2; ++i1)
206                 localizedTemplates.insert(qt_(i1->second.guiName), toqstr(i1->second.lyxName));
207         // Sort alphabetically by (localized) GUI name
208         QStringList keys = localizedTemplates.keys();
209         qSort(keys.begin(), keys.end(), SortLocaleAware);
210         for (QString & key : keys) {
211                 QString const value = localizedTemplates[key];
212                 externalCO->addItem(key, value);
213         }
214
215         // Fill the origins combo
216         for (size_t i = 0; i != sizeof(origins) / sizeof(origins[0]); ++i)
217                 originCO->addItem(qt_(origin_gui_strs[i]));
218
219         // add scale item
220         widthUnitCO->insertItem(0, qt_("Scale%"), "scale");
221
222         // remove all units from bb that depend on font or other dimensions
223         // we cannot use these, since we need to compare against absolute
224         // values from the image file.
225         xlUnitCO->noPercents();
226         xlUnitCO->removeFontDependent();
227         xrUnitCO->noPercents();
228         xrUnitCO->removeFontDependent();
229         ytUnitCO->noPercents();
230         ytUnitCO->removeFontDependent();
231         ybUnitCO->noPercents();
232         ybUnitCO->removeFontDependent();
233 }
234
235
236 bool GuiExternal::activateAspectratio() const
237 {
238         if (usingScale())
239                 return false;
240
241         QString const wstr = widthED->text();
242         if (wstr.isEmpty())
243                 return false;
244         bool wIsDbl;
245         double val = wstr.trimmed().toDouble(&wIsDbl);
246         if (wIsDbl && float_equal(val, 0.0, 0.05))
247                 return false;
248         Length l;
249         if (!wIsDbl && (!isValidLength(fromqstr(wstr), &l) || l.zero()))
250                 return false;
251
252         QString const hstr = heightED->text();
253         if (hstr.isEmpty())
254                 return false;
255         bool hIsDbl;
256         val = hstr.trimmed().toDouble(&hIsDbl);
257         if (hIsDbl && float_equal(val, 0.0, 0.05))
258                 return false;
259         if (!hIsDbl && (!isValidLength(fromqstr(hstr), &l) || l.zero()))
260                 return false;
261
262         return true;
263 }
264
265
266 bool GuiExternal::usingScale() const
267 {
268         return (widthUnitCO->itemData(
269                 widthUnitCO->currentIndex()).toString() == "scale");
270 }
271
272
273 void GuiExternal::bbChanged()
274 {
275         bbChanged_ = true;
276         changed();
277 }
278
279
280 void GuiExternal::browseClicked()
281 {
282         QString const template_name =
283                 externalCO->itemData(externalCO->currentIndex()).toString();
284         QString const str = browse(fileED->text(), template_name);
285         if (!str.isEmpty()) {
286                 fileED->setText(str);
287                 changed();
288         }
289 }
290
291
292 void GuiExternal::change_adaptor()
293 {
294         changed();
295 }
296
297
298 void GuiExternal::extraChanged(const QString & text)
299 {
300         extra_[extraFormatCO->currentText()] = text;
301         changed();
302 }
303
304
305 void GuiExternal::formatChanged(const QString & format)
306 {
307         extraED->setText(extra_[format]);
308 }
309
310
311 void GuiExternal::getbbClicked()
312 {
313         xlED->setText("0");
314         ybED->setText("0");
315         xrED->setText("0");
316         ytED->setText("0");
317
318         string const filename = fromqstr(fileED->text());
319         if (filename.empty())
320                 return;
321
322         FileName const abs_file(support::makeAbsPath(filename, fromqstr(bufferFilePath())));
323
324         // try to get it from the file, if possible
325         string bb = graphics::readBB_from_PSFile(abs_file);
326         if (bb.empty()) {
327                 // we don't, so ask the Graphics Cache if it has loaded the file
328                 int width = 0;
329                 int height = 0;
330
331                 graphics::Cache & gc = graphics::Cache::get();
332                 if (gc.inCache(abs_file)) {
333                         graphics::Image const * image = gc.item(abs_file)->image();
334
335                         if (image) {
336                                 width  = image->width();
337                                 height = image->height();
338                         }
339                 }
340                 bb = "0 0 " + convert<string>(width) + ' ' + convert<string>(height);
341         }
342
343         doubleToWidget(xlED, token(bb, ' ', 0));
344         doubleToWidget(ybED, token(bb, ' ', 1));
345         doubleToWidget(xrED, token(bb, ' ', 2));
346         doubleToWidget(ytED, token(bb, ' ', 3));
347         // the values from the file always have the bigpoint-unit bp
348         xlUnitCO->setCurrentIndex(0);
349         ybUnitCO->setCurrentIndex(0);
350         xrUnitCO->setCurrentIndex(0);
351         ytUnitCO->setCurrentIndex(0);
352
353         bbChanged_ = false;
354 }
355
356
357 void GuiExternal::sizeChanged()
358 {
359         aspectratioCB->setEnabled(activateAspectratio());
360         changed();
361 }
362
363
364 void GuiExternal::templateChanged()
365 {
366         updateTemplate();
367         changed();
368 }
369
370
371 void GuiExternal::widthUnitChanged()
372 {
373         if (usingScale())
374                 widthED->setValidator(new QDoubleValidator(0, 1000, 2, widthED));
375         else
376                 widthED->setValidator(unsignedLengthValidator(widthED));
377
378         heightED->setEnabled(!usingScale());
379         heightUnitCO->setEnabled(!usingScale());
380         changed();
381 }
382
383
384 static void setRotation(QLineEdit & angleED, QComboBox & originCO,
385         external::RotationData const & data)
386 {
387         originCO.setCurrentIndex(int(data.origin()));
388         doubleToWidget(&angleED, data.angle);
389 }
390
391
392 static void getRotation(external::RotationData & data,
393         QLineEdit const & angleED, QComboBox const & originCO)
394 {
395         typedef external::RotationData::OriginType OriginType;
396
397         data.origin(static_cast<OriginType>(originCO.currentIndex()));
398         data.angle = widgetToDoubleStr(&angleED);
399 }
400
401
402 static void setSize(QLineEdit & widthED, LengthCombo & widthUnitCO,
403         QLineEdit & heightED, LengthCombo & heightUnitCO,
404         QCheckBox & aspectratioCB,
405         external::ResizeData const & data)
406 {
407         bool using_scale = data.usingScale();
408         string scale = data.scale;
409         if (data.no_resize()) {
410                 // Everything is zero, so default to this!
411                 using_scale = true;
412                 scale = "100";
413         }
414
415         if (using_scale) {
416                 doubleToWidget(&widthED, scale);
417                 widthUnitCO.setCurrentItem("scale");
418         } else
419                 lengthToWidgets(&widthED, &widthUnitCO,
420                                 data.width.asString(), Length::defaultUnit());
421
422         string const h = data.height.zero() ? string() : data.height.asString();
423         Length::UNIT const default_unit = data.width.zero() ?
424                 Length::defaultUnit() : data.width.unit();
425         lengthToWidgets(&heightED, &heightUnitCO, h, default_unit);
426
427         heightED.setEnabled(!using_scale);
428         heightUnitCO.setEnabled(!using_scale);
429
430         aspectratioCB.setChecked(data.keepAspectRatio);
431
432         bool const disable_aspectRatio = using_scale ||
433                 data.width.zero() || data.height.zero();
434         aspectratioCB.setEnabled(!disable_aspectRatio);
435 }
436
437
438 static void getSize(external::ResizeData & data,
439         QLineEdit const & widthED, QComboBox const & widthUnitCO,
440         QLineEdit const & heightED, LengthCombo const & heightUnitCO,
441         QCheckBox const & aspectratioCB, bool const scaling)
442 {
443         if (scaling) {
444                 // scaling instead of a width
445                 data.scale = widgetToDoubleStr(&widthED);
446                 data.width = Length();
447         } else {
448                 data.width = Length(widgetsToLength(&widthED, &widthUnitCO));
449                 data.scale = string();
450         }
451         data.height = Length(widgetsToLength(&heightED, &heightUnitCO));
452         data.keepAspectRatio = aspectratioCB.isChecked();
453 }
454
455
456 void setCrop(QCheckBox & clipCB,
457         QLineEdit & xlED, QLineEdit & ybED,
458         QLineEdit & xrED, QLineEdit & ytED,
459         LengthCombo & xlUnitCO, LengthCombo & ybUnitCO,
460         LengthCombo & xrUnitCO, LengthCombo & ytUnitCO,
461         external::ClipData const & data)
462 {
463         clipCB.setChecked(data.clip);
464         Length::UNIT const default_unit = data.bbox.xl.zero() ?
465                 Length::defaultUnit() : data.bbox.xl.unit();
466         lengthToWidgets(&xlED, &xlUnitCO, data.bbox.xl, default_unit);
467         lengthToWidgets(&ybED, &ybUnitCO, data.bbox.yb, default_unit);
468         lengthToWidgets(&xrED, &xrUnitCO, data.bbox.xr, default_unit);
469         lengthToWidgets(&ytED, &ytUnitCO, data.bbox.yt, default_unit);
470 }
471
472
473 static void getCrop(external::ClipData & data,
474         QCheckBox const & clipCB,
475         QLineEdit const & xlED, QLineEdit const & ybED,
476         QLineEdit const & xrED, QLineEdit const & ytED,
477         LengthCombo const & xlUnitCO, LengthCombo const & ybUnitCO,
478         LengthCombo const & xrUnitCO, LengthCombo const & ytUnitCO,
479         bool bb_changed)
480 {
481         data.clip = clipCB.isChecked();
482
483         if (!bb_changed)
484                 return;
485
486         data.bbox.xl = Length(widgetsToLength(&xlED, &xlUnitCO));
487         data.bbox.yb = Length(widgetsToLength(&ybED, &ybUnitCO));
488         data.bbox.xr = Length(widgetsToLength(&xrED, &xrUnitCO));
489         data.bbox.yt = Length(widgetsToLength(&ytED, &ytUnitCO));
490 }
491
492
493 void GuiExternal::updateContents()
494 {
495         if (params_.filename.empty())
496                 tab->setCurrentIndex(0);
497
498         string const name =
499                 params_.filename.outputFileName(fromqstr(bufferFilePath()));
500         fileED->setText(toqstr(name));
501
502         externalCO->setCurrentIndex(
503                 externalCO->findData(toqstr(params_.templatename())));
504         updateTemplate();
505
506         draftCB->setChecked(params_.draft);
507
508         displayGB->setChecked(params_.display);
509         displayscaleED->setText(QString::number(params_.lyxscale));
510         bool scaled = params_.display && !isBufferReadonly() &&
511                         (params_.preview_mode != PREVIEW_INSTANT);
512         displayscaleED->setEnabled(scaled);
513         scaleLA->setEnabled(scaled);
514         displayGB->setEnabled(lyxrc.display_graphics);
515
516
517         setRotation(*angleED, *originCO, params_.rotationdata);
518
519         setSize(*widthED, *widthUnitCO, *heightED, *heightUnitCO,
520                 *aspectratioCB, params_.resizedata);
521
522         setCrop(*clipCB, *xlED, *ybED, *xrED, *ytED,
523                 *xlUnitCO, *ybUnitCO, *xrUnitCO, *ytUnitCO, params_.clipdata);
524         bbChanged_ = !params_.clipdata.bbox.empty();
525
526         isValid();
527 }
528
529
530 void GuiExternal::updateTemplate()
531 {
532         external::TemplateManager const & etm =
533                 external::TemplateManager::get();
534         external::Template const * const templ = etm.getTemplateByName(
535                 fromqstr(externalCO->itemData(externalCO->currentIndex()).toString()));
536         externalTB->setPlainText(toqstr(translateIfPossible(
537                                 templ ? templ->helpText : docstring())));
538         if (!templ)
539                 return;
540
541         // Ascertain which (if any) transformations the template supports
542         // and disable tabs and Group Boxes hosting unsupported transforms.
543         typedef vector<external::TransformID> TransformIDs;
544         TransformIDs const transformIds = templ->transformIds;
545         TransformIDs::const_iterator tr_begin = transformIds.begin();
546         TransformIDs::const_iterator const tr_end = transformIds.end();
547
548         bool rotate = std::find(tr_begin, tr_end, external::Rotate) != tr_end;
549         rotationGB->setEnabled(rotate);
550
551         bool resize = std::find(tr_begin, tr_end, external::Resize) != tr_end;
552         scaleGB->setEnabled(resize);
553
554         bool clip = std::find(tr_begin, tr_end, external::Clip) != tr_end;
555         cropGB->setEnabled(clip);
556
557         sizetab->setEnabled(rotate || resize || clip);
558         tab->setTabEnabled(tab->indexOf(sizetab), rotate || resize || clip);
559
560         bool found = std::find(tr_begin, tr_end, external::Extra) != tr_end;
561         optionsGB->setEnabled(found);
562
563         bool scaled = displayGB->isChecked() && displayGB->isEnabled() &&
564                         !isBufferReadonly() && (templ->preview_mode != PREVIEW_INSTANT);
565         displayscaleED->setEnabled(scaled);
566         scaleLA->setEnabled(scaled);
567
568         if (!found)
569                 return;
570
571         // Ascertain whether the template has any formats supporting
572         // the 'Extra' option
573         extra_.clear();
574         extraED->clear();
575         extraFormatCO->clear();
576
577         external::Template::Formats::const_iterator it  = templ->formats.begin();
578         external::Template::Formats::const_iterator end = templ->formats.end();
579         for (; it != end; ++it) {
580                 if (it->second.option_transformers.find(external::Extra) ==
581                     it->second.option_transformers.end())
582                         continue;
583                 string const format = it->first;
584                 string const opt = params_.extradata.get(format);
585                 extraFormatCO->addItem(toqstr(format));
586                 extra_[toqstr(format)] = toqstr(opt);
587         }
588
589         bool const enabled = extraFormatCO->count()  > 0;
590
591         optionsGB->setEnabled(enabled);
592         extraED->setEnabled(enabled && !isBufferReadonly());
593         extraFormatCO->setEnabled(enabled);
594
595         if (enabled) {
596                 extraFormatCO->setCurrentIndex(0);
597                 extraED->setText(extra_[extraFormatCO->currentText()]);
598         }
599 }
600
601
602 void GuiExternal::applyView()
603 {
604         params_.filename.set(fromqstr(fileED->text()), fromqstr(bufferFilePath()));
605         params_.settemplate(fromqstr(externalCO->itemData(externalCO->currentIndex()).toString()));
606
607         params_.draft = draftCB->isChecked();
608         params_.lyxscale = displayscaleED->text().toInt();
609         params_.display = displayGB->isChecked();
610
611         if (rotationGB->isEnabled())
612                 getRotation(params_.rotationdata, *angleED, *originCO);
613
614         if (scaleGB->isEnabled())
615                 getSize(params_.resizedata, *widthED, *widthUnitCO,
616                         *heightED, *heightUnitCO, *aspectratioCB, usingScale());
617
618         if (cropGB->isEnabled())
619                 getCrop(params_.clipdata, *clipCB, *xlED, *ybED, *xrED, *ytED,
620                         *xlUnitCO, *ybUnitCO, *xrUnitCO, *ytUnitCO, bbChanged_);
621
622         if (optionsGB->isEnabled()) {
623                 MapType::const_iterator it = extra_.begin();
624                 MapType::const_iterator const end = extra_.end();
625                 for (; it != end; ++it)
626                         params_.extradata.set(fromqstr(it.key()), fromqstr(it.value().trimmed()));
627         }
628 }
629
630
631 bool GuiExternal::initialiseParams(string const & sdata)
632 {
633         InsetExternal::string2params(sdata, buffer(), params_);
634         return true;
635 }
636
637
638 void GuiExternal::clearParams()
639 {
640         params_ = InsetExternalParams();
641 }
642
643
644 void GuiExternal::dispatchParams()
645 {
646         string const lfun = InsetExternal::params2string(params_, buffer());
647         dispatch(FuncRequest(getLfun(), lfun));
648 }
649
650
651 static QStringList templateFilters(QString const & template_name)
652 {
653         /// Determine the template file extension
654         external::TemplateManager const & etm =
655                 external::TemplateManager::get();
656         external::Template const * const et_ptr =
657                 etm.getTemplateByName(fromqstr(template_name));
658
659         string filter;
660         if (et_ptr && et_ptr->fileRegExp != "" && et_ptr->fileRegExp != "*") {
661                 filter += to_utf8(_(et_ptr->guiName));
662                 filter += " (";
663                 filter += et_ptr->fileRegExp;
664                 filter += ")";
665         }
666         return fileFilters(toqstr(filter));
667 }
668
669
670 QString GuiExternal::browse(QString const & input,
671                                      QString const & template_name) const
672 {
673         QString const title = qt_("Select external file");
674         QString const bufpath = bufferFilePath();
675         QStringList const filter = templateFilters(template_name);
676
677         QString const label1 = qt_("D&ocuments");
678         QString const dir1 = toqstr(lyxrc.document_path);
679
680         return browseRelToParent(input, bufpath, title, filter, false, label1, dir1);
681 }
682
683
684 Dialog * createGuiExternal(GuiView & lv) { return new GuiExternal(lv); }
685
686
687 } // namespace frontend
688 } // namespace lyx
689
690 #include "moc_GuiExternal.cpp"