| 15 | #include <interfaces/iprojectcontroller.h> |
| 16 | |
| 17 | DocumentSwitcherItem::DocumentSwitcherItem(KDevelop::IDocument *document) |
| 18 | { |
| 19 | setIcon(document->icon()); |
| 20 | |
| 21 | const QUrl &url = document->url(); |
| 22 | |
| 23 | KDevelop::IProjectController *projectController = KDevelop::ICore::self()->projectController(); |
| 24 | |
| 25 | // Extract file name and path. |
| 26 | QString text = url.fileName(); |
| 27 | QString path = projectController->prettyFilePath(url, KDevelop::IProjectController::FormatPlain); |
| 28 | |
| 29 | const bool isPartOfOpenProject = QDir::isRelativePath(path); |
| 30 | if (path.endsWith(QLatin1Char('/'))) { |
| 31 | path.chop(1); |
| 32 | } |
| 33 | if (isPartOfOpenProject) { |
| 34 | const int projectNameSize = path.indexOf(QLatin1Char(':')); |
| 35 | |
| 36 | // first: project name, second: path to file in project (might be just '/' when the file is in the project root dir) |
| 37 | const QPair<QString, QString> fileInProjectInfo = (projectNameSize < 0) |
| 38 | ? qMakePair(path, QStringLiteral("/")) |
| 39 | : qMakePair(path.left(projectNameSize), path.mid(projectNameSize + 1)); |
| 40 | |
| 41 | text = QStringLiteral("%1 (%2:%3)").arg(text, fileInProjectInfo.first, fileInProjectInfo.second); |
| 42 | } |
| 43 | else { |
| 44 | text += QLatin1String(" (") + path + QLatin1Char(')'); |
| 45 | } |
| 46 | |
| 47 | setText(text); |
| 48 | |
| 49 | // Set item data. |
| 50 | KDevelop::IProject *project = projectController->findProjectForUrl(url); |
| 51 | setData(QVariant::fromValue(project), DocumentSwitcherTreeView::ProjectRole); |
| 52 | } |
| 53 | |
| 54 | DocumentSwitcherItem::~DocumentSwitcherItem() = default; |
| 55 |
nothing calls this directly
no test coverage detected