2006-03-05 17:24:44 +00:00
|
|
|
/**
|
2007-08-31 05:53:55 +00:00
|
|
|
* \file GuiCommandBuffer.cpp
|
2006-03-05 17:24:44 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
2007-10-07 18:40:01 +00:00
|
|
|
* \author Lars
|
|
|
|
* \author Asger and Jürgen
|
2006-03-05 17:24:44 +00:00
|
|
|
* \author John Levon
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
#include "GuiCommandBuffer.h"
|
2007-11-13 14:04:32 +00:00
|
|
|
|
2009-04-03 17:00:09 +00:00
|
|
|
#include "GuiApplication.h"
|
2007-08-31 05:53:55 +00:00
|
|
|
#include "GuiCommandEdit.h"
|
2007-11-13 14:04:32 +00:00
|
|
|
#include "GuiView.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "qt_helpers.h"
|
|
|
|
|
2007-10-07 18:40:01 +00:00
|
|
|
#include "BufferView.h"
|
|
|
|
#include "Cursor.h"
|
2010-02-09 16:11:13 +00:00
|
|
|
#include "LyX.h"
|
2007-10-07 18:40:01 +00:00
|
|
|
#include "LyXAction.h"
|
|
|
|
#include "FuncRequest.h"
|
2009-01-18 21:50:23 +00:00
|
|
|
#include "Session.h"
|
2007-10-07 18:40:01 +00:00
|
|
|
|
|
|
|
#include "support/lstrings.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-10-22 14:37:32 +00:00
|
|
|
#include <QHBoxLayout>
|
|
|
|
#include <QKeyEvent>
|
|
|
|
#include <QListWidget>
|
|
|
|
#include <QMouseEvent>
|
|
|
|
#include <QPixmap>
|
2006-03-05 17:24:44 +00:00
|
|
|
#include <QPushButton>
|
2006-10-22 14:37:32 +00:00
|
|
|
#include <QToolTip>
|
|
|
|
#include <QVBoxLayout>
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2007-12-12 18:57:56 +00:00
|
|
|
using namespace lyx::support;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2022-07-13 16:56:10 +02:00
|
|
|
// Simple wrapper around the LastCommand session stuff.
|
|
|
|
|
|
|
|
// The whole last commands list
|
|
|
|
vector<string> const & history() { return theSession().lastCommands().getcommands(); }
|
|
|
|
|
|
|
|
// add command to the list (and remove duplicates)
|
|
|
|
void addHistory(string const & cmd) { theSession().lastCommands().add(cmd); }
|
|
|
|
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
class QTempListBox : public QListWidget {
|
|
|
|
public:
|
|
|
|
QTempListBox() {
|
|
|
|
//setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
|
|
|
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
setWindowModality(Qt::WindowModal);
|
|
|
|
setWindowFlags(Qt::Popup);
|
|
|
|
setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
}
|
|
|
|
protected:
|
2020-10-01 10:42:11 +03:00
|
|
|
bool event(QEvent * ev) override {
|
2009-01-18 21:50:23 +00:00
|
|
|
if (ev->type() == QEvent::MouseButtonPress) {
|
|
|
|
QMouseEvent * me = static_cast<QMouseEvent *>(ev);
|
2021-03-21 12:38:05 +01:00
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
|
|
|
if (me->position().x() < 0 || me->position().y() < 0
|
|
|
|
|| me->position().x() > width() || me->position().y() > height())
|
|
|
|
#else
|
2009-01-18 21:50:23 +00:00
|
|
|
if (me->x() < 0 || me->y() < 0
|
|
|
|
|| me->x() > width() || me->y() > height())
|
2021-03-21 12:38:05 +01:00
|
|
|
#endif
|
2009-01-18 21:50:23 +00:00
|
|
|
hide();
|
|
|
|
return true;
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
2009-01-18 21:50:23 +00:00
|
|
|
return QListWidget::event(ev);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2020-10-01 10:42:11 +03:00
|
|
|
void keyPressEvent(QKeyEvent * ev) override {
|
2006-10-22 14:37:32 +00:00
|
|
|
if (ev->key() == Qt::Key_Escape) {
|
2006-03-05 17:24:44 +00:00
|
|
|
hide();
|
|
|
|
return;
|
2007-06-21 06:38:50 +00:00
|
|
|
} else if (ev->key() == Qt::Key_Return || ev->key() == Qt::Key_Space) {
|
|
|
|
// emit signal
|
2009-01-18 21:50:23 +00:00
|
|
|
itemClicked(currentItem());
|
2007-06-21 06:38:50 +00:00
|
|
|
} else
|
|
|
|
QListWidget::keyPressEvent(ev);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-07-23 13:11:54 +02:00
|
|
|
} // namespace
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
|
2007-11-05 13:52:37 +00:00
|
|
|
GuiCommandBuffer::GuiCommandBuffer(GuiView * view)
|
2009-01-18 21:50:23 +00:00
|
|
|
: view_(view)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2015-03-13 00:47:21 +01:00
|
|
|
QPixmap qpup = getPixmap("images/", "up", "svgz,png");
|
|
|
|
QPixmap qpdown = getPixmap("images/", "down", "svgz,png");
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
QVBoxLayout * top = new QVBoxLayout(this);
|
|
|
|
QHBoxLayout * layout = new QHBoxLayout(0);
|
|
|
|
|
2016-06-26 16:58:18 +02:00
|
|
|
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);
|
|
|
|
|
2009-01-18 21:50:23 +00:00
|
|
|
upPB = new QPushButton(qpup, "", this);
|
|
|
|
upPB->setToolTip(qt_("List of previous commands"));
|
2016-06-26 16:58:18 +02:00
|
|
|
upPB->setMaximumSize(button_size);
|
|
|
|
upPB->setIconSize(icon_size);
|
2009-01-18 21:50:23 +00:00
|
|
|
downPB = new QPushButton(qpdown, "", this);
|
|
|
|
downPB->setToolTip(qt_("Next command"));
|
2016-06-26 16:58:18 +02:00
|
|
|
downPB->setMaximumSize(button_size);
|
|
|
|
downPB->setIconSize(icon_size);
|
2009-01-18 21:50:23 +00:00
|
|
|
downPB->setEnabled(false);
|
|
|
|
connect(downPB, SIGNAL(clicked()), this, SLOT(down()));
|
|
|
|
connect(upPB, SIGNAL(pressed()), this, SLOT(listHistoryUp()));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
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()));
|
2015-04-18 19:10:33 +02:00
|
|
|
connect(edit_, SIGNAL(escapePressed()), this, SLOT(hideParent()));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2009-01-18 21:50:23 +00:00
|
|
|
layout->addWidget(upPB, 0);
|
|
|
|
layout->addWidget(downPB, 0);
|
2006-03-05 17:24:44 +00:00
|
|
|
layout->addWidget(edit_, 10);
|
Allow compiling with Qt6
This commit allows compiling LyX with Qt6 when using autotools.
For a successful compilation the following 2 conditions must be met.
1) The Qt6 qmake has to come first in PATH, so that the command
"qmake -v | grep -o 'Qt version .'" returns "Qt version 6".
2) The --enable-qt6 switch has to be passed to the configure command.
If --enable-qt6 is used but Qt6 is not found, Qt5 is tried as a fallback.
If also Qt5 is not found, configuring for Qt4 is attempted.
If --enable-qt6 is not used, then things go as usual. This means that Qt5
is tried first and then Qt4, unless --disable-qt5 is used, in which case
Qt4 is directly attempted. This means that existing scripts should
continue working unmodified.
LyX should compile with Qt6 on windows and linux, and possibly also on
mac, but I could not test that. However, it is not guaranteed that it
works as it should. In particular I am not sure that I got right the
conversion from QRegExp to QRegularExpression. For sure, the syntax
highlighting seems to not work right. Someone in the know should take
a look at that. I am able to load documents and compile them but some
thourough testing is needed. However, when compiling for Qt5 or Qt4,
I tried to make sure that the functionality is preserved.
2021-03-15 17:09:09 +01:00
|
|
|
#if QT_VERSION < 0x060000
|
2006-10-22 14:37:32 +00:00
|
|
|
layout->setMargin(0);
|
Allow compiling with Qt6
This commit allows compiling LyX with Qt6 when using autotools.
For a successful compilation the following 2 conditions must be met.
1) The Qt6 qmake has to come first in PATH, so that the command
"qmake -v | grep -o 'Qt version .'" returns "Qt version 6".
2) The --enable-qt6 switch has to be passed to the configure command.
If --enable-qt6 is used but Qt6 is not found, Qt5 is tried as a fallback.
If also Qt5 is not found, configuring for Qt4 is attempted.
If --enable-qt6 is not used, then things go as usual. This means that Qt5
is tried first and then Qt4, unless --disable-qt5 is used, in which case
Qt4 is directly attempted. This means that existing scripts should
continue working unmodified.
LyX should compile with Qt6 on windows and linux, and possibly also on
mac, but I could not test that. However, it is not guaranteed that it
works as it should. In particular I am not sure that I got right the
conversion from QRegExp to QRegularExpression. For sure, the syntax
highlighting seems to not work right. Someone in the know should take
a look at that. I am able to load documents and compile them but some
thourough testing is needed. However, when compiling for Qt5 or Qt4,
I tried to make sure that the functionality is preserved.
2021-03-15 17:09:09 +01:00
|
|
|
#else
|
|
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
#endif
|
2006-03-05 17:24:44 +00:00
|
|
|
top->addLayout(layout);
|
Allow compiling with Qt6
This commit allows compiling LyX with Qt6 when using autotools.
For a successful compilation the following 2 conditions must be met.
1) The Qt6 qmake has to come first in PATH, so that the command
"qmake -v | grep -o 'Qt version .'" returns "Qt version 6".
2) The --enable-qt6 switch has to be passed to the configure command.
If --enable-qt6 is used but Qt6 is not found, Qt5 is tried as a fallback.
If also Qt5 is not found, configuring for Qt4 is attempted.
If --enable-qt6 is not used, then things go as usual. This means that Qt5
is tried first and then Qt4, unless --disable-qt5 is used, in which case
Qt4 is directly attempted. This means that existing scripts should
continue working unmodified.
LyX should compile with Qt6 on windows and linux, and possibly also on
mac, but I could not test that. However, it is not guaranteed that it
works as it should. In particular I am not sure that I got right the
conversion from QRegExp to QRegularExpression. For sure, the syntax
highlighting seems to not work right. Someone in the know should take
a look at that. I am able to load documents and compile them but some
thourough testing is needed. However, when compiling for Qt5 or Qt4,
I tried to make sure that the functionality is preserved.
2021-03-15 17:09:09 +01:00
|
|
|
#if QT_VERSION < 0x060000
|
2006-10-22 14:37:32 +00:00
|
|
|
top->setMargin(0);
|
Allow compiling with Qt6
This commit allows compiling LyX with Qt6 when using autotools.
For a successful compilation the following 2 conditions must be met.
1) The Qt6 qmake has to come first in PATH, so that the command
"qmake -v | grep -o 'Qt version .'" returns "Qt version 6".
2) The --enable-qt6 switch has to be passed to the configure command.
If --enable-qt6 is used but Qt6 is not found, Qt5 is tried as a fallback.
If also Qt5 is not found, configuring for Qt4 is attempted.
If --enable-qt6 is not used, then things go as usual. This means that Qt5
is tried first and then Qt4, unless --disable-qt5 is used, in which case
Qt4 is directly attempted. This means that existing scripts should
continue working unmodified.
LyX should compile with Qt6 on windows and linux, and possibly also on
mac, but I could not test that. However, it is not guaranteed that it
works as it should. In particular I am not sure that I got right the
conversion from QRegExp to QRegularExpression. For sure, the syntax
highlighting seems to not work right. Someone in the know should take
a look at that. I am able to load documents and compile them but some
thourough testing is needed. However, when compiling for Qt5 or Qt4,
I tried to make sure that the functionality is preserved.
2021-03-15 17:09:09 +01:00
|
|
|
#else
|
|
|
|
top->setContentsMargins(0, 0, 0, 0);
|
|
|
|
#endif
|
2007-08-24 07:13:07 +00:00
|
|
|
setFocusProxy(edit_);
|
2009-01-18 21:50:23 +00:00
|
|
|
|
2022-07-13 16:56:10 +02:00
|
|
|
upPB->setEnabled(!history().empty());
|
2009-01-18 21:50:23 +00:00
|
|
|
|
2022-07-13 16:56:10 +02:00
|
|
|
history_pos_ = history().end();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiCommandBuffer::dispatch()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2015-04-18 19:10:33 +02:00
|
|
|
std::string const cmd = fromqstr(edit_->text());
|
|
|
|
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();
|
|
|
|
}
|
2009-01-18 21:50:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiCommandBuffer::listHistoryUp()
|
|
|
|
{
|
2022-07-13 16:56:10 +02:00
|
|
|
if (history().size() == 1) {
|
|
|
|
edit_->setText(toqstr(history().back()));
|
2009-01-18 21:50:23 +00:00
|
|
|
upPB->setEnabled(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QPoint const & pos = upPB->mapToGlobal(QPoint(0, 0));
|
2022-07-13 16:56:10 +02:00
|
|
|
showList(history(), pos, true);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiCommandBuffer::complete()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
string const input = fromqstr(edit_->text());
|
|
|
|
string new_input;
|
2009-03-15 13:20:15 +00:00
|
|
|
vector<string> const & comp = completions(input, new_input);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2022-08-06 07:13:51 +02:00
|
|
|
if (comp.empty() || comp.size() == 1) {
|
2009-01-18 21:50:23 +00:00
|
|
|
if (new_input != input)
|
|
|
|
edit_->setText(toqstr(new_input));
|
2022-08-06 07:13:51 +02:00
|
|
|
// If there is only one match, indicate this by adding a space
|
|
|
|
if (comp.size() == 1)
|
|
|
|
edit_->setText(edit_->text() + " ");
|
2006-03-05 17:24:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
edit_->setText(toqstr(new_input));
|
2009-01-18 21:50:23 +00:00
|
|
|
QPoint const & pos = edit_->mapToGlobal(QPoint(0, 0));
|
|
|
|
showList(comp, pos);
|
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2009-01-18 21:50:23 +00:00
|
|
|
void GuiCommandBuffer::showList(vector<string> const & list,
|
|
|
|
QPoint const & pos, bool reversed) const
|
|
|
|
{
|
|
|
|
QTempListBox * listBox = new QTempListBox;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
// For some reason the scrollview's contents are larger
|
|
|
|
// than the number of actual items...
|
2022-07-13 16:56:10 +02:00
|
|
|
for (auto const & item : list) {
|
2009-03-15 13:20:15 +00:00
|
|
|
if (reversed)
|
2022-07-13 16:56:10 +02:00
|
|
|
listBox->insertItem(0, toqstr(item));
|
2009-03-15 13:20:15 +00:00
|
|
|
else
|
2022-07-13 16:56:10 +02:00
|
|
|
listBox->addItem(toqstr(item));
|
2009-01-18 21:50:23 +00:00
|
|
|
}
|
2022-08-06 07:13:51 +02:00
|
|
|
// Select the first item
|
|
|
|
listBox->setCurrentItem(listBox->item(0));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2009-03-15 13:20:15 +00:00
|
|
|
listBox->resize(listBox->sizeHint());
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2009-01-18 21:50:23 +00:00
|
|
|
int const y = max(0, pos.y() - listBox->height());
|
|
|
|
listBox->move(pos.x(), y);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2009-01-18 21:50:23 +00:00
|
|
|
connect(listBox, SIGNAL(itemClicked(QListWidgetItem *)),
|
2009-05-23 09:40:44 +00:00
|
|
|
this, SLOT(itemSelected(QListWidgetItem *)));
|
2009-01-18 21:50:23 +00:00
|
|
|
connect(listBox, SIGNAL(itemActivated(QListWidgetItem *)),
|
2009-05-23 09:40:44 +00:00
|
|
|
this, SLOT(itemSelected(QListWidgetItem *)));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2009-01-18 21:50:23 +00:00
|
|
|
listBox->show();
|
|
|
|
listBox->setFocus();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-23 09:40:44 +00:00
|
|
|
void GuiCommandBuffer::itemSelected(QListWidgetItem * item)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
QWidget const * widget = static_cast<QWidget const *>(sender());
|
|
|
|
const_cast<QWidget *>(widget)->hide();
|
2009-01-18 21:50:23 +00:00
|
|
|
edit_->setText(item->text()+ ' ');
|
2007-06-21 06:38:50 +00:00
|
|
|
edit_->activateWindow();
|
2006-03-05 17:24:44 +00:00
|
|
|
edit_->setFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiCommandBuffer::up()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-10-07 18:40:01 +00:00
|
|
|
string const h = historyUp();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2009-01-18 21:50:23 +00:00
|
|
|
if (!h.empty())
|
2006-03-05 17:24:44 +00:00
|
|
|
edit_->setText(toqstr(h));
|
2009-01-18 21:50:23 +00:00
|
|
|
|
2022-07-13 16:56:10 +02:00
|
|
|
upPB->setEnabled(history_pos_ != history().begin());
|
|
|
|
downPB->setEnabled(history_pos_ != history().end());
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiCommandBuffer::down()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-10-07 18:40:01 +00:00
|
|
|
string const h = historyDown();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2009-01-18 21:50:23 +00:00
|
|
|
if (!h.empty())
|
2006-03-05 17:24:44 +00:00
|
|
|
edit_->setText(toqstr(h));
|
|
|
|
|
2022-07-13 16:56:10 +02:00
|
|
|
downPB->setEnabled(!history().empty()
|
|
|
|
&& history_pos_ != history().end() - 1);
|
|
|
|
upPB->setEnabled(history_pos_ != history().begin());
|
2009-01-18 21:50:23 +00:00
|
|
|
}
|
2017-07-03 13:53:14 -04:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiCommandBuffer::hideParent()
|
2007-04-29 08:58:09 +00:00
|
|
|
{
|
|
|
|
view_->setFocus();
|
2015-04-18 19:10:33 +02:00
|
|
|
view_->resetCommandExecute();
|
2007-04-29 08:58:09 +00:00
|
|
|
edit_->setText(QString());
|
|
|
|
edit_->clearFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-07 18:40:01 +00:00
|
|
|
string const GuiCommandBuffer::historyUp()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2022-07-13 16:56:10 +02:00
|
|
|
if (history_pos_ == history().begin())
|
2007-10-07 18:40:01 +00:00
|
|
|
return string();
|
|
|
|
|
|
|
|
return *(--history_pos_);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-07 18:40:01 +00:00
|
|
|
string const GuiCommandBuffer::historyDown()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2022-07-13 16:56:10 +02:00
|
|
|
if (history_pos_ == history().end())
|
2007-10-07 18:40:01 +00:00
|
|
|
return string();
|
2022-07-13 16:56:10 +02:00
|
|
|
if (history_pos_ + 1 == history().end())
|
2007-10-07 18:40:01 +00:00
|
|
|
return string();
|
|
|
|
|
|
|
|
return *(++history_pos_);
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2007-10-07 18:40:01 +00:00
|
|
|
|
|
|
|
vector<string> const
|
|
|
|
GuiCommandBuffer::completions(string const & prefix, string & new_prefix)
|
|
|
|
{
|
|
|
|
vector<string> comp;
|
2022-07-13 16:56:10 +02:00
|
|
|
for (auto const & act : lyxaction) {
|
|
|
|
if (prefixIs(act.first, prefix))
|
|
|
|
comp.push_back(act.first);
|
2020-11-19 14:03:26 +02:00
|
|
|
}
|
2022-08-06 07:13:51 +02:00
|
|
|
// now add all the other items that contain the prefix
|
|
|
|
for (auto const & act : lyxaction) {
|
|
|
|
if (!prefixIs(act.first, prefix) && contains(act.first, prefix))
|
|
|
|
comp.push_back(act.first);
|
|
|
|
}
|
2007-10-07 18:40:01 +00:00
|
|
|
|
|
|
|
if (comp.empty()) {
|
|
|
|
new_prefix = prefix;
|
|
|
|
return comp;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (comp.size() == 1) {
|
|
|
|
new_prefix = comp[0];
|
2022-08-06 07:13:51 +02:00
|
|
|
return comp;
|
2007-10-07 18:40:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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;
|
2020-11-19 14:03:26 +02:00
|
|
|
for (auto const & cmd : comp) {
|
|
|
|
if (prefixIs(cmd, test))
|
|
|
|
vtmp.push_back(cmd);
|
|
|
|
}
|
2007-10-07 18:40:01 +00:00
|
|
|
if (vtmp.size() != comp.size()) {
|
|
|
|
test.erase(test.length() - 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
test += tmp[test.length()];
|
|
|
|
}
|
|
|
|
|
|
|
|
new_prefix = test;
|
|
|
|
return comp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-18 19:10:33 +02:00
|
|
|
DispatchResult const & GuiCommandBuffer::dispatch(string const & str)
|
2007-10-07 18:40:01 +00:00
|
|
|
{
|
2015-04-18 19:10:33 +02:00
|
|
|
if (str.empty()) {
|
|
|
|
static DispatchResult empty_dr;
|
|
|
|
return empty_dr;
|
|
|
|
}
|
2007-10-07 18:40:01 +00:00
|
|
|
|
2022-07-13 16:56:10 +02:00
|
|
|
addHistory(trim(str));
|
|
|
|
history_pos_ = history().end();
|
|
|
|
upPB->setEnabled(history_pos_ != history().begin());
|
|
|
|
downPB->setEnabled(history_pos_ != history().end());
|
2007-10-07 18:40:01 +00:00
|
|
|
FuncRequest func = lyxaction.lookupFunc(str);
|
2010-04-09 19:00:42 +00:00
|
|
|
func.setOrigin(FuncRequest::COMMANDBUFFER);
|
2015-04-18 19:10:33 +02:00
|
|
|
return lyx::dispatch(func);
|
2007-10-07 18:40:01 +00:00
|
|
|
}
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
2006-05-18 08:51:12 +00:00
|
|
|
|
2008-11-14 14:28:50 +00:00
|
|
|
#include "moc_GuiCommandBuffer.cpp"
|