Changeset View
Changeset View
Standalone View
Standalone View
addons/project/kateprojectworker.cpp
Show First 20 Lines • Show All 124 Lines • ▼ Show 20 Line(s) | 107 | { | |||
---|---|---|---|---|---|
125 | int slashIndex = path.lastIndexOf(QLatin1Char('/')); | 125 | int slashIndex = path.lastIndexOf(QLatin1Char('/')); | ||
126 | 126 | | |||
127 | /** | 127 | /** | ||
128 | * no slash? | 128 | * no slash? | ||
129 | * simple, no recursion, append new item toplevel | 129 | * simple, no recursion, append new item toplevel | ||
130 | */ | 130 | */ | ||
131 | if (slashIndex < 0) { | 131 | if (slashIndex < 0) { | ||
132 | dir2Item[path] = new KateProjectItem(KateProjectItem::Directory, path); | 132 | dir2Item[path] = new KateProjectItem(KateProjectItem::Directory, path); | ||
133 | | ||||
134 | qDebug() << path; // TODO: this path is relative. What we need is the absolute path. Files are also stored with full path | ||||
135 | dir2Item[path]->setData(path, Qt::UserRole); | ||||
136 | | ||||
133 | dir2Item[QString()]->appendRow(dir2Item[path]); | 137 | dir2Item[QString()]->appendRow(dir2Item[path]); | ||
134 | return dir2Item[path]; | 138 | return dir2Item[path]; | ||
135 | } | 139 | } | ||
136 | 140 | | |||
137 | /** | 141 | /** | ||
138 | * else, split and recurse | 142 | * else, split and recurse | ||
139 | */ | 143 | */ | ||
140 | const QString leftPart = path.left(slashIndex); | 144 | const QString leftPart = path.left(slashIndex); | ||
141 | const QString rightPart = path.right(path.size() - (slashIndex + 1)); | 145 | const QString rightPart = path.right(path.size() - (slashIndex + 1)); | ||
142 | 146 | | |||
143 | /** | 147 | /** | ||
144 | * special handling if / with nothing on one side are found | 148 | * special handling if / with nothing on one side are found | ||
145 | */ | 149 | */ | ||
146 | if (leftPart.isEmpty() || rightPart.isEmpty()) { | 150 | if (leftPart.isEmpty() || rightPart.isEmpty()) { | ||
147 | return directoryParent(dir2Item, leftPart.isEmpty() ? rightPart : leftPart); | 151 | return directoryParent(dir2Item, leftPart.isEmpty() ? rightPart : leftPart); | ||
148 | } | 152 | } | ||
149 | 153 | | |||
150 | /** | 154 | /** | ||
151 | * else: recurse on left side | 155 | * else: recurse on left side | ||
152 | */ | 156 | */ | ||
153 | dir2Item[path] = new KateProjectItem(KateProjectItem::Directory, rightPart); | 157 | dir2Item[path] = new KateProjectItem(KateProjectItem::Directory, rightPart); | ||
158 | dir2Item[path]->setData(path, Qt::UserRole); | ||||
154 | directoryParent(dir2Item, leftPart)->appendRow(dir2Item[path]); | 159 | directoryParent(dir2Item, leftPart)->appendRow(dir2Item[path]); | ||
155 | return dir2Item[path]; | 160 | return dir2Item[path]; | ||
156 | } | 161 | } | ||
157 | 162 | | |||
158 | void KateProjectWorker::loadFilesEntry(QStandardItem *parent, const QVariantMap &filesEntry, QMap<QString, KateProjectItem *> *file2Item) | 163 | void KateProjectWorker::loadFilesEntry(QStandardItem *parent, const QVariantMap &filesEntry, QMap<QString, KateProjectItem *> *file2Item) | ||
159 | { | 164 | { | ||
160 | QDir dir(m_baseDir); | 165 | QDir dir(m_baseDir); | ||
161 | if (!dir.cd(filesEntry[QStringLiteral("directory")].toString())) { | 166 | if (!dir.cd(filesEntry[QStringLiteral("directory")].toString())) { | ||
Show All 21 Lines | 184 | for (const QString &filePath : files) { | |||
183 | if (file2Item->contains(filePath)) { | 188 | if (file2Item->contains(filePath)) { | ||
184 | continue; | 189 | continue; | ||
185 | } | 190 | } | ||
186 | 191 | | |||
187 | /** | 192 | /** | ||
188 | * get file info and skip NON-files | 193 | * get file info and skip NON-files | ||
189 | */ | 194 | */ | ||
190 | QFileInfo fileInfo(filePath); | 195 | QFileInfo fileInfo(filePath); | ||
196 | // if (fileInfo.isDir()) { | ||||
197 | // qDebug() << filePath; | ||||
198 | // } | ||||
191 | if (!fileInfo.isFile()) { | 199 | if (!fileInfo.isFile()) { | ||
192 | continue; | 200 | continue; | ||
193 | } | 201 | } | ||
194 | 202 | | |||
195 | /** | 203 | /** | ||
196 | * construct the item with right directory prefix | 204 | * construct the item with right directory prefix | ||
197 | * already hang in directories in tree | 205 | * already hang in directories in tree | ||
198 | */ | 206 | */ | ||
199 | KateProjectItem *fileItem = new KateProjectItem(KateProjectItem::File, fileInfo.fileName()); | 207 | KateProjectItem *fileItem = new KateProjectItem(KateProjectItem::File, fileInfo.fileName()); | ||
200 | fileItem->setData(filePath, Qt::ToolTipRole); | 208 | fileItem->setData(filePath, Qt::ToolTipRole); | ||
201 | 209 | | |||
202 | // get the directory's relative path to the base directory | 210 | // get the directory's relative path to the base directory | ||
203 | QString dirRelPath = dir.relativeFilePath(fileInfo.absolutePath()); | 211 | QString dirRelPath = dir.relativeFilePath(fileInfo.absolutePath()); | ||
204 | // if the relative path is ".", clean it up | 212 | // if the relative path is ".", clean it up | ||
205 | if (dirRelPath == QStringLiteral(".")) { | 213 | if (dirRelPath == QStringLiteral(".")) { | ||
206 | dirRelPath = QString(); | 214 | dirRelPath = QString(); | ||
207 | } | 215 | } | ||
208 | 216 | | |||
209 | item2ParentPath.append(QPair<QStandardItem *, QStandardItem *>(fileItem, directoryParent(dir2Item, dirRelPath))); | 217 | QStandardItem* parentDirectoryItem = directoryParent(dir2Item, dirRelPath); | ||
218 | item2ParentPath.append(QPair<QStandardItem *, QStandardItem *>(fileItem, parentDirectoryItem)); | ||||
210 | fileItem->setData(filePath, Qt::UserRole); | 219 | fileItem->setData(filePath, Qt::UserRole); | ||
211 | (*file2Item)[filePath] = fileItem; | 220 | (*file2Item)[filePath] = fileItem; | ||
212 | } | 221 | } | ||
213 | 222 | | |||
214 | /** | 223 | /** | ||
215 | * plug in the file items to the tree | 224 | * plug in the file items to the tree | ||
216 | */ | 225 | */ | ||
217 | auto i = item2ParentPath.constBegin(); | 226 | auto i = item2ParentPath.constBegin(); | ||
▲ Show 20 Lines • Show All 290 Lines • Show Last 20 Lines |