Debian Codegraph @

CorsixTH/Lua/dialogs/resizables/file_browsers/choose_font.lua

raw
1 --[[ Copyright (c) 2013 Edvin "Lego3" Linge
2
3 Permission is hereby granted, free of charge, to any person obtaining a copy of
4 this software and associated documentation files (the "Software"), to deal in
5 the Software without restriction, including without limitation the rights to
6 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7 of the Software, and to permit persons to whom the Software is furnished to do
8 so, subject to the following conditions:
9
10 The above copyright notice and this permission notice shall be included in all
11 copies or substantial portions of the Software.
12
13 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 SOFTWARE. --]]
20
21 local TH = require("TH")
22 local lfsext = TH.lfsExt()
23
24 --! Window where the user can choose a font file.
25 class "UIChooseFont" (UIFileBrowser)
26
27 ---@type UIChooseFont
28 local UIChooseFont = _G["UIChooseFont"]
29
30 function UIChooseFont:UIChooseFont(ui, mode)
31 -- Create the root item (or items, on Windows).
32 local root
33 local roots = lfsext.volumes()
34 if #roots > 1 then
35 for k, v in pairs(roots) do
36 roots[k] = FilteredFileTreeNode(v, {".ttc", ".otf", ".ttf"})
37 end
38 root = DummyRootNode(roots)
39 else
40 root = FilteredFileTreeNode(roots[1], {".ttc", ".otf", ".ttf"})
41 end
42 self:UIFileBrowser(ui, mode, _S.font_location_window.caption:format(".ttc, .otf, .ttf"), 265, root)
43 end
44
45 --! Function called by clicking button of existing save #num
46 function UIChooseFont:choiceMade(name)
47 local app = TheApp
48 app.config.unicode_font = name
49 app:saveConfig()
50 app.gfx:loadFontFile()
51 if class.is(self.parent, UIOptions) then
52 self.parent:checkForAvailableLanguages()
53 end
54 self:close()
55 end
56
57 function UIChooseFont:close()
58 UIResizable.close(self)
59 if self.mode == "menu" then
60 self.ui:addWindow(UIFolder(self.ui, self.mode))
61 end
62 end