KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Utility method to convert all 3D buttons to Toolbar type buttons in project database
PRODUCT: 4D | VERSION: 19 | PLATFORM: Mac & Win
Published On: October 4, 2021

When converting a database to project mode, you may notice that all highlight buttons will be automatically converted to 3D buttons. Since 3D buttons do not show any visual indication of mouse hover or clicking, you can use this utility method to convert all 3D buttons to Toolbar type buttons to show this visual highlight.

// Method: __automateButtonProperties
// Description
// Method that will convert all 3D buttons to Toolbar type buttons
//
// Parameters
// $1 - Path of the project mode conversion log file
// ----------------------------------------------------

C_TEXT($1;$path_t)
C_TEXT($json_t)
C_TEXT($msg_t)
C_TEXT($sourcePath_t)
C_TEXT($tableFormPath_t)
C_TEXT($projFormPath_t)
C_TEXT($object_t)

C_OBJECT($json_o)
C_OBJECT($message_o)
C_OBJECT($button_o)
C_OBJECT($formDef_o)
C_OBJECT($objects_o)
C_OBJECT($toSet_o)

C_COLLECTION($messages_c)
C_COLLECTION($tableButtons_c)
C_COLLECTION($projectButtons_c)
C_COLLECTIONn>($buttons_c)

$path_t:=$1

If (Test path name($path_t)=Is a document)
   $json_t:=Document to text($path_t)
   $json_o:=JSON Parse($json_t)
   $messages_c:=$json_o.messages
  
   $tableButtons_c:=New collection
   $projectButtons_c:=New collection
   $buttons_c:=New collection
  
   $msg_t:="Highlight buttons are unsupported and converted as invisible buttons. You may consider using 3D buttons instead."
   $sourcePath_t:=Folder("/SOURCES/").platformPath
   $tableFormPath_t:=$sourcePath_t+"TableForms"+Folder separator
   $projFormPath_t:=$sourcePath_t+"Forms"+Folder separator
  
   // Find all highlight button warnings from JSON log file
   For each ($message_o;$messages_c)
     If ($message_o.message=$msg_t)
       If ($message_o.table#Null)
         $button_o:=New object
         $button_o.path:=$tableFormPath_t+String($message_o.table)+Folder separator+$message_o.form+Folder separator+"form.4DForm"
         $button_o.name:=$message_o.object
       Else
         $button_o:=New object
         $button_o.path:=$projFormPath_t+$message_o.form+Folder separator+"form.4DForm"
         $button_o.name:=$message_o.object
       End if
       $buttons_c.push($button_o)
     End if
   End for each
  
   // Go through each highlight button and change an attribute
   For each ($button_o;$buttons_c)
     If (Test path name($button_o.path)=Is a document)
       $formDef_o:=JSON Parse(Document to text($button_o.path))
       If ($formDef_o.pages#Null)
         For each ($objects_o;$formDef_o.pages)
           If ($objects_o#Null)
             If ($objects_o.objects#Null)
               For each ($object_t;$objects_o.objects)
                 If ($object_t=$button_o.name)
                   $objects_o.objects[$object_t]["style"]:="toolbar"
                   $objects_o.objects[$object_t]["events"]:=New collection("onClick")
                   $objects_o.objects[$object_t]["text"]:=""
                   $objects_o.objects[$object_t]["display"]:=True
                 End if
               End for each
             End if
           End if
         End for each
       TEXT TO DOCUMENT($button_o.path;JSON Stringify($formDef_o;*))
     End if
    End if
   End for each
  
End if

ALERT("Finished button conversion")