Quick "Fuzzy Help" hack

Mac OSX specific forum
User avatar
Piero
Addict
Addict
Posts: 914
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Quick "Fuzzy Help" hack

Post by Piero »

Quick "Fuzzy Help" hack ;)

NEVER FORGET you can also search https://www.purebasic.com/documentation/PureBasic.pdf (and often quickly get even better help/infos, if you have a good PDF reader like Skim)

Notes:
Dear Fred…
IDE tools seem to have "focus problems" when they use a parameter (I tried some AS "activation" tricks)… in this case it's not a big deal, but see when you search for 'file'… (you get an "unfocused AS list dialog")
Did you also guillotine the google bot? It seems bad, especially @finding Forum [code] stuff…

Code: Select all

; IDE tool, Parameter: %WORD (help on current PB word, but a bit different from standard PB help…)

#helppath$="/Applications/PureBasic.app/Contents/Resources/help/purebasic/"
#ind=#helppath$+"reference/reference.html" ; default

fi$="https://www.purebasic.fr/english/index.php" ; default
#forum="https://www.purebasic.fr/english/search.php?keywords="

fig$="https://www.google.com/" ; default
; adding '/documentation ' excludes non-english help docs:
#forumg="https://www.google.com/search?q=site:purebasic.fr OR site:purebasic.com/documentation "
; Bookmark (JS snippet) to search selection (MULTIPLE words) with a browser (e.g., FireFox):
; javascript:window.open('https://www.google.com/search?q=site:purebasic.fr OR site:purebasic.com/documentation '+document.getSelection());

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) + ~"\n"
         EndIf
      Wend
      CloseProgram(shell)
   EndIf
   ProcedureReturn RTrim(Output$,~"\n")
EndProcedure

Procedure ResizeWebWindow()
   ResizeGadget(10, #PB_Ignore, #PB_Ignore, WindowWidth(0), WindowHeight(0)-52)
   ResizeGadget(4, #PB_Ignore, #PB_Ignore, WindowWidth(0)-410, #PB_Ignore)
   ResizeGadget(5, WindowWidth(0)-220, #PB_Ignore, #PB_Ignore, #PB_Ignore)
   ResizeGadget(6, WindowWidth(0)-70, #PB_Ignore, #PB_Ignore, #PB_Ignore)
   ResizeGadget(7, WindowWidth(0)-140, #PB_Ignore, #PB_Ignore, #PB_Ignore)
EndProcedure

wl2$= ProgramParameter()
;  wl2$= "file" ; "" ; "runtime" ; "" ; tests

If OpenWindow(0, 0, 0, 1024, 868, "Help for: "+wl2$, #PB_Window_Invisible| #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget)
   CreateStatusBar(0, WindowID(0))
   AddStatusBarField(#PB_Ignore)
   StatusBarText(0, 0, "Welcome to the Help MiniBrowser!", 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$) ; wl$ ?!? this is definitely a RAW hack !!!
   ButtonGadget(5, 0, 3, 80, 25, "Browser")
   ButtonGadget(6, 0, 3, 70, 25, "Forum")
   ButtonGadget(7, 0, 3, 70, 25, "Google")
   If WebGadget(10, 0, 31, 0, 0, "") = 0
      MessageRequester("Error", "Webkit library not found", 0)
      End ; Quit
   EndIf
   BindEvent(#PB_Event_SizeWindow, @ResizeWebWindow())
   ResizeWebWindow() ; Adjust the gadget to the current window size
   
   wl$=wl2$
   if wl$
      s.s=sh("grep -i '"+wl$+"' "+#helppath$+~"index.xml | awk -F'\"' '{ print $(NF-1) }' | sort -u")
      if CountString(s,~"\n")
         s=sh(~"osascript\n choose from list (paragraphs of \"" + s + ~"\")")
      EndIf   
      s=#helppath$+ s
   EndIf
   if s = #helppath$+"false" or s = #helppath$ or wl$ = ""
      wl$=#ind
      If wl2$
         fi$= URLEncoder(#forum+wl2$)
         fig$= URLEncoder(#forumg+wl2$)
      EndIf
   else
      wl$= URLEncoder(s)
      fi$= URLEncoder(#forum+wl2$)
      fig$= URLEncoder(#forumg+wl2$)
   EndIf
   SetGadgetText(10, wl$)
   HideWindow (0,#False)
   
   Repeat
      Event = WaitWindowEvent(10)
      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
                  RunProgram("open",GetGadgetText(10),"")
               Case 6
                  SetGadgetText(10, fi$)
               Case 7
                  SetGadgetText(10, fig$)
            EndSelect
            SetGadgetText(4, GetGadgetText(10))
         Case #PB_Event_Menu 
            Select EventMenu()
               Case #PB_Menu_Quit
                  End
            EndSelect
         Case #PB_Event_CloseWindow
            End
      EndSelect
   ForEver
EndIf
User avatar
Piero
Addict
Addict
Posts: 914
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Update

Post by Piero »

Brute-force AS hack ;) to fix (some "AS" IDE tools') "focus problems" without having to use 2 programs:

Code: Select all

if CountString(s,~"\n")
   s=sh(~"osascript\n set pp to (paragraphs of \"" + s + ~"\") \ntell app \"System Events\" to set lp to a reference to item -1 of (processes whose visible is true)\n"+
      ~"tell app \"purebasic\"\nactivate\n set p to choose from list pp default items (item 1 of pp) \nend\ntell app \"System Events\" to set frontmost of lp to true\n p")
EndIf

Tested on 621 sequoia
User avatar
Piero
Addict
Addict
Posts: 914
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Skim.app selection search in PureBasic.pdf

Post by Piero »

Code: Select all

-- AppleScript PB IDE Tool for Skim selection search in PureBasic.pdf
property pbpdf : "~/Desktop/PureBasic.pdf" -- with ~/ use a path without spaces… else you can 'quote it'
tell application "PureBasic" to activate -- just in case (needed only for app launchers/debug)
tell application "System Events"
	set scint to a reference to text area 1 of scroll area 1 of group 1 of group 1 of splitter group 1 of splitter group 1 of item 1 of (windows of application process "PureBasic" whose name begins with "PureBasic") -- in this case, only for better code readability…
	tell scint to set sel to value of attribute "AXSelectedText"
	tell application "Skim" to activate
	do shell script "open -a Skim " & pbpdf
	delay 0.3 -- just in case 
	tell application process "skim" to keystroke "f" using {option down, command down}
	delay 0.7 -- in case of panel closed
	if sel ≠ "" then tell application process "skim" to keystroke sel
end tell
Post Reply