mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
'fold lines like this' action
This commit is contained in:
+10
-39
@@ -16,7 +16,6 @@
|
||||
|
||||
package com.intellij.codeInspection.suspiciousNameCombination;
|
||||
|
||||
import com.intellij.CommonBundle;
|
||||
import com.intellij.codeInsight.daemon.GroupNames;
|
||||
import com.intellij.codeInsight.daemon.JavaErrorMessages;
|
||||
import com.intellij.codeInspection.InspectionsBundle;
|
||||
@@ -29,7 +28,7 @@ import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.NameUtil;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.ui.AddDeleteListPanel;
|
||||
import com.intellij.ui.AddEditDeleteListPanel;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -38,10 +37,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.ListDataEvent;
|
||||
import javax.swing.event.ListDataListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -209,23 +204,10 @@ public class SuspiciousNameCombinationInspection extends BaseLocalInspectionTool
|
||||
}
|
||||
}
|
||||
|
||||
private class MyOptionsPanel extends AddDeleteListPanel {
|
||||
private JButton myEditButton;
|
||||
private class MyOptionsPanel extends AddEditDeleteListPanel<String> {
|
||||
|
||||
public MyOptionsPanel() {
|
||||
super(InspectionsBundle.message("suspicious.name.combination.options.title"), myNameGroups);
|
||||
myEditButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
editSelectedItem();
|
||||
}
|
||||
});
|
||||
myList.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) {
|
||||
editSelectedItem();
|
||||
}
|
||||
}
|
||||
});
|
||||
myListModel.addListDataListener(new ListDataListener() {
|
||||
public void intervalAdded(ListDataEvent e) {
|
||||
saveChanges();
|
||||
@@ -241,31 +223,20 @@ public class SuspiciousNameCombinationInspection extends BaseLocalInspectionTool
|
||||
});
|
||||
}
|
||||
|
||||
@Override protected JButton[] createButtons() {
|
||||
myEditButton = new JButton(CommonBundle.message("button.edit"));
|
||||
return new JButton[] { myAddButton, myEditButton, myDeleteButton };
|
||||
}
|
||||
|
||||
protected Object findItemToAdd() {
|
||||
protected String findItemToAdd() {
|
||||
return Messages.showInputDialog(this,
|
||||
InspectionsBundle.message("suspicious.name.combination.options.prompt"),
|
||||
InspectionsBundle.message("suspicious.name.combination.add.titile"),
|
||||
Messages.getQuestionIcon(), "", null);
|
||||
}
|
||||
|
||||
private void editSelectedItem() {
|
||||
int index = myList.getSelectedIndex();
|
||||
if (index >= 0) {
|
||||
String inputValue = (String) myListModel.get(index);
|
||||
String newValue = Messages.showInputDialog(this,
|
||||
InspectionsBundle.message("suspicious.name.combination.options.prompt"),
|
||||
InspectionsBundle.message("suspicious.name.combination.edit.title"),
|
||||
Messages.getQuestionIcon(),
|
||||
inputValue, null);
|
||||
if (newValue != null) {
|
||||
myListModel.set(index, newValue);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected String editSelectedItem(String inputValue) {
|
||||
return Messages.showInputDialog(this,
|
||||
InspectionsBundle.message("suspicious.name.combination.options.prompt"),
|
||||
InspectionsBundle.message("suspicious.name.combination.edit.title"),
|
||||
Messages.getQuestionIcon(),
|
||||
inputValue, null);
|
||||
}
|
||||
|
||||
private void saveChanges() {
|
||||
|
||||
+26
-12
@@ -4,8 +4,9 @@ import com.intellij.openapi.options.ConfigurationException;
|
||||
import com.intellij.openapi.options.SearchableConfigurable;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.ui.VerticalFlowLayout;
|
||||
import com.intellij.ui.AddDeleteListPanel;
|
||||
import com.intellij.ui.AddEditDeleteListPanel;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -20,11 +21,7 @@ public class ConsoleFoldingConfigurable implements SearchableConfigurable {
|
||||
private JPanel myMainComponent;
|
||||
private MyAddDeleteListPanel myPositivePanel;
|
||||
private MyAddDeleteListPanel myNegativePanel;
|
||||
private final ConsoleFoldingSettings mySettings;
|
||||
|
||||
public ConsoleFoldingConfigurable(ConsoleFoldingSettings settings) {
|
||||
mySettings = settings;
|
||||
}
|
||||
private final ConsoleFoldingSettings mySettings = ConsoleFoldingSettings.getSettings();
|
||||
|
||||
public JComponent createComponent() {
|
||||
if (myMainComponent == null) {
|
||||
@@ -37,6 +34,10 @@ public class ConsoleFoldingConfigurable implements SearchableConfigurable {
|
||||
return myMainComponent;
|
||||
}
|
||||
|
||||
public void addRule(@NotNull String rule) {
|
||||
myPositivePanel.addRule(rule);
|
||||
}
|
||||
|
||||
public boolean isModified() {
|
||||
return !Arrays.asList(myNegativePanel.getListItems()).equals(mySettings.getNegativePatterns()) ||
|
||||
!Arrays.asList(myPositivePanel.getListItems()).equals(mySettings.getPositivePatterns());
|
||||
@@ -59,6 +60,7 @@ public class ConsoleFoldingConfigurable implements SearchableConfigurable {
|
||||
myPositivePanel = null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getId() {
|
||||
return getDisplayName();
|
||||
}
|
||||
@@ -80,20 +82,23 @@ public class ConsoleFoldingConfigurable implements SearchableConfigurable {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static class MyAddDeleteListPanel extends AddDeleteListPanel {
|
||||
private static class MyAddDeleteListPanel extends AddEditDeleteListPanel<String> {
|
||||
private final String myQuery;
|
||||
|
||||
public MyAddDeleteListPanel(String title, String query) {
|
||||
super(title, new ArrayList());
|
||||
super(title, new ArrayList<String>());
|
||||
myQuery = query;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
protected Object findItemToAdd() {
|
||||
return Messages.showInputDialog(this, myQuery,
|
||||
"Folding pattern",
|
||||
Messages.getQuestionIcon(), "", null);
|
||||
protected String findItemToAdd() {
|
||||
return showEditDialog("");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private String showEditDialog(final String initialValue) {
|
||||
return Messages.showInputDialog(this, myQuery, "Folding pattern", Messages.getQuestionIcon(), initialValue, null);
|
||||
}
|
||||
|
||||
void resetFrom(List<String> patterns) {
|
||||
@@ -109,5 +114,14 @@ public class ConsoleFoldingConfigurable implements SearchableConfigurable {
|
||||
patterns.add((String)o);
|
||||
}
|
||||
}
|
||||
|
||||
public void addRule(String rule) {
|
||||
addElement(rule);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String editSelectedItem(String item) {
|
||||
return showEditDialog(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.intellij.execution.console;
|
||||
|
||||
import com.intellij.openapi.components.PersistentStateComponent;
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.components.State;
|
||||
import com.intellij.openapi.components.Storage;
|
||||
import com.intellij.util.containers.CollectionFactory;
|
||||
@@ -24,6 +25,10 @@ public class ConsoleFoldingSettings implements PersistentStateComponent<ConsoleF
|
||||
}
|
||||
}
|
||||
|
||||
public static ConsoleFoldingSettings getSettings() {
|
||||
return ServiceManager.getService(ConsoleFoldingSettings.class);
|
||||
}
|
||||
|
||||
public boolean shouldFoldLine(String line) {
|
||||
return containsAny(line, myPositivePatterns) && !containsAny(line, myNegativePatterns);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
package com.intellij.execution.console;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ModalityState;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.SelectionModel;
|
||||
import com.intellij.openapi.options.ShowSettingsUtil;
|
||||
import com.intellij.openapi.project.DumbAwareAction;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
public class FoldLinesWithSubstring extends DumbAwareAction {
|
||||
private final Editor myEditor;
|
||||
|
||||
public FoldLinesWithSubstring(Editor editor) {
|
||||
super("Fold lines like this");
|
||||
myEditor = editor;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private String getSingleLineSelection() {
|
||||
final SelectionModel model = myEditor.getSelectionModel();
|
||||
final Document document = myEditor.getDocument();
|
||||
if (!model.hasSelection()) {
|
||||
final int offset = myEditor.getCaretModel().getOffset();
|
||||
if (offset <= document.getTextLength()) {
|
||||
final int lineNumber = document.getLineNumber(offset);
|
||||
final String line = document.getText().substring(document.getLineStartOffset(lineNumber), document.getLineEndOffset(lineNumber)).trim();
|
||||
if (StringUtil.isNotEmpty(line)) {
|
||||
return line;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
final int start = model.getSelectionStart();
|
||||
final int end = model.getSelectionEnd();
|
||||
if (document.getLineNumber(start) == document.getLineNumber(end)) {
|
||||
final String selection = document.getText().substring(start, end).trim();
|
||||
if (StringUtil.isNotEmpty(selection)) {
|
||||
return selection;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(AnActionEvent e) {
|
||||
final boolean enabled = getSingleLineSelection() != null;
|
||||
e.getPresentation().setEnabled(enabled);
|
||||
e.getPresentation().setVisible(enabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
final String selection = getSingleLineSelection();
|
||||
assert selection != null;
|
||||
ShowSettingsUtil.getInstance().editConfigurable(myEditor.getProject(), new ConsoleFoldingConfigurable() {
|
||||
@Override
|
||||
public void reset() {
|
||||
super.reset();
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
addRule(selection);
|
||||
}
|
||||
}, ModalityState.stateForComponent(createComponent()));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ package com.intellij.execution.impl;
|
||||
import com.intellij.codeInsight.navigation.IncrementalSearchHandler;
|
||||
import com.intellij.execution.ConsoleFolding;
|
||||
import com.intellij.execution.ExecutionBundle;
|
||||
import com.intellij.execution.console.FoldLinesWithSubstring;
|
||||
import com.intellij.execution.filters.*;
|
||||
import com.intellij.execution.process.ProcessHandler;
|
||||
import com.intellij.execution.ui.ConsoleView;
|
||||
@@ -762,6 +763,7 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo
|
||||
final DefaultActionGroup group = new DefaultActionGroup();
|
||||
group.add(new ClearAllAction());
|
||||
group.add(new CopyAction());
|
||||
group.add(new FoldLinesWithSubstring(myEditor));
|
||||
group.addSeparator();
|
||||
final ActionManager actionManager = ActionManager.getInstance();
|
||||
group.add(actionManager.getAction(DiffActions.COMPARE_WITH_CLIPBOARD));
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.intellij.ui;
|
||||
|
||||
import com.intellij.CommonBundle;
|
||||
import com.intellij.ui.components.JBList;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
@@ -33,7 +34,7 @@ import java.util.List;
|
||||
* @author anna
|
||||
* @since 5.1
|
||||
*/
|
||||
public abstract class AddDeleteListPanel extends PanelWithButtons {
|
||||
public abstract class AddDeleteListPanel<T> extends PanelWithButtons {
|
||||
private final String myTitle;
|
||||
protected JButton myAddButton = new JButton(CommonBundle.message("button.add"));
|
||||
protected JButton myDeleteButton = new JButton(CommonBundle.message("button.delete"));
|
||||
@@ -41,7 +42,7 @@ public abstract class AddDeleteListPanel extends PanelWithButtons {
|
||||
protected JList myList = new JBList(myListModel);
|
||||
|
||||
public AddDeleteListPanel(final String title,
|
||||
final List initialList) {
|
||||
final List<T> initialList) {
|
||||
myTitle = title;
|
||||
for (Object o : initialList) {
|
||||
if (o != null) {
|
||||
@@ -56,11 +57,7 @@ public abstract class AddDeleteListPanel extends PanelWithButtons {
|
||||
});
|
||||
myAddButton.addActionListener(new ActionListener(){
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
final Object itemToAdd = findItemToAdd();
|
||||
if (itemToAdd != null){
|
||||
myListModel.addElement(itemToAdd);
|
||||
myList.setSelectedValue(itemToAdd, true);
|
||||
}
|
||||
addElement(findItemToAdd());
|
||||
}
|
||||
});
|
||||
myDeleteButton.addActionListener(new ActionListener() {
|
||||
@@ -71,7 +68,15 @@ public abstract class AddDeleteListPanel extends PanelWithButtons {
|
||||
initPanel();
|
||||
}
|
||||
|
||||
protected abstract Object findItemToAdd();
|
||||
protected void addElement(@Nullable T itemToAdd) {
|
||||
if (itemToAdd != null){
|
||||
myListModel.addElement(itemToAdd);
|
||||
myList.setSelectedValue(itemToAdd, true);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected abstract T findItemToAdd();
|
||||
|
||||
public Object [] getListItems(){
|
||||
List<Object> items = new ArrayList<Object>();
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.intellij.ui;
|
||||
|
||||
import com.intellij.CommonBundle;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
public abstract class AddEditDeleteListPanel<T> extends AddDeleteListPanel<T> {
|
||||
private JButton myEditButton;
|
||||
|
||||
public AddEditDeleteListPanel(final String title, final List<T> initialList) {
|
||||
super(title, initialList);
|
||||
myEditButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
editSelectedItem();
|
||||
}
|
||||
});
|
||||
myList.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) {
|
||||
editSelectedItem();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override protected JButton[] createButtons() {
|
||||
myEditButton = new JButton(CommonBundle.message("button.edit"));
|
||||
return new JButton[] { myAddButton, myEditButton, myDeleteButton };
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected abstract T editSelectedItem(T item);
|
||||
|
||||
private void editSelectedItem() {
|
||||
int index = myList.getSelectedIndex();
|
||||
if (index >= 0) {
|
||||
T newValue = editSelectedItem((T) myListModel.get(index));
|
||||
if (newValue != null) {
|
||||
myListModel.set(index, newValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user