Skip to content

Commit bf66512

Browse files
jhandleyJosh Handley
authored andcommitted
Add prefix command to dictionary blender
1 parent c13e09f commit bf66512

File tree

3 files changed

+82
-2
lines changed

3 files changed

+82
-2
lines changed

Dictionary Blender/MainForm.cs

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ private void InitializeFunctions()
3333
_functions.Add("FLATTEN",new BlenderFunction(ProcessFlatten,1,2));
3434
_functions.Add("RUN",new BlenderFunction(ProcessRun,1));
3535
_functions.Add("UNSUBITEMIZE",new BlenderFunction(ProcessUnsubitemize,1));
36-
_functions.Add("UNCHECKBOXIZE",new BlenderFunction(ProcessUncheckboxize,1));
36+
_functions.Add("UNCHECKBOXIZE", new BlenderFunction(ProcessUncheckboxize, 1));
37+
_functions.Add("PREFIX_NAMES", new BlenderFunction(ProcessPrefixNames, 2));
3738
}
3839

3940
public MainForm()
@@ -795,6 +796,73 @@ private void ProcessUncheckboxize(string[] commands)
795796
SetOutputSuccess(String.Format(Messages.UncheckboxizedSuccess,item.Name,numCheckboxes));
796797
}
797798

799+
// PREFIX_NAMES -- symbol prefix
800+
private void ProcessPrefixNames(string[] commands)
801+
{
802+
DataDictionaryObject symbol = GetSymbolFromName(commands[1], SymbolTypes.AllSupported);
803+
DataDictionary dictionary = GetDataDictionaryFromSymbol(symbol);
804+
805+
// Only supports dictionaries for now
806+
if (symbol != dictionary) {
807+
throw new Exception(String.Format(Messages.SymbolNotAllowedType, symbol.Name));
808+
}
809+
810+
string prefix = commands[2];
811+
812+
string oldName = symbol.Name;
813+
string newName = prefix + symbol.Name;
814+
815+
CheckIfValidNewName(dictionary, newName);
816+
817+
dictionary.Levels.ForEach(l => PrefixLevel(dictionary, prefix, l));
818+
819+
// a couple things if changing the name of a dictionary
820+
if (symbol == dictionary)
821+
{
822+
_dictionaries.Remove(dictionary.Name);
823+
_dictionarySymbols.Remove(dictionary.Name);
824+
825+
_dictionaries.Add(newName, dictionary);
826+
}
827+
828+
// change the name
829+
symbol.Name = newName;
830+
831+
LoadDictionarySymbols(dictionary);
832+
RefreshSymbolParents();
833+
834+
SetOutputSuccess(String.Format(Messages.PrefixSuccess, oldName, prefix));
835+
}
836+
837+
private void PrefixDictObjectName(DataDictionary dict, string prefix, DataDictionaryObject ddo)
838+
{
839+
string oldName = ddo.Name;
840+
string newName = prefix + ddo.Name;
841+
842+
CheckIfValidNewName(dict, newName);
843+
844+
// change the name
845+
ddo.Name = newName;
846+
}
847+
848+
private void PrefixLevel(DataDictionary dict, string prefix, Level l)
849+
{
850+
PrefixDictObjectName(dict, prefix, l);
851+
l.IDs.Items.ForEach(i => PrefixItem(dict, prefix, i));
852+
l.Records.ForEach(r => PrefixRecord(dict, prefix, r));
853+
}
854+
855+
private void PrefixRecord(DataDictionary dict, string prefix, Record r)
856+
{
857+
PrefixDictObjectName(dict, prefix, r);
858+
r.Items.ForEach(i => PrefixItem(dict, prefix, i));
859+
}
860+
861+
private void PrefixItem(DataDictionary dict, string prefix, Item i)
862+
{
863+
PrefixDictObjectName(dict, prefix, i);
864+
i.ValueSets.ForEach(vs => PrefixDictObjectName(dict, prefix, vs));
865+
}
798866

799867
}
800868
}

Dictionary Blender/Messages.Designer.cs

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Dictionary Blender/Messages.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,4 +246,7 @@
246246
<data name="UnsubitemizeNameInvalid" xml:space="preserve">
247247
<value>Unsubitemizing {0} could not occur because the needed name {1} was not available</value>
248248
</data>
249+
<data name="PrefixSuccess" xml:space="preserve">
250+
<value>{0} prefixed with {1}</value>
251+
</data>
249252
</root>

0 commit comments

Comments
 (0)