• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KTextEditor

ktexteditor.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE project
00002    Copyright (C) 2001 Christoph Cullmann (cullmann@kde.org)
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017    Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include <config.h>
00021 
00022 #include "cursor.h"
00023 
00024 #include "configpage.h"
00025 #include "configpage.moc"
00026 
00027 #include "factory.h"
00028 #include "factory.moc"
00029 
00030 #include "editor.h"
00031 #include "editor.moc"
00032 
00033 #include "document.h"
00034 #include "document.moc"
00035 
00036 #include "view.h"
00037 #include "view.moc"
00038 
00039 #include "plugin.h"
00040 #include "plugin.moc"
00041 
00042 #include "commandinterface.h"
00043 #include "markinterface.h"
00044 #include "modificationinterface.h"
00045 #include "searchinterface.h"
00046 #include "sessionconfiginterface.h"
00047 #include "templateinterface.h"
00048 #include "texthintinterface.h"
00049 #include "variableinterface.h"
00050 #include "containerinterface.h"
00051 
00052 #include "documentadaptor_p.h"
00053 #include "documentadaptor_p.moc"
00054 
00055 #include "annotationinterface.h"
00056 #include "annotationinterface.moc"
00057 
00058 //#include <kaction.h>
00059 #include <kparts/factory.h>
00060 #include <kpluginfactory.h>
00061 #include <kpluginloader.h>
00062 #include <kdebug.h>
00063 
00064 using namespace KTextEditor;
00065 
00066 Factory::Factory( QObject *parent )
00067  : KParts::Factory( parent )
00068  , d(0)
00069 {
00070 }
00071 
00072 Factory::~Factory()
00073 {
00074 }
00075 
00076 class KTextEditor::EditorPrivate {
00077   public:
00078     EditorPrivate()
00079       : simpleMode (false) { }
00080     bool simpleMode;
00081 };
00082 
00083 Editor::Editor( QObject *parent )
00084  : QObject ( parent )
00085  , d(new KTextEditor::EditorPrivate())
00086 {
00087 }
00088 
00089 Editor::~Editor()
00090 {
00091   delete d;
00092 }
00093 
00094 void Editor::setSimpleMode (bool on)
00095 {
00096   d->simpleMode = on;
00097 }
00098 
00099 bool Editor::simpleMode () const
00100 {
00101   return d->simpleMode;
00102 }
00103 
00104 
00105 class KTextEditor::DocumentPrivate {
00106   public:
00107     DocumentPrivate()
00108       : openingError(false), suppressOpeningErrorDialogs(false) { }
00109     bool openingError;
00110     bool suppressOpeningErrorDialogs;
00111     QString openingErrorMessage;
00112 };
00113 
00114 Document::Document( QObject *parent)
00115  : KParts::ReadWritePart(parent)
00116  , d(new DocumentPrivate())
00117 {
00118         qRegisterMetaType<KTextEditor::Document*>("KTextEditor::Document*");
00119     new DocumentAdaptor(this);
00120 }
00121 
00122 Document::~Document()
00123 {
00124   delete d;
00125 }
00126 
00127 void Document::setSuppressOpeningErrorDialogs(bool suppress) {
00128   d->suppressOpeningErrorDialogs=suppress;
00129 }
00130 
00131 bool Document::suppressOpeningErrorDialogs() const {
00132   return d->suppressOpeningErrorDialogs;
00133 }
00134 
00135 bool Document::openingError() const {
00136   return d->openingError;
00137 }
00138 
00139 QString Document::openingErrorMessage() const {
00140   return d->openingErrorMessage;
00141 }
00142 
00143 void Document::setOpeningError(bool errors) {
00144   d->openingError=errors;
00145 }
00146 
00147 void Document::setOpeningErrorMessage(const QString& message) {
00148   d->openingErrorMessage=message;
00149 }
00150 
00151 bool Document::cursorInText(const Cursor& cursor)
00152 {
00153   if ( (cursor.line()<0) || (cursor.line()>=lines())) return false;
00154   return (cursor.column()>=0) && (cursor.column()<=lineLength(cursor.line())); // = because new line isn't usually contained in line length
00155 }
00156 
00157 bool KTextEditor::Document::replaceText( const Range & range, const QString & text, bool block )
00158 {
00159   bool success = true;
00160   startEditing();
00161   success &= removeText(range, block);
00162   success &= insertText(range.start(), text, block);
00163   endEditing();
00164   return success;
00165 }
00166 
00167 bool Document::replaceText( const Range & range, const QStringList & text, bool block )
00168 {
00169   bool success = true;
00170   startEditing();
00171   success &= removeText(range, block);
00172   success &= insertText(range.start(), text, block);
00173   endEditing();
00174   return success;
00175 }
00176 
00177 bool View::isActiveView() const
00178 {
00179   return this == document()->activeView();
00180 }
00181 
00182 bool View::setSelection(const Cursor& position, int length,bool wrap)
00183 {
00184   KTextEditor::Document *doc=document();
00185   if (!document()) return false;
00186   if (length==0) return false;
00187   if (!doc->cursorInText(position)) return false;
00188   Cursor end=Cursor(position.line(),position.column());
00189   if (!wrap) {
00190     int col=end.column()+length;
00191     if (col<0) col=0;
00192     if (col>doc->lineLength(end.line())) col=doc->lineLength(end.line());
00193     end.setColumn(col);
00194   } else {
00195     kDebug()<<"KTextEditor::View::setSelection(pos,len,true) not implemented yet";
00196   }
00197   return setSelection(Range(position,end));
00198 }
00199 
00200 bool View::insertText (const QString &text )
00201 {
00202   KTextEditor::Document *doc=document();
00203   if (!doc) return false;
00204   return doc->insertText(cursorPosition(),text);
00205 }
00206 
00207 Plugin *KTextEditor::createPlugin ( KService::Ptr service, QObject *parent )
00208 {
00209   return KService::createInstance<KTextEditor::Plugin>(service, parent);
00210 }
00211 
00212 struct KTextEditorFactorySet : public QSet<KPluginFactory*>
00213 {
00214   KTextEditorFactorySet();
00215   ~KTextEditorFactorySet();
00216 };
00217 K_GLOBAL_STATIC(KTextEditorFactorySet, s_factories)
00218 KTextEditorFactorySet::KTextEditorFactorySet() {
00219   // K_GLOBAL_STATIC is cleaned up *after* Q(Core)Application is gone
00220   // but we have to cleanup before -> use qAddPostRoutine
00221   qAddPostRoutine(s_factories.destroy);
00222 }
00223 KTextEditorFactorySet::~KTextEditorFactorySet() {
00224   qRemovePostRoutine(s_factories.destroy); // post routine is installed!
00225   qDeleteAll(*this);
00226 }
00227 
00228 Editor *KTextEditor::editor(const char *libname)
00229 {
00230   KPluginFactory *fact=KPluginLoader(libname).factory();
00231 
00232   KTextEditor::Factory *ef=qobject_cast<KTextEditor::Factory*>(fact);
00233 
00234   if (!ef) {
00235     delete fact;
00236     return 0;
00237   }
00238 
00239   s_factories->insert(fact);
00240 
00241   return ef->editor();
00242 }
00243 
00244 bool Document::isEmpty( ) const
00245 {
00246   return documentEnd() == Cursor::start();
00247 }
00248 
00249 ConfigPage::ConfigPage ( QWidget *parent )
00250   : QWidget (parent)
00251   , d(0)
00252 {}
00253 
00254 ConfigPage::~ConfigPage ()
00255 {}
00256 
00257 View::View ( QWidget *parent )
00258   : QWidget(parent), KXMLGUIClient()
00259   , d(0)
00260 {}
00261 
00262 View::~View ()
00263 {}
00264 
00265 Plugin::Plugin ( QObject *parent )
00266   : QObject (parent)
00267   , d(0)
00268 {}
00269 
00270 Plugin::~Plugin ()
00271 {}
00272 
00273 MarkInterface::MarkInterface ()
00274   : d(0)
00275 {}
00276 
00277 MarkInterface::~MarkInterface ()
00278 {}
00279 
00280 ModificationInterface::ModificationInterface ()
00281   : d(0)
00282 {}
00283 
00284 ModificationInterface::~ModificationInterface ()
00285 {}
00286 
00287 ContainerInterface::ContainerInterface ()
00288 {}
00289 
00290 ContainerInterface::~ContainerInterface ()
00291 {}
00292 
00293 MdiContainer::MdiContainer ()
00294 {}
00295 
00296 MdiContainer::~MdiContainer ()
00297 {}
00298 
00299 SearchInterface::SearchInterface()
00300   : d(0)
00301 {}
00302 
00303 SearchInterface::~SearchInterface()
00304 {}
00305 
00306 SessionConfigInterface::SessionConfigInterface()
00307   : d(0)
00308 {}
00309 
00310 SessionConfigInterface::~SessionConfigInterface()
00311 {}
00312 
00313 TemplateInterface::TemplateInterface()
00314   : d(0)
00315 {}
00316 
00317 TemplateInterface::~TemplateInterface()
00318 {}
00319 
00320 TextHintInterface::TextHintInterface()
00321   : d(0)
00322 {}
00323 
00324 TextHintInterface::~TextHintInterface()
00325 {}
00326 
00327 VariableInterface::VariableInterface()
00328   : d(0)
00329 {}
00330 
00331 VariableInterface::~VariableInterface()
00332 {}
00333 
00334 DocumentAdaptor::DocumentAdaptor(Document *document):
00335   QDBusAbstractAdaptor(document),m_document(document) {
00336 }
00337 
00338 DocumentAdaptor::~DocumentAdaptor() {}
00339 
00340 bool DocumentAdaptor::clear() {
00341   return m_document->clear();
00342 }
00343 
00344 bool DocumentAdaptor::reload() {
00345   return m_document->documentReload();
00346 }
00347 
00348 bool DocumentAdaptor::save() {
00349   return m_document->documentSave();
00350 }
00351 
00352 bool DocumentAdaptor::saveAs() {
00353   return m_document->documentSaveAs();
00354 }
00355 
00356 bool DocumentAdaptor::setTextLines(const QStringList &text) {
00357   return m_document->setText(text);
00358 }
00359 
00360 bool DocumentAdaptor::isEmpty() const {
00361   return m_document->isEmpty();
00362 }
00363 
00364 bool DocumentAdaptor::setEncoding(const QString &encoding) {
00365   return m_document->setEncoding(encoding);
00366 }
00367 
00368 const QString &DocumentAdaptor::encoding() const {
00369   return m_document->encoding();
00370 }
00371 
00372 bool DocumentAdaptor::setText(const QString &text) {
00373   return m_document->setText(text);
00374 }
00375 
00376 QString DocumentAdaptor::text() const {
00377   return m_document->text();
00378 }
00379 
00380 int DocumentAdaptor::lines() const {
00381   return m_document->lines();
00382 }
00383 
00384 int DocumentAdaptor::totalCharacters() const {
00385   return m_document->totalCharacters();
00386 }
00387 
00388 int DocumentAdaptor::lineLength(int line) const {
00389   return m_document->lineLength(line);
00390 }
00391 
00392 QPoint DocumentAdaptor::endOfLine(int line) const {
00393   Cursor c=m_document->endOfLine(line);
00394   return QPoint(c.column(),c.line());
00395 }
00396 
00397 bool DocumentAdaptor::insertText(const QPoint& cursor,const QString& text, bool block) {
00398   return m_document->insertText(Cursor(cursor.y(),cursor.x()),text,block);
00399 }
00400 
00401 bool DocumentAdaptor::insertTextLines(const QPoint& cursor,const QStringList& text, bool block) {
00402   return m_document->insertText(Cursor(cursor.y(),cursor.x()),text,block);
00403 }
00404 
00405 bool DocumentAdaptor::cursorInText(const QPoint& cursor) {
00406   return m_document->cursorInText(Cursor(cursor.y(),cursor.x()));
00407 }
00408 
00409 bool DocumentAdaptor::insertLine(int line, const QString& text) {
00410   return m_document->insertLine(line,text);
00411 }
00412 
00413 bool DocumentAdaptor::insertLines(int line, const QStringList& text) {
00414   return m_document->insertLines(line,text);
00415 }
00416 
00417 bool DocumentAdaptor::removeLine(int line) {
00418   return m_document->removeLine(line);
00419 }
00420 
00421 // kate: space-indent on; indent-width 2; replace-tabs on;
00422 

KTextEditor

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal