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