| 126 | } |
| 127 | |
| 128 | bool KDevelop::renameUrl(const KDevelop::IProject* project, const QUrl& oldname, const QUrl& newname) |
| 129 | { |
| 130 | bool wasVcsMoved = false; |
| 131 | IPlugin* vcsplugin = project->versionControlPlugin(); |
| 132 | if (vcsplugin) { |
| 133 | auto* vcs = vcsplugin->extension<IBasicVersionControl>(); |
| 134 | |
| 135 | // We have a vcs and the file/folder is controller, need to make the rename through vcs |
| 136 | if (vcs->isVersionControlled(oldname)) { |
| 137 | VcsJob* job = vcs->move(oldname, newname); |
| 138 | if (job && !job->exec()) { |
| 139 | return false; |
| 140 | } |
| 141 | wasVcsMoved = true; |
| 142 | } |
| 143 | } |
| 144 | // Fallback for the case of no vcs, or not-vcs-managed file/folder |
| 145 | |
| 146 | // try to save-as the text document, so users can directly continue to work |
| 147 | // on the renamed url as well as keeping the undo-stack intact |
| 148 | IDocument* document = ICore::self()->documentController()->documentForUrl(oldname); |
| 149 | if (document && document->textDocument()) { |
| 150 | if (!document->textDocument()->saveAs(newname)) { |
| 151 | return false; |
| 152 | } |
| 153 | if (!wasVcsMoved) { |
| 154 | // unlink the old file |
| 155 | removeUrl(project, oldname, false); |
| 156 | } |
| 157 | return true; |
| 158 | } else if (!wasVcsMoved) { |
| 159 | // fallback for non-textdocuments (also folders e.g.) |
| 160 | KIO::CopyJob* job = KIO::move(oldname, newname); |
| 161 | KJobWidgets::setWindow(job, QApplication::activeWindow()); |
| 162 | bool success = job->exec(); |
| 163 | if (success) { |
| 164 | // save files that where opened in this folder under the new name |
| 165 | Path oldBasePath(oldname); |
| 166 | Path newBasePath(newname); |
| 167 | const auto documents = ICore::self()->documentController()->openDocuments(); |
| 168 | for (auto* doc : documents) { |
| 169 | auto textDoc = doc->textDocument(); |
| 170 | if (textDoc && oldname.isParentOf(doc->url())) { |
| 171 | const auto path = Path(textDoc->url()); |
| 172 | const auto relativePath = oldBasePath.relativePath(path); |
| 173 | const auto newPath = Path(newBasePath, relativePath); |
| 174 | textDoc->saveAs(newPath.toUrl()); |
| 175 | } |
| 176 | } |
| 177 | } |
| 178 | return success; |
| 179 | } else { |
| 180 | return true; |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | bool KDevelop::renamePath(const KDevelop::IProject* project, const KDevelop::Path& oldName, const KDevelop::Path& newName) |
| 185 | { |
nothing calls this directly
no test coverage detected