browse history action ( IDEA-21689 & Co)

This commit is contained in:
Gregory Shrago
2011-03-29 19:33:21 +04:00
parent 810074407e
commit bad7f4b217
4 changed files with 61 additions and 6 deletions
@@ -29,6 +29,7 @@ import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.CaretModel;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.actions.ContentChooser;
import com.intellij.openapi.editor.ex.EditorEx;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ex.ProjectEx;
@@ -46,6 +47,7 @@ import org.xmlpull.v1.XmlSerializer;
import java.awt.event.KeyEvent;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
/**
@@ -61,6 +63,7 @@ public class ConsoleHistoryController {
private final ConsoleHistoryModel myModel;
private final AnAction myHistoryNext = new MyAction(true);
private final AnAction myHistoryPrev = new MyAction(false);
private final AnAction myBrowseHistory = new MyBrowseAction();
private boolean myMultiline;
private long myLastSaveStamp;
@@ -110,15 +113,16 @@ public class ConsoleHistoryController {
}
private void configureActions() {
// todo add clipboard-like history viewer/selector action
EmptyAction.setupAction(myHistoryNext, "Console.History.Next", null);
EmptyAction.setupAction(myHistoryPrev, "Console.History.Previous", null);
EmptyAction.setupAction(myBrowseHistory, "Console.History.Browse", null);
if (!myMultiline) {
myHistoryNext.registerCustomShortcutSet(KeyEvent.VK_UP, 0, null);
myHistoryPrev.registerCustomShortcutSet(KeyEvent.VK_DOWN, 0, null);
}
myHistoryNext.registerCustomShortcutSet(myHistoryNext.getShortcutSet(), myConsole.getConsoleEditor().getComponent());
myHistoryPrev.registerCustomShortcutSet(myHistoryPrev.getShortcutSet(), myConsole.getConsoleEditor().getComponent());
myBrowseHistory.registerCustomShortcutSet(myBrowseHistory.getShortcutSet(), myConsole.getConsoleEditor().getComponent());
}
private File getFile() {
@@ -205,6 +209,9 @@ public class ConsoleHistoryController {
return myHistoryPrev;
}
public AnAction getBrowseHistory() {
return myBrowseHistory;
}
protected void actionTriggered(final String command) {
final Editor editor = myConsole.getConsoleEditor();
@@ -287,4 +294,37 @@ public class ConsoleHistoryController {
out.endTag(null, "console-history");
out.endDocument();
}
private class MyBrowseAction extends AnAction {
@Override
public void update(final AnActionEvent e) {
e.getPresentation().setEnabled(myModel.getHistorySize() > 0);
}
@Override
public void actionPerformed(final AnActionEvent e) {
final ContentChooser<String> chooser = new ContentChooser<String>(myConsole.getProject(), myConsole.getTitle(), true) {
@Override
protected void removeContentAt(final String content) {
myModel.removeFromHistory(content);
}
@Override
protected String getStringRepresentationFor(final String content) {
return content;
}
@Override
protected List<String> getContents() {
return myModel.getHistory();
}
};
chooser.show();
if (chooser.isOK()) {
actionTriggered(myModel.getHistory().get(chooser.getSelectedIndex()));
}
}
}
}
@@ -133,7 +133,7 @@ public abstract class ContentChooser<Data> extends DialogWrapper {
return mySplitter;
}
protected abstract void removeContentAt(final Data Content);
protected abstract void removeContentAt(final Data content);
protected String getDimensionServiceKey() {
return "#com.intellij.openapi.editor.actions.MultiplePasteAction.Chooser";
@@ -22,13 +22,21 @@ public class ConsoleHistoryModel implements ModificationTracker {
public void addToHistory(final String statement) {
synchronized (myHistory) {
myModificationTracker ++;
myHistoryCursor = -1;
myHistory.remove(statement);
removeFromHistory(statement);
if (myHistory.size() >= myMaxHistorySize) {
myHistory.removeLast();
}
myHistory.addFirst(statement);
else {
myHistory.addFirst(statement);
}
}
}
public void removeFromHistory(final String statement) {
synchronized (myHistory) {
myModificationTracker ++;
myHistoryCursor = -1;
myHistory.remove(statement);
}
}
@@ -44,6 +52,12 @@ public class ConsoleHistoryModel implements ModificationTracker {
}
}
public int getHistorySize() {
synchronized (myHistory) {
return myHistory.size();
}
}
public void setMaxHistorySize(final int maxHistorySize) {
synchronized (myHistory) {
myMaxHistorySize = maxHistorySize;
@@ -426,6 +426,7 @@
<group id="Console.HistoryActions">
<action id="Console.History.Previous" class="com.intellij.openapi.actionSystem.EmptyAction" text="Previous"/>
<action id="Console.History.Next" class="com.intellij.openapi.actionSystem.EmptyAction" text="Next"/>
<action id="Console.History.Browse" class="com.intellij.openapi.actionSystem.EmptyAction" text="Browse" use-shortcut-of="RecentFiles"/>
</group>
<group id="Internal" text="Internal Actions" internal="true" popup="true">