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

Method createFromTemplate

plugins/filetemplates/filetemplatesplugin.cpp:191–234  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

189}
190
191void 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
236FileTemplatesPlugin::TemplateType FileTemplatesPlugin::determineTemplateType(const QUrl& url)
237{

Callers

nothing calls this directly

Calls 15

activeDocumentMethod · 0.80
documentControllerMethod · 0.80
currentSelectionMethod · 0.80
selectionControllerMethod · 0.80
folderMethod · 0.80
projectsMethod · 0.80
projectControllerMethod · 0.80
projectsBaseDirectoryMethod · 0.80
setAttributeMethod · 0.80
showMethod · 0.80
toUrlMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected