//TH-Header //***************************************************************************************** // Copyright (c) 2014 KURANT Project // All rights reserved. // // $FileName : FINDFILES.DG // $ProjectName : The Hammer 2.0 // $Authors : Wil van Antwerpen, Michael Kurz, Sergey V. Natarov, Bernhard Ponemayr // $Created : 01.25.2014 01:08 // $Type : LGPL // // Contents: Find Text in Files // //***************************************************************************************** //TH-RevisionStart //TH-RevisionEnd // Project Object Structure // oFindFiles is a ToolPanel // oFindText is a ComboForm // oFileTypes is a cComboForm // oPath is a ComboForm // oFolderSelectBN is a Button // oMatchWord is a CheckBox // oMatchCase is a CheckBox // oRegularExpression is a CheckBox // oSearchSubFolders is a CheckBox // oShowAllResults is a CheckBox // oOK_bn is a Button // oCancel_bn is a Button // Register all objects Register_Object oCancel_bn Register_Object oFileTypes Register_Object oFindFiles Register_Object oFindText Register_Object oFolderSelectBN Register_Object oMatchCase Register_Object oMatchWord Register_Object oOK_bn Register_Object oPath Register_Object oRegularExpression Register_Object oSearchSubFolders Register_Object oShowAllResults Use mEditorMacros.pkg Use dfClient.pkg Use dfCmbFrm.pkg Use cComboForm.pkg Use Windows.pkg Activate_View Activate_oFindFiles For oFindFiles Object oFindFiles Is a ToolPanel Property Integer piWasButton Public False #IF (!@ >= 140) Set pbSizeToClientArea to False #ENDIF Set popup_state To True Set scope_state To True Set Border_Style To Border_Dialog Set Label To "Find in Files" Set Location To 26 20 Set Size To 115 338 Object oFindText Is a cComboForm Set Label To "Fi&nd what:" Set Size To 13 194 Set Location To 7 65 Set Form_Border To 0 Set Form_Margin To 100 Set combo_sort_state To False Procedure Combo_Fill_List End_Procedure // Combo_fill_list Procedure SaveValue String sVal Get value To sVal If (combo_item_matching(Self,sVal)) Eq -1 Send Combo_insert_item 0 sVal End_Procedure End_Object // oFindText Object oFileTypes Is a cComboForm Set Label To "In Files/file &types:" Set Size To 13 194 Set Location To 23 65 Set Form_Border To 0 Set combo_sort_state To False Set form_margin Item 0 To 100 Procedure LoadPredefinedValues String sTypes sPart sAllSource Send combo_delete_data Get psFileTypes Of ghoEditorProperties To sTypes Move ( (Trim(sTypes)) + "|") To sTypes While sTypes Ne "" Move (Left(sTypes,(Pos("|",sTypes)))) To sPart Move (Replace(sPart,sTypes,"")) To sTypes Move (Left(sTypes,(Pos("|",sTypes)))) To sPart Move (Replace(sPart,sTypes,"")) To sTypes Move (Replace("|",sPart,"")) To sPart Send combo_add_item sPart If sPart Ne "*.*" Move (sAllSource + sPart + ";") To sAllSource End Move (Left(sAllSource,((length(sAllSource))-1))) To sAllSource Send combo_insert_item 0 sAllSource Set value Item 0 To sAllSource End_Procedure // Combo_fill_list Procedure SaveValue String sVal Get value To sVal If (combo_item_matching(Self,sVal)) Eq -1 Send Combo_insert_item 0 sVal End_Procedure End_Object // oFileTypes Object oPath Is a cComboForm Set Label To "In f&older:" Set Size To 13 194 Set Location To 39 65 Set Form_Border To 0 Set Form_Margin To 100 Set combo_sort_state To False Procedure combo_add_item_ex String sPara0 String sPart While (Pos(";",sPara0)) Ne 0 Move (Left(sPara0,(Pos(";",sPara0)))) To sPart Move (Replace(sPart,sPara0,"")) To sPara0 Move (Replace(";",sPart,"")) To sPart If (combo_item_matching(Self,sPart)) Eq -1 Send combo_add_item sPart End If (combo_item_matching(Self,sPara0)) Eq -1 Send combo_add_item sPara0 End_Procedure Procedure LoadPredefinedValues Send combo_delete_data Send combo_add_item "Whole Workspace" Send combo_add_item_ex (CurrentRuntimePkgPath(ghoWorkSpaceHandlerEx)) Send combo_add_item_ex (CurrentAppSrcPath(ghoWorkSpaceHandlerEx)) Send combo_add_item_ex (CurrentDDSrcPath(ghoWorkSpaceHandlerEx)) Send combo_add_item_ex (CurrentProgramPath(ghoWorkspaceHandlerEx)) Set value To "Whole Workspace" End_Procedure // Combo_fill_list Procedure SaveValue String sVal Get value To sVal If (combo_item_matching(Self,sVal)) Eq -1 Send Combo_insert_item 1 sVal End_Procedure Procedure SelectDirectory String sDir Send activate To (Self) get_directory sDir Get SelectFolderWithInit "Select Directory to search" sDir To sDir If sDir Ne "" Set value To sDir End_Procedure End_Object // oPath Object oFolderSelectBN Is a Button Set Size To 11 12 Set Location To 40 259 Procedure OnClick Send SelectDirectory To oPath End_Procedure // OnClick Set label To "..." Set focus_mode To pointer_only End_Object // oFolderSelectBN Object oMatchWord Is a CheckBox Set Label To "Match &whole Word only" Set Size To 10 91 Set Location To 56 65 Procedure ToggleAndActivate Set checked_state To (Not(checked_state(Self))) Send activate To (Self) End_Procedure End_Object // oMatchWord Object oMatchCase Is a CheckBox Set Label To "Match c&ase" Set Size To 10 54 Set Location To 69 65 Procedure ToggleAndActivate Set checked_state To (Not(checked_state(Self))) Send activate To (Self) End_Procedure End_Object // oMatchCase Object oRegularExpression Is a CheckBox Set Label To "Regular &expression" Set Size To 10 77 Set Location To 82 65 Procedure ToggleAndActivate Set checked_state To (Not(checked_state(Self))) Send activate To (Self) End_Procedure End_Object // oRegularExpression Object oSearchSubFolders Is a CheckBox Set Label To "Search &Subfolders" Set Size To 10 75 Set Location To 56 188 Procedure ToggleAndActivate Set checked_state To (Not(checked_state(Self))) Send activate To (Self) End_Procedure End_Object // oSearchSubFolders Object oShowAllResults Is a CheckBox Set Label To "Show all &Results" Set Size To 10 69 Set Location To 69 188 Procedure ToggleAndActivate Set checked_state To (Not(checked_state(Self))) Send activate To (Self) End_Procedure End_Object // oShowAllResults Object oOK_bn Is a Button Set Label To "&Find" Set Location To 7 278 Set Default_State To True Procedure OnClick String sFindText sFileTypes sPath sAppSrc sLastPath sProgram Integer iLen iLastDeviderPos bSubFolders bMatchCase bMatchWord bShowAll bRegExp Get value Of oFindText To sFindText Get value Of oFileTypes To sFileTypes Get value Of oPath To sPath Get checked_state Of oSearchSubFolders To bSubFolders Get checked_state Of oMatchCase To bMatchCase Get checked_state Of oMatchWord To bMatchWord Get checked_state Of oShowAllResults To bShowAll Get checked_state Of oRegularExpression To bRegExp If (Trim(sFindText)) Eq "" Begin Send stop_box "No search Text" Procedure_Return End If (Trim(sFileTypes)) Eq "" Move "*.*" To sFileTypes If (Trim(sPath)) Eq "" Move "." To sPath Else Begin If (uppercase(Trim(sPath))) Eq "WHOLE WORKSPACE" Begin Move (CurrentAppSrcPath(ghoWorkSpaceHandlerEx)) To sAppSrc If (Pos(";",sAppSrc)) Ne 0 Move (Left(sAppSrc,((Pos(";",sAppSrc))-1))) To sAppSrc // only take the first path Move (CurrentProgramPath(ghoWorkSpaceHandlerEx)) To sProgram If (uppercase(Trim(sAppsrc))) Eq (uppercase(Trim(sProgram))) Begin // i asume not a all-on-one directory Move sAppsrc To sPath End Else Begin Move "" To sLastPath Move (length(sAppSrc)) To iLen While (iLen Gt 0) If (Mid(sAppSrc,1,iLen)) Eq "\" Begin Move iLen To iLastDeviderPos Move 0 To iLen End Else Decrement iLen End If iLastDeviderPos Ne 0 Move (Left(sAppSrc,(iLastDeviderPos-1))) To sAppsrc Move sAppSrc To sPath Move 1 To bSubFolders End End End Send SaveValues Send RequestStartFileFind to (oClientArea(oMain(Self))) sPath sFileTypes sFindText bSubFolders bMatchCase bMatchWord bShowAll bRegExp End_Procedure End_Object // oOK_bn Object oCancel_bn Is a Button Set Label To "&Cancel" Set Location To 23 278 Procedure OnClick If (Not(enabled_state(oOk_bn(Self)))) Begin Set piWasButton To True Send RequestCancelFileFind to (oClientArea(oMain(Self))) Send activate To (oFindText(Self)) End Else Send close_panel End_Procedure End_Object // oCancel_bn Set locate_mode To center_on_screen On_Key (key_alt+key_f) Send KeyAction To oOk_bn On_Key (key_alt+key_c) Send KeyAction To oCancel_bn On_Key (key_alt+key_n) Send activate To (oFindText(Self)) On_Key (key_alt+key_t) Send activate To (oFileTypes(Self)) On_Key (key_alt+key_o) Send activate To (oPath(Self)) On_Key (key_alt+Key_w) Send ToggleAndActivate To (oMatchWord(Self)) On_Key (key_alt+Key_a) Send ToggleAndActivate To (oMatchCase(Self)) On_Key (key_alt+Key_s) Send ToggleAndActivate To (oSearchSubFolders(Self)) On_Key (key_alt+key_r) Send ToggleAndActivate To (oShowAllResults(Self)) On_Key (key_alt+key_e) Send ToggleAndActivate To (oRegularExpression(Self)) On_Key KCANCEL Send close_panel Procedure OnStartFind Set enabled_state Of oFindText To False Set enabled_state Of oFileTypes To False Set enabled_state Of oPath To False Set enabled_state Of oOK_bn To False Set enabled_state Of oMatchWord To False Set enabled_state Of oMatchCase To False Set enabled_state Of oSearchSubFolders To False Set enabled_state Of oShowAllResults To False Set enabled_state Of oFolderSelectBN To False Set enabled_state Of oRegularExpression To False Send activate To oCancel_bn End_Procedure Procedure OnFinishFind Set enabled_state Of oFindText To True Set enabled_state Of oFileTypes To True Set enabled_state Of oPath To True Set enabled_state Of oOK_bn To True Set enabled_state Of oMatchWord To True Set enabled_state Of oMatchCase To True Set enabled_state Of oSearchSubFolders To True Set enabled_state Of oShowAllResults To True Set enabled_state Of oRegularExpression To True Set enabled_state Of oFolderSelectBN To True If (Not(piWasButton(Self))) Send close_panel Set piWasButton To False End_Procedure Procedure SaveValues Broadcast Send SaveValue End_Procedure Procedure LoadComboValuesFromString Integer hoObj String sData String sPart sFirst Integer iFirst Move 1 To iFirst Send Combo_delete_data To hoObj While (Pos("|",sData)) Ne 0 Move (Left(sData,(Pos("|",sData)))) To sPart Move (Replace(sPart,sData,"")) To sData Move (Replace("|",sPart,"")) To sPart If (iFirst) Begin Move sPart To sFirst Move 0 To iFirst End Else If (Trim(sPart)) Ne "" Send Combo_add_item To hoObj sPart End If (Trim(sFirst)) Ne "" Set value Of hoObj To sFirst Else Set value Of hoObj To "" End_Procedure Procedure LoadSettings String sWrkSpace String sVal Get EditorWorkspaceToolID To sWrkSpace Move ( (uppercase(Trim(sWrkSpace))) + "FFS" ) To sWrkSpace Clear editor Move gsUserName To editor.User Move sWrkSpace To editor.Type Move "FFFindtext" To editor.File Find Ge editor by Index.1 // USER,TYPE,FILE If ( (found) And (editor.user Eq gsUserName) And (editor.Type Eq sWrkspace) And (editor.File Eq "FFFindtext") ) Begin Send LoadComboValuesFromString (oFindText(Self)) editor.Data End Else Begin Set value Of (oFindText(Self)) To "" Send combo_delete_data To (oFindText(Self)) End Clear editor Move gsUserName To editor.User Move sWrkSpace To editor.Type Move "FFFiletypes" To editor.File Find Ge editor by Index.1 // USER,TYPE,FILE If ( (found) And (editor.user Eq gsUserName) And (editor.Type Eq sWrkspace) And (editor.File Eq "FFFiletypes") ) Begin Send LoadComboValuesFromString (oFileTypes(Self)) editor.Data End Else Send LoadPredefinedValues To (oFileTypes(Self)) Clear editor Move gsUserName To editor.User Move sWrkSpace To editor.Type Move "FFFindpath" To editor.File Find Ge editor by Index.1 // USER,TYPE,FILE If ( (found) And (editor.user Eq gsUserName) And (editor.Type Eq sWrkspace) And (editor.File Eq "FFFindpath") ) Begin Send LoadComboValuesFromString (oPath(Self)) editor.Data End Else Send LoadPredefinedValues To (oPath(Self)) Set checked_state Of (oMatchWord(Self)) To False Clear editor Move gsUserName To editor.User Move sWrkSpace To editor.Type Move "FFMatchword" To editor.File Find Ge editor by Index.1 // USER,TYPE,FILE If ( (found) And (editor.user Eq gsUserName) And (editor.Type Eq sWrkspace) And (editor.File Eq "FFMatchword") ) Begin If editor.Data Eq "TRUE" Set checked_state Of (oMatchword(Self)) To True End Set checked_state Of (oMatchCase(Self)) To False Clear editor Move gsUserName To editor.User Move sWrkSpace To editor.Type Move "FFMatchcase" To editor.File Find Ge editor by Index.1 // USER,TYPE,FILE If ( (found) And (editor.user Eq gsUserName) And (editor.Type Eq sWrkspace) And (editor.File Eq "FFMatchcase") ) Begin If editor.Data Eq "TRUE" Set checked_state Of (oMatchcase(Self)) To True End Set checked_state Of (oSearchSubFolders(Self)) To False Clear editor Move gsUserName To editor.User Move sWrkSpace To editor.Type Move "FFSearchsubfolder" To editor.File Find Ge editor by Index.1 // USER,TYPE,FILE If ( (found) And (editor.user Eq gsUserName) And (editor.Type Eq sWrkspace) And (editor.File Eq "FFSearchsubfolder") ) Begin If editor.Data Eq "TRUE" Set checked_state Of (oSearchSubFolders(Self)) To True End Set checked_state Of (oShowAllResults(Self)) To False Clear editor Move gsUserName To editor.User Move sWrkSpace To editor.Type Move "FFShowAllResults" To editor.File Find Ge editor by Index.1 // USER,TYPE,FILE If ( (found) And (editor.user Eq gsUserName) And (editor.Type Eq sWrkspace) And (editor.File Eq "FFShowAllResults") ) Begin If editor.Data Eq "TRUE" Set checked_state Of (oShowAllResults(Self)) To True End Set checked_state Of (oRegularExpression(Self)) To False Clear editor Move gsUserName To editor.User Move sWrkSpace To editor.Type Move "FFRegularExpression" To editor.File Find Ge editor by Index.1 // USER,TYPE,FILE If ( (found) And (editor.user Eq gsUserName) And (editor.Type Eq sWrkspace) And (editor.File Eq "FFRegularExpression") ) Begin If editor.Data Eq "TRUE" Set checked_state Of (oRegularExpression(Self)) To True End End_Procedure Function ComboValuesAsString Integer hoObj Returns String Integer iCou String sVal sRet Get value Of hoObj To sRet // save the current value as first entry Move (sRet + "|") To sRet If (combo_item_count(hoObj)) Eq 0 Procedure_Return sRet For iCou From 0 To ( (combo_item_count(hoObj)) -1) Get combo_value Of hoObj Item iCou To sVal Move (sRet + sVal + "|") To sRet If iCou Ge 30 Move ( (combo_item_count(hoObj)) -1) To iCou // i think 30 entries should be enough Loop Function_Return sRet End_Function Procedure SaveSettings String sWrkSpace String sVal Get EditorWorkspaceToolID To sWrkSpace Move ( (uppercase(Trim(sWrkSpace))) + "FFS" ) To sWrkSpace Clear editor Move gsUserName To editor.User Move sWrkSpace To editor.Type Find Ge editor by Index.1 // USER,TYPE,FILE If (finderr) Clear editor While ( (editor.Recnum Ne 0) And (editor.User Eq gsUserName) And (editor.Type Eq sWrkSpace) ) reread editor Delete editor unlock Clear editor Move gsUserName To editor.User Move sWrkSpace To editor.Type Find Ge editor by Index.1 // USER,TYPE,FILE If (finderr) Clear editor End Clear editor Get ComboValuesAsString (oFindText(Self)) To sVal lock Move gsUserName To editor.User Move sWrkSpace To editor.Type Move "FFFindtext" To editor.File Move sVal To editor.data Saverecord editor unlock Clear editor Get ComboValuesAsString (oFileTypes(Self)) To sVal lock Move gsUserName To editor.User Move sWrkSpace To editor.Type Move "FFFiletypes" To editor.File Move sVal To editor.data Saverecord editor unlock Clear editor Get ComboValuesAsString (oPath(Self)) To sVal lock Move gsUserName To editor.User Move sWrkSpace To editor.Type Move "FFFindpath" To editor.File Move sVal To editor.data Saverecord editor unlock Clear editor lock Move gsUserName To editor.User Move sWrkSpace To editor.Type Move "FFMatchword" To editor.File If (checked_state(oMatchWord(Self))) Move "TRUE" To editor.data Else Move "FALSE" To editor.Data Saverecord editor unlock Clear editor lock Move gsUserName To editor.User Move sWrkSpace To editor.Type Move "FFMatchcase" To editor.File If (checked_state(oMatchcase(Self))) Move "TRUE" To editor.data Else Move "FALSE" To editor.Data Saverecord editor unlock Clear editor lock Move gsUserName To editor.User Move sWrkSpace To editor.Type Move "FFSearchsubfolder" To editor.File If (checked_state(oSearchSubfolders(Self))) Move "TRUE" To editor.data Else Move "FALSE" To editor.Data Saverecord editor unlock Clear editor lock Move gsUserName To editor.User Move sWrkSpace To editor.Type Move "FFShowAllResults" To editor.File If (checked_state(oShowAllResults(Self))) Move "TRUE" To editor.data Else Move "FALSE" To editor.Data Saverecord editor unlock Clear editor lock Move gsUserName To editor.User Move sWrkSpace To editor.Type Move "FFRegularExpression" To editor.File If (checked_state(oRegularExpression(Self))) Move "TRUE" To editor.data Else Move "FALSE" To editor.Data Saverecord editor Unlock End_Procedure // SaveSettings End_Object // oFindFiles