Changeset View
Changeset View
Standalone View
Standalone View
addons/close-except-like/close_except_plugin.cpp
Show First 20 Lines • Show All 103 Lines • ▼ Show 20 Line(s) | 88 | CloseExceptPluginView::CloseExceptPluginView( | |||
---|---|---|---|---|---|
104 | , m_mainWindow(mw) | 104 | , m_mainWindow(mw) | ||
105 | { | 105 | { | ||
106 | KXMLGUIClient::setComponentName (QStringLiteral("katecloseexceptplugin"), i18n("Close Except/Like Plugin")); | 106 | KXMLGUIClient::setComponentName (QStringLiteral("katecloseexceptplugin"), i18n("Close Except/Like Plugin")); | ||
107 | setXMLFile( QStringLiteral("ui.rc") ); | 107 | setXMLFile( QStringLiteral("ui.rc") ); | ||
108 | 108 | | |||
109 | actionCollection()->addAction(QStringLiteral("file_close_except"), m_except_menu); | 109 | actionCollection()->addAction(QStringLiteral("file_close_except"), m_except_menu); | ||
110 | actionCollection()->addAction(QStringLiteral("file_close_like"), m_like_menu); | 110 | actionCollection()->addAction(QStringLiteral("file_close_like"), m_like_menu); | ||
111 | 111 | | |||
112 | // Subscribe self to document creation | 112 | connect(KTextEditor::Editor::instance(), &KTextEditor::Editor::documentCreated, | ||
113 | connect( | 113 | this, &CloseExceptPluginView::documentCreated); | ||
114 | KTextEditor::Editor::instance() | | |||
115 | , SIGNAL(documentCreated(KTextEditor::Editor*, KTextEditor::Document*)) | | |||
116 | , this | | |||
117 | , SLOT(documentCreated(KTextEditor::Editor*, KTextEditor::Document*)) | | |||
118 | ); | | |||
119 | // Configure toggle action and connect it to update state | 114 | // Configure toggle action and connect it to update state | ||
120 | m_show_confirmation_action->setChecked(m_plugin->showConfirmationNeeded()); | 115 | m_show_confirmation_action->setChecked(m_plugin->showConfirmationNeeded()); | ||
121 | connect( | 116 | connect(m_show_confirmation_action, &KToggleAction::toggled, | ||
122 | m_show_confirmation_action | 117 | m_plugin, &CloseExceptPlugin::toggleShowConfirmation); | ||
123 | , SIGNAL(toggled(bool)) | | |||
124 | , m_plugin | | |||
125 | , SLOT(toggleShowConfirmation(bool)) | | |||
126 | ); | | |||
127 | // | 118 | // | ||
128 | connect( | 119 | connect(m_mainWindow, &KTextEditor::MainWindow::viewCreated, | ||
129 | m_mainWindow | 120 | this, &CloseExceptPluginView::viewCreated); | ||
130 | , SIGNAL(viewCreated(KTextEditor::View*)) | | |||
131 | , this | | |||
132 | , SLOT(viewCreated(KTextEditor::View*)) | | |||
133 | ); | | |||
134 | // Fill menu w/ currently opened document masks/groups | 121 | // Fill menu w/ currently opened document masks/groups | ||
135 | updateMenu(); | 122 | updateMenu(); | ||
136 | 123 | | |||
137 | m_mainWindow->guiFactory()->addClient(this); | 124 | m_mainWindow->guiFactory()->addClient(this); | ||
138 | } | 125 | } | ||
139 | 126 | | |||
140 | CloseExceptPluginView::~CloseExceptPluginView() | 127 | CloseExceptPluginView::~CloseExceptPluginView() | ||
141 | { | 128 | { | ||
Show All 10 Lines | |||||
152 | { | 139 | { | ||
153 | connectToDocument(document); | 140 | connectToDocument(document); | ||
154 | updateMenu(); | 141 | updateMenu(); | ||
155 | } | 142 | } | ||
156 | 143 | | |||
157 | void CloseExceptPluginView::connectToDocument(KTextEditor::Document* document) | 144 | void CloseExceptPluginView::connectToDocument(KTextEditor::Document* document) | ||
158 | { | 145 | { | ||
159 | // Subscribe self to document close and name changes | 146 | // Subscribe self to document close and name changes | ||
160 | connect( | 147 | connect(document, &KTextEditor::Document::aboutToClose, | ||
161 | document | 148 | this, &CloseExceptPluginView::updateMenuSlotStub); | ||
162 | , SIGNAL(aboutToClose(KTextEditor::Document*)) | 149 | connect(document, &KTextEditor::Document::documentNameChanged, | ||
163 | , this | 150 | this, &CloseExceptPluginView::updateMenuSlotStub); | ||
164 | , SLOT(updateMenuSlotStub(KTextEditor::Document*)) | 151 | connect(document, &KTextEditor::Document::documentUrlChanged, | ||
165 | ); | 152 | this, &CloseExceptPluginView::updateMenuSlotStub); | ||
166 | connect( | | |||
167 | document | | |||
168 | , SIGNAL(documentNameChanged(KTextEditor::Document*)) | | |||
169 | , this | | |||
170 | , SLOT(updateMenuSlotStub(KTextEditor::Document*)) | | |||
171 | ); | | |||
172 | connect( | | |||
173 | document | | |||
174 | , SIGNAL(documentUrlChanged(KTextEditor::Document*)) | | |||
175 | , this | | |||
176 | , SLOT(updateMenuSlotStub(KTextEditor::Document*)) | | |||
177 | ); | | |||
178 | } | 153 | } | ||
179 | 154 | | |||
180 | void CloseExceptPluginView::updateMenuSlotStub(KTextEditor::Document*) | 155 | void CloseExceptPluginView::updateMenuSlotStub(KTextEditor::Document*) | ||
181 | { | 156 | { | ||
182 | updateMenu(); | 157 | updateMenu(); | ||
183 | } | 158 | } | ||
184 | 159 | | |||
185 | void CloseExceptPluginView::appendActionsFrom( | 160 | void CloseExceptPluginView::appendActionsFrom( | ||
186 | const std::set<QUrl>& paths | 161 | const std::set<QUrl>& paths | ||
187 | , actions_map_type& actions | 162 | , actions_map_type& actions | ||
188 | , KActionMenu* menu | 163 | , KActionMenu* menu | ||
189 | , QSignalMapper* mapper | 164 | , QSignalMapper* mapper | ||
190 | ) | 165 | ) | ||
191 | { | 166 | { | ||
192 | Q_FOREACH(const QUrl& path, paths) | 167 | Q_FOREACH(const QUrl& path, paths) | ||
193 | { | 168 | { | ||
194 | QString action = path.path() + QLatin1Char('*'); | 169 | QString action = path.path() + QLatin1Char('*'); | ||
195 | actions[action] = QPointer<QAction>(new QAction(action, menu)); | 170 | actions[action] = QPointer<QAction>(new QAction(action, menu)); | ||
196 | menu->addAction(actions[action]); | 171 | menu->addAction(actions[action]); | ||
197 | connect(actions[action], SIGNAL(triggered()), mapper, SLOT(map())); | 172 | //connect(actions[action], &QAction::triggered, mapper, &QSignalMapper::map); | ||
173 | connect(actions[action], &QAction::triggered, | ||||
174 | mapper, static_cast<void (QSignalMapper::*)()>(&QSignalMapper::map)); | ||||
198 | mapper->setMapping(actions[action], action); | 175 | mapper->setMapping(actions[action], action); | ||
199 | } | 176 | } | ||
200 | } | 177 | } | ||
201 | 178 | | |||
202 | void CloseExceptPluginView::appendActionsFrom( | 179 | void CloseExceptPluginView::appendActionsFrom( | ||
203 | const std::set<QString>& masks | 180 | const std::set<QString>& masks | ||
204 | , actions_map_type& actions | 181 | , actions_map_type& actions | ||
205 | , KActionMenu* menu | 182 | , KActionMenu* menu | ||
206 | , QSignalMapper* mapper | 183 | , QSignalMapper* mapper | ||
207 | ) | 184 | ) | ||
208 | { | 185 | { | ||
209 | Q_FOREACH(const QString& mask, masks) | 186 | Q_FOREACH(const QString& mask, masks) | ||
210 | { | 187 | { | ||
211 | QString action = mask.startsWith(QLatin1Char('*')) ? mask : mask + QLatin1Char('*'); | 188 | QString action = mask.startsWith(QLatin1Char('*')) ? mask : mask + QLatin1Char('*'); | ||
212 | actions[action] = QPointer<QAction>(new QAction(action, menu)); | 189 | actions[action] = QPointer<QAction>(new QAction(action, menu)); | ||
213 | menu->addAction(actions[action]); | 190 | menu->addAction(actions[action]); | ||
214 | connect(actions[action], SIGNAL(triggered()), mapper, SLOT(map())); | 191 | connect(actions[action], &QAction::triggered, | ||
192 | mapper, static_cast<void (QSignalMapper::*)()>(&QSignalMapper::map)); | ||||
215 | mapper->setMapping(actions[action], action); | 193 | mapper->setMapping(actions[action], action); | ||
216 | } | 194 | } | ||
217 | } | 195 | } | ||
218 | 196 | | |||
219 | QPointer<QSignalMapper> CloseExceptPluginView::updateMenu( | 197 | QPointer<QSignalMapper> CloseExceptPluginView::updateMenu( | ||
220 | const std::set<QUrl>& paths | 198 | const std::set<QUrl>& paths | ||
221 | , const std::set<QString>& masks | 199 | , const std::set<QString>& masks | ||
222 | , actions_map_type& actions | 200 | , actions_map_type& actions | ||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Line(s) | 270 | { | |||
294 | break; | 272 | break; | ||
295 | } | 273 | } | ||
296 | } | 274 | } | ||
297 | } | 275 | } | ||
298 | qDebug() << "stage #2: Collected" << paths.size() << "paths and" << masks.size() << "masks"; | 276 | qDebug() << "stage #2: Collected" << paths.size() << "paths and" << masks.size() << "masks"; | ||
299 | // | 277 | // | ||
300 | m_except_mapper = updateMenu(paths, masks, m_except_actions, m_except_menu); | 278 | m_except_mapper = updateMenu(paths, masks, m_except_actions, m_except_menu); | ||
301 | m_like_mapper = updateMenu(paths, masks, m_like_actions, m_like_menu); | 279 | m_like_mapper = updateMenu(paths, masks, m_like_actions, m_like_menu); | ||
302 | connect(m_except_mapper, SIGNAL(mapped(const QString&)), this, SLOT(closeExcept(const QString&))); | 280 | connect(m_except_mapper, static_cast<void (QSignalMapper::*)(const QString&)>(&QSignalMapper::mapped), | ||
303 | connect(m_like_mapper, SIGNAL(mapped(const QString&)), this, SLOT(closeLike(const QString&))); | 281 | this, &CloseExceptPluginView::closeExcept); | ||
282 | connect(m_like_mapper, static_cast<void (QSignalMapper::*)(const QString&)>(&QSignalMapper::mapped), | ||||
283 | this, &CloseExceptPluginView::closeLike); | ||||
304 | } | 284 | } | ||
305 | } | 285 | } | ||
306 | 286 | | |||
307 | void CloseExceptPluginView::close(const QString& item, const bool close_if_match) | 287 | void CloseExceptPluginView::close(const QString& item, const bool close_if_match) | ||
308 | { | 288 | { | ||
309 | QChar asterisk=QLatin1Char('*'); | 289 | QChar asterisk=QLatin1Char('*'); | ||
310 | assert( | 290 | assert( | ||
311 | "Parameter seems invalid! Is smth has changed in the code?" | 291 | "Parameter seems invalid! Is smth has changed in the code?" | ||
▲ Show 20 Lines • Show All 80 Lines • Show Last 20 Lines |