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