Jean-Baptiste Queru | b56ea2a | 2013-01-08 11:11:20 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2000-2012 JetBrains s.r.o. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package com.intellij.application.options.codeStyle.arrangement.action; |
| 17 | |
Jean-Baptiste Queru | b56ea2a | 2013-01-08 11:11:20 -0800 | [diff] [blame] | 18 | import com.intellij.application.options.codeStyle.arrangement.match.ArrangementMatchingRulesControl; |
| 19 | import com.intellij.application.options.codeStyle.arrangement.match.ArrangementMatchingRulesModel; |
| 20 | import com.intellij.icons.AllIcons; |
| 21 | import com.intellij.openapi.actionSystem.AnAction; |
| 22 | import com.intellij.openapi.actionSystem.AnActionEvent; |
| 23 | import com.intellij.openapi.application.ApplicationBundle; |
Tor Norbye | 9258464 | 2014-04-17 08:39:25 -0700 | [diff] [blame] | 24 | import com.intellij.openapi.project.DumbAware; |
Jean-Baptiste Queru | b56ea2a | 2013-01-08 11:11:20 -0800 | [diff] [blame] | 25 | import com.intellij.openapi.util.SystemInfoRt; |
| 26 | import gnu.trove.TIntArrayList; |
| 27 | |
| 28 | /** |
| 29 | * @author Denis Zhdanov |
| 30 | * @since 8/26/12 7:41 PM |
| 31 | */ |
Tor Norbye | 9258464 | 2014-04-17 08:39:25 -0700 | [diff] [blame] | 32 | public class RemoveArrangementRuleAction extends AnAction implements DumbAware { |
Jean-Baptiste Queru | b56ea2a | 2013-01-08 11:11:20 -0800 | [diff] [blame] | 33 | |
| 34 | public RemoveArrangementRuleAction() { |
| 35 | getTemplatePresentation().setText(ApplicationBundle.message("arrangement.action.rule.remove.text")); |
| 36 | getTemplatePresentation().setDescription(ApplicationBundle.message("arrangement.action.rule.remove.description")); |
| 37 | } |
| 38 | |
| 39 | @Override |
| 40 | public void update(AnActionEvent e) { |
Jean-Baptiste Queru | 2bd2b7c | 2013-04-01 14:41:51 -0700 | [diff] [blame] | 41 | ArrangementMatchingRulesControl control = ArrangementMatchingRulesControl.KEY.getData(e.getDataContext()); |
Tor Norbye | e782c57 | 2014-09-18 11:43:07 -0700 | [diff] [blame^] | 42 | e.getPresentation().setEnabled(control != null && !control.getSelectedModelRows().isEmpty() && control.getEditingRow() == -1); |
Jean-Baptiste Queru | b56ea2a | 2013-01-08 11:11:20 -0800 | [diff] [blame] | 43 | e.getPresentation().setIcon(SystemInfoRt.isMac ? AllIcons.ToolbarDecorator.Mac.Remove : AllIcons.ToolbarDecorator.Remove); |
| 44 | } |
| 45 | |
| 46 | @Override |
| 47 | public void actionPerformed(AnActionEvent e) { |
Jean-Baptiste Queru | 2bd2b7c | 2013-04-01 14:41:51 -0700 | [diff] [blame] | 48 | ArrangementMatchingRulesControl control = ArrangementMatchingRulesControl.KEY.getData(e.getDataContext()); |
Jean-Baptiste Queru | b56ea2a | 2013-01-08 11:11:20 -0800 | [diff] [blame] | 49 | if (control == null) { |
| 50 | return; |
| 51 | } |
| 52 | |
| 53 | control.hideEditor(); |
| 54 | |
| 55 | final TIntArrayList rowsToRemove = control.getSelectedModelRows(); |
| 56 | if (rowsToRemove.isEmpty()) { |
| 57 | return; |
| 58 | } |
| 59 | |
| 60 | final ArrangementMatchingRulesModel model = control.getModel(); |
| 61 | control.runOperationIgnoreSelectionChange(new Runnable() { |
| 62 | @Override |
| 63 | public void run() { |
| 64 | for (int i = 0; i < rowsToRemove.size(); i++) { |
| 65 | int row = rowsToRemove.get(i); |
| 66 | model.removeRow(row); |
| 67 | } |
| 68 | } |
| 69 | }); |
| 70 | } |
| 71 | } |