interfaces
context.cpp
00001 /* This file is part of KDevelop 00002 Copyright 2001-2002 Matthias Hoelzer-Kluepfel <hoelzer@kde.org> 00003 Copyright 2001-2002 Bernd Gehrmann <bernd@kdevelop.org> 00004 Copyright 2001 Sandy Meier <smeier@kdevelop.org> 00005 Copyright 2002 Daniel Engelschalt <daniel.engelschalt@gmx.net> 00006 Copyright 2002 Simon Hausmann <hausmann@kde.org> 00007 Copyright 2002-2003 Roberto Raggi <roberto@kdevelop.org> 00008 Copyright 2003 Mario Scalas <mario.scalas@libero.it> 00009 Copyright 2003 Harald Fernengel <harry@kdevelop.org> 00010 Copyright 2003,2006 Hamish Rodda <rodda@kde.org> 00011 Copyright 2004 Alexander Dymo <adymo@kdevelop.org> 00012 Copyright 2006 Adam Treat <treat@kde.org> 00013 00014 This library is free software; you can redistribute it and/or 00015 modify it under the terms of the GNU Library General Public 00016 License as published by the Free Software Foundation; either 00017 version 2 of the License, or (at your option) any later version. 00018 00019 This library is distributed in the hope that it will be useful, 00020 but WITHOUT ANY WARRANTY; without even the implied warranty of 00021 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00022 Library General Public License for more details. 00023 00024 You should have received a copy of the GNU Library General Public License 00025 along with this library; see the file COPYING.LIB. If not, write to 00026 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00027 Boston, MA 02110-1301, USA. 00028 */ 00029 00030 #include "context.h" 00031 00032 #include <QDir> 00033 #include <QList> 00034 00035 #include <ktexteditor/document.h> 00036 00037 namespace KDevelop 00038 { 00039 00040 Context::Context() 00041 : d(0) 00042 {} 00043 00044 Context::~Context() 00045 {} 00046 00047 bool Context::hasType( int aType ) const 00048 { 00049 return aType == this->type(); 00050 } 00051 00052 class EditorContextPrivate 00053 { 00054 public: 00055 EditorContextPrivate( KTextEditor::View* view ) 00056 : m_view( view ) 00057 { 00058 m_url = view->document()->url(); 00059 m_position = view->cursorPosition(); 00060 } 00061 00062 KUrl m_url; 00063 KTextEditor::Cursor m_position; 00064 QString m_currentLine, m_currentWord; 00065 KTextEditor::View* m_view; 00066 }; 00067 00068 EditorContext::EditorContext( KTextEditor::View* view ) 00069 : Context(), d( new EditorContextPrivate( view ) ) 00070 {} 00071 00072 EditorContext::~EditorContext() 00073 { 00074 delete d; 00075 } 00076 00077 int EditorContext::type() const 00078 { 00079 return Context::EditorContext; 00080 } 00081 00082 KUrl EditorContext::url() const 00083 { 00084 return d->m_url; 00085 } 00086 00087 KTextEditor::Cursor EditorContext::position() const 00088 { 00089 return d->m_position; 00090 } 00091 00092 QString EditorContext::currentLine() const 00093 { 00094 return d->m_currentLine; 00095 } 00096 00097 QString EditorContext::currentWord() const 00098 { 00099 return d->m_currentWord; 00100 } 00101 00102 KTextEditor::View* EditorContext::view() const 00103 { 00104 return d->m_view; 00105 } 00106 00107 class FileContextPrivate 00108 { 00109 public: 00110 FileContextPrivate( const KUrl::List &urls ) 00111 : m_urls( urls ) 00112 {} 00113 00114 KUrl::List m_urls; 00115 }; 00116 00117 FileContext::FileContext( const KUrl::List &urls ) 00118 : Context(), d( new FileContextPrivate( urls ) ) 00119 {} 00120 00121 FileContext::~FileContext() 00122 { 00123 delete d; 00124 } 00125 00126 int FileContext::type() const 00127 { 00128 return Context::FileContext; 00129 } 00130 00131 KUrl::List FileContext::urls() const 00132 { 00133 return d->m_urls; 00134 } 00135 00136 class ProjectItemContextPrivate 00137 { 00138 public: 00139 ProjectItemContextPrivate( const QList<ProjectBaseItem*> &items ) 00140 : m_items( items ) 00141 {} 00142 00143 QList<ProjectBaseItem*> m_items; 00144 }; 00145 00146 ProjectItemContext::ProjectItemContext( const QList<ProjectBaseItem*> &items ) 00147 : Context(), d( new ProjectItemContextPrivate( items ) ) 00148 {} 00149 00150 ProjectItemContext::~ProjectItemContext() 00151 { 00152 delete d; 00153 } 00154 00155 int ProjectItemContext::type() const 00156 { 00157 return Context::ProjectItemContext; 00158 } 00159 00160 QList<ProjectBaseItem*> ProjectItemContext::items() const 00161 { 00162 return d->m_items; 00163 } 00164 00165 } 00166
KDE 4.2 API Reference