mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[apps/graph] Destroy variable record with same name when renaming func
This commit is contained in:
@@ -54,6 +54,9 @@ bool StorageListController::textFieldDidFinishEditing(TextField * textField, con
|
||||
strlcpy(baseName, text, textLength - argumentLength + 1);
|
||||
}
|
||||
|
||||
// Delete any variable with the same name
|
||||
GlobalContext::DestroyRecordsBaseNamedWithoutExtension(baseName, GlobalContext::funcExtension /*TODO store elsewhere?*/);
|
||||
|
||||
// Set the name
|
||||
Ion::Storage::Record::ErrorStatus error = StorageFunction::BaseNameCompliant(baseName) ? modelStore()->recordAtIndex(m_selectableTableView.selectedRow()).setBaseNameWithExtension(baseName, GlobalContext::funcExtension /*TODO store elsewhere?*/) : Ion::Storage::Record::ErrorStatus::NonCompliantName;
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace Shared {
|
||||
constexpr char GlobalContext::expExtension[];
|
||||
constexpr char GlobalContext::funcExtension[];
|
||||
//constexpr char GlobalContext::seqExtension[];
|
||||
constexpr const char * GlobalContext::k_extensions[];
|
||||
|
||||
bool GlobalContext::SymbolAbstractNameIsFree(const char * baseName) {
|
||||
return SymbolAbstractRecordWithBaseName(baseName).isNull();
|
||||
@@ -51,6 +52,14 @@ Poincare::Expression GlobalContext::ExpressionFromFunctionRecord(Ion::Storage::R
|
||||
return f.expressionWithSymbol();
|
||||
}
|
||||
|
||||
void GlobalContext::DestroyRecordsBaseNamedWithoutExtension(const char * baseName, const char * extension) {
|
||||
for (int i = 0; i < k_numberOfExtensions; i++) {
|
||||
if (strcmp(k_extensions[i], extension) != 0) {
|
||||
Ion::Storage::sharedStorage()->destroyRecordWithBaseNameAndExtension(baseName, k_extensions[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const Expression GlobalContext::expressionForSymbol(const SymbolAbstract & symbol) {
|
||||
Ion::Storage::Record r = SymbolAbstractRecordWithBaseName(symbol.name());
|
||||
return ExpressionForSymbolAndRecord(symbol, r);
|
||||
|
||||
@@ -15,8 +15,10 @@ class Integer;
|
||||
|
||||
class GlobalContext final : public Poincare::Context {
|
||||
public:
|
||||
static constexpr char funcExtension[] = "func"; // TODO: store this elsewhere?
|
||||
static constexpr int k_numberOfExtensions = 2;
|
||||
static constexpr char expExtension[] = "exp"; // TODO: store this elsewhere?
|
||||
static constexpr char funcExtension[] = "func"; // TODO: store this elsewhere?
|
||||
static constexpr const char * k_extensions[] = {expExtension, funcExtension};
|
||||
//static constexpr char seqExtension[] = "seq";
|
||||
|
||||
// Storage information
|
||||
@@ -30,6 +32,9 @@ public:
|
||||
// Set expression for record
|
||||
static Ion::Storage::Record::ErrorStatus SetExpressionForFunctionRecord(Poincare::Expression e, Ion::Storage::Record record, const char * baseName);
|
||||
|
||||
// Destroy records
|
||||
static void DestroyRecordsBaseNamedWithoutExtension(const char * baseName, const char * extension);
|
||||
|
||||
/* Expression for symbol
|
||||
* The expression recorded in global context is already an expression.
|
||||
* Otherwise, we would need the context and the angle unit to evaluate it */
|
||||
|
||||
@@ -98,6 +98,7 @@ public:
|
||||
Record recordBaseNamedWithExtensions(const char * baseName, const char * extension[], size_t numberOfExtensions);
|
||||
|
||||
// Record destruction
|
||||
void destroyRecordWithBaseNameAndExtension(const char * baseName, const char * extension);
|
||||
void destroyRecordsWithExtension(const char * extension);
|
||||
|
||||
private:
|
||||
|
||||
@@ -216,6 +216,10 @@ Storage::Record Storage::recordBaseNamedWithExtensions(const char * baseName, co
|
||||
return Record();
|
||||
}
|
||||
|
||||
void Storage::destroyRecordWithBaseNameAndExtension(const char * baseName, const char * extension) {
|
||||
recordBaseNamedWithExtension(baseName, extension).destroy();
|
||||
}
|
||||
|
||||
void Storage::destroyRecordsWithExtension(const char * extension) {
|
||||
size_t extensionLength = strlen(extension);
|
||||
char * currentRecordStart = (char *)m_buffer;
|
||||
|
||||
Reference in New Issue
Block a user