]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiCommandBuffer.cpp
Revert "Mark some intentional fall-throughs (in a way understandable to gcc)"
[lyx.git] / src / frontends / qt4 / GuiCommandBuffer.cpp
index f3179f0e84694f8ab145d16bd8af028026915ea5..4d94d97738af0af4d8aac90d9487bdd6abf1686e 100644 (file)
@@ -79,7 +79,7 @@ protected:
        }
 };
 
-} // end of anon
+} // namespace
 
 
 GuiCommandBuffer::GuiCommandBuffer(GuiView * view)
@@ -88,32 +88,37 @@ GuiCommandBuffer::GuiCommandBuffer(GuiView * view)
        transform(lyxaction.func_begin(), lyxaction.func_end(),
                back_inserter(commands_), firster());
 
-       QPixmap qpup = getPixmap("images/", "up", "png");
-       QPixmap qpdown = getPixmap("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);
 
+       edit_ = new GuiCommandEdit(this);
+       edit_->setMinimumSize(edit_->sizeHint());
+       edit_->setFocusPolicy(Qt::ClickFocus);
+
+       int height = max(24, 2 * (edit_->sizeHint().height() / 2));
+       QSize button_size = QSize(height, height);
+       QSize icon_size = button_size - QSize(4, 4);
+
        upPB = new QPushButton(qpup, "", this);
        upPB->setToolTip(qt_("List of previous commands"));
-       upPB->setMaximumSize(24, 24);
+       upPB->setMaximumSize(button_size);
+       upPB->setIconSize(icon_size);
        downPB = new QPushButton(qpdown, "", this);
        downPB->setToolTip(qt_("Next command"));
-       downPB->setMaximumSize(24, 24);
+       downPB->setMaximumSize(button_size);
+       downPB->setIconSize(icon_size);
        downPB->setEnabled(false);
        connect(downPB, SIGNAL(clicked()), this, SLOT(down()));
        connect(upPB, SIGNAL(pressed()), this, SLOT(listHistoryUp()));
 
-       edit_ = new GuiCommandEdit(this);
-       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);
@@ -123,11 +128,11 @@ GuiCommandBuffer::GuiCommandBuffer(GuiView * view)
        top->setMargin(0);
        setFocusProxy(edit_);
 
-       LastCommandsSection::LastCommands last_commands 
+       LastCommandsSection::LastCommands last_commands
                = theSession().lastCommands().getcommands();
-       LastCommandsSection::LastCommands::const_iterator it 
+       LastCommandsSection::LastCommands::const_iterator it
                = last_commands.begin();
-       LastCommandsSection::LastCommands::const_iterator end 
+       LastCommandsSection::LastCommands::const_iterator end
                = last_commands.end();
 
        upPB->setEnabled(it != end);
@@ -138,22 +143,19 @@ GuiCommandBuffer::GuiCommandBuffer(GuiView * view)
 }
 
 
-void GuiCommandBuffer::cancel()
-{
-       view_->setFocus();
-       edit_->setText(QString());
-}
-
-
 void GuiCommandBuffer::dispatch()
 {
-       QString const 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();
+       }
 }
 
 
@@ -229,7 +231,6 @@ void GuiCommandBuffer::itemSelected(QListWidgetItem * item)
 
 void GuiCommandBuffer::up()
 {
-       string const input = fromqstr(edit_->text());
        string const h = historyUp();
 
        if (!h.empty())
@@ -242,7 +243,6 @@ void GuiCommandBuffer::up()
 
 void GuiCommandBuffer::down()
 {
-       string const input = fromqstr(edit_->text());
        string const h = historyDown();
 
        if (!h.empty())
@@ -252,14 +252,14 @@ void GuiCommandBuffer::down()
                           && history_pos_ != history_.end() - 1);
        upPB->setEnabled(history_pos_ != history_.begin());
 }
-       
+
 
 void GuiCommandBuffer::hideParent()
 {
        view_->setFocus();
+       view_->resetCommandExecute();
        edit_->setText(QString());
        edit_->clearFocus();
-       hide();
 }
 
 
@@ -272,7 +272,7 @@ public:
        bool operator()(string const & s) const { return prefixIs(s, p); }
 };
 
-} // end of anon namespace
+} // namespace
 
 
 string const GuiCommandBuffer::historyUp()
@@ -295,19 +295,6 @@ string const GuiCommandBuffer::historyDown()
 }
 
 
-docstring const GuiCommandBuffer::getCurrentState() const
-{
-       return view_->currentBufferView()->cursor().currentState();
-}
-
-
-void GuiCommandBuffer::hide() const
-{
-       FuncRequest cmd(LFUN_COMMAND_EXECUTE, "off");
-       lyx::dispatch(cmd);
-}
-
-
 vector<string> const
 GuiCommandBuffer::completions(string const & prefix, string & new_prefix)
 {
@@ -347,10 +334,12 @@ 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();
@@ -358,7 +347,7 @@ void GuiCommandBuffer::dispatch(string const & str)
        downPB->setEnabled(history_pos_ != history_.end());
        FuncRequest func = lyxaction.lookupFunc(str);
        func.setOrigin(FuncRequest::COMMANDBUFFER);
-       lyx::dispatch(func);
+       return lyx::dispatch(func);
 }
 
 } // namespace frontend