1. WEE online context sensitive help for GTK words

If you are always online it is much easier to use the online GTK documentation as opposed to downloading a bunch of GTK files into a directory and referencing that directory. This modified version of wee.exw context help procedure also includes my modification that automatically runs the view declaration routine if a html help article is not available for the current word - identifier.

9/16 2:53pm edited to use nm-online to detect if computer is connected to the internet.

global procedure context_help() 
      sequence text, decls, word, name_space, path 
      integer pos, junk 
      object help 
      text = get_edit_text() 
      pos = get_pos() 
      word = word_pos(text, pos) 
      if length(word) < 2 then 
            name_space = "" 
            word = "" 
      else 
            name_space = word[2] 
            word = word[1] 
      end if 
       
-- mods: load Gtk Widget help file. Must have Gtk html help files installed in ~/WEE/EuGTK/Docs    
-- uses NetworkManager command nm-online to determine if computer is online 
-- https://developer.gnome.org/NetworkManager/stable/nm-online.html 
if match("Gtk",word) = 1 then    
            if system_exec("nm-online -x") then -- offline  
                  ui_show_uri("FILE://"& canonical_path(sprintf("~/xwee/EuGTK/Docs/%s.html",{word}))) 
            else -- online 
                  ui_show_uri("https://developer.gnome.org/gtk3/stable/"& sprintf("%s.html",{word})) 
            end if 
            return 
      end if 
-- 
       
-- load the search.dat file 
if length(search_dat) = 0 then 
            sequence paths = include_search_paths 
            for i = 1 to length(paths) do 
                  path = paths[i] 
                  if path[$] = SLASH then 
                        path = path[1..$-1] 
                  end if 
                  path &= join_path({"..","docs","html"}) & SLASH 
                  --puts(1, path&"\n") 
                  integer f = open(path & "js" & SLASH & "search.js","r") 
                  if f != -1 then 
                        help_dir = canonical_path(path) 
                        if help_dir[$] != SLASH then 
                              help_dir &= SLASH 
                        end if 
                        object line = gets(f) 
                        while sequence(line) do 
                              integer x = find(':', line) 
                              if x and line[1] = '"' then 
                                    --puts(1, line[2..x-2]&" "&line[x+1..$]&"\n") 
                                    search_idx = append(search_idx, line[2..x-2]) 
                                    line = tr(line[x+1..$-1], "[]", "{}") 
                                    line = value(line) 
                                    search_dat = append(search_dat, line[2]) 
                              end if 
                              line = gets(f) 
                        end while 
                        close(f) 
                        exit 
                  end if 
            end for 
--            if length(search_dat) = 0 then 
--                  ui_message_box_error(window_title, "File not found: euphoria/docs/html/js/search.js") 
--                  return 
--            end if 
      end if 
       
      -- search search.dat for matching entry 
      help = {} 
      for i = 1 to length(search_idx) do 
            if equal(search_idx[i], word) then 
                  help = search_dat[i] 
                  exit 
            end if 
      end for 
      if atom(help) or length(help) = 0 then 
--                mod: automatically view declaration, if no help file available 
--                  view_declaration() 
--                  ui_message_box_error("Help",  
--                  "Didn't find any help on the topic: "&word& 
--                  "\nPlease put the cursor over an Euphoria identifier"& 
--                  "\nor standard library routine and try again.") 
                  ui_message_box_error("Help", 
                  "Didn't find any help on the topic: "&word&  
                  "\nWee will attempt display the words declaration") 
                  view_declaration() 
            return 
      end if 
      if length(help) > 1 then 
            -- multiple help entries 
            path = "" 
            decls = get_declarations(parse(text, file_name), pos, name_space) 
            for j = 1 to length(decls) by 2 do 
                  if equal(decls[j], word) then 
                        if atom(decls[j+1]) then 
                              path = file_name 
                        else 
                              path = decls[j+1][1] 
                        end if 
                         
                        for i = 1 to length(help) do 
                              if match(sreplace(help[i][1],"_",{SLASH})&".e", path) then 
                                    --show_help(help[i][1], help[i][2]) 
                                    ui_show_uri("file://" & help_dir & help[i][1] & ".html#" & help[i][2]) 
                                    return 
                              end if 
                        end for 
                  end if 
            end for 
      end if 
      -- only one help entry, just show it 
      --show_help(help[1][1], help[1][2]) 
      ui_show_uri("file://" & help_dir & help[1][1] & ".html#" & help[1][2]) 
end procedure 

Regards,
Kenneth Rhodes

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu