3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Angus Leeming
7 * \author Jürgen Spitzmüller
9 * Full author contact details are available in file CREDITS.
14 #include "GuiSendto.h"
15 #include "qt_helpers.h"
18 #include "BufferParams.h"
20 #include "FuncRequest.h"
22 #include "support/filetools.h"
23 #include "support/gettext.h"
24 #include "support/qstring_helpers.h"
29 #include <QListWidget>
30 #include <QPushButton>
33 using namespace lyx::support;
39 GuiSendTo::GuiSendTo(GuiView & lv)
40 : GuiDialog(lv, "sendto", qt_("Export or Send Document")), format_(0)
44 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
45 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
46 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
48 connect(formatLW, SIGNAL(itemClicked(QListWidgetItem *)),
49 this, SLOT(slotFormatHighlighted(QListWidgetItem *)));
50 connect(formatLW, SIGNAL(itemActivated(QListWidgetItem *)),
51 this, SLOT(slotFormatSelected(QListWidgetItem *)));
52 connect(formatLW, SIGNAL(itemClicked(QListWidgetItem *)),
53 this, SLOT(changed_adaptor()));
54 connect(formatLW, SIGNAL(itemSelectionChanged()),
55 this, SLOT(changed_adaptor()));
56 connect(commandCO, SIGNAL(editTextChanged(QString)),
57 this, SLOT(changed_adaptor()));
59 bc().setPolicy(ButtonPolicy::OkApplyCancelPolicy);
61 bc().setApply(applyPB);
62 bc().setCancel(closePB);
66 void GuiSendTo::changed_adaptor()
72 void GuiSendTo::updateContents()
74 all_formats_ = buffer().params().exportableFormats(false);
75 sort(all_formats_.begin(), all_formats_.end(), Format::formatSorter);
76 // Save the current selection if any
77 Format const * current_format = nullptr;
78 int const line = formatLW->currentRow();
79 if (line >= 0 && static_cast<unsigned int>(line) < all_formats_.size()
80 && formatLW->selectedItems().size() > 0)
81 current_format = all_formats_[line];
82 // Reset the list widget
84 for (Format const * f : all_formats_) {
85 formatLW->addItem(toqstr(translateIfPossible(f->prettyname())));
86 // Restore the selection
87 if (current_format && f->prettyname() == current_format->prettyname())
88 formatLW->setCurrentRow(formatLW->count() - 1);
93 void GuiSendTo::applyView()
95 int const line = formatLW->currentRow();
96 QString const command = commandCO->currentText().trimmed();
98 if (commandCO->findText(command) == -1)
99 commandCO->insertItem(0, command);
101 if (line < 0 || line > formatLW->count())
104 format_ = all_formats_[line];
109 bool GuiSendTo::isValid()
111 int const line = formatLW->currentRow();
113 if (line < 0 || line > int(formatLW->count()))
116 return (formatLW->selectedItems().size() > 0
117 && formatLW->count() != 0);
121 bool GuiSendTo::initialiseParams(string const &)
124 paramsToDialog(format_, command_);
129 void GuiSendTo::paramsToDialog(Format const * /*format*/, QString const & command)
131 if (!command.isEmpty())
132 commandCO->addItem(command);
134 bc().setValid(isValid());
138 void GuiSendTo::dispatchParams()
140 if (!format_ || format_->name().empty())
143 string data = format_->name();
144 if (!command_.isEmpty())
145 data += " " + fromqstr(command_);
147 FuncCode const lfun = command_.isEmpty() ?
148 LFUN_BUFFER_EXPORT : getLfun();
150 dispatch(FuncRequest(lfun, data));
153 Dialog * createGuiSendTo(GuiView & lv) { return new GuiSendTo(lv); }
156 } // namespace frontend
159 #include "moc_GuiSendto.cpp"