From 19d2cb7cc0ab2e20ffcf591457c7601319d447fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Tue, 23 Oct 2018 14:44:56 +0200 Subject: [PATCH] [apps] Add parentheses when selecting a function in VarBoxController --- apps/variable_box_controller.cpp | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/apps/variable_box_controller.cpp b/apps/variable_box_controller.cpp index 61eae5507..904cee784 100644 --- a/apps/variable_box_controller.cpp +++ b/apps/variable_box_controller.cpp @@ -157,12 +157,31 @@ bool VariableBoxController::selectLeaf(int selectedRow) { /* We do not want to handle OK/EXE events in that case. */ return false; } + + // Deselect the table assert(selectedRow >= 0 && selectedRow < numberOfRows()); m_selectableTableView.deselectTable(); + + // Get the name text to insert Storage::Record record = recordAtIndex(selectedRow); - char truncatedName[SymbolAbstract::k_maxNameSize]; - SymbolAbstract::TruncateExtension(truncatedName, record.fullName(), SymbolAbstract::k_maxNameSize); - sender()->handleEventWithText(truncatedName); + assert(Shared::StorageFunction::k_maxNameWithArgumentSize > 0); + assert(Shared::StorageFunction::k_maxNameWithArgumentSize > SymbolAbstract::k_maxNameSize); + size_t nameToHandleMaxSize = Shared::StorageFunction::k_maxNameWithArgumentSize - 1; + char nameToHandle[nameToHandleMaxSize]; + size_t nameLength = SymbolAbstract::TruncateExtension(nameToHandle, record.fullName(), nameToHandleMaxSize); + + if (m_currentPage == Page::Function) { + // Add parentheses to a function name + assert(nameLength < nameToHandleMaxSize); + nameToHandle[nameLength++] = '('; + assert(nameLength < nameToHandleMaxSize); + nameToHandle[nameLength++] = ')'; + assert(nameLength < nameToHandleMaxSize); + nameToHandle[nameLength] = 0; + } + + // Handle the text + sender()->handleEventWithText(nameToHandle); app()->dismissModalViewController(); return true; }