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