Tech Tip: Utility method to change all forms' color scheme in project mode
PRODUCT: 4D | VERSION: 19 | PLATFORM: Mac & Win
Published On: May 16, 2022
Provided below is a utility method to quickly change all project and table forms' color scheme to "inherited", "light", or "dark" based on first argument.
// Method: applyColorSchemeToAllForms // Description // Applies a color scheme to all forms // // Parameters // $1 - Use "inherited", "light", or "dark" // // Example // applyColorSchemeToAllForms("light") // ---------------------------------------------------- C_TEXT($1; $colorScheme_t) C_TEXT($sourcePath_t) C_TEXT($form_t) C_OBJECT($formJSON_o) ARRAY LONGINT($table_al; 0) ARRAY TEXT($table_at; 0) ARRAY TEXT($forms_at; 0) ARRAY TEXT($tableForms_at; 0) C_COLLECTION($formPaths_c) If (Count parameters>0) $colorScheme_t:=$1 If ($colorScheme_t="inherited") | ($colorScheme_t="light") | ($colorScheme_t="dark") $sourcePath_t:=Get 4D folder(Database folder)+"Project"+Folder separator+"Sources"+Folder separator // Get all table names and numbers GET TABLE TITLES($table_at; $table_al) $formPaths_c:=New collection // Push all project form paths to collection FORM GET NAMES($forms_at) For ($i; 1; Size of array($forms_at)) $formPaths_c.push($sourcePath_t+"Forms"+Folder separator+$forms_at{$i}+Folder separator+"form.4DForm") End for // Push all table form paths to collection For ($i; 1; Size of array($table_al)) FORM GET NAMES(Table($table_al{$i})->; $tableForms_at) For ($j; 1; Size of array($tableForms_at)) $formPaths_c.push($sourcePath_t+"TableForms"+Folder separator+String($table_al{$i})+Folder separator+$tableForms_at{$j}+Folder separator+"form.4DForm") End for End for // For each form path in the collection For each ($form_t; $formPaths_c) If (Test path name($form_t)=Is a document) $formJSON_o:=JSON Parse(Document to text($form_t)) $formJSON_o.colorScheme:=$colorScheme_t TEXT TO DOCUMENT($form_t; JSON Stringify($formJSON_o; *)) End if End for each ALERT("All forms changed to "+$colorScheme_t+" mode.") Else ALERT("'"+$colorScheme_t+"'"+" is not a valid color scheme. Please use 'inherited', 'light', or 'dark'") End if End if |