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); } } |