1 /***************************************************************************
2 pluginKatexmltools.cpp
3 copyright : (C) 2001-2002 by Daniel Naber
4 email : daniel.naber@t-online.de
5 ***************************************************************************/
6
7/***************************************************************************
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or ( at your option ) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 ***************************************************************************/
22
23#ifndef PLUGIN_KATEXMLTOOLS_H
24#define PLUGIN_KATEXMLTOOLS_H
25
26#include "pseudo_dtd.h"
27
28#include <qstring.h>
29
30#include <kate/plugin.h>
31#include <kate/application.h>
32#include <kate/documentmanager.h>
33#include <kate/mainwindow.h>
34
35#include <ktexteditor/document.h>
36#include <ktexteditor/view.h>
37#include <ktexteditor/codecompletioninterface.h>
38#include <ktexteditor/codecompletionmodel.h>
39#include <ktexteditor/codecompletionmodelcontrollerinterface.h>
40
41#include <kcombobox.h>
42#include <kdialog.h>
43#include <QVariantList>
44
45
46class PluginKateXMLTools : public Kate::Plugin
47{
48 Q_OBJECT
49
50 public:
51 explicit PluginKateXMLTools( QObject* parent = 0, const QVariantList& = QVariantList() );
52 ~PluginKateXMLTools();
53 Kate::PluginView *createView(Kate::MainWindow *mainWindow);
54};
55
56class PluginKateXMLToolsCompletionModel
57 : public KTextEditor::CodeCompletionModel2
58 , public KTextEditor::CodeCompletionModelControllerInterface3
59{
60 Q_OBJECT
61 Q_INTERFACES(KTextEditor::CodeCompletionModelControllerInterface3)
62
63 public:
64 PluginKateXMLToolsCompletionModel( QObject *parent );
65 virtual ~PluginKateXMLToolsCompletionModel();
66
67 virtual int columnCount(const QModelIndex&) const;
68 virtual int rowCount(const QModelIndex &parent) const;
69 virtual QModelIndex parent(const QModelIndex& index) const;
70 virtual QModelIndex index(int row, int column, const QModelIndex& parent) const;
71 virtual QVariant data(const QModelIndex &idx, int role) const;
72
73 virtual void executeCompletionItem2(
74 KTextEditor::Document *document
75 , const KTextEditor::Range &word
76 , const QModelIndex &index
77 ) const;
78
79 virtual bool shouldStartCompletion(
80 KTextEditor::View *view
81 , const QString &insertedText
82 , bool userInsertion
83 , const KTextEditor::Cursor &position
84 );
85
86 public slots:
87
88 void getDTD();
89
90 void slotInsertElement();
91 void slotCloseElement();
92
93 void slotFinished( KJob *job );
94 void slotData( KIO::Job *, const QByteArray &data );
95
96 void completionInvoked( KTextEditor::View *kv, const KTextEditor::Range &range, InvocationType invocationType );
97
98 /// Connected to the document manager, to manage the dtd collection.
99 void slotDocumentDeleted( KTextEditor::Document *doc );
100
101 protected:
102
103 QString currentModeToString() const;
104 static QStringList sortQStringList( QStringList list );
105 //bool eventFilter( QObject *object, QEvent *event );
106
107 QString insideTag( KTextEditor::View &kv );
108 QString insideAttribute( KTextEditor::View &kv );
109
110 static bool isOpeningTag( const QString& tag );
111 static bool isClosingTag( const QString& tag );
112 static bool isEmptyTag( const QString& tag );
113 static bool isQuote( const QString& ch );
114
115 QString getParentElement( KTextEditor::View &view, int skipCharacters );
116
117 enum Mode {none, entities, attributevalues, attributes, elements, closingtag};
118 enum PopupMode {noPopup, tagname, attributename, attributevalue, entityname};
119
120 enum Level {groupNode = 1};
121
122 /// Assign the PseudoDTD @p dtd to the Kate::Document @p doc
123 void assignDTD( PseudoDTD *dtd, KTextEditor::Document *doc );
124
125 /// temporary placeholder for the metaDTD file
126 QString m_dtdString;
127 /// temporary placeholder for the document to assign a DTD to while the file is loaded
128 KTextEditor::Document *m_docToAssignTo;
129 /// URL of the last loaded meta DTD
130 QString m_urlString;
131
132 QStringList m_allowed;
133
134 Mode m_mode;
135 int m_correctPos;
136
137 // code completion stuff:
138 KTextEditor::CodeCompletionInterface* m_codeInterface;
139
140 /// maps KTE::Document -> DTD
141 QHash<KTextEditor::Document *, PseudoDTD *> m_docDtds;
142
143 /// maps DTD filename -> DTD
144 QHash<QString, PseudoDTD *> m_dtds;
145};
146
147class PluginKateXMLToolsView : public Kate::PluginView, public Kate::XMLGUIClient
148{
149 Q_OBJECT
150
151 public:
152
153 explicit PluginKateXMLToolsView( Kate::MainWindow *win);
154 virtual ~PluginKateXMLToolsView();
155
156 protected:
157 PluginKateXMLToolsCompletionModel m_model;
158 Kate::DocumentManager *m_documentManager;
159};
160
161class InsertElement : public KDialog
162{
163
164 Q_OBJECT
165
166 public:
167 InsertElement( QWidget *parent, const char *name );
168 ~InsertElement();
169 QString showDialog( QStringList &completions );
170 private slots:
171 void slotHistoryTextChanged( const QString& );
172
173};
174
175#endif // PLUGIN_KATEXMLTOOLS_H
176
177// kate: space-indent on; indent-width 2; replace-tabs on; mixed-indent off;
178