| 144 | } |
| 145 | |
| 146 | const DiffViewsCtrl::ViewData DiffViewsCtrl::createView(const QUrl& url, RepoStatusModel::Areas area) |
| 147 | { |
| 148 | auto* docCtrl = ICore::self()->documentController(); |
| 149 | |
| 150 | // If an appropriate view is already cached |
| 151 | // return it |
| 152 | QString key = viewKey(url, area); |
| 153 | auto viewDataIt = m_views.find(key); |
| 154 | if (viewDataIt != m_views.end()) { |
| 155 | return viewDataIt->second; |
| 156 | } |
| 157 | |
| 158 | // Create a new view and populate the |
| 159 | // ViewData structure |
| 160 | ViewData data; |
| 161 | data.project = ICore::self()->projectController()->findProjectForUrl(url); |
| 162 | |
| 163 | if (data.project == nullptr) |
| 164 | return data; |
| 165 | |
| 166 | data.area = area; |
| 167 | data.doc = docCtrl->openDocumentFromText(QString()); |
| 168 | data.ktDoc = data.doc->textDocument(); |
| 169 | data.url = url; |
| 170 | data.vcs = gitForUrl(url); |
| 171 | |
| 172 | // Cache the new view data |
| 173 | m_views[key] = data; |
| 174 | |
| 175 | // Set the view title |
| 176 | if (area == RepoStatusModel::Index) |
| 177 | data.doc->setPrettyName(i18n("%1 (staged)", url.fileName())); |
| 178 | else if (area == RepoStatusModel::IndexRoot) |
| 179 | data.doc->setPrettyName(i18n("Staged (%1)", url.fileName())); |
| 180 | else if (area == RepoStatusModel::WorkTreeRoot) |
| 181 | data.doc->setPrettyName(i18n("Unstaged (%1)", url.fileName())); |
| 182 | else if (area == RepoStatusModel::WorkTree) |
| 183 | data.doc->setPrettyName(i18n("%1 (unstaged)", url.fileName())); |
| 184 | |
| 185 | // Connect cleanup handlers on document/project closure and kdevelop shutdown |
| 186 | connect(ICore::self()->projectController(), &IProjectController::projectClosed, this, [=] (KDevelop::IProject* proj) { |
| 187 | if (proj == data.project) { |
| 188 | auto dataIt = m_views.find(key); |
| 189 | if (dataIt != m_views.end()) |
| 190 | dataIt->second.doc->close(); |
| 191 | } |
| 192 | }); |
| 193 | connect(ICore::self(), &ICore::aboutToShutdown, this, [=] { |
| 194 | auto dataIt = m_views.find(key); |
| 195 | if (dataIt != m_views.end()) |
| 196 | dataIt->second.doc->close(); |
| 197 | }); |
| 198 | connect(data.ktDoc, &KTextEditor::Document::aboutToClose, this, [=]() { m_views.erase(key); }); |
| 199 | |
| 200 | // Set the context menu for the document & add the appropriate actions to it |
| 201 | const auto& views = data.ktDoc->views(); |
| 202 | for (auto view : views) |
| 203 | setupDiffActions(view, area); |
no test coverage detected