Hi Well here`s a constant viewer with reverse look up via number also double rmb click to search the net at the current constant. Constant.txt file is for pb v5.60.
. constant.txt list to large.
zebuddi.
Code: Select all
EnableExplicit
CompilerIf #PB_Compiler_Thread = 0
MessageRequester("Compiler Options", "Please CheckMark (Create Thread Safe) in the Compiler Options")
End
CompilerEndIf
;{- Enumerations / DataSections
;{ Windows
Enumeration
#Window_Main
EndEnumeration
;}
;{ Gadgets
Enumeration
#ListIcon_procs
#String_Search
#StatusBar_Window
#ListIcon
#checkbox
EndEnumeration
;}
Define.l Event, EventWindow, EventGadget, EventType, EventMenu
;}
Structure nslist
name.s
value.s
List procs.s()
EndStructure
Structure condata
constant.s
List procs.s()
EndStructure
Global NewList fileString.s()
Global NewList condata.condata()
Global NewList nslist.nslist() ; track from file on disk NSList.txt
Global title$ = "Pure Constant Finder"
Procedure Do_AssoProcData(List fileString.s(), List condata.condata())
Protected a$
If ReadFile(0, "constants.txt")
While Not Eof(0)
a$ = ReadString(0 ,#PB_Ascii)
If Left(a$, 10) = "Migration_"
a$ = "Possibly Depricated or Changed - See Current PureBasic Manual For Latest Info"
EndIf
AddElement(fileString())
fileString() = a$
Wend
CloseFile(0)
EndIf
With condata()
ForEach fileString()
If Left(fileString(), 4) = "#PB_"
AddElement(condata())
\constant = fileString()
Else
AddElement(condata())
AddElement(\procs())
\procs() = fileString()
EndIf
Next
EndWith
EndProcedure
Procedure.s _FormatNumber(number.i)
Protected s.s=Str(number), i
i=Len(s)
While i>3
i-3
s=InsertString(s,",",i+1)
Wend
ProcedureReturn s
EndProcedure
Procedure do_list() ; parse file names.txt and fill nslist structured linkedlist
Protected a$, p
If ReadFile(0,"C:\Users\Dufus\AppData\Roaming\PureBasic\tools\Constants.txt")
; MessageRequester("",GetCurrentDirectory()+"Constants.txt")
With nslist()
While Eof(0)=0
a$=ReadString(0,ReadStringFormat(0))
p=FindString(a$," = ")
AddElement(nslist())
\name=Left(a$,p-1)
\value=Right(a$,(Len(a$)-(p+2)))
Wend
EndWith
CloseFile(0)
EndIf
EndProcedure
Procedure OpenWindow_Main()
If OpenWindow(#Window_Main, 450, 32, 497, 573, title$, #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_TitleBar|#PB_Window_ScreenCentered|#PB_Window_SizeGadget)
If CreateStatusBar(#StatusBar_Window, WindowID(#Window_Main))
AddStatusBarField(350)
AddStatusBarField(147)
EndIf
ListIconGadget(#ListIcon, 0, 0, 497, 325, "Nb", 60, #PB_ListIcon_AlwaysShowSelection|#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect)
AddGadgetColumn(#ListIcon,2,"Constant",237)
AddGadgetColumn(#ListIcon,3,"value",230)
GadgetToolTip(#ListIcon,"Double Right Click For Web Search")
SetGadgetColor(#ListIcon, #PB_Gadget_LineColor, $D3D3D3 )
ListIconGadget(#ListIcon_procs, 0, 346, 497, 180, "Nb",60, #PB_ListIcon_AlwaysShowSelection|#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect)
AddGadgetColumn(#ListIcon_procs,1,"PB Associated Procedures",437)
GadgetToolTip(#ListIcon_procs,"Double left Click For Web Search")
SetGadgetColor(#ListIcon_procs, #PB_Gadget_LineColor, $D3D3D3 )
CheckBoxGadget(#checkbox, 420, 326, 70, 20,"#PB Only")
StringGadget(#String_Search, 0, 525, 497, 25, "")
SetActiveGadget(#String_Search)
SetGadgetColor(#ListIcon,#PB_Gadget_BackColor,$80FFFF)
SetGadgetColor(#ListIcon_procs,#PB_Gadget_BackColor,$80FFFF)
SetGadgetColor(#String_Search,#PB_Gadget_BackColor, $1FF6F5)
StickyWindow(#Window_Main , #True)
EndIf
EndProcedure
Procedure.b IsNumeric(string.s)
If Val(String) > 0
ProcedureReturn #True
Else
ProcedureReturn #False
EndIf
EndProcedure
Procedure check(aaa) ; threaded auto update routine
Protected check$, match_counter,ag, initgadget=0, oldcheck$, st.i, checkbox_state.b
checkbox_state = GetGadgetState(#checkbox)
Debug "in"
Repeat
oldcheck$=GetGadgetText(#String_Search)
Delay(575)
If oldcheck$<>GetGadgetText(#String_Search) Or GetGadgetState(#checkbox) <> checkbox_state ;If changed
checkbox_state = GetGadgetState(#checkbox)
ClearGadgetItems(#ListIcon_procs)
ClearGadgetItems(#ListIcon)
check$=GetGadgetText(#String_Search)
If check$>""
ForEach nslist()
If FindString(LCase(nslist()\name),LCase(check$)) Or FindString(LCase(nslist()\value),LCase(check$)) ; match in either name or value definition in the linkedlist
If IsNumeric(check$)
If Val(check$) = Val(nslist()\value)
If GetGadgetState(#checkbox) = #PB_Checkbox_Checked
If Left(nslist()\name, 4) = "#PB_"
match_counter+1
AddGadgetItem(#ListIcon,-1, Str(match_counter) + ". "+Chr(10) + nslist()\name +Chr(10)+nslist()\value)
EndIf
Else
match_counter+1
AddGadgetItem(#ListIcon,-1, Str(match_counter) + ". "+Chr(10) + nslist()\name +Chr(10)+nslist()\value)
EndIf
EndIf
Else
If GetGadgetState(#checkbox) = #PB_Checkbox_Checked
If Left(nslist()\name, 4) = "#PB_"
match_counter+1
AddGadgetItem(#ListIcon,-1, Str(match_counter) + ". "+Chr(10) + nslist()\name +Chr(10)+nslist()\value)
EndIf
Else
match_counter+1
AddGadgetItem(#ListIcon,-1, Str(match_counter) + ". "+Chr(10) + nslist()\name +Chr(10)+nslist()\value)
EndIf
EndIf
If GetGadgetText(#String_Search)<>check$ ; check if user altered search term if true abandon current search
Break
EndIf
EndIf
Next
If match_counter=0
AddGadgetItem(#ListIcon,-1,Chr(10)+"No Match`s Found")
EndIf
StatusBarText(#StatusBar_Window,0,"Found "+_FormatNumber(match_counter)+" Matches")
EndIf
If GetGadgetText(#String_Search)="" ; search term is empty clear listview
match_counter=0
ClearGadgetItems(#ListIcon)
StatusBarText(#StatusBar_Window,0,"No Search Term")
EndIf
EndIf
st=0
match_counter=0
SetActiveGadget(#String_Search)
ForEver
EndProcedure
Procedure showprocs()
Protected listpos, selectedtext.s, counter = 0
ClearGadgetItems(#ListIcon_procs)
listpos = GetGadgetState(#ListIcon)
selectedtext = GetGadgetItemText(#ListIcon, listpos, 1)
With condata()
ForEach condata()
If \constant = selectedtext
ForEach \procs()
counter + 1
AddGadgetItem(#ListIcon_procs, -1, Str(counter) + Chr(10) + \procs()+"()")
Debug "at: " + Str(ListIndex(condata())) + " " + \procs()
Next
EndIf
Next
EndWith
EndProcedure
Procedure showbrowser()
Protected selectedtext.s
selectedtext = GetGadgetItemText(#ListIcon, GetGadgetState(#ListIcon), 1)
If Left(selectedtext, 4) = "#PB_"
RunProgram("https://www.google.co.uk/search?q=site:http://www.purebasic.fr/english+&gws_rd=cr,ssl&ei=pGIxVtKbJMz-aZHev4AO#q=%23"+selectedtext)
Else
RunProgram("http://social.msdn.microsoft.com/search/en-us/windows/desktop?query="+RemoveString(selectedtext, Chr(35))+Chr(38)+"Function Refinement=181")
EndIf
EndProcedure
Procedure showassociatedprocs()
Protected selectedtext.s = GetGadgetItemText(#ListIcon_procs, GetGadgetState(#ListIcon_procs), 1)
RunProgram("https://www.google.co.uk/search?q=site:http://www.purebasic.fr/english+&gws_rd=cr,ssl&ei=pGIxVtKbJMz-aZHev4AO#q=%23"+Left(selectedtext, Len(selectedtext)-1))
EndProcedure
do_list()
Do_AssoProcData(fileString(), condata())
OpenWindow_Main()
SetWindowTitle(#Window_Main,title$ + " " + _FormatNumber(ListSize(nslist()))+" Constants Found ")
Define selectedtext.s, listpos, s$
BindGadgetEvent(#ListIcon, @showprocs(), #PB_EventType_LeftClick)
BindGadgetEvent(#ListIcon, @showbrowser(), #PB_EventType_RightDoubleClick)
BindGadgetEvent(#ListIcon_procs, @showassociatedprocs(), #PB_EventType_RightDoubleClick )
Define mythread=CreateThread(@check(),0)
;{- Event loop
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_CloseWindow
EventWindow = EventWindow()
If EventWindow = #Window_Main
FreeList(nslist())
CloseWindow(#Window_Main)
Break
EndIf
EndSelect
ForEver
;
;}