Code: Select all
#helppath$="/Applications/PureBasic.app/Contents/Resources/help/purebasic/"
#ind=#helppath$+"reference/reference.html"
Procedure.s sh(search$)
Protected Output$, shell
shell = RunProgram("/bin/sh","","",
#PB_Program_Open|#PB_Program_Write|#PB_Program_Read)
If shell
WriteProgramStringN(shell,search$)
WriteProgramData(shell,#PB_Program_Eof,0)
While ProgramRunning(shell)
If AvailableProgramOutput(shell)
Output$ + ReadProgramString(shell)
EndIf
Wend
CloseProgram(shell)
EndIf
ProcedureReturn Output$
EndProcedure
wl$=ProgramParameter()
if wl$
s.s=#helppath$+sh("grep -i '"+wl$+"' "+#helppath$+~"index.xml | awk -F'\"' '{ print $(NF-1) }' | head -n 1")
EndIf
if s = #helppath$ or wl$ = ""
wl$=#ind
else
wl$ = URLEncoder(s)
EndIf
Enumeration
#Kbd_CmdQ
#Kbd_ret
EndEnumeration
Procedure ResizeWebWindow()
ResizeGadget(10, #PB_Ignore, #PB_Ignore, WindowWidth(0), WindowHeight(0)-52)
ResizeGadget(4, #PB_Ignore, #PB_Ignore, WindowWidth(0)-250, #PB_Ignore)
ResizeGadget(5, WindowWidth(0)-60, #PB_Ignore, #PB_Ignore, #PB_Ignore)
; ResizeGadget(6, #PB_Ignore, #PB_Ignore, WindowWidth(0), #PB_Ignore)
EndProcedure
If OpenWindow(0, 100, 200, 800, 800, "PureBasic MiniBrowser v1.0", #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget)
CreateStatusBar(0, WindowID(0))
AddStatusBarField(#PB_Ignore)
StatusBarText(0, 0, "Welcome to the world's smallest Browser !", 0)
ButtonGadget(1, 0, 3, 60, 25, "Back")
ButtonGadget(2, 60, 3, 60, 25, "Next")
ButtonGadget(3, 120, 3, 60, 25, "Stop")
StringGadget(4, 185, 5, 0, 20, wl$)
ButtonGadget(5, 0, 3, 60, 25, "Go")
;FrameGadget(6, 0, 30, 0, 2, "", 2) ; Nice little separator
If WebGadget(10, 0, 31, 0, 0, wl$) = 0
MessageRequester("Error", "Webkit library not found", 0)
End ; Quit
EndIf
AddKeyboardShortcut(0, #PB_Shortcut_Return, #Kbd_ret)
AddKeyboardShortcut(0, #PB_Shortcut_Command| #PB_Shortcut_Q, #Kbd_CmdQ)
; Use bindevent() to have a realtime window resize
BindEvent(#PB_Event_SizeWindow, @ResizeWebWindow())
ResizeWebWindow() ; Adjust the gadget to the current window size
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Gadget
Select EventGadget()
Case 1
SetGadgetState(10, #PB_Web_Back)
Case 2
SetGadgetState(10, #PB_Web_Forward)
Case 3
SetGadgetState(10, #PB_Web_Stop)
Case 5
SetGadgetText(10, GetGadgetText(4))
EndSelect
Case #PB_Event_Menu
Select EventMenu()
Case #Kbd_CmdQ, #PB_Menu_Quit
CloseWindow(0)
End
case #Kbd_ret
SetGadgetText(10, #ind)
EndSelect
EndSelect
Until Event = #PB_Event_CloseWindow
EndIf