mirror of
https://github.com/koreader/koreader
synced 2024-11-16 06:12:56 +00:00
6e35e683dd
This plugin mostly sets up a "Text editor>" submenu, that allows browsing files, creating a new file, and managing a history of previously opened file for easier re-opening. It restore previous scroll and cursor positions on re-opening. Additional "Check lua" syntax button is added when editing a .lua file, and prevent saving if errors. The text editing is mainly provided by the enhanced InputDialog. InputDialog: added a few more options, the main one being 'save_callback', which will add a Save and Close buttons and manage saving/discarding/exiting. If "fullscreen" and "add_nav_bar", will add a show/hide keyboard button to it. Moved the preset buttons setup code in their own InputDialog methods for clarity of the main init code. Buttons are now enabled/disabled depending on context for feedback (eg: Save is disabled as long as text has not been modified). Added util.checkLuaSyntax(lua_string), might be useful elsewhere.
117 lines
3.2 KiB
Lua
117 lines
3.2 KiB
Lua
--[[--
|
|
This widget displays a login dialog with a username and password.
|
|
]]
|
|
|
|
local Blitbuffer = require("ffi/blitbuffer")
|
|
local CenterContainer = require("ui/widget/container/centercontainer")
|
|
local FrameContainer = require("ui/widget/container/framecontainer")
|
|
local Geom = require("ui/geometry")
|
|
local InputDialog = require("ui/widget/inputdialog")
|
|
local InputText = require("ui/widget/inputtext")
|
|
local Size = require("ui/size")
|
|
local UIManager = require("ui/uimanager")
|
|
local VerticalGroup = require("ui/widget/verticalgroup")
|
|
local _ = require("gettext")
|
|
local Screen = require("device").screen
|
|
|
|
local LoginDialog = InputDialog:extend{
|
|
username = "",
|
|
username_hint = "username",
|
|
password = "",
|
|
password_hint = "password",
|
|
}
|
|
|
|
function LoginDialog:init()
|
|
-- init title and buttons in base class
|
|
InputDialog.init(self)
|
|
self.input_username = InputText:new{
|
|
text = self.username,
|
|
hint = self.username_hint,
|
|
face = self.input_face,
|
|
width = self.width * 0.9,
|
|
focused = true,
|
|
scroll = false,
|
|
parent = self,
|
|
}
|
|
|
|
self.input_password = InputText:new{
|
|
text = self.password,
|
|
hint = self.password_hint,
|
|
face = self.input_face,
|
|
width = self.width * 0.9,
|
|
text_type = "password",
|
|
focused = false,
|
|
scroll = false,
|
|
parent = self,
|
|
}
|
|
|
|
self.dialog_frame = FrameContainer:new{
|
|
radius = Size.radius.window,
|
|
padding = 0,
|
|
margin = 0,
|
|
background = Blitbuffer.COLOR_WHITE,
|
|
VerticalGroup:new{
|
|
align = "left",
|
|
self.title_widget,
|
|
self.title_bar,
|
|
-- username input
|
|
CenterContainer:new{
|
|
dimen = Geom:new{
|
|
w = self.title_bar:getSize().w,
|
|
h = self.input_username:getSize().h,
|
|
},
|
|
self.input_username,
|
|
},
|
|
-- password input
|
|
CenterContainer:new{
|
|
dimen = Geom:new{
|
|
w = self.title_bar:getSize().w,
|
|
h = self.input_password:getSize().h,
|
|
},
|
|
self.input_password,
|
|
},
|
|
-- buttons
|
|
CenterContainer:new{
|
|
dimen = Geom:new{
|
|
w = self.title_bar:getSize().w,
|
|
h = self.button_table:getSize().h,
|
|
},
|
|
self.button_table,
|
|
}
|
|
}
|
|
}
|
|
|
|
self._input_widget = self.input_username
|
|
|
|
self[1] = CenterContainer:new{
|
|
dimen = Geom:new{
|
|
w = Screen:getWidth(),
|
|
h = Screen:getHeight() - self._input_widget:getKeyboardDimen().h,
|
|
},
|
|
self.dialog_frame,
|
|
}
|
|
end
|
|
|
|
function LoginDialog:getCredential()
|
|
local username = self.input_username:getText()
|
|
local password = self.input_password:getText()
|
|
return username, password
|
|
end
|
|
|
|
function LoginDialog:onSwitchFocus(inputbox)
|
|
-- unfocus current inputbox
|
|
self._input_widget:unfocus()
|
|
self._input_widget:onCloseKeyboard()
|
|
UIManager:close(self)
|
|
|
|
-- focus new inputbox
|
|
self._input_widget = inputbox
|
|
self._input_widget:focus()
|
|
self._input_widget:onShowKeyboard()
|
|
|
|
UIManager:show(self)
|
|
end
|
|
|
|
return LoginDialog
|
|
|