summaryrefslogtreecommitdiffstats
path: root/parts/abbrev/abbrevpart.h
blob: f0029b51cebc5e08c249d87f7ac2056a70b0fc51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/***************************************************************************
 *   Copyright (C) 2002 Roberto Raggi                                      *
 *   [email protected]                                                  *
 *   Copyright (C) 2002 by Bernd Gehrmann                                  *
 *   [email protected]                                                    *
 *   Copyright (C) 2003 by Alexander Dymo                                  *
 *   [email protected]                                                 *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef _ABBREVPART_H_
#define _ABBREVPART_H_

#include <qmap.h>
#include <qptrlist.h>
#include "kdevplugin.h"

#include <ktexteditor/codecompletioninterface.h>

class KDialogBase;

namespace KParts{
    class Part;
}

namespace KTextEditor{
    class Document;
    class EditInterface;
    class ViewCursorInterface;
}

struct CodeTemplate {
    QString name;
    QString description;
    QString code;
    QString suffixes;
};

class CodeTemplateList {
public:
    CodeTemplateList();
    ~CodeTemplateList();

    QMap<QString, CodeTemplate* > operator[](QString suffix);
    void insert(QString name, QString description, QString code, QString suffixes);
    void remove(const QString &suffixes, const QString &name);
    void clear();
    QStringList suffixes();

    QPtrList<CodeTemplate> allTemplates() const;

private:
    QMap<QString, QMap<QString, CodeTemplate* > > templates;
    QPtrList<CodeTemplate> allCodeTemplates;
    QStringList m_suffixes;
};

class AbbrevPart : public KDevPlugin
{
    Q_OBJECT

public:
    AbbrevPart( QObject *parent, const char *name, const QStringList & );
    ~AbbrevPart();

    bool autoWordCompletionEnabled() const;
    void setAutoWordCompletionEnabled( bool enabled );

    void addTemplate(const QString &templ, const QString &descr,
                     const QString &suffixes, const QString &code);
    void removeTemplate(const QString &suffixes, const QString &name);
    void clearTemplates();
    CodeTemplateList templates() const;

private slots:
    void slotExpandText();
    void slotExpandAbbrev();
    void configWidget(KDialogBase *dlg);
    void slotActivePartChanged( KParts::Part* );
    void slotTextChanged();
    void slotCompletionAborted();
    void slotCompletionDone();
    void slotFilterInsertString( KTextEditor::CompletionEntry*, QString* );
    void slotAboutToShowCompletionBox();

private:
    void updateActions();
    void load();
    void save();
    QString currentWord() const;
    QValueList<KTextEditor::CompletionEntry> findAllWords(const QString &text, const QString &prefix);
    void insertChars( const QString &chars );
//    QAsciiDict<CodeTemplate> m_templates;
    CodeTemplateList m_templates;
    bool m_inCompletion;
    int m_prevLine;
    int m_prevColumn;
    int m_sequenceLength;
    bool m_autoWordCompletionEnabled;
    QString m_completionFile;

    KTextEditor::Document* docIface;
    KTextEditor::EditInterface* editIface;
    KTextEditor::ViewCursorInterface* viewCursorIface;
    KTextEditor::CodeCompletionInterface* completionIface;
};

#endif