Use SourceCode.inc Use cButtonDPI.pkg Activate_View Activate_oCodeIndenter_vw for oCodeIndenter_vw Object oCodeIndenter_vw is a dbView Set Size to 291 539 Set Location to 2 2 Set Border_Style to Border_Thick Set Maximize_Icon to True Set Label to "Code Indenter" Set pbAutoActivate to True Set pbAcceptDropFiles to True Set Icon to "CodeIndent.ico" Property String psStudioFindFileMask "" Property Boolean pbHaveBeenPaged False Object oCodeIntenter is a cCodeIndenter End_Object Object oOpenDialog is an OpenDialog Handle hWorkspace String sFolder // Get phoWorkspace of ghoApplication to hWorkspace // Get psAppSrcPath of hWorkspace to sFolder // Set Initial_Folder to sFolder Set Filter_Index to 1 End_Object Object oStudioEditorSettings_grp is a Group Set Size to 57 198 Set Location to 3 9 Object oStudioTypefaceSetting_fm is a Form Set Size to 13 109 Set Location to 14 38 Set Enabled_State to False Set Label_Col_Offset to 2 Set Label to "Font" Set Label_Justification_Mode to JMode_Right End_Object Object oStudioFontSizeSetting_fm is a Form Set Size to 13 17 Set Location to 14 173 Set Enabled_State to False Set Label_Col_Offset to 2 Set Label to "Size" Set Label_Justification_Mode to JMode_Right End_Object Object oStudioTabSizeSetting_fm is a Form Set Size to 13 17 Set Location to 31 173 Set Enabled_State to False Set Label_Col_Offset to 2 Set Label to "Tab size" Set Label_Justification_Mode to JMode_Right End_Object Object oStudioConvertTabs_cb is a CheckBox Set Size to 10 50 Set Location to 33 8 Set Label to "Convert tabs to spaces while typing" Set Enabled_State to False End_Object Object oEditorInfo_tb is a TextBox Set Size to 9 172 Set Location to 44 8 Set Label to "These settings will be applied when indenting code" End_Object End_Object Object oFileName_fm is a Form Set Size to 13 207 Set Location to 19 268 Set Label to "Select File" Set Label_Col_Offset to 0 Set Label_Justification_Mode to JMode_Right Set peAnchors to anTopLeftRight Procedure Prompt Boolean bOpen bReadOnly String sFileTitle String[] sSelectedFiles Set Filter_String of oOpenDialog to CS_OpenFileStdFilter Get Show_Dialog of oOpenDialog to bOpen If bOpen Begin Get TickReadOnly_State of oOpenDialog to bReadOnly Get File_Title of oOpenDialog to sFileTitle Get Selected_Files of oOpenDialog to sSelectedFiles Set Value to sSelectedFiles[0] Send LoadFile of oEditor_edt Set Label of oProcessInfo_tb to CS_IdleText End End_Procedure End_Object Object oLoad_btn is a cButtonDPI Set Size to 13 50 Set Location to 19 482 Set Label to 'Load' Set peAnchors to anTopRight Set psToolTip to "The Studios 'Find File Mask' is used as the 'All Source' filter for the Open File dialog." Set pbAutoEnable to True Procedure OnClick Send Prompt of oFileName_fm End_Procedure End_Object Object oStudioFindFileMask_fm is a Form Set Size to 13 207 Set Location to 35 268 Set Enabled_State to False Set Label_Col_Offset to 2 Set Label_Justification_Mode to JMode_Right Set Label to "Find File Mask" Set peAnchors to anTopLeftRight End_Object Object oEditor_edt is a cTextEdit Set Size to 197 523 Set Location to 67 8 Set peAnchors to anAll Set pbWrap to False Procedure LoadFile String sFile Get Value of oFileName_fm to sFile Send Delete_Data Send ReadFromDisk Send Activate End_Procedure Procedure SaveFile Boolean bOK Get WriteToDisk to bOK If (bOK = False) Begin Send Info_Box "An error occured and the file wasn't saved properly. Please see the 'Backup' folder for the original file." End Else Begin Send Info_Box "Success! The new file was saved.\n(And a backup copy was saved to the 'Backup' sub-folder.)" End End_Procedure Procedure ProcessFile Integer iLines iCtr String sLine Get Line_Count to iLines Decrement iLines For iCtr from 0 to iLines Get Line iCtr to sLine Move (Trim(sLine)) to sLine // A slight optimization to avoid always adding a new line at end-of-file. If (iCtr = iLines and sLine = "") Break Send ProcessLine of oCodeIntenter sLine Loop End_Procedure Procedure Display String[] vArray Integer iSize iCtr Get ptArray of oCodeIntenter to vArray Set Dynamic_Update_State to False Set Value to '' Move (SizeOfArray(vArray)) to iSize Decrement iSize For iCtr from 0 to iSize Send AppendText vArray[ictr] Loop Set Dynamic_Update_State to True End_Procedure End_Object Object oProcessInfo_tb is a TextBox Set Auto_Size_State to False Set Size to 9 49 Set Location to 274 299 Set Justification_Mode to JMode_Right Set Label to CS_IdleText Set TextColor to clRed Set peAnchors to anBottomRight End_Object Object oProcess_btn is a cButtonDPI Set Location to 271 353 Set Label to "PROCESS!" Set peAnchors to anBottomRight Set Default_State to True Set FontWeight to fw_Bold Set pbAutoEnable to True Procedure OnClick String sCode Integer iLines Boolean bOK Get Line_Count of oEditor_edt to iLines If (iLines < 10) Begin Get Value of oEditor_edt to sCode Move (Trim(sCode)) to sCode If (sCode = "") Begin Send Info_Box "Nothing to process!" Procedure_Return End End Set Label of oProcessInfo_tb to CS_WorkingText Send Init of oCodeIntenter Send ProcessFile of oEditor_edt Send Display of oEditor_edt Set Label of oProcessInfo_tb to CS_ReadyText End_Procedure Procedure DoEnable String sValue Get Value of oEditor_edt to sValue Set Enabled_State to (sValue <> "") End_Procedure End_Object Object oSave_btn is a cButtonDPI Set Location to 271 427 Set Label to 'Save' Set peAnchors to anBottomRight Set pbAutoEnable to True Procedure OnClick Send SaveFile of oEditor_edt End_Procedure Procedure DoEnable String sValue Get Value of oEditor_edt to sValue Set Enabled_State to (sValue <> "") End_Procedure End_Object Object oClear_btn is a cButtonDPI Set Size to 14 50 Set Location to 271 481 Set Label to "Clear" Set peAnchors to anBottomRight Set pbAutoEnable to True Procedure OnClick Set Value of oFileName_fm to "" Send Delete_Data of oEditor_edt Set Label of oProcessInfo_tb to CS_IdleText End_Procedure Procedure DoEnable String sValue Get Value of oEditor_edt to sValue Set Enabled_State to (sValue <> "") End_Procedure End_Object Object oNumberOfChars_fm is a Form Set Size to 13 57 Set Location to 271 81 Set Label_Col_Offset to 2 Set Label_Justification_Mode to JMode_Right Set Label to "Number of characters" Set Enabled_State to False Set Form_Datatype to Mask_Numeric_Window Set Form_Mask to "Z### ### ###" Set peAnchors to anBottomLeft End_Object Object oAddToStudio_btn is a Button Set Size to 14 52 Set Location to 271 145 Set Label to "Add to Studio" Set peAnchors to anBottomLeft Set psToolTip to "Dialog that adds this program to the Studio's 'Tools' menu." Procedure OnClick Set pbCodeIndent of ghoApplication to True Send Popup of (oAddToStudio_dg(Client_Id(phoMainPanel(ghoApplication)))) End_Procedure End_Object Procedure ReadFromDisk String sFile Integer iSize iFileSize UChar[] uFile Get Value of oFileName_fm to sFile // Read the sequential file Direct_Input channel 5 sFile If (SeqEof) Begin Procedure_Return End // Read entire file into UChar array Read_Block channel 5 uFile -1 Close_Input channel 5 Move (SizeOfArray(uFile)) to iFileSize Get_Argument_Size to iSize If (iFileSize > iSize) Begin Set_Argument_Size (iFileSize + 1024) End Move (UCharArrayToString(uFile)) to sFile Set Value of oEditor_edt to sFile Set Value of oNumberOfChars_fm to iFileSize End_Procedure Function WriteToDisk Returns Boolean String sFile sText Integer iSize iFileSize iCh Boolean bOK Get Backup to bOK If (bOK = False) Begin Send Info_Box "Sorry, the backup failed due to a problem. Process was interupted." Function_Return False End Get Value of oEditor_edt to sText If (Trim(sText) = "") Begin Send Info_Box "Nothing to output" Function_Return False End Get Value of oFileName_fm to sFile Get Seq_Open_Output_Channel sFile to iCh If (iCh = DF_SEQ_CHANNEL_ERROR) Begin Function_Return False End Move 0 to Err Direct_Output channel iCh sFile Write channel iCh sText Close_Input channel iCh Function_Return (Err = False) End_Function Function Backup Returns Boolean String sFileName sPath sFileOnly Boolean bExists bOK Integer iRetval Get Value of oFileName_fm to sFileName Get ParseFolderName sFileName to sPath Get ParseFileName sFileName to sFileOnly Get vFolderFormat sPath to sPath Move (sPath + "Backup") to sPath File_Exist sPath bExists If (bExists = False) Begin Get vCreateDirectory sPath to iRetval If (iRetval = True) Begin Function_Return False End End Get vCopyFile sFileName (sPath + "\" + sFileOnly) to iRetval Function_Return (iRetval = 0) End_Function // Reads current Studio settings and set property & form values accordingly. Procedure ReadCurrentStudioSettings String sStudioFindFileMask sFontName sFontSize sSettingsGroupLabel sDFVersion Integer iFontSize iExpandTabs iIndentStyle iTabSize Integer iMajorVersion iMinorVersion Move FMAC_VERSION to iMajorVersion Move FMAC_REVISION to iMinorVersion Move (String(iMajorVersion) + "." + String(iMinorVersion)) to sDFVersion Move CS_StudioEditorSettingsStart to sSettingsGroupLabel Move (CS_StudioEditorSettingsStart * String(sDFVersion) * CS_StudioEditorSettingsEnd) to sSettingsGroupLabel Set Label of oStudioEditorSettings_grp to sSettingsGroupLabel Get StudioCodeEditorSettings of ghoApplication CS_StudioFontName False to sFontName Get StudioCodeEditorSettings of ghoApplication CS_StudioFontSize True to sFontSize Move (Integer(sFontSize) * 20) to iFontSize Set Value of oStudioTypefaceSetting_fm to sFontName Set Value of oStudioFontSizeSetting_fm to sFontSize // Must set Editor typeface first Set psTypeFace of oEditor_edt to sFontName Set piFontSize of oEditor_edt to iFontSize Get StudioFileMaskSettings of ghoApplication to sStudioFindFileMask If (sStudioFindFileMask <> String(cx_RegKeyVDFKeyDoesNotExist)) Begin Set Value of oStudioFindFileMask_fm to sStudioFindFileMask Set psStudioFindFileMask to sStudioFindFileMask End // I'm not sure what this does... Get StudioCodeEditorSettings of ghoApplication CS_StudioIndentStyle True to iIndentStyle // Studio - Configure Editor - Tabs - Tab Size Get StudioCodeEditorSettings of ghoApplication CS_StudioTabSize True to iTabSize // Studio - Configure Editor - Tabs - "Convert tabs to spaces while typing..." Get StudioCodeEditorSettings of ghoApplication CS_StudioExpandTabs True to iExpandTabs Set Value of oStudioTabSizeSetting_fm to iTabSize Set Checked_State of oStudioConvertTabs_cb to (iExpandTabs = 1) Set piTabSize of oCodeIntenter to iTabSize Set pbExpandTabs of oCodeIntenter to (iExpandTabs = 1) End_Procedure // Allow a file to be dropped on the view: Procedure OnFileDropped String sFilename Boolean bLast Boolean bExists Forward Send OnFileDropped sFilename bLast If (bLast = True) Begin Get vFilePathExists sFilename to bExists If (bExists = True) Begin Set Value of oFileName_fm to sFilename Send LoadFile of oEditor_edt Set Label of oProcessInfo_tb to CS_IdleText End Else Begin Send Info_Box "File does not exist." End End Else Begin Send Info_Box "Only one file can be dropped on the view. The last file will be used." End End_Procedure // - We use a property so we only do this once // at startup of the program. // - This is late enough in the activation chain to // activate the Clean Markers view if a "/c" flag // was passed on the command line. // - It is also late enough to load the editor object // with a file as it has been paged when we get here. Procedure OnSetFocus Boolean bHaveBeenPaged bCodeIndent String sValue sAutoLoadAppSrc Forward Send OnSetFocus Get pbHaveBeenPaged to bHaveBeenPaged If (bHaveBeenPaged = True) Begin Procedure_Return End Set pbHaveBeenPaged to True Send ReadCurrentStudioSettings // This could be used to show the Code Indent view at startup: Get psAutoLoadAppSrc of ghoApplication to sAutoLoadAppSrc Get pbCodeIndent of ghoApplication to bCodeIndent If (bCodeIndent = False) Begin Send Activate_oCleanMarkersView // We also need to page the object again, else // the CodeIndent view will be shown although it is // the Clean Markers view that has the focus. Send Page_Object True Procedure_Return End Get psAutoLoadAppSrc of ghoApplication to sValue If (sValue <> "") Begin Set Value of oFileName_fm to sValue Send LoadFile of oEditor_edt End End_Procedure On_Key kClear Send KeyAction of oClear_btn On_Key kSave_Record Send KeyAction of oSave_btn On_Key Key_Ctrl+Key_S Send KeyAction of oSave_btn On_Key Key_Ctrl+Key_O Send KeyAction of oLoad_btn On_Key Key_Ctrl+Key_F4 Send None End_Object