Changeset View
Changeset View
Standalone View
Standalone View
plugins/filetemplates/filetemplatesplugin.cpp
1 | #include "filetemplatesplugin.h" | 1 | #include "filetemplatesplugin.h" | ||
---|---|---|---|---|---|
2 | #include "templateclassassistant.h" | 2 | #include "templateclassassistant.h" | ||
3 | #include "templatepreviewtoolview.h" | 3 | #include "templatepreviewtoolview.h" | ||
4 | #include "debug.h" | 4 | #include "debug.h" | ||
5 | 5 | | |||
6 | #include <language/codegen/templatesmodel.h> | 6 | #include <language/codegen/templatesmodel.h> | ||
7 | #include <language/interfaces/editorcontext.h> | 7 | #include <language/interfaces/editorcontext.h> | ||
8 | #include <interfaces/icore.h> | 8 | #include <interfaces/icore.h> | ||
9 | #include <interfaces/iproject.h> | ||||
9 | #include <interfaces/iuicontroller.h> | 10 | #include <interfaces/iuicontroller.h> | ||
10 | #include <interfaces/context.h> | 11 | #include <interfaces/context.h> | ||
11 | #include <interfaces/contextmenuextension.h> | 12 | #include <interfaces/contextmenuextension.h> | ||
12 | #include <interfaces/idocumentcontroller.h> | 13 | #include <interfaces/idocumentcontroller.h> | ||
14 | #include <interfaces/iselectioncontroller.h> | ||||
15 | #include <interfaces/iprojectcontroller.h> | ||||
13 | #include <project/projectmodel.h> | 16 | #include <project/projectmodel.h> | ||
14 | #include <util/path.h> | 17 | #include <util/path.h> | ||
15 | 18 | | |||
16 | #include <KActionCollection> | 19 | #include <KActionCollection> | ||
17 | #include <KConfigGroup> | 20 | #include <KConfigGroup> | ||
18 | #include <KLocalizedString> | 21 | #include <KLocalizedString> | ||
19 | #include <KPluginFactory> | 22 | #include <KPluginFactory> | ||
20 | 23 | | |||
▲ Show 20 Lines • Show All 173 Lines • ▼ Show 20 Line(s) | 192 | { | |||
194 | } | 197 | } | ||
195 | if (!baseUrl.isValid()) { | 198 | if (!baseUrl.isValid()) { | ||
196 | // fall-back to currently active document's parent directory | 199 | // fall-back to currently active document's parent directory | ||
197 | IDocument* doc = ICore::self()->documentController()->activeDocument(); | 200 | IDocument* doc = ICore::self()->documentController()->activeDocument(); | ||
198 | if (doc && doc->url().isValid()) { | 201 | if (doc && doc->url().isValid()) { | ||
199 | baseUrl = doc->url().adjusted(QUrl::RemoveFilename); | 202 | baseUrl = doc->url().adjusted(QUrl::RemoveFilename); | ||
200 | } | 203 | } | ||
201 | } | 204 | } | ||
205 | if (!baseUrl.isValid()) { | ||||
206 | // fall-back to currently selected project's or item's base directory | ||||
207 | ProjectItemContext* 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: home path | ||||
229 | baseUrl = QUrl::fromLocalFile(QDir::homePath()); | ||||
230 | } | ||||
202 | TemplateClassAssistant* assistant = new TemplateClassAssistant(QApplication::activeWindow(), baseUrl); | 231 | TemplateClassAssistant* assistant = new TemplateClassAssistant(QApplication::activeWindow(), baseUrl); | ||
203 | assistant->setAttribute(Qt::WA_DeleteOnClose); | 232 | assistant->setAttribute(Qt::WA_DeleteOnClose); | ||
204 | assistant->show(); | 233 | assistant->show(); | ||
205 | } | 234 | } | ||
206 | 235 | | |||
207 | FileTemplatesPlugin::TemplateType FileTemplatesPlugin::determineTemplateType(const QUrl& url) | 236 | FileTemplatesPlugin::TemplateType FileTemplatesPlugin::determineTemplateType(const QUrl& url) | ||
208 | { | 237 | { | ||
209 | QDir dir(url.toLocalFile()); | 238 | QDir dir(url.toLocalFile()); | ||
▲ Show 20 Lines • Show All 80 Lines • Show Last 20 Lines |