[apps] Make app accessors static members of App classes

This commit is contained in:
Ruben Dashyan
2019-07-19 13:27:15 +02:00
committed by EmilieNumworks
parent 44809f4b3f
commit eb6d697927
31 changed files with 63 additions and 70 deletions

View File

@@ -27,6 +27,9 @@ public:
void tidy() override;
CalculationStore m_calculationStore;
};
static App * app() {
return static_cast<App *>(Container::activeApp());
}
bool textFieldDidReceiveEvent(::TextField * textField, Ion::Events::Event event) override;
bool layoutFieldDidReceiveEvent(::LayoutField * layoutField, Ion::Events::Event event) override;
// TextFieldDelegateApp
@@ -39,10 +42,6 @@ private:
EditExpressionController m_editExpressionController;
};
inline App * app() {
return static_cast<App *>(Container::activeApp());
}
}
#endif

View File

@@ -151,7 +151,7 @@ KDCoordinate HistoryController::rowHeight(int j) {
return 0;
}
Calculation * calculation = m_calculationStore->calculationAtIndex(j);
return calculation->height(app()->localContext(), j == selectedRow() && selectedSubviewType() == SubviewType::Output) + 4 * Metric::CommonSmallMargin;
return calculation->height(App::app()->localContext(), j == selectedRow() && selectedSubviewType() == SubviewType::Output) + 4 * Metric::CommonSmallMargin;
}
int HistoryController::typeAtLocation(int i, int j) {

View File

@@ -75,7 +75,7 @@ void HistoryViewCell::reloadScroll() {
}
void HistoryViewCell::reloadOutputSelection() {
Calculation::DisplayOutput display = m_calculation.displayOutput(app()->localContext());
Calculation::DisplayOutput display = m_calculation.displayOutput(App::app()->localContext());
/* Select the right output according to the calculation display output. This
* will reload the scroll to display the selected output. */
if (display == Calculation::DisplayOutput::ExactAndApproximate) {
@@ -136,10 +136,11 @@ void HistoryViewCell::setCalculation(Calculation * calculation, bool expanded) {
if (m_calculationExpanded == expanded && *calculation == m_calculation) {
return;
}
Poincare::Context * context = App::app()->localContext();
// Memoization
m_calculation = *calculation;
m_calculationExpanded = expanded;
Calculation::DisplayOutput display = calculation->displayOutput(app()->localContext());
Calculation::DisplayOutput display = calculation->displayOutput(context);
m_inputView.setLayout(calculation->createInputLayout());
/* Both output expressions have to be updated at the same time. Otherwise,
* when updating one layout, if the second one still points to a deleted
@@ -149,13 +150,13 @@ void HistoryViewCell::setCalculation(Calculation * calculation, bool expanded) {
if (display == Calculation::DisplayOutput::ExactOnly) {
rightOutputLayout = calculation->createExactOutputLayout();
} else {
rightOutputLayout = calculation->createApproximateOutputLayout(app()->localContext());
rightOutputLayout = calculation->createApproximateOutputLayout(context);
if (display == Calculation::DisplayOutput::ExactAndApproximate || (display == Calculation::DisplayOutput::ExactAndApproximateToggle && expanded)) {
leftOutputLayout = calculation->createExactOutputLayout();
}
}
m_scrollableOutputView.setLayouts(rightOutputLayout, leftOutputLayout);
I18n::Message equalMessage = calculation->exactAndApproximateDisplayedOutputsAreEqual(app()->localContext()) == Calculation::EqualSign::Equal ? I18n::Message::Equal : I18n::Message::AlmostEqual;
I18n::Message equalMessage = calculation->exactAndApproximateDisplayedOutputsAreEqual(context) == Calculation::EqualSign::Equal ? I18n::Message::Equal : I18n::Message::AlmostEqual;
m_scrollableOutputView.setEqualMessage(equalMessage);
/* The displayed input and outputs have changed. We need to re-layout the cell

View File

@@ -36,6 +36,9 @@ public:
#endif
ScriptStore m_scriptStore;
};
static App * app() {
return static_cast<App *>(Container::activeApp());
}
~App();
bool prepareForExit() override {
if (m_consoleController.inputRunLoopActive()) {
@@ -84,10 +87,6 @@ private:
VariableBoxController m_variableBoxController;
};
inline App * app() {
return static_cast<App *>(Container::activeApp());
}
}
#endif

View File

@@ -57,7 +57,7 @@ bool ConsoleController::loadPythonEnvironment() {
/* We load functions and variables names in the variable box before running
* any other python code to avoid failling to load functions and variables
* due to memory exhaustion. */
app()->variableBoxController()->loadFunctionsAndVariables();
App::app()->variableBoxController()->loadFunctionsAndVariables();
return true;
}
@@ -290,7 +290,7 @@ bool ConsoleController::textFieldDidReceiveEvent(TextField * textField, Ion::Eve
return true;
}
}
return app()->textInputDidReceiveEvent(textField, event);
return App::app()->textInputDidReceiveEvent(textField, event);
}
bool ConsoleController::textFieldDidFinishEditing(TextField * textField, const char * text, Ion::Events::Event event) {

View File

@@ -58,7 +58,7 @@ bool EditorController::textAreaDidReceiveEvent(TextArea * textArea, Ion::Events:
saveScript();
return false;
}
if (app()->textInputDidReceiveEvent(textArea, event)) {
if (App::app()->textInputDidReceiveEvent(textArea, event)) {
return true;
}
if (event == Ion::Events::EXE) {
@@ -109,7 +109,7 @@ bool EditorController::textAreaDidReceiveEvent(TextArea * textArea, Ion::Events:
}
VariableBoxController * EditorController::variableBoxForInputEventHandler(InputEventHandler * textInput) {
VariableBoxController * varBox = app()->variableBoxController();
VariableBoxController * varBox = App::app()->variableBoxController();
varBox->loadFunctionsAndVariables();
return varBox;
}

View File

@@ -36,7 +36,7 @@ MenuController::MenuController(Responder * parentResponder, App * pythonDelegate
}
ConsoleController * MenuController::consoleController() {
return app()->consoleController();
return App::app()->consoleController();
}
StackViewController * MenuController::stackViewController() {

View File

@@ -33,7 +33,7 @@ void VariableBoxController::didEnterResponderChain(Responder * previousFirstResp
* environment where Python has already been inited. This way, we do not
* deinit Python when leaving the VariableBoxController, so we do not lose the
* environment that was loaded when entering the VariableBoxController. */
assert(app()->pythonIsInited());
assert(App::app()->pythonIsInited());
}
static bool shouldAddObject(const char * name, int maxLength) {

View File

@@ -30,6 +30,9 @@ public:
CartesianFunctionStore m_functionStore;
Shared::InteractiveCurveViewRange m_graphRange;
};
static App * app() {
return static_cast<App *>(Container::activeApp());
}
InputViewController * inputViewController() override;
char XNT() override;
NestedMenuController * variableBoxForInputEventHandler(InputEventHandler * textInput) override;
@@ -52,10 +55,6 @@ private:
InputViewController m_inputViewController;
};
inline App * app() {
return static_cast<App *>(Container::activeApp());
}
}
#endif

View File

@@ -52,7 +52,7 @@ Expression::Coordinate2D CalculationGraphController::computeNewPointOfInteresetF
}
CartesianFunctionStore * CalculationGraphController::functionStore() const {
return app()->functionStore();
return App::app()->functionStore();
}
bool CalculationGraphController::handleLeftRightEvent(Ion::Events::Event event) {

View File

@@ -10,23 +10,23 @@ using namespace Poincare;
namespace Graph {
bool GraphControllerHelper::privateMoveCursorHorizontally(Shared::CurveViewCursor * cursor, int direction, Shared::InteractiveCurveViewRange * range, int numberOfStepsInGradUnit, Ion::Storage::Record record) {
ExpiringPointer<CartesianFunction> function = app()->functionStore()->modelForRecord(record);
ExpiringPointer<CartesianFunction> function = App::app()->functionStore()->modelForRecord(record);
double xCursorPosition = cursor->x();
double x = direction > 0 ? xCursorPosition + range->xGridUnit()/numberOfStepsInGradUnit : xCursorPosition - range->xGridUnit()/numberOfStepsInGradUnit;
double y = function->evaluateAtAbscissa(x, app()->localContext());
double y = function->evaluateAtAbscissa(x, App::app()->localContext());
cursor->moveTo(x, y);
return true;
}
void GraphControllerHelper::reloadDerivativeInBannerViewForCursorOnFunction(Shared::CurveViewCursor * cursor, Ion::Storage::Record record) {
ExpiringPointer<CartesianFunction> function = app()->functionStore()->modelForRecord(record);
ExpiringPointer<CartesianFunction> function = App::app()->functionStore()->modelForRecord(record);
constexpr size_t bufferSize = FunctionBannerDelegate::k_maxNumberOfCharacters+PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits);
char buffer[bufferSize];
const char * space = " ";
int numberOfChar = function->derivativeNameWithArgument(buffer, bufferSize, CartesianFunction::Symbol());
const char * legend = "=";
numberOfChar += strlcpy(buffer+numberOfChar, legend, bufferSize-numberOfChar);
double y = function->approximateDerivative(cursor->x(), app()->localContext());
double y = function->approximateDerivative(cursor->x(), App::app()->localContext());
numberOfChar += PoincareHelpers::ConvertFloatToText<double>(y, buffer + numberOfChar, bufferSize-numberOfChar, Constant::ShortNumberOfSignificantDigits);
strlcpy(buffer+numberOfChar, space, bufferSize-numberOfChar);
bannerView()->derivativeView()->setText(buffer);

View File

@@ -44,7 +44,7 @@ bool TangentGraphController::textFieldDidFinishEditing(TextField * textField, co
if (myApp->hasUndefinedValue(text, floatBody)) {
return false;
}
ExpiringPointer<CartesianFunction> function = app()->functionStore()->modelForRecord(m_record);
ExpiringPointer<CartesianFunction> function = App::app()->functionStore()->modelForRecord(m_record);
double y = function->evaluateAtAbscissa(floatBody, myApp->localContext());
m_cursor->moveTo(floatBody, y);
interactiveCurveViewRange()->panToMakePointVisible(m_cursor->x(), m_cursor->y(), cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio);
@@ -70,7 +70,7 @@ void TangentGraphController::reloadBannerView() {
const char * legend = "a=";
int legendLength = strlcpy(buffer, legend, bufferSize);
ExpiringPointer<CartesianFunction> function = app()->functionStore()->modelForRecord(m_record);
ExpiringPointer<CartesianFunction> function = App::app()->functionStore()->modelForRecord(m_record);
double y = function->approximateDerivative(m_cursor->x(), context);
PoincareHelpers::ConvertFloatToText<double>(y, buffer + legendLength, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits);
m_bannerView->aView()->setText(buffer);

View File

@@ -82,7 +82,7 @@ KDCoordinate DerivativeParameterController::cellHeight() {
}
CartesianFunctionStore * DerivativeParameterController::functionStore() {
return app()->functionStore();
return App::app()->functionStore();
}
}

View File

@@ -70,7 +70,7 @@ void FunctionParameterController::willDisplayCellForIndex(HighlightCell * cell,
}
ExpiringPointer<CartesianFunction> FunctionParameterController::function() {
return app()->functionStore()->modelForRecord(m_record);
return App::app()->functionStore()->modelForRecord(m_record);
}
}

View File

@@ -18,6 +18,9 @@ public:
App * unpack(Container * container) override;
Descriptor * descriptor() override;
};
static App * app() {
return static_cast<App *>(Container::activeApp());
}
Snapshot * snapshot() const {
return static_cast<Snapshot *>(::App::snapshot());
}
@@ -26,10 +29,6 @@ private:
Controller m_controller;
};
inline App * app() {
return static_cast<App *>(Container::activeApp());
}
}
#endif

View File

@@ -162,7 +162,7 @@ void Controller::tableViewDidChangeSelection(SelectableTableView * t, int previo
}
SelectableTableViewDataSource * Controller::selectionDataSource() const {
return app()->snapshot();
return App::app()->snapshot();
}
}

View File

@@ -54,6 +54,9 @@ public:
char m_calculation[k_calculationSize];
Page m_activePage;
};
static App * app() {
return static_cast<App *>(Container::activeApp());
}
Snapshot * snapshot() const { return static_cast<Snapshot *>(::App::snapshot()); }
private:
App(Snapshot * snapshot);
@@ -63,10 +66,6 @@ private:
StackViewController m_stackViewController;
};
inline App * app() {
return static_cast<App *>(Container::activeApp());
}
}
#endif

View File

@@ -79,7 +79,7 @@ CalculationController::CalculationController(Responder * parentResponder, InputE
}
void CalculationController::didEnterResponderChain(Responder * previousResponder) {
app()->snapshot()->setActivePage(App::Snapshot::Page::Calculations);
App::app()->snapshot()->setActivePage(App::Snapshot::Page::Calculations);
updateTitle();
reloadLawCurveView();
m_selectableTableView.reloadData();

View File

@@ -73,7 +73,7 @@ void Probability::LawController::viewWillAppear() {
}
void Probability::LawController::didBecomeFirstResponder() {
app()->snapshot()->setActivePage(App::Snapshot::Page::Law);
App::app()->snapshot()->setActivePage(App::Snapshot::Page::Law);
if (selectedRow() == -1) {
selectCellAtLocation(0, 0);
} else {

View File

@@ -99,7 +99,7 @@ void ParametersController::reinitCalculation() {
}
void ParametersController::didBecomeFirstResponder() {
app()->snapshot()->setActivePage(App::Snapshot::Page::Parameters);
App::app()->snapshot()->setActivePage(App::Snapshot::Page::Parameters);
FloatParameterController::didBecomeFirstResponder();
}

View File

@@ -40,6 +40,9 @@ public:
uint32_t m_rangeVersion;
int m_selectedSeriesIndex;
};
static App * app() {
return static_cast<App *>(Container::activeApp());
}
RegressionController * regressionController() { return &m_regressionController; }
private:
App(Snapshot * snapshot);
@@ -57,10 +60,6 @@ private:
RegressionController m_regressionController;
};
inline App * app() {
return static_cast<App *>(Container::activeApp());
}
}
#endif

View File

@@ -41,7 +41,7 @@ void GraphOptionsController::viewWillAppear() {
bool GraphOptionsController::handleEvent(Ion::Events::Event event) {
if (event == Ion::Events::OK || event == Ion::Events::EXE || event == Ion::Events::Right) {
if (selectedRow() == numberOfRows() -1) {
RegressionController * regressionController = app()->regressionController();
RegressionController * regressionController = App::app()->regressionController();
regressionController->setSeries(m_graphController->selectedSeriesIndex());
StackViewController * stack = static_cast<StackViewController *>(parentResponder());
stack->push(regressionController);

View File

@@ -20,7 +20,7 @@ void StoreParameterController::viewWillAppear() {
bool StoreParameterController::handleEvent(Ion::Events::Event event) {
if ((event == Ion::Events::OK || event == Ion::Events::EXE || event == Ion::Events::Right) && selectedRow() == numberOfRows() - 1) {
RegressionController * regressionController = app()->regressionController();
RegressionController * regressionController = App::app()->regressionController();
regressionController->setSeries(m_series);
StackViewController * stack = static_cast<StackViewController *>(parentResponder());
stack->push(regressionController);

View File

@@ -33,6 +33,9 @@ public:
SequenceStore m_sequenceStore;
CurveViewRange m_graphRange;
};
static App * app() {
return static_cast<App *>(Container::activeApp());
}
InputViewController * inputViewController() override;
// TODO: override variableBoxForInputEventHandler to lock sequence in the variable box once they appear there
// NestedMenuController * variableBoxForInputEventHandler(InputEventHandler * textInput) override;
@@ -58,10 +61,6 @@ private:
InputViewController m_inputViewController;
};
inline App * app() {
return static_cast<App *>(Container::activeApp());
}
}
#endif

View File

@@ -109,7 +109,7 @@ void ListController::editExpression(int sequenceDefinition, Ion::Events::Event e
}
InputViewController * inputController = Shared::FunctionApp::app()->inputViewController();
// Invalidate the sequences context cache
app()->localContext()->resetCache();
App::app()->localContext()->resetCache();
switch (sequenceDefinition) {
case 0:
inputController->edit(this, event, this, initialText,
@@ -267,7 +267,7 @@ void ListController::editExpression(Ion::Events::Event event) {
void ListController::reinitSelectedExpression(ExpiringPointer<ExpressionModelHandle> model) {
// Invalidate the sequences context cache
app()->localContext()->resetCache();
App::app()->localContext()->resetCache();
Sequence * sequence = static_cast<Sequence *>(model.pointer());
switch (sequenceDefinitionForRow(selectedRow())) {
case 1:
@@ -295,7 +295,7 @@ void ListController::reinitSelectedExpression(ExpiringPointer<ExpressionModelHan
bool ListController::removeModelRow(Ion::Storage::Record record) {
Shared::FunctionListController::removeModelRow(record);
// Invalidate the sequences context cache
app()->localContext()->resetCache();
App::app()->localContext()->resetCache();
return true;
}

View File

@@ -56,7 +56,7 @@ bool ListParameterController::handleEvent(Ion::Events::Event event) {
#else
if (selectedRowIndex == 2+hasAdditionalRow) {
#endif
app()->localContext()->resetCache();
App::app()->localContext()->resetCache();
return handleEnterOnRow(selectedRowIndex-hasAdditionalRow-1);
}
}
@@ -82,7 +82,7 @@ bool ListParameterController::textFieldDidFinishEditing(TextField * textField, c
}
sequence()->setInitialRank(index);
// Invalidate sequence context cache when changing sequence type
app()->localContext()->resetCache();
App::app()->localContext()->resetCache();
m_selectableTableView.reloadCellAtLocation(0, selectedRow());
m_selectableTableView.handleEvent(event);
return true;

View File

@@ -60,7 +60,7 @@ bool TypeParameterController::handleEvent(Ion::Events::Event event) {
m_listController->selectPreviousNewSequenceCell();
sequence()->setType(sequenceType);
// Invalidate sequence context cache when changing sequence type
app()->localContext()->resetCache();
App::app()->localContext()->resetCache();
// Reset the first index if the new type is "Explicit"
if (sequenceType == Sequence::Type::Explicit) {
sequence()->setInitialRank(0);
@@ -135,7 +135,7 @@ void TypeParameterController::setRecord(Ion::Storage::Record record) {
}
SequenceStore * TypeParameterController::sequenceStore() {
return app()->functionStore();
return App::app()->functionStore();
}
StackViewController * TypeParameterController::stackController() const {

View File

@@ -29,6 +29,9 @@ public:
void tidy() override;
EquationStore m_equationStore;
};
static App * app() {
return static_cast<App *>(Container::activeApp());
}
InputViewController * inputViewController() { return &m_inputViewController; }
ViewController * solutionsControllerStack() { return &m_alternateEmptyViewController; }
ViewController * intervalController() { return &m_intervalController; }
@@ -45,10 +48,6 @@ private:
InputViewController m_inputViewController;
};
inline App * app() {
return static_cast<App *>(Container::activeApp());
}
}
#endif

View File

@@ -104,7 +104,7 @@ bool IntervalController::textFieldDidFinishEditing(TextField * textField, const
void IntervalController::buttonAction() {
StackViewController * stack = stackController();
m_equationStore->approximateSolve(textFieldDelegateApp()->localContext());
stack->push(app()->solutionsControllerStack(), KDColorWhite, Palette::SubTab, Palette::SubTab);
stack->push(App::app()->solutionsControllerStack(), KDColorWhite, Palette::SubTab, Palette::SubTab);
}
}

View File

@@ -192,14 +192,14 @@ void ListController::resolveEquations() {
case EquationStore::Error::RequireApproximateSolution:
{
StackViewController * stack = stackController();
stack->push(app()->intervalController(), KDColorWhite, Palette::PurpleBright, Palette::PurpleBright);
stack->push(App::app()->intervalController(), KDColorWhite, Palette::PurpleBright, Palette::PurpleBright);
return;
}
default:
{
assert(e == EquationStore::Error::NoError);
StackViewController * stack = stackController();
stack->push(app()->solutionsControllerStack(), KDColorWhite, Palette::PurpleBright, Palette::PurpleBright);
stack->push(App::app()->solutionsControllerStack(), KDColorWhite, Palette::PurpleBright, Palette::PurpleBright);
}
}
}
@@ -233,7 +233,7 @@ StackViewController * ListController::stackController() const {
}
InputViewController * ListController::inputController() {
return app()->inputViewController();
return App::app()->inputViewController();
}
}

View File

@@ -108,7 +108,7 @@ void SolutionsController::viewWillAppear() {
bool requireWarning = false;
if (m_equationStore->type() == EquationStore::Type::Monovariable) {
m_contentView.setWarningMessages(I18n::Message::OnlyFirstSolutionsDisplayed0, I18n::Message::OnlyFirstSolutionsDisplayed1);
requireWarning = m_equationStore->haveMoreApproximationSolutions(app()->localContext());
requireWarning = m_equationStore->haveMoreApproximationSolutions(App::app()->localContext());
} else if (m_equationStore->type() == EquationStore::Type::PolynomialMonovariable && m_equationStore->numberOfSolutions() == 1) {
assert(Preferences::sharedPreferences()->complexFormat() == Preferences::ComplexFormat::Real);
m_contentView.setWarningMessages(I18n::Message::PolynomeHasNoRealSolution0, I18n::Message::PolynomeHasNoRealSolution1);