• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KTextEditor

  • interfaces
  • ktexteditor
document.h
Go to the documentation of this file.
1/* This file is part of the KDE libraries
2 Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org>
3 Copyright (C) 2005 Dominik Haumann (dhdev@gmx.de) (documentation)
4
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 as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21#ifndef KDELIBS_KTEXTEDITOR_DOCUMENT_H
22#define KDELIBS_KTEXTEDITOR_DOCUMENT_H
23
24#include <ktexteditor/ktexteditor_export.h>
25// the very important KTextEditor::Cursor class
26#include <ktexteditor/cursor.h>
27#include <ktexteditor/range.h>
28
29// our main baseclass of the KTextEditor::Document
30#include <kparts/part.h>
31
32// the list of views
33#include <QtCore/QList>
34#include <QtCore/QMetaType>
35
36namespace KTextEditor
37{
38
39class Editor;
40class View;
41
111class KTEXTEDITOR_EXPORT Document : public KParts::ReadWritePart
112{
113 Q_OBJECT
114
115 public:
123 Document ( QObject *parent = 0);
124
128 virtual ~Document ();
129
130 /*
131 * Methods to create and manage the views of this document and access the
132 * global editor object.
133 */
134 public:
142 virtual Editor *editor () = 0;
143
149 virtual View *createView ( QWidget *parent ) = 0;
150
154 virtual View* activeView() const = 0;
155
159 virtual const QList<View*> &views() const = 0;
160
161 Q_SIGNALS:
172 void viewCreated (KTextEditor::Document *document, KTextEditor::View *view);
173
174 /*
175 * General information about this document and its content.
176 */
177 public:
185 virtual const QString &documentName () const = 0;
186
191 virtual QString mimeType() = 0;
192
193 /*
194 * SIGNALS
195 * following signals should be emitted by the editor document.
196 */
197 Q_SIGNALS:
203 void documentNameChanged ( KTextEditor::Document *document );
204
210 void documentUrlChanged ( KTextEditor::Document *document );
211
220 void modifiedChanged ( KTextEditor::Document *document );
221
225//warning ADD IN KDE5
226// void readWriteChanged (KTextEditor::Document *document);
227
228 /*
229 * VERY IMPORTANT: Methods to set and query the current encoding of the
230 * document
231 */
232 public:
246 virtual bool setEncoding (const QString &encoding) = 0;
247
255 virtual const QString &encoding () const = 0;
256
257 /*
258 * General file related actions.
259 * All this actions cause user interaction in some cases.
260 */
261 public:
269 virtual bool documentReload () = 0;
270
277 virtual bool documentSave () = 0;
278
285 virtual bool documentSaveAs () = 0;
286
287 Q_SIGNALS:
292 void documentSavedOrUploaded(KTextEditor::Document* document,bool saveAs);
293
294 /*
295 * Methodes to create/end editing sequences.
296 */
297 public:
320 virtual bool startEditing () = 0;
321
328 virtual bool endEditing () = 0;
329
330 /*
331 * General access to the document's text content.
332 */
333 public:
339 virtual QString text () const = 0;
340
349 virtual QString text ( const Range& range, bool block = false ) const = 0;
350
357 virtual QChar character( const Cursor& position ) const = 0;
358
368 virtual QStringList textLines ( const Range& range, bool block = false ) const = 0;
369
376 virtual QString line ( int line ) const = 0;
377
383 virtual int lines () const = 0;
384
390 virtual Cursor documentEnd() const = 0;
391
396 inline Range documentRange() const { return Range(Cursor::start(), documentEnd()); }
397
404 virtual int totalCharacters() const = 0;
405
409 virtual bool isEmpty() const;
410
418 virtual int lineLength ( int line ) const = 0;
419
425 inline Cursor endOfLine(int line) const { return Cursor(line, lineLength(line)); }
426
433 virtual bool setText ( const QString &text ) = 0;
434
441 virtual bool setText ( const QStringList &text ) = 0;
442
448 virtual bool clear () = 0;
449
458 virtual bool insertText ( const Cursor &position, const QString &text, bool block = false ) = 0;
459
468 virtual bool insertText ( const Cursor &position, const QStringList &text, bool block = false ) = 0;
469
478 virtual bool replaceText ( const Range &range, const QString &text, bool block = false );
479
488 virtual bool replaceText ( const Range &range, const QStringList &text, bool block = false );
489
497 virtual bool removeText ( const Range &range, bool block = false ) = 0;
498
506 virtual bool cursorInText(const Cursor &cursor);
507
520 virtual bool insertLine ( int line, const QString &text ) = 0;
521
534 virtual bool insertLines ( int line, const QStringList &text ) = 0;
535
542 virtual bool removeLine ( int line ) = 0;
543
544 /*
545 * SIGNALS
546 * Following signals should be emitted by the document if the text content
547 * is changed.
548 */
549 Q_SIGNALS:
555 void textChanged(KTextEditor::Document *document);
556
565 void textInserted(KTextEditor::Document *document, const KTextEditor::Range& range);
566
574 void textRemoved(KTextEditor::Document *document, const KTextEditor::Range& range);
575
584 void textRemoved(KTextEditor::Document *document, const KTextEditor::Range& range, const QString& oldText);
585
596 void textChanged(KTextEditor::Document *document, const KTextEditor::Range& oldRange, const KTextEditor::Range& newRange);
597
609 void textChanged(KTextEditor::Document *document, const KTextEditor::Range& oldRange, const QString& oldText, const KTextEditor::Range& newRange);
610
620 void aboutToClose(KTextEditor::Document *document);
621
631 void aboutToReload(KTextEditor::Document *document);
632
642 void reloaded(KTextEditor::Document *document);
643
653 void exclusiveEditStart(KTextEditor::Document *document);
654
661 void exclusiveEditEnd(KTextEditor::Document *document);
662
663 /*
664 * Access to the mode/highlighting subsystem
665 */
666 public:
672 virtual QString mode() const = 0;
673
679 virtual QString highlightingMode() const = 0;
680
686 virtual QStringList modes() const = 0;
687
693 virtual QStringList highlightingModes() const = 0;
694
701 virtual bool setMode(const QString &name) = 0;
702
709 virtual bool setHighlightingMode(const QString &name) = 0;
710
719 virtual QString highlightingModeSection( int index ) const = 0;
720
729 virtual QString modeSection( int index ) const = 0;
730
731 /*
732 * SIGNALS
733 * Following signals should be emitted by the document if the mode
734 * of the document changes
735 */
736 Q_SIGNALS:
744 void modeChanged(KTextEditor::Document *document);
745
753 void highlightingModeChanged(KTextEditor::Document *document);
754
755 private:
756 class DocumentPrivate* const d;
757
758 public:
766 void setSuppressOpeningErrorDialogs(bool suppress);
767 bool suppressOpeningErrorDialogs() const;
772 bool openingError() const;
773 QString openingErrorMessage() const;
774
779 bool isOrphaned() const;
780 void setOrphaned(bool value);
781
782 protected:
783 void setOpeningError(bool errors);
784 void setOpeningErrorMessage(const QString& message);
785};
786
787}
788
789Q_DECLARE_METATYPE(KTextEditor::Document*)
790
791#endif
792
793// kate: space-indent on; indent-width 2; replace-tabs on;
794
KParts::ReadWritePart
KTextEditor::Cursor
An object which represents a position in a Document.
Definition: cursor.h:62
KTextEditor::Document
A KParts derived class representing a text document.
Definition: document.h:112
KTextEditor::Document::textRemoved
void textRemoved(KTextEditor::Document *document, const KTextEditor::Range &range, const QString &oldText)
The document emits this signal whenever range was removed, i.e.
KTextEditor::Document::startEditing
virtual bool startEditing()=0
Begin an editing sequence.
KTextEditor::Document::documentSaveAs
virtual bool documentSaveAs()=0
Save the current file to another location.
KTextEditor::Document::removeText
virtual bool removeText(const Range &range, bool block=false)=0
Remove the text specified in range.
KTextEditor::Document::removeLine
virtual bool removeLine(int line)=0
Remove line from the document.
KTextEditor::Document::documentNameChanged
void documentNameChanged(KTextEditor::Document *document)
This signal is emitted whenever the document name changes.
KTextEditor::Document::insertLine
virtual bool insertLine(int line, const QString &text)=0
Insert line(s) at the given line number.
KTextEditor::Document::setEncoding
virtual bool setEncoding(const QString &encoding)=0
This signal is emitted whenever the readWrite state of a document changes.
KTextEditor::Document::reloaded
void reloaded(KTextEditor::Document *document)
Emitted after the current document was reloaded.
KTextEditor::Document::textChanged
void textChanged(KTextEditor::Document *document)
The document emits this signal whenever its text changes.
KTextEditor::Document::line
virtual QString line(int line) const =0
Get a single text line.
KTextEditor::Document::setText
virtual bool setText(const QString &text)=0
Set the given text as new document content.
KTextEditor::Document::viewCreated
void viewCreated(KTextEditor::Document *document, KTextEditor::View *view)
This signal is emitted whenever the document creates a new view.
KTextEditor::Document::setText
virtual bool setText(const QStringList &text)=0
Set the given text as new document content.
KTextEditor::Document::setHighlightingMode
virtual bool setHighlightingMode(const QString &name)=0
Set the current mode of the document by giving its name.
KTextEditor::Document::insertLines
virtual bool insertLines(int line, const QStringList &text)=0
Insert line(s) at the given line number.
KTextEditor::Document::activeView
virtual View * activeView() const =0
Return the view which currently has user focus, if any.
KTextEditor::Document::modeSection
virtual QString modeSection(int index) const =0
Returns the name of the section for a mode given its index in the highlight list (as returned by mode...
KTextEditor::Document::documentRange
Range documentRange() const
A Range which encompasses the whole document.
Definition: document.h:396
KTextEditor::Document::createView
virtual View * createView(QWidget *parent)=0
Create a new view attached to parent.
KTextEditor::Document::character
virtual QChar character(const Cursor &position) const =0
Get the character at cursor.
KTextEditor::Document::clear
virtual bool clear()=0
Remove the whole content of the document.
KTextEditor::Document::text
virtual QString text() const =0
Get the document content.
KTextEditor::Document::modeChanged
void modeChanged(KTextEditor::Document *document)
Warn anyone listening that the current document's mode has changed.
KTextEditor::Document::lines
virtual int lines() const =0
Get the count of lines of the document.
KTextEditor::Document::documentReload
virtual bool documentReload()=0
Reload the current file.
KTextEditor::Document::aboutToClose
void aboutToClose(KTextEditor::Document *document)
Warn anyone listening that the current document is about to close.
KTextEditor::Document::documentName
virtual const QString & documentName() const =0
Get this document's name.
KTextEditor::Document::textChanged
void textChanged(KTextEditor::Document *document, const KTextEditor::Range &oldRange, const KTextEditor::Range &newRange)
The document emits this signal whenever the text in range oldRange was removed and replaced with the ...
KTextEditor::Document::documentSavedOrUploaded
void documentSavedOrUploaded(KTextEditor::Document *document, bool saveAs)
This signal should be emitted after a document has been saved to disk or for remote files uploaded.
KTextEditor::Document::documentSave
virtual bool documentSave()=0
Save the current file.
KTextEditor::Document::highlightingMode
virtual QString highlightingMode() const =0
Return the name of the currently used mode.
KTextEditor::Document::exclusiveEditEnd
void exclusiveEditEnd(KTextEditor::Document *document)
In conjunction with exclusiveEditStart(), signals that the document's content may be changed again wi...
KTextEditor::Document::highlightingModeChanged
void highlightingModeChanged(KTextEditor::Document *document)
Warn anyone listening that the current document's highlighting mode has changed.
KTextEditor::Document::lineLength
virtual int lineLength(int line) const =0
Get the length of a given line in characters.
KTextEditor::Document::textChanged
void textChanged(KTextEditor::Document *document, const KTextEditor::Range &oldRange, const QString &oldText, const KTextEditor::Range &newRange)
The document emits this signal whenever the text in range oldRange was removed and replaced with the ...
KTextEditor::Document::modes
virtual QStringList modes() const =0
Return a list of the names of all possible modes.
KTextEditor::Document::mimeType
virtual QString mimeType()=0
Get this document's mimetype.
KTextEditor::Document::endOfLine
Cursor endOfLine(int line) const
Get the end cursor position of line line.
Definition: document.h:425
KTextEditor::Document::editor
virtual Editor * editor()=0
Get the global editor object.
KTextEditor::Document::totalCharacters
virtual int totalCharacters() const =0
Get the count of characters in the document.
KTextEditor::Document::encoding
virtual const QString & encoding() const =0
Get the current chosen encoding.
KTextEditor::Document::textRemoved
void textRemoved(KTextEditor::Document *document, const KTextEditor::Range &range)
The document emits this signal whenever range was removed, i.e.
KTextEditor::Document::highlightingModeSection
virtual QString highlightingModeSection(int index) const =0
Returns the name of the section for a highlight given its index in the highlight list (as returned by...
KTextEditor::Document::textLines
virtual QStringList textLines(const Range &range, bool block=false) const =0
Get the document content within the given range.
KTextEditor::Document::insertText
virtual bool insertText(const Cursor &position, const QString &text, bool block=false)=0
Insert text at position.
KTextEditor::Document::exclusiveEditStart
void exclusiveEditStart(KTextEditor::Document *document)
Upon emission, the document's content may only be changed by the initiator of this signal until exclu...
KTextEditor::Document::textInserted
void textInserted(KTextEditor::Document *document, const KTextEditor::Range &range)
The document emits this signal whenever text was inserted.
KTextEditor::Document::documentEnd
virtual Cursor documentEnd() const =0
End position of the document.
KTextEditor::Document::views
virtual const QList< View * > & views() const =0
Returns the views pre-casted to KTextEditor::Views.
KTextEditor::Document::aboutToReload
void aboutToReload(KTextEditor::Document *document)
Warn anyone listening that the current document is about to reload.
KTextEditor::Document::text
virtual QString text(const Range &range, bool block=false) const =0
Get the document content within the given range.
KTextEditor::Document::modifiedChanged
void modifiedChanged(KTextEditor::Document *document)
This signal is emitted whenever the document's buffer changed from either state unmodified to modifie...
KTextEditor::Document::setMode
virtual bool setMode(const QString &name)=0
Set the current mode of the document by giving its name.
KTextEditor::Document::highlightingModes
virtual QStringList highlightingModes() const =0
Return a list of the names of all possible modes.
KTextEditor::Document::mode
virtual QString mode() const =0
Return the name of the currently used mode.
KTextEditor::Document::insertText
virtual bool insertText(const Cursor &position, const QStringList &text, bool block=false)=0
Insert text at position.
KTextEditor::Document::endEditing
virtual bool endEditing()=0
End an editing sequence.
KTextEditor::Document::documentUrlChanged
void documentUrlChanged(KTextEditor::Document *document)
This signal is emitted whenever the document URL changes.
KTextEditor::Editor
Accessor interface for Editor part.
Definition: editor.h:103
KTextEditor::Range
An object representing a section of text, from one Cursor to another.
Definition: range.h:55
KTextEditor::View
A text widget with KXMLGUIClient that represents a Document.
Definition: view.h:146
QList
QObject
QWidget
cursor.h
ktexteditor_export.h
KTextEditor
Namespace for the KDE Text Editor Interfaces.
Definition: annotationinterface.h:31
part.h
range.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KTextEditor

Skip menu "KTextEditor"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal