Changeset View
Changeset View
Standalone View
Standalone View
kdevplatform/project/abstractfilemanagerplugin.cpp
Show All 35 Lines | |||||
36 | #include <KDirWatch> | 36 | #include <KDirWatch> | ||
37 | 37 | | |||
38 | #include <interfaces/iproject.h> | 38 | #include <interfaces/iproject.h> | ||
39 | #include <interfaces/icore.h> | 39 | #include <interfaces/icore.h> | ||
40 | #include <interfaces/iprojectcontroller.h> | 40 | #include <interfaces/iprojectcontroller.h> | ||
41 | #include <serialization/indexedstring.h> | 41 | #include <serialization/indexedstring.h> | ||
42 | 42 | | |||
43 | #include "projectfiltermanager.h" | 43 | #include "projectfiltermanager.h" | ||
44 | #include "projectwatcher.h" | ||||
44 | #include "debug.h" | 45 | #include "debug.h" | ||
45 | 46 | | |||
46 | #define ifDebug(x) | 47 | #define ifDebug(x) | ||
47 | 48 | | |||
48 | using namespace KDevelop; | 49 | using namespace KDevelop; | ||
49 | 50 | | |||
50 | //BEGIN Helper | 51 | //BEGIN Helper | ||
51 | 52 | | |||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Line(s) | 75 | public: | |||
98 | void stopWatcher(ProjectFolderItem* folder); | 99 | void stopWatcher(ProjectFolderItem* folder); | ||
99 | /// Continues watching the given folder for changes. | 100 | /// Continues watching the given folder for changes. | ||
100 | void continueWatcher(ProjectFolderItem* folder); | 101 | void continueWatcher(ProjectFolderItem* folder); | ||
101 | /// Common renaming function. | 102 | /// Common renaming function. | ||
102 | bool rename(ProjectBaseItem* item, const Path& newPath); | 103 | bool rename(ProjectBaseItem* item, const Path& newPath); | ||
103 | 104 | | |||
104 | void removeFolder(ProjectFolderItem* folder); | 105 | void removeFolder(ProjectFolderItem* folder); | ||
105 | 106 | | |||
106 | QHash<IProject*, KDirWatch*> m_watchers; | 107 | QHash<IProject*, ProjectWatcher*> m_watchers; | ||
107 | QHash<IProject*, QList<FileManagerListJob*> > m_projectJobs; | 108 | QHash<IProject*, QList<FileManagerListJob*> > m_projectJobs; | ||
108 | QVector<QString> m_stoppedFolders; | 109 | QVector<QString> m_stoppedFolders; | ||
109 | ProjectFilterManager m_filters; | 110 | ProjectFilterManager m_filters; | ||
110 | }; | 111 | }; | ||
111 | 112 | | |||
112 | void AbstractFileManagerPluginPrivate::projectClosing(IProject* project) | 113 | void AbstractFileManagerPluginPrivate::projectClosing(IProject* project) | ||
113 | { | 114 | { | ||
114 | if ( m_projectJobs.contains(project) ) { | 115 | if ( m_projectJobs.contains(project) ) { | ||
115 | // make sure the import job does not live longer than the project | 116 | // make sure the import job does not live longer than the project | ||
116 | // see also addLotsOfFiles test | 117 | // see also addLotsOfFiles test | ||
117 | foreach( FileManagerListJob* job, m_projectJobs[project] ) { | 118 | foreach( FileManagerListJob* job, m_projectJobs[project] ) { | ||
118 | qCDebug(FILEMANAGER) << "killing project job:" << job; | 119 | qCDebug(FILEMANAGER) << "killing project job:" << job; | ||
119 | job->abort(); | 120 | job->abort(); | ||
120 | } | 121 | } | ||
121 | m_projectJobs.remove(project); | 122 | m_projectJobs.remove(project); | ||
122 | } | 123 | } | ||
123 | #ifdef TIME_IMPORT_JOB | 124 | #ifdef TIME_IMPORT_JOB | ||
mwolff: If you find this overly useful (I don't personally, but OK), please commit this part right away… | |||||
Not exactly like that: the timer should only be started when the project is still being watched. Without that conditional the debug statement can print multiple additional times with a 0s timing. I'll push to 5.2 and hold off updating this rev. until the commit has been merged by someone. rjvbb: Not exactly like that: the timer should only be started when the project is still being watched. | |||||
124 | QElapsedTimer timer; | 125 | QElapsedTimer timer; | ||
125 | if (m_watchers.contains(project)) { | 126 | if (m_watchers.contains(project)) { | ||
126 | timer.start(); | 127 | timer.start(); | ||
127 | } | 128 | } | ||
128 | #endif | 129 | #endif | ||
129 | delete m_watchers.take(project); | 130 | delete m_watchers.take(project); | ||
130 | #ifdef TIME_IMPORT_JOB | 131 | #ifdef TIME_IMPORT_JOB | ||
131 | if (timer.isValid()) { | 132 | if (timer.isValid()) { | ||
▲ Show 20 Lines • Show All 134 Lines • ▼ Show 20 Line(s) | 266 | { | |||
266 | qCDebug(FILEMANAGER) << "created:" << path_; | 267 | qCDebug(FILEMANAGER) << "created:" << path_; | ||
267 | QFileInfo info(path_); | 268 | QFileInfo info(path_); | ||
268 | 269 | | |||
269 | ///FIXME: share memory with parent | 270 | ///FIXME: share memory with parent | ||
270 | const Path path(path_); | 271 | const Path path(path_); | ||
271 | const IndexedString indexedPath(path.pathOrUrl()); | 272 | const IndexedString indexedPath(path.pathOrUrl()); | ||
272 | const IndexedString indexedParent(path.parent().pathOrUrl()); | 273 | const IndexedString indexedParent(path.parent().pathOrUrl()); | ||
273 | 274 | | |||
274 | QHashIterator<IProject*, KDirWatch*> it(m_watchers); | 275 | QHashIterator<IProject*, ProjectWatcher*> it(m_watchers); | ||
275 | while (it.hasNext()) { | 276 | while (it.hasNext()) { | ||
276 | const auto p = it.next().key(); | 277 | const auto p = it.next().key(); | ||
277 | if ( !p->projectItem()->model() ) { | 278 | if ( !p->projectItem()->model() ) { | ||
278 | // not yet finished with loading | 279 | // not yet finished with loading | ||
279 | // FIXME: how should this be handled? see unit test | 280 | // FIXME: how should this be handled? see unit test | ||
280 | continue; | 281 | continue; | ||
281 | } | 282 | } | ||
282 | if ( !q->isValid(path, info.isDir(), p) ) { | 283 | if ( !q->isValid(path, info.isDir(), p) ) { | ||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Line(s) | 329 | if (path_.startsWith(folder)) { | |||
329 | return; | 330 | return; | ||
330 | } | 331 | } | ||
331 | } | 332 | } | ||
332 | qCDebug(FILEMANAGER) << "deleted:" << path_; | 333 | qCDebug(FILEMANAGER) << "deleted:" << path_; | ||
333 | 334 | | |||
334 | const Path path(QUrl::fromLocalFile(path_)); | 335 | const Path path(QUrl::fromLocalFile(path_)); | ||
335 | const IndexedString indexed(path.pathOrUrl()); | 336 | const IndexedString indexed(path.pathOrUrl()); | ||
336 | 337 | | |||
337 | QHashIterator<IProject*, KDirWatch*> it(m_watchers); | 338 | QHashIterator<IProject*, ProjectWatcher*> it(m_watchers); | ||
338 | while (it.hasNext()) { | 339 | while (it.hasNext()) { | ||
339 | const auto p = it.next().key(); | 340 | const auto p = it.next().key(); | ||
340 | if (path == p->path()) { | 341 | if (path == p->path()) { | ||
341 | KMessageBox::error(qApp->activeWindow(), | 342 | KMessageBox::error(qApp->activeWindow(), | ||
342 | i18n("The base folder of project <b>%1</b>" | 343 | i18n("The base folder of project <b>%1</b>" | ||
343 | " got deleted or moved outside of KDevelop.\n" | 344 | " got deleted or moved outside of KDevelop.\n" | ||
344 | "The project has to be closed.", p->name()), | 345 | "The project has to be closed.", p->name()), | ||
345 | i18n("Project Folder Deleted") ); | 346 | i18n("Project Folder Deleted") ); | ||
▲ Show 20 Lines • Show All 140 Lines • ▼ Show 20 Line(s) | |||||
486 | ProjectFolderItem *AbstractFileManagerPlugin::import( IProject *project ) | 487 | ProjectFolderItem *AbstractFileManagerPlugin::import( IProject *project ) | ||
487 | { | 488 | { | ||
488 | ProjectFolderItem *projectRoot = createFolderItem( project, project->path(), nullptr ); | 489 | ProjectFolderItem *projectRoot = createFolderItem( project, project->path(), nullptr ); | ||
489 | emit folderAdded( projectRoot ); | 490 | emit folderAdded( projectRoot ); | ||
490 | qCDebug(FILEMANAGER) << "imported new project" << project->name() << "at" << projectRoot->path(); | 491 | qCDebug(FILEMANAGER) << "imported new project" << project->name() << "at" << projectRoot->path(); | ||
491 | 492 | | |||
492 | ///TODO: check if this works for remote files when something gets changed through another KDE app | 493 | ///TODO: check if this works for remote files when something gets changed through another KDE app | ||
493 | if ( project->path().isLocalFile() ) { | 494 | if ( project->path().isLocalFile() ) { | ||
494 | d->m_watchers[project] = new KDirWatch( project ); | 495 | auto watcher = new ProjectWatcher(project, &d->m_filters); | ||
this part of the patch (i.e. introducing the temporary and referencing it instead of looking it up repeatedly in m_watchers) is fine, but unrelated to this patch. Please commit it separately. mwolff: this part of the patch (i.e. introducing the temporary and referencing it instead of looking it… | |||||
495 | 496 | | |||
496 | connect(d->m_watchers[project], &KDirWatch::created, | 497 | // set up the signal handling | ||
498 | connect(watcher, &KDirWatch::created, | ||||
497 | this, [&] (const QString& path_) { d->created(path_); }); | 499 | this, [&] (const QString& path_) { d->created(path_); }); | ||
498 | connect(d->m_watchers[project], &KDirWatch::deleted, | 500 | connect(watcher, &KDirWatch::deleted, | ||
499 | this, [&] (const QString& path_) { d->deleted(path_); }); | 501 | this, [&] (const QString& path_) { d->deleted(path_); }); | ||
500 | 502 | watcher->addDir(project->path().toLocalFile(), KDirWatch::WatchSubDirs | KDirWatch:: WatchFiles ); | |||
501 | d->m_watchers[project]->addDir(project->path().toLocalFile(), KDirWatch::WatchSubDirs | KDirWatch:: WatchFiles ); | 503 | d->m_watchers[project] = watcher; | ||
502 | } | 504 | } | ||
503 | 505 | | |||
504 | d->m_filters.add(project); | 506 | d->m_filters.add(project); | ||
505 | 507 | | |||
506 | return projectRoot; | 508 | return projectRoot; | ||
507 | } | 509 | } | ||
508 | 510 | | |||
509 | KJob* AbstractFileManagerPlugin::createImportJob(ProjectFolderItem* item) | 511 | KJob* AbstractFileManagerPlugin::createImportJob(ProjectFolderItem* item) | ||
▲ Show 20 Lines • Show All 171 Lines • Show Last 20 Lines |
If you find this overly useful (I don't personally, but OK), please commit this part right away with the following code: