* don't remember empty expressions

This commit is contained in:
Reinhard Pointner 2011-12-07 05:45:51 +00:00
parent e1f76a671b
commit 49e432dd81
1 changed files with 33 additions and 25 deletions

View File

@ -31,8 +31,8 @@ import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.RunnableFuture;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.ThreadPoolExecutor.DiscardOldestPolicy;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -605,6 +605,10 @@ class FormatDialog extends JDialog {
// check syntax
format = new ExpressionFormat(editor.getText().trim());
if (format.getExpression().isEmpty()) {
throw new ScriptException("Expression is empty");
}
// create new recent history and ignore duplicates
Set<String> recent = new LinkedHashSet<String>();
@ -612,8 +616,12 @@ class FormatDialog extends JDialog {
recent.add(format.getExpression());
// add next 4 most recent formats
for (int i = 0, limit = Math.min(4, mode.persistentFormatHistory().size()); i < limit; i++) {
recent.add(mode.persistentFormatHistory().get(i));
for (String expression : mode.persistentFormatHistory()) {
recent.add(expression);
if (recent.size() >= 5) {
break;
}
}
// update persistent history