mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[shared] Factorize code between ExpressionFieldDelegateApp and
TextFieldDelegateApp
This commit is contained in:
@@ -22,7 +22,7 @@ char ExpressionFieldDelegateApp::privateXNT(LayoutField * layoutField) {
|
||||
}
|
||||
|
||||
bool ExpressionFieldDelegateApp::layoutFieldShouldFinishEditing(LayoutField * layoutField, Ion::Events::Event event) {
|
||||
return event == Ion::Events::OK || event == Ion::Events::EXE;
|
||||
return isFinishingEvent(event);
|
||||
}
|
||||
|
||||
bool ExpressionFieldDelegateApp::layoutFieldDidReceiveEvent(LayoutField * layoutField, Ion::Events::Event event) {
|
||||
@@ -34,32 +34,22 @@ bool ExpressionFieldDelegateApp::layoutFieldDidReceiveEvent(LayoutField * layout
|
||||
char buffer[TextField::maxBufferSize()];
|
||||
int bufferSize = TextField::maxBufferSize();
|
||||
int length = layoutField->serialize(buffer, bufferSize);
|
||||
Expression exp = Expression::parse(buffer);
|
||||
if (length >= bufferSize-1) {
|
||||
/* If the buffer is totally full, it is VERY likely that writeTextInBuffer
|
||||
* escaped before printing utterly the expression. */
|
||||
displayWarning(I18n::Message::SyntaxError);
|
||||
return true;
|
||||
}
|
||||
if (exp.isUninitialized()) {
|
||||
layoutField->app()->displayWarning(I18n::Message::SyntaxError);
|
||||
if (unparsableText(buffer, layoutField)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (event == Ion::Events::Var) {
|
||||
if (!layoutField->isEditing()) {
|
||||
layoutField->setEditing(true);
|
||||
}
|
||||
AppsContainer * appsContainer = (AppsContainer *)layoutField->app()->container();
|
||||
VariableBoxController * variableBoxController = appsContainer->variableBoxController();
|
||||
variableBoxController->setSender(layoutField);
|
||||
layoutField->app()->displayModalViewController(variableBoxController, 0.f, 0.f, Metric::PopUpTopMargin, Metric::PopUpLeftMargin, 0, Metric::PopUpRightMargin);
|
||||
return true;
|
||||
forceEdition(layoutField);
|
||||
return displayVariableBoxController(layoutField);
|
||||
}
|
||||
if (event == Ion::Events::XNT) {
|
||||
if (!layoutField->isEditing()) {
|
||||
layoutField->setEditing(true);
|
||||
}
|
||||
forceEdition(layoutField);
|
||||
const char xnt[2] = {privateXNT(layoutField), 0};
|
||||
return layoutField->handleEventWithText(xnt);
|
||||
}
|
||||
@@ -72,4 +62,12 @@ Toolbox * ExpressionFieldDelegateApp::toolboxForLayoutField(LayoutField * layout
|
||||
return toolbox;
|
||||
}
|
||||
|
||||
/* Private */
|
||||
|
||||
void ExpressionFieldDelegateApp::forceEdition(LayoutField * layoutField) {
|
||||
if (!layoutField->isEditing()) {
|
||||
layoutField->setEditing(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user