File indexing completed on 2024-12-08 05:14:49
0001 // SPDX-License-Identifier: GPL-2.0-or-later 0002 // SPDX-FileCopyrightText: 2007 Dominik Seichter <domseichter@web.de> 0003 0004 #ifndef TOKEN_HELP_DIALOG_H 0005 #define TOKEN_HELP_DIALOG_H 0006 0007 #include <QDialog> 0008 0009 #include "ui_tokenhelpwidget.h" 0010 #include <KTreeWidgetSearchLineWidget> 0011 0012 class QLineEdit; 0013 class QTreeWidgetItem; 0014 0015 class BatchRenamer; 0016 class KRenameModel; 0017 class KRenameUnformattedWrappedModel; 0018 0019 class TokenHelpDialog : public QDialog 0020 { 0021 Q_OBJECT 0022 public: 0023 TokenHelpDialog(KRenameModel *model, BatchRenamer *renamer, 0024 QLineEdit *edit, QWidget *parent = nullptr); 0025 0026 ~TokenHelpDialog() override; 0027 0028 /** Adds a category to the help dialog. 0029 * The category will be added and all its commands will also be added to the "All" category. 0030 * 0031 * \param headline headline of the category 0032 * \param commands list of all tokens 0033 * \param icon icon of the category 0034 * \param first if true make sure that this is the first category (after all) and is selected by 0035 * default. 0036 */ 0037 void add(const QString &headline, const QStringList &commands, const QIcon &icon, bool first = false); 0038 0039 /** 0040 * Retrieve the separator between token and help 0041 * \returns the token separator 0042 */ 0043 static const QString getTokenSeparator(); 0044 0045 public Q_SLOTS: 0046 int exec() override; 0047 0048 private Q_SLOTS: 0049 void slotInsert(); 0050 0051 void slotCategoryChanged(QTreeWidgetItem *item); 0052 void saveConfig(); 0053 0054 void slotEnableControls(); 0055 void slotPreviewClicked(bool bPreview); 0056 void slotUpdatePreview(); 0057 0058 private: 0059 void loadConfig(); 0060 0061 /** 0062 * Select a category by its name. 0063 * \param category user visible name of a category 0064 */ 0065 void selectCategory(const QString &category); 0066 0067 /** 0068 * Add all tokens stored in the list 0069 * m_recent to the list of tokens and to categories. 0070 */ 0071 void addRecentTokens(); 0072 0073 /** 0074 * Add a token to the list of recent tokens. 0075 * \param token the token itself 0076 * \param help the help string for the token 0077 */ 0078 void addToRecentTokens(const QString &token, const QString &help); 0079 0080 private: 0081 KRenameUnformattedWrappedModel *m_model; 0082 0083 Ui::TokenHelpWidget m_widget; 0084 0085 QLineEdit *m_edit; 0086 BatchRenamer *m_renamer; 0087 0088 QMap<QString, QStringList> m_map; 0089 0090 QString m_first; 0091 0092 QString m_lastSelected; 0093 QStringList m_recent; 0094 0095 static const int S_MAX_RECENT; ///< Maximum number of recent tokens 0096 }; 0097 0098 #endif // TOKEN_HELP_DIALOG_H