File indexing completed on 2025-02-16 04:57:43

0001 /*
0002  * SPDX-FileCopyrightText: 2006 Dmitry Morozhnikov <dmiceman@mail.ru>
0003  * SPDX-FileCopyrightText: 2018-2024 Laurent Montel <montel@kde.org>
0004  *
0005  * SPDX-License-Identifier: GPL-2.0-or-later
0006  */
0007 
0008 #include "templatesinsertcommandpushbutton.h"
0009 
0010 #include "templateparser_debug.h"
0011 #include <KLocalizedString>
0012 
0013 using namespace TemplateParser;
0014 
0015 TemplatesInsertCommandPushButton::TemplatesInsertCommandPushButton(QWidget *parent, const QString &name)
0016     : QPushButton(parent)
0017     , mMenuCommand(new TemplatesCommandMenu(this))
0018 {
0019     setObjectName(name);
0020     setText(i18n("&Insert Command"));
0021 
0022     mMenuCommand->setObjectName(QLatin1StringView("templatescommandmenu"));
0023     mMenuCommand->fillMenu();
0024     mMenuCommand->fillSubMenus();
0025     setMenu(mMenuCommand->menu());
0026     connect(mMenuCommand, qOverload<const QString &, int>(&TemplatesCommandMenu::insertCommand), this, &TemplatesInsertCommandPushButton::insertCommand);
0027 
0028     setToolTip(i18nc("@info:tooltip", "Select a command to insert into the template"));
0029     setWhatsThis(i18nc("@info:whatsthis",
0030                        "Traverse this menu to find a command to insert into the current template "
0031                        "being edited.  The command will be inserted at the cursor location, "
0032                        "so you want to move your cursor to the desired insertion point first."));
0033 }
0034 
0035 TemplatesInsertCommandPushButton::~TemplatesInsertCommandPushButton() = default;
0036 
0037 TemplatesCommandMenu::MenuTypes TemplatesInsertCommandPushButton::type() const
0038 {
0039     return mMenuCommand->type();
0040 }
0041 
0042 void TemplatesInsertCommandPushButton::setType(TemplatesCommandMenu::MenuTypes type)
0043 {
0044     mMenuCommand->setType(type);
0045     setMenu(mMenuCommand->menu());
0046 }
0047 
0048 #include "moc_templatesinsertcommandpushbutton.cpp"