* Bug 10455 fixed: helpbrowser improved
[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     if id==[] then
20         id = basename(url)
21     end
22     isSection = grep(id, "/^section_/", "r") <> []
23     tmp = msprintf("#^jar:file:/%s/modules/helptools/jar#", SCI)
24     isExternal = grep(url, tmp, "r") == []
25
26     select action
27     case "changeLang"
28         if currentLang == param then
29             return
30         else
31             global %helps
32             helpbrowser(%helps(:,1), id, param, %f);
33
34             // Recording the new lang in user's profile
35             filename = SCIHOME + filesep() + "configuration.xml"
36             doc = xmlRead(filename)
37             xmlSetValues("//Setting/Profile/HelpBrowser", ["lang" ; param], doc)
38             xmlWrite(doc, filename);
39             xmlDelete(doc)
40         end
41     case "online"
42         if isExternal
43             msg = _("Help browser: Pages of external modules can''t be viewed online")
44             messagebox(msg, "modal")
45             return
46         end
47         if isSection
48             msg = _("Help browser: Tables of contents can''t be targeted online")
49             messagebox(msg, "modal")
50             return
51         end
52         v = getversion()
53         if grep(v, "-branch-") <> []
54             v = "current"
55         else
56             v = getversion("scilab")
57             v = msprintf("%d.%d.%d", v(1),v(2),v(3))
58         end
59         url = "https://help.scilab.org/docs/%s/%s/%s.html"
60         url = msprintf(url, v, currentLang, id)
61
62         openURL(url)
63
64     case "bugs"
65         if isExternal
66             msg = _("Help browser: Bugs of external modules can''t be listed.")
67             messagebox(msg, "modal")
68             return
69         end
70         if isSection
71             msg = _("Help browser: Table of contents can''t be targeted in Bugzilla")
72             messagebox(msg, "modal")
73             return
74         end
75         BugzillaSearch = "http://bugzilla.scilab.org/buglist.cgi" + ..
76           "?product=Scilab software&query_format=advanced" + ..
77           "&short_desc_type=regexp&short_desc=£"+..
78           "&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED" + ..
79           "&order=resolution,bug_id DESC"
80         if ~isdef("param","l") | type(param)<>10 | param(1)<>"unresolved"
81             BugzillaSearch = BugzillaSearch + "&bug_status=RESOLVED"
82         end
83         prepend = "(^|[^a-zA-Z_])"
84         append = "([^0-9a-zA-Z_%3B]|$)"
85         url = strsubst(BugzillaSearch, "£", prepend+"("+id+")"+append)
86         openURL(url)
87     end
88 endfunction
89
90 // ---------------------------------------------------------------------------
91
92 function openURL(url)
93     v = xmlGetValues("//web/body/web", ["default-browser" "command-browser"])
94     [default, cmd] = (v(1)=="true", v(2))
95
96     select getos()
97     case "Windows"
98         if default
99             winopen(url)
100         else
101             unix(msprintf("start """" %s ""%s""", v(2), url))
102         end
103
104     case "Linux"
105         if default, cmd = "xdg-open ", end
106         unix(cmd + """" + url + """")
107
108     case "Darwin"
109         if default, cmd = "open ", end
110         unix(cmd + """" + url + """")
111     end
112 endfunction
113