summaryrefslogtreecommitdiffstats
path: root/parts/abbrev/abbrevpart.h
blob: 2a1f9416f761a9a19e053a5893edf557518a31c1 (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
114
/***************************************************************************
 *   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 <tqmap.h>
#include <tqptrlist.h>
#include "kdevplugin.h"

#include <ktexteditor/codecompletioninterface.h>

class KDialogBase;

namespace KParts{
    class Part;
}

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

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

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

    TQMap<TQString, CodeTemplate* > operator[](TQString suffix);
    void insert(TQString name, TQString description, TQString code, TQString suffixes);
    void remove(const TQString &suffixes, const TQString &name);
    void clear();
    TQStringList suffixes();

    TQPtrList<CodeTemplate> allTemplates() const;

private:
    TQMap<TQString, TQMap<TQString, CodeTemplate* > > templates;
    TQPtrList<CodeTemplate> allCodeTemplates;
    TQStringList m_suffixes;
};

class AbbrevPart : public KDevPlugin
{
    Q_OBJECT
  TQ_OBJECT

public:
    AbbrevPart( TQObject *parent, const char *name, const TQStringList & );
    ~AbbrevPart();

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

    void addTemplate(const TQString &templ, const TQString &descr,
                     const TQString &suffixes, const TQString &code);
    void removeTemplate(const TQString &suffixes, const TQString &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*, TQString* );
    void slotAboutToShowCompletionBox();

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

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

#endif