Text editor plugin, InputDialog enhancements (#4135)

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.
This commit is contained in:
poire-z
2018-08-06 21:16:30 +02:00
committed by GitHub
parent 1d18b01cf7
commit 6e35e683dd
11 changed files with 927 additions and 62 deletions

View File

@@ -29,6 +29,7 @@ local ButtonTable = FocusManager:new{
function ButtonTable:init()
self.selected = { x = 1, y = 1 }
self.buttons_layout = {}
self.button_by_id = {}
self.container = VerticalGroup:new{ width = self.width }
table.insert(self, self.container)
if self.zero_sep then
@@ -61,6 +62,9 @@ function ButtonTable:init()
text_font_size = self.button_font_size,
show_parent = self.show_parent,
}
if btn_entry.id then
self.button_by_id[btn_entry.id] = button
end
local button_dim = button:getSize()
local vertical_sep = LineWidget:new{
background = Blitbuffer.COLOR_GREY,
@@ -121,4 +125,8 @@ function ButtonTable:onSelectByKeyPress()
end
end
function ButtonTable:getButtonById(id)
return self.button_by_id[id] -- nil if not found
end
return ButtonTable