Use SourceCode.inc Use cScintillaEdit.pkg Use cButtonDPI.pkg Use Windows.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 Boolean pbHaveBeenPaged False Object oCodeIndenter is a cCodeIndenter End_Object Object oOpenDialog is an OpenDialog Set Filter_Index to 1 End_Object Object oStudioEditorSettings_grp is a Group Set Size to 57 198 Set Location to 3 9 Set Label to "DataFlex Studio XX.x Code Editor Settings" Object oStudioTypefaceSetting_fm is a Form Set Size to 12 126 Set Location to 14 26 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 12 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 Set Form_Datatype to 0 End_Object Object oStudioTabSizeSetting_fm is a Form Set Size to 12 17 Set Location to 28 173 Set Label_Col_Offset to 2 Set Label to "Tab Size" Set Label_Justification_Mode to JMode_Right Set Form_Datatype to 0 Set Skip_State to True Procedure OnChange Integer iTabSize Get Value to iTabSize Set piTabSize of oCodeIndenter to iTabSize End_Procedure End_Object Object oStudioConvertTabs_cb is a CheckBox Set Size to 10 50 Set Location to 29 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 162 Set Location to 44 8 Set Label to "(These settings will be applied when indenting code)" End_Object End_Object Object oSelectSourceFile_grp is a Group Set Size to 57 315 Set Location to 3 215 Set Label to "Select Source File To Indent" Set peAnchors to anTopLeftRight Object oLoad_btn is a cButtonDPI Set Size to 12 44 Set Location to 15 265 Set Label to "Select File" Set peAnchors to anTopRight Set psToolTip to "The Studios 'Find File Mask' is used as the 'All Source' filter for the Open File dialog." Procedure OnClick Send Prompt of oFileName_fm End_Procedure End_Object Object oFileName_fm is a Form Set Size to 12 220 Set Location to 15 41 Set Label to "File Name" Set Label_Col_Offset to 0 Set Label_Justification_Mode to JMode_Right Set peAnchors to anTopLeftRight Procedure Prompt Boolean bOpen bReadOnly String sFileTitle sFileFilter String[] sSelectedFiles Integer iCurrentItem Get FullFilterString of oStudioFindFileMask_cf to sFileFilter Get WinCombo_Current_Item of oStudioFindFileMask_cf to iCurrentItem // This is zero based. Set Filter_String of oOpenDialog to sFileFilter Set Filter_Index of oOpenDialog to (iCurrentItem + 1) 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 oStudioFindFileMask_cf is a ComboForm Set Size to 11 220 Set Location to 30 41 Set Label to "File Mask" Set Label_Col_Offset to 2 Set Label_Justification_Mode to JMode_Right Set peAnchors to anTopLeftRight Set Combo_Sort_State to False Procedure Combo_Fill_List String[] asFilterArray Integer iSize iCount iCurrentItem Forward Send Combo_Fill_List Get AllFiltersAsArray to asFilterArray Move (SizeOfArray(asFilterArray)) to iSize Decrement iSize For iCount from 0 to iSize Send Combo_Add_Item asFilterArray[iCount] Loop Set Value to asFilterArray[0] End_Procedure Function AllFiltersAsArray Returns String[] String sVDFExtensions sVDFVersion Integer iMajorVersion iMinorVersion String[] asFilterArray Move FMAC_VERSION to iMajorVersion Move FMAC_REVISION to iMinorVersion Move (String(iMajorVersion) + "." + String(iMinorVersion)) to sVDFVersion Move CS_StdExtensions to asFilterArray[SizeOfArray(asFilterArray)] Move CS_VDFAndTemplExt to asFilterArray[SizeOfArray(asFilterArray)] Move CS_PkgIncExt to asFilterArray[SizeOfArray(asFilterArray)] Move CS_SrcPkgExt to asFilterArray[SizeOfArray(asFilterArray)] Get StudioFileExtensions sVDFVersion to sVDFExtensions If (sVDFExtensions <> String(cx_RegKeyVDFKeyDoesNotExist)) Begin Move sVDFExtensions to asFilterArray[SizeOfArray(asFilterArray)] End Function_Return asFilterArray End_Function Function FullFilterString Returns String String[] asFilterArray String sFilterString sValue Integer iSize iCount Get AllFiltersAsArray to asFilterArray Move (SizeOfArray(asFilterArray)) to iSize Decrement iSize Move "" to sFilterString For iCount from 0 to iSize Move asFilterArray[iCount] to sValue Move (sFilterString + (sValue + "|" + sValue + "|")) to sFilterString Loop Function_Return sFilterString End_Function Function StudioFileExtensions String sVDFVersion Returns String Handle hoReg String sStudioRegPath sRetval Boolean bExists bOk Get Create (RefClass(cRegistry)) to hoReg Move CS_StudioPath to sStudioRegPath If (sVDFVersion > "17.1") Begin Move (Replace("Visual ", sStudioRegPath, "")) to sStudioRegPath End Move (sStudioRegPath + sVDFVersion + CS_StudioPathEnd) to sStudioRegPath Set phRootKey of hoReg to HKEY_CURRENT_USER // First check if the VDF version is installed Get KeyExists of hoReg sStudioRegPath to bExists If (bExists = False) Begin Send Destroy of hoReg Function_Return cx_RegKeyVDFKeyDoesNotExist End Get OpenKey of hoReg sStudioRegPath to bOk If (bOk = True) Begin Set pfAccessRights of hoReg to KEY_READ Get ReadString of hoReg CS_VdfExtensionsKey to sRetval End Send CloseKey of hoReg Send Destroy of hoReg Function_Return sRetval End_Function // To "un-select" the text in the comboform on startup Procedure DoApplyAnchors Integer Arg1 Integer Arg2 Handle hoBkComboForm Integer iStart iEnd If (Focus(Desktop)=Self) Begin Get SelStart to iStart Get SelEnd to iEnd End Forward Send DoApplyAnchors Arg1 Arg2 Send SetSel iStart iEnd End_Procedure End_Object End_Object Object oEditor_edt is a cScintillaEdit Set Size to 197 523 Set Location to 67 8 Set peAnchors to anAll Set Enabled_State 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 oCodeIndenter sLine Loop End_Procedure Procedure Display String[] vArray Integer iSize iCtr Get ptArray of oCodeIndenter to vArray Set Dynamic_Update_State to False //Set Value to '' Send Delete_Data 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 //Procedure onPaged //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 Size to 14 63 Set Label to "PROCESS!" Set peAnchors to anBottomRight Set Default_State to True Set FontWeight to fw_Bold Set pbAutoEnable to True Set psImage to "Process.ico" Procedure OnClick String sCode Integer iLines 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 oCodeIndenter 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 Set psImage to "ActionSave.ico" 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 Set psImage to "ActionClear.ico" 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 12 57 Set Location to 272 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 Integer eResult 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 oFileName_fm to sFile Get CM_SaveFile of oEditor_edt sFile False to eResult Function_Return (eResult = CME_SUCCESS) End_Function Function Backup Returns Boolean String sFileName sPath sFileOnly Boolean bExists 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 // 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 oCodeIndenter to iTabSize Set pbExpandTabs of oCodeIndenter 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 Procedure Activate_View Returns Integer Boolean bCodeIndent String sValue Forward Send Activate_View Send ReadCurrentStudioSettings // This could be used to show the Code Indent view at startup: Get psAutoLoadAppSrc of ghoApplication to sValue If (sValue <> "") Begin Set Value of oFileName_fm to sValue Send LoadFile of oEditor_edt Send Top_of_Panel End Get pbCodeIndent of ghoApplication to bCodeIndent If (bCodeIndent = False) Begin Send Switch_Next_View of (Client_Id(phoMainPanel(ghoApplication))) 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