#include "GuiCompleter.h"
+#include "GuiApplication.h"
+#include "GuiWorkArea.h"
+#include "GuiView.h"
+#include "qt_helpers.h"
+
#include "Buffer.h"
#include "BufferView.h"
#include "CompletionList.h"
#include "Cursor.h"
#include "Dimension.h"
-#include "GuiWorkArea.h"
-#include "GuiView.h"
#include "LyX.h"
#include "LyXRC.h"
#include "Paragraph.h"
-#include "qt_helpers.h"
#include "version.h"
+#include "support/debug.h"
#include "support/lassert.h"
#include "support/lstrings.h"
-#include "support/debug.h"
+#include "support/qstring_helpers.h"
-#include <QApplication>
#include <QHeaderView>
#include <QKeyEvent>
#include <QPainter>
protected:
void paint(QPainter *painter, const QStyleOptionViewItem &option,
- const QModelIndex &index) const
+ const QModelIndex &index) const override
{
if (index.column() == 0) {
QItemDelegate::paint(painter, option, index);
return false;
}
///
- int columnCount(const QModelIndex & /*parent*/ = QModelIndex()) const
+ int columnCount(const QModelIndex & /*parent*/ = QModelIndex()) const override
{
return 2;
}
///
- int rowCount(const QModelIndex & /*parent*/ = QModelIndex()) const
+ int rowCount(const QModelIndex & /*parent*/ = QModelIndex()) const override
{
if (list_ == 0)
return 0;
}
///
- QVariant data(const QModelIndex & index, int role) const
+ QVariant data(const QModelIndex & index, int role) const override
{
if (list_ == 0)
return QVariant();
// get icon from cache
QPixmap scaled;
- QString const name = ":" + toqstr(list_->icon(index.row()));
- if (name == ":")
+ QString const name = toqstr(list_->icon(index.row()));
+ if (name.isEmpty())
return scaled;
- if (!QPixmapCache::find("completion" + name, &scaled)) {
+ if (!QPixmapCache::find("completion:" + name, &scaled)) {
// load icon from disk
- QPixmap p = QPixmap(name);
+ QPixmap p = getPixmap("images", name, "svgz,png");
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);
+ QPixmapCache::insert("completion:" + name, scaled);
}
return scaled;
}
updateVisibility(cur, start, keep);
- if (cur.result().screenUpdate())
- gui_->bufferView().processUpdateFlags(cur.result().screenUpdate());
+ gui_->bufferView().processUpdateFlags(cur.result().screenUpdate());
}
// has a bad memory about it and we have to tell him again and again.
QTreeView * listView = static_cast<QTreeView *>(popup());
listView->header()->setStretchLastSection(false);
- setSectionResizeMode(listView->header(), 0, QHeaderView::Stretch);
- setSectionResizeMode(listView->header(), 1, QHeaderView::Fixed);
+ listView->header()->setSectionResizeMode(0, QHeaderView::Stretch);
+ listView->header()->setSectionResizeMode(1, QHeaderView::Fixed);
listView->header()->resizeSection(1, 22);
// show/update popup
showPopup(cur);
// redraw if needed
- if (cur.result().screenUpdate())
- gui_->bufferView().processUpdateFlags(cur.result().screenUpdate());
+ gui_->bufferView().processUpdateFlags(cur.result().screenUpdate());
}
showInline(cur);
// redraw if needed
- if (cur.result().screenUpdate())
- gui_->bufferView().processUpdateFlags(cur.result().screenUpdate());
+ gui_->bufferView().processUpdateFlags(cur.result().screenUpdate());
}
hideInline(cur);
// redraw if needed
- if (cur.result().screenUpdate())
- gui_->bufferView().processUpdateFlags(cur.result().screenUpdate());
+ gui_->bufferView().processUpdateFlags(cur.result().screenUpdate());
}
void GuiCompleter::tab()
{
- BufferView * bv = &gui_->bufferView();
- Cursor cur = bv->cursor();
+ BufferView & bv = gui_->bufferView();
+ Cursor cur = bv.cursor();
cur.screenUpdateFlags(Update::None);
// check that inline completion is active
return;
}
- // Make undo possible
- UndoGroupHelper ugh;
- cur.recordUndo();
+ // Prepare for undo (recordUndo is invoked in the insets' insertCompletion methods)
+ UndoGroupHelper ugh(cur.buffer());
// If completion is active, at least complete by one character
docstring prefix = cur.inset().completionPrefix(cur);
hidePopup();
hideInline(cur);
updateVisibility(false, false);
+
+ // redraw if needed
+ bv.processUpdateFlags(cur.result().screenUpdate());
return;
}
docstring nextchar = completion.substr(prefix.size(), 1);
docstring longestCompletion = longestUniqueCompletion();
prefix = cur.inset().completionPrefix(cur);
docstring postfix = longestCompletion.substr(min(longestCompletion.size(), prefix.size()));
- cur.inset().insertCompletion(cur, postfix, false);
- old_cursor_ = bv->cursor();
+ cur.inset().insertCompletion(cur, postfix, uniqueCompletionAvailable());
+ old_cursor_ = bv.cursor();
updatePrefix(cur);
// show popup without delay because the completion was not unique
popup_timer_.start(0);
// redraw if needed
- if (cur.result().screenUpdate())
- gui_->bufferView().processUpdateFlags(cur.result().screenUpdate());
+ bv.processUpdateFlags(cur.result().screenUpdate());
}
hidePopup();
hideInline(cur);
- if (cur.result().screenUpdate())
- gui_->bufferView().processUpdateFlags(cur.result().screenUpdate());
+ gui_->bufferView().processUpdateFlags(cur.result().screenUpdate());
cur.endUndoGroup();
}
if (inlineVisible())
updateInline(cur, completion);
- if (cur.result().screenUpdate())
- gui_->bufferView().processUpdateFlags(cur.result().screenUpdate());
+ gui_->bufferView().processUpdateFlags(cur.result().screenUpdate());
}
} // namespace frontend