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