MCPcopy Create free account
hub / github.com/KDE/kdevelop / DocumentSwitcherItem

Method DocumentSwitcherItem

plugins/documentswitcher/documentswitcheritem.cpp:17–52  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15#include <interfaces/iprojectcontroller.h>
16
17DocumentSwitcherItem::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
54DocumentSwitcherItem::~DocumentSwitcherItem() = default;
55

Callers

nothing calls this directly

Calls 9

projectControllerMethod · 0.80
prettyFilePathMethod · 0.80
endsWithMethod · 0.80
midMethod · 0.80
findProjectForUrlMethod · 0.80
iconMethod · 0.45
urlMethod · 0.45
fileNameMethod · 0.45
indexOfMethod · 0.45

Tested by

no test coverage detected