|
From: SVN by r. <sv...@ca...> - 2009-08-03 07:46:28
|
Author: roy
Date: 2009-08-03 09:46:11 +0200 (Mon, 03 Aug 2009)
New Revision: 413
Modified:
src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java
src/main/java/nl/improved/sqlclient/history/HistoryPersister.java
Log:
rewrote history
Modified: src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java
===================================================================
--- src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2009-08-02 15:24:51 UTC (rev 412)
+++ src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2009-08-03 07:46:11 UTC (rev 413)
@@ -60,7 +60,7 @@
import nl.improved.sqlclient.history.HistoryPersister;
import nl.improved.sqlclient.history.exception.CouldNotLoadHistoryException;
import nl.improved.sqlclient.history.exception.CouldNotSaveHistoryException;
-import nl.improved.sqlclient.util.Function;
+//import nl.improved.sqlclient.util.Function;
import nl.improved.sqlclient.util.LimitedArrayList;
//import nl.improved.sqlclient.util.oracle.Functions;
import org.w3c.dom.Document;
@@ -659,7 +659,7 @@
* Handle key input.
* @param inp the character that is being pressed by the user.
*/
- protected void handleInput(InputKey inp) {
+ protected synchronized void handleInput(InputKey inp) {
try {
if (!inp.isSpecialKey() || (inp.getSpecialKeyValue() != InputKey.SpecialKey.PAGE_UP && inp.getSpecialKeyValue() != InputKey.SpecialKey.PAGE_DOWN)) {
screen.setPageUpCount(0); // some character entered, so reset pageup count
@@ -690,7 +690,7 @@
SQLCommand newSqlCommand = commandHistory.get(cIndex);
String commandString = newSqlCommand.getCommandString();
if (commandString.matches(matchPattern)) {
- commandHistory.remove(commandIndex);
+ commandHistory.remove(commandLines);
commandIndex = commandHistory.indexOf(newSqlCommand);
commandLines = newSqlCommand;
Point cursorPosition = screen.getCursorPosition();
@@ -703,24 +703,10 @@
beep(); // TODO clear search??
return;
} else if (executeCommand(sqlCommand)) {
- // clear command history
- if (commandIndex != commandHistory.size()-1) {
- SQLCommand tmpLines = commandLines;
- commandLines = commandHistory.get(commandHistory.size()-1);
- if (commandLines.getCommandString().equals("")) {
- commandHistory.add(commandHistory.size()-1, tmpLines);
- } else {
- commandHistory.add(tmpLines);
- commandLines = tmpLines;
- }
- commandHistory.remove(commandIndex);
- }
- if (!commandLines.getCommandString().equals("")) {
- commandLines = new SQLCommand();
- commandHistory.add(commandLines);
- newLine();
- }
+ commandLines = new SQLCommand();
+ commandHistory.add(commandLines);
commandIndex = commandHistory.size()-1;
+ newLine();
Point cursorPosition = screen.getCursorPosition();
cursorPosition.y = commandLines.getLines().size()-1;
cursorPosition.x = commandLines.getLines().get(cursorPosition.y).length();
@@ -816,20 +802,16 @@
* @return the editable version of the commandlines.
*/
protected SQLCommand getEditableCommand() {
- if (commandHistory.indexOf(commandLines) != commandHistory.size()-1) {
- List<? extends CharSequence> tmp = commandLines.getLines();
- if (commandHistory.get(commandHistory.size()-1).getLines().size() == 1
- && commandHistory.get(commandHistory.size()-1).getLines().get(0).length() == 0) {
- commandLines = commandHistory.get(commandHistory.size()-1);
- commandLines.getEditableLines().remove(0);
- } else {
- commandLines = new SQLCommand();
- commandHistory.add(commandLines);
+ if (commandIndex != commandHistory.size() -1) {
+ SQLCommand current = commandLines;
+ commandLines = new SQLCommand();
+ commandLines.getEditableLines().clear();
+ for (StringBuffer buf : current.getEditableLines()) {
+ commandLines.getEditableLines().add(new StringBuffer(buf));
}
- for (int i = 0; i < tmp.size(); i++) {
- commandLines.getEditableLines().add(new StringBuffer(tmp.get(i)));
- }
- commandIndex = commandHistory.size()-1;
+ commandHistory.add(commandLines);
+ commandIndex = commandHistory.size() -1;
+
}
return commandLines;
}
Modified: src/main/java/nl/improved/sqlclient/history/HistoryPersister.java
===================================================================
--- src/main/java/nl/improved/sqlclient/history/HistoryPersister.java 2009-08-02 15:24:51 UTC (rev 412)
+++ src/main/java/nl/improved/sqlclient/history/HistoryPersister.java 2009-08-03 07:46:11 UTC (rev 413)
@@ -88,7 +88,7 @@
return tot;
} catch (IOException e) {
history.add(EMPTY_COMMAND);
- shell.setCommandIndex(0);
+ //shell.setCommandIndex(0);
throw new CouldNotLoadHistoryException(e);
}
}
|
|
From: SVN by r. <sv...@ca...> - 2009-09-26 13:29:54
|
Author: roy
Date: 2009-09-26 15:29:39 +0200 (Sat, 26 Sep 2009)
New Revision: 423
Modified:
src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java
src/main/java/nl/improved/sqlclient/history/HistoryPersister.java
Log:
clean up code for history
some more history fixes
Modified: src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java
===================================================================
--- src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2009-09-26 12:51:06 UTC (rev 422)
+++ src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2009-09-26 13:29:39 UTC (rev 423)
@@ -69,10 +69,6 @@
*/
private List<SQLCommand> commandHistory = new LimitedArrayList<SQLCommand>(50);
/**
- * Index for browsing commands.
- */
- private int commandIndex = 0;
- /**
* Some debug info holding the last trace of an exception.
*/
private String lastExceptionDetails;
@@ -192,8 +188,8 @@
specialActionKeys.put(InputKey.SpecialKey.UP, new KeyAction() {
@Override
public void execute() {
- if (commandIndex > 0) {
- commandLines = commandHistory.get(--commandIndex);
+ if (commandHistory.indexOf(commandLines) > 0) {
+ commandLines = commandHistory.get(commandHistory.indexOf(commandLines)-1);
Point cursorPosition = screen.getCursorPosition();
cursorPosition.y = commandLines.getLines().size()-1;
CharSequence lineBuffer = commandLines.getLines().get(cursorPosition.y);
@@ -208,8 +204,8 @@
specialActionKeys.put(InputKey.SpecialKey.DOWN, new KeyAction() {
@Override
public void execute() {
- if (commandIndex < commandHistory.size()-1) {
- commandLines = commandHistory.get(++commandIndex);
+ if (commandHistory.indexOf(commandLines) < commandHistory.size()-1) {
+ commandLines = commandHistory.get(commandHistory.indexOf(commandLines)+1);
Point cursorPosition = screen.getCursorPosition();
cursorPosition.y = commandLines.getLines().size()-1;
CharSequence lineBuffer = commandLines.getLines().get(cursorPosition.y);
@@ -480,18 +476,6 @@
return commandHistory;
}
- public int getCommandIndex() {
- return commandIndex;
- }
-
- /**
- * Change the current command index.
- * @param i
- */
- public void setCommandIndex(int i) {
- this.commandIndex = i;
- }
-
public abstract void show();
/**
@@ -662,14 +646,13 @@
if (command.length() > 0 && command.charAt(0) == '/') { // search in history
String matchPattern=".*"+command.substring(1,command.length())+".*";
for (int cIndex = commandHistory.size()-1; cIndex >=0; cIndex--) {
- if (cIndex == commandIndex) {
+ if (cIndex == commandHistory.indexOf(commandLines)) {
continue; // skip current command
}
SQLCommand newSqlCommand = commandHistory.get(cIndex);
String commandString = newSqlCommand.getCommandString();
if (commandString.matches(matchPattern)) {
commandHistory.remove(commandLines);
- commandIndex = commandHistory.indexOf(newSqlCommand);
commandLines = newSqlCommand;
Point cursorPosition = screen.getCursorPosition();
cursorPosition.y = 0;
@@ -681,9 +664,12 @@
beep(); // TODO clear search??
return;
} else if (executeCommand(sqlCommand)) {
+ if (commandHistory.indexOf(sqlCommand) < commandHistory.size()-1) {
+ commandHistory.remove(sqlCommand);
+ commandHistory.add(sqlCommand);
+ }
commandLines = new SQLCommand();
commandHistory.add(commandLines);
- commandIndex = commandHistory.size()-1;
newLine();
Point cursorPosition = screen.getCursorPosition();
cursorPosition.y = commandLines.getLines().size()-1;
@@ -721,6 +707,9 @@
} else {
Point cursorPosition = screen.getCursorPosition();
List<StringBuffer> editableLines = getEditableCommand().getEditableLines();
+ if (editableLines.size() < cursorPosition.y) {
+ editableLines.add(new StringBuffer());
+ }
StringBuffer currentLine = editableLines.get(cursorPosition.y);
if (cursorPosition.x > currentLine.length()) {
for (int i = currentLine.length(); i < cursorPosition.x; i++) {
@@ -780,16 +769,19 @@
* @return the editable version of the commandlines.
*/
protected SQLCommand getEditableCommand() {
- if (commandIndex != commandHistory.size() -1) {
+ if (commandHistory.indexOf(commandLines) != commandHistory.size() -1) {
SQLCommand current = commandLines;
commandLines = new SQLCommand();
commandLines.getEditableLines().clear();
for (StringBuffer buf : current.getEditableLines()) {
commandLines.getEditableLines().add(new StringBuffer(buf));
}
+ SQLCommand last = commandHistory.get(commandHistory.size()-1);
+ // clean up empty last
+ if (last.getLines().size() == 1 && last.getLines().get(0).length() == 0) {
+ commandHistory.remove(last);
+ }
commandHistory.add(commandLines);
- commandIndex = commandHistory.size() -1;
-
}
return commandLines;
}
Modified: src/main/java/nl/improved/sqlclient/history/HistoryPersister.java
===================================================================
--- src/main/java/nl/improved/sqlclient/history/HistoryPersister.java 2009-09-26 12:51:06 UTC (rev 422)
+++ src/main/java/nl/improved/sqlclient/history/HistoryPersister.java 2009-09-26 13:29:39 UTC (rev 423)
@@ -27,7 +27,6 @@
import nl.improved.sqlclient.AbstractSQLShellWindow;
import nl.improved.sqlclient.SQLCommand;
-import nl.improved.sqlclient.SQLShell;
import nl.improved.sqlclient.history.exception.CouldNotLoadHistoryException;
import nl.improved.sqlclient.history.exception.CouldNotSaveHistoryException;
@@ -84,7 +83,7 @@
}
log("ok 2");
r.close();
- shell.setCommandIndex(history.size() - 1);
+ //shell.setCommandIndex(history.size() - 1);
return tot;
} catch (IOException e) {
history.add(EMPTY_COMMAND);
@@ -102,7 +101,6 @@
public static void saveHistory(final AbstractSQLShellWindow shell, final String key,
final boolean excludeLastCommand) throws CouldNotSaveHistoryException {
List<SQLCommand> history = shell.getCommandHistory();
- int commandIndex = shell.getCommandIndex();
log("saving history... (" + history.size() + " commands)");
|