]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiCommandBuffer.cpp
On Linux show in crash message box the backtrace
[lyx.git] / src / frontends / qt4 / GuiCommandBuffer.cpp
index dffe69bbe54ba858de40e979cf23e1e73c38fad4..f3179f0e84694f8ab145d16bd8af028026915ea5 100644 (file)
 
 #include "GuiCommandBuffer.h"
 
+#include "GuiApplication.h"
 #include "GuiCommandEdit.h"
 #include "GuiView.h"
 #include "qt_helpers.h"
 
 #include "BufferView.h"
 #include "Cursor.h"
-#include "LyXFunc.h"
+#include "LyX.h"
 #include "LyXAction.h"
 #include "FuncRequest.h"
 #include "Session.h"
@@ -87,8 +88,8 @@ GuiCommandBuffer::GuiCommandBuffer(GuiView * view)
        transform(lyxaction.func_begin(), lyxaction.func_end(),
                back_inserter(commands_), firster());
 
-       QPixmap qpup(":/images/up.png");
-       QPixmap qpdown(":/images/down.png");
+       QPixmap qpup = getPixmap("images/", "up", "png");
+       QPixmap qpdown = getPixmap("images/", "down", "png");
 
        QVBoxLayout * top = new QVBoxLayout(this);
        QHBoxLayout * layout = new QHBoxLayout(0);
@@ -146,7 +147,7 @@ void GuiCommandBuffer::cancel()
 
 void GuiCommandBuffer::dispatch()
 {
-       QString cmd = edit_->text();
+       QString const cmd = edit_->text();
        view_->setFocus();
        edit_->setText(QString());
        edit_->clearFocus();
@@ -172,7 +173,7 @@ void GuiCommandBuffer::complete()
 {
        string const input = fromqstr(edit_->text());
        string new_input;
-       vector<string> comp = completions(input, new_input);
+       vector<string> const & comp = completions(input, new_input);
 
        if (comp.empty()) {
                if (new_input != input)
@@ -194,30 +195,29 @@ void GuiCommandBuffer::showList(vector<string> const & list,
        // than the number of actual items...
        vector<string>::const_iterator cit = list.begin();
        vector<string>::const_iterator end = list.end();
-       if (!reversed) {
-               for (; cit != end; ++cit)
-                       listBox ->addItem(toqstr(*cit));
-       } else {
-               for (--end; end != cit; --end)
-                       listBox ->addItem(toqstr(*end));
+       for (; cit != end; ++cit) {
+               if (reversed)
+                       listBox->insertItem(0, toqstr(*cit));
+               else
+                       listBox->addItem(toqstr(*cit));
        }
 
-       listBox->resize(listBox ->sizeHint());
+       listBox->resize(listBox->sizeHint());
 
        int const y = max(0, pos.y() - listBox->height());
        listBox->move(pos.x(), y);
 
        connect(listBox, SIGNAL(itemClicked(QListWidgetItem *)),
-               this, SLOT(item_selected(QListWidgetItem *)));
+               this, SLOT(itemSelected(QListWidgetItem *)));
        connect(listBox, SIGNAL(itemActivated(QListWidgetItem *)),
-               this, SLOT(item_selected(QListWidgetItem *)));
+               this, SLOT(itemSelected(QListWidgetItem *)));
 
        listBox->show();
        listBox->setFocus();
 }
 
 
-void GuiCommandBuffer::item_selected(QListWidgetItem * item)
+void GuiCommandBuffer::itemSelected(QListWidgetItem * item)
 {
        QWidget const * widget = static_cast<QWidget const *>(sender());
        const_cast<QWidget *>(widget)->hide();
@@ -248,7 +248,8 @@ void GuiCommandBuffer::down()
        if (!h.empty())
                edit_->setText(toqstr(h));
 
-       downPB->setEnabled(history_pos_ != history_.end()-1);
+       downPB->setEnabled(!history_.empty()
+                          && history_pos_ != history_.end() - 1);
        upPB->setEnabled(history_pos_ != history_.begin());
 }
        
@@ -296,14 +297,13 @@ string const GuiCommandBuffer::historyDown()
 
 docstring const GuiCommandBuffer::getCurrentState() const
 {
-       return view_->view()->cursor().currentState();
+       return view_->currentBufferView()->cursor().currentState();
 }
 
 
 void GuiCommandBuffer::hide() const
 {
        FuncRequest cmd(LFUN_COMMAND_EXECUTE, "off");
-       theLyXFunc().setLyXView(view_);
        lyx::dispatch(cmd);
 }
 
@@ -313,7 +313,7 @@ GuiCommandBuffer::completions(string const & prefix, string & new_prefix)
 {
        vector<string> comp;
 
-       copy_if(commands_.begin(), commands_.end(),
+       lyx::copy_if(commands_.begin(), commands_.end(),
                back_inserter(comp), prefix_p(prefix));
 
        if (comp.empty()) {
@@ -333,7 +333,7 @@ GuiCommandBuffer::completions(string const & prefix, string & new_prefix)
                test += tmp[test.length()];
        while (test.length() < tmp.length()) {
                vector<string> vtmp;
-               copy_if(comp.begin(), comp.end(),
+               lyx::copy_if(comp.begin(), comp.end(),
                        back_inserter(vtmp), prefix_p(test));
                if (vtmp.size() != comp.size()) {
                        test.erase(test.length() - 1);
@@ -357,8 +357,7 @@ void GuiCommandBuffer::dispatch(string const & str)
        upPB->setEnabled(history_pos_ != history_.begin());
        downPB->setEnabled(history_pos_ != history_.end());
        FuncRequest func = lyxaction.lookupFunc(str);
-       func.origin = FuncRequest::COMMANDBUFFER;
-       theLyXFunc().setLyXView(view_);
+       func.setOrigin(FuncRequest::COMMANDBUFFER);
        lyx::dispatch(func);
 }