summaryrefslogtreecommitdiffstats
path: root/part/kxmleditorpart.h
blob: 7087bf0ba19388c796979c57b999802ff9df3b1a (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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
/***************************************************************************
                          kxmleditorpart.h  -  description
                             -------------------
    begin                : Wed Sep 19 2001
    copyright            : (C) 2001, 2002, 2003 by The KXMLEditor Team
    email                : OleBowle@gmx.de
 ***************************************************************************/
 
/***************************************************************************
 *                                                                         *
 *   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 KXMLEDITORPART_H
#define KXMLEDITORPART_H

#include <kparts/part.h>
#include <kparts/browserextension.h>

#include <tqdom.h>
#include <tqptrlist.h>

#include "kxe_treeview.h"

#define FILE_DIALOG_FILTER "*.xml|XML files\n*.xsl|XSL files\n*.xslt|XSLT files\n*.svg|SVG files\n*.xul|XUL files\n*.rc|Resource UI files\n*.ui|User Interface UI files\n*|All files"

class TQTabWidget;
class KXE_ViewElement;
class KXESearchDialog;
class TQTextEdit;
class KAction;
class KToolBarPopupAction;
class KXmlEditorComboAction;
class TQDomNode;
class TQKeyEvent;
class KXMLEditorPartIfaceReadOnly; // DCOP interface
class KCommandHistory;
class KPrinter;
class TQSplitter;
class KXEDocument;


/** @short This is the KPart of KXMLEditor. */
class KXMLEditorPart : public KParts::ReadWritePart
{
		Q_OBJECT

public:
		/** @short Constructor

		Creates the actions, the view (widgets) and changes to "begin state".
		*/
		KXMLEditorPart( bool fReadWrite, KXEDocument* pDocument, TQWidget * pParent, const char * pszName );

		/** @short Destructor */
		virtual ~KXMLEditorPart();

		/** @short Changes the behaviour of this part to readonly or readwrite. */
		virtual void setReadWrite( bool fReadWrite = true );

		/** @short Returns the selected XML object's path or an empty string, if no object is selected. */
		TQString getSelectedPath() const { return m_pViewTree->getSelectedPath(); }

		/** @short Copy XML node into clipboard */
		TQTextDrag * copyNode(TQDomNode *);

		/** @short Paste XML node from clipboard into document */
		bool pasteNode(TQDomNode *, TQMimeSource *);

		/** @short Drag&Drop move */
		bool dropMoveNode(TQDomElement &, TQDomNode &);

		/** @short Prints the document on specified printer.
			@param pPrinter printer which will be used for printing. */
		virtual void print(KPrinter* pPrinter);

		/** @short Returns underlying document. */
		KXEDocument* document()  	{ return m_pDocument; }

		/** @short Changes underlying document object */
		void setDocument(KXEDocument *pDocument);

public slots:
		/**
		 * Reimplemented from @ref KParts::KReadWritePart::setModified.
		 *
		 * Alters the window caption according to the given flag and
		 * calls the base functionality.
		 */
		virtual void setModified( bool fModified );

		/** @short Updates tree view after creating new element */
		void updateNodeCreated(const TQDomNode & node);

		/** @short Updates tree view after deleting new element */
		void updateNodeDeleted(const TQDomNode & node);

		/** @short Updates tree view after change element properties */
		void updateNodeChanged( const TQDomElement & domElement );

		/** @short Updates tree view after change char. data properties */
		void updateNodeChanged( const TQDomCharacterData & node ) ;

		/** @short Updates tree view after change proc. instr. properties */
		void updateNodeChanged( const TQDomProcessingInstruction &domProcInstr );

		/** @short Updates tree view after move node */
		void updateNodeMoved( const TQDomNode & node );

		/**
		 * @short Reimplemented from @ref KParts::KReadWritePart::setModified.
		 */
		virtual void setModified() { setModified(true);  }
		
		/** @short Slot connected to File->Save As action. */
		bool slotFileSaveAs();

		/** @short Inserts special proc.instruction into document. */
		void slotActVersionEncoding();

		/** @short Called on user's action response.
		Creates <?xml-stylesheet ...?> processing instruction
		with reference to specified stylesheet URI.
		*/
		void slotActAttachStylesheet();
	
		/** @short Called on user's action response. */
		void slotActDetachStylesheet();
	
		/** @short Called on user's action response */
		void slotActDetachSchema();
	
		/** @short Called on user's action response */
		void slotActAttachSchema();

		/** @short Cut the marked text/object into the clipboard */
		void slotEditCut();

		/** @short Copy the marked text/object into the clipboard */
		void slotEditCopy();

		/** @short Paste the clipboard into the document */
		void slotEditPaste();

		/** @short Displays search dialog and finds string in this tree view */
		void slotEditFind();

		/** @short Finds next occurence of string in this tree view */
		void slotEditFindNext();

		/** @short Deselects currently selected item */
		void slotEditDeselect() { m_pViewTree->editDeselect(); }

		/** @short Selects the selected item's parent item. */
		void slotViewNodeUp() { m_pViewTree->viewNodeUp(); }

		/** @short Expands the selected tree item's subtree. */
		void slotViewExpNode() { m_pViewTree->viewExpNode(-1); }

		/** @short Expands the selected tree item's subtree to the given level. */
		void slotViewExpNode( int nLevel ) { m_pViewTree->viewExpNode(nLevel); }

		/** @short Collapses the selected tree item's subtree. */
		void slotViewColNode() { m_pViewTree->viewColNode(0); }

		/** @short Collapses the selected tree item's subtree to the given level. */
		void slotViewColNode( int nLevel ) { m_pViewTree->viewColNode(nLevel); }

		/** @short Insert XML element into document */
		void slotXmlElementInsert();

		/** @short Edit XML element */
		void slotXmlElementEdit();

		/** @short Add attribute to an XML element. */
		void slotXmlAttributesAdd();

		/** @short Delete all attributes of an XML element. */
		void slotXmlAttributesDel();

		/** @short Delete an attribute of an XML element. */
		void slotXmlAttributeDel();

		/** @short Insert proc.instruction into document */
		void slotXmlProcInstrInsert();

		/** @short Edit proc.instruction */
		void slotXmlProcInstrEdit();

		/* @short Insert text into element. */
		void slotActInsertText();

		/* @short Insert CDATA section. */
		void slotActInsertCDATA();

		/* @short Insert comment to element. */
		void slotActInsertComment();

		/* @short Edit character data */
		void slotXmlCharDataEdit();

		/* @short Moves a node up (change its position with its prev. siblings position) */
		void slotXmlMoveNodeUp();

		/* @short Moves a node down (change its position with its next siblings position) */
		void slotXmlMoveNodeDown();

		/** @short toggles bookmark on the selected item */
		void slotBookmarksToggle();

		/** @short Searches for the previous bookmarked item */
		void slotBookmarksPrev() { m_pViewTree->bookmarksPrev(); }

		/** @short Searches for the next bookmarked item */
		void slotBookmarksNext() { m_pViewTree->bookmarksNext(); }

		/** @short Shows configuration dialog (@ref OptionsDialog) */
		void slotConfigure();

		void slotPathSelected( const TQString & szPath );
		void slotPathSelected();
		void slotPathClear();

		/** @short Called when a tree view items text was changed via inplace-renaming. */
		void slotItemRenamedInplace( TQListViewItem * pItem );

		/** @short Called whan an attributes name was changed via inplace editing. */
		void slotAttributeNameChangedInplace( const TQDomAttr &, const TQString );

		/** @short Called whan an attributes value was changed via inplace editing. */
		void slotAttributeValueChangedInplace( const TQDomAttr &, const TQString );

		/** @short Called when File->Print or icon from the toolbar is selected. */
		void slotActPrint();

		/** @short Slot for editing node properties. */
		void slotActProperties();

		/** @short Slot for editing xml as a text in separate dialog window. */
		void slotActEditRawXml();

		/** @short Slot for removing XML nodes. */
		void slotActDelete();

		void slotTreeViewKeyPressed(TQKeyEvent *e);

		/** @short Slot that performs redo function. */
		void slotActRedo();

		/** @short Slot that performs undo function. */
		void slotActUndo();

protected:

		void updateActions();
		
		/** @short Opens the file @ref KParts::ReadOnlyPart::m_file. */
		virtual bool openFile();

		/** @short Saves the file @ref KParts::ReadOnlyPart::m_file. */
		virtual bool saveFile();

		/** @short Draws header for printouts (made of file name).
			@param painter a painter to use for drawing
			@param pageNumber number of currently drawn page counted from 0
			@param ypos y coordinate of upper border of the header
			@sa printPage() @sa printFooter()
		*/
		void printHeader(TQPainter* painter, int pageNumber, int ypos, int width);

		/** @short Draws footer for printouts (page number).
			@param painter a painter to use for drawing
			@param pageNumber number of currently drawn page counted from 0
			@param ypos y coordinate of upper border of the footer
			@sa printHeader() @sa printFooter()
		*/
		void printFooter(TQPainter* painter,int pageNumber, int ypos, int width);

		/** @short Draws page for printing purposes.

		If there are more pages to print, method
		returns true. Otherwise returns false.
			@param painter a painter to use for srawing
			@param pageNumber number of currently drawn page counted from 0
			@param top y coordinate of upper edge from where page should be drawn
			@param width,height size of the medium (e.g. paper)
			@sa printPage() @sa printHeader()
		*/
		bool printPage(TQPainter* painter,int pageNumber, int top, int width, int height);

		/** @short Used in printing function printPage(). */
		unsigned int m_printLineNumber;

		/** @short Used in printing function printPage(). */
		TQStringList m_printLines;

		// the actions
		KAction * m_pActEditFind;
		KAction * m_pActEditFindNext;
		KAction * m_pActEditDeselect;
		KAction * m_pActViewNodeUp;
		KToolBarPopupAction * m_pActViewExpNode;
		KToolBarPopupAction * m_pActViewColNode;
		KAction * m_pActXmlElementInsert;
		KAction * m_pActXmlAttributesAdd;
		KAction * m_pActXmlAttributesDel;
		KAction * m_pActXmlAttributeDel;
		KAction * m_pActXmlProcInstrInsert;
		KAction * m_pActInsertText;
		KAction * m_pActInsertCDATA;
		KAction * m_pActInsertComment;
		KAction * m_pActXmlMoveNodeUp;
		KAction * m_pActXmlMoveNodeDown;
		KAction * m_pActBookmarksToggle;
		KAction * m_pActBookmarksPrev;
		KAction * m_pActBookmarksNext;
		KXmlEditorComboAction * m_pActPathCombo;

	protected slots:
		void started();
		void completed();
		void canceled();

		/** @short Enables/disables actions and changes views  */
		void slotSelectionCleared(bool);

		/** @short Enables/disables actions depending on the given XML element and changes views  */
		void slotSelectionChanged( const TQDomElement & );

		/** @short Enables/disables actions and changes views */
		void slotSelectionChanged( const TQDomCharacterData & );

		/** @short Enables/disables actions and changes views */
		void slotSelectionChanged( const TQDomProcessingInstruction & );

		/** @short Shows the requested context menu at the given position. */
		void slotContextMenuRequested( const TQString & szMenuName, const TQPoint & pos );

		/** @short Invoked everytime document has new content */
		void slotDocOpened();

	private:
		/** this view displays the XML-document's tree structure */
		KXE_TreeView * m_pViewTree;

		/** the tab widget, contains: m_pViewElement, m_pViewContents */
		TQTabWidget * m_pTabWidget;

		/** widget to display XML element */
		KXE_ViewElement * m_pViewElement;

		/** edit widget for contents */
		TQTextEdit * m_pViewContents;

		/** widget to display a proc.instr. */
		TQTextEdit * m_pViewProcInstr;

		/** the search dialog, used for find action */
		KXESearchDialog * m_pDlgSearch;

		/** DCOP object having access to XML document. It may by NULL if no DCOP inteface is provided
		or read only privided by @ref KXMLEditorPartReadOnlyIface or full read-write @ref KXMLEditorPartIface .*/
		KXMLEditorPartIfaceReadOnly * m_pDCOPIface;

		bool m_bAlreadyModified;

		/** our browser extension */
		KParts::BrowserExtension * m_pBrowserExt;
		
		/** @short Stores pointer to command history list, which provide undo/redo functionality */
		KCommandHistory* m_pCmdHistory;
		
		/** @short Action for cutting nodes to clipboard.*/
		KAction* m_pActEditCut;

		/** @short Action for copying nodes to clipboard.*/
		KAction* m_pActEditCopy;

		/** @short Action for pasting nodes from clipboard.*/
		KAction* m_pActEditPaste;

		/** Action for editing properties of currently selected node. */
		KAction* m_pActProperties;

		/** Action for editing raw XML of currently selected node. */
		KAction* m_pActEditRawXml;

		/** Action for deleting currently selected node. */
		KAction* m_pActDelete;

		/** @short Action for changing version and encoding of XM file. */
		KAction* m_pActVersionEncoding;

		/** @short Action for attaching stylehseets to xml files. */
		KAction* m_pActAttachStylesheet;

		/** @short Action for detaching stylehseets from xml files. */
		KAction* m_pActDetachStylesheet;

		/** @short Action for attaching schemas to xml files. */
		KAction* m_pActAttachSchema;

		/** @short Action for detaching schemas from xml files. */
		KAction* m_pActDetachSchema;
		
		/** Printer object. */
		KPrinter *m_pPrinter;

		/** spitter - main widget in the part */
		TQSplitter *pSplitter;

		/** Pointer to underlying KXEDocument object */
		KXEDocument* m_pDocument;
		
signals:
		// Add URL to recent file list
		void sigAddRecentURL(const KURL &);
};

/**
 * The browser extension for our part (@ref KXMLEditorPart).
 */
class KXMLEditorBrowserExtension : public KParts::BrowserExtension
{
		Q_OBJECT

	public:
		/** @short Constructor */
		KXMLEditorBrowserExtension( KXMLEditorPart * pParent, const char * pszName = "KXMLEditorBrowserExtension" )
			: KParts::BrowserExtension( pParent, pszName ),
			m_pPart(pParent)
			{ emit enableAction("print", true); }

	public slots:
		void slotEditCut() { m_pPart->slotEditCut(); }
		void slotEditCopy() { m_pPart->slotEditCopy(); }
		void slotEditPaste() { m_pPart->slotEditPaste(); }
		void print() { m_pPart->slotActPrint(); }

	protected:
		/** @short Stores pointer to the part. */
		KXMLEditorPart * m_pPart;
};

#endif