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