@@ -1179,7 +1179,6 @@ SCP_string VariableDialogModel::copyContainer(int index)
1179
1179
}
1180
1180
1181
1181
_containerItems.back ().name = newName;
1182
- _containerItems.back ().name = _containerItems.back ().name .substr (0 , TOKEN_LENGTH - 1 );
1183
1182
return _containerItems.back ().name ;
1184
1183
}
1185
1184
@@ -1193,6 +1192,7 @@ SCP_string VariableDialogModel::changeContainerName(int index, SCP_string newNam
1193
1192
}
1194
1193
1195
1194
// We cannot have two containers with the same name, but we need to check that somewhere else (like on accept attempt).
1195
+ // Otherwise editing variables and containers becomes super annoying.
1196
1196
container->name = newName.substr (0 , TOKEN_LENGTH - 1 );
1197
1197
return container->name ;
1198
1198
}
@@ -1258,7 +1258,7 @@ SCP_string VariableDialogModel::addListItem(int index, SCP_string item)
1258
1258
}
1259
1259
1260
1260
if (container->string ) {
1261
- container->stringValues .push_back (item);
1261
+ container->stringValues .push_back (item. substr ( 0 , TOKEN_LENGTH - 1 ) );
1262
1262
return container->stringValues .back ();
1263
1263
} else {
1264
1264
auto temp = trimIntegerString (item);
@@ -1332,6 +1332,7 @@ std::pair<SCP_string, SCP_string> VariableDialogModel::addMapItem(int index)
1332
1332
return ret;
1333
1333
}
1334
1334
1335
+ // Overload for specified key and/or Value
1335
1336
std::pair<SCP_string, SCP_string> VariableDialogModel::addMapItem (int index, SCP_string key, SCP_string value)
1336
1337
{
1337
1338
auto container = lookupContainer (index );
@@ -1368,7 +1369,7 @@ std::pair<SCP_string, SCP_string> VariableDialogModel::addMapItem(int index, SCP
1368
1369
} while (conflict && count < 101 );
1369
1370
} else {
1370
1371
if (container->stringKeys ){
1371
- newKey = key;
1372
+ newKey = key. substr ( 0 , TOKEN_LENGTH - 1 ) ;
1372
1373
} else {
1373
1374
newKey = trimIntegerString (key);
1374
1375
}
@@ -1382,7 +1383,7 @@ std::pair<SCP_string, SCP_string> VariableDialogModel::addMapItem(int index, SCP
1382
1383
container->keys .push_back (ret.first );
1383
1384
1384
1385
if (container->string ) {
1385
- ret.second = value;
1386
+ ret.second = value. substr ( 0 , TOKEN_LENGTH - 1 ) ;
1386
1387
container->stringValues .push_back (ret.second );
1387
1388
container->numberValues .push_back (0 );
1388
1389
} else {
@@ -1436,7 +1437,7 @@ SCP_string VariableDialogModel::changeListItem(int containerIndex, int index, SC
1436
1437
return " " ;
1437
1438
}
1438
1439
1439
- *listItem = newString;
1440
+ *listItem = newString. substr ( 0 , TOKEN_LENGTH - 1 ) ;
1440
1441
1441
1442
} else {
1442
1443
auto listItem = lookupContainerNumberItem (containerIndex, index );
@@ -1500,7 +1501,7 @@ std::pair<SCP_string, SCP_string> VariableDialogModel::copyMapItem(int index, in
1500
1501
1501
1502
auto key = lookupContainerKey (index , mapIndex);
1502
1503
1503
- if (! key) {
1504
+ if (key == nullptr ) {
1504
1505
return std::make_pair (" " , " " );
1505
1506
}
1506
1507
@@ -1509,13 +1510,14 @@ std::pair<SCP_string, SCP_string> VariableDialogModel::copyMapItem(int index, in
1509
1510
if (container->string ){
1510
1511
auto value = lookupContainerStringItem (index , mapIndex);
1511
1512
1512
- // no valid value.
1513
- if (! value){
1513
+ // not a valid value.
1514
+ if (value == nullptr ){
1514
1515
return std::make_pair (" " , " " );
1515
1516
}
1516
1517
1517
1518
SCP_string copyValue = *value;
1518
- SCP_string newKey = *key + " 0" ;
1519
+ SCP_string baseNewKey = key->substr (0 , TOKEN_LENGTH - 4 );
1520
+ SCP_string newKey = baseNewKey + " 0" ;
1519
1521
int count = 0 ;
1520
1522
1521
1523
bool found;
@@ -1531,10 +1533,10 @@ std::pair<SCP_string, SCP_string> VariableDialogModel::copyMapItem(int index, in
1531
1533
1532
1534
// attempt did not work, try next number
1533
1535
if (found) {
1534
- sprintf (newKey, " %s%i" , key-> c_str (), ++count);
1536
+ sprintf (newKey, " %s%i" , baseNewKey. c_str (), ++count);
1535
1537
}
1536
1538
1537
- } while (found && count < 100 );
1539
+ } while (found && count < 999 );
1538
1540
1539
1541
// we could not generate a new key .... somehow.
1540
1542
if (found){
@@ -1557,7 +1559,8 @@ std::pair<SCP_string, SCP_string> VariableDialogModel::copyMapItem(int index, in
1557
1559
}
1558
1560
1559
1561
int copyValue = *value;
1560
- SCP_string newKey = *key + " 0" ;
1562
+ SCP_string baseNewKey = key->substr (0 , TOKEN_LENGTH - 4 );
1563
+ SCP_string newKey = baseNewKey + " 0" ;
1561
1564
int count = 0 ;
1562
1565
1563
1566
bool found;
@@ -1573,7 +1576,7 @@ std::pair<SCP_string, SCP_string> VariableDialogModel::copyMapItem(int index, in
1573
1576
1574
1577
// attempt did not work, try next number
1575
1578
if (found) {
1576
- sprintf (newKey, " %s%i" , key-> c_str (), ++count);
1579
+ sprintf (newKey, " %s%i" , baseNewKey. c_str (), ++count);
1577
1580
}
1578
1581
1579
1582
} while (found && count < 100 );
@@ -1706,7 +1709,7 @@ SCP_string VariableDialogModel::changeMapItemKey(int index, int keyRow, SCP_stri
1706
1709
}
1707
1710
1708
1711
if (container->stringKeys ){
1709
- container->keys [keyRow] = newKey;
1712
+ container->keys [keyRow] = newKey. substr ( 0 , TOKEN_LENGTH - 1 ) ;
1710
1713
} else {
1711
1714
container->keys [keyRow] = trimIntegerString (newKey);
1712
1715
}
@@ -1723,7 +1726,7 @@ SCP_string VariableDialogModel::changeMapItemStringValue(int index, int itemInde
1723
1726
return " " ;
1724
1727
}
1725
1728
1726
- *item = newValue;
1729
+ *item = newValue. substr ( 0 , TKEN_LENGTH - 1 ) ;
1727
1730
1728
1731
return *item;
1729
1732
}
@@ -1936,13 +1939,15 @@ const SCP_vector<std::array<SCP_string, 3>> VariableDialogModel::getVariableValu
1936
1939
if (!safeToAlterVariable (item)){
1937
1940
notes = " Referenced" ;
1938
1941
} else if (item.deleted ){
1939
- notes = " Deleted" ;
1942
+ notes = " To Be Deleted" ;
1940
1943
} else if (item.originalName == " " ){
1941
1944
notes = " New" ;
1942
- } else if (item.name != item.originalName ){
1943
- notes = " Renamed" ;
1944
1945
} else if ((item.string && item.stringValue == " " ) || (!item.string && item.numberValue == 0 )){
1945
1946
notes = " Default Value" ;
1947
+ } else if (item.name != item.originalName ){
1948
+ notes = " Renamed" ;
1949
+ } else {
1950
+ notes = " Unreferenced" ;
1946
1951
}
1947
1952
1948
1953
SCP_string temp;
@@ -2091,7 +2096,7 @@ const SCP_vector<std::array<SCP_string, 3>> VariableDialogModel::getContainerNam
2091
2096
if (!safeToAlterContainer (item)){
2092
2097
notes = " Referenced" ;
2093
2098
} else if (item.deleted ) {
2094
- notes = " Deleted" ;
2099
+ notes = " To Be Deleted" ;
2095
2100
} else if (item.originalName == " " ) {
2096
2101
notes = " New" ;
2097
2102
} else if (item.name != item.originalName ){
@@ -2100,6 +2105,8 @@ const SCP_vector<std::array<SCP_string, 3>> VariableDialogModel::getContainerNam
2100
2105
notes = " Empty Map" ;
2101
2106
} else if (item.list && ((item.string && item.stringValues .empty ()) || (!item.string && item.numberValues .empty ()))){
2102
2107
notes = " Empty List" ;
2108
+ } else {
2109
+ notes = " Unreferenced" ;
2103
2110
}
2104
2111
2105
2112
outStrings.push_back (std::array<SCP_string, 3 >{item.name , type, notes});
0 commit comments