Use Windows.pkg Use cRefactorDbView.pkg Use SourceCode.inc Use Working.pkg Use cScintillaEdit.pkg Use oEditorProperties.pkg Use mfiletime.pkg Use vWin32fh.pkg Use cRemoveUnusedLocals.pkg Use cUnusedSourceFiles.pkg Activate_View Activate_oEditorView_vw For oEditorView_vw Object oEditorView_vw is a cRefactorDbView Set Size to 263 492 Set Border_Style to Border_Thick Set Maximize_Icon to True Set Label to "Refactoring Editor" Set pbAutoActivate to True Set pbAcceptDropFiles to True Set Icon to "Editor.ico" Set phoEditorView of ghoApplication to Self Property Handle phoRemoveUnusedLocals 0 Property Handle phoReportUnusedSource 0 Property Handle phoBPO 0 Property String psLineBreak "" Property Boolean pbLastLineBreak False Property tRefactorActions pRefactorActions Object oRemoveUnusedLocals is a cRemoveUnusedLocals Set phoRemoveUnusedLocals to Self End_Object Object oReportUnusedSourceFiles is a cUnusedSourceFiles Set phoReportUnusedSource to Self End_Object Object oEditor_edt is a cScintillaEdit Set Size to 248 473 Set Location to 8 10 Set peAnchors to anAll Set Enabled_State to False Set phoEditor of ghoApplication to (Self) Property Boolean piInSetFocus False Property DateTime pdtCurrentFileDateTime Function RefactorSourceFileInEditor Returns Boolean tRefactorActions RefactorActions Move False to Err Move 0 to LastErr Get pRefactorActions to RefactorActions If (RefactorActions.bReindent = True) Begin Send UpdateStatusBar "Reindenting source code..." False Send RefactorReIndent End If (RefactorActions.bProperCasing = True) Begin Send UpdateStatusBar "Making proper casing..." False Send RefactorNormalizeCase End If (RefactorActions.bDropSelf = True) Begin Send RefactorDropSelf End Function_Return (Err = False) End_Function Procedure LoadEditorFile String sFileName Integer eStatus Send Delete_Data Get CM_OpenFile sFileName to eStatus Send FillFileTimeStamp sFileName // Update the filetime. End_Procedure Procedure SaveFile Boolean bOK Send DispatchAnyKey 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 UpdateStatusBar "Changes saved!" True End End_Procedure Function IsEditorRefactorActions Returns Boolean tRefactorActions RefactorActions Boolean bChecked Move False to bChecked Get pRefactorActions to RefactorActions Case Begin Case (RefactorActions.bDropSelf = True) Move True to bChecked Case Break Case (RefactorActions.bProperCasing = True) Move True to bChecked Case Break Case (RefactorActions.bReindent = True) Move True to bChecked Case Break Case End Function_Return bChecked End_Function Function CharacterCount Returns Integer Integer iLineCount iStartPos iEndPos Integer iTotalCharacters Move 0 to iTotalCharacters Get EditorMessage SCI_GETLINECOUNT 0 0 to iLineCount If (iLineCount > 0) Begin Get EditorMessage SCI_POSITIONFROMLINE 0 0 to iStartPos Get EditorMessage SCI_GETLINEENDPOSITION (iLineCount - 1) 0 to iEndPos Get EditorMessage SCI_COUNTCHARACTERS iStartPos iEndPos to iTotalCharacters End Function_Return iTotalCharacters End_Function Procedure ApplyEditorOptions Forward Send ApplyEditorOptions End_Procedure Procedure FillFileTimeStamp String sFileName DateTime dtCurrentFileDateTime Get FileModTime sFileName to dtCurrentFileDateTime Set pdtCurrentFileDateTime to dtCurrentFileDateTime End_Procedure // Returns the DateTime of the passed file name was modified, with seconds (only) precision. Function FileModTime String sFileName Returns DateTime Date dDate Integer iYY iHH iMM iSS Boolean bExists DateTime dtFileDateTime Move (NullDateTime()) to dtFileDateTime Get vFilePathExists sFileName to bExists If (bExists = True) Begin Get_File_Mod_Time sFileName to dDate iHH iMM iSS Move dDate to dtFileDateTime Move (DateGetYear (dtFileDateTime)) to iYY Move (DateSetYear (dtFileDateTime, iYY)) to dtFileDateTime Move (DateSetHour (dtFileDateTime, iHH)) to dtFileDateTime Move (DateSetMinute (dtFileDateTime, iMM)) to dtFileDateTime Move (DateSetSecond (dtFileDateTime, iSS)) to dtFileDateTime Move (DateSetMillisecond(dtFileDateTime, 0)) to dtFileDateTime End Function_Return dtFileDateTime End_Function Function IsFileTimeNewer String sFileName Returns Boolean Boolean bExists bIsNewer DateTime dtCurrentFileDateTime dtCompareFileDateTime Move False to bIsNewer Get vFilePathExists sFileName to bExists If (bExists = True) Begin Get pdtCurrentFileDateTime to dtCurrentFileDateTime Get FileModTime sFileName to dtCompareFileDateTime Move (dtCompareFileDateTime > dtCurrentFileDateTime) to bIsNewer End Function_Return bIsNewer End_Function // Note: We need this "intermediate" procedure because the phoMainPanel property // is zero when the program starts - which generates a runtime error. Procedure SwitchNextView Send Switch_Next_View of (Client_Id(phoMainPanel(ghoApplication))) End_Procedure { MethodType=Property } Procedure Set piTabSize Integer iTabSize Send EditorMessage SCI_SETTABWIDTH iTabSize Set piTabSize of ghoEditorProperties to iTabSize Send SaveIni of ghoEditorProperties End_Procedure { MethodType=Property } Function piTabSize Returns Integer Integer iTabSize Send EditorMessage SCI_GETTABWIDTH iTabSize Function_Return iTabSize End_Function Procedure OnModified Handle hoEditor Integer iLines iSize Forward Send OnModified Get phoEditor of ghoApplication to hoEditor Get Line_Count of hoEditor to iLines Get CharacterCount of hoEditor to iSize Send UpdateStatusBar "" False iLines iSize End_Procedure // Used for checking if the file in editor has changed externally and // if so reload it. Procedure OnSetFocus Integer iRet iCurrentLine String sMsg sFileName Handle hoMain Boolean bUserModified bHasChangedExternal bDoReloadFile Send OnSelChange Send OnOvertypeChange Move False to bDoReloadFile Get Main_Panel_Id to hoMain If (not(piInSetFocus(Self))) Begin // recursive protection Set piInSetFocus to True Get psCurrentSourceFileName of ghoApplication to sFileName Get IsFileTimeNewer sFileName to bHasChangedExternal Get CM_IsModified to bUserModified If (bHasChangedExternal and bUserModified) Begin If (bUserModified) Begin Append sMsg "The file has been changed by another program.\n\n" End Append sMsg "Do you want to reload it?\n" If (bUserModified) Begin Append sMsg "Pressing YES will discard any changes made.\n" End Get YesNo_Box sMsg (Label(hoMain)) to iRet If (iRet = MBR_Yes) Begin Move True to bDoReloadFile End Else Begin Send FillFileTimeStamp sFileName // Update the file modified datetime. End End // If file has changed externally, but we didn't edit, then do not ask, just refresh If (bHasChangedExternal and bUserModified = False) Begin Move True to bDoReloadFile End If (bDoReloadFile = True) Begin Get CurrentLine to iCurrentLine Get CM_OpenFile sFileName to iRet Send EditorMessage SCI_SETSAVEPOINT If (iCurrentLine <> 0) Begin Send EditorMessage SCI_GOTOLINE iCurrentLine End Send FillFileTimeStamp sFileName // Update the file modified datetime. End Set piInSetFocus to False End End_Procedure // This short-cut key will keep the UI consistent, as the editor was "grabbing" this // key combination and did nothing, but everywhere else it flippes through the views/tab-pages. On_Key Key_Ctrl+Key_Tab Send SwitchNextView On_Key Key_Ctrl+Key_S Send Request_Save End_Object Object oBPO is a BusinessProcess Delegate Set phoBPO to Self Property Boolean pbOk Property String[] pasFolderNames Property String psFileFilter Procedure OnProcess String sFolderName sFileName Boolean bOk bExists bIsFileInFilter bStop Boolean bIsRefactorFunctions String[] asFolderNames String sFileFilter Integer iCount iSize iItems Handle hoReportUnusedSource tRefactorActions RefactorActions tCounters Counters tsSearchResult[] asSearchResult Get IsRefactorFunctions False to iItems // If this is false we only have report functions. Move (iItems <> 0) to bIsRefactorFunctions Move False to bOk Send SetProgressBarText Get pRefactorActions to RefactorActions Get pasFolderNames to asFolderNames Get psFileFilter to sFileFilter Get AllSourceFiles of ghoApplication asFolderNames sFileFilter to asSearchResult Move (SizeOfArray(asSearchResult)) to iSize Decrement iSize // If at least one refactoring function was selected (and not only report functions) If (bIsRefactorFunctions = True) Begin For iCount from 0 to iSize Move asSearchResult[iCount].sAlternateFileName to sFolderName Move asSearchResult[iCount].sFilename to sFileName Set Title_Text of ghoStatusPanel to ("Folder:" * String(sFolderName)) Set Message_Text of ghoStatusPanel to ("File:" * String(sFileName)) Send Update_status ("File No:" * String(iCount + 1) * "of:" * String(iSize + 1)) Get IsFileInFilter of ghoApplication sFileName sFileFilter to bIsFileInFilter If (bIsFileInFilter = True) Begin // *** Process File *** Get vFolderFormat sFolderName to sFolderName Get ProcessFile (sFolderName + sFileName) False to bOK End Get Cancel_Check to bStop If (bStop = True) Begin Procedure_Return End Loop End // bUnusedSource needs to be treated a bit differently because we need to "feed" the logic // with all workspace folders we've found. (Can't use the file by file approach) If (RefactorActions.bUnusedSource = True) Begin If (SizeOfArray(asFolderNames) <> 0) Begin Get IsBackupFolder of ghoApplication to bExists If (bExists = False) Begin Get BackupFolder of ghoApplication "" to sFolderName End Get phoReportUnusedSource to hoReportUnusedSource Get psFileFilter to sFileFilter Set psFileFilter of hoReportUnusedSource to sFileFilter Set pasAllFolders of hoReportUnusedSource to asFolderNames Set Action_Text of ghoStatusPanel to "" Send DoProcess to hoReportUnusedSource Get piNoOfUnusedSourceFiles of hoReportUnusedSource to Counters.iUnusedSourceFiles Get pbOK of hoReportUnusedSource to bOk Send TallyCounters Counters End End Set pbOk to bOk End_Procedure Procedure Update_Status String sProgress String sPath Boolean bWorkspaceMode Get pbWorkspaceMode of ghoApplication to bWorkspaceMode If (bWorkspaceMode = True) Begin Get psHomePath of ghoApplication to sPath If (sPath <> "") Begin // Strip out the path, so we can see the filename without it being cut off. Move (Replace(sPath, sProgress, "..")) to sProgress End End Forward Send Update_Status sProgress End_Procedure Procedure SetProgressBarText String sMessage Move "Processing file:" to sMessage Set Process_Caption to (Label(phoMainPanel(ghoApplication))) Set Process_Message to sMessage Set Process_Title to "Refactoring Source Code" End_Procedure Set Display_Error_State to True Set Allow_Cancel_State to True End_Object // Returns True if at least one of the refactor actions has been selected, _except_ for report functions Function IsActionsExceptReports Returns Boolean Handle hoRefactorView Integer iCheckboxFunctions Get phoRefactorView of ghoApplication to hoRefactorView Get IsRefactorFunctions of hoRefactorView False to iCheckboxFunctions Function_Return (iCheckboxFunctions > 0) End_Function Function WriteToDisk Returns Boolean String sFileName Integer eResult Boolean bOK Handle hoEditor Get phoEditor of ghoApplication to hoEditor Get psCurrentSourceFileName of ghoApplication to sFileName Get SaveBackupFile of ghoApplication sFileName 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 CM_SaveFile of hoEditor sFileName False to eResult Send FillFileTimeStamp of hoEditor sFileName Function_Return (eResult = CME_SUCCESS) End_Function Procedure LoadFile String sFileName If (sFileName = "") Begin Procedure_Return End Send LoadEditorFile of (phoEditor(ghoApplication)) sFileName End_Procedure Procedure RemoveReportLogFiles String sPath Boolean bOK tRefactorActions RefactorActions Get pRefactorActions to RefactorActions Get vFolderFormat sPath to sPath If (RefactorActions.bUnusedSource = True) Begin Get vDeleteFile (sPath + CS_BackupFolder + CS_DirSeparator + CS_UnusedSourceLogFile) to bOK End End_Procedure // Checks the counters to see if the file was changed Function FileCountersChanged tCounters Counters Returns Boolean Boolean bChanged Move False to bChanged Case Begin Case (Counters.iTrimmed <> 0) Move True to bChanged Case Break Case (Counters.iRemoveMarker <> 0) Move True to bChanged Case Break Case (Counters.iRemoveLocal <> 0) Move True to bChanged Case Break Case (Counters.iRemoveFonts <> 0) Move True to bChanged Case Break Case (Counters.iRemovePublic <> 0) Move True to bChanged Case Break Case (Counters.iRemovePrivate <> 0) Move True to bChanged Case Break Case (Counters.iInlineIfElse <> 0) Move True to bChanged Case Break Case (Counters.iEndComments <> 0) Move True to bChanged Case Break Case (Counters.iUClassToRefClass <> 0) Move True to bChanged Case Break Case (Counters.iReindent <> 0) Move True to bChanged Case Break Case (Counters.iProperCasing <> 0) Move True to bChanged Case Break Case (Counters.iDropSelf <> 0) Move True to bChanged Case Break Case (Counters.iProjectObjectStructure <> 0) Move True to bChanged Case (Counters.iRemoveEmptyLines <> 0) Move True to bChanged Case Break Case (Counters.iUnusedLocalVariables <> 0) Move True to bChanged Case Break Case End Function_Return bChanged End_Function Procedure TallyCounters tCounters Counters tCounters Totals Get pTotalCounters of ghoApplication to Totals Add Counters.iTrimmed to Totals.iTrimmed Add Counters.iRemoveMarker to Totals.iRemoveMarker Add Counters.iRemoveLocal to Totals.iRemoveLocal Add Counters.iRemoveFonts to Totals.iRemoveFonts Add Counters.iRemovePublic to Totals.iRemovePublic Add Counters.iRemovePrivate to Totals.iRemovePrivate Add Counters.iInlineIfElse to Totals.iInlineIfElse Add Counters.iEndComments to Totals.iEndComments Add Counters.iUClassToRefClass to Totals.iUClassToRefClass Add Counters.iReindent to Totals.iReindent Add Counters.iProperCasing to Totals.iProperCasing Add Counters.iDropSelf to Totals.iDropSelf Add Counters.iProjectObjectStructure to Totals.iProjectObjectStructure Add Counters.iReplaceMoveStatement to Totals.iReplaceMoveStatement Add Counters.iRemoveEmptyLines to Totals.iRemoveEmptyLines Add Counters.iUnusedSourceFiles to Totals.iUnusedSourceFiles Add Counters.iUnusedLocalVariables to Totals.iUnusedLocalVariables Set pTotalCounters of ghoApplication to Totals End_Procedure Procedure IncrementChangedFiles Integer iCount Get piChangedFileCount of ghoApplication to iCount Increment iCount Set piChangedFileCount of ghoApplication to iCount End_Procedure Procedure IncrementFileCount Integer iCount Get piFileCount of ghoApplication to iCount Increment iCount Set piFileCount of ghoApplication to iCount End_Procedure // // *** MAIN PROCESS *** // Procedure MAIN_PROCESS tRefactorActions ReFactorActions tRefactorCheckbox[] aRefactorCheckboxes String[] asFolderNames String sFileFilter sPath sFileName sText sTotalTime Handle hoEditor hoBPO Boolean bOK bWorkspaceMode bActionsExceptReports bIsEditorRefactorActions Integer eResponse DateTime dtExecStart dtExecEnd TimeSpan tsTotalTime tCounters Totals Set pRefactorActions to ReFactorActions Set paRefactorCheckboxes to aRefactorCheckboxes Get pbWorkspaceMode of ghoApplication to bWorkspaceMode Get phoEditor of ghoApplication to hoEditor Get IsEditorRefactorActions of hoEditor to bIsEditorRefactorActions Get IsActionsExceptReports to bActionsExceptReports // We only switch to this view if any refactoring functions have been choosen // that is dependent of the editor object. If (bIsEditorRefactorActions = True) Begin // Switch view! Send Switch_Next_View of (Client_Id(phoMainPanel(ghoApplication))) Send Activate of hoEditor End If (bActionsExceptReports = True) Begin If (bWorkspaceMode = True) Begin Get StartWarning bWorkspaceMode "" to eResponse If (eResponse <> MBR_Yes) Begin Procedure_Return End End Else If (bWorkspaceMode = False) Begin Get psCurrentSourceFileName of ghoApplication to sFileName Get StartWarning bWorkspaceMode sFileName to eResponse If (eResponse <> MBR_Yes) Begin Procedure_Return End End End Move (CurrentDateTime()) to dtExecStart Get phoBPO to hoBPO Set pasFolderNames of hoBPO to ReFactorActions.asFolderNames Set psFileFilter of hoBPO to ReFactorActions.sFileFilter Send InitializeCounters Move False to Err Move 0 to LastErr Get psHomePath of ghoApplication to sPath Send RemoveReportLogFiles sPath If (bWorkspaceMode = True) Begin Send DoProcess of hoBPO Get pbOk of hoBPO to bOk End Else Begin Get psCurrentSourceFileName of ghoApplication to sFileName Get ProcessFile sFileName True to bOK End If (bOK = True) Begin Move (CurrentDateTime()) to dtExecEnd Move (dtExecEnd - dtExecStart) to tsTotalTime Get TimeSpanToString tsTotalTime to sTotalTime Send UpdateStatusBar ("Process completed. Elapsed Time:" * sTotalTime) True Get vFolderFormat sPath to sPath Get SummaryText True to sText // Send Info_Box (sText + "\n\nProcess completed. Elapsed Time:" * sTotalTime) (psProduct(ghoApplication)) Send ActivateLogFile If (RefactorActions.bUnusedSource = True) Begin Get pTotalCounters of ghoApplication to Totals If (Totals.iUnusedSourceFiles <> 0) Begin Send DisplayUnusedSourceFilesDialog of (Client_Id(ghoCommandBars)) End End End Else Begin Send Info_Box "The Process was unsuccessful." (psProduct(ghoApplication)) End End_Procedure // Processes the file passed (with path) and performs the actions that have been chosen on it. // This function will always create a backup file and then call parsefile // for the actual work. Function ProcessFile String sFileName Boolean bFileMode Returns Boolean Boolean bSuccess bSaveBak bChanged String sBackupFile Integer iRetval tCounters Counters Move True to bSuccess Get pbShouldBackupFile of ghoApplication to bSaveBak If (bSaveBak = True) Begin Get SaveBackupFile of ghoApplication sFileName to bSuccess End If (bSuccess = True) Begin Send UpdateStatusBar sFileName True Get ParseFile sFileName (&Counters) bFileMode to bSuccess Send IncrementFileCount Get FileCountersChanged Counters to bChanged If (bChanged = True) Begin Send IncrementChangedFiles End // If no changes were made; move the file back its original place Else Begin Get BackupFileName of ghoApplication sFileName to sBackupFile Get vMoveFile sBackupFile sFileName to iRetval If (iRetval <> 0) Begin Showln "Error moving file: " sBackupFile End End // Add to grand totals: Send TallyCounters Counters End Function_Return bSuccess End_Function // If bFileMode = True, only one source file is operated on. Function ParseFile String sSourceFile tCounters ByRef Counters Boolean bFileMode Returns Boolean Boolean bParseOK bChanged bWriteOK Boolean bIsEditorRefactorActions bSaved bIsSame Boolean bProjectObjectStructureStart bProjectObjectStructureEnd bRegisterAllObjectsStart bRegisterAllObjectsEnd bWriteLine Integer iLine eSplitBy iTabSize iNoOfEmptyLines iMaxNoOfEmptyLines iSize //iFileSize String sLine sBasePath sFileNameOnly Handle hoRemoveUnusedLocals hoEditor String[] asSourceFile asNewSourceFile asObjectNames tRefactorActions RefactorActions Move False to Err Move False to bParseOK Move False to bProjectObjectStructureStart Move False to bProjectObjectStructureEnd Move False to bRegisterAllObjectsStart Move False to bRegisterAllObjectsEnd Get phoEditor of ghoApplication to hoEditor Get pRefactorActions to RefactorActions Move RefactorActions.iTabSize to iTabSize Move RefactorActions.iMaxBlankLines to iMaxNoOfEmptyLines Get ReadSourceFileToArray sSourceFile to asSourceFile Get ParseFileName sSourceFile to sFileNameOnly Move (SizeOfArray(asSourceFile)) to iSize Set Message_Text of ghoStatusPanel to ("Parsing:" * String(sFileNameOnly) * "Lines:" * String(iSize)) Decrement iSize For iLine from 0 to iSize Move True to bWriteLine Send UpdateStatusBar "Refactoring..." False // Read a line from the source file's string array. // This is the same string that potentially gets changed by several // refactoring functions below, as it is passed as ByRef. Move asSourceFile[iLine] to sLine If (RefactorActions.bRemoveMarkers = True) Begin Get FindStudioMarker sLine to bWriteLine If (bWriteLine = False) Begin Increment Counters.iRemoveMarker End End If (RefactorActions.bRemoveFonts = True and bWriteLine = True) Begin Get IsNotSansSerifTypeFaceLine sLine to bWriteLine If (bWriteLine = False) Begin Increment Counters.iRemoveFonts End End If (bWriteLine = True) Begin If (RefactorActions.bRemoveLocals = True) Begin Get RemoveLocal (&sLine) to bChanged If (bChanged = True) Begin Increment Counters.iRemoveLocal End End If (RefactorActions.bPropertyPublic = True) Begin Get RemovePropertyPublic (&sLine) to bChanged If (bChanged = True) Begin Increment Counters.iRemovePublic End End If (RefactorActions.bPropertyPrivate = True) Begin Get RemovePropertyPrivate (&sLine) to bChanged If (bChanged = True) Begin Increment Counters.iRemovePrivate End End If (RefactorActions.bInlineIfElse = True) Begin Move RefactorActions.eSplitBy to eSplitBy Get SplitInlineIfElseLine (&sLine) eSplitBy iTabSize to bChanged If (bChanged = True) Begin Increment Counters.iInlineIfElse End End If (RefactorActions.bRemoveEndComments = True) Begin Get RemoveEndComments (&sLine) to bChanged If (bChanged = True) Begin Increment Counters.iEndComments End End If (RefactorActions.bUClassToRefClass = True) Begin Get ChangeUClassToRefClass (&sLine) to bChanged If (bChanged = True) Begin Increment Counters.iUClassToRefClass End End If (RefactorActions.bReplaceMoveStatement = True) Begin Get ReplaceCalcToMoveStatement (&sLine) to bChanged If (bChanged = True) Begin Increment Counters.iReplaceMoveStatement End End If (RefactorActions.bProjectObjectStructure = True) Begin // Do checking in reverse order; from bottom to top. If (bRegisterAllObjectsEnd = False) Begin If (bRegisterAllObjectsStart = False) Begin Get IsRegisterAllObjectsStart sLine to bRegisterAllObjectsStart End If (bRegisterAllObjectsStart = True) Begin Get IsRegisterObjectInArray sLine asObjectNames to bWriteLine Move False to bProjectObjectStructureStart End If (bRegisterAllObjectsStart = False and bProjectObjectStructureEnd = False and bProjectObjectStructureStart = False) Begin Get IsProjectObjectStructureStart sLine to bProjectObjectStructureStart End If (bProjectObjectStructureStart = True) Begin Get ProjectObjectStructureLine sLine (&asObjectNames) to bWriteLine End Get IsRegisterAllObjectsEnd sLine to bRegisterAllObjectsEnd If (bWriteLine = False) Begin Increment Counters.iProjectObjectStructure End End End If (RefactorActions.bRTrimLines = True) Begin // Must be after remove end comments Get RemoveTrailingSpaces (&sLine) to bChanged If (bChanged = True) Begin Increment Counters.iTrimmed End End If (RefactorActions.bInToContains = True) Begin Get ChangeInToContains (&sLine) to bChanged If (bChanged = True) Begin Increment Counters.iInToContains End End // ToDo: For now these are dummy functions that needs to be finalized: If (RefactorActions.bGetAddress = True) Begin Get ChangeGetAddress (&sLine) to bChanged If (bChanged = True) Begin Increment Counters.iGetAddress End End If (RefactorActions.bCompareOperators = True) Begin Get ChangeCompareOperators (&sLine) to bChanged If (bChanged = True) Begin Increment Counters.iCompareOperators End End // NOTE: Here the changed line is saved back to the array. If (bWriteLine = True) Begin Move sLine to asNewSourceFile[SizeOfArray(asNewSourceFile)] End End Loop If (RefactorActions.bRemoveUnusedLocals = True) Begin Get phoRemoveUnusedLocals to hoRemoveUnusedLocals Get psHomePath of ghoApplication to sBasePath Move (sBasePath + CS_BackupFolder) to sBasePath Get MainProcedure of hoRemoveUnusedLocals (&asNewSourceFile) to bParseOK If (bParseOK = True) Begin Get piNoOfUnusedLocalVariables of hoRemoveUnusedLocals to Counters.iUnusedLocalVariables Set piNoOfUnusedLocalVariables of hoRemoveUnusedLocals to 0 End End // This must go before we write the soure file back and the editor refactoring functions. If (RefactorActions.bRemoveBlankLines = True) Begin Get RemoveMultipleEmptyLines (&asNewSourceFile) iMaxNoOfEmptyLines to iNoOfEmptyLines Move iNoOfEmptyLines to Counters.iRemoveEmptyLines End // We need to write the changes back to the source file before we call any Editor refactor function. Move (IsSameArray(asSourceFile, asNewSourceFile)) to bIsSame If (bIsSame = False) Begin Get WriteArrayToSourceFile sSourceFile asNewSourceFile to bWriteOK If (bWriteOK = False) Begin Function_Return False End End If (bFileMode = True) Begin Send UpdateSourceFileNameDisplay of ghoApplication sSourceFile End // Is there any refactor action that should be performed by the editor? Get IsEditorRefactorActions of hoEditor to bIsEditorRefactorActions If (bIsEditorRefactorActions = True) Begin // It seems it can be a bit to soon to try to load the newly edited file above, // because Windows haven't finished writing/releasing it yet. // Sleep 1 Send WaitForFileToGetWritten sSourceFile // This will display the file in the toolbar _and_ load it in the editor. If (bFileMode = False) Begin Send UpdateSourceFileNameDisplay of ghoApplication sSourceFile End // Tell the editor to perform refactor function(s) on the source file. Get RefactorSourceFileInEditor of hoEditor to bChanged If (bChanged = True) Begin If (RefactorActions.bReindent = True) Begin Increment Counters.iReindent End If (RefactorActions.bProperCasing = True) Begin Increment Counters.iProperCasing End If (RefactorActions.bDropSelf = True) Begin Increment Counters.iDropSelf End Get WriteToDisk of hoEditor to bSaved End End If (Err = False) Begin Move True to bParseOK End Function_Return bParseOK End_Function Procedure WaitForFileToGetWritten String sFile Integer iCh iMaxSec Boolean bOK bExist DateTime dtStart dtStartCheck TimeSpan tsTime Move False to bOK Move 3 to iMaxSec Get vFilePathExists sFile to bExist If (bExist = False) Begin Procedure_Return End Move (CurrentDateTime()) to dtStart Get Seq_New_Channel to iCh Repeat Direct_Input channel iCh Move (SeqEof = False) to bOK If (bOK = False) Begin Close_Input channel iCh End Move (CurrentDateTime()) to dtStartCheck Move (dtStartCheck - dtStart) to tsTime If (SpanSeconds(tsTime) > iMaxSec) Begin Move True to bOK End Until (bOK = True) Close_Input channel iCh Send Seq_Release_Channel iCh End_Procedure Function ReadSourceFileToArray String sSourceFile Returns String[] Boolean bLastLineBreak bEndOfFile bFirstLine Integer iLine iChannel iFileSize String sLine sLastLine sLineBreak sFileNameOnly String[] asSourceFile Move 0 to iLine Move True to bFirstLine Move False to bEndOfFile Move False to bLastLineBreak Move "" to sLastLine Get Seq_New_Channel to iChannel If (iChannel = DF_SEQ_CHANNEL_NOT_AVAILABLE) Begin Function_Return asSourceFile End Get ParseFileName sSourceFile to sFileNameOnly Set Message_Text of ghoStatusPanel to ("Reading:" * String(sFileNameOnly)) Get vWin32_APIFileSize sSourceFile to iFileSize Move (ResizeArray(asSourceFile, iFileSize)) to asSourceFile // Need to use binary read mode if we want to preserve tab characters and not have automatic tab replacement // filemode options don't seem to work as documented, not sure why. // Direct_Input channel iInChannel ("binary: "+"cr: 13: "+"eof: 26: "+sSourceFile) // Direct_Input channel iInChannel ("binary: "+"cr: 13:"+"eof: 26:"+sSourceFile) Direct_Input channel iChannel ("binary:" + sSourceFile) While (bEndOfFile = False) Readln channel iChannel sLine Move (SeqEof) to bEndOfFile If (bEndOfFile and Length(sLastLine) > 0) Begin If (Right(sLastLine, 1) = CS_CR) Begin Move True to bLastLineBreak End End Move sLine to sLastLine If (bFirstLine = True) Begin Move False to bFirstLine // Determine the linebreak character to use for the file based on what is in the first line // The readline automatically reads Until LF, but does not report LF back in the string If (Length(sLine) > 0 and Right(sLine, 1) = CS_CR) Begin Move CS_CRLF to sLineBreak End Else Begin Move CS_LF to sLineBreak End Set psLineBreak to sLineBreak End If (sLineBreak = CS_CRLF) Begin If (Right(sLine, 1) = CS_CR) Begin Move (Left(sLine, Length(sLine) - 1)) to sLine End End If (bEndOfFile = False) Begin Move sLine to asSourceFile[iLine] Increment iLine End Loop Move (ResizeArray(asSourceFile, iLine)) to asSourceFile Set pbLastLineBreak to bLastLineBreak Close_Input channel iChannel Send Seq_Release_Channel iChannel Function_Return asSourceFile End_Function Function WriteArrayToSourceFile String sSourceFile String[] asNewSourceFile Returns Boolean Boolean bLastLineBreak Integer iOutChannel iSize iCount String sLineBreak Move False to Err Get psLineBreak to sLineBreak Get pbLastLineBreak to bLastLineBreak Get Seq_New_Channel to iOutChannel If (iOutChannel = DF_SEQ_CHANNEL_NOT_AVAILABLE) Begin Function_Return False End Direct_Output channel iOutChannel sSourceFile Move (SizeOfArray(asNewSourceFile)) to iSize Decrement iSize For iCount From 0 to (iSize-1) Write channel iOutChannel asNewSourceFile[iCount] sLineBreak Loop If (bLastLineBreak=True) Begin Write channel iOutChannel asNewSourceFile[iSize] sLineBreak End Else Begin Write channel iOutChannel asNewSourceFile[iSize] End Close_Input channel iOutChannel Send Seq_Release_Channel iOutChannel Function_Return (Err = False) End_Function Function StartWarning Boolean bWorkspaceMode String sFileName Returns Integer Boolean bSaveBak Integer eResponse iSelectedFunctionsCount String sMessage Get SelectedFunctions to iSelectedFunctionsCount If (bWorkspaceMode) Begin Append sMessage "Prior running these routines you should ALWAYS have checked in the source code with a version control system and/or " Append sMessage "make a backup!\n\n" Append sMessage ("You have selected" * String(iSelectedFunctionsCount) * "refactoring functions that will be applied ") Append sMessage "to all files for the selected folders and subfolders that matches " Append sMessage "the 'File extensions to parse' drop-down list.\n\nContinue?" End Else Begin Append sMessage ("You have selected" * String(iSelectedFunctionsCount) * "refactoring functions that will be applied to this source file:\n ") Append sMessage sFileName Append sMessage "\n\nContinue?" End Get pbShouldBackupFile of ghoApplication to bSaveBak If (bSaveBak=False) Begin Append sMessage "\n\nAttention: Please note that you did not enable the 'Create backup files' option in the Settings dialog" End Get YesNo_Box sMessage "" MB_DEFBUTTON2 to eResponse Function_Return eResponse End_Function Function SummaryText Boolean bWriteLogFile Returns String String sText sLogText sLogFile sPath sTimeText sProgram Integer iChangedFiles Integer iFileCount iChannel tCounters Totals tRefactorActions RefactorActions DateTime dtToday Get pRefactorActions to RefactorActions Get pTotalCounters of ghoApplication to Totals Get piChangedFileCount of ghoApplication to iChangedFiles Get piFileCount of ghoApplication to iFileCount Move ("Total number of files changed:" * String(iChangedFiles) * "out of" * String(iFileCount) * "Files.\n") to sText Move (sText + "\nStatistics:\n===========") to sText If (RefactorActions.bRTrimLines = True) Begin Append sText ("\nRight trimmed" * String(Totals.iTrimmed) * "lines") End If (RefactorActions.bRemoveMarkers = True) Begin Append sText ("\nMarkers removed" * String(Totals.iRemoveMarker)) End If (RefactorActions.bRemoveLocals = True) Begin Append sText ("\nLocal keywords removed" * String(Totals.iRemoveLocal)) End If (RefactorActions.bRemoveFonts = True) Begin Append sText ("\nStatic fonts removed" * String(Totals.iRemoveFonts)) End If (RefactorActions.bPropertyPublic = True) Begin Append sText ("\nPublic keywords removed" * String(Totals.iRemovePublic)) End If (RefactorActions.bPropertyPrivate = True) Begin Append sText ("\nPrivate keywords removed" * String(Totals.iRemovePrivate)) End If (RefactorActions.bInlineIfElse = True) Begin Append sText ("\nIf/Else lines changed" * String(Totals.iInlineIfElse)) End If (RefactorActions.bRemoveEndComments = True) Begin Append sText ("\nEnd Comments removed" * String(Totals.iEndComments)) End If (RefactorActions.bUClassToRefClass = True) Begin Append sText ("\nChange 'U_class' style to 'RefClass'" * String(Totals.iUClassToRefClass)) End If (RefactorActions.bReindent = True) Begin Append sText ("\nReindent Source Code" * String(Totals.iReindent)) End If (RefactorActions.bProperCasing = True) Begin Append sText ("\nMaking proper Upper/Lowercase Source Code" * String(Totals.iProperCasing)) End If (RefactorActions.bDropSelf = True) Begin Append sText ("\nDropping 'Self'" * String(Totals.iDropSelf)) End If (RefactorActions.bProjectObjectStructure = True) Begin Append sText ("\nRemoved 'Project Object Structure' lines" * String(Totals.iProjectObjectStructure)) End If (RefactorActions.bReplaceMoveStatement = True) Begin Append sText ("\nReplaced to use 'Move' command" * String(Totals.iReplaceMoveStatement)) End If (RefactorActions.bRemoveBlankLines = True) Begin Append sText ("\nRemoved number of empty lines" * String(Totals.iRemoveEmptyLines)) End If (RefactorActions.bGetAddress = True) Begin Append sText ("\nReplaced 'GetAddress of' command" * String(Totals.iGetAddress)) End If (RefactorActions.bInToContains = True) Begin Append sText ("\nReplaced 'IN' with 'Contains'" * String(Totals.iInToContains)) End If (RefactorActions.bCompareOperators = True) Begin Append sText ("\nReplaced 'If sTmp Ne '' Begin' " * String(Totals.iCompareOperators)) End If (RefactorActions.bRemoveUnusedLocals = True) Begin Append sText ("\nRemoved number of unused Local variables " * String(Totals.iUnusedLocalVariables)) End If (RefactorActions.bUnusedSource = True) Begin Append sText ("\nNumber of files unused by source program(s)" * String(Totals.iUnusedSourceFiles)) End If (bWriteLogFile = True) Begin Get psIdleText of (phoStatusBar(ghoCommandBars)) to sTimeText Get psHomePath of ghoApplication to sPath Get vFolderFormat sPath to sPath Move (sPath + CS_BackupFolder + CS_DirSeparator + CS_SummaryLogfileName) to sLogFile Get Seq_New_Channel to iChannel If (iChannel <> DF_SEQ_CHANNEL_NOT_AVAILABLE) Begin Append_Output channel iChannel sLogFile Move (Replaces("\n", sText, (Character(13) + Character(10)))) to sLogText Get psProduct of ghoApplication to sProgram Move (CurrentDateTime()) to dtToday Writeln channel iChannel "Created by: " sProgram " -- " dtToday Writeln channel iChannel sLogText Writeln channel iChannel sTimeText Writeln channel iChannel Close_Input channel iChannel Send Seq_Release_Channel iChannel End End Function_Return sText End_Function Procedure InitializeCounters tCounters EmptyTotals Set piChangedFileCount of ghoApplication to 0 Set piFileCount of ghoApplication to 0 Set pTotalCounters of ghoApplication to EmptyTotals Set piNoOfUnusedLocalVariables of (phoRemoveUnusedLocals(Self)) to 0 End_Procedure // Allow a .sws file, source file or folder to be dropped on the view: Procedure OnFileDropped String sFilename Boolean bLast String sFileExt Boolean bFile bFolder bSWSFile Handle hoEditor Get phoEditor of ghoApplication to hoEditor Forward Send OnFileDropped sFilename bLast // Try to find out if a file or a folder name // was dropped on the view: If (bLast = True) Begin Get ParseFileExtension sFilename to sFileExt Move (Lowercase(sFileExt)) to sFileExt Move (sFileExt = "") to bFolder Move (sFileExt = "sws") to bSWSFile Move (bSWSFile = False and bFolder = False) to bFile If (bFile = True) Begin Send UpdateSourceFileNameDisplay of ghoApplication sFileName Send LoadFile sFilename Set pbWorkspaceMode of ghoApplication to False End Else If (bSWSFile = True) Begin Send UpdateWorkspaceSelectorDisplay of ghoApplication sFilename Set pbWorkspaceMode of ghoApplication to True End Else If (bFolder = True) Begin Send Info_Box "You cannot drop a folder on this view." 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 String sSourceFilename Forward Send Activate_View Get psCurrentSourceFileName of ghoApplication to sSourceFilename If (sSourceFilename <> "") Begin Send UpdateSourceFileNameDisplay of ghoApplication sSourceFilename Send LoadFile sSourceFilename Send Top_of_Panel End Send Switch_Next_View of (Client_Id(phoMainPanel(ghoApplication))) End_Procedure Function pbShouldSave Returns Boolean Boolean bChanged bIsReadOnly Handle hoEditor Get phoEditor of ghoApplication to hoEditor Get CM_IsModified of hoEditor to bChanged Get CM_IsReadOnly of hoEditor to bIsReadOnly Function_Return (bChanged = True and bIsReadOnly = False) End_Function Procedure Request_Save Handle hoEditor Boolean bChanged Get phoEditor of ghoApplication to hoEditor Get pbShouldSave to bChanged If (bChanged = True) Begin Send SaveFile of hoEditor End End_Procedure Procedure Request_Clear Handle hoEditor Get phoEditor of ghoApplication to hoEditor Send Delete_Data of hoEditor Send UpdateStatusBar "" False End_Procedure Procedure Request_Clear_All Handle hoEditor Get phoEditor of ghoApplication to hoEditor Send Delete_Data of hoEditor Send UpdateStatusBar "" False End_Procedure Procedure UpdateStatusBar String sText Boolean bIdleTextOnly Integer iLi Integer iChrs Handle hoStatusBar Integer iLines iCharacters Move (StatusBar_Id(Self)) to hoStatusBar If (num_arguments > 2) Begin Move iChrs to iCharacters If (iCharacters = 0) Begin Move 0 to iLines End Else Begin Move iLi to iLines End Set NumberOfEditorLines of hoStatusBar to iLines Set NumberOfEditorCharacters of hoStatusBar to iCharacters End Else Begin If (bIdleTextOnly = True) Begin Set psIdleText of hoStatusBar to sText Set ActionText of hoStatusBar to "" End Else Begin Set ActionText of hoStatusBar to sText End End End_Procedure Procedure OnSetFocus Set piActiveView of ghoApplication to CI_CodeIndenter Self End_Procedure Object oView_IdleHandler is a cIdleHandler Set pbEnabled to True Procedure OnIdle String sSWSFile Get psSWSFile of ghoApplication to sSWSFile Set Enabled_State to (sSWSFile <> "") End_Procedure End_Object Procedure End_Construct_Object Forward Send End_Construct_Object // Define the save procedure for the editor object. Send DefineOnKey of (phoEditor(ghoApplication)) CMD_FileSaveAll msg_Request_Save End_Procedure End_Object