21 #ifndef _KATE_DOCUMENT_H_
22 #define _KATE_DOCUMENT_H_
24 #include "katesupercursor.h"
25 #include "katetextline.h"
27 #include "katebuffer.h"
28 #include "katecodefoldinghelpers.h"
30 #include "../interfaces/document.h"
32 #include <ktexteditor/configinterfaceextension.h>
33 #include <ktexteditor/encodinginterface.h>
34 #include <ktexteditor/sessionconfiginterface.h>
35 #include <ktexteditor/editinterfaceext.h>
36 #include <ktexteditor/templateinterface.h>
38 #include <dcopobject.h>
40 #include <kmimetype.h>
43 #include <tqintdict.h>
45 #include <tqdatetime.h>
49 namespace KIO {
class TransferJob; }
55 class KateCodeFoldingTree;
58 class KateViewInternal;
63 class KateDocumentConfig;
64 class KateHighlighting;
65 class KatePartPluginItem;
66 class KatePartPluginInfo;
72 class KateKeyInterceptorFunctor;
79 public KTextEditor::ConfigInterfaceExtension,
80 public KTextEditor::EncodingInterface,
81 public KTextEditor::SessionConfigInterface,
82 public KTextEditor::EditInterfaceExt,
83 public KTextEditor::TemplateInterface,
89 friend class KateViewInternal;
93 KateDocument (
bool bSingleViewMode=
false,
bool bBrowserView=
false,
bool bReadOnly=
false,
94 TQWidget *parentWidget = 0,
const char *widgetName = 0, TQObject * = 0,
const char * = 0);
103 void unloadAllPlugins ();
105 void enableAllPluginsGUI (KateView *view);
106 void disableAllPluginsGUI (KateView *view);
108 void loadPlugin (uint pluginIndex);
109 void unloadPlugin (uint pluginIndex);
111 void enablePluginGUI (KTextEditor::Plugin *plugin, KateView *view);
112 void enablePluginGUI (KTextEditor::Plugin *plugin);
114 void disablePluginGUI (KTextEditor::Plugin *plugin, KateView *view);
115 void disablePluginGUI (KTextEditor::Plugin *plugin);
118 TQMemArray<KTextEditor::Plugin *> m_plugins;
121 bool readOnly ()
const {
return m_bReadOnly; }
122 bool browserView ()
const {
return m_bBrowserView; }
123 bool singleViewMode ()
const {
return m_bSingleViewMode; }
128 bool m_bSingleViewMode;
137 KTextEditor::View *createView( TQWidget *parent,
const char *name );
138 TQPtrList<KTextEditor::View> views ()
const;
140 inline KateView *activeView ()
const {
return m_activeView; }
143 TQPtrList<KateView> m_views;
144 TQPtrList<KTextEditor::View> m_textEditViews;
145 KateView *m_activeView;
156 void setActiveView( KateView *view );
162 uint configPages ()
const;
163 KTextEditor::ConfigPage *configPage (uint number = 0, TQWidget *parent = 0,
const char *name=0 );
164 TQString configPageName (uint number = 0)
const;
165 TQString configPageFullName (uint number = 0)
const;
166 TQPixmap configPagePixmap (uint number = 0,
int size =
KIcon::SizeSmall)
const;
172 TQString text()
const;
174 TQString text ( uint startLine, uint startCol, uint endLine, uint endCol )
const;
175 TQString text ( uint startLine, uint startCol, uint endLine, uint endCol,
bool blockwise )
const;
177 TQString textLine ( uint line )
const;
179 bool setText(
const TQString &);
182 bool insertText ( uint line, uint col,
const TQString &s );
183 bool insertText ( uint line, uint col,
const TQString &s,
bool blockwise );
185 bool removeText ( uint startLine, uint startCol, uint endLine, uint endCol );
186 bool removeText ( uint startLine, uint startCol, uint endLine, uint endCol,
bool blockwise );
188 bool insertLine ( uint line,
const TQString &s );
189 bool removeLine ( uint line );
191 uint numLines()
const;
192 uint numVisLines()
const;
193 uint length ()
const;
194 int lineLength ( uint line )
const;
198 void charactersInteractivelyInserted(
int ,
int ,
const TQString&);
199 void charactersSemiInteractivelyInserted(
int ,
int ,
const TQString&);
200 void backspacePressed();
209 void editStart (
bool withUndo =
true);
211 void editBegin () { editStart(); }
231 bool editInsertText ( uint line, uint col,
const TQString &s );
239 bool editRemoveText ( uint line, uint col, uint len );
249 bool editMarkLineAutoWrapped ( uint line,
bool autowrapped );
261 bool editWrapLine ( uint line, uint col,
bool newLine =
true,
bool *newLineAdded = 0 );
270 bool editUnWrapLine ( uint line,
bool removeLine =
true, uint length = 0 );
278 bool editInsertLine ( uint line,
const TQString &s );
284 bool editRemoveLine ( uint line );
292 bool wrapText (uint startLine, uint endLine);
300 void editTextInserted ( uint line, uint col, uint len);
305 void editTextRemoved ( uint line, uint col, uint len);
310 void editLineWrapped ( uint line, uint col, uint len );
315 void editLineUnWrapped ( uint line, uint col );
320 void editLineInserted ( uint line );
325 void editLineRemoved ( uint line );
330 void undoSafePoint();
338 uint editSessionNumber;
341 bool m_undoComplexMerge;
353 uint undoCount ()
const;
354 uint redoCount ()
const;
356 uint undoSteps ()
const;
357 void setUndoSteps ( uint steps );
360 friend class KateTemplateHandler;
363 TQPtrList<KateSuperCursor> m_superCursors;
368 TQPtrList<KateUndoGroup> undoItems;
369 TQPtrList<KateUndoGroup> redoItems;
370 bool m_undoDontMerge;
371 bool m_undoIgnoreCancel;
372 TQTimer* m_undoMergeTimer;
377 bool docWasSavedWhenUndoWasEmpty;
378 bool docWasSavedWhenRedoWasEmpty;
381 void updateModified();
385 void textInserted(
int line,
int column);
391 KTextEditor::Cursor *createCursor ();
392 TQPtrList<KTextEditor::Cursor> cursors ()
const;
395 TQPtrList<KTextEditor::Cursor> myCursors;
401 bool searchText (
unsigned int startLine,
unsigned int startCol,
402 const TQString &text,
unsigned int *foundAtLine,
unsigned int *foundAtCol,
403 unsigned int *matchLen,
bool casesensitive =
true,
bool backwards =
false);
404 bool searchText (
unsigned int startLine,
unsigned int startCol,
405 const TQRegExp ®exp,
unsigned int *foundAtLine,
unsigned int *foundAtCol,
406 unsigned int *matchLen,
bool backwards =
false);
413 bool setHlMode (uint mode);
415 TQString hlModeName (uint mode);
416 TQString hlModeSectionName (uint mode);
419 void bufferHlChanged ();
422 void setDontChangeHlOnSave();
444 void readSessionConfig (
KConfig *);
445 void writeSessionConfig (
KConfig *);
446 void configDialog ();
452 uint mark( uint line );
454 void setMark( uint line, uint markType );
455 void clearMark( uint line );
457 void addMark( uint line, uint markType );
458 void removeMark( uint line, uint markType );
460 TQPtrList<KTextEditor::Mark> marks();
463 void setPixmap( MarkInterface::MarkTypes,
const TQPixmap& );
464 void setDescription( MarkInterface::MarkTypes,
const TQString& );
465 TQString markDescription( MarkInterface::MarkTypes );
466 TQPixmap *markPixmap( MarkInterface::MarkTypes );
467 TQColor markColor( MarkInterface::MarkTypes );
469 void setMarksUserChangable( uint markMask );
470 uint editableMarks();
474 void markChanged( KTextEditor::Mark, KTextEditor::MarkInterfaceExtension::MarkChangeAction );
477 TQIntDict<KTextEditor::Mark> m_marks;
478 TQIntDict<TQPixmap> m_markPixmaps;
479 TQIntDict<TQString> m_markDescriptions;
480 uint m_editableMarks;
520 TQString niceFileSize();
530 KMimeType::Ptr mimeTypeForContent();
536 TQString variable(
const TQString &name )
const;
539 void variableChanged(
const TQString &,
const TQString & );
542 TQMap<TQString, TQString> m_storedVariables;
548 bool openURL(
const KURL &url );
558 bool openFile (KIO::Job * job);
563 void setReadWrite (
bool readwrite =
true );
565 void setModified(
bool m );
568 void slotDataKate ( KIO::Job* kio_job,
const TQByteArray &data );
569 void slotFinishedKate ( KIO::Job * job );
572 void abortLoadKate();
574 void activateDirWatch ();
575 void deactivateDirWatch ();
577 TQString m_dirWatchFile;
589 Kate::ConfigPage *
hlConfigPage (TQWidget *) {
return 0; }
590 Kate::ConfigPage *viewDefaultsConfigPage (TQWidget *) {
return 0; }
591 Kate::ConfigPage *saveConfigPage( TQWidget * ) {
return 0; }
593 Kate::ActionMenu *hlActionMenu (
const TQString& , TQObject* = 0,
const char* = 0) {
return 0; }
594 Kate::ActionMenu *exportActionMenu (
const TQString& , TQObject* = 0,
const char* = 0) {
return 0; }
600 bool typeChars ( KateView *type,
const TQString &chars );
605 inline uint lastLine()
const {
return numLines()-1; }
608 void setConfigFlags (uint flags);
611 void repaintViews(
bool paintOnlyDirty =
true);
613 inline KateHighlighting *highlight () {
return m_buffer->highlight(); }
615 inline KateHighlighting *highlight ()
const {
return m_buffer->highlight(); }
618 void tagLines(
int start,
int end);
623 void exportAs(
const TQString&) { };
626 void modifiedChanged ();
627 void preHighlightChanged(uint);
630 void internalHlChanged();
633 void addView(KTextEditor::View *);
634 void removeView(KTextEditor::View *);
639 bool ownedView(KateView *);
640 bool isLastView(
int numViews);
648 void paste ( KateView* view );
651 void insertIndentChars ( KateView *view );
653 void indent ( KateView *view, uint line,
int change );
654 void comment ( KateView *view, uint line, uint column,
int change );
655 void align ( KateView *view, uint line );
657 enum TextTransform { Uppercase, Lowercase, Capitalize };
666 void transform ( KateView *view,
const KateTextCursor &, TextTransform );
670 void joinLines( uint first, uint last );
673 void optimizeLeadingSpace( uint line,
int flags,
int change );
674 void replaceWithOptimizedSpace( uint line, uint upto_column, uint space,
int flags );
676 bool removeStringFromBegining(
int line, TQString &str);
677 bool removeStringFromEnd(
int line, TQString &str);
688 bool nextNonSpaceCharPos(
int &line,
int &col);
697 bool previousNonSpaceCharPos(
int &line,
int &col);
703 void addStartLineCommentToSingleLine(
int line,
int attrib=0);
708 bool removeStartLineCommentFromSingleLine(
int line,
int attrib=0);
713 void addStartStopCommentToSingleLine(
int line,
int attrib=0);
717 bool removeStartStopCommentFromSingleLine(
int line,
int attrib=0);
727 void addStartStopCommentToSelection( KateView *view,
int attrib=0 );
731 void addStartLineCommentToSelection( KateView *view,
int attrib=0 );
739 bool removeStartStopCommentFromSelection( KateView *view,
int attrib=0 );
743 bool removeStartLineCommentFromSelection( KateView *view,
int attrib=0 );
751 void newBracketMark(
const KateTextCursor& start, KateBracketRange& bm,
int maxLines = -1 );
759 TQString
docName () {
return m_docName;};
763 void lineInfo (KateLineInfo *info,
unsigned int line);
765 KateCodeFoldingTree *foldingTree ();
773 bool isModifiedOnDisc() {
return m_modOnHd; };
799 void setEncoding (
const TQString &e);
800 TQString encoding()
const;
803 void setWordWrap (
bool on);
806 void setWordWrapAt (uint col);
810 void setPageUpDownMovesCursor(
bool on);
811 bool pageUpDownMovesCursor();
826 void fileNameChanged ();
829 void applyWordWrap ();
833 inline uint getRealLine(
unsigned int virtualLine)
835 return m_buffer->lineNumber (virtualLine);
838 inline uint getVirtualLine(
unsigned int realLine)
840 return m_buffer->lineVisibleNumber (realLine);
843 inline uint visibleLines ()
845 return m_buffer->countVisible ();
850 return m_buffer->line (i);
855 return m_buffer->plainLine (i);
859 void codeFoldingUpdated();
860 void aboutToRemoveText(
const KateTextRange&);
864 void slotModOnHdDirty (
const TQString &path);
865 void slotModOnHdCreated (
const TQString &path);
866 void slotModOnHdDeleted (
const TQString &path);
878 bool createDigest ( TQCString &result );
885 TQString reasonedMOHString()
const;
895 void removeTrailingSpace( uint line );
898 void updateFileType (
int newType,
bool user =
false);
900 int fileType ()
const {
return m_fileType; };
916 unsigned char m_modOnHdReason;
924 bool m_fileTypeSetByUser;
931 bool m_encodingSticky;
934 void slotQueryClose_save(
bool *handled,
bool* abortClosing);
937 void makeAttribs (
bool needInvalidate =
true);
939 static bool checkOverwrite(
KURL u );
941 static void setDefaultEncoding (
const TQString &encoding);
943 void setEncodingSticky(
bool e ) { m_encodingSticky = e; }
949 inline KateDocumentConfig *config () {
return m_config; };
951 void updateConfig ();
954 KateDocumentConfig *m_config;
964 void readDirConfig ();
970 void readVariables(
bool onlyViewAndRenderer =
false);
976 void readVariableLine( TQString t,
bool onlyViewAndRenderer =
false );
980 void setViewVariable( TQString var, TQString val );
986 static bool checkBoolValue( TQString value,
bool *result );
992 static bool checkIntValue( TQString value,
int *result );
997 static bool checkColorValue( TQString value, TQColor &col );
1002 static TQRegExp kvLine;
1003 static TQRegExp kvLineWildcard;
1004 static TQRegExp kvLineMime;
1005 static TQRegExp kvVar;
1007 KIO::TransferJob *m_job;
1012 bool setTabInterceptor(KateKeyInterceptorFunctor *interceptor);
1013 bool removeTabInterceptor(KateKeyInterceptorFunctor *interceptor);
1014 bool invokeTabInterceptor(
KKey);
1017 virtual bool insertTemplateTextImplementation ( uint line, uint column,
const TQString &templateString,
const TQMap<TQString,TQString> &initialValues, TQWidget *parentWindow=0 );
1018 KateKeyInterceptorFunctor *m_tabInterceptor;
1021 void testTemplateCode();
1022 void dumpRegionTree();
1030 bool setSelection ( uint startLine, uint startCol, uint endLine, uint endCol );
1031 bool clearSelection ();
1032 bool hasSelection ()
const;
1033 TQString selection ()
const;
1034 bool removeSelectedText ();
1048 #define signals public
1051 #define signals protected
1052 void selectionChanged ();
1059 bool blockSelectionMode ();
1060 bool setBlockSelectionMode (
bool on);
1061 bool toggleBlockSelectionMode ();
1067 uint documentNumber ()
const;
KAction * saveAs(const TQObject *recvr, const char *slot, KActionCollection *parent, const char *name=0)
Interface for embedding KateDocument into a browser.
Simple cursor class with no document pointer.
The Attribute class incorporates all text decorations supported by Kate.
virtual void setDocName(TQString)
Sets the document name.
virtual TQString docName()
Returns the document name.
kndbgstream & flush(kndbgstream &s)
KAction * clear(const TQObject *recvr, const char *slot, KActionCollection *parent, const char *name=0)
virtual ConfigPage * colorConfigPage(TQWidget *)=0
Represents a range of text, from the start() to the end().
const KShortcut & paste()
This interface provides access to the Kate Document class.
virtual ConfigPage * selectConfigPage(TQWidget *)=0
virtual ConfigPage * fontConfigPage(TQWidget *)=0
The Kate::View text editor interface.
Extensions to the Document Interface.
Class to manage a group of undo items.
Handles all of the work of rendering the text (used for the views and printing)
Provides Auto-Indent functionality for katepart.
virtual ConfigPage * editConfigPage(TQWidget *)=0
virtual ConfigPage * indentConfigPage(TQWidget *)=0
virtual void isModOnHD(bool=false)
deprecated for KDE 4.0, just does reloadFile, which will ask the normal "do you want it really" quest...
const KShortcut & selectAll()
UndoType
Types for undo items.
virtual ConfigPage * keysConfigPage(TQWidget *)=0
virtual void slotModifiedOnDisk(View *v=0)=0
These stuff is implemented as slots in the real document.
virtual void reloadFile()=0
Reloads the current document from disk if possible.
Possible additional features:
const KShortcut & print()
An arbitrary highlighting interface for Kate.
The KateBuffer class maintains a collections of lines.
virtual void setModifiedOnDisk(int reason)=0
For client apps that want to deal with files modified on disk, it is nessecary to reset this property...
virtual ConfigPage * hlConfigPage(TQWidget *)=0