diff --git a/apps/math_toolbox.cpp b/apps/math_toolbox.cpp index b0e319531..c9e4ae3ec 100644 --- a/apps/math_toolbox.cpp +++ b/apps/math_toolbox.cpp @@ -8,10 +8,29 @@ * and the text which would be edited by clicking on the row. When the node is a * subtree, the edited text is set at I18n::Message::Default. */ +const int pointedLayoutPathIntegral[] = {2, 0}; +const int pointedLayoutPathSum[] = {2}; const ToolboxMessageTree calculChildren[4] = { ToolboxMessageTree(I18n::Message::DiffCommandWithArg, I18n::Message::DerivateNumber, I18n::Message::DiffCommandWithArg, nullptr, 0), - ToolboxMessageTree(I18n::Message::IntCommandWithArg, I18n::Message::Integral, I18n::Message::IntCommandWithArg, nullptr, 0, new IntegralLayout(new EmptyVisibleLayout(), new EmptyVisibleLayout, new HorizontalLayout(const_cast(Poincare::ExpressionLayout::ExpressionLayoutArray2(new EmptyVisibleLayout(), new StringLayout("dx",2))), 2, false), false)), - ToolboxMessageTree(I18n::Message::SumCommandWithArg, I18n::Message::Sum, I18n::Message::SumCommandWithArg), + ToolboxMessageTree(I18n::Message::IntCommandWithArg, I18n::Message::Integral, I18n::Message::IntCommandWithArg, nullptr, 0, + new IntegralLayout( + new EmptyVisibleLayout(), + new EmptyVisibleLayout(), + new HorizontalLayout(const_cast(Poincare::ExpressionLayout::ExpressionLayoutArray2( + new EmptyVisibleLayout(), + new StringLayout("dx",2))), 2, false), false), + const_cast(&pointedLayoutPathIntegral[0]), + 2), + ToolboxMessageTree(I18n::Message::SumCommandWithArg, I18n::Message::Sum, I18n::Message::SumCommandWithArg, nullptr, 0, + new SumLayout( + new HorizontalLayout(const_cast(Poincare::ExpressionLayout::ExpressionLayoutArray2( + new StringLayout("n=",2), + new EmptyVisibleLayout())), 2, false), + new EmptyVisibleLayout(), + new EmptyVisibleLayout(), + false), + const_cast(&pointedLayoutPathSum[0]), + 1), ToolboxMessageTree(I18n::Message::ProductCommandWithArg, I18n::Message::Product, I18n::Message::ProductCommandWithArg)}; const ToolboxMessageTree complexChildren[5] = { @@ -129,7 +148,11 @@ bool MathToolbox::selectLeaf(ToolboxMessageTree * selectedMessageTree) { // Deal with ExpressionEditor::Controller for now. m_selectableTableView.deselectTable(); ExpressionLayout * newLayout = selectedMessageTree->layout()->clone(); - expressionEditorControllerSender()->insertLayoutAtCursor(newLayout, newLayout->editableChild(2)->editableChild(0)); + ExpressionLayout * pointedLayout = newLayout; + for (int i = 0; i < selectedMessageTree->pointedPathLength(); i++) { + pointedLayout = pointedLayout->editableChild(selectedMessageTree->pointedPath()[i]); + } + expressionEditorControllerSender()->insertLayoutAtCursor(newLayout, pointedLayout); app()->dismissModalViewController(); return true; } diff --git a/escher/include/escher/toolbox_message_tree.h b/escher/include/escher/toolbox_message_tree.h index aebf25db4..253ce36ce 100644 --- a/escher/include/escher/toolbox_message_tree.h +++ b/escher/include/escher/toolbox_message_tree.h @@ -6,23 +6,29 @@ class ToolboxMessageTree : public MessageTree { public: - constexpr ToolboxMessageTree(I18n::Message label = (I18n::Message)0, I18n::Message text = (I18n::Message)0, I18n::Message insertedText = (I18n::Message)0, const ToolboxMessageTree * children = nullptr, int numberOfChildren = 0, Poincare::ExpressionLayout * layout = nullptr) : + constexpr ToolboxMessageTree(I18n::Message label = (I18n::Message)0, I18n::Message text = (I18n::Message)0, I18n::Message insertedText = (I18n::Message)0, const ToolboxMessageTree * children = nullptr, int numberOfChildren = 0, Poincare::ExpressionLayout * layout = nullptr, int * pointedLayoutPath = nullptr, int pointedLayoutPathLength = 0) : MessageTree(label, numberOfChildren), m_children(children), m_text(text), m_insertedText(insertedText), - m_layout(layout) + m_layout(layout), + m_pointedLayoutPath(pointedLayoutPath), + m_pointedLayoutPathLength(pointedLayoutPathLength) { }; const MessageTree * children(int index) const override; I18n::Message text() const; I18n::Message insertedText() const; Poincare::ExpressionLayout * layout() const { return m_layout; } + int * pointedPath() const { return m_pointedLayoutPath; } + int pointedPathLength() const { return m_pointedLayoutPathLength; } private: const ToolboxMessageTree * m_children; I18n::Message m_text; I18n::Message m_insertedText; Poincare::ExpressionLayout * m_layout; + int * m_pointedLayoutPath; + int m_pointedLayoutPathLength; }; #endif