* 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:
@@ -639,12 +639,15 @@ CalcView::LoadSettings(BMessage* archive)
|
|||||||
// load display text
|
// load display text
|
||||||
const char* display;
|
const char* display;
|
||||||
if (archive->FindString("displayText", &display) < B_OK) {
|
if (archive->FindString("displayText", &display) < B_OK) {
|
||||||
puts("Missing display text from CalcView archive.\n");
|
puts("Missing expression text from CalcView archive.\n");
|
||||||
} else {
|
} else {
|
||||||
// init expression text
|
// init expression text
|
||||||
fExpressionTextView->SetText(display);
|
fExpressionTextView->SetText(display);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// load expression history
|
||||||
|
fExpressionTextView->LoadSettings(archive);
|
||||||
|
|
||||||
// parse calculator description
|
// parse calculator description
|
||||||
_ParseCalcDesc(fKeypadDescription);
|
_ParseCalcDesc(fKeypadDescription);
|
||||||
|
|
||||||
@@ -686,6 +689,10 @@ CalcView::SaveSettings(BMessage* archive) const
|
|||||||
if (ret == B_OK)
|
if (ret == B_OK)
|
||||||
ret = archive->AddString("displayText", fExpressionTextView->Text());
|
ret = archive->AddString("displayText", fExpressionTextView->Text());
|
||||||
|
|
||||||
|
// record expression history
|
||||||
|
if (ret == B_OK)
|
||||||
|
ret = fExpressionTextView->SaveSettings(archive);
|
||||||
|
|
||||||
// record calculator description
|
// record calculator description
|
||||||
if (ret == B_OK)
|
if (ret == B_OK)
|
||||||
ret = archive->AddString("calcDesc", fKeypadDescription);
|
ret = archive->AddString("calcDesc", fKeypadDescription);
|
||||||
@@ -740,7 +747,7 @@ CalcView::Evaluate()
|
|||||||
} else if (((value < EXP_SWITCH_HI) && (value > EXP_SWITCH_LO)) ||
|
} else if (((value < EXP_SWITCH_HI) && (value > EXP_SWITCH_LO)) ||
|
||||||
((value > -EXP_SWITCH_HI) && (value < -EXP_SWITCH_LO))) {
|
((value > -EXP_SWITCH_HI) && (value < -EXP_SWITCH_LO))) {
|
||||||
// print in std form
|
// print in std form
|
||||||
sprintf(buf, "%9f", value);
|
sprintf(buf, "%.13f", value);
|
||||||
|
|
||||||
// hack to remove surplus zeros!
|
// hack to remove surplus zeros!
|
||||||
if (strchr(buf, '.')) {
|
if (strchr(buf, '.')) {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#include "ExpressionTextView.h"
|
#include "ExpressionTextView.h"
|
||||||
|
|
||||||
#include <new>
|
#include <new>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#include <Beep.h>
|
#include <Beep.h>
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
@@ -72,6 +73,7 @@ ExpressionTextView::KeyDown(const char* bytes, int32 numBytes)
|
|||||||
NextExpression();
|
NextExpression();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
BString current = Text();
|
||||||
|
|
||||||
// handle in InputTextView, except B_TAB
|
// handle in InputTextView, except B_TAB
|
||||||
if (bytes[0] != 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
|
// as soon as something is typed, we are at the
|
||||||
// end of the expression history
|
// end of the expression history
|
||||||
fHistoryPos = fPreviousExpressions.CountItems();
|
if (current != Text())
|
||||||
|
fHistoryPos = fPreviousExpressions.CountItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -119,6 +122,9 @@ ExpressionTextView::ApplyChanges()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ExpressionTextView::AddKeypadLabel(const char* label)
|
ExpressionTextView::AddKeypadLabel(const char* label)
|
||||||
{
|
{
|
||||||
@@ -156,6 +162,18 @@ ExpressionTextView::Clear()
|
|||||||
void
|
void
|
||||||
ExpressionTextView::AddExpressionToHistory(const char* expression)
|
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);
|
BString* item = new (nothrow) BString(expression);
|
||||||
if (!item)
|
if (!item)
|
||||||
return;
|
return;
|
||||||
@@ -212,3 +230,33 @@ ExpressionTextView::NextExpression()
|
|||||||
SetExpression(item->String());
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -44,6 +44,9 @@ class ExpressionTextView : public InputTextView {
|
|||||||
void PreviousExpression();
|
void PreviousExpression();
|
||||||
void NextExpression();
|
void NextExpression();
|
||||||
|
|
||||||
|
void LoadSettings(const BMessage* archive);
|
||||||
|
status_t SaveSettings(BMessage* archive) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CalcView* fCalcView;
|
CalcView* fCalcView;
|
||||||
BString fKeypadLabels;
|
BString fKeypadLabels;
|
||||||
|
|||||||
@@ -95,7 +95,6 @@ InputTextView::MakeFocus(bool focus)
|
|||||||
BTextView::MakeFocus(focus);
|
BTextView::MakeFocus(focus);
|
||||||
if (focus)
|
if (focus)
|
||||||
SelectAll();
|
SelectAll();
|
||||||
ApplyChanges();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user