Template for history of Find

Share your advanced PureBasic knowledge/code with the community.
User avatar
gurj
Enthusiast
Enthusiast
Posts: 658
Joined: Thu Jan 22, 2009 3:48 am
Location: china
Contact:

Template for history of Find

Post by gurj »

updated 3 time
Template for history of Find

Code: Select all

;line51 add SetGadgetState(1,0):g1=0,ok,for win pb5.61
;ComboBoxGadget() bug To pbIDE's Find/Replace bug
;also try line17 to ComboBoxGadget(1, 105, 0, 305, 25);,#PB_ComboBox_Editable)

; For [Find],If Not use SetGadgetState(1,0):g1=0
;   will is bug Or wrong.
; because If Removed Item=GetGadgetState(1) And Item>-1,Editable will=""
; see line38:
;      If g1>0
;        RemoveGadgetItem(1,g1+1)
; optimised and update to:
; Template for history of Find
; http://www.purebasic.fr/english/viewtopic.php?f=12&t=69173

OpenWindow(0, 0, 0, 415, 140, "Find", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
TextGadget(0, 30, 5, 70, 25, "Search for:")
ComboBoxGadget(1, 105, 0, 305, 25,#PB_ComboBox_Editable)
ButtonGadget(2, 5, 110, 100, 25, "Find Next")

For a=0 To 3
 AddGadgetItem(1,a,Str(a))
Next
SetGadgetText(1,"-1")

g1=GetGadgetState(1)
#maxCount=5;CountGadgetItems(1)<=#maxCount;********
Repeat:ev=WaitWindowEvent():Select ev
  Case #PB_Event_Gadget:eg=EventGadget()
   Select eg
     
    Case 1:g1=GetGadgetState(1)
     
    Case 2:g1s.s= GetGadgetText(1)
     If g1s<>"":If g1<>0
       b=CountGadgetItems(1)
       AddGadgetItem(1,0,g1s)
       ;-{**********:
       If g1>0
        RemoveGadgetItem(1,g1+1)
        ;}**********
       Else;g1=-1
        For a=1 To b
         If GetGadgetItemText(1,a,0)=g1s
          RemoveGadgetItem(1,a):Break
         EndIf
         If b=#maxCount
          RemoveGadgetItem(1,#maxCount)
         EndIf
        Next
       EndIf
       SetGadgetState(1,0):g1=0
      EndIf
      ;-{find in ... , add your codes here}
     EndIf
   EndSelect
   
  Case #PB_Event_CloseWindow:Break
EndSelect:ForEver
End
Last edited by gurj on Sat Sep 30, 2017 2:34 pm, edited 2 times in total.
my pb for chinese:
http://ataorj.ys168.com
User avatar
gurj
Enthusiast
Enthusiast
Posts: 658
Joined: Thu Jan 22, 2009 3:48 am
Location: china
Contact:

Re: Template for history of Find

Post by gurj »

optimised
updated 2 for 1 optimised:'ElseIf g1=-1' to 'Else'
updated 1 for 1 wrong.
my pb for chinese:
http://ataorj.ys168.com
Post Reply