blob: 5fbcdccd38e97c19384eb21410812cb16d2730f3 [file] [log] [blame]
Jean-Baptiste Querub56ea2a2013-01-08 11:11:20 -08001/*
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 */
16package com.intellij.application.options.codeStyle.arrangement.action;
17
Jean-Baptiste Querub56ea2a2013-01-08 11:11:20 -080018import com.intellij.application.options.codeStyle.arrangement.match.ArrangementMatchingRulesControl;
19import com.intellij.application.options.codeStyle.arrangement.match.ArrangementMatchingRulesModel;
20import com.intellij.icons.AllIcons;
21import com.intellij.openapi.actionSystem.AnAction;
22import com.intellij.openapi.actionSystem.AnActionEvent;
23import com.intellij.openapi.application.ApplicationBundle;
Tor Norbye92584642014-04-17 08:39:25 -070024import com.intellij.openapi.project.DumbAware;
Jean-Baptiste Querub56ea2a2013-01-08 11:11:20 -080025import com.intellij.openapi.util.SystemInfoRt;
26import gnu.trove.TIntArrayList;
27
28/**
29 * @author Denis Zhdanov
30 * @since 8/26/12 7:41 PM
31 */
Tor Norbye92584642014-04-17 08:39:25 -070032public class RemoveArrangementRuleAction extends AnAction implements DumbAware {
Jean-Baptiste Querub56ea2a2013-01-08 11:11:20 -080033
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 Queru2bd2b7c2013-04-01 14:41:51 -070041 ArrangementMatchingRulesControl control = ArrangementMatchingRulesControl.KEY.getData(e.getDataContext());
Tor Norbyee782c572014-09-18 11:43:07 -070042 e.getPresentation().setEnabled(control != null && !control.getSelectedModelRows().isEmpty() && control.getEditingRow() == -1);
Jean-Baptiste Querub56ea2a2013-01-08 11:11:20 -080043 e.getPresentation().setIcon(SystemInfoRt.isMac ? AllIcons.ToolbarDecorator.Mac.Remove : AllIcons.ToolbarDecorator.Remove);
44 }
45
46 @Override
47 public void actionPerformed(AnActionEvent e) {
Jean-Baptiste Queru2bd2b7c2013-04-01 14:41:51 -070048 ArrangementMatchingRulesControl control = ArrangementMatchingRulesControl.KEY.getData(e.getDataContext());
Jean-Baptiste Querub56ea2a2013-01-08 11:11:20 -080049 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}