* Bugs 9909 12889 fixed: helpbrowser improved (LANG, www, issues)
[scilab.git] / scilab / modules / helptools / macros / helpbrowser_menus_cb.sci
1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) 2020 - Samuel GOUGEON
3 //
4 // This file is hereby licensed under the terms of the GNU GPL v2.0,
5 // pursuant to article 5.3.4 of the CeCILL v.2.1.
6 // This file was originally licensed under the terms of the CeCILL v2.1,
7 // and continues to be available under such terms.
8 // For more information, see the COPYING file which you should have received
9 // along with this program.
10
11 function helpbrowser_menus_cb(action, param)
12     // PRIVATE function used by the help browser
13
14     jimport org.scilab.modules.gui.helpbrowser.ScilabHelpBrowser
15     hb = ScilabHelpBrowser.getHelpBrowserWithoutCreation()
16     url = hb.getCurrentURL()
17     [?,?,?, currentLang] = regexp(url, "/scilab_(.+?)_help.jar/")
18     id = hb.getCurrentID()
19     isSection = grep(id, "/^section_/", "r") <> []
20     tmp = msprintf("#^jar:file:/%s/modules/helptools/jar#", SCI)
21     isExternal = grep(url, tmp, "r") == []
22
23     select action
24     case "changeLang"
25         if currentLang == param then
26             return
27         else
28             hb.close()
29             global %helps
30             helpbrowser(%helps(:,1), id, param, %f);
31         end
32     case "online"
33         if isExternal
34             msg = _("Help browser: Pages of external modules can''t be viewed online")
35             messagebox(msg, "modal")
36             return
37         end
38         if isSection
39             msg = _("Help browser: Tables of contents can''t be targeted online")
40             messagebox(msg, "modal")
41             return
42         end
43         v = getversion("scilab")
44         v = msprintf("%d.%d.%d", v(1),v(2),v(3))
45         url = "https://help.scilab.org/docs/%s/%s/%s.html"
46         url = msprintf(url,v, currentLang, id)
47         openURL(url)
48
49     case "bugs"
50         if isExternal
51             msg = _("Help browser: Bugs of external modules can''t be listed.")
52             messagebox(msg, "modal")
53             return
54         end
55         if isSection
56             msg = _("Help browser: Table of contents can''t be targeted in Bugzilla")
57             messagebox(msg, "modal")
58             return
59         end
60         BugzillaSearch = "http://bugzilla.scilab.org/buglist.cgi" + ..
61           "?product=Scilab software&query_format=advanced" + ..
62           "&short_desc_type=regexp&short_desc=£"+..
63           "&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED" + ..
64           "&order=resolution,bug_id DESC"
65         if ~isdef("param","l") | type(param)<>10 | param(1)<>"unresolved"
66             BugzillaSearch = BugzillaSearch + "&bug_status=RESOLVED"
67         end
68         prepend = "(^|[^a-zA-Z_])"
69         append = "([^0-9a-zA-Z_%3B]|$)"
70         url = strsubst(BugzillaSearch, "£", prepend+"("+id+")"+append)
71         openURL(url)
72     end
73 endfunction
74
75 // ---------------------------------------------------------------------------
76
77 function openURL(url)
78     v = xmlGetValues("//web/body/web", ["default-browser" "command-browser"])
79     [default, cmd] = (v(1)=="true", v(2))
80
81     select getos()
82     case "Windows"
83         if default
84             winopen(url)
85         else
86             unix(msprintf("start """" %s ""%s""", v(2), url))
87         end
88
89     case "Linux"
90         if default, cmd = "xdg-open ", end
91         unix(cmd + """" + url + """")
92
93     case "Darwin"
94         if default, cmd = "open ", end
95         unix(cmd + """" + url + """")
96     end
97 endfunction
98