@@ -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}
0 commit comments