File indexing completed on 2024-05-05 04:39:49

0001 /*
0002     SPDX-FileCopyrightText: 2012 Miha Čančula <miha@noughmad.eu>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef KDEVPLATFORM_PLUGIN_TEMPLATECLASSASSISTANT_H
0008 #define KDEVPLATFORM_PLUGIN_TEMPLATECLASSASSISTANT_H
0009 
0010 #include <KAssistantDialog>
0011 #include <QUrl>
0012 
0013 namespace KDevelop
0014 {
0015 
0016 /**
0017  * @brief An assistant for creating new source code files using Grantlee templates.
0018  *
0019  * This assistant guides the user through generating source code from templates.
0020  * Currently, class and unit test templates are supported.
0021  *
0022  * Depending on the selected template type (@c Class or @c Test, see SourceFileTemplate::type()),
0023  * The assistant creates appropriate pages for setting the required options.
0024  *
0025  * When creating a new class, an ICreateClassHelper is used for the language-specific features.
0026  * If no such helper exists for the chosen template, a generic implementation is used.
0027  * The actual generation of classes is done using a TemplateClassGenerator.
0028  **/
0029 class TemplateClassAssistant : public KAssistantDialog
0030 {
0031     Q_OBJECT
0032 public:
0033     /**
0034      * Creates a new assistant
0035      *
0036      * @param parent parent widget
0037      * @param baseUrl the directory where the new class should be created
0038      **/
0039     explicit TemplateClassAssistant(QWidget* parent, const QUrl& baseUrl = QUrl());
0040     /**
0041      * Destroys the assistant
0042      **/
0043     ~TemplateClassAssistant() override;
0044 
0045     /**
0046      * Sets up the template selection page
0047      */
0048     void setup();
0049 
0050     /**
0051      * @return The url from where the assistant was started.
0052      *
0053      * If the assistant was started from the context menu of a project item,
0054      * this function returns that item's URL. Otherwise, this returns an invalid URL.
0055      */
0056     QUrl baseUrl() const;
0057 
0058     /**
0059      * Called when the user selected a template in the first page of the assistant.
0060      *
0061      * This function creates all the other pages, depending on the type of the selected template.
0062      *
0063      * @param templateDescription template description file of the selected template
0064      */
0065     void templateChosen(const QString& templateDescription);
0066 
0067 public Q_SLOTS:
0068     void next() override;
0069     void back() override;
0070     void accept() override;
0071 
0072     /**
0073      * Sets whether the current page is valid or not.
0074      * If the page is valid, the "Next" or "Finish" button will be displayed.
0075      *
0076      * @param valid true if the user-provided information on the current page is valid, false otherwise
0077      */
0078     void setCurrentPageValid(bool valid);
0079 
0080 private:
0081     class TemplateClassAssistantPrivate* const d;
0082 };
0083 
0084 }
0085 
0086 #endif // KDEVPLATFORM_PLUGIN_TEMPLATECLASSASSISTANT_H