Han-Symbol Move to Folder

From Vectorlab
Jump to: navigation, search

Moves a symbol or symbol definition to a given folder by name. Creates the folder at root level if the name doesn't correspond to an existing folder name and is not some other object. Mind: this doesn't move symbol folders. By Orso B. Schmid

{ Orso *********************************************** }
{ moves a symbol definition to the root level OR another folder }
{ accepts a symbol instance (15) or sym definition (16), not symbol folders }
{ pass an empty string to bring a sym back to the root level }
PROCEDURE H_MoveToFolder(symDefH : HANDLE; newFolderName: STRING);
		foldH : HANDLE;
		tempFoldName : STRING;
		{ get the definition if needed }
		IF GetType(symDefH) = 15 THEN
			symDefH := GetObject(GetSDName(symDefH));
		{ this won't happen if the starting obj symDefH is not a symm or symdef }
		IF GetType(symDefH)=16 THEN BEGIN
			tempFoldName := CreateUUID; { this always creates, needed as reference }
			{ if string is empty, move to the root folder }
			{ if the folder is already in the root folder, 
			its parent is "Sym List" and we don't need to move it }
			IF ((Len(newFolderName) = 0) & (getType(GetParent(symDefH)) <> 54)) THEN
				newFolderName := tempFoldName;
			{ if the string is not empty and the folder doesn't exist, create the folder }
			{ it automatically goes in root level }
			IF (Len(newFolderName) > 0) & (getObject(newFolderName) = NIL) THEN BEGIN
			foldH := getObject(newFolderName);
			{ now this could return any object, not only a folder by name }
			{ insert the target symbol into the folder }
			IF (foldH <> NIL) & (GetType(foldH) = 92) THEN BEGIN
				InsertSymbolInFolder(foldH, symDefH);
				{ remove the temp folder, the target sym remains }
				IF newFolderName = tempFoldName THEN