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