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"
19 #include "Converter.h"
21 #include "FuncRequest.h"
24 #include "support/qstring_helpers.h"
25 #include "support/filetools.h"
28 #include <QListWidget>
29 #include <QPushButton>
32 using namespace lyx::support;
38 GuiSendTo::GuiSendTo(GuiView & lv)
39 : GuiDialog(lv, "sendto", qt_("Send Document to Command"))
43 connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
44 connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
45 connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
47 connect(formatLW, SIGNAL(itemClicked(QListWidgetItem *)),
48 this, SLOT(slotFormatHighlighted(QListWidgetItem *)));
49 connect(formatLW, SIGNAL(itemActivated(QListWidgetItem *)),
50 this, SLOT(slotFormatSelected(QListWidgetItem *)));
51 connect(formatLW, SIGNAL(itemClicked(QListWidgetItem *)),
52 this, SLOT(changed_adaptor()));
53 connect(formatLW, SIGNAL(itemSelectionChanged()),
54 this, SLOT(changed_adaptor()));
55 connect(commandCO, SIGNAL(textChanged(QString)),
56 this, SLOT(changed_adaptor()));
58 bc().setPolicy(ButtonPolicy::OkApplyCancelPolicy);
60 bc().setApply(applyPB);
61 bc().setCancel(closePB);
65 void GuiSendTo::changed_adaptor()
71 void GuiSendTo::updateContents()
73 all_formats_ = buffer().exportableFormats(false);
75 // Save the current selection if any
76 Format const * current_format = 0;
77 int const line = formatLW->currentRow();
78 if (line >= 0 && line <= formatLW->count()
79 && formatLW->selectedItems().size() > 0)
80 current_format = all_formats_[line];
82 // Check whether the current contents of the browser will be
83 // changed by loading the contents of formats
85 keys.resize(all_formats_.size());
87 vector<string>::iterator result = keys.begin();
88 vector<Format const *>::const_iterator it = all_formats_.begin();
89 vector<Format const *>::const_iterator end = all_formats_.end();
91 int current_line = -1;
92 for (int ln = 0; it != end; ++it, ++result, ++ln) {
93 *result = (*it)->prettyname();
95 && (*it)->prettyname() == current_format->prettyname())
102 for (vector<string>::const_iterator it = keys.begin();
103 it != keys.end(); ++it) {
104 formatLW->addItem(qt_(*it));
107 // Restore the selection
108 if (current_line > -1)
109 formatLW->setCurrentItem(formatLW->item(current_line));
113 void GuiSendTo::applyView()
115 int const line = formatLW->currentRow();
116 QString const command = commandCO->currentText().trimmed();
118 if (commandCO->findText(command) == -1)
119 commandCO->insertItem(0, command);
121 if (line < 0 || line > formatLW->count())
124 format_ = all_formats_[line];
129 bool GuiSendTo::isValid()
131 int const line = formatLW->currentRow();
133 if (line < 0 || line > int(formatLW->count()))
136 return (formatLW->selectedItems().size() > 0
137 && formatLW->count() != 0
138 && !commandCO->currentText().isEmpty());
142 bool GuiSendTo::initialiseParams(string const &)
145 paramsToDialog(format_, command_);
150 void GuiSendTo::paramsToDialog(Format const * /*format*/, QString const & command)
152 if (!command.isEmpty())
153 commandCO->addItem(command);
155 bc().setValid(isValid());
159 void GuiSendTo::dispatchParams()
161 if (command_.isEmpty() || !format_ || format_->name().empty())
164 string const data = format_->name() + " " + fromqstr(command_);
165 dispatch(FuncRequest(getLfun(), data));
168 Dialog * createGuiSendTo(GuiView & lv) { return new GuiSendTo(lv); }
171 } // namespace frontend
174 #include "moc_GuiSendto.cpp"