File indexing completed on 2024-05-05 05:52:19
0001 /* This file is part of the Kate project. 0002 * Based on the snippet plugin from KDevelop 4. 0003 * 0004 * SPDX-FileCopyrightText: 2007 Robert Gruber <rgruber@users.sourceforge.net> 0005 * SPDX-FileCopyrightText: 2010 Milian Wolff <mail@milianw.de> 0006 * SPDX-FileCopyrightText: 2012 Christoph Cullmann <cullmann@kde.org> 0007 * SPDX-FileCopyrightText: 2014 Sven Brauch <svenbrauch@gmail.com> 0008 * 0009 * SPDX-License-Identifier: LGPL-2.0-or-later 0010 */ 0011 0012 #pragma once 0013 0014 #include <KNSWidgets/Action> 0015 #include <KTextEditor/MainWindow> 0016 0017 #include "ui_snippetview.h" 0018 0019 class QStandardItem; 0020 class KateSnippetGlobal; 0021 class QAction; 0022 class QSortFilterProxyModel; 0023 0024 namespace KTextEditor 0025 { 0026 } 0027 0028 /** 0029 * This class gets embedded into the right tool view by the KateSnippetGlobal. 0030 * @author Robert Gruber <rgruber@users.sourceforge.net> 0031 * @author Milian Wolff <mail@milianw.de> 0032 */ 0033 class SnippetView : public QWidget, public Ui::SnippetViewBase 0034 { 0035 Q_OBJECT 0036 0037 public: 0038 explicit SnippetView(KateSnippetGlobal *plugin, KTextEditor::MainWindow *mainWindow, QWidget *parent = nullptr); 0039 0040 public: 0041 void setupActionsForWindow(QWidget *widget); 0042 0043 private Q_SLOTS: 0044 /** 0045 * Opens the "Add Repository" dialog. 0046 */ 0047 void slotAddRepo(); 0048 0049 /** 0050 * Opens the "Edit repository" dialog. 0051 */ 0052 void slotEditRepo(); 0053 0054 /** 0055 * Removes the selected repository from the disk. 0056 */ 0057 void slotRemoveRepo(); 0058 0059 /** 0060 * Insert the selected snippet into the current file 0061 */ 0062 void slotSnippetClicked(const QModelIndex &index); 0063 0064 /** 0065 * Open the edit dialog for the selected snippet 0066 */ 0067 void slotEditSnippet(); 0068 0069 /** 0070 * Removes the selected snippet from the tree and the filesystem 0071 */ 0072 void slotRemoveSnippet(); 0073 0074 /** 0075 * Creates a new snippet and open the edit dialog for it 0076 */ 0077 void slotAddSnippet(); 0078 0079 void contextMenu(const QPoint &pos); 0080 /// disables or enables available actions based on the currently selected item 0081 void validateActions(); 0082 0083 /// insert snippet on double click 0084 bool eventFilter(QObject *, QEvent *) override; 0085 0086 private: 0087 QStandardItem *currentItem(); 0088 0089 KateSnippetGlobal *m_plugin; 0090 QSortFilterProxyModel *m_proxy; 0091 0092 QAction *m_addRepoAction; 0093 QAction *m_removeRepoAction; 0094 QAction *m_editRepoAction; 0095 QAction *m_addSnippetAction; 0096 QAction *m_removeSnippetAction; 0097 QAction *m_editSnippetAction; 0098 KNSWidgets::Action *m_getNewStuffAction; 0099 };