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