1/**
2 * \file
3 *
4 * \brief Declate Kate's Close Except/Like plugin classes
5 *
6 * Copyright (C) 2012 Alex Turbov <i.zaufi@gmail.com>
7 *
8 * \date Thu Mar 8 08:13:43 MSK 2012 -- Initial design
9 */
10/*
11 * KateCloseExceptPlugin is free software: you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * KateCloseExceptPlugin is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 * See the GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along
22 * with this program. If not, see <http://www.gnu.org/licenses/>.
23 */
24
25#ifndef __SRC__CLOSE_EXCEPT_PLUGIN_H__
26# define __SRC__CLOSE_EXCEPT_PLUGIN_H__
27
28// Project specific includes
29
30// Standard includes
31# include <kate/plugin.h>
32# include <kate/pluginconfigpageinterface.h>
33# include <KActionMenu>
34# include <KTextEditor/Document>
35# include <KTextEditor/View>
36# include <KToggleAction>
37# include <QtCore/QSignalMapper>
38# include <cassert>
39# include <set>
40
41namespace kate {
42class CloseExceptPlugin; // forward declaration
43
44/**
45 * \brief Plugin to close docs grouped by extension or location
46 */
47class CloseExceptPluginView
48 : public Kate::PluginView
49 , public Kate::XMLGUIClient
50{
51 Q_OBJECT
52 typedef QMap<QString, QPointer<KAction> > actions_map_type;
53
54public:
55 /// Default constructor
56 CloseExceptPluginView(Kate::MainWindow*, const KComponentData&, CloseExceptPlugin*);
57 /// Destructor
58 ~CloseExceptPluginView();
59
60private Q_SLOTS:
61 void viewCreated(KTextEditor::View*);
62 void documentCreated(KTextEditor::Editor*, KTextEditor::Document*);
63 void updateMenuSlotStub(KTextEditor::Document*);
64 void close(const QString&, const bool);
65 void closeExcept(const QString& item)
66 {
67 close(item, false);
68 }
69 void closeLike(const QString& item)
70 {
71 close(item, true);
72 }
73
74private:
75 void connectToDocument(KTextEditor::Document*);
76 void updateMenu();
77 QPointer<QSignalMapper> updateMenu(
78 const std::set<QString>&
79 , const std::set<QString>&
80 , actions_map_type&
81 , KActionMenu*
82 );
83 void appendActionsFrom(
84 const std::set<QString>&
85 , actions_map_type&
86 , KActionMenu*
87 , QSignalMapper*
88 );
89
90 CloseExceptPlugin* m_plugin;
91 QPointer<KToggleAction> m_show_confirmation_action;
92 QPointer<KActionMenu> m_except_menu;
93 QPointer<KActionMenu> m_like_menu;
94 QPointer<QSignalMapper> m_except_mapper;
95 QPointer<QSignalMapper> m_like_mapper;
96 actions_map_type m_except_actions;
97 actions_map_type m_like_actions;
98};
99
100/**
101 * \brief Plugin view class
102 */
103class CloseExceptPlugin : public Kate::Plugin
104{
105 Q_OBJECT
106
107public:
108 /// Default constructor
109 CloseExceptPlugin(QObject* = 0, const QList<QVariant>& = QList<QVariant>());
110 /// Destructor
111 virtual ~CloseExceptPlugin() {}
112 /// Create a new view of this plugin for the given main window
113 Kate::PluginView* createView(Kate::MainWindow*);
114 /// \name Plugin interface implementation
115 //@{
116 void readSessionConfig(KConfigBase*, const QString&);
117 void writeSessionConfig(KConfigBase*, const QString&);
118 //@}
119 bool showConfirmationNeeded() const
120 {
121 return m_show_confirmation_needed;
122 }
123
124public Q_SLOTS:
125 void toggleShowConfirmation(bool flag)
126 {
127 m_show_confirmation_needed = flag;
128 }
129
130private:
131 bool m_show_confirmation_needed;
132};
133
134} // namespace kate
135#endif // __SRC__CLOSE_EXCEPT_PLUGIN_H__
136