Source

pynoto / src / PythonEditor / PythonCompliter.cpp

#include <QDebug>
#include "Include/PynotoApplication.h"
#include "Include/IProjectPlugin.h"
#include "PythonCompliter.h"
#include "PythonEditorWidget.h"
#include "ComplititionList.h"

namespace PythonEditor {

PythonCompliter::PythonCompliter(PythonEditorWidget* parent):
    QObject(parent),
    _editor(parent),
    _list(NULL)
{
    _project = Aux::plugin<Project::IProjectPlugin*>("project")->project();
    connect(_project, SIGNAL(interpretChanged()), SLOT(initPyCode()));
    connect(_project, SIGNAL(lintChanged()), SLOT(checkErrors()));
    _list = new ComplititionList(_editor, _editor->viewport());
    initPyCode();
}

void PythonCompliter::initPyCode()
{
    bool reload = true;
    if (!_python)
        reload = false;
    _python = _project->pythonCode();
    if (_python){
        connect(_python, SIGNAL(errors(QString,QList<ErrorItem>)), SLOT(onErrors(QString,QList<ErrorItem>)));
        connect(_python, SIGNAL(complitition(QString,int,QString,QList<Completition>)), SLOT(onComplit(QString,int,QString,QList<Completition>)));
    }
    if (reload && _python)
        checkErrors();
}

void PythonCompliter::checkErrors()
{
    if (_python)
        _python->errorList(_editor->fileName(), _editor->content());
}

void PythonCompliter::showComplit(int pos)
{
    if (_python)
        _python->codeComplit(_editor->fileName(), _editor->content(), pos);
}

void PythonCompliter::hide()
{
}

void PythonCompliter::onErrors(const QString& fileName, const QList<PythonCode::IPythonCode::ErrorItem>& items)
{
    if (fileName == _editor->fileName()){
        _editor->setErrors(items);
    }
}

void PythonCompliter::onComplit(const QString& fileName, int pos, const QString& word, const QList<Completition>& items)
{
    if (fileName != _editor->fileName())
        return;
    hide();
    _list->complete(pos, word, items);
}

bool PythonCompliter::isVisible()
{
    return _list->popup()->isVisible();
}

}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.