1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
|
/*
* KDevelop Problem Reporter
*
* Copyright 2010 Dmitry Risenberg <dmitry.risenberg@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "watcheddocumentset.h"
#include <interfaces/icore.h>
#include <interfaces/idocument.h>
#include <interfaces/iprojectcontroller.h>
#include <interfaces/idocumentcontroller.h>
#include <interfaces/iproject.h>
#include <project/projectmodel.h>
#include <project/interfaces/iprojectfilemanager.h>
#include "problemreporterplugin.h"
using namespace KDevelop;
WatchedDocumentSet::WatchedDocumentSet(ProblemModel* parent)
:QObject(parent)
{
}
void WatchedDocumentSet::setCurrentDocument(const KDevelop::IndexedString&)
{
}
WatchedDocumentSet::DocumentSet WatchedDocumentSet::get() const
{
return m_documents;
}
ProblemModel* WatchedDocumentSet::model() const
{
return static_cast<ProblemModel*>(parent());
}
CurrentDocumentSet::CurrentDocumentSet(const KDevelop::IndexedString& document, ProblemModel * parent)
: WatchedDocumentSet(parent)
{
m_documents.insert(document);
}
void CurrentDocumentSet::setCurrentDocument(const KDevelop::IndexedString& url)
{
m_documents.clear();
m_documents.insert(url);
emit changed();
}
ProblemModel::Scope CurrentDocumentSet::getScope() const
{
return ProblemModel::CurrentDocument;
}
OpenDocumentSet::OpenDocumentSet(ProblemModel* parent)
: WatchedDocumentSet(parent)
{
QList<KDevelop::IDocument*> docs = model()->plugin()->core()->documentController()->openDocuments();
foreach (KDevelop::IDocument* doc, docs) {
m_documents.insert(KDevelop::IndexedString(doc->url()));
}
connect(model()->plugin()->core()->documentController(), SIGNAL(documentClosed(KDevelop::IDocument*)), this, SLOT(documentClosed(KDevelop::IDocument*)));
connect(model()->plugin()->core()->documentController(), SIGNAL(textDocumentCreated(KDevelop::IDocument*)), this, SLOT(documentCreated(KDevelop::IDocument*)));
}
void OpenDocumentSet::documentClosed(KDevelop::IDocument* doc)
{
if (m_documents.remove(KDevelop::IndexedString(doc->url()))) {
emit changed();
}
}
void OpenDocumentSet::documentCreated(KDevelop::IDocument* doc)
{
m_documents.insert(KDevelop::IndexedString(doc->url()));
emit changed();
}
ProblemModel::Scope OpenDocumentSet::getScope() const
{
return ProblemModel::OpenDocuments;
}
ProjectSet::ProjectSet(ProblemModel* parent)
: WatchedDocumentSet(parent)
{
}
void ProjectSet::fileAdded(ProjectFileItem* file)
{
m_documents.insert(IndexedString(file->url()));
emit changed();
}
void ProjectSet::fileRemoved(ProjectFileItem* file)
{
if (m_documents.remove(IndexedString(file->url()))) {
emit changed();
}
}
void ProjectSet::fileRenamed(const KUrl& oldFile, ProjectFileItem* newFile)
{
if (m_documents.remove(IndexedString(oldFile))) {
m_documents.insert(IndexedString(newFile->url()));
}
}
void ProjectSet::trackProjectFiles(const IProject* project)
{
if (project) {
// The implementation should derive from QObject somehow
QObject* fileManager = dynamic_cast<QObject*>(project->projectFileManager());
if (fileManager) {
connect(fileManager, SIGNAL(fileAdded(ProjectFileItem*)), this, SLOT(fileAdded(ProjectFileItem*)));
connect(fileManager, SIGNAL(fileRemoved(ProjectFileItem*)), this, SLOT(fileRemoved(ProjectFileItem*)));
connect(fileManager, SIGNAL(fileRenamed(KUrl,ProjectFileItem*)), this, SLOT(fileRenamed(KUrl,ProjectFileItem*)));
}
}
}
CurrentProjectSet::CurrentProjectSet(const KDevelop::IndexedString& document, ProblemModel* parent)
: ProjectSet(parent), m_currentProject(0)
{
setCurrentDocumentInternal(document);
trackProjectFiles(m_currentProject);
}
void CurrentProjectSet::setCurrentDocument(const KDevelop::IndexedString& url)
{
setCurrentDocumentInternal(url);
}
void CurrentProjectSet::setCurrentDocumentInternal(const KDevelop::IndexedString& url)
{
IProject* projectForUrl = model()->plugin()->core()->projectController()->findProjectForUrl(url.str());
if (projectForUrl && projectForUrl != m_currentProject) {
m_documents.clear();
m_currentProject = projectForUrl;
QList<ProjectFileItem*> files = m_currentProject->files();
foreach (ProjectFileItem* file, files) {
m_documents.insert(IndexedString(file->url()));
}
emit changed();
}
}
ProblemModel::Scope CurrentProjectSet::getScope() const
{
return ProblemModel::CurrentProject;
}
AllProjectSet::AllProjectSet(ProblemModel* parent)
: ProjectSet(parent)
{
foreach(const IProject* project, model()->plugin()->core()->projectController()->projects()) {
foreach (ProjectFileItem* file, project->files()) {
m_documents.insert(IndexedString(file->url()));
}
trackProjectFiles(project);
}
}
ProblemModel::Scope AllProjectSet::getScope() const
{
return ProblemModel::AllProjects;
}
|