KTextEditor
document.cpp
Go to the documentation of this file.
00001 /* This file is part of the KDE project 00002 * 00003 * Copyright (C) 2010 Bernhard Beschow <bbeschow@cs.tu-berlin.de> 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Library General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 2 of the License, or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Library General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Library General Public License 00016 * along with this library; see the file COPYING.LIB. If not, write to 00017 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00018 * Boston, MA 02110-1301, USA. 00019 */ 00020 00021 #include "document.h" 00022 #include "document.moc" 00023 00024 #include "documentadaptor_p.h" 00025 #include "documentadaptor_p.moc" 00026 00027 using namespace KTextEditor; 00028 00029 00030 DocumentAdaptor::DocumentAdaptor(Document *document): 00031 QDBusAbstractAdaptor(document),m_document(document) { 00032 } 00033 00034 DocumentAdaptor::~DocumentAdaptor() {} 00035 00036 bool DocumentAdaptor::clear() { 00037 return m_document->clear(); 00038 } 00039 00040 bool DocumentAdaptor::reload() { 00041 return m_document->documentReload(); 00042 } 00043 00044 bool DocumentAdaptor::save() { 00045 return m_document->documentSave(); 00046 } 00047 00048 bool DocumentAdaptor::saveAs() { 00049 return m_document->documentSaveAs(); 00050 } 00051 00052 bool DocumentAdaptor::setTextLines(const QStringList &text) { 00053 return m_document->setText(text); 00054 } 00055 00056 bool DocumentAdaptor::isEmpty() const { 00057 return m_document->isEmpty(); 00058 } 00059 00060 bool DocumentAdaptor::setEncoding(const QString &encoding) { 00061 return m_document->setEncoding(encoding); 00062 } 00063 00064 const QString &DocumentAdaptor::encoding() const { 00065 return m_document->encoding(); 00066 } 00067 00068 bool DocumentAdaptor::setText(const QString &text) { 00069 return m_document->setText(text); 00070 } 00071 00072 QString DocumentAdaptor::text() const { 00073 return m_document->text(); 00074 } 00075 00076 int DocumentAdaptor::lines() const { 00077 return m_document->lines(); 00078 } 00079 00080 int DocumentAdaptor::totalCharacters() const { 00081 return m_document->totalCharacters(); 00082 } 00083 00084 int DocumentAdaptor::lineLength(int line) const { 00085 return m_document->lineLength(line); 00086 } 00087 00088 QPoint DocumentAdaptor::endOfLine(int line) const { 00089 Cursor c=m_document->endOfLine(line); 00090 return QPoint(c.column(),c.line()); 00091 } 00092 00093 bool DocumentAdaptor::insertText(const QPoint& cursor,const QString& text, bool block) { 00094 return m_document->insertText(Cursor(cursor.y(),cursor.x()),text,block); 00095 } 00096 00097 bool DocumentAdaptor::insertTextLines(const QPoint& cursor,const QStringList& text, bool block) { 00098 return m_document->insertText(Cursor(cursor.y(),cursor.x()),text,block); 00099 } 00100 00101 bool DocumentAdaptor::cursorInText(const QPoint& cursor) { 00102 return m_document->cursorInText(Cursor(cursor.y(),cursor.x())); 00103 } 00104 00105 bool DocumentAdaptor::insertLine(int line, const QString& text) { 00106 return m_document->insertLine(line,text); 00107 } 00108 00109 bool DocumentAdaptor::insertLines(int line, const QStringList& text) { 00110 return m_document->insertLines(line,text); 00111 } 00112 00113 bool DocumentAdaptor::removeLine(int line) { 00114 return m_document->removeLine(line); 00115 } 00116 00117 00118 class KTextEditor::DocumentPrivate { 00119 public: 00120 DocumentPrivate() 00121 : openingError(false), suppressOpeningErrorDialogs(false) { } 00122 bool openingError; 00123 bool suppressOpeningErrorDialogs; 00124 QString openingErrorMessage; 00125 }; 00126 00127 Document::Document( QObject *parent) 00128 : KParts::ReadWritePart(parent) 00129 , d(new DocumentPrivate()) 00130 { 00131 qRegisterMetaType<KTextEditor::Document*>("KTextEditor::Document*"); 00132 new DocumentAdaptor(this); 00133 } 00134 00135 Document::~Document() 00136 { 00137 delete d; 00138 } 00139 00140 void Document::setSuppressOpeningErrorDialogs(bool suppress) { 00141 d->suppressOpeningErrorDialogs=suppress; 00142 } 00143 00144 bool Document::suppressOpeningErrorDialogs() const { 00145 return d->suppressOpeningErrorDialogs; 00146 } 00147 00148 bool Document::openingError() const { 00149 return d->openingError; 00150 } 00151 00152 QString Document::openingErrorMessage() const { 00153 return d->openingErrorMessage; 00154 } 00155 00156 void Document::setOpeningError(bool errors) { 00157 d->openingError=errors; 00158 } 00159 00160 void Document::setOpeningErrorMessage(const QString& message) { 00161 d->openingErrorMessage=message; 00162 } 00163 00164 bool Document::cursorInText(const Cursor& cursor) 00165 { 00166 if ( (cursor.line()<0) || (cursor.line()>=lines())) return false; 00167 return (cursor.column()>=0) && (cursor.column()<=lineLength(cursor.line())); // = because new line isn't usually contained in line length 00168 } 00169 00170 bool KTextEditor::Document::replaceText( const Range & range, const QString & text, bool block ) 00171 { 00172 bool success = true; 00173 startEditing(); 00174 success &= removeText(range, block); 00175 success &= insertText(range.start(), text, block); 00176 endEditing(); 00177 return success; 00178 } 00179 00180 bool Document::replaceText( const Range & range, const QStringList & text, bool block ) 00181 { 00182 bool success = true; 00183 startEditing(); 00184 success &= removeText(range, block); 00185 success &= insertText(range.start(), text, block); 00186 endEditing(); 00187 return success; 00188 } 00189 00190 bool Document::isEmpty( ) const 00191 { 00192 return documentEnd() == Cursor::start(); 00193 } 00194 00195 // kate: space-indent on; indent-width 2; replace-tabs on;
KDE 4.6 API Reference