• Skip to content
  • Skip to link menu
KDE 4.3 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 "loadsavefiltercheckplugin.h"
00059 #include "loadsavefiltercheckplugin.moc"
00060 
00061 //#include <kaction.h>
00062 #include <kparts/factory.h>
00063 #include <kpluginfactory.h>
00064 #include <kpluginloader.h>
00065 #include <kdebug.h>
00066 
00067 using namespace KTextEditor;
00068 
00069 Factory::Factory( QObject *parent )
00070  : KParts::Factory( parent )
00071  , d(0)
00072 {
00073 }
00074 
00075 Factory::~Factory()
00076 {
00077 }
00078 
00079 class KTextEditor::EditorPrivate {
00080   public:
00081     EditorPrivate()
00082       : simpleMode (false) { }
00083     bool simpleMode;
00084 };
00085 
00086 Editor::Editor( QObject *parent )
00087  : QObject ( parent )
00088  , d(new KTextEditor::EditorPrivate())
00089 {
00090 }
00091 
00092 Editor::~Editor()
00093 {
00094   delete d;
00095 }
00096 
00097 void Editor::setSimpleMode (bool on)
00098 {
00099   d->simpleMode = on;
00100 }
00101 
00102 bool Editor::simpleMode () const
00103 {
00104   return d->simpleMode;
00105 }
00106 
00107 
00108 class KTextEditor::DocumentPrivate {
00109   public:
00110     DocumentPrivate()
00111       : openingError(false), suppressOpeningErrorDialogs(false) { }
00112     bool openingError;
00113     bool suppressOpeningErrorDialogs;
00114     QString openingErrorMessage;
00115 };
00116 
00117 Document::Document( QObject *parent)
00118  : KParts::ReadWritePart(parent)
00119  , d(new DocumentPrivate())
00120 {
00121         qRegisterMetaType<KTextEditor::Document*>("KTextEditor::Document*");
00122     new DocumentAdaptor(this);
00123 }
00124 
00125 Document::~Document()
00126 {
00127   delete d;
00128 }
00129 
00130 void Document::setSuppressOpeningErrorDialogs(bool suppress) {
00131   d->suppressOpeningErrorDialogs=suppress;
00132 }
00133 
00134 bool Document::suppressOpeningErrorDialogs() const {
00135   return d->suppressOpeningErrorDialogs;
00136 }
00137 
00138 bool Document::openingError() const {
00139   return d->openingError;
00140 }
00141 
00142 QString Document::openingErrorMessage() const {
00143   return d->openingErrorMessage;
00144 }
00145 
00146 void Document::setOpeningError(bool errors) {
00147   d->openingError=errors;
00148 }
00149 
00150 void Document::setOpeningErrorMessage(const QString& message) {
00151   d->openingErrorMessage=message;
00152 }
00153 
00154 bool Document::cursorInText(const Cursor& cursor)
00155 {
00156   if ( (cursor.line()<0) || (cursor.line()>=lines())) return false;
00157   return (cursor.column()>=0) && (cursor.column()<=lineLength(cursor.line())); // = because new line isn't usually contained in line length
00158 }
00159 
00160 bool KTextEditor::Document::replaceText( const Range & range, const QString & text, bool block )
00161 {
00162   bool success = true;
00163   startEditing();
00164   success &= removeText(range, block);
00165   success &= insertText(range.start(), text, block);
00166   endEditing();
00167   return success;
00168 }
00169 
00170 bool Document::replaceText( const Range & range, const QStringList & 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 View::isActiveView() const
00181 {
00182   return this == document()->activeView();
00183 }
00184 
00185 bool View::setSelection(const Cursor& position, int length,bool wrap)
00186 {
00187   KTextEditor::Document *doc=document();
00188   if (!document()) return false;
00189   if (length==0) return false;
00190   if (!doc->cursorInText(position)) return false;
00191   Cursor end=Cursor(position.line(),position.column());
00192   if (!wrap) {
00193     int col=end.column()+length;
00194     if (col<0) col=0;
00195     if (col>doc->lineLength(end.line())) col=doc->lineLength(end.line());
00196     end.setColumn(col);
00197   } else {
00198     kDebug()<<"KTextEditor::View::setSelection(pos,len,true) not implemented yet";
00199   }
00200   return setSelection(Range(position,end));
00201 }
00202 
00203 bool View::insertText (const QString &text )
00204 {
00205   KTextEditor::Document *doc=document();
00206   if (!doc) return false;
00207   return doc->insertText(cursorPosition(),text,blockSelection());
00208 }
00209 
00210 Plugin *KTextEditor::createPlugin ( KService::Ptr service, QObject *parent )
00211 {
00212   return service->createInstance<KTextEditor::Plugin>(parent);
00213 }
00214 
00215 struct KTextEditorFactorySet : public QSet<KPluginFactory*>
00216 {
00217   KTextEditorFactorySet();
00218   ~KTextEditorFactorySet();
00219 };
00220 K_GLOBAL_STATIC(KTextEditorFactorySet, s_factories)
00221 KTextEditorFactorySet::KTextEditorFactorySet() {
00222   // K_GLOBAL_STATIC is cleaned up *after* Q(Core)Application is gone
00223   // but we have to cleanup before -> use qAddPostRoutine
00224   qAddPostRoutine(s_factories.destroy);
00225 }
00226 KTextEditorFactorySet::~KTextEditorFactorySet() {
00227   qRemovePostRoutine(s_factories.destroy); // post routine is installed!
00228   qDeleteAll(*this);
00229 }
00230 
00231 Editor *KTextEditor::editor(const char *libname)
00232 {
00233   KPluginFactory *fact=KPluginLoader(libname).factory();
00234 
00235   KTextEditor::Factory *ef=qobject_cast<KTextEditor::Factory*>(fact);
00236 
00237   if (!ef) {
00238     delete fact;
00239     return 0;
00240   }
00241 
00242   s_factories->insert(fact);
00243 
00244   return ef->editor();
00245 }
00246 
00247 bool Document::isEmpty( ) const
00248 {
00249   return documentEnd() == Cursor::start();
00250 }
00251 
00252 ConfigPage::ConfigPage ( QWidget *parent )
00253   : QWidget (parent)
00254   , d(0)
00255 {}
00256 
00257 ConfigPage::~ConfigPage ()
00258 {}
00259 
00260 View::View ( QWidget *parent )
00261   : QWidget(parent), KXMLGUIClient()
00262   , d(0)
00263 {}
00264 
00265 View::~View ()
00266 {}
00267 
00268 Plugin::Plugin ( QObject *parent )
00269   : QObject (parent)
00270   , d(0)
00271 {}
00272 
00273 Plugin::~Plugin ()
00274 {}
00275 
00276 MarkInterface::MarkInterface ()
00277   : d(0)
00278 {}
00279 
00280 MarkInterface::~MarkInterface ()
00281 {}
00282 
00283 ModificationInterface::ModificationInterface ()
00284   : d(0)
00285 {}
00286 
00287 ModificationInterface::~ModificationInterface ()
00288 {}
00289 
00290 ContainerInterface::ContainerInterface ()
00291 {}
00292 
00293 ContainerInterface::~ContainerInterface ()
00294 {}
00295 
00296 MdiContainer::MdiContainer ()
00297 {}
00298 
00299 MdiContainer::~MdiContainer ()
00300 {}
00301 
00302 ViewBarContainer::ViewBarContainer()
00303 {}
00304 
00305 ViewBarContainer::~ViewBarContainer()
00306 {}
00307 
00308 
00309 SearchInterface::SearchInterface()
00310   : d(0)
00311 {}
00312 
00313 SearchInterface::~SearchInterface()
00314 {}
00315 
00316 SessionConfigInterface::SessionConfigInterface()
00317   : d(0)
00318 {}
00319 
00320 SessionConfigInterface::~SessionConfigInterface()
00321 {}
00322 
00323 TemplateInterface::TemplateInterface()
00324   : d(0)
00325 {}
00326 
00327 TemplateInterface::~TemplateInterface()
00328 {}
00329 
00330 TextHintInterface::TextHintInterface()
00331   : d(0)
00332 {}
00333 
00334 TextHintInterface::~TextHintInterface()
00335 {}
00336 
00337 VariableInterface::VariableInterface()
00338   : d(0)
00339 {}
00340 
00341 VariableInterface::~VariableInterface()
00342 {}
00343 
00344 DocumentAdaptor::DocumentAdaptor(Document *document):
00345   QDBusAbstractAdaptor(document),m_document(document) {
00346 }
00347 
00348 DocumentAdaptor::~DocumentAdaptor() {}
00349 
00350 bool DocumentAdaptor::clear() {
00351   return m_document->clear();
00352 }
00353 
00354 bool DocumentAdaptor::reload() {
00355   return m_document->documentReload();
00356 }
00357 
00358 bool DocumentAdaptor::save() {
00359   return m_document->documentSave();
00360 }
00361 
00362 bool DocumentAdaptor::saveAs() {
00363   return m_document->documentSaveAs();
00364 }
00365 
00366 bool DocumentAdaptor::setTextLines(const QStringList &text) {
00367   return m_document->setText(text);
00368 }
00369 
00370 bool DocumentAdaptor::isEmpty() const {
00371   return m_document->isEmpty();
00372 }
00373 
00374 bool DocumentAdaptor::setEncoding(const QString &encoding) {
00375   return m_document->setEncoding(encoding);
00376 }
00377 
00378 const QString &DocumentAdaptor::encoding() const {
00379   return m_document->encoding();
00380 }
00381 
00382 bool DocumentAdaptor::setText(const QString &text) {
00383   return m_document->setText(text);
00384 }
00385 
00386 QString DocumentAdaptor::text() const {
00387   return m_document->text();
00388 }
00389 
00390 int DocumentAdaptor::lines() const {
00391   return m_document->lines();
00392 }
00393 
00394 int DocumentAdaptor::totalCharacters() const {
00395   return m_document->totalCharacters();
00396 }
00397 
00398 int DocumentAdaptor::lineLength(int line) const {
00399   return m_document->lineLength(line);
00400 }
00401 
00402 QPoint DocumentAdaptor::endOfLine(int line) const {
00403   Cursor c=m_document->endOfLine(line);
00404   return QPoint(c.column(),c.line());
00405 }
00406 
00407 bool DocumentAdaptor::insertText(const QPoint& cursor,const QString& text, bool block) {
00408   return m_document->insertText(Cursor(cursor.y(),cursor.x()),text,block);
00409 }
00410 
00411 bool DocumentAdaptor::insertTextLines(const QPoint& cursor,const QStringList& text, bool block) {
00412   return m_document->insertText(Cursor(cursor.y(),cursor.x()),text,block);
00413 }
00414 
00415 bool DocumentAdaptor::cursorInText(const QPoint& cursor) {
00416   return m_document->cursorInText(Cursor(cursor.y(),cursor.x()));
00417 }
00418 
00419 bool DocumentAdaptor::insertLine(int line, const QString& text) {
00420   return m_document->insertLine(line,text);
00421 }
00422 
00423 bool DocumentAdaptor::insertLines(int line, const QStringList& text) {
00424   return m_document->insertLines(line,text);
00425 }
00426 
00427 bool DocumentAdaptor::removeLine(int line) {
00428   return m_document->removeLine(line);
00429 }
00430 
00431 class KTextEditor::LoadSaveFilterCheckPluginPrivate {
00432   public:
00433     LoadSaveFilterCheckPluginPrivate(){}
00434     ~LoadSaveFilterCheckPluginPrivate(){}
00435 };
00436 
00437 LoadSaveFilterCheckPlugin::LoadSaveFilterCheckPlugin(QObject *parent):
00438     QObject(),
00439     d(new LoadSaveFilterCheckPluginPrivate()) { }
00440 
00441 LoadSaveFilterCheckPlugin::~LoadSaveFilterCheckPlugin() { delete d; }
00442 
00443 CoordinatesToCursorInterface::~CoordinatesToCursorInterface() {
00444 }
00445 
00446 // kate: space-indent on; indent-width 2; replace-tabs on;
00447 

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
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
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