* fix leading spaces after evaluating

* increase to 13 digits after decimal point
* load and save the expression history


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17776 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus 2006-06-07 22:42:00 +00:00
parent 1c7004e4e7
commit d2176a2d86
4 changed files with 61 additions and 4 deletions

View File

@ -639,12 +639,15 @@ CalcView::LoadSettings(BMessage* archive)
// load display text
const char* display;
if (archive->FindString("displayText", &display) < B_OK) {
puts("Missing display text from CalcView archive.\n");
puts("Missing expression text from CalcView archive.\n");
} else {
// init expression text
fExpressionTextView->SetText(display);
}
// load expression history
fExpressionTextView->LoadSettings(archive);
// parse calculator description
_ParseCalcDesc(fKeypadDescription);
@ -686,6 +689,10 @@ CalcView::SaveSettings(BMessage* archive) const
if (ret == B_OK)
ret = archive->AddString("displayText", fExpressionTextView->Text());
// record expression history
if (ret == B_OK)
ret = fExpressionTextView->SaveSettings(archive);
// record calculator description
if (ret == B_OK)
ret = archive->AddString("calcDesc", fKeypadDescription);
@ -740,7 +747,7 @@ CalcView::Evaluate()
} else if (((value < EXP_SWITCH_HI) && (value > EXP_SWITCH_LO)) ||
((value > -EXP_SWITCH_HI) && (value < -EXP_SWITCH_LO))) {
// print in std form
sprintf(buf, "%9f", value);
sprintf(buf, "%.13f", value);
// hack to remove surplus zeros!
if (strchr(buf, '.')) {

View File

@ -9,6 +9,7 @@
#include "ExpressionTextView.h"
#include <new>
#include <stdio.h>
#include <Beep.h>
#include <Window.h>
@ -72,6 +73,7 @@ ExpressionTextView::KeyDown(const char* bytes, int32 numBytes)
NextExpression();
return;
}
BString current = Text();
// handle in InputTextView, except B_TAB
if (bytes[0] != B_TAB)
@ -83,7 +85,8 @@ ExpressionTextView::KeyDown(const char* bytes, int32 numBytes)
// as soon as something is typed, we are at the
// end of the expression history
fHistoryPos = fPreviousExpressions.CountItems();
if (current != Text())
fHistoryPos = fPreviousExpressions.CountItems();
}
@ -119,6 +122,9 @@ ExpressionTextView::ApplyChanges()
}
// #pragma mark -
void
ExpressionTextView::AddKeypadLabel(const char* label)
{
@ -156,6 +162,18 @@ ExpressionTextView::Clear()
void
ExpressionTextView::AddExpressionToHistory(const char* expression)
{
// clean out old expressions that are the same as
// the one to be added
int32 count = fPreviousExpressions.CountItems();
for (int32 i = 0; i < count; i++) {
BString* item = (BString*)fPreviousExpressions.ItemAt(i);
if (*item == expression && fPreviousExpressions.RemoveItem(i)) {
delete item;
i--;
count--;
}
}
BString* item = new (nothrow) BString(expression);
if (!item)
return;
@ -212,3 +230,33 @@ ExpressionTextView::NextExpression()
SetExpression(item->String());
}
// #pragma mark -
void
ExpressionTextView::LoadSettings(const BMessage* archive)
{
const char* oldExpression;
for (int32 i = 0;
archive->FindString("previous expression", i, &oldExpression) == B_OK;
i++) {
AddExpressionToHistory(oldExpression);
}
}
status_t
ExpressionTextView::SaveSettings(BMessage* archive) const
{
int32 count = fPreviousExpressions.CountItems();
for (int32 i = 0; i < count; i++) {
BString* item = (BString*)fPreviousExpressions.ItemAtFast(i);
status_t ret = archive->AddString("previous expression", item->String());
if (ret < B_OK)
return ret;
}
return B_OK;
}

View File

@ -44,6 +44,9 @@ class ExpressionTextView : public InputTextView {
void PreviousExpression();
void NextExpression();
void LoadSettings(const BMessage* archive);
status_t SaveSettings(BMessage* archive) const;
private:
CalcView* fCalcView;
BString fKeypadLabels;

View File

@ -95,7 +95,6 @@ InputTextView::MakeFocus(bool focus)
BTextView::MakeFocus(focus);
if (focus)
SelectAll();
ApplyChanges();
}
}