GuiBibtex::GuiBibtex(LyXView & lv)
- : GuiDialog(lv, "bibtex"), ControlCommand(*this, "bibtex")
+ : GuiCommand(lv, "bibtex")
{
setupUi(this);
setViewTitle( _("BibTeX Bibliography"));
- setController(this, false);
QDialog::setModal(true);
databaseLW->clear();
- docstring bibs = params()["bibfiles"];
+ docstring bibs = params_["bibfiles"];
docstring bib;
while (!bibs.empty()) {
bibtocCB->setChecked(bibtotoc() && !bibtopic);
bibtocCB->setEnabled(!bibtopic);
- docstring btprint(params()["btprint"]);
+ docstring btprint = params_["btprint"];
int btp = 0;
if (btprint == "btPrintNotCited")
btp = 1;
dbs += qstring_to_ucs4(databaseLW->item(i)->text());
}
- params()["bibfiles"] = dbs;
+ params_["bibfiles"] = dbs;
- docstring const bibstyle(qstring_to_ucs4(styleCB->currentText()));
- bool const bibtotoc(bibtocCB->isChecked());
+ docstring const bibstyle = qstring_to_ucs4(styleCB->currentText());
+ bool const bibtotoc = bibtocCB->isChecked();
if (bibtotoc && (!bibstyle.empty())) {
// both bibtotoc and style
- params()["options"] = "bibtotoc," + bibstyle;
+ params_["options"] = "bibtotoc," + bibstyle;
} else if (bibtotoc) {
// bibtotoc and no style
- params()["options"] = from_ascii("bibtotoc");
+ params_["options"] = from_ascii("bibtotoc");
} else {
// only style. An empty one is valid, because some
// documentclasses have an own \bibliographystyle{}
// command!
- params()["options"] = bibstyle;
+ params_["options"] = bibstyle;
}
// bibtopic allows three kinds of sections:
switch (btp) {
case 0:
- params()["btprint"] = from_ascii("btPrintCited");
+ params_["btprint"] = from_ascii("btPrintCited");
break;
case 1:
- params()["btprint"] = from_ascii("btPrintNotCited");
+ params_["btprint"] = from_ascii("btPrintNotCited");
break;
case 2:
- params()["btprint"] = from_ascii("btPrintAll");
+ params_["btprint"] = from_ascii("btPrintAll");
break;
}
if (!usingBibtopic())
- params()["btprint"] = docstring();
+ params_["btprint"] = docstring();
}
bool GuiBibtex::bibtotoc() const
{
- return prefixIs(to_utf8(params()["options"]), "bibtotoc");
+ return prefixIs(to_utf8(params_["options"]), "bibtotoc");
}
break;
}
- docstring bst = params()["options"];
+ docstring bst = params_["options"];
if (bibtotoc()){
// bibstyle exists?
if (contains(bst, ',')) {
// propose default style file for new insets
// existing insets might have (legally) no bst files
// (if the class already provides a style)
- if (bst.empty() && params()["bibfiles"].empty())
+ if (bst.empty() && params_["bibfiles"].empty())
bst = defaultstyle;
// FIXME UNICODE
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
+ * \author Lars
+ * \author Asger and Jürgen
* \author John Levon
*
* Full author contact details are available in file CREDITS.
#include "GuiCommandEdit.h"
#include "qt_helpers.h"
+#include "BufferView.h"
+#include "Cursor.h"
+#include "LyXFunc.h"
+#include "LyXAction.h"
+#include "FuncRequest.h"
+
+#include "frontends/LyXView.h"
+
+#include "support/lyxalgo.h"
+#include "support/lstrings.h"
#include "support/filetools.h"
#include <QHBoxLayout>
#include <QToolTip>
#include <QVBoxLayout>
-using lyx::support::libFileSearch;
-
-using std::vector;
+using std::back_inserter;
+using std::transform;
using std::string;
+using std::vector;
+
namespace lyx {
namespace frontend {
+using support::prefixIs;
+using support::libFileSearch;
+
+
namespace {
class QTempListBox : public QListWidget {
GuiCommandBuffer::GuiCommandBuffer(GuiViewBase * view)
- : view_(view), controller_(*view)
+ : view_(view), lv_(*view), history_pos_(history_.end())
{
+ transform(lyxaction.func_begin(), lyxaction.func_end(),
+ back_inserter(commands_), firster());
+
QPixmap qpup(toqstr(libFileSearch("images", "up", "png").absFilename()));
QPixmap qpdown(toqstr(libFileSearch("images", "down", "png").absFilename()));
QPushButton * up = new QPushButton(qpup, "", this);
up->setMaximumSize(24, 24);
- up->setToolTip(qt_("Previous command"));
- connect(up, SIGNAL(clicked()), this, SLOT(up()));
QPushButton * down = new QPushButton(qpdown, "", this);
down->setToolTip(qt_("Next command"));
down->setMaximumSize(24, 24);
void GuiCommandBuffer::dispatch()
{
- controller_.dispatch(fromqstr(edit_->text()));
+ dispatch(fromqstr(edit_->text()));
view_->setFocus();
edit_->setText(QString());
edit_->clearFocus();
{
string const input = fromqstr(edit_->text());
string new_input;
- vector<string> comp = controller_.completions(input, new_input);
+ vector<string> comp = completions(input, new_input);
if (comp.empty() && new_input == input) {
// show_info_suffix(qt_("[no match]"), input);
void GuiCommandBuffer::up()
{
string const input = fromqstr(edit_->text());
- string const h = controller_.historyUp();
+ string const h = historyUp();
if (h.empty()) {
// show_info_suffix(qt_("[Beginning of history]"), input);
void GuiCommandBuffer::down()
{
string const input = fromqstr(edit_->text());
- string const h = controller_.historyDown();
+ string const h = historyDown();
if (h.empty()) {
// show_info_suffix(qt_("[End of history]"), input);
view_->setFocus();
edit_->setText(QString());
edit_->clearFocus();
- controller_.hide();
+ hide();
}
-#if 0
-void XMiniBuffer::show_info_suffix(string const & suffix, string const & input)
+namespace {
+
+class prefix_p {
+public:
+ string p;
+ prefix_p(string const & s) : p(s) {}
+ bool operator()(string const & s) const { return prefixIs(s, p); }
+};
+
+} // end of anon namespace
+
+
+string const GuiCommandBuffer::historyUp()
{
- stored_input_ = input;
- info_suffix_shown_ = true;
- set_input(input + ' ' + suffix);
- suffix_timer_->start();
+ if (history_pos_ == history_.begin())
+ return string();
+
+ return *(--history_pos_);
}
-void XMiniBuffer::suffix_timeout()
+string const GuiCommandBuffer::historyDown()
{
- info_suffix_shown_ = false;
- set_input(stored_input_);
+ if (history_pos_ == history_.end())
+ return string();
+ if (history_pos_ + 1 == history_.end())
+ return string();
+
+ return *(++history_pos_);
}
-#endif
+
+docstring const GuiCommandBuffer::getCurrentState() const
+{
+ return lv_.view()->cursor().currentState();
+}
+
+
+void GuiCommandBuffer::hide() const
+{
+ lv_.showMiniBuffer(false);
+}
+
+
+vector<string> const
+GuiCommandBuffer::completions(string const & prefix, string & new_prefix)
+{
+ vector<string> comp;
+
+ copy_if(commands_.begin(), commands_.end(),
+ back_inserter(comp), prefix_p(prefix));
+
+ if (comp.empty()) {
+ new_prefix = prefix;
+ return comp;
+ }
+
+ if (comp.size() == 1) {
+ new_prefix = comp[0];
+ return vector<string>();
+ }
+
+ // find maximal available prefix
+ string const tmp = comp[0];
+ string test = prefix;
+ if (tmp.length() > test.length())
+ test += tmp[test.length()];
+ while (test.length() < tmp.length()) {
+ vector<string> vtmp;
+ copy_if(comp.begin(), comp.end(),
+ back_inserter(vtmp), prefix_p(test));
+ if (vtmp.size() != comp.size()) {
+ test.erase(test.length() - 1);
+ break;
+ }
+ test += tmp[test.length()];
+ }
+
+ new_prefix = test;
+ return comp;
+}
+
+
+void GuiCommandBuffer::dispatch(string const & str)
+{
+ if (str.empty())
+ return;
+
+ history_.push_back(str);
+ history_pos_ = history_.end();
+ FuncRequest func = lyxaction.lookupFunc(str);
+ func.origin = FuncRequest::COMMANDBUFFER;
+ lv_.dispatch(func);
+}
} // namespace frontend
} // namespace lyx
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
+ * \author Lars
+ * \author Asger and Jürgen
* \author John Levon
*
* Full author contact details are available in file CREDITS.
#ifndef GUICOMMANDBUFFER_H
#define GUICOMMANDBUFFER_H
-#include "ControlCommandBuffer.h"
+#include "support/docstring.h"
#include <QWidget>
+#include <vector>
+
class QListWidgetItem;
namespace lyx {
namespace frontend {
+class LyXView;
+class GuiViewBase;
class GuiCommandEdit;
class GuiCommandBuffer : public QWidget
private:
/// owning view
GuiViewBase * view_;
- /// controller
- ControlCommandBuffer controller_;
+ ///
+ LyXView & lv_;
/// command widget
GuiCommandEdit * edit_;
+
+ /// return the previous history entry if any
+ std::string const historyUp();
+ /// return the next history entry if any
+ std::string const historyDown();
+
+ /// return the font and depth in the active BufferView as a message.
+ docstring const getCurrentState() const;
+
+ /// hide the command buffer.
+ void hide() const;
+
+ /// return the possible completions
+ std::vector<std::string> const completions(std::string const & prefix,
+ std::string & new_prefix);
+
+ /// dispatch a command
+ void dispatch(std::string const & str);
+
+ /// available command names
+ std::vector<std::string> commands_;
+
+ /// command history
+ std::vector<std::string> history_;
+
+ /// current position in command history
+ std::vector<std::string>::const_iterator history_pos_;
};
} // namespace frontend