]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiCommandBuffer.cpp
Use QFontMetrics information for underlines (and friends) width and position
[lyx.git] / src / frontends / qt4 / GuiCommandBuffer.cpp
index 5f48010d761c7884257f3bb402a10694048ab981..9880e2b996a37a6f60929ef61281b139ff85a936 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", "svgz,png");
+       QPixmap qpdown = getPixmap("images/", "down", "svgz,png");
 
        QVBoxLayout * top = new QVBoxLayout(this);
        QHBoxLayout * layout = new QHBoxLayout(0);
@@ -107,12 +108,11 @@ GuiCommandBuffer::GuiCommandBuffer(GuiView * view)
        edit_->setMinimumSize(edit_->sizeHint());
        edit_->setFocusPolicy(Qt::ClickFocus);
 
-       connect(edit_, SIGNAL(escapePressed()), this, SLOT(cancel()));
        connect(edit_, SIGNAL(returnPressed()), this, SLOT(dispatch()));
        connect(edit_, SIGNAL(tabPressed()), this, SLOT(complete()));
        connect(edit_, SIGNAL(upPressed()), this, SLOT(up()));
        connect(edit_, SIGNAL(downPressed()), this, SLOT(down()));
-       connect(edit_, SIGNAL(hidePressed()), this, SLOT(hideParent()));
+       connect(edit_, SIGNAL(escapePressed()), this, SLOT(hideParent()));
 
        layout->addWidget(upPB, 0);
        layout->addWidget(downPB, 0);
@@ -137,22 +137,19 @@ GuiCommandBuffer::GuiCommandBuffer(GuiView * view)
 }
 
 
-void GuiCommandBuffer::cancel()
-{
-       view_->setFocus();
-       edit_->setText(QString());
-}
-
-
 void GuiCommandBuffer::dispatch()
 {
-       QString cmd = edit_->text();
-       view_->setFocus();
-       edit_->setText(QString());
-       edit_->clearFocus();
-       std::string const cmd_ = fromqstr(cmd);
-       theSession().lastCommands().add(cmd_);
-       dispatch(cmd_);
+       std::string const cmd = fromqstr(edit_->text());
+       if (!cmd.empty())
+               theSession().lastCommands().add(cmd);
+       DispatchResult const & dr = dispatch(cmd);
+       if (!dr.error()) {
+               view_->setFocus();
+               edit_->setText(QString());
+               edit_->clearFocus();
+               // If the toolbar was "auto", it is not needed anymore
+               view_->resetCommandExecute();
+       }
 }
 
 
@@ -207,16 +204,16 @@ void GuiCommandBuffer::showList(vector<string> const & list,
        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();
@@ -247,7 +244,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());
 }
        
@@ -255,9 +253,9 @@ void GuiCommandBuffer::down()
 void GuiCommandBuffer::hideParent()
 {
        view_->setFocus();
+       view_->resetCommandExecute();
        edit_->setText(QString());
        edit_->clearFocus();
-       hide();
 }
 
 
@@ -295,15 +293,7 @@ string const GuiCommandBuffer::historyDown()
 
 docstring const GuiCommandBuffer::getCurrentState() const
 {
-       return view_->view()->cursor().currentState();
-}
-
-
-void GuiCommandBuffer::hide() const
-{
-       FuncRequest cmd(LFUN_COMMAND_EXECUTE, "off");
-       theLyXFunc().setLyXView(view_);
-       lyx::dispatch(cmd);
+       return view_->currentBufferView()->cursor().currentState();
 }
 
 
@@ -312,7 +302,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()) {
@@ -332,7 +322,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);
@@ -346,19 +336,20 @@ GuiCommandBuffer::completions(string const & prefix, string & new_prefix)
 }
 
 
-void GuiCommandBuffer::dispatch(string const & str)
+DispatchResult const & GuiCommandBuffer::dispatch(string const & str)
 {
-       if (str.empty())
-               return;
+       if (str.empty()) {
+               static DispatchResult empty_dr;
+               return empty_dr;
+       }
 
        history_.push_back(trim(str));
        history_pos_ = history_.end();
        upPB->setEnabled(history_pos_ != history_.begin());
        downPB->setEnabled(history_pos_ != history_.end());
        FuncRequest func = lyxaction.lookupFunc(str);
-       func.origin = FuncRequest::COMMANDBUFFER;
-       theLyXFunc().setLyXView(view_);
-       lyx::dispatch(func);
+       func.setOrigin(FuncRequest::COMMANDBUFFER);
+       return lyx::dispatch(func);
 }
 
 } // namespace frontend