TDE core libraries
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

katedocument.h 30KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075
  1. /* This file is part of the KDE libraries
  2. Copyright (C) 2001-2004 Christoph Cullmann <cullmann@kde.org>
  3. Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org>
  4. Copyright (C) 1999 Jochen Wilhelmy <digisnap@cs.tu-berlin.de>
  5. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Library General Public
  7. License version 2 as published by the Free Software Foundation.
  8. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Library General Public License for more details.
  12. You should have received a copy of the GNU Library General Public License
  13. along with this library; see the file COPYING.LIB. If not, write to
  14. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  15. Boston, MA 02110-1301, USA.
  16. */
  17. #ifndef _KATE_DOCUMENT_H_
  18. #define _KATE_DOCUMENT_H_
  19. #include "katesupercursor.h"
  20. #include "katetextline.h"
  21. #include "kateundo.h"
  22. #include "katebuffer.h"
  23. #include "katecodefoldinghelpers.h"
  24. #include "../interfaces/document.h"
  25. #include <tdetexteditor/configinterfaceextension.h>
  26. #include <tdetexteditor/encodinginterface.h>
  27. #include <tdetexteditor/sessionconfiginterface.h>
  28. #include <tdetexteditor/editinterfaceext.h>
  29. #include <tdetexteditor/templateinterface.h>
  30. #include <dcopobject.h>
  31. #include <kmimetype.h>
  32. #include <tdelocale.h>
  33. #include <tqintdict.h>
  34. #include <tqmap.h>
  35. #include <tqdatetime.h>
  36. namespace KTextEditor { class Plugin; }
  37. namespace TDEIO { class TransferJob; }
  38. class KateUndoGroup;
  39. class KateCmd;
  40. class KateAttribute;
  41. class KateAutoIndent;
  42. class KateCodeFoldingTree;
  43. class KateBuffer;
  44. class KateView;
  45. class KateViewInternal;
  46. class KateArbitraryHighlight;
  47. class KateSuperRange;
  48. class KateLineInfo;
  49. class KateBrowserExtension;
  50. class KateDocumentConfig;
  51. class KateHighlighting;
  52. class KatePartPluginItem;
  53. class KatePartPluginInfo;
  54. class KTempFile;
  55. class TQTimer;
  56. class KateKeyInterceptorFunctor;
  57. //
  58. // Kate KTextEditor::Document class (and even KTextEditor::Editor ;)
  59. //
  60. class KateDocument : public Kate::Document,
  61. public Kate::DocumentExt,
  62. public KTextEditor::ConfigInterfaceExtension,
  63. public KTextEditor::EncodingInterface,
  64. public KTextEditor::SessionConfigInterface,
  65. public KTextEditor::EditInterfaceExt,
  66. public KTextEditor::TemplateInterface,
  67. public DCOPObject
  68. {
  69. K_DCOP
  70. Q_OBJECT
  71. friend class KateViewInternal;
  72. friend class KateRenderer;
  73. public:
  74. KateDocument (bool bSingleViewMode=false, bool bBrowserView=false, bool bReadOnly=false,
  75. TQWidget *parentWidget = 0, const char *widgetName = 0, TQObject * = 0, const char * = 0);
  76. ~KateDocument ();
  77. bool closeURL();
  78. //
  79. // Plugins section
  80. //
  81. public:
  82. void unloadAllPlugins ();
  83. void enableAllPluginsGUI (KateView *view);
  84. void disableAllPluginsGUI (KateView *view);
  85. void loadPlugin (uint pluginIndex);
  86. void unloadPlugin (uint pluginIndex);
  87. void enablePluginGUI (KTextEditor::Plugin *plugin, KateView *view);
  88. void enablePluginGUI (KTextEditor::Plugin *plugin);
  89. void disablePluginGUI (KTextEditor::Plugin *plugin, KateView *view);
  90. void disablePluginGUI (KTextEditor::Plugin *plugin);
  91. private:
  92. TQMemArray<KTextEditor::Plugin *> m_plugins;
  93. public:
  94. bool readOnly () const { return m_bReadOnly; }
  95. bool browserView () const { return m_bBrowserView; }
  96. bool singleViewMode () const { return m_bSingleViewMode; }
  97. KateBrowserExtension *browserExtension () { return m_extension; }
  98. private:
  99. // only to make part work, don't change it !
  100. bool m_bSingleViewMode;
  101. bool m_bBrowserView;
  102. bool m_bReadOnly;
  103. KateBrowserExtension *m_extension;
  104. //
  105. // KTextEditor::Document stuff
  106. //
  107. public:
  108. KTextEditor::View *createView( TQWidget *parent, const char *name );
  109. TQPtrList<KTextEditor::View> views () const;
  110. inline KateView *activeView () const { return m_activeView; }
  111. private:
  112. TQPtrList<KateView> m_views;
  113. TQPtrList<KTextEditor::View> m_textEditViews;
  114. KateView *m_activeView;
  115. /**
  116. * set the active view.
  117. *
  118. * If @p view is allready the active view, nothing is done.
  119. *
  120. * If the document is modified on disk, ask the user what to do.
  121. *
  122. * @since Kate 2.4
  123. */
  124. void setActiveView( KateView *view );
  125. //
  126. // KTextEditor::ConfigInterfaceExtension stuff
  127. //
  128. public slots:
  129. uint configPages () const;
  130. KTextEditor::ConfigPage *configPage (uint number = 0, TQWidget *parent = 0, const char *name=0 );
  131. TQString configPageName (uint number = 0) const;
  132. TQString configPageFullName (uint number = 0) const;
  133. TQPixmap configPagePixmap (uint number = 0, int size = TDEIcon::SizeSmall) const;
  134. //
  135. // KTextEditor::EditInterface stuff
  136. //
  137. public slots:
  138. TQString text() const;
  139. TQString text ( uint startLine, uint startCol, uint endLine, uint endCol ) const;
  140. TQString text ( uint startLine, uint startCol, uint endLine, uint endCol, bool blockwise ) const;
  141. TQString textLine ( uint line ) const;
  142. bool setText(const TQString &);
  143. bool clear ();
  144. bool insertText ( uint line, uint col, const TQString &s );
  145. bool insertText ( uint line, uint col, const TQString &s, bool blockwise );
  146. bool removeText ( uint startLine, uint startCol, uint endLine, uint endCol );
  147. bool removeText ( uint startLine, uint startCol, uint endLine, uint endCol, bool blockwise );
  148. bool insertLine ( uint line, const TQString &s );
  149. bool removeLine ( uint line );
  150. uint numLines() const;
  151. uint numVisLines() const;
  152. uint length () const;
  153. int lineLength ( uint line ) const;
  154. signals:
  155. void textChanged ();
  156. void charactersInteractivelyInserted(int ,int ,const TQString&);
  157. void charactersSemiInteractivelyInserted(int ,int ,const TQString&);
  158. void backspacePressed();
  159. public:
  160. //BEGIN editStart/editEnd (start, end, undo, cursor update, view update)
  161. /**
  162. * Enclose editor actions with @p editStart() and @p editEnd() to group
  163. * them.
  164. * @param withUndo if true, add undo history
  165. */
  166. void editStart (bool withUndo = true);
  167. /** Same as editStart() with undo */
  168. void editBegin () { editStart(); }
  169. /**
  170. * End a editor operation.
  171. * @see editStart()
  172. */
  173. void editEnd ();
  174. private:
  175. bool m_isInUndo; ///< set to true in undo/redo
  176. //END editStart/editEnd
  177. //BEGIN LINE BASED INSERT/REMOVE STUFF (editStart() and editEnd() included)
  178. public:
  179. /**
  180. * Add a string in the given line/column
  181. * @param line line number
  182. * @param col column
  183. * @param s string to be inserted
  184. * @return true on success
  185. */
  186. bool editInsertText ( uint line, uint col, const TQString &s );
  187. /**
  188. * Remove a string in the given line/column
  189. * @param line line number
  190. * @param col column
  191. * @param len length of text to be removed
  192. * @return true on success
  193. */
  194. bool editRemoveText ( uint line, uint col, uint len );
  195. /**
  196. * Mark @p line as @p autowrapped. This is necessary if static word warp is
  197. * enabled, because we have to know whether to insert a new line or add the
  198. * wrapped words to the followin line.
  199. * @param line line number
  200. * @param autowrapped autowrapped?
  201. * @return true on success
  202. */
  203. bool editMarkLineAutoWrapped ( uint line, bool autowrapped );
  204. /**
  205. * Wrap @p line. If @p newLine is true, ignore the textline's flag
  206. * KateTextLine::flagAutoWrapped and force a new line. Whether a new line
  207. * was needed/added you can grab with @p newLineAdded.
  208. * @param line line number
  209. * @param col column
  210. * @param newLine if true, force a new line
  211. * @param newLineAdded return value is true, if new line was added (may be 0)
  212. * @return true on success
  213. */
  214. bool editWrapLine ( uint line, uint col, bool newLine = true, bool *newLineAdded = 0 );
  215. /**
  216. * Unwrap @p line. If @p removeLine is true, we force to join the lines. If
  217. * @p removeLine is true, @p length is ignored (eg not needed).
  218. * @param line line number
  219. * @param removeLine if true, force to remove the next line
  220. * @param length length of the line
  221. * @return true on success
  222. */
  223. bool editUnWrapLine ( uint line, bool removeLine = true, uint length = 0 );
  224. /**
  225. * Insert a string at the given line.
  226. * @param line line number
  227. * @param s string to insert
  228. * @return true on success
  229. */
  230. bool editInsertLine ( uint line, const TQString &s );
  231. /**
  232. * Remove a line
  233. * @param line line number
  234. * @return true on success
  235. */
  236. bool editRemoveLine ( uint line );
  237. /**
  238. * Remove a line
  239. * @param startLine line to begin wrapping
  240. * @param endLine line to stop wrapping
  241. * @return true on success
  242. */
  243. bool wrapText (uint startLine, uint endLine);
  244. //END LINE BASED INSERT/REMOVE STUFF
  245. signals:
  246. /**
  247. * Emitted each time text is inserted into a pre-existing line, including appends.
  248. * Does not include newly inserted lines at the moment. ### needed?
  249. */
  250. void editTextInserted ( uint line, uint col, uint len);
  251. /**
  252. * Emitted each time text is removed from a line, including truncates and space removal.
  253. */
  254. void editTextRemoved ( uint line, uint col, uint len);
  255. /**
  256. * Emmitted when text from @p line was wrapped at position pos onto line @p nextLine.
  257. */
  258. void editLineWrapped ( uint line, uint col, uint len );
  259. /**
  260. * Emitted each time text from @p nextLine was upwrapped onto @p line.
  261. */
  262. void editLineUnWrapped ( uint line, uint col );
  263. /**
  264. * Emitted whenever a line is inserted before @p line, becoming itself line @ line.
  265. */
  266. void editLineInserted ( uint line );
  267. /**
  268. * Emitted when a line is deleted.
  269. */
  270. void editLineRemoved ( uint line );
  271. private:
  272. void undoStart();
  273. void undoEnd();
  274. void undoSafePoint();
  275. private slots:
  276. void undoCancel();
  277. private:
  278. void editAddUndo (KateUndoGroup::UndoType type, uint line, uint col, uint len, const TQString &text);
  279. uint editSessionNumber;
  280. bool editIsRunning;
  281. bool editWithUndo;
  282. bool m_undoComplexMerge;
  283. KateUndoGroup* m_editCurrentUndo;
  284. //
  285. // KTextEditor::UndoInterface stuff
  286. //
  287. public slots:
  288. void undo ();
  289. void redo ();
  290. void clearUndo ();
  291. void clearRedo ();
  292. uint undoCount () const;
  293. uint redoCount () const;
  294. uint undoSteps () const;
  295. void setUndoSteps ( uint steps );
  296. private:
  297. friend class KateTemplateHandler;
  298. private:
  299. TQPtrList<KateSuperCursor> m_superCursors;
  300. //
  301. // some internals for undo/redo
  302. //
  303. TQPtrList<KateUndoGroup> undoItems;
  304. TQPtrList<KateUndoGroup> redoItems;
  305. bool m_undoDontMerge; //create a setter later on and remove the friend declaration
  306. bool m_undoIgnoreCancel;
  307. TQTimer* m_undoMergeTimer;
  308. // these two variables are for resetting the document to
  309. // non-modified if all changes have been undone...
  310. KateUndoGroup* lastUndoGroupWhenSaved;
  311. KateUndoGroup* lastRedoGroupWhenSaved;
  312. bool docWasSavedWhenUndoWasEmpty;
  313. bool docWasSavedWhenRedoWasEmpty;
  314. // this sets
  315. void updateModified();
  316. signals:
  317. void undoChanged ();
  318. void textInserted(int line,int column);
  319. //
  320. // KTextEditor::CursorInterface stuff
  321. //
  322. public slots:
  323. KTextEditor::Cursor *createCursor ();
  324. TQPtrList<KTextEditor::Cursor> cursors () const;
  325. private:
  326. TQPtrList<KTextEditor::Cursor> myCursors;
  327. //
  328. // KTextEditor::SearchInterface stuff
  329. //
  330. public slots:
  331. bool searchText (unsigned int startLine, unsigned int startCol,
  332. const TQString &text, unsigned int *foundAtLine, unsigned int *foundAtCol,
  333. unsigned int *matchLen, bool casesensitive = true, bool backwards = false);
  334. bool searchText (unsigned int startLine, unsigned int startCol,
  335. const TQRegExp &regexp, unsigned int *foundAtLine, unsigned int *foundAtCol,
  336. unsigned int *matchLen, bool backwards = false);
  337. //
  338. // KTextEditor::HighlightingInterface stuff
  339. //
  340. public slots:
  341. uint hlMode ();
  342. bool setHlMode (uint mode);
  343. uint hlModeCount ();
  344. TQString hlModeName (uint mode);
  345. TQString hlModeSectionName (uint mode);
  346. public:
  347. void bufferHlChanged ();
  348. private:
  349. void setDontChangeHlOnSave();
  350. signals:
  351. void hlChanged ();
  352. //
  353. // Kate::ArbitraryHighlightingInterface stuff
  354. //
  355. public:
  356. KateArbitraryHighlight* arbitraryHL() const { return m_arbitraryHL; };
  357. private slots:
  358. void tagArbitraryLines(KateView* view, KateSuperRange* range);
  359. //
  360. // KTextEditor::ConfigInterface stuff
  361. //
  362. public slots:
  363. void readConfig ();
  364. void writeConfig ();
  365. void readConfig (TDEConfig *);
  366. void writeConfig (TDEConfig *);
  367. void readSessionConfig (TDEConfig *);
  368. void writeSessionConfig (TDEConfig *);
  369. void configDialog ();
  370. //
  371. // KTextEditor::MarkInterface and MarkInterfaceExtension
  372. //
  373. public slots:
  374. uint mark( uint line );
  375. void setMark( uint line, uint markType );
  376. void clearMark( uint line );
  377. void addMark( uint line, uint markType );
  378. void removeMark( uint line, uint markType );
  379. TQPtrList<KTextEditor::Mark> marks();
  380. void clearMarks();
  381. void setPixmap( MarkInterface::MarkTypes, const TQPixmap& );
  382. void setDescription( MarkInterface::MarkTypes, const TQString& );
  383. TQString markDescription( MarkInterface::MarkTypes );
  384. TQPixmap *markPixmap( MarkInterface::MarkTypes );
  385. TQColor markColor( MarkInterface::MarkTypes );
  386. void setMarksUserChangable( uint markMask );
  387. uint editableMarks();
  388. signals:
  389. void marksChanged();
  390. void markChanged( KTextEditor::Mark, KTextEditor::MarkInterfaceExtension::MarkChangeAction );
  391. private:
  392. TQIntDict<KTextEditor::Mark> m_marks;
  393. TQIntDict<TQPixmap> m_markPixmaps;
  394. TQIntDict<TQString> m_markDescriptions;
  395. uint m_editableMarks;
  396. //
  397. // KTextEditor::PrintInterface
  398. //
  399. public slots:
  400. bool printDialog ();
  401. bool print ();
  402. //
  403. // KTextEditor::DocumentInfoInterface ( ### unfinished )
  404. //
  405. public:
  406. /**
  407. * @return the name of the mimetype for the document.
  408. *
  409. * This method is using KMimeType::findByURL, and if the pointer
  410. * is then still the default MimeType for a nonlocal or unsaved file,
  411. * uses mimeTypeForContent().
  412. *
  413. * @since Kate 2.3
  414. */
  415. TQString mimeType();
  416. /**
  417. * @return the calculated size in bytes that the document would have when saved to
  418. * disk.
  419. *
  420. * @since Kate 2.3
  421. * @todo implement this (it returns 0 right now)
  422. */
  423. long fileSize();
  424. /**
  425. * @return the calculated size the document would have when saved to disk
  426. * as a human readable string.
  427. *
  428. * @since Kate 2.3
  429. * @todo implement this (it returns "UNKNOWN")
  430. */
  431. TQString niceFileSize();
  432. /**
  433. * @return a pointer to the KMimeType for this document, found by analyzing the
  434. * actual content.
  435. *
  436. * Note that this method is *not* part of the DocumentInfoInterface.
  437. *
  438. * @since Kate 2.3
  439. */
  440. KMimeType::Ptr mimeTypeForContent();
  441. //
  442. // KTextEditor::VariableInterface
  443. //
  444. public:
  445. TQString variable( const TQString &name ) const;
  446. signals:
  447. void variableChanged( const TQString &, const TQString & );
  448. private:
  449. TQMap<TQString, TQString> m_storedVariables;
  450. //
  451. // KParts::ReadWrite stuff
  452. //
  453. public:
  454. bool openURL( const KURL &url );
  455. /* Anders:
  456. I reimplemented this, since i need to check if backup succeeded
  457. if requested */
  458. bool save();
  459. /* Anders: Reimplemented to do kate specific stuff */
  460. bool saveAs( const KURL &url );
  461. bool openFile (TDEIO::Job * job);
  462. bool openFile ();
  463. bool saveFile ();
  464. void setReadWrite ( bool readwrite = true );
  465. void setModified( bool m );
  466. private slots:
  467. void slotDataKate ( TDEIO::Job* tdeio_job, const TQByteArray &data );
  468. void slotFinishedKate ( TDEIO::Job * job );
  469. private:
  470. void abortLoadKate();
  471. void activateDirWatch ();
  472. void deactivateDirWatch ();
  473. TQString m_dirWatchFile;
  474. //
  475. // Kate::Document stuff, this is all deprecated!!!!!!!!!!
  476. //
  477. public:
  478. Kate::ConfigPage *colorConfigPage (TQWidget *) { return 0; }
  479. Kate::ConfigPage *fontConfigPage (TQWidget *) { return 0; }
  480. Kate::ConfigPage *indentConfigPage (TQWidget *) { return 0; }
  481. Kate::ConfigPage *selectConfigPage (TQWidget *) { return 0; }
  482. Kate::ConfigPage *editConfigPage (TQWidget *) { return 0; }
  483. Kate::ConfigPage *keysConfigPage (TQWidget *) { return 0; }
  484. Kate::ConfigPage *hlConfigPage (TQWidget *) { return 0; }
  485. Kate::ConfigPage *viewDefaultsConfigPage (TQWidget *) { return 0; }
  486. Kate::ConfigPage *saveConfigPage( TQWidget * ) { return 0; }
  487. Kate::ActionMenu *hlActionMenu (const TQString& /* text */, TQObject* /* parent */ = 0, const char* /* name */ = 0) { return 0; }
  488. Kate::ActionMenu *exportActionMenu (const TQString& /* text */, TQObject* /* parent */ = 0, const char* /* name */ = 0) { return 0; }
  489. public:
  490. /**
  491. * Type chars in a view
  492. */
  493. bool typeChars ( KateView *type, const TQString &chars );
  494. /**
  495. * gets the last line number (numLines() -1)
  496. */
  497. inline uint lastLine() const { return numLines()-1; }
  498. uint configFlags ();
  499. void setConfigFlags (uint flags);
  500. // Repaint all of all of the views
  501. void repaintViews(bool paintOnlyDirty = true);
  502. inline KateHighlighting *highlight () { return m_buffer->highlight(); }
  503. inline KateHighlighting *highlight () const { return m_buffer->highlight(); }
  504. public slots: //please keep prototypes and implementations in same order
  505. void tagLines(int start, int end);
  506. void tagLines(KateTextCursor start, KateTextCursor end);
  507. //export feature, obsolute
  508. public slots:
  509. void exportAs(const TQString&) { };
  510. signals:
  511. void modifiedChanged ();
  512. void preHighlightChanged(uint);
  513. private slots:
  514. void internalHlChanged();
  515. public:
  516. void addView(KTextEditor::View *);
  517. void removeView(KTextEditor::View *);
  518. void addSuperCursor(class KateSuperCursor *, bool privateC);
  519. void removeSuperCursor(class KateSuperCursor *, bool privateC);
  520. bool ownedView(KateView *);
  521. bool isLastView(int numViews);
  522. uint currentColumn( const KateTextCursor& );
  523. void newLine( KateTextCursor&, KateViewInternal * ); // Changes input
  524. void backspace( KateView *view, const KateTextCursor& );
  525. void del( KateView *view, const KateTextCursor& );
  526. void transpose( const KateTextCursor& );
  527. void paste ( KateView* view );
  528. public:
  529. void insertIndentChars ( KateView *view );
  530. void indent ( KateView *view, uint line, int change );
  531. void comment ( KateView *view, uint line, uint column, int change );
  532. void align ( KateView *view, uint line );
  533. enum TextTransform { Uppercase, Lowercase, Capitalize };
  534. /**
  535. Handling uppercase, lowercase and capitalize for the view.
  536. If there is a selection, that is transformed, otherwise for uppercase or
  537. lowercase the character right of the cursor is transformed, for capitalize
  538. the word under the cursor is transformed.
  539. */
  540. void transform ( KateView *view, const KateTextCursor &, TextTransform );
  541. /**
  542. Unwrap a range of lines.
  543. */
  544. void joinLines( uint first, uint last );
  545. private:
  546. void optimizeLeadingSpace( uint line, int flags, int change );
  547. void replaceWithOptimizedSpace( uint line, uint upto_column, uint space, int flags );
  548. bool removeStringFromBegining(int line, TQString &str);
  549. bool removeStringFromEnd(int line, TQString &str);
  550. /**
  551. Find the position (line and col) of the next char
  552. that is not a space. If found line and col point to the found character.
  553. Otherwise they have both the value -1.
  554. @param line Line of the character which is examined first.
  555. @param col Column of the character which is examined first.
  556. @return True if the specified or a following character is not a space
  557. Otherwise false.
  558. */
  559. bool nextNonSpaceCharPos(int &line, int &col);
  560. /**
  561. Find the position (line and col) of the previous char
  562. that is not a space. If found line and col point to the found character.
  563. Otherwise they have both the value -1.
  564. @return True if the specified or a preceding character is not a space.
  565. Otherwise false.
  566. */
  567. bool previousNonSpaceCharPos(int &line, int &col);
  568. /**
  569. * Sets a comment marker as defined by the language providing the attribute
  570. * @p attrib on the line @p line
  571. */
  572. void addStartLineCommentToSingleLine(int line, int attrib=0);
  573. /**
  574. * Removes a comment marker as defined by the language providing the attribute
  575. * @p attrib on the line @p line
  576. */
  577. bool removeStartLineCommentFromSingleLine(int line, int attrib=0);
  578. /**
  579. * @see addStartLineCommentToSingleLine.
  580. */
  581. void addStartStopCommentToSingleLine(int line, int attrib=0);
  582. /**
  583. *@see removeStartLineCommentFromSingleLine.
  584. */
  585. bool removeStartStopCommentFromSingleLine(int line, int attrib=0);
  586. /**
  587. *@see removeStartLineCommentFromSingleLine.
  588. */
  589. bool removeStartStopCommentFromRegion(const KateTextCursor &start, const KateTextCursor &end, int attrib=0);
  590. /**
  591. * Add a comment marker as defined by the language providing the attribute
  592. * @p attrib to each line in the selection.
  593. */
  594. void addStartStopCommentToSelection( KateView *view, int attrib=0 );
  595. /**
  596. * @see addStartStopCommentToSelection.
  597. */
  598. void addStartLineCommentToSelection( KateView *view, int attrib=0 );
  599. /**
  600. * Removes comment markers relevant to the language providing
  601. * the attribuge @p attrib from each line in the selection.
  602. *
  603. * @return whether the operation succeded.
  604. */
  605. bool removeStartStopCommentFromSelection( KateView *view, int attrib=0 );
  606. /**
  607. * @see removeStartStopCommentFromSelection.
  608. */
  609. bool removeStartLineCommentFromSelection( KateView *view, int attrib=0 );
  610. public:
  611. TQString getWord( const KateTextCursor& cursor );
  612. public:
  613. void tagAll();
  614. void newBracketMark( const KateTextCursor& start, KateBracketRange& bm, int maxLines = -1 );
  615. bool findMatchingBracket( KateTextCursor& start, KateTextCursor& end, int maxLines = -1 );
  616. private:
  617. void guiActivateEvent( KParts::GUIActivateEvent *ev );
  618. public:
  619. TQString docName () {return m_docName;};
  620. void setDocName (TQString docName);
  621. void lineInfo (KateLineInfo *info, unsigned int line);
  622. KateCodeFoldingTree *foldingTree ();
  623. public:
  624. /**
  625. * @return wheather the document is modified on disc since last saved.
  626. *
  627. * @since 3.3
  628. */
  629. bool isModifiedOnDisc() { return m_modOnHd; };
  630. /** @deprecated */
  631. void isModOnHD( bool =false ) {};
  632. void setModifiedOnDisk( int reason );
  633. public slots:
  634. /**
  635. * Ask the user what to do, if the file has been modified on disc.
  636. * Reimplemented from Kate::Document.
  637. *
  638. * @since 3.3
  639. */
  640. void slotModifiedOnDisk( Kate::View *v=0 );
  641. /**
  642. * Reloads the current document from disc if possible
  643. */
  644. void reloadFile();
  645. private:
  646. int m_isasking; // don't reenter slotModifiedOnDisk when this is true
  647. // -1: ignore once, 0: false, 1: true
  648. public slots:
  649. void setEncoding (const TQString &e);
  650. TQString encoding() const;
  651. public slots:
  652. void setWordWrap (bool on);
  653. bool wordWrap ();
  654. void setWordWrapAt (uint col);
  655. uint wordWrapAt ();
  656. public slots:
  657. void setPageUpDownMovesCursor(bool on);
  658. bool pageUpDownMovesCursor();
  659. signals:
  660. void modStateChanged (Kate::Document *doc);
  661. void nameChanged (Kate::Document *doc);
  662. public slots:
  663. // clear buffer/filename - update the views
  664. void flush ();
  665. signals:
  666. /**
  667. * The file has been saved (perhaps the name has changed). The main window
  668. * can use this to change its caption
  669. */
  670. void fileNameChanged ();
  671. public slots:
  672. void applyWordWrap ();
  673. // code folding
  674. public:
  675. inline uint getRealLine(unsigned int virtualLine)
  676. {
  677. return m_buffer->lineNumber (virtualLine);
  678. }
  679. inline uint getVirtualLine(unsigned int realLine)
  680. {
  681. return m_buffer->lineVisibleNumber (realLine);
  682. }
  683. inline uint visibleLines ()
  684. {
  685. return m_buffer->countVisible ();
  686. }
  687. inline KateTextLine::Ptr kateTextLine(uint i)
  688. {
  689. return m_buffer->line (i);
  690. }
  691. inline KateTextLine::Ptr plainKateTextLine(uint i)
  692. {
  693. return m_buffer->plainLine (i);
  694. }
  695. signals:
  696. void codeFoldingUpdated();
  697. void aboutToRemoveText(const KateTextRange&);
  698. void textRemoved();
  699. private slots:
  700. void slotModOnHdDirty (const TQString &path);
  701. void slotModOnHdCreated (const TQString &path);
  702. void slotModOnHdDeleted (const TQString &path);
  703. private:
  704. /**
  705. * create a MD5 digest of the file, if it is a local file,
  706. * and fill it into the string @p result.
  707. * This is using KMD5::hexDigest().
  708. *
  709. * @return wheather the operation was attempted and succeded.
  710. *
  711. * @since 3.3
  712. */
  713. bool createDigest ( TQCString &result );
  714. /**
  715. * create a string for the modonhd warnings, giving the reason.
  716. *
  717. * @since 3.3
  718. */
  719. TQString reasonedMOHString() const;
  720. /**
  721. * Removes all trailing whitespace form @p line, if
  722. * the cfRemoveTrailingDyn confg flag is set,
  723. * and the active view cursor is not on line and behind
  724. * the last nonspace character.
  725. *
  726. * @since 3.3
  727. */
  728. void removeTrailingSpace( uint line );
  729. public:
  730. void updateFileType (int newType, bool user = false);
  731. int fileType () const { return m_fileType; };
  732. //
  733. // REALLY internal data ;)
  734. //
  735. private:
  736. // text buffer
  737. KateBuffer *m_buffer;
  738. KateArbitraryHighlight* m_arbitraryHL;
  739. KateAutoIndent *m_indenter;
  740. bool hlSetByUser;
  741. bool m_modOnHd;
  742. unsigned char m_modOnHdReason;
  743. TQCString m_digest; // MD5 digest, updated on load/save
  744. TQString m_docName;
  745. int m_docNameNumber;
  746. // file type !!!
  747. int m_fileType;
  748. bool m_fileTypeSetByUser;
  749. /**
  750. * document is still reloading a file
  751. */
  752. bool m_reloading;
  753. bool m_loading; ///< true in openFile() untill the data is read.
  754. bool m_encodingSticky; ///< true when requests to set encoding should be ignored.
  755. public slots:
  756. void slotQueryClose_save(bool *handled, bool* abortClosing);
  757. public:
  758. void makeAttribs (bool needInvalidate = true);
  759. static bool checkOverwrite( KURL u );
  760. static void setDefaultEncoding (const TQString &encoding);
  761. void setEncodingSticky( bool e ) { m_encodingSticky = e; }
  762. /**
  763. * Configuration
  764. */
  765. public:
  766. inline KateDocumentConfig *config () { return m_config; };
  767. void updateConfig ();
  768. private:
  769. KateDocumentConfig *m_config;
  770. /**
  771. * Variable Reader
  772. * TODO add register functionality/tdetexteditor interface
  773. */
  774. private:
  775. /**
  776. * read dir config file
  777. */
  778. void readDirConfig ();
  779. /**
  780. Reads all the variables in the document.
  781. Called when opening/saving a document
  782. */
  783. void readVariables(bool onlyViewAndRenderer = false);
  784. /**
  785. Reads and applies the variables in a single line
  786. TODO registered variables gets saved in a [map]
  787. */
  788. void readVariableLine( TQString t, bool onlyViewAndRenderer = false );
  789. /**
  790. Sets a view variable in all the views.
  791. */
  792. void setViewVariable( TQString var, TQString val );
  793. /**
  794. @return weather a string value could be converted
  795. to a bool value as supported.
  796. The value is put in *result.
  797. */
  798. static bool checkBoolValue( TQString value, bool *result );
  799. /**
  800. @return weather a string value could be converted
  801. to a integer value.
  802. The value is put in *result.
  803. */
  804. static bool checkIntValue( TQString value, int *result );
  805. /**
  806. Feeds value into @p col using TQColor::setNamedColor() and returns
  807. wheather the color is valid
  808. */
  809. static bool checkColorValue( TQString value, TQColor &col );
  810. /**
  811. * helper regex to capture the document variables
  812. */
  813. static TQRegExp kvLine;
  814. static TQRegExp kvLineWildcard;
  815. static TQRegExp kvLineMime;
  816. static TQRegExp kvVar;
  817. TDEIO::TransferJob *m_job;
  818. KTempFile *m_tempFile;
  819. // TemplateInterface
  820. public:
  821. bool setTabInterceptor(KateKeyInterceptorFunctor *interceptor); /* perhaps make it moregeneral like an eventfilter*/
  822. bool removeTabInterceptor(KateKeyInterceptorFunctor *interceptor);
  823. bool invokeTabInterceptor(KKey);
  824. protected:
  825. virtual bool insertTemplateTextImplementation ( uint line, uint column, const TQString &templateString, const TQMap<TQString,TQString> &initialValues, TQWidget *parentWindow=0 );
  826. KateKeyInterceptorFunctor *m_tabInterceptor;
  827. protected slots:
  828. void testTemplateCode();
  829. void dumpRegionTree();
  830. //BEGIN DEPRECATED
  831. //
  832. // KTextEditor::SelectionInterface stuff
  833. // DEPRECATED, this will be removed for KDE 4.x !!!!!!!!!!!!!!!!!!!!
  834. //
  835. public slots:
  836. bool setSelection ( uint startLine, uint startCol, uint endLine, uint endCol );
  837. bool clearSelection ();
  838. bool hasSelection () const;
  839. TQString selection () const;
  840. bool removeSelectedText ();
  841. bool selectAll();
  842. //
  843. // KTextEditor::SelectionInterfaceExt
  844. //
  845. int selStartLine();
  846. int selStartCol();
  847. int selEndLine();
  848. int selEndCol();
  849. // hack, only there to still support the deprecated stuff, will be removed for KDE 4.x
  850. #undef signals
  851. #define signals public
  852. signals:
  853. #undef signals
  854. #define signals protected
  855. void selectionChanged ();
  856. //
  857. // KTextEditor::BlockSelectionInterface stuff
  858. // DEPRECATED, this will be removed for KDE 4.x !!!!!!!!!!!!!!!!!!!!
  859. //
  860. public slots:
  861. bool blockSelectionMode ();
  862. bool setBlockSelectionMode (bool on);
  863. bool toggleBlockSelectionMode ();
  864. private:
  865. //END DEPRECATED
  866. k_dcop:
  867. uint documentNumber () const;
  868. long documentListPosition () const;
  869. void setDocumentListPosition (long pos);
  870. };
  871. #endif
  872. // kate: space-indent on; indent-width 2; replace-tabs on;