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 <QtDBus/QtDBus> 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 00035 #include "view.h" 00036 #include "view.moc" 00037 00038 #include "plugin.h" 00039 #include "plugin.moc" 00040 00041 #include "recoveryinterface.h" 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 "annotationinterface.h" 00053 #include "annotationinterface.moc" 00054 00055 #include "loadsavefiltercheckplugin.h" 00056 #include "loadsavefiltercheckplugin.moc" 00057 00058 #include "modeinterface.h" 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 QString defaultEncoding; 00083 }; 00084 00085 Editor::Editor( QObject *parent ) 00086 : QObject ( parent ) 00087 , d(new KTextEditor::EditorPrivate()) 00088 { 00089 } 00090 00091 Editor::~Editor() 00092 { 00093 delete d; 00094 } 00095 00096 void Editor::setSimpleMode (bool on) 00097 { 00098 d->simpleMode = on; 00099 } 00100 00101 bool Editor::simpleMode () const 00102 { 00103 return d->simpleMode; 00104 } 00105 00106 const QString &Editor::defaultEncoding () const 00107 { 00108 return d->defaultEncoding; 00109 } 00110 00111 void Editor::setDefaultEncoding (const QString &defaultEncoding) 00112 { 00113 d->defaultEncoding = defaultEncoding; 00114 } 00115 00116 bool View::isActiveView() const 00117 { 00118 return this == document()->activeView(); 00119 } 00120 00121 bool View::setSelection(const Cursor& position, int length,bool wrap) 00122 { 00123 KTextEditor::Document *doc=document(); 00124 if (!document()) return false; 00125 if (length==0) return false; 00126 if (!doc->cursorInText(position)) return false; 00127 Cursor end=Cursor(position.line(),position.column()); 00128 if (!wrap) { 00129 int col=end.column()+length; 00130 if (col<0) col=0; 00131 if (col>doc->lineLength(end.line())) col=doc->lineLength(end.line()); 00132 end.setColumn(col); 00133 } else { 00134 kDebug()<<"KTextEditor::View::setSelection(pos,len,true) not implemented yet"; 00135 } 00136 return setSelection(Range(position,end)); 00137 } 00138 00139 bool View::insertText (const QString &text ) 00140 { 00141 KTextEditor::Document *doc=document(); 00142 if (!doc) return false; 00143 return doc->insertText(cursorPosition(),text,blockSelection()); 00144 } 00145 00146 #ifndef KDE_NO_DEPRECATED 00147 Plugin *KTextEditor::createPlugin ( KService::Ptr service, QObject *parent ) 00148 { 00149 QString error; 00150 Plugin* plugin = service->createInstance<KTextEditor::Plugin>(parent, QVariantList(), &error); 00151 if (!plugin) 00152 kWarning() << error; 00153 return plugin; 00154 } 00155 #endif 00156 00157 struct KTextEditorFactorySet : public QSet<KPluginFactory*> 00158 { 00159 KTextEditorFactorySet(); 00160 ~KTextEditorFactorySet(); 00161 }; 00162 K_GLOBAL_STATIC(KTextEditorFactorySet, s_factories) 00163 KTextEditorFactorySet::KTextEditorFactorySet() { 00164 // K_GLOBAL_STATIC is cleaned up *after* Q(Core)Application is gone 00165 // but we have to cleanup before -> use qAddPostRoutine 00166 qAddPostRoutine(s_factories.destroy); 00167 } 00168 KTextEditorFactorySet::~KTextEditorFactorySet() { 00169 qRemovePostRoutine(s_factories.destroy); // post routine is installed! 00170 qDeleteAll(*this); 00171 } 00172 00173 Editor *KTextEditor::editor(const char *libname) 00174 { 00175 KPluginFactory *fact=KPluginLoader(libname).factory(); 00176 00177 KTextEditor::Factory *ef=qobject_cast<KTextEditor::Factory*>(fact); 00178 00179 if (!ef) { 00180 delete fact; 00181 return 0; 00182 } 00183 00184 s_factories->insert(fact); 00185 00186 return ef->editor(); 00187 } 00188 00189 ConfigPage::ConfigPage ( QWidget *parent ) 00190 : QWidget (parent) 00191 , d(0) 00192 {} 00193 00194 ConfigPage::~ConfigPage () 00195 {} 00196 00197 View::View ( QWidget *parent ) 00198 : QWidget(parent), KXMLGUIClient() 00199 , d(0) 00200 {} 00201 00202 View::~View () 00203 {} 00204 00205 Plugin::Plugin ( QObject *parent ) 00206 : QObject (parent) 00207 , d(0) 00208 {} 00209 00210 Plugin::~Plugin () 00211 {} 00212 00213 MarkInterface::MarkInterface () 00214 : d(0) 00215 {} 00216 00217 MarkInterface::~MarkInterface () 00218 {} 00219 00220 ModificationInterface::ModificationInterface () 00221 : d(0) 00222 {} 00223 00224 ModificationInterface::~ModificationInterface () 00225 {} 00226 00227 ContainerInterface::ContainerInterface () 00228 {} 00229 00230 ContainerInterface::~ContainerInterface () 00231 {} 00232 00233 MdiContainer::MdiContainer () 00234 {} 00235 00236 MdiContainer::~MdiContainer () 00237 {} 00238 00239 ViewBarContainer::ViewBarContainer() 00240 {} 00241 00242 ViewBarContainer::~ViewBarContainer() 00243 {} 00244 00245 00246 SearchInterface::SearchInterface() 00247 : d(0) 00248 {} 00249 00250 SearchInterface::~SearchInterface() 00251 {} 00252 00253 SessionConfigInterface::SessionConfigInterface() 00254 : d(0) 00255 {} 00256 00257 SessionConfigInterface::~SessionConfigInterface() 00258 {} 00259 00260 ParameterizedSessionConfigInterface::ParameterizedSessionConfigInterface() 00261 {} 00262 00263 ParameterizedSessionConfigInterface::~ParameterizedSessionConfigInterface() 00264 {} 00265 00266 TemplateInterface::TemplateInterface() 00267 : d(0) 00268 {} 00269 00270 TemplateInterface::~TemplateInterface() 00271 {} 00272 00273 TextHintInterface::TextHintInterface() 00274 : d(0) 00275 {} 00276 00277 TextHintInterface::~TextHintInterface() 00278 {} 00279 00280 VariableInterface::VariableInterface() 00281 : d(0) 00282 {} 00283 00284 VariableInterface::~VariableInterface() 00285 {} 00286 00287 class KTextEditor::LoadSaveFilterCheckPluginPrivate { 00288 public: 00289 LoadSaveFilterCheckPluginPrivate(){} 00290 ~LoadSaveFilterCheckPluginPrivate(){} 00291 }; 00292 00293 LoadSaveFilterCheckPlugin::LoadSaveFilterCheckPlugin(QObject *parent): 00294 QObject(parent), 00295 d(new LoadSaveFilterCheckPluginPrivate()) { } 00296 00297 LoadSaveFilterCheckPlugin::~LoadSaveFilterCheckPlugin() { delete d; } 00298 00299 CoordinatesToCursorInterface::~CoordinatesToCursorInterface() { 00300 } 00301 00302 00303 00304 ModeInterface::ModeInterface() { 00305 } 00306 00307 ModeInterface::~ModeInterface() { 00308 } 00309 00310 RecoveryInterface::RecoveryInterface() 00311 : d(0) { 00312 } 00313 00314 RecoveryInterface::~RecoveryInterface() { 00315 } 00316 00317 00318 // kate: space-indent on; indent-width 2; replace-tabs on; 00319
KDE 4.6 API Reference