Restored from previous forum. Originally posted by Jose.
Hi All,
I allways wanted to be able to search for the word under the cursor or selected text automatically, I just sometimes want to do quick search for the word under the cursor, instead of having to first select it and copy, then paste it into the find box;
This small code change to the FindWindow.pb file does just this.
The code looked like this;
Procedure OpenFindWindow(State)
If OpenWindow(#WINDOW_Find, 0, 0, #WINDOW_Find_Width, #WINDOW_Find_Height, #PB_Window_SystemMenu | #PB_Window_WindowCentered | #PB_Window_Invisible, Langage(72))
I change it to look like this, to help lazy people like me.
Procedure OpenFindWindow(State)
Protected CurrentWord.s ;-Add This
CurrentWord = GetCurrentWord() ;-Add This
If Len(CurrentWord) > 1 ;-Add This
GlobalFindText$ = CurrentWord ;-Add This
EndIf ;-Add This
If OpenWindow(#WINDOW_Find, 0, 0, #WINDOW_Find_Width, #WINDOW_Find_Height, #PB_Window_SystemMenu | #PB_Window_WindowCentered | #PB_Window_Invisible, Langage(72))
This little trick makes it easy to search for the word under the cursor, as it gets inserted into the find automatically.
@Fred and Danilo
Thanks for a great editor, maybe you could improve on this or add it to the editor for future, this is how many other editors I have used work.
Thanks
Small change great saving
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by ebs.
Jose,
That's a GREAT help! Can I suggest one addition? Add this line:
right after:
near the end of the procedure.
This will select whatever text is in the "Find:" string gadget. If you want to search for the current word, you just click "Next". But if you want to change the the text to search for, you can just start typing without having to select anything.
Regards,
Eric
Jose,
That's a GREAT help! Can I suggest one addition? Add this line:
Code: Select all
; select text in FindWord
SendMessage_(GadgetID(#GADGET_Find_FindWord), #EM_SETSEL, 0, -1)
Code: Select all
ActivateGadget(#GADGET_Find_FindWord)
This will select whatever text is in the "Find:" string gadget. If you want to search for the current word, you just click "Next". But if you want to change the the text to search for, you can just start typing without having to select anything.
Regards,
Eric
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Jose.
Thanks, Ebs
I thought about that after figuring this one out, but did not get that far.
Here is the latest code for the complete procedure, copy and paste this over the existing code in FindWindow.pb
Thanks All
Thanks, Ebs
I thought about that after figuring this one out, but did not get that far.
Here is the latest code for the complete procedure, copy and paste this over the existing code in FindWindow.pb
Code: Select all
Procedure OpenFindWindow(State)
Protected CurrentWord.s
CurrentWord = GetCurrentWord()
If Len(CurrentWord) > 1
GlobalFindText$ = CurrentWord
EndIf
If OpenWindow(#WINDOW_Find, 0, 0, #WINDOW_Find_Width, #WINDOW_Find_Height, #PB_Window_SystemMenu | #PB_Window_WindowCentered | #PB_Window_Invisible, Langage(72))
Left = 10 : Top = 10
CreateGadgetList(WindowID(#WINDOW_Find))
TextGadget (#GADGET_Find_Label1 , Left, Top+2, 90 , 18, Langage(73), #PB_Text_Right) : Left + 100 ; "Find :"
StringGadget(#GADGET_Find_FindWord, Left, Top , #WINDOW_Find_Width-Left-10, 20, GlobalFindText$) : Left = 10 : Top + 30
CheckBoxGadget(#GADGET_Find_EnableReplace, Left, Top+2, 90 , 18, Langage(74), #PB_CheckBox_Right) : Left + 100 ; "Replace with :"
StringGadget (#GADGET_Find_ReplaceWord , Left, Top , #WINDOW_Find_Width-Left-10, 20, GlobalReplaceText$) : Top + 30
CheckBoxGadget(#GADGET_Find_EnableWholeWord, Left, Top+2, 140, 18, Langage(75)) : Left + 150 ; "Whole word only"
CheckBoxGadget(#GADGET_Find_EnableMatchCase, Left, Top+2, 140, 18, Langage(76)) : Top + 35 ; "Match case"
ButtonWidth = #WINDOW_Find_Width/4
ButtonGadget (#GADGET_Find_Cancel , ButtonWidth*3, Top, ButtonWidth-10, 25, Langage(77)) ; "Cancel"
ButtonGadget (#GADGET_Find_ReplaceAll, 4+ButtonWidth*2, Top, ButtonWidth-10, 25, Langage(78)) ; "Replace All"
ButtonGadget (#GADGET_Find_Replace , 8+ButtonWidth , Top, ButtonWidth-10, 25, Langage(79)) ; "Replace"
ButtonGadget (#GADGET_Find_Next , 10 , Top, ButtonWidth-10, 25, Langage(80), #PB_Button_Default) ; "Next"
AddKeyboardShortcut(#WINDOW_Find, #PB_Shortcut_Return, #GADGET_Find_Next)
AddKeyboardShortcut(#WINDOW_Find, #PB_Shortcut_Escape, #GADGET_Find_Cancel)
SetGadgetState(#GADGET_Find_EnableReplace, State)
UpdateDisableState(State)
If GlobalFindFlags & #FIND_WholeWord : SetGadgetState(#GADGET_Find_EnableWholeWord,1) : EndIf
If GlobalFindFlags & #FIND_MatchCase : SetGadgetState(#GADGET_Find_EnableMatchCase,1) : EndIf
ActivateGadget(#GADGET_Find_FindWord)
; select text in FindWord
SendMessage_(GadgetID(#GADGET_Find_FindWord), #EM_SETSEL, 0, -1)
HideWindow(#WINDOW_Find, 0)
EndIf
EndProcedure