summaryrefslogtreecommitdiffstats
path: root/kate/plugins/wordcompletion/docwordcompletion.h
blob: e2ff3cfb251b322cc34ab4ce81afc4ca46f17248 (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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License version 2 as published by the Free Software Foundation.

    This library 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
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.

    ---
    file: docwordcompletion.h

    KTextEditor plugin to autocompletion with document words.
    Copyright Anders Lund <anders.lund@lund.tdcadsl.dk>, 2003

    The following completion methods are supported:
    * Completion with bigger matching words in
      either direction (backward/forward).
    * NOT YET Pop up a list of all bigger matching words in document

*/

#ifndef _DocWordCompletionPlugin_h_
#define _DocWordCompletionPlugin_h_

#include <tdetexteditor/plugin.h>
#include <tdetexteditor/view.h>
#include <tdetexteditor/codecompletioninterface.h>
#include <tdetexteditor/configinterfaceextension.h>
#include <kxmlguiclient.h>

#include <tqevent.h>
#include <tqobject.h>
#include <tqvaluelist.h>

class DocWordCompletionPlugin
  : public KTextEditor::Plugin
  , public KTextEditor::PluginViewInterface
  , public KTextEditor::ConfigInterfaceExtension
{
  TQ_OBJECT

  public:
    DocWordCompletionPlugin( TQObject *parent = 0,
                            const char* name = 0,
                            const TQStringList &args = TQStringList() );
    virtual ~DocWordCompletionPlugin() {};

    void addView (KTextEditor::View *view);
    void removeView (KTextEditor::View *view);

    void readConfig();
    void writeConfig();

    // ConfigInterfaceExtention
    uint configPages() const { return 1; };
    KTextEditor::ConfigPage * configPage( uint number, TQWidget *parent, const char *name );
    TQString configPageName( uint ) const;
    TQString configPageFullName( uint ) const;
    TQPixmap configPagePixmap( uint, int ) const;

    uint treshold() const { return m_treshold; };
    void setTreshold( uint t ) { m_treshold = t; };
    bool autoPopupEnabled() const { return m_autopopup; };
    void setAutoPopupEnabled( bool enable ) { m_autopopup = enable; };


  private:
    TQPtrList<class DocWordCompletionPluginView> m_views;
    uint m_treshold;
    bool m_autopopup;

};

class DocWordCompletionPluginView
   : public TQObject, public KXMLGUIClient
{
  TQ_OBJECT

  public:
    DocWordCompletionPluginView( uint treshold=3, bool autopopup=true, KTextEditor::View *view=0,
                               const char *name=0 );
    ~DocWordCompletionPluginView() {};

    void settreshold( uint treshold );

  private slots:
    void completeBackwards();
    void completeForwards();
    void shellComplete();

    void popupCompletionList( TQString word=TQString::null );
    void autoPopupCompletionList();
    void toggleAutoPopup();

    void slotVariableChanged( const TQString &, const TQString & );

  private:
    void complete( bool fw=true );

    TQString word();
    TQValueList<KTextEditor::CompletionEntry> allMatches( const TQString &word );
    TQString findLongestUnique(const TQValueList < KTextEditor::CompletionEntry > &matches);
    KTextEditor::View *m_view;
    struct DocWordCompletionPluginViewPrivate *d;
};

class DocWordCompletionConfigPage : public KTextEditor::ConfigPage
{
  TQ_OBJECT
  public:
    DocWordCompletionConfigPage( DocWordCompletionPlugin *completion, TQWidget *parent, const char *name );
    virtual ~DocWordCompletionConfigPage() {};

    virtual void apply();
    virtual void reset();
    virtual void defaults();

  private:
    DocWordCompletionPlugin *m_completion;
    class TQCheckBox *cbAutoPopup;
    class TQSpinBox *sbAutoPopup;
    class TQLabel *lSbRight;
};

#endif // _DocWordCompletionPlugin_h_