| 189 | } |
| 190 | |
| 191 | void FileTemplatesPlugin::createFromTemplate() |
| 192 | { |
| 193 | QUrl baseUrl; |
| 194 | if (auto* action = qobject_cast<QAction*>(sender())) |
| 195 | { |
| 196 | baseUrl = action->data().toUrl(); |
| 197 | } |
| 198 | if (!baseUrl.isValid()) { |
| 199 | // fall-back to currently active document's parent directory |
| 200 | IDocument* doc = ICore::self()->documentController()->activeDocument(); |
| 201 | if (doc && doc->url().isValid()) { |
| 202 | baseUrl = doc->url().adjusted(QUrl::RemoveFilename); |
| 203 | } |
| 204 | } |
| 205 | if (!baseUrl.isValid()) { |
| 206 | // fall-back to currently selected project's or item's base directory |
| 207 | auto* projectContext = dynamic_cast<ProjectItemContext*>(ICore::self()->selectionController()->currentSelection()); |
| 208 | if (projectContext) { |
| 209 | const QList<ProjectBaseItem*> items = projectContext->items(); |
| 210 | if (items.size() == 1) { |
| 211 | ProjectBaseItem* item = items.at(0); |
| 212 | if (item->folder()) { |
| 213 | baseUrl = item->path().toUrl(); |
| 214 | } else if (item->target()) { |
| 215 | baseUrl = item->parent()->path().toUrl(); |
| 216 | } |
| 217 | } |
| 218 | } |
| 219 | } |
| 220 | if (!baseUrl.isValid()) { |
| 221 | // fall back to base directory of currently open project, if there is only one |
| 222 | const QList<IProject*> projects = ICore::self()->projectController()->projects(); |
| 223 | if (projects.size() == 1) { |
| 224 | baseUrl = projects.at(0)->path().toUrl(); |
| 225 | } |
| 226 | } |
| 227 | if (!baseUrl.isValid()) { |
| 228 | // last resort |
| 229 | baseUrl = ICore::self()->projectController()->projectsBaseDirectory(); |
| 230 | } |
| 231 | auto* assistant = new TemplateClassAssistant(QApplication::activeWindow(), baseUrl); |
| 232 | assistant->setAttribute(Qt::WA_DeleteOnClose); |
| 233 | assistant->show(); |
| 234 | } |
| 235 | |
| 236 | FileTemplatesPlugin::TemplateType FileTemplatesPlugin::determineTemplateType(const QUrl& url) |
| 237 | { |
nothing calls this directly
no test coverage detected