private void textEntrySubmittedHandler(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { string contents = textBox1.Text; textBox1.Text = ""; if (contents.Trim().Equals("")) { return; } history.Push(contents); DisplayEntry dmEntry = new DisplayEntry(DisplayType.CALCULATION, contents); addDisplayEntry(dmEntry); CalculatorMessage cm = calc.evalulate(contents); DisplayEntry dm = new DisplayEntry((cm.getStatus() == Status.SUCCESS) ? DisplayType.RESULT : DisplayType.ERROR, cm.getBody()); addDisplayEntry(dm); while (reverseHistory.Count != 0) { history.Push(reverseHistory.Pop()); } } else if (e.KeyCode == Keys.Up) { // Revert to history if (history.Count > 0) { reverseHistory.Push(textBox1.Text); textBox1.Text = history.Pop(); } } else if (e.KeyCode == Keys.Down) { if (!textBox1.Text.Trim().Equals("") && reverseHistory.Count > 0) { string contents = textBox1.Text; textBox1.Text = reverseHistory.Pop(); history.Push(contents); } } }
private void addDisplayEntry(DisplayEntry entry) { writeHTMLToWebBrowser(entry.getHTML()); }