class GuiCompletionModel : public QAbstractListModel {
public:
///
- GuiCompletionModel(QObject * parent, Inset::CompletionListPtr l)
- : QAbstractListModel(parent), list(l) {}
+ GuiCompletionModel(QObject * parent, Inset::CompletionList const * l)
+ : QAbstractListModel(parent), list_(l) {}
+ ///
+ ~GuiCompletionModel()
+ { delete list_; }
///
int columnCount(const QModelIndex & /*parent*/ = QModelIndex()) const
{
///
int rowCount(const QModelIndex & /*parent*/ = QModelIndex()) const
{
- if (list.get() == 0)
+ if (list_ == 0)
return 0;
else
- return list->size();
+ return list_->size();
}
///
QVariant data(const QModelIndex & index, int role) const
{
- if (list.get() == 0)
+ if (list_ == 0)
return QVariant();
if (index.row() < 0 || index.row() >= rowCount())
return QVariant();
if (index.column() == 0)
- return toqstr(list->data(index.row()));
+ return toqstr(list_->data(index.row()));
else if (index.column() == 1) {
// get icon from cache
QPixmap scaled;
- QString const name = ":" + toqstr(list->icon(index.row()));
+ QString const name = ":" + toqstr(list_->icon(index.row()));
if (!QPixmapCache::find("completion" + name, scaled)) {
// load icon from disk
QPixmap p = QPixmap(name);
private:
///
- Inset::CompletionListPtr list;
+ Inset::CompletionList const * list_;
};
: QCompleter(parent), gui_(gui), updateLock_(0)
{
// Setup the completion popup
- setModel(new GuiCompletionModel(this, Inset::CompletionListPtr()));
+ setModel(new GuiCompletionModel(this, 0));
setCompletionMode(QCompleter::PopupCompletion);
setWidget(gui_);
/// returns the resource string used to load an icon.
virtual std::string icon(size_t /*idx*/) const { return std::string(); }
};
- typedef boost::shared_ptr<CompletionList> CompletionListPtr;
/// Returns true if the inset supports completions.
virtual bool completionSupported(Cursor const &) const { return false; }
virtual bool automaticPopupCompletion() const { return true; }
/// Returns completion suggestions at cursor position. Return an
/// null pointer if no completion is a available or possible.
- virtual CompletionListPtr completionList(Cursor const &) const
- { return CompletionListPtr(); }
+ /// The caller is responsible to free the return object!
+ virtual CompletionList const * completionList(Cursor const &) const
+ { return 0; }
/// Returns the completion prefix to filter the suggestions for completion.
/// This is only called if completionList returned a non-null list.
virtual docstring completionPrefix(Cursor const &) const
}
-Inset::CompletionListPtr InsetText::completionList(Cursor const & cur) const
+Inset::CompletionList const * InsetText::completionList(Cursor const & cur) const
{
if (!completionSupported(cur))
- return CompletionListPtr();
+ return 0;
- return CompletionListPtr(new TextCompletionList(cur));
+ return new TextCompletionList(cur);
}
///
bool automaticPopupCompletion() const;
///
- CompletionListPtr completionList(Cursor const & cur) const;
+ CompletionList const * completionList(Cursor const & cur) const;
///
docstring completionPrefix(Cursor const & cur) const;
///
#include "support/docstream.h"
#include <algorithm>
-#include <deque>
#include <sstream>
using namespace std;
}
-Inset::CompletionListPtr InsetMathNest::completionList(Cursor const & cur) const
+Inset::CompletionList const * InsetMathNest::completionList(Cursor const & cur) const
{
if (!cur.inMacroMode())
- return CompletionListPtr();
+ return 0;
- return CompletionListPtr(new MathCompletionList(cur));
+ return new MathCompletionList(cur);
}
size_type MathCompletionList::size() const
{
- return favorites.size() + locals.size() + globals.size();
+ return locals.size() + globals.size();
}
docstring MathCompletionList::data(size_t idx) const
{
- size_t fsize = favorites.size();
size_t lsize = locals.size();
- if (idx >= fsize + lsize)
- return globals[idx - lsize - fsize];
- else if (idx >= fsize)
- return locals[idx - fsize];
+ if (idx >= lsize)
+ return globals[idx - lsize];
else
- return favorites[idx];
+ return locals[idx];
}
{
// get the latex command
docstring cmd;
- size_t fsize = favorites.size();
size_t lsize = locals.size();
- if (idx >= fsize + lsize)
- cmd = globals[idx - lsize - fsize];
- else if (idx >= fsize)
- cmd = locals[idx - fsize];
+ if (idx >= lsize)
+ cmd = globals[idx - lsize];
else
- cmd = favorites[idx];
+ cmd = locals[idx];
// get the icon resource name by stripping the backslash
return "images/math/" + to_utf8(cmd.substr(1)) + ".png";
}
-
-
-void MathCompletionList::addToFavorites(docstring const & completion)
-{
- // remove old occurrence
- std::deque<docstring>::iterator it;
- for (it = favorites.begin(); it != favorites.end(); ++it) {
- if (*it == completion) {
- favorites.erase(it);
- break;
- }
- }
-
- // put it to the front
- favorites.push_front(completion);
- favorites.resize(min(int(favorites.size()), 10));
-}
-
-
std::vector<docstring> MathCompletionList::globals;
-std::deque<docstring> MathCompletionList::favorites;
} // namespace lyx
#include "InsetMath.h"
-#include <deque>
-
namespace lyx {
class MathCompletionList : public Inset::CompletionList {
static std::vector<docstring> globals;
///
std::vector<docstring> locals;
- ///
- static std::deque<docstring> favorites;
};
/** Abstract base class for all math objects that contain nested items.
///
bool automaticPopupCompletion() const;
///
- CompletionListPtr completionList(Cursor const & cur) const;
+ CompletionList const * completionList(Cursor const & cur) const;
///
docstring completionPrefix(Cursor const & cur) const;
///
}
-Inset::CompletionListPtr MathMacro::completionList(Cursor const & cur) const
+Inset::CompletionList const * MathMacro::completionList(Cursor const & cur) const
{
if (displayMode() != DISPLAY_UNFOLDED)
return InsetMathNest::completionList(cur);
- return CompletionListPtr(new MathCompletionList(cur.bv().cursor()));
+ return new MathCompletionList(cur.bv().cursor());
}
///
bool automaticPopupCompletion() const;
///
- CompletionListPtr completionList(Cursor const & cur) const;
+ CompletionList const * completionList(Cursor const & cur) const;
///
docstring completionPrefix(Cursor const & cur) const;
///