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"
19 #include "FuncRequest.h"
21 #include "support/qstring_helpers.h"
22 #include "support/filetools.h"
25 #include <QListWidget>
26 #include <QPushButton>
29 using namespace lyx::support;
35 GuiSendTo::GuiSendTo(GuiView & lv)
36 : GuiDialog(lv, "sendto", qt_("Send Document to Command"))
40 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
41 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
42 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
44 connect(formatLW, SIGNAL(itemClicked(QListWidgetItem *)),
45 this, SLOT(slotFormatHighlighted(QListWidgetItem *)));
46 connect(formatLW, SIGNAL(itemActivated(QListWidgetItem *)),
47 this, SLOT(slotFormatSelected(QListWidgetItem *)));
48 connect(formatLW, SIGNAL(itemClicked(QListWidgetItem *)),
49 this, SLOT(changed_adaptor()));
50 connect(formatLW, SIGNAL(itemSelectionChanged()),
51 this, SLOT(changed_adaptor()));
52 connect(commandCO, SIGNAL(textChanged(QString)),
53 this, SLOT(changed_adaptor()));
55 bc().setPolicy(ButtonPolicy::OkApplyCancelPolicy);
57 bc().setApply(applyPB);
58 bc().setCancel(closePB);
62 void GuiSendTo::changed_adaptor()
68 void GuiSendTo::updateContents()
70 all_formats_ = buffer().exportableFormats(false);
72 // Save the current selection if any
73 Format const * current_format = 0;
74 int const line = formatLW->currentRow();
75 if (line >= 0 && line <= formatLW->count()
76 && formatLW->selectedItems().size() > 0)
77 current_format = all_formats_[line];
79 // Check whether the current contents of the browser will be
80 // changed by loading the contents of formats
82 keys.resize(all_formats_.size());
84 vector<string>::iterator result = keys.begin();
85 vector<Format const *>::const_iterator it = all_formats_.begin();
86 vector<Format const *>::const_iterator end = all_formats_.end();
88 int current_line = -1;
89 for (int ln = 0; it != end; ++it, ++result, ++ln) {
90 *result = (*it)->prettyname();
92 && (*it)->prettyname() == current_format->prettyname())
99 for (vector<string>::const_iterator it = keys.begin();
100 it != keys.end(); ++it) {
101 formatLW->addItem(qt_(*it));
104 // Restore the selection
105 if (current_line > -1)
106 formatLW->setCurrentItem(formatLW->item(current_line));
110 void GuiSendTo::applyView()
112 int const line = formatLW->currentRow();
113 QString const command = commandCO->currentText().trimmed();
115 if (commandCO->findText(command) == -1)
116 commandCO->insertItem(0, command);
118 if (line < 0 || line > formatLW->count())
121 format_ = all_formats_[line];
126 bool GuiSendTo::isValid()
128 int const line = formatLW->currentRow();
130 if (line < 0 || line > int(formatLW->count()))
133 return (formatLW->selectedItems().size() > 0
134 && formatLW->count() != 0
135 && !commandCO->currentText().isEmpty());
139 bool GuiSendTo::initialiseParams(string const &)
142 paramsToDialog(format_, command_);
147 void GuiSendTo::paramsToDialog(Format const * /*format*/, QString const & command)
149 if (!command.isEmpty())
150 commandCO->addItem(command);
152 bc().setValid(isValid());
156 void GuiSendTo::dispatchParams()
158 if (command_.isEmpty() || !format_ || format_->name().empty())
161 string const data = format_->name() + " " + fromqstr(command_);
162 dispatch(FuncRequest(getLfun(), data));
165 Dialog * createGuiSendTo(GuiView & lv) { return new GuiSendTo(lv); }
168 } // namespace frontend
171 #include "moc_GuiSendto.cpp"