]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiExternal.cpp
8bbf4f5313af617c0cfa6506b305c3228960cc47
[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/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/lstrings.h"
33 #include "support/lyxlib.h"
34 #include "support/os.h"
35
36 #include "LengthCombo.h"
37 #include "qt_helpers.h"
38 #include "Validator.h"
39
40 #include <QCheckBox>
41 #include <QLineEdit>
42 #include <QPushButton>
43 #include <QTabWidget>
44 #include <QTextBrowser>
45
46 using namespace std;
47 using namespace lyx::support;
48
49 namespace lyx {
50 namespace frontend {
51
52 using namespace external;
53
54 namespace {
55
56 RotationDataType origins[] = {
57         RotationData::DEFAULT,
58         RotationData::TOPLEFT,
59         RotationData::BOTTOMLEFT,
60         RotationData::BASELINELEFT,
61         RotationData::CENTER,
62         RotationData::TOPCENTER,
63         RotationData::BOTTOMCENTER,
64         RotationData::BASELINECENTER,
65         RotationData::TOPRIGHT,
66         RotationData::BOTTOMRIGHT,
67         RotationData::BASELINERIGHT
68 };
69
70
71 // These are the strings, corresponding to the above, that the GUI should
72 // use. Note that they can/should be translated.
73 char const * const origin_gui_strs[] = {
74         N_("Default"),
75         N_("Top left"), N_("Bottom left"), N_("Baseline left"),
76         N_("Center"), N_("Top center"), N_("Bottom center"), N_("Baseline center"),
77         N_("Top right"), N_("Bottom right"), N_("Baseline right")
78 };
79
80 external::Template getTemplate(int i)
81 {
82         external::TemplateManager::Templates::const_iterator i1
83                 = external::TemplateManager::get().getTemplates().begin();
84         advance(i1, i);
85         return i1->second;
86 }
87
88 } // namespace anon
89
90
91 GuiExternal::GuiExternal(GuiView & lv)
92         : GuiDialog(lv, "external", qt_("External Material")), bbChanged_(false)
93 {
94         setupUi(this);
95
96         connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
97         connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
98         connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
99
100         connect(displayCB, SIGNAL(toggled(bool)),
101                 showCO, SLOT(setEnabled(bool)));
102         connect(displayCB, SIGNAL(toggled(bool)),
103                 displayscaleED, SLOT(setEnabled(bool)));
104         connect(showCO, SIGNAL(activated(QString)),
105                 this, SLOT(change_adaptor()));
106         connect(originCO, SIGNAL(activated(int)),
107                 this, SLOT(change_adaptor()));
108         connect(aspectratioCB, SIGNAL(stateChanged(int)),
109                 this, SLOT(change_adaptor()));
110         connect(browsePB, SIGNAL(clicked()),
111                 this, SLOT(browseClicked()));
112         connect(editPB, SIGNAL(clicked()),
113                 this, SLOT(editClicked()));
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(displayCB, SIGNAL(stateChanged(int)),
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(draftCB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
144
145         QIntValidator * validator = new QIntValidator(displayscaleED);
146         validator->setBottom(1);
147         displayscaleED->setValidator(validator);
148
149         angleED->setValidator(new QDoubleValidator(-360, 360, 2, angleED));
150
151         xlED->setValidator(new QIntValidator(xlED));
152         ybED->setValidator(new QIntValidator(ybED));
153         xrED->setValidator(new QIntValidator(xrED));
154         ytED->setValidator(new QIntValidator(ytED));
155
156         widthED->setValidator(unsignedLengthValidator(widthED));
157         heightED->setValidator(unsignedLengthValidator(heightED));
158
159         setFocusProxy(fileED);
160
161         bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
162
163         bc().setOK(okPB);
164         bc().setApply(applyPB);
165         bc().setCancel(closePB);
166
167         bc().addReadOnly(fileED);
168         bc().addReadOnly(browsePB);
169         bc().addReadOnly(editPB);
170         bc().addReadOnly(externalCO);
171         bc().addReadOnly(draftCB);
172         bc().addReadOnly(displayscaleED);
173         bc().addReadOnly(showCO);
174         bc().addReadOnly(displayCB);
175         bc().addReadOnly(angleED);
176         bc().addReadOnly(originCO);
177         bc().addReadOnly(heightUnitCO);
178         bc().addReadOnly(heightED);
179         bc().addReadOnly(aspectratioCB);
180         bc().addReadOnly(widthUnitCO);
181         bc().addReadOnly(widthED);
182         bc().addReadOnly(clipCB);
183         bc().addReadOnly(getbbPB);
184         bc().addReadOnly(ytED);
185         bc().addReadOnly(xlED);
186         bc().addReadOnly(xrED);
187         bc().addReadOnly(ybED);
188         bc().addReadOnly(extraFormatCO);
189         bc().addReadOnly(extraED);
190
191         bc().addCheckedLineEdit(angleED, angleLA);
192         bc().addCheckedLineEdit(displayscaleED, scaleLA);
193         bc().addCheckedLineEdit(heightED, heightLA);
194         bc().addCheckedLineEdit(widthED, widthLA);
195         bc().addCheckedLineEdit(xlED, lbLA);
196         bc().addCheckedLineEdit(ybED, lbLA);
197         bc().addCheckedLineEdit(xrED, rtLA);
198         bc().addCheckedLineEdit(ytED, rtLA);
199         bc().addCheckedLineEdit(fileED, fileLA);
200
201         external::TemplateManager::Templates::const_iterator i1, i2;
202         i1 = external::TemplateManager::get().getTemplates().begin();
203         i2 = external::TemplateManager::get().getTemplates().end();
204         for (; i1 != i2; ++i1)
205                 externalCO->addItem(qt_(i1->second.lyxName));
206
207         // Fill the origins combo
208         for (size_t i = 0; i != sizeof(origins) / sizeof(origins[0]); ++i)
209                 originCO->addItem(qt_(origin_gui_strs[i]));
210
211         // Fill the width combo
212         widthUnitCO->addItem(qt_("Scale%"));
213         for (int i = 0; i < num_units; i++)
214                 widthUnitCO->addItem(qt_(unit_name_gui[i]));
215 }
216
217
218 bool GuiExternal::activateAspectratio() const
219 {
220         if (widthUnitCO->currentIndex() == 0)
221                 return false;
222
223         string const wstr = fromqstr(widthED->text());
224         if (wstr.empty())
225                 return false;
226         bool const wIsDbl = isStrDbl(wstr);
227         if (wIsDbl && float_equal(convert<double>(wstr), 0.0, 0.05))
228                 return false;
229         Length l;
230         if (!wIsDbl && (!isValidLength(wstr, &l) || l.zero()))
231                 return false;
232
233         string const hstr = fromqstr(heightED->text());
234         if (hstr.empty())
235                 return false;
236         bool const hIsDbl = isStrDbl(hstr);
237         if (hIsDbl && float_equal(convert<double>(hstr), 0.0, 0.05))
238                 return false;
239         if (!hIsDbl && (!isValidLength(hstr, &l) || l.zero()))
240                 return false;
241
242         return true;
243 }
244
245
246 void GuiExternal::bbChanged()
247 {
248         bbChanged_ = true;
249         changed();
250 }
251
252
253 void GuiExternal::browseClicked()
254 {
255         int const choice =  externalCO->currentIndex();
256         QString const template_name = toqstr(getTemplate(choice).lyxName);
257         QString const str = browse(fileED->text(), template_name);
258         if (!str.isEmpty()) {
259                 fileED->setText(str);
260                 changed();
261         }
262 }
263
264
265 void GuiExternal::change_adaptor()
266 {
267         changed();
268 }
269
270
271 void GuiExternal::editClicked()
272 {
273         editExternal();
274 }
275
276
277 void GuiExternal::extraChanged(const QString & text)
278 {
279         extra_[extraFormatCO->currentText()] = text;
280         changed();
281 }
282
283
284 void GuiExternal::formatChanged(const QString & format)
285 {
286         extraED->setText(extra_[format]);
287 }
288
289
290 void GuiExternal::getbbClicked()
291 {
292         xlED->setText("0");
293         ybED->setText("0");
294         xrED->setText("0");
295         ytED->setText("0");
296
297         string const filename = fromqstr(fileED->text());
298         if (filename.empty())
299                 return;
300
301         FileName const abs_file(support::makeAbsPath(filename, fromqstr(bufferFilepath())));
302
303         // try to get it from the file, if possible
304         string bb = readBB_from_PSFile(abs_file);
305         if (bb.empty()) {
306                 // we don't, so ask the Graphics Cache if it has loaded the file
307                 int width = 0;
308                 int height = 0;
309
310                 graphics::Cache & gc = graphics::Cache::get();
311                 if (gc.inCache(abs_file)) {
312                         graphics::Image const * image = gc.item(abs_file)->image();
313
314                         if (image) {
315                                 width  = image->width();
316                                 height = image->height();
317                         }
318                 }
319                 bb = "0 0 " + convert<string>(width) + ' ' + convert<string>(height);
320         }
321
322         xlED->setText(toqstr(token(bb, ' ', 0)));
323         ybED->setText(toqstr(token(bb, ' ', 1)));
324         xrED->setText(toqstr(token(bb, ' ', 2)));
325         ytED->setText(toqstr(token(bb, ' ', 3)));
326
327         bbChanged_ = false;
328 }
329
330
331 void GuiExternal::sizeChanged()
332 {
333         aspectratioCB->setEnabled(activateAspectratio());
334         changed();
335 }
336
337
338 void GuiExternal::templateChanged()
339 {
340         updateTemplate();
341         changed();
342 }
343
344
345 void GuiExternal::widthUnitChanged()
346 {
347         bool useHeight = (widthUnitCO->currentIndex() > 0);
348
349         if (useHeight)
350                 widthED->setValidator(unsignedLengthValidator(widthED));
351         else
352                 widthED->setValidator(new QDoubleValidator(0, 1000, 2, widthED));
353
354         heightED->setEnabled(useHeight);
355         heightUnitCO->setEnabled(useHeight);
356         changed();
357 }
358
359
360 static Length::UNIT defaultUnit()
361 {
362         Length::UNIT default_unit = Length::CM;
363         switch (lyxrc.default_papersize) {
364         case PAPER_USLETTER:
365         case PAPER_USLEGAL:
366         case PAPER_USEXECUTIVE:
367                 default_unit = Length::IN;
368                 break;
369         default:
370                 break;
371         }
372         return default_unit;
373 }
374
375
376 static void setDisplay(
377         QCheckBox & displayCB, QComboBox & showCO, QLineEdit & scaleED,
378         external::DisplayType display, unsigned int scale, bool read_only)
379 {
380         int item = 0;
381         switch (display) {
382         case external::DefaultDisplay:
383                 item = 0;
384                 break;
385         case external::MonochromeDisplay:
386                 item = 1;
387                 break;
388         case external::GrayscaleDisplay:
389                 item = 2;
390                 break;
391         case external::ColorDisplay:
392                 item = 3;
393                 break;
394         case external::PreviewDisplay:
395                 item = 4;
396                 break;
397         case external::NoDisplay:
398                 item = 0;
399                 break;
400         }
401
402         showCO.setCurrentIndex(item);
403         bool const no_display = display == external::NoDisplay;
404         showCO.setEnabled(!no_display && !read_only);
405         displayCB.setChecked(!no_display);
406         scaleED.setEnabled(!no_display && !read_only);
407         scaleED.setText(QString::number(scale));
408 }
409
410
411 static external::DisplayType display(QCheckBox const & displayCB,
412         QComboBox const & showCO)
413 {
414         if (!displayCB.isChecked())
415                 return external::NoDisplay;
416         switch (showCO.currentIndex()) {
417         default:
418         case 0:
419                 return external::DefaultDisplay;
420         case 1:
421                 return external::MonochromeDisplay;
422         case 2:
423                 return external::GrayscaleDisplay;
424         case 3:
425                 return external::ColorDisplay;
426         case 4:
427                 return external::PreviewDisplay;
428         }
429 }
430
431
432 static void setRotation(QLineEdit & angleED, QComboBox & originCO,
433         external::RotationData const & data)
434 {
435         originCO.setCurrentIndex(int(data.origin()));
436         angleED.setText(toqstr(data.angle));
437 }
438
439
440 static void getRotation(external::RotationData & data,
441         QLineEdit const & angleED, QComboBox const & originCO)
442 {
443         typedef external::RotationData::OriginType OriginType;
444
445         data.origin(static_cast<OriginType>(originCO.currentIndex()));
446         data.angle = fromqstr(angleED.text());
447 }
448
449
450 static void setSize(QLineEdit & widthED, QComboBox & widthUnitCO,
451         QLineEdit & heightED, LengthCombo & heightUnitCO,
452         QCheckBox & aspectratioCB,
453         external::ResizeData const & data)
454 {
455         bool using_scale = data.usingScale();
456         string scale = data.scale;
457         if (data.no_resize()) {
458                 // Everything is zero, so default to this!
459                 using_scale = true;
460                 scale = "100";
461         }
462
463         if (using_scale) {
464                 widthED.setText(toqstr(scale));
465                 widthUnitCO.setCurrentIndex(0);
466         } else {
467                 widthED.setText(QString::number(data.width.value()));
468                 // Because 'Scale' is position 0...
469                 // Note also that width cannot be zero here, so
470                 // we don't need to worry about the default unit.
471                 widthUnitCO.setCurrentIndex(data.width.unit() + 1);
472         }
473
474         string const h = data.height.zero() ? string() : data.height.asString();
475         Length::UNIT default_unit = data.width.zero() ?
476                 defaultUnit() : data.width.unit();
477         lengthToWidgets(&heightED, &heightUnitCO, h, default_unit);
478
479         heightED.setEnabled(!using_scale);
480         heightUnitCO.setEnabled(!using_scale);
481
482         aspectratioCB.setChecked(data.keepAspectRatio);
483
484         bool const disable_aspectRatio = using_scale ||
485                 data.width.zero() || data.height.zero();
486         aspectratioCB.setEnabled(!disable_aspectRatio);
487 }
488
489
490 static void getSize(external::ResizeData & data,
491         QLineEdit const & widthED, QComboBox const & widthUnitCO,
492         QLineEdit const & heightED, LengthCombo const & heightUnitCO,
493         QCheckBox const & aspectratioCB)
494 {
495         string const width = fromqstr(widthED.text());
496
497         if (widthUnitCO.currentIndex() > 0) {
498                 // Subtract one, because scale is 0.
499                 int const unit = widthUnitCO.currentIndex() - 1;
500
501                 Length w;
502                 if (isValidLength(width, &w))
503                         data.width = w;
504                 else if (isStrDbl(width))
505                         data.width = Length(convert<double>(width),
506                                            static_cast<Length::UNIT>(unit));
507                 else
508                         data.width = Length();
509
510                 data.scale = string();
511
512         } else {
513                 // scaling instead of a width
514                 data.scale = width;
515                 data.width = Length();
516         }
517
518         data.height = Length(widgetsToLength(&heightED, &heightUnitCO));
519
520         data.keepAspectRatio = aspectratioCB.isChecked();
521 }
522
523
524 void setCrop(QCheckBox & clipCB,
525         QLineEdit & xlED, QLineEdit & ybED,
526         QLineEdit & xrED, QLineEdit & ytED,
527         external::ClipData const & data)
528 {
529         clipCB.setChecked(data.clip);
530         graphics::BoundingBox const & bbox = data.bbox;
531         xlED.setText(QString::number(bbox.xl));
532         ybED.setText(QString::number(bbox.yb));
533         xrED.setText(QString::number(bbox.xr));
534         ytED.setText(QString::number(bbox.yt));
535 }
536
537
538 static void getCrop(external::ClipData & data,
539         QCheckBox const & clipCB,
540         QLineEdit const & xlED, QLineEdit const & ybED,
541         QLineEdit const & xrED, QLineEdit const & ytED,
542         bool bb_changed)
543 {
544         data.clip = clipCB.isChecked();
545
546         if (!bb_changed)
547                 return;
548
549         data.bbox.xl = xlED.text().toInt();
550         data.bbox.yb = ybED.text().toInt();
551         data.bbox.xr = xrED.text().toInt();
552         data.bbox.yt = ytED.text().toInt();
553 }
554
555
556 void GuiExternal::updateContents()
557 {
558         tab->setCurrentIndex(0);
559
560         string const name =
561                 params_.filename.outputFilename(fromqstr(bufferFilepath()));
562         fileED->setText(toqstr(name));
563
564         int index = -1;
565         external::TemplateManager::Templates::const_iterator i1, i2;
566         i1 = external::TemplateManager::get().getTemplates().begin();
567         i2 = external::TemplateManager::get().getTemplates().end();
568         for (int i = 0; i1 != i2; ++i1, ++i) {
569                 if (i1->second.lyxName == params_.templatename()) {
570                         index = i;
571                         break;
572                 }
573         }
574
575         externalCO->setCurrentIndex(index);
576         updateTemplate();
577
578         draftCB->setChecked(params_.draft);
579
580         setDisplay(*displayCB, *showCO, *displayscaleED,
581                    params_.display, params_.lyxscale, isBufferReadonly());
582
583         setRotation(*angleED, *originCO, params_.rotationdata);
584
585         setSize(*widthED, *widthUnitCO, *heightED, *heightUnitCO,
586                 *aspectratioCB, params_.resizedata);
587
588         setCrop(*clipCB, *xlED, *ybED, *xrED, *ytED, params_.clipdata);
589         bbChanged_ = !params_.clipdata.bbox.empty();
590
591         isValid();
592 }
593
594
595 void GuiExternal::updateTemplate()
596 {
597         external::Template templ = getTemplate(externalCO->currentIndex());
598         externalTB->setPlainText(qt_(templ.helpText));
599
600         // Ascertain which (if any) transformations the template supports
601         // and disable tabs hosting unsupported transforms.
602         typedef vector<external::TransformID> TransformIDs;
603         TransformIDs const transformIds = templ.transformIds;
604         TransformIDs::const_iterator tr_begin = transformIds.begin();
605         TransformIDs::const_iterator const tr_end = transformIds.end();
606
607         bool found = std::find(tr_begin, tr_end, external::Rotate) != tr_end;
608         tab->setTabEnabled(tab->indexOf(rotatetab), found);
609         found = std::find(tr_begin, tr_end, external::Resize) != tr_end;
610         tab->setTabEnabled(tab->indexOf(scaletab), found);
611
612         found = std::find(tr_begin, tr_end, external::Clip) != tr_end;
613         tab->setTabEnabled(tab->indexOf(croptab), found);
614
615         found = std::find(tr_begin, tr_end, external::Extra) != tr_end;
616         tab->setTabEnabled(tab->indexOf(optionstab), found);
617
618         if (!found)
619                 return;
620
621         // Ascertain whether the template has any formats supporting
622         // the 'Extra' option
623         extra_.clear();
624         extraED->clear();
625         extraFormatCO->clear();
626
627         external::Template::Formats::const_iterator it  = templ.formats.begin();
628         external::Template::Formats::const_iterator end = templ.formats.end();
629         for (; it != end; ++it) {
630                 if (it->second.option_transformers.find(external::Extra) ==
631                     it->second.option_transformers.end())
632                         continue;
633                 string const format = it->first;
634                 string const opt = params_.extradata.get(format);
635                 extraFormatCO->addItem(toqstr(format));
636                 extra_[toqstr(format)] = toqstr(opt);
637         }
638
639         bool const enabled = extraFormatCO->count()  > 0;
640
641         tab->setTabEnabled(tab->indexOf(optionstab), enabled);
642         extraED->setEnabled(enabled && !isBufferReadonly());
643         extraFormatCO->setEnabled(enabled);
644
645         if (enabled) {
646                 extraFormatCO->setCurrentIndex(0);
647                 extraED->setText(extra_[extraFormatCO->currentText()]);
648         }
649 }
650
651
652 void GuiExternal::applyView()
653 {
654         params_.filename.set(fromqstr(fileED->text()), fromqstr(bufferFilepath()));
655         params_.settemplate(getTemplate(externalCO->currentIndex()).lyxName);
656
657         params_.draft = draftCB->isChecked();
658         params_.lyxscale = displayscaleED->text().toInt();
659         params_.display = display(*displayCB, *showCO);
660
661         if (tab->isTabEnabled(tab->indexOf(rotatetab)))
662                 getRotation(params_.rotationdata, *angleED, *originCO);
663
664         if (tab->isTabEnabled(tab->indexOf(scaletab)))
665                 getSize(params_.resizedata, *widthED, *widthUnitCO,
666                         *heightED, *heightUnitCO, *aspectratioCB);
667
668         if (tab->isTabEnabled(tab->indexOf(croptab)))
669                 getCrop(params_.clipdata, *clipCB, *xlED, *ybED,
670                         *xrED, *ytED, bbChanged_);
671
672         if (tab->isTabEnabled(tab->indexOf(optionstab))) {
673                 MapType::const_iterator it = extra_.begin();
674                 MapType::const_iterator const end = extra_.end();
675                 for (; it != end; ++it)
676                         params_.extradata.set(fromqstr(it.key()), fromqstr(it.value().trimmed()));
677         }
678 }
679
680
681 bool GuiExternal::initialiseParams(string const & data)
682 {
683         InsetExternal::string2params(data, buffer(), params_);
684         return true;
685 }
686
687
688 void GuiExternal::clearParams()
689 {
690         params_ = InsetExternalParams();
691 }
692
693
694 void GuiExternal::dispatchParams()
695 {
696         string const lfun = InsetExternal::params2string(params_, buffer());
697         dispatch(FuncRequest(getLfun(), lfun));
698 }
699
700
701 void GuiExternal::editExternal()
702 {
703         applyView();
704         string const lfun = InsetExternal::params2string(params_, buffer());
705         dispatch(FuncRequest(LFUN_INSET_EDIT, lfun));
706 }
707
708
709 static QStringList templateFilters(QString const & template_name)
710 {
711         /// Determine the template file extension
712         external::TemplateManager const & etm =
713                 external::TemplateManager::get();
714         external::Template const * const et_ptr =
715                 etm.getTemplateByName(fromqstr(template_name));
716
717         return fileFilters(et_ptr ? toqstr(et_ptr->fileRegExp) : QString());
718 }
719
720
721 QString GuiExternal::browse(QString const & input,
722                                      QString const & template_name) const
723 {
724         QString const title = qt_("Select external file");
725         QString const bufpath = bufferFilepath();
726         QStringList const filter = templateFilters(template_name);
727
728         QString const label1 = qt_("Documents|#o#O");
729         QString const dir1 = toqstr(lyxrc.document_path);
730
731         return browseRelFile(input, bufpath, title, filter, false, label1, dir1);
732 }
733
734
735 Dialog * createGuiExternal(GuiView & lv) { return new GuiExternal(lv); }
736
737
738 } // namespace frontend
739 } // namespace lyx
740
741 #include "GuiExternal_moc.cpp"