; --------------------------------------------------------------------------------------------; Copyright (c) Fantaisie Software. All rights reserved.; Dual licensed under the GPL and Fantaisie Software licenses.; See LICENSE and LICENSE-FANTAISIE in the project root for license information.; --------------------------------------------------------------------------------------------;; Crossplatform help viewer that uses the WebGadget for html display; and a contsnts/index file in xml (generated by docmaker);; Used only on Mac for now;CompilerIf #CompileMac; stores the urls for the index and contents table and search resultsGlobal NewList Help_Index.s()Global NewList Help_Contents.s()Global NewList Help_Search.s()Global HelpDirectory$Global HelpLanguage$Procedure SetHelpDirectory()CompilerIf #SpiderBasic; For now, we ship only english docHelpDirectory$ = PureBasicPath$+"help/"+LCase(#ProductName$)+"/"CompilerElseSelect UCase(CurrentLanguage$)Case "FRANCAIS"HelpDirectory$ = PureBasicPath$+"help/"+LCase(#ProductName$)+"_french/"Case "DEUTSCH"HelpDirectory$ = PureBasicPath$+"help/"+LCase(#ProductName$)+"_german/"DefaultHelpDirectory$ = PureBasicPath$+"help/"+LCase(#ProductName$)+"/"EndSelectCompilerEndIfEndProcedureProcedure LoadHelpPage(Url$)Debug "current: " + GetGadgetText(#GADGET_Help_Viewer)Debug "setting: " + Url$SetGadgetText(#GADGET_Help_Viewer, "file://" + ReplaceString(HelpDirectory,ドル " ", "%20") + Url$) ; we need escaped space as it's a web pathEndProcedureProcedure AddXMLHelpEntries(*Node, Sublevel); add all subitems of a contents entry to the help*Child = ChildXMLNode(*Node)While *ChildIf XMLNodeType(*Child) = #PB_XML_Normal And GetXMLNodeName(*Child) = "entry"; add gadget entryAddGadgetItem(#GADGET_Help_Tree, -1, GetXMLAttribute(*Child, "title"), 0, Sublevel); add url entryAddElement(Help_Contents())Help_Contents() = GetXMLAttribute(*Child, "url"); add any child entriesAddXMLHelpEntries(*Child, Sublevel+1)EndIf*Child = NextXMLNode(*Child)WendEndProcedureProcedure LoadHelpIndex(); Load the contents tree;ClearList(Help_Contents())ClearGadgetItems(#GADGET_Help_Tree)If LoadXML(#XML_Help, HelpDirectory$ + "contents.xml"); do not check XMLStatus, just use whatever got loaded correctly in any case*Contents = MainXMLNode(#XML_Help)If *Contents And GetXMLNodeName(*Contents) = "contents"AddXMLHelpEntries(*Contents, 0)EndIfFreeXML(#XML_Help)EndIf; Load the index file;ClearList(Help_Index())ClearGadgetItems(#GADGET_Help_Index)If LoadXML(#XML_Help, HelpDirectory$ + "index.xml")*Index = MainXMLNode(#XML_Help)If *Index And GetXMLNodeName(*Index) = "index"*Child = ChildXMLNode(*Index)While *ChildIf XMLNodeType(*Child) = #PB_XML_Normal And GetXMLNodeName(*Child) = "entry"; add gadget entryAddGadgetItem(#GADGET_Help_Index, -1, GetXMLAttribute(*Child, "title")); add url entryAddElement(Help_Index())Help_Index() = GetXMLAttribute(*Child, "url")EndIf*Child = NextXMLNode(*Child)WendEndIfFreeXML(#XML_Help)EndIfEndProcedureProcedure OpenHelpWindow()HelpLanguage$ = CurrentLanguage$SetHelpDirectory()If IsWindow(#WINDOW_Help) = 0Flags = #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget | #PB_Window_InvisibleIf HelpWindowX = -1 And HelpWindowY = -1Flags | #PB_Window_ScreenCenteredEndIfIf HelpWindowMaximizedFlags | #PB_Window_MaximizeEndIfIf OpenWindow(#WINDOW_Help, HelpWindowX, HelpWindowY, HelpWindowWidth, HelpWindowHeight, Language("Help","Title"), Flags)ContainerGadget(#GADGET_Help_Container, 0, 0, 0, 0, #PB_Container_BorderLess)ButtonImageGadget(#GADGET_Help_Back, 0, 0, 0, 0, ImageID(#IMAGE_Help_Back))ButtonImageGadget(#GADGET_Help_Forward, 0, 0, 0, 0, ImageID(#IMAGE_Help_Forward))ButtonImageGadget(#GADGET_Help_Home, 0, 0, 0, 0, ImageID(#IMAGE_Help_Home))ButtonImageGadget(#GADGET_Help_Previous,0, 0, 0, 0, ImageID(#IMAGE_Help_Previous))ButtonImageGadget(#GADGET_Help_Next, 0, 0, 0, 0, ImageID(#IMAGE_Help_Next))WebGadget(#GADGET_Help_Viewer, 0, 0, 0, 0, "file://" + ReplaceString(HelpDirectory,ドル " ", "%20") + "reference/reference.html") ; we need escaped space as it's a web pathCloseGadgetList()GadgetToolTip(#GADGET_Help_Back, Language("Help","Back"))GadgetToolTip(#GADGET_Help_Forward, Language("Help","Forward"))GadgetToolTip(#GADGET_Help_Home, Language("Help","Home"))GadgetToolTip(#GADGET_Help_Previous,Language("Help","Previous"))GadgetToolTip(#GADGET_Help_Next, Language("Help","Next"))PanelGadget(#GADGET_Help_Panel, 0, 0, 0, 0)AddGadgetItem(#GADGET_Help_Panel, -1, Language("Help", "Contents"))TreeGadget(#GADGET_Help_Tree, 0, 0, 0, 0)AddGadgetItem(#GADGET_Help_Panel, -1, Language("Help", "Index"))ListViewGadget(#GADGET_Help_Index, 0, 0, 0, 0)AddGadgetItem(#GADGET_Help_Panel, -1, Language("Help", "Search"))StringGadget(#GADGET_Help_SearchValue, 10, 10, 0, 25, "")ButtonGadget(#GADGET_Help_SearchGo, 0, 45, 100, 25, Language("Help", "StartSearch"))ListViewGadget(#GADGET_Help_SearchResults, 0, 80, 0, 0)CloseGadgetList()SplitterGadget(#GADGET_Help_Splitter, 5, 10+HelpButtonHeight, HelpWindowWidth-10, HelpWindowHeight-15-HelpButtonHeight, #GADGET_Help_Panel, #GADGET_Help_Container, #PB_Splitter_Vertical)LoadHelpIndex() ; load the index/contents and fill the gadgetsAddKeyboardShortcut(#WINDOW_Help, #PB_Shortcut_Return, #MENU_Help_Enter)EnsureWindowOnDesktop(#WINDOW_Help)HideWindow(#WINDOW_Help, 0)ResizeGadget(#GADGET_Help_Splitter, 5, 10+HelpButtonHeight, WindowWidth(#WINDOW_Help)-10, WindowHeight(#WINDOW_Help)-15-HelpButtonHeight)SetGadgetState(#GADGET_Help_Splitter, HelpWindowSplitter)HelpWindowEvents(#PB_Event_SizeWindow)EndIfElseSetWindowForeground(#WINDOW_Help)EndIfEndProcedureProcedure SearchHelpFile(Url,ドル Text$)Length = Len(Text$)match = 0title = 0Title$ = ""; The html files are small. We can load them fully into memory for a fast search;If ReadFile(#FILE_HelpSearch, HelpDirectory$+Url$)Size = Lof(#FILE_HelpSearch)If Size > 0 ; just a sanity check*Buffer = AllocateMemory(Size+SizeOf(Character)) ; null char at the end for for simple CompareMEmoryStringIf *BufferReadData(#FILE_HelpSearch, *Buffer, Size); Note: this assumes that the IDE is compiled in ascii (as the html file is ascii too)*Cursor.Ascii = *BufferSize - LengthWhile Size > 0 And (match = 0 Or title = 0) ; need to find a matching word and a title tagIf CompareMemoryString(*Cursor, ToAscii(Text$), #PB_String_NoCase, Length, #PB_Ascii) = #PB_String_Equal; matchmatch = 1*Cursor + LengthSize - LengthElseIf CompareMemoryString(*Cursor, ToAscii("<title>"), #PB_String_NoCase, 7, #PB_Ascii) = #PB_String_Equal; title tagtitle = 1*TitleEnd = *Cursor + 7While Size > (*TitleEnd - *Cursor) And CompareMemoryString(*TitleEnd, ToAscii("</title>"), #PB_String_NoCase, 8, #PB_Ascii) <> #PB_String_Equal*TitleEnd + 1WendTitle$ = Trim(PeekS(*Cursor+7, *TitleEnd - *Cursor - 7, #PB_Ascii))*Cursor + 7 ; just jump over the <title> so the title text is searched too!Size - 7ElseIf *Cursor\a = '<'; other tag (do not search in tags)*Cursor + 1Size - 1While Size > 0 And *Cursor\a <> '>'*Cursor + 1Size - 1Wend*Cursor + 1 ; skip >Size - 1ElseSize - 1*Cursor + 1EndIfWendFreeMemory(*Buffer)EndIfEndIfCloseFile(#FILE_HelpSearch)EndIfIf matchAddGadgetItem(#GADGET_Help_SearchResults, -1, Title$)AddElement(Help_Search())Help_Search() = Url$EndIfEndProcedureProcedure ResizeHelpSplitterContent(); Panel partPanelWidth = GetGadgetAttribute(#GADGET_Help_Panel, #PB_Panel_ItemWidth)PanelHeight = GetGadgetAttribute(#GADGET_Help_Panel, #PB_Panel_ItemHeight)GetRequiredSize(#GADGET_Help_SearchGo, @ButtonWidth, @ButtonHeight)ButtonWidth = Max(ButtonWidth, 100)StringHeight = GetRequiredHeight(#GADGET_Help_SearchValue)ResizeGadget(#GADGET_Help_Tree , 0, 0, PanelWidth, PanelHeight)ResizeGadget(#GADGET_Help_Index , 0, 0, PanelWidth, PanelHeight)ResizeGadget(#GADGET_Help_SearchValue , 10, 10, PanelWidth-20, StringHeight)ResizeGadget(#GADGET_Help_SearchGo , (PanelWidth-ButtonWidth)/2, 20+StringHeight, ButtonWidth, ButtonHeight)ResizeGadget(#GADGET_Help_SearchResults, 0, 30+StringHeight+ButtonHeight, PanelWidth, PanelHeight-30-StringHeight-ButtonHeight); Viewer partWidth = GadgetWidth(#GADGET_Help_Container)Height = GadgetHeight(#GADGET_Help_Container)GetRequiredSize(#GADGET_Help_Back, @ButtonWidth, @ButtonHeight)ResizeGadget(#GADGET_Help_Back, 2, 0, ButtonWidth, ButtonHeight) ; Don't use 0 as x axis, as on OS X the splitter do some artefactsResizeGadget(#GADGET_Help_Forward, 10+ButtonWidth, 0, ButtonWidth, ButtonHeight)ResizeGadget(#GADGET_Help_Home, 18+ButtonWidth*2, 0, ButtonWidth, ButtonHeight)ResizeGadget(#GADGET_Help_Previous, Width-13-ButtonWidth*2, 0, ButtonWidth, ButtonHeight)ResizeGadget(#GADGET_Help_Next, Width-5-ButtonWidth, 0, ButtonWidth, ButtonHeight)ResizeGadget(#GADGET_Help_Viewer, 2, 10+ButtonHeight, Width-4, Height-10-ButtonHeight)EndProcedureProcedure ResizeHelpWindow()ResizeGadget(#GADGET_Help_Splitter, 5, 10+HelpButtonHeight, WindowWidth(#WINDOW_Help)-10, WindowHeight(#WINDOW_Help)-15-HelpButtonHeight)EndProcedureProcedure HelpWindowEvents(EventID)If EventID = #PB_Event_GadgetEventGadget = EventGadget()ElseIf EventID = #PB_Event_MenuIf EventMenu() = #MENU_Help_Enter And GetActiveGadget() = #GADGET_Help_SearchValueEventID = #PB_Event_GadgetEventGadget = #GADGET_Help_SearchGoEndIfEndIfSelect EventIDCase #PB_Event_CloseWindowIf MemorizeWindow And IsWindowMinimized(#WINDOW_Help) = 0HelpWindowMaximized = IsWindowMaximized(#WINDOW_Help)If HelpWindowMaximized = 0HelpWindowX = WindowX(#WINDOW_Help)HelpWindowY = WindowY(#WINDOW_Help)HelpWindowWidth = WindowWidth(#WINDOW_Help)HelpWindowHeight = WindowHeight(#WINDOW_Help)EndIfHelpWindowSplitter = GetGadgetState(#GADGET_Help_Splitter)EndIfCloseWindow(#WINDOW_Help)Case #PB_Event_GadgetSelect EventGadgetCase #GADGET_Help_Treeindex = GetGadgetState(#GADGET_Help_Tree)If index <> -1SelectElement(Help_Contents(), index)LoadHelpPage(Help_Contents())EndIfCase #GADGET_Help_Indexindex = GetGadgetState(#GADGET_Help_Index)If index <> -1SelectElement(Help_Index(), index)LoadHelpPage(Help_Index())EndIfCase #GADGET_Help_HomeLoadHelpPage("reference/reference.html")Case #GADGET_Help_BackSetGadgetState(#GADGET_Help_Viewer, #PB_Web_Back)Case #GADGET_Help_ForwardSetGadgetState(#GADGET_Help_Viewer, #PB_Web_Forward)Case #GADGET_Help_Previous, #GADGET_Help_NextUrl$ = GetGadgetText(#GADGET_Help_Viewer)Url$ = ReplaceString(Right(Url,ドル Len(Url$)-Len(HelpDirectory$)-7), "%20", " ") ; cut the base and "file://", and unescape the URL; find this url in the contents to get the next/previous chapter entryForEach Help_Contents()If IsEqualFile(Url,ドル Help_Contents()) ; do not use simple compare, as GetGadgetText on WebGadget/OSX changes the casing of the namesSublevel = GetGadgetItemAttribute(#GADGET_Help_Tree, ListIndex(Help_Contents()), #PB_Tree_SubLevel); the next/previous entry in the chapter is the next/previous in the list, but only; if it has the same sublevel in the contents tree;If EventGadget = #GADGET_Help_PreviousResult = PreviousElement(Help_Contents())ElseResult = NextElement(Help_Contents())EndIfIf Result And GetGadgetItemAttribute(#GADGET_Help_Tree, ListIndex(Help_Contents()), #PB_Tree_SubLevel) = SublevelLoadHelpPage(Help_Contents())EndIfBreakEndIfNext Help_Contents()Case #GADGET_Help_SearchGoClearGadgetItems(#GADGET_Help_SearchResults)ClearList(Help_Search())Search$ = Trim(GetGadgetText(#GADGET_Help_SearchValue)); The html help is organized in one level of directories with html files inside;If Search$ <> ""If ExamineDirectory(0, HelpDirectory,ドル "*")While NextDirectoryEntry(0)If DirectoryEntryType(0) = #PB_DirectoryEntry_DirectoryDirectory$ = DirectoryEntryName(0)If Directory$ <> "." And Directory$ <> ".."; search directory contentIf ExamineDirectory(1, HelpDirectory$ + Directory,ドル "*.html")While NextDirectoryEntry(1)If DirectoryEntryType(1) = #PB_DirectoryEntry_File; search the file contentSearchHelpFile(Directory$ + "/" + DirectoryEntryName(1), Search$)EndIfWendFinishDirectory(1)EndIfEndIfEndIfWendFinishDirectory(0)EndIfEndIfIf ListSize(Help_Search()) = 0 ; no results foundAddGadgetItem(#GADGET_Help_SearchResults, 0, Language("Help", "NoResults"))AddElement(Help_Search())Help_Search() = "reference/reference.html" ; in case the user clicks thisEndIfCase #GADGET_Help_SearchResultsindex = GetGadgetState(#GADGET_Help_SearchResults)If index <> -1SelectElement(Help_Search(), index)LoadHelpPage(Help_Search())EndIfCase #GADGET_Help_SplitterResizeHelpSplitterContent()EndSelectCase #PB_Event_SizeWindowResizeHelpWindow()EndSelectEndProcedureProcedure UpdateHelpWindow()SetWindowTitle(#WINDOW_Help, Language("Help","Title"))SetGadgetAttribute(#GADGET_Help_Back, #PB_Button_Image, ImageID(#IMAGE_Help_Back)) ; possible theme changeSetGadgetAttribute(#GADGET_Help_Forward, #PB_Button_Image, ImageID(#IMAGE_Help_Forward))SetGadgetAttribute(#GADGET_Help_Home, #PB_Button_Image, ImageID(#IMAGE_Help_Home))SetGadgetAttribute(#GADGET_Help_Previous, #PB_Button_Image, ImageID(#IMAGE_Help_Previous))SetGadgetAttribute(#GADGET_Help_Next, #PB_Button_Image, ImageID(#IMAGE_Help_Next))GadgetToolTip(#GADGET_Help_Back, Language("Help","Back"))GadgetToolTip(#GADGET_Help_Forward, Language("Help","Forward"))GadgetToolTip(#GADGET_Help_Home, Language("Help","Home"))GadgetToolTip(#GADGET_Help_Previous,Language("Help","Previous"))GadgetToolTip(#GADGET_Help_Next, Language("Help","Next"))SetGadgetText(#GADGET_Help_SearchGo, Language("Help", "StartSearch"))SetGadgetItemText(#GADGET_Help_Panel, 0, Language("Help", "Contents"), 0)SetGadgetItemText(#GADGET_Help_Panel, 1, Language("Help", "Index"), 0)SetGadgetItemText(#GADGET_Help_Panel, 2, Language("Help", "Search"), 0)HelpWindowEvents(#PB_Event_SizeWindow); Reload the index, content and show the reference page if the language changed;If HelpLanguage$ <> CurrentLanguage$HelpLanguage$ = CurrentLanguage$SetHelpDirectory()LoadHelpIndex()LoadHelpPage("reference/reference.html")ClearGadgetItems(#GADGET_Help_SearchResults)ClearList(Help_Search())EndIfEndProcedureProcedure DisplayHelp(CurrentWord$)SetHelpDirectory()If CheckPureBasicKeyWords(CurrentWord$) <> ""HelpFile$ = CheckPureBasicKeyWords(CurrentWord$)+".html"ElseCurrentWord$ = LCase(CurrentWord$)For k=0 To NbBasicFunctions-1If CurrentWord$ = LCase(BasicFunctions(k)\Name$); We don't have the matching table for a function, so scan every directories to find the file;DirID = ExamineDirectory(#PB_Any, HelpDirectory,ドル "*")If DirIDWhile NextDirectoryEntry(DirID)If DirectoryEntryType(DirID) = #PB_DirectoryEntry_DirectoryIf FileSize(HelpDirectory$+DirectoryEntryName(DirID)+"/"+CurrentWord$+".html") > 0HelpFile$ = DirectoryEntryName(DirID)+"/"+CurrentWord$+".html"EndIfEndIfWendFinishDirectory(DirID)EndIfBreakEndIfNextEndIfIf HelpFile$ = ""HelpFile$ = "reference/reference.html"EndIfIf UseHelpToolF1 And HelpToolOpenSetGadgetText(#GADGET_HelpTool_Viewer, "file://"+ReplaceString(HelpDirectory,ドル " ", "%20")+HelpFile$) ; we need escaped space as it's a web pathActivateTool("HelpTool") ; switches to the toolElseOpenHelpWindow()LoadHelpPage(HelpFile$)EndIfEndProcedureCompilerEndIf
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。