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

List:       ktexteditor-devel
Subject:    Re: Completion-Interface
From:       Andreas Pakulat <apaku () gmx ! de>
Date:       2008-04-18 9:02:24
Message-ID: 20080418090223.GB7152 () morpheus ! apaku ! dnsalias ! org
[Download RAW message or body]

On 17.04.08 18:49:38, Christoph Cullmann wrote:
> The current way locks a whole row of C++ specific stuff into the part.

Thats wrong, it puts in a bunch of things that can be used for
completion of a couple of languages and even non-code completion.

> In our view (from the devs at the sprint), as much easier interface
> would be sufficient, which allows the handling of only one model per
> view but moves the whole logic to the user of the interface.

Well its code, anything can be done. The question is wether every
application that uses katepart and wants to merge multiple models should
write its own code or wether it should be inside kate itself. I guess
currently we're in a bad position to decide that, because there's
basically only 1 application that has the need for that -
kdevelop/quanta (which can share the merging code).

> My sketch would be:
> 
> 1. new interface which allows only to register one completion model for a view

See my other response, kdevelop definetly needs multiple models at some
point in the flow of completions from the plugins to kate.

> 2. in addition, a delegate should be registered, to allow the app to handle 
> the displaying

I'm fine with that, except that this would be a quite complex delegate
as we'd probably want to have one for each underlying model in kdevelop
- like one for c++, one for CMake, QMake and so on.

> That way, the whole filtering and sorting can be implemented in the app and 
> the interface + implementation is small. The current >> 3000 lines of code 
> are not acceptable for show a such simple thingy.

So basically your problem is that you (you as in kate devs) didn't write
the code and don't want to maintain it? I can understand that, so maybe
an even more stripped down interface would be good, which allows an
application to do _everything_ - including the view - itself? Then you
basically don't have to maintain any code.

BTW: Writing a simple completion model is really not a problem with the
current interface. It takes like 30 minutes without any idea about the
API. You just have to re-implement 2 methods and hook the model instance
to the view. Attached is the snippet-model as an example which uses a
plain list of snippets to provide completion.

Andreas

-- 
Try to value useful qualities in one who loves you.

["snippetcompletionmodel.cpp" (text/x-c++src)]

/***************************************************************************
 *   This file is part of KDevelop                                         *
 *   Copyright 2008 Andreas Pakulat <apaku@gmx.de>                         *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Library General Public License as       *
 *   published by the Free Software Foundation; either version 2 of the    *
 *   License, or (at your option) any later version.                       *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU Library General Public     *
 *   License along with this program; if not, write to the                 *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
 ***************************************************************************/

#include "snippetcompletionmodel.h"
#include <ktexteditor/document.h>
#include "snippet.h"
#include "snippetstore.h"
#include "snippetrepository.h"

SnippetCompletionModel::SnippetCompletionModel()
    : KTextEditor::CodeCompletionModel(0)
{
    initData();
}

SnippetCompletionModel::~SnippetCompletionModel()
{
}

QVariant SnippetCompletionModel::data( const QModelIndex& idx, int role ) const
{
    if( !idx.isValid() || role != Qt::DisplayRole || idx.row() < 0 || idx.row() >= \
rowCount()  || idx.column() != KTextEditor::CodeCompletionModel::Name )
        return QVariant();
    return m_snippets.at( idx.row() )->text();
}

void SnippetCompletionModel::executeCompletionItem( KTextEditor::Document* doc, const \
KTextEditor::Range& w, int row ) const {
    Snippet* snippet = m_snippets.at( row );
    //Instead of the name of the snippet we want its text
    doc->replaceText( w, snippet->getSnippetPlainText() );
}

void SnippetCompletionModel::completionInvoked(KTextEditor::View *view, const \
KTextEditor::Range &range, InvocationType invocationType) {
    initData();
}

void SnippetCompletionModel::initData()
{
    m_snippets.clear();
    SnippetStore* store = SnippetStore::instance();
    for(int i = 0; i < store->rowCount(); i++ )
    {
        SnippetRepository* repo = dynamic_cast<SnippetRepository*>( store->item( i, 0 \
) );  if( repo )
        {
            m_snippets += repo->getSnippets();
        }
    }
    reset();
    setRowCount( m_snippets.count() );
}


["snippetcompletionmodel.h" (text/x-chdr)]

/***************************************************************************
 *   This file is part of KDevelop                                         *
 *   Copyright 2008 Andreas Pakulat <apaku@gmx.de>                         *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Library General Public License as       *
 *   published by the Free Software Foundation; either version 2 of the    *
 *   License, or (at your option) any later version.                       *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU Library General Public     *
 *   License along with this program; if not, write to the                 *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
 ***************************************************************************/

#ifndef SNIPPETCODECOMPLETION_H
#define SNIPPETCODECOMPLETION_H

#include <ktexteditor/codecompletionmodel.h>

namespace KTextEditor
{
class Document;
}

class Snippet;

class SnippetCompletionModel : public KTextEditor::CodeCompletionModel
{
public:
    SnippetCompletionModel();
    ~SnippetCompletionModel();

    QVariant data( const QModelIndex& idx, int role = Qt::DisplayRole ) const;
    void completionInvoked(KTextEditor::View *view, const KTextEditor::Range &range, \
InvocationType invocationType);  void executeCompletionItem( KTextEditor::Document* \
doc, const KTextEditor::Range& w, int row ) const; private:
    void initData();
    QList<Snippet*> m_snippets;
};

#endif



_______________________________________________
KTextEditor-Devel mailing list
KTextEditor-Devel@kde.org
https://mail.kde.org/mailman/listinfo/ktexteditor-devel


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

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