File indexing completed on 2024-05-05 05:51:23

0001 /* This file is part of the KDE project
0002  *
0003  *  SPDX-FileCopyrightText: 2019 Dominik Haumann <dhaumann@kde.org>
0004  *
0005  *  SPDX-License-Identifier: LGPL-2.0-or-later
0006  */
0007 #pragma once
0008 
0009 #include "ui_configwidget.h"
0010 #include "ui_tooldialog.h"
0011 
0012 #include <KTextEditor/ConfigPage>
0013 #include <KTextEditor/Plugin>
0014 
0015 #include <QDialog>
0016 #include <QStandardItemModel>
0017 
0018 class KConfig;
0019 class KateExternalToolsPlugin;
0020 class KateExternalTool;
0021 
0022 /**
0023  * The config widget.
0024  * The config widget allows the user to view a list of services of the type
0025  * "Kate/ExternalTool" and add, remove or edit them.
0026  */
0027 class KateExternalToolsConfigWidget : public KTextEditor::ConfigPage, public Ui::ExternalToolsConfigWidget
0028 {
0029     Q_OBJECT
0030 public:
0031     KateExternalToolsConfigWidget(QWidget *parent, KateExternalToolsPlugin *plugin);
0032     ~KateExternalToolsConfigWidget() override;
0033 
0034     QString name() const override;
0035     QString fullName() const override;
0036     QIcon icon() const override;
0037 
0038 public Q_SLOTS:
0039     void apply() override;
0040     void reset() override;
0041     void defaults() override
0042     {
0043         reset();
0044     }
0045 
0046 private Q_SLOTS:
0047     void addNewTool(KateExternalTool *tool);
0048     void lazyInitDefaultsMenu(QMenu *defaultsMenu);
0049     void slotAddDefaultTool(int defaultToolsIndex);
0050     void slotAddCategory();
0051     void slotAddTool();
0052     void slotEdit();
0053     void slotRemove();
0054     void slotSelectionChanged();
0055     void slotItemChanged(QStandardItem *item);
0056 
0057     /**
0058      * Helper to open the ToolDialog.
0059      * Returns true, if the user clicked OK.
0060      */
0061     bool editTool(KateExternalTool *tool);
0062 
0063     /**
0064      * Creates a new category or returns existing one.
0065      */
0066     QStandardItem *addCategory(const QString &translatedCategory);
0067 
0068     /**
0069      * Returns the currently active category. The returned pointer is always valid.
0070      */
0071     QStandardItem *currentCategory() const;
0072 
0073 private:
0074     bool m_changed = false;
0075     KateExternalToolsPlugin *m_plugin;
0076     std::vector<KateExternalTool *> m_toolsToRemove;
0077     QStandardItemModel m_toolsModel;
0078     QStandardItem *m_noCategory = nullptr;
0079 
0080     struct ChangedToolInfo {
0081         KateExternalTool *tool = nullptr;
0082         QString oldName;
0083     };
0084     std::vector<ChangedToolInfo> m_changedTools;
0085 };
0086 
0087 /**
0088  * A Dialog to edit a single KateExternalTool object
0089  */
0090 class KateExternalToolServiceEditor : public QDialog
0091 {
0092     Q_OBJECT
0093 
0094 public:
0095     explicit KateExternalToolServiceEditor(KateExternalTool *tool, KateExternalToolsPlugin *plugin, QWidget *parent = nullptr);
0096 
0097 private Q_SLOTS:
0098     /**
0099      * Run when the OK button is clicked, to ensure critical values are provided.
0100      */
0101     void slotOKClicked();
0102 
0103     /**
0104      * show a mimetype chooser dialog
0105      */
0106     void showMTDlg();
0107 
0108 public:
0109     Ui::ToolDialog ui;
0110 
0111 private:
0112     KateExternalToolsPlugin *m_plugin;
0113     KateExternalTool *m_tool;
0114 };
0115 
0116 // kate: space-indent on; indent-width 4; replace-tabs on;