7df4e3bb1155d8cd9855f1ca4b0d9f51b9b0635b
[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             global %helps
29             helpbrowser(%helps(:,1), id, param, %f);
30         end
31     case "online"
32         if isExternal
33             msg = _("Help browser: Pages of external modules can''t be viewed online")
34             messagebox(msg, "modal")
35             return
36         end
37         if isSection
38             msg = _("Help browser: Tables of contents can''t be targeted online")
39             messagebox(msg, "modal")
40             return
41         end
42         v = getversion()
43         if grep(v, "-branch-") <> []
44             v = "current"
45         else
46             v = getversion("scilab")
47             v = msprintf("%d.%d.%d", v(1),v(2),v(3))
48         end
49         url = "https://help.scilab.org/docs/%s/%s/%s.html"
50         url = msprintf(url, v, currentLang, id)
51         openURL(url)
52
53     case "bugs"
54         if isExternal
55             msg = _("Help browser: Bugs of external modules can''t be listed.")
56             messagebox(msg, "modal")
57             return
58         end
59         if isSection
60             msg = _("Help browser: Table of contents can''t be targeted in Bugzilla")
61             messagebox(msg, "modal")
62             return
63         end
64         BugzillaSearch = "http://bugzilla.scilab.org/buglist.cgi" + ..
65           "?product=Scilab software&query_format=advanced" + ..
66           "&short_desc_type=regexp&short_desc=£"+..
67           "&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED" + ..
68           "&order=resolution,bug_id DESC"
69         if ~isdef("param","l") | type(param)<>10 | param(1)<>"unresolved"
70             BugzillaSearch = BugzillaSearch + "&bug_status=RESOLVED"
71         end
72         prepend = "(^|[^a-zA-Z_])"
73         append = "([^0-9a-zA-Z_%3B]|$)"
74         url = strsubst(BugzillaSearch, "£", prepend+"("+id+")"+append)
75         openURL(url)
76     end
77 endfunction
78
79 // ---------------------------------------------------------------------------
80
81 function openURL(url)
82     v = xmlGetValues("//web/body/web", ["default-browser" "command-browser"])
83     [default, cmd] = (v(1)=="true", v(2))
84
85     select getos()
86     case "Windows"
87         if default
88             winopen(url)
89         else
90             unix(msprintf("start """" %s ""%s""", v(2), url))
91         end
92
93     case "Linux"
94         if default, cmd = "xdg-open ", end
95         unix(cmd + """" + url + """")
96
97     case "Darwin"
98         if default, cmd = "open ", end
99         unix(cmd + """" + url + """")
100     end
101 endfunction
102