[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kwrite-devel
Subject:    Re: KTextEditor argument hinting
From:       Thomas Friedrichsmeier <thomas.friedrichsmeier () ruhr-uni-bochum ! de>
Date:       2019-01-31 9:20:45
Message-ID: 20190131102045.272859b3 () edge
[Download RAW message or body]


On Fri, 25 Jan 2019 15:12:52 +0100
Thomas Friedrichsmeier <thomas.friedrichsmeier@ruhr-uni-bochum.de>
wrote:
> I'm currently trying to figure out how to show argument hints in a
> ktexteditor view. I can register a CodeCompletionModel all right, but
> any completions where I set ArgumentHintDepth to non-zero just
> disappear.

Ok, I admit that was a difficult type of question, so more specifically:
In the following minimal example, why does the hint disappear as soon
as I return 1 for ArgumentHintDepth (instead of popping up in a
separate tip, as I would expect):

class MyDummyModel : public KTextEditor::CodeCompletionModel {
public:
  MyDummyModel(QObject *parent) :
    KTextEditor::CodeCompletionModel(parent) {
    setRowCount(1);
    setHasGroups(false);
  };
  ~MyDummyModel() {};

  QVariant data(const QModelIndex & index, int role) const {
    int col = index.column ();
    if (role == Qt::DisplayRole) {
      if (col == KTextEditor::CodeCompletionModel::Name) {
        return i18n("dummyhint");
      }
    } else if (role ==
        KTextEditor::CodeCompletionModel::ArgumentHintDepth) {
      return 1; // change to 0, and the dummy hint is visible
    }
    return QVariant();
  }

  void completionInvoked(KTextEditor::View * view,
     const KTextEditor::Range & range,
     KTextEditor::CodeCompletionModel::InvocationType invocationType) {
    // fake an update:
    beginResetModel();
    endResetModel();
  }
};

void testMyDummyModel() {
  KTextEditor::Editor* editor = KTextEditor::Editor::instance();
  KTextEditor::Document* m_doc = editor->createDocument(0);
  KTextEditor::View* m_view = m_doc->createView(0);
  KTextEditor::CodeCompletionInterface* m_iface =
    qobject_cast<KTextEditor::CodeCompletionInterface*>(m_view);
  m_iface->registerCompletionModel(new MyDummyModel(m_view));
  m_iface->setAutomaticInvocationEnabled(true);
  m_view->show ();
};

Thanks!
Thomas

[Attachment #3 (application/pgp-signature)]

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic