//TH-Header //***************************************************************************************** // Copyright (c) 2017 KURANT Project // All rights reserved. // // $FileName : FINDFILES.DG // $ProjectName : The Hammer 2.0 // $Authors : Sergey V. Natarov, Wil van Antwerpen, Michael Kurz, Bernhard Ponemayr // $Created : 01.25.2014 01:08 // $Type : LGPL // // Contents: Find Text in Files // //***************************************************************************************** //TH-RevisionStart //TH-RevisionEnd 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 False Set pbSizeToClientArea to False 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 120 338 Set locate_mode to center_on_screen // Hot Keys 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 On_Key (key_alt+key_t) Send activate to oFileTypes On_Key (key_alt+key_o) Send activate to oPath On_Key (key_alt+Key_w) Send ToggleAndActivate to oMatchWord On_Key (key_alt+Key_a) Send ToggleAndActivate to oMatchCase On_Key (key_alt+Key_s) Send ToggleAndActivate to oSearchSubFolders On_Key (key_alt+key_r) Send ToggleAndActivate to oShowAllResults On_Key (key_alt+key_x) Send ToggleAndActivate to oExcludeComments On_Key (key_alt+key_e) Send ToggleAndActivate to oRegularExpression On_Key KCANCEL Send close_panel Object oFindText is a cComboForm Set Label to "Fi&nd what:" Set Size to 13 195 Set Location to 10 75 Set Form_Border to 0 Set Form_Margin to 100 Set combo_sort_state to False Set Label_Col_Offset to 2 Set Label_Justification_Mode to JMode_Right 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 195 Set Location to 26 75 Set Form_Border to 0 Set combo_sort_state to False Set form_margin item 0 to 100 Set Label_Col_Offset to 2 Set Label_Justification_Mode to JMode_Right 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 180 Set Location to 42 75 Set Form_Border to 0 Set Form_Margin to 100 Set combo_sort_state to False Set Label_Col_Offset to 2 Set Label_Justification_Mode to JMode_Right 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 (_T("Whole Workspace", 881)) 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 (_T("Whole Workspace", 881)) 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 (_T("Select Directory to search", 882)) sDir to sDir If sDir Ne "" Set value to sDir End_Procedure End_Object // oPath Object oFolderSelectBN is a Button Set Size to 13 15 Set Location to 42 255 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 59 75 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 72 75 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 85 75 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 59 183 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 72 183 Procedure ToggleAndActivate Set checked_state to (not(checked_state(Self))) Send activate to (Self) End_Procedure End_Object // oShowAllResults Object oExcludeComments is a CheckBox Set Label to "E&xclude Comments" Set Size to 10 75 Set Location to 85 183 Procedure ToggleAndActivate Set checked_state to (not(checked_state(Self))) Send activate to (Self) End_Procedure End_Object // oExcludeComments Object oOK_bn is a Button Set Size to 13 50 Set Label to "&Find" Set Location to 10 277 Set Default_State to True Procedure OnClick Boolean bSubFolders bMatchCase bMatchWord bShowAll bRegExp bExcludeComments String sFindText sFileTypes sPath sAppSrc sLastPath sProgram sWWs sTHPath Integer iLen iLastDeviderPos iFolder iFolders tTHWorkspace THWorkspace 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 oExcludeComments to bExcludeComments Get checked_state of oRegularExpression to bRegExp If (Trim(sFindText)) Eq "" Begin Send stop_box (_T("No search Text", 890)) Procedure_Return End If (Trim(sFileTypes)) Eq "" Move "*.*" to sFileTypes If (Trim(sPath)) Eq "" Move "." to sPath Else Begin Move (_T("Whole Workspace", 881)) to sWWs If (Trim(sPath)=sWWs) 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 // Add TH Specific workspace folders to the search path Get pTHWorkspace of ghoApplication To THWorkspace Move (SizeOfArray(THWorkspace.saFolders)) to iFolders For iFolder from 0 to (iFolders-1) If (iFolder>0) Begin // iFolder=0 == [current workspace] so skip that one Move (RTrim(THWorkspace.saFolders[iFolder])) To sTHPath If (Right(sTHPath,1)="\") Move (Left(sTHPath,Length(sTHPath)-1)) To sTHPath Move (sPath+";"+sTHPath) To sPath End Loop End End Send SaveValues Send SaveSettings Send RequestStartFileFind to (oClientArea(oMain(Self))) sPath sFileTypes sFindText bSubFolders bMatchCase bMatchWord bShowAll bRegExp bExcludeComments End_Procedure End_Object // oOK_bn Object oCancel_bn is a Button Set Size to 13 50 Set Label to "&Cancel" Set Location to 26 277 Procedure OnClick If (not(enabled_state(oOk_bn(Self)))) Begin Set piWasButton to True Send RequestCancelFileFind to (oClientArea(oMain(Self))) Send activate to oFindText End Else Begin Send close_panel // will also save settings End End_Procedure End_Object // oCancel_bn 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 oExcludeComments 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 oExcludeComments 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 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 LoadSettings tTHWorkspace THWorkspace Set value Of oFindText To "" Send combo_delete_data To oFindText Get pTHWorkspace of ghoApplication To THWorkspace Send LoadComboValuesFromString (oFindText(Self)) THWorkspace.sFFText // If (THWorkspace.sFFTypes="") Send LoadPredefinedValues to oFileTypes Else Send LoadComboValuesFromString (oFileTypes(Self)) THWorkspace.sFFTypes // If (THWorkspace.sFFPath="") Send LoadPredefinedValues to oPath Else Send LoadComboValuesFromString (oPath(Self)) THWorkspace.sFFPath // Set checked_state of oMatchWord to THWorkspace.iFFMatchWord Set checked_state of oMatchCase to THWorkspace.iFFMatchCase Set checked_state of oSearchSubFolders to THWorkspace.iFFSubFolders Set checked_state Of oShowAllResults To THWorkspace.iFFShowAll Set checked_State of oExcludeComments To THWorkspace.iFFExcludeComments Set checked_state of oRegularExpression to THWorkspace.iFFRegExp End_Procedure Procedure SaveSettings tTHWorkspace THWorkspace Get pTHWorkspace of ghoApplication To THWorkspace Get ComboValuesAsString (oFindText(Self)) to THWorkspace.sFFText Get ComboValuesAsString (oFileTypes(Self)) to THWorkspace.sFFTypes Get ComboValuesAsString (oPath(Self)) to THWorkspace.sFFPath Get checked_state of oMatchWord to THWorkspace.iFFMatchWord Get checked_state of oMatchcase to THWorkspace.iFFMatchCase Get checked_state of oSearchSubfolders to THWorkspace.iFFSubFolders Get checked_state Of oShowAllResults To THWorkspace.iFFShowAll Get Checked_State Of oExcludeComments To THWorkspace.iFFExcludeComments Get checked_state Of oRegularExpression To THWorkspace.iFFRegExp Set pTHWorkspace of ghoApplication To THWorkspace // Send THDoWriteWorkspace End_Procedure // SaveSettings Procedure Close_Panel Send SaveSettings Forward Send Close_Panel End_Procedure #IFDEF TH_TRANSLATION Procedure Translate Set Label to gILanguage[877] Set Label of oFindText to gILanguage[878] Set Label of oFileTypes to gILanguage[879] Set Label of oPath to gILanguage[880] Send LoadPredefinedValues to oPath Set label of oFolderSelectBN to gILanguage[883] Set Label of oMatchWord to gILanguage[884] Set Label of oMatchCase to gILanguage[885] Set Label of oRegularExpression to gILanguage[886] Set Label of oSearchSubFolders to gILanguage[887] Set Label of oShowAllResults to gILanguage[888] Set Label of oOK_bn to gILanguage[889] Set Label of oCancel_bn to gILanguage[891] End_Procedure #ENDIF Procedure Activating Forward Send Activating #IFDEF TH_TRANSLATION Send Translate #ENDIF End_Procedure End_Object // oFindFiles