#include "CompletionList.h"
#include "Cursor.h"
#include "Dimension.h"
-#include "FuncRequest.h"
#include "GuiWorkArea.h"
#include "GuiView.h"
-#include "LyXFunc.h"
+#include "LyX.h"
#include "LyXRC.h"
#include "Paragraph.h"
#include "version.h"
#include <QApplication>
#include <QHeaderView>
+#include <QKeyEvent>
#include <QPainter>
#include <QPixmapCache>
#include <QScrollBar>
{
if (list_ == 0)
return 0;
- else
- return list_->size();
+ return list_->size();
}
///
if (index.column() == 0)
return toqstr(list_->data(index.row()));
- if (index.column() == 1) {
- // get icon from cache
- QPixmap scaled;
- QString const name = ":" + toqstr(list_->icon(index.row()));
- if (!QPixmapCache::find("completion" + name, scaled)) {
- // load icon from disk
- QPixmap p = QPixmap(name);
- if (!p.isNull()) {
- // scale it to 16x16 or smaller
- scaled = p.scaled(min(16, p.width()), min(16, p.height()),
- Qt::KeepAspectRatio, Qt::SmoothTransformation);
- }
-
- QPixmapCache::insert("completion" + name, scaled);
+ if (index.column() != 1)
+ return QVariant();
+
+ // get icon from cache
+ QPixmap scaled;
+ QString const name = ":" + toqstr(list_->icon(index.row()));
+ if (!QPixmapCache::find("completion" + name, scaled)) {
+ // load icon from disk
+ QPixmap p = QPixmap(name);
+ if (!p.isNull()) {
+ // scale it to 16x16 or smaller
+ scaled = p.scaled(min(16, p.width()), min(16, p.height()),
+ Qt::KeepAspectRatio, Qt::SmoothTransformation);
}
- return scaled;
+ QPixmapCache::insert("completion" + name, scaled);
}
- return QVariant();
+ return scaled;
}
private:
model_ = new GuiCompletionModel(this, 0);
setModel(model_);
setCompletionMode(QCompleter::PopupCompletion);
- setCaseSensitivity(Qt::CaseInsensitive);
+ setCaseSensitivity(Qt::CaseSensitive);
setWidget(gui_);
// create the popup
QTreeView *listView = new QTreeView;
- listView->setEditTriggers(QAbstractItemView::NoEditTriggers);
- listView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
- listView->setSelectionBehavior(QAbstractItemView::SelectRows);
- listView->setSelectionMode(QAbstractItemView::SingleSelection);
+ listView->setEditTriggers(QAbstractItemView::NoEditTriggers);
+ listView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ listView->setSelectionBehavior(QAbstractItemView::SelectRows);
+ listView->setSelectionMode(QAbstractItemView::SingleSelection);
listView->header()->hide();
listView->setIndentation(0);
listView->setUniformRowHeights(true);
}
-void GuiCompleter::updateVisibility(Cursor & cur, bool start, bool keep, bool cursorInView)
+void GuiCompleter::updateVisibility(Cursor & cur, bool start, bool keep)
{
// parameters which affect the completion
bool moved = cur != old_cursor_;
if (moved)
old_cursor_ = cur;
- bool possiblePopupState = popupPossible(cur) && cursorInView;
- bool possibleInlineState = inlinePossible(cur) && cursorInView;
+ bool const possiblePopupState = popupPossible(cur);
+ bool const possibleInlineState = inlinePossible(cur);
// we moved or popup state is not ok for popup?
if ((moved && !keep) || !possiblePopupState)
if (!inlineVisible() && possibleInlineState && start
&& cur.inset().automaticInlineCompletion())
inline_timer_.start(int(lyxrc.completion_inline_delay * 1000));
- else {
+ else if (cur.inMathed() && !lyxrc.completion_inline_math) {
// no inline completion, hence a metrics update is needed
- if (!(cur.disp_.update() & Update::Force))
- cur.updateFlags(cur.disp_.update() | Update::SinglePar);
+ if (!(cur.result().screenUpdate() & Update::Force))
+ cur.screenUpdateFlags(cur.result().screenUpdate() | Update::SinglePar);
}
// update prefix if any completion is possible
void GuiCompleter::updateVisibility(bool start, bool keep)
{
Cursor cur = gui_->bufferView().cursor();
- cur.updateFlags(Update::None);
+ cur.screenUpdateFlags(Update::None);
updateVisibility(cur, start, keep);
- if (cur.disp_.update())
- gui_->bufferView().processUpdateFlags(cur.disp_.update());
+ if (cur.result().screenUpdate())
+ gui_->bufferView().processUpdateFlags(cur.result().screenUpdate());
}
void GuiCompleter::asyncUpdatePopup()
{
Cursor cur = gui_->bufferView().cursor();
- if (!cur.inset().completionSupported(cur)) {
+ if (!cur.inset().completionSupported(cur)
+ || !cur.bv().paragraphVisible(cur)) {
popupVisible_ = false;
return;
}
void GuiCompleter::showPopup()
{
Cursor cur = gui_->bufferView().cursor();
- cur.updateFlags(Update::None);
+ cur.screenUpdateFlags(Update::None);
showPopup(cur);
// redraw if needed
- if (cur.disp_.update())
- gui_->bufferView().processUpdateFlags(cur.disp_.update());
+ if (cur.result().screenUpdate())
+ gui_->bufferView().processUpdateFlags(cur.result().screenUpdate());
}
void GuiCompleter::showInline()
{
Cursor cur = gui_->bufferView().cursor();
- cur.updateFlags(Update::None);
+ cur.screenUpdateFlags(Update::None);
showInline(cur);
// redraw if needed
- if (cur.disp_.update())
- gui_->bufferView().processUpdateFlags(cur.disp_.update());
+ if (cur.result().screenUpdate())
+ gui_->bufferView().processUpdateFlags(cur.result().screenUpdate());
}
void GuiCompleter::hidePopup()
{
Cursor cur = gui_->bufferView().cursor();
- cur.updateFlags(Update::None);
+ cur.screenUpdateFlags(Update::None);
hidePopup(cur);
// redraw if needed
- if (cur.disp_.update())
- gui_->bufferView().processUpdateFlags(cur.disp_.update());
+ if (cur.result().screenUpdate())
+ gui_->bufferView().processUpdateFlags(cur.result().screenUpdate());
}
void GuiCompleter::hideInline()
{
Cursor cur = gui_->bufferView().cursor();
- cur.updateFlags(Update::None);
+ cur.screenUpdateFlags(Update::None);
hideInline(cur);
// redraw if needed
- if (cur.disp_.update())
- gui_->bufferView().processUpdateFlags(cur.disp_.update());
+ if (cur.result().screenUpdate())
+ gui_->bufferView().processUpdateFlags(cur.result().screenUpdate());
}
{
BufferView * bv = &gui_->bufferView();
Cursor cur = bv->cursor();
- cur.updateFlags(Update::None);
+ cur.screenUpdateFlags(Update::None);
// check that inline completion is active
if (!inlineVisible() && !uniqueCompletionAvailable()) {
}
// Make undo possible
+ cur.beginUndoGroup();
cur.recordUndo();
// If completion is active, at least complete by one character
hidePopup(cur);
hideInline(cur);
updateVisibility(false, false);
+ cur.endUndoGroup();
return;
}
docstring nextchar = completion.substr(prefix.size(), 1);
- if (!cur.inset().insertCompletion(cur, nextchar, false))
+ if (!cur.inset().insertCompletion(cur, nextchar, false)) {
+ cur.endUndoGroup();
return;
+ }
updatePrefix(cur);
// try to complete as far as it is unique
popup_timer_.start(0);
// redraw if needed
- if (cur.disp_.update())
- gui_->bufferView().processUpdateFlags(cur.disp_.update());
+ if (cur.result().screenUpdate())
+ gui_->bufferView().processUpdateFlags(cur.result().screenUpdate());
+ cur.endUndoGroup();
}
void GuiCompleter::popupActivated(const QString & completion)
{
Cursor cur = gui_->bufferView().cursor();
- cur.updateFlags(Update::None);
-
+ cur.screenUpdateFlags(Update::None);
+
+ cur.beginUndoGroup();
cur.recordUndo();
docstring prefix = cur.inset().completionPrefix(cur);
hidePopup(cur);
hideInline(cur);
- if (cur.disp_.update())
- gui_->bufferView().processUpdateFlags(cur.disp_.update());
+ if (cur.result().screenUpdate())
+ gui_->bufferView().processUpdateFlags(cur.result().screenUpdate());
+ cur.endUndoGroup();
}
return;
Cursor cur = gui_->bufferView().cursor();
- cur.updateFlags(Update::None);
+ cur.screenUpdateFlags(Update::None);
if (inlineVisible())
updateInline(cur, completion);
- if (cur.disp_.update())
- gui_->bufferView().processUpdateFlags(cur.disp_.update());
+ if (cur.result().screenUpdate())
+ gui_->bufferView().processUpdateFlags(cur.result().screenUpdate());
}
} // namespace frontend