2016-05-02 02:39:31 +00:00
|
|
|
--[[--
|
|
|
|
Widget for taking user input.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2019-10-20 14:43:28 +00:00
|
|
|
local InputDialog = require("ui/widget/inputdialog")
|
|
|
|
local @{ui.uimanager|UIManager} = require("ui/uimanager")
|
|
|
|
local @{logger} = require("logger")
|
|
|
|
local @{gettext|_} = require("gettext")
|
|
|
|
|
2016-05-02 02:39:31 +00:00
|
|
|
local sample_input
|
|
|
|
sample_input = InputDialog:new{
|
|
|
|
title = _("Dialog title"),
|
|
|
|
input = "default value",
|
2019-10-20 14:43:28 +00:00
|
|
|
-- A placeholder text shown in the text box.
|
|
|
|
input_hint = _("Hint text"),
|
2021-12-01 11:37:18 +00:00
|
|
|
-- input_type = nil, -- default for text
|
2019-10-20 14:43:28 +00:00
|
|
|
-- A description shown above the input.
|
|
|
|
description = _("Some more description."),
|
2016-06-26 00:53:08 +00:00
|
|
|
-- text_type = "password",
|
2016-05-02 02:39:31 +00:00
|
|
|
buttons = {
|
|
|
|
{
|
|
|
|
{
|
|
|
|
text = _("Cancel"),
|
2022-03-04 20:20:00 +00:00
|
|
|
id = "close",
|
2016-05-02 02:39:31 +00:00
|
|
|
callback = function()
|
|
|
|
UIManager:close(sample_input)
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text = _("Save"),
|
2016-05-26 06:09:49 +00:00
|
|
|
-- button with is_enter_default set to true will be
|
|
|
|
-- triggered after user press the enter key from keyboard
|
|
|
|
is_enter_default = true,
|
|
|
|
callback = function()
|
2019-10-20 14:43:28 +00:00
|
|
|
logger.dbg("Got user input as raw text:", sample_input:getInputText())
|
|
|
|
logger.dbg("Got user input as value:", sample_input:getInputValue())
|
2016-05-26 06:09:49 +00:00
|
|
|
end,
|
2016-05-02 02:39:31 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
UIManager:show(sample_input)
|
2018-03-30 10:46:36 +00:00
|
|
|
sample_input:onShowKeyboard()
|
2016-05-02 02:39:31 +00:00
|
|
|
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
To get a full screen text editor, use:
|
2019-10-20 14:43:28 +00:00
|
|
|
fullscreen = true, -- No need to provide any height and width.
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
condensed = true,
|
|
|
|
allow_newline = true,
|
|
|
|
cursor_at_end = false,
|
|
|
|
-- and one of these:
|
|
|
|
add_scroll_buttons = true,
|
|
|
|
add_nav_bar = true,
|
|
|
|
|
2018-08-06 19:16:30 +00:00
|
|
|
To add |Save|Close| buttons, use:
|
|
|
|
save_callback = function(content, closing)
|
2019-10-20 14:43:28 +00:00
|
|
|
-- ...Deal with the edited content...
|
2018-08-06 19:16:30 +00:00
|
|
|
if closing then
|
2019-10-20 14:43:28 +00:00
|
|
|
UIManager:nextTick(
|
|
|
|
-- Stuff to do when InputDialog is closed, if anything.
|
|
|
|
)
|
2018-08-06 19:16:30 +00:00
|
|
|
end
|
|
|
|
return nil -- sucess, default notification shown
|
|
|
|
return true, success_notif_text
|
|
|
|
return false, error_infomsg_text
|
|
|
|
end
|
2019-10-20 14:43:28 +00:00
|
|
|
|
2018-08-06 19:16:30 +00:00
|
|
|
To additionally add a Reset button and have |Reset|Save|Close|, use:
|
|
|
|
reset_callback = function()
|
|
|
|
return original_content -- success
|
|
|
|
return original_content, success_notif_text
|
|
|
|
return nil, error_infomsg_text
|
|
|
|
end
|
2019-10-20 14:43:28 +00:00
|
|
|
|
2018-08-06 19:16:30 +00:00
|
|
|
If you don't need more buttons than these, use these options for consistency
|
|
|
|
between dialogs, and don't provide any buttons.
|
|
|
|
Text used on these buttons and their messages and notifications can be
|
|
|
|
changed by providing alternative text with these additional options:
|
|
|
|
reset_button_text
|
|
|
|
save_button_text
|
|
|
|
close_button_text
|
|
|
|
close_unsaved_confirm_text
|
|
|
|
close_cancel_button_text
|
|
|
|
close_discard_button_text
|
|
|
|
close_save_button_text
|
|
|
|
close_discarded_notif_text
|
|
|
|
|
2017-04-04 13:31:13 +00:00
|
|
|
If it would take the user more than half a minute to recover from a mistake,
|
|
|
|
a "Cancel" button <em>must</em> be added to the dialog. The cancellation button
|
|
|
|
should be kept on the left and the button executing the action on the right.
|
|
|
|
|
|
|
|
It is strongly recommended to use a text describing the action to be
|
|
|
|
executed, as demonstrated in the example above. If the resulting phrase would be
|
|
|
|
longer than three words it should just read "OK".
|
|
|
|
|
2016-05-02 02:39:31 +00:00
|
|
|
]]
|
|
|
|
|
2017-03-27 04:42:58 +00:00
|
|
|
local Blitbuffer = require("ffi/blitbuffer")
|
2013-10-18 20:38:07 +00:00
|
|
|
local ButtonTable = require("ui/widget/buttontable")
|
2017-03-27 04:42:58 +00:00
|
|
|
local CenterContainer = require("ui/widget/container/centercontainer")
|
2021-07-15 14:28:54 +00:00
|
|
|
local CheckButton = require("ui/widget/checkbutton")
|
2018-03-30 10:46:36 +00:00
|
|
|
local Device = require("device")
|
2022-03-04 20:20:00 +00:00
|
|
|
local FocusManager = require("ui/widget/focusmanager")
|
2017-03-27 04:42:58 +00:00
|
|
|
local Font = require("ui/font")
|
|
|
|
local FrameContainer = require("ui/widget/container/framecontainer")
|
|
|
|
local Geom = require("ui/geometry")
|
2021-06-29 09:01:12 +00:00
|
|
|
local GestureRange = require("ui/gesturerange")
|
2018-08-06 19:16:30 +00:00
|
|
|
local InfoMessage = require("ui/widget/infomessage")
|
2013-10-18 20:38:07 +00:00
|
|
|
local InputText = require("ui/widget/inputtext")
|
2018-01-29 20:27:24 +00:00
|
|
|
local MovableContainer = require("ui/widget/container/movablecontainer")
|
2018-08-06 19:16:30 +00:00
|
|
|
local MultiConfirmBox = require("ui/widget/multiconfirmbox")
|
|
|
|
local Notification = require("ui/widget/notification")
|
2017-09-13 14:56:20 +00:00
|
|
|
local Size = require("ui/size")
|
2022-01-20 10:36:35 +00:00
|
|
|
local TitleBar = require("ui/widget/titlebar")
|
2013-10-18 20:38:07 +00:00
|
|
|
local UIManager = require("ui/uimanager")
|
2017-10-08 15:53:25 +00:00
|
|
|
local VerticalGroup = require("ui/widget/verticalgroup")
|
|
|
|
local VerticalSpan = require("ui/widget/verticalspan")
|
2018-03-30 10:46:36 +00:00
|
|
|
local Screen = Device.screen
|
2021-05-16 10:45:36 +00:00
|
|
|
local T = require("ffi/util").template
|
2022-09-13 21:09:49 +00:00
|
|
|
local util = require("util")
|
2018-08-06 19:16:30 +00:00
|
|
|
local _ = require("gettext")
|
2013-07-30 15:07:33 +00:00
|
|
|
|
Clarify our OOP semantics across the codebase (#9586)
Basically:
* Use `extend` for class definitions
* Use `new` for object instantiations
That includes some minor code cleanups along the way:
* Updated `Widget`'s docs to make the semantics clearer.
* Removed `should_restrict_JIT` (it's been dead code since https://github.com/koreader/android-luajit-launcher/pull/283)
* Minor refactoring of LuaSettings/LuaData/LuaDefaults/DocSettings to behave (mostly, they are instantiated via `open` instead of `new`) like everything else and handle inheritance properly (i.e., DocSettings is now a proper LuaSettings subclass).
* Default to `WidgetContainer` instead of `InputContainer` for stuff that doesn't actually setup key/gesture events.
* Ditto for explicit `*Listener` only classes, make sure they're based on `EventListener` instead of something uselessly fancier.
* Unless absolutely necessary, do not store references in class objects, ever; only values. Instead, always store references in instances, to avoid both sneaky inheritance issues, and sneaky GC pinning of stale references.
* ReaderUI: Fix one such issue with its `active_widgets` array, with critical implications, as it essentially pinned *all* of ReaderUI's modules, including their reference to the `Document` instance (i.e., that was a big-ass leak).
* Terminal: Make sure the shell is killed on plugin teardown.
* InputText: Fix Home/End/Del physical keys to behave sensibly.
* InputContainer/WidgetContainer: If necessary, compute self.dimen at paintTo time (previously, only InputContainers did, which might have had something to do with random widgets unconcerned about input using it as a baseclass instead of WidgetContainer...).
* OverlapGroup: Compute self.dimen at *init* time, because for some reason it needs to do that, but do it directly in OverlapGroup instead of going through a weird WidgetContainer method that it was the sole user of.
* ReaderCropping: Under no circumstances should a Document instance member (here, self.bbox) risk being `nil`ed!
* Kobo: Minor code cleanups.
2022-10-06 00:14:48 +00:00
|
|
|
local InputDialog = FocusManager:extend{
|
2018-03-30 10:46:36 +00:00
|
|
|
is_always_active = true,
|
2014-03-13 13:52:43 +00:00
|
|
|
title = "",
|
|
|
|
input = "",
|
|
|
|
input_hint = "",
|
2017-03-27 04:42:58 +00:00
|
|
|
description = nil,
|
2014-03-13 13:52:43 +00:00
|
|
|
buttons = nil,
|
|
|
|
input_type = nil,
|
2021-06-29 19:42:18 +00:00
|
|
|
deny_keyboard_hiding = false, -- don't hide keyboard on tap outside
|
2014-03-13 13:52:43 +00:00
|
|
|
enter_callback = nil,
|
Terminal emulator: full rewrite, real vt52 emulator (#8636)
New real terminal emulator, replacing the old plugin.
The emulator is basically a vt52 terminal (enriched with
some ANSI-sequences, as ash, vi and mksh don't behave well
on a vt52 term).
So far working: ash, mksh, bash, nano, vi, busybox, watch...
The input supports: tab-completion; cursor movement;
backspace; start of line, end of line (long press);
page up, page down (long press).
User scripts may be placed in the koterm.koplugin/scripts/
folder, aliases can be put in the file aliases and startup
command in the file profile.user in that folder.
2022-01-28 19:33:09 +00:00
|
|
|
strike_callback = nil, -- call this on every keystroke (used by Terminal plugin's TermInputText)
|
|
|
|
inputtext_class = InputText, -- (Terminal plugin provides TermInputText)
|
2018-08-06 19:16:30 +00:00
|
|
|
readonly = false, -- don't allow editing, will not show keyboard
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
allow_newline = false, -- allow entering new lines (this disables any enter_callback)
|
|
|
|
cursor_at_end = true, -- starts with cursor at end of text, ready for appending
|
2021-11-28 22:30:15 +00:00
|
|
|
use_available_height = false, -- adjust input box to fill available height on screen
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
fullscreen = false, -- adjust to full screen minus keyboard
|
|
|
|
condensed = false, -- true will prevent adding air and balance between elements
|
|
|
|
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
|
|
|
|
add_nav_bar = false, -- append a row of page navigation buttons
|
2018-08-06 19:16:30 +00:00
|
|
|
-- note that the text widget can be scrolled with Swipe North/South even when no button
|
|
|
|
keyboard_hidden = false, -- start with keyboard hidden in full fullscreen mode
|
|
|
|
-- needs add_nav_bar to have a Show keyboard button to get it back
|
2018-08-10 16:05:09 +00:00
|
|
|
scroll_by_pan = false, -- allow scrolling by lines with Pan (= Swipe, but wait a bit at end
|
|
|
|
-- of gesture before releasing) (may conflict with movable)
|
2018-08-06 19:16:30 +00:00
|
|
|
|
|
|
|
-- If save_callback provided, a Save and a Close buttons will be added to the first row
|
|
|
|
-- if reset_callback provided, a Reset button will be added (before Save) to the first row
|
|
|
|
save_callback = nil, -- Called with the input text content when Save (and true as 2nd arg
|
|
|
|
-- if closing, false if non-closing Save).
|
|
|
|
-- Should return nil or true on success, false on failure.
|
|
|
|
-- (This save_callback can do some syntax check before saving)
|
|
|
|
reset_callback = nil, -- Called with no arg, should return the original content on success,
|
|
|
|
-- nil on failure.
|
|
|
|
-- Both these callbacks can return a string as a 2nd return value.
|
|
|
|
-- This string is then shown:
|
|
|
|
-- - on success: as the notification text instead of the default one
|
|
|
|
-- - on failure: in an InfoMessage
|
2018-09-04 21:55:58 +00:00
|
|
|
close_callback = nil, -- Called when closing (if discarded or saved, after save_callback if saved)
|
2020-06-08 18:47:31 +00:00
|
|
|
edited_callback = nil, -- Called on each text modification
|
2018-08-06 19:16:30 +00:00
|
|
|
|
|
|
|
-- For use by TextEditor plugin:
|
|
|
|
view_pos_callback = nil, -- Called with no arg to get initial top_line_num/charpos,
|
|
|
|
-- called with (top_line_num, charpos) to give back position on close.
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
|
2021-06-29 09:01:12 +00:00
|
|
|
-- Set to false if movable gestures conflicts with subwidgets gestures
|
|
|
|
is_movable = true,
|
2014-04-23 14:19:29 +00:00
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
width = nil,
|
2014-04-23 14:19:29 +00:00
|
|
|
|
2016-02-02 17:38:14 +00:00
|
|
|
text_width = nil,
|
|
|
|
text_height = nil,
|
|
|
|
|
2022-01-20 10:36:35 +00:00
|
|
|
bottom_v_padding = 0,
|
2017-04-29 08:38:09 +00:00
|
|
|
input_face = Font:getFace("x_smallinfofont"),
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
input_padding = Size.padding.default,
|
2017-09-13 14:56:20 +00:00
|
|
|
input_margin = Size.margin.default,
|
2017-10-08 15:53:25 +00:00
|
|
|
button_padding = Size.padding.default,
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
border_size = Size.border.window,
|
2018-08-06 19:16:30 +00:00
|
|
|
|
2019-12-06 21:55:35 +00:00
|
|
|
-- See TextBoxWidget for details about these options
|
|
|
|
alignment = "left",
|
|
|
|
justified = false,
|
|
|
|
lang = nil,
|
|
|
|
para_direction_rtl = nil,
|
|
|
|
auto_para_direction = false,
|
|
|
|
alignment_strict = false,
|
|
|
|
|
2018-08-06 19:16:30 +00:00
|
|
|
-- for internal use
|
|
|
|
_text_modified = false, -- previous known modified status
|
|
|
|
_top_line_num = nil,
|
|
|
|
_charpos = nil,
|
|
|
|
_buttons_edit_callback = nil,
|
|
|
|
_buttons_scroll_callback = nil,
|
|
|
|
_buttons_backup_done = false,
|
|
|
|
_buttons_backup = nil,
|
2013-07-30 15:07:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function InputDialog:init()
|
2022-03-04 20:20:00 +00:00
|
|
|
self.layout = {{}}
|
2021-09-17 17:36:57 +00:00
|
|
|
self.screen_width = Screen:getWidth()
|
|
|
|
self.screen_height = Screen:getHeight()
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
if self.fullscreen then
|
2021-06-29 09:01:12 +00:00
|
|
|
self.is_movable = false
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
self.border_size = 0
|
2021-09-17 17:36:57 +00:00
|
|
|
self.width = self.screen_width - 2*self.border_size
|
2018-08-06 19:16:30 +00:00
|
|
|
self.covers_fullscreen = true -- hint for UIManager:_repaint()
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
else
|
2021-09-17 17:36:57 +00:00
|
|
|
self.width = self.width or math.floor(math.min(self.screen_width, self.screen_height) * 0.8)
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
end
|
|
|
|
if self.condensed then
|
|
|
|
self.text_width = self.width - 2*(self.border_size + self.input_padding + self.input_margin)
|
|
|
|
else
|
2020-06-12 23:56:36 +00:00
|
|
|
self.text_width = self.text_width or math.floor(self.width * 0.9)
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
end
|
2018-08-06 19:16:30 +00:00
|
|
|
if self.readonly then -- hide keyboard if we can't edit
|
|
|
|
self.keyboard_hidden = true
|
|
|
|
end
|
2021-06-29 19:42:18 +00:00
|
|
|
if self.fullscreen or self.add_nav_bar then
|
|
|
|
self.deny_keyboard_hiding = true
|
|
|
|
end
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
|
|
|
|
-- Title & description
|
2022-01-20 10:36:35 +00:00
|
|
|
self.title_bar = TitleBar:new{
|
|
|
|
width = self.width,
|
|
|
|
align = "left",
|
|
|
|
with_bottom_line = true,
|
|
|
|
title = self.title,
|
|
|
|
title_multilines = true,
|
|
|
|
bottom_v_padding = self.bottom_v_padding,
|
|
|
|
info_text = self.description,
|
|
|
|
show_parent = self,
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
-- Vertical spaces added before and after InputText
|
|
|
|
-- (these will be adjusted later to center the input text if needed)
|
|
|
|
-- (can be disabled by setting condensed=true)
|
2022-01-20 10:36:35 +00:00
|
|
|
local padding_width = self.condensed and 0 or Size.padding.default
|
|
|
|
local vspan_before_input_text = VerticalSpan:new{ width = padding_width }
|
|
|
|
local vspan_after_input_text = VerticalSpan:new{ width = padding_width }
|
2017-03-27 04:42:58 +00:00
|
|
|
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
-- Buttons
|
2018-08-06 19:16:30 +00:00
|
|
|
-- In case of re-init(), keep backup of original buttons and restore them
|
|
|
|
self:_backupRestoreButtons()
|
|
|
|
-- If requested, add predefined buttons alongside provided ones
|
|
|
|
if self.save_callback then
|
|
|
|
-- If save_callback provided, adds (Reset) / Save / Close buttons
|
|
|
|
self:_addSaveCloseButtons()
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
end
|
2018-08-06 19:16:30 +00:00
|
|
|
if self.add_nav_bar then -- Home / End / Up / Down buttons
|
|
|
|
self:_addScrollButtons(true)
|
|
|
|
elseif self.add_scroll_buttons then -- Up / Down buttons
|
|
|
|
self:_addScrollButtons(false)
|
|
|
|
end
|
|
|
|
-- Buttons Table
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
self.button_table = ButtonTable:new{
|
|
|
|
width = self.width - 2*self.button_padding,
|
|
|
|
button_font_face = "cfont",
|
|
|
|
button_font_size = 20,
|
|
|
|
buttons = self.buttons,
|
|
|
|
zero_sep = true,
|
|
|
|
show_parent = self,
|
|
|
|
}
|
|
|
|
local buttons_container = CenterContainer:new{
|
|
|
|
dimen = Geom:new{
|
|
|
|
w = self.width,
|
|
|
|
h = self.button_table:getSize().h,
|
|
|
|
},
|
|
|
|
self.button_table,
|
|
|
|
}
|
|
|
|
|
2019-11-25 13:31:54 +00:00
|
|
|
-- Remember provided text_height if any (to restore it on keyboard height change)
|
|
|
|
if self.orig_text_height == nil then
|
|
|
|
if self.text_height then
|
|
|
|
self.orig_text_height = self.text_height
|
|
|
|
else
|
|
|
|
self.orig_text_height = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
-- InputText
|
|
|
|
if not self.text_height or self.fullscreen then
|
|
|
|
-- We need to find the best height to avoid screen overflow
|
|
|
|
-- Create a dummy input widget to get some metrics
|
Terminal emulator: full rewrite, real vt52 emulator (#8636)
New real terminal emulator, replacing the old plugin.
The emulator is basically a vt52 terminal (enriched with
some ANSI-sequences, as ash, vi and mksh don't behave well
on a vt52 term).
So far working: ash, mksh, bash, nano, vi, busybox, watch...
The input supports: tab-completion; cursor movement;
backspace; start of line, end of line (long press);
page up, page down (long press).
User scripts may be placed in the koterm.koplugin/scripts/
folder, aliases can be put in the file aliases and startup
command in the file profile.user in that folder.
2022-01-28 19:33:09 +00:00
|
|
|
local input_widget = self.inputtext_class:new{
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
text = self.fullscreen and "-" or self.input,
|
2021-10-29 11:03:57 +00:00
|
|
|
input_type = self.input_type,
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
face = self.input_face,
|
|
|
|
width = self.text_width,
|
|
|
|
padding = self.input_padding,
|
|
|
|
margin = self.input_margin,
|
2019-12-06 21:55:35 +00:00
|
|
|
lang = self.lang, -- these might influence height
|
|
|
|
para_direction_rtl = self.para_direction_rtl,
|
|
|
|
auto_para_direction = self.auto_para_direction,
|
Revamp flash_ui handling, once more, with feeling ;) (#7262)
* Simplify flash_ui handling (by handling the unhighlight pre-callback, c.f., #7262 for more details).
* UIManager: Handle translucent window-level widgets (and those wrapped in a translucent MovableContainer) properly in setDirty directly, making sure what's *underneath* them gets repainted to avoid alpha layering glitches. (This was previously handled via localized hacks).
* Update UIManager's documentation, and format it properly for ldoc parsing, making the HTML docs more useful.
* ReaderView: Reinitialize the various page areas when opening a new document, to prevent poisoning from the previous document.
* Event: Handle nils in an event's arguments.
* CheckButton/RadioButton: Switch to simple inversion to handle highlighting
* CheckButton: Make the highlight span the inner frame's width, instead of just the text's width, if possible.
* AlphaContainer: Fix & simplify, given the UIManager alpha handling.
* MovableContainer: When translucent, cache the canvas bb used for composition.
* Avoid spurious refreshes in a few widgets using various dummy *TextWidgets in order to first compute a text height.
* KeyValuePage: Avoid floats in size computations.
2021-02-20 17:22:48 +00:00
|
|
|
for_measurement_only = true, -- flag it as a dummy, so it won't trigger any bogus repaint/refresh...
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
}
|
|
|
|
local text_height = input_widget:getTextHeight()
|
|
|
|
local line_height = input_widget:getLineHeight()
|
|
|
|
local input_pad_height = input_widget:getSize().h - text_height
|
2018-08-06 19:16:30 +00:00
|
|
|
local keyboard_height = 0
|
|
|
|
if not self.keyboard_hidden then
|
|
|
|
keyboard_height = input_widget:getKeyboardDimen().h
|
|
|
|
end
|
2019-11-25 13:31:54 +00:00
|
|
|
input_widget:onCloseWidget() -- free() textboxwidget and keyboard
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
-- Find out available height
|
2021-09-17 17:36:57 +00:00
|
|
|
local available_height = self.screen_height
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
- 2*self.border_size
|
2022-01-20 10:36:35 +00:00
|
|
|
- self.title_bar:getHeight()
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
- vspan_before_input_text:getSize().h
|
|
|
|
- input_pad_height
|
|
|
|
- vspan_after_input_text:getSize().h
|
|
|
|
- buttons_container:getSize().h
|
|
|
|
- keyboard_height
|
2021-11-28 22:30:15 +00:00
|
|
|
if self.fullscreen or self.use_available_height or text_height > available_height then
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
-- Don't leave unusable space in the text widget, as the user could think
|
|
|
|
-- it's an empty line: move that space in pads after and below (for centering)
|
|
|
|
self.text_height = math.floor(available_height / line_height) * line_height
|
|
|
|
local pad_height = available_height - self.text_height
|
|
|
|
local pad_before = math.ceil(pad_height / 2)
|
|
|
|
local pad_after = pad_height - pad_before
|
|
|
|
vspan_before_input_text.width = vspan_before_input_text.width + pad_before
|
|
|
|
vspan_after_input_text.width = vspan_after_input_text.width + pad_after
|
2021-11-28 22:30:15 +00:00
|
|
|
if text_height > available_height then
|
|
|
|
self.cursor_at_end = false -- stay at start if overflowed
|
|
|
|
end
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
else
|
|
|
|
-- Don't leave unusable space in the text widget
|
|
|
|
self.text_height = text_height
|
|
|
|
end
|
|
|
|
end
|
2018-08-06 19:16:30 +00:00
|
|
|
if self.view_pos_callback then
|
|
|
|
-- Get initial cursor and top line num from callback
|
|
|
|
-- (will work in case of re-init as these are saved by onClose()
|
|
|
|
self._top_line_num, self._charpos = self.view_pos_callback()
|
|
|
|
end
|
Terminal emulator: full rewrite, real vt52 emulator (#8636)
New real terminal emulator, replacing the old plugin.
The emulator is basically a vt52 terminal (enriched with
some ANSI-sequences, as ash, vi and mksh don't behave well
on a vt52 term).
So far working: ash, mksh, bash, nano, vi, busybox, watch...
The input supports: tab-completion; cursor movement;
backspace; start of line, end of line (long press);
page up, page down (long press).
User scripts may be placed in the koterm.koplugin/scripts/
folder, aliases can be put in the file aliases and startup
command in the file profile.user in that folder.
2022-01-28 19:33:09 +00:00
|
|
|
self._input_widget = self.inputtext_class:new{
|
2014-03-13 13:52:43 +00:00
|
|
|
text = self.input,
|
|
|
|
hint = self.input_hint,
|
|
|
|
face = self.input_face,
|
2019-12-06 21:55:35 +00:00
|
|
|
alignment = self.alignment,
|
|
|
|
justified = self.justified,
|
|
|
|
lang = self.lang,
|
|
|
|
para_direction_rtl = self.para_direction_rtl,
|
|
|
|
auto_para_direction = self.auto_para_direction,
|
|
|
|
alignment_strict = self.alignment_strict,
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
width = self.text_width,
|
2016-02-02 17:38:14 +00:00
|
|
|
height = self.text_height or nil,
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
padding = self.input_padding,
|
|
|
|
margin = self.input_margin,
|
2014-03-13 13:52:43 +00:00
|
|
|
input_type = self.input_type,
|
2015-10-06 13:18:07 +00:00
|
|
|
text_type = self.text_type,
|
2016-05-26 06:09:49 +00:00
|
|
|
enter_callback = self.enter_callback or function()
|
|
|
|
for _,btn_row in ipairs(self.buttons) do
|
|
|
|
for _,btn in ipairs(btn_row) do
|
|
|
|
if btn.is_enter_default then
|
|
|
|
btn.callback()
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end,
|
Terminal emulator: full rewrite, real vt52 emulator (#8636)
New real terminal emulator, replacing the old plugin.
The emulator is basically a vt52 terminal (enriched with
some ANSI-sequences, as ash, vi and mksh don't behave well
on a vt52 term).
So far working: ash, mksh, bash, nano, vi, busybox, watch...
The input supports: tab-completion; cursor movement;
backspace; start of line, end of line (long press);
page up, page down (long press).
User scripts may be placed in the koterm.koplugin/scripts/
folder, aliases can be put in the file aliases and startup
command in the file profile.user in that folder.
2022-01-28 19:33:09 +00:00
|
|
|
strike_callback = self.strike_callback,
|
2018-08-06 19:16:30 +00:00
|
|
|
edit_callback = self._buttons_edit_callback, -- nil if no Save/Close buttons
|
|
|
|
scroll_callback = self._buttons_scroll_callback, -- nil if no Nav or Scroll buttons
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
scroll = true,
|
2018-08-10 16:05:09 +00:00
|
|
|
scroll_by_pan = self.scroll_by_pan,
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
cursor_at_end = self.cursor_at_end,
|
2018-08-06 19:16:30 +00:00
|
|
|
readonly = self.readonly,
|
2014-03-13 13:52:43 +00:00
|
|
|
parent = self,
|
2018-08-06 19:16:30 +00:00
|
|
|
is_text_edited = self._text_modified,
|
|
|
|
top_line_num = self._top_line_num,
|
|
|
|
charpos = self._charpos,
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
2022-03-04 20:20:00 +00:00
|
|
|
table.insert(self.layout[1], self._input_widget)
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
if self.allow_newline then -- remove any enter_callback
|
|
|
|
self._input_widget.enter_callback = nil
|
|
|
|
end
|
2022-03-04 20:20:00 +00:00
|
|
|
self:mergeLayoutInVertical(self.button_table)
|
|
|
|
self:refocusWidget()
|
2018-08-06 19:16:30 +00:00
|
|
|
-- Complementary setup for some of our added buttons
|
|
|
|
if self.save_callback then
|
|
|
|
local save_button = self.button_table:getButtonById("save")
|
|
|
|
if self.readonly then
|
|
|
|
save_button:setText(_("Read only"), save_button.width)
|
|
|
|
elseif not self._input_widget:isTextEditable() then
|
|
|
|
save_button:setText(_("Not editable"), save_button.width)
|
|
|
|
end
|
|
|
|
end
|
2014-04-23 14:19:29 +00:00
|
|
|
|
2021-09-02 20:53:54 +00:00
|
|
|
-- Combine all
|
|
|
|
self.vgroup = VerticalGroup:new{
|
|
|
|
align = "left",
|
|
|
|
self.title_bar,
|
|
|
|
vspan_before_input_text,
|
|
|
|
CenterContainer:new{
|
|
|
|
dimen = Geom:new{
|
|
|
|
w = self.width,
|
|
|
|
h = self._input_widget:getSize().h,
|
|
|
|
},
|
|
|
|
self._input_widget,
|
|
|
|
},
|
|
|
|
-- added widgets may be inserted here
|
|
|
|
vspan_after_input_text,
|
|
|
|
buttons_container,
|
|
|
|
}
|
|
|
|
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
-- Final widget
|
2014-03-13 13:52:43 +00:00
|
|
|
self.dialog_frame = FrameContainer:new{
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
radius = self.fullscreen and 0 or Size.radius.window,
|
2014-03-13 13:52:43 +00:00
|
|
|
padding = 0,
|
|
|
|
margin = 0,
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
bordersize = self.border_size,
|
2014-10-22 13:34:11 +00:00
|
|
|
background = Blitbuffer.COLOR_WHITE,
|
2021-09-02 20:53:54 +00:00
|
|
|
self.vgroup,
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
local frame = self.dialog_frame
|
2021-06-29 09:01:12 +00:00
|
|
|
if self.is_movable then
|
|
|
|
self.movable = MovableContainer:new{ -- (UIManager expects this as 'self.movable')
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
self.dialog_frame,
|
|
|
|
}
|
2021-06-29 09:01:12 +00:00
|
|
|
frame = self.movable
|
2018-03-30 10:46:36 +00:00
|
|
|
end
|
2018-08-06 19:16:30 +00:00
|
|
|
local keyboard_height = self.keyboard_hidden and 0
|
|
|
|
or self._input_widget:getKeyboardDimen().h
|
2014-03-13 13:52:43 +00:00
|
|
|
self[1] = CenterContainer:new{
|
|
|
|
dimen = Geom:new{
|
2021-09-17 17:36:57 +00:00
|
|
|
w = self.screen_width,
|
|
|
|
h = self.screen_height - keyboard_height,
|
2014-03-13 13:52:43 +00:00
|
|
|
},
|
2021-10-01 18:33:39 +00:00
|
|
|
ignore_if_over = "height",
|
Text input fixes and enhancements (#4084)
InputText, ScrollTextWidget, TextBoxWidget:
- proper line scrolling when moving cursor or inserting/deleting text
to behave like most text editors do
- fix cursor navigation, optimize refreshes when moving only the cursor,
don't recreate the textwidget when moving cursor up/down
- optimize refresh areas, stick to "ui" to avoid a "partial" black
flash every 6 appended or deleted chars
InputText:
- fix issue when toggling Show password multiple times
- new option: InputText.cursor_at_end (default: true)
- if no InputText.height provided, measure the text widget height
that we would start with, and use a ScrollTextWidget with that
fixed height, so widget does not overflow container if we extend
the text and increase the number of lines
- as we are using "ui" refreshes while text editing, allows refreshing
the InputText with a diagonal swipe on it (actually, refresh the
whole screen, which allows refreshing the keyboard too if needed)
ScrollTextWidget:
- properly align scrollbar with its TextBoxWidget
TextBoxWidget:
- some cleanup (added new properties to avoid many method calls), added
proxy methods for upper widgets to get them
- reordered/renamed/refactored the *CharPos* methods for easier reading
(sorry for the diff that won't help reviewing, but that was needed)
InputDialog:
- new options:
allow_newline = false, -- allow entering new lines
cursor_at_end = true, -- starts with cursor at end of text, ready to append
fullscreen = false, -- adjust to full screen minus keyboard
condensed = false, -- true will prevent adding air and balance between elements
add_scroll_buttons = false, -- add scroll Up/Down buttons to first row of buttons
add_nav_bar = false, -- append a row of page navigation buttons
- find the most adequate text height, when none provided or fullscreen, to
not overflow screen (and not be stuck with Cancel/Save buttons hidden)
- had to disable the use of a MovableContainer (many issues like becoming
transparent when a PathChooser comes in front, Hold to paste from
clipboard, moving the InputDialog under the keyboard and getting stuck...)
GestureRange: fix possible crash (when event processed after widget
destruction ?)
LoginDialog: fix some ui stack increase and possible crash when switching
focus many times.
2018-07-19 06:30:40 +00:00
|
|
|
frame
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
2021-06-29 09:01:12 +00:00
|
|
|
if Device:isTouchDevice() then -- is used to hide the keyboard with a tap outside of inputbox
|
|
|
|
self.ges_events = {
|
|
|
|
Tap = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "tap",
|
|
|
|
range = self[1].dimen, -- screen above the keyboard
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
end
|
2022-03-04 20:20:00 +00:00
|
|
|
if Device:hasKeys() then
|
|
|
|
self.key_events.CloseDialog = { {Device.input.group.Back}, doc = "close dialog" }
|
|
|
|
end
|
2021-09-02 20:53:54 +00:00
|
|
|
if self._added_widgets then
|
|
|
|
for _, widget in ipairs(self._added_widgets) do
|
|
|
|
self:addWidget(widget, true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function InputDialog:addWidget(widget, re_init)
|
2022-03-04 20:20:00 +00:00
|
|
|
table.insert(self.layout, #self.layout, {widget})
|
2021-09-02 20:53:54 +00:00
|
|
|
if not re_init then -- backup widget for re-init
|
|
|
|
widget = CenterContainer:new{
|
|
|
|
dimen = Geom:new{
|
|
|
|
w = self.width,
|
|
|
|
h = widget:getSize().h,
|
|
|
|
},
|
|
|
|
widget,
|
|
|
|
}
|
|
|
|
if not self._added_widgets then
|
|
|
|
self._added_widgets = {}
|
|
|
|
end
|
|
|
|
table.insert(self._added_widgets, widget)
|
|
|
|
end
|
|
|
|
-- insert widget before the bottom buttons and their previous vspan
|
|
|
|
table.insert(self.vgroup, #self.vgroup-1, widget)
|
2021-06-29 09:01:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function InputDialog:onTap()
|
2021-06-29 19:42:18 +00:00
|
|
|
if self.deny_keyboard_hiding then
|
2021-06-29 09:01:12 +00:00
|
|
|
return
|
|
|
|
end
|
2021-08-13 22:49:19 +00:00
|
|
|
if self._input_widget.onCloseKeyboard then
|
|
|
|
self._input_widget:onCloseKeyboard()
|
|
|
|
end
|
2014-12-01 14:39:41 +00:00
|
|
|
end
|
|
|
|
|
2016-02-17 17:41:17 +00:00
|
|
|
function InputDialog:getInputText()
|
|
|
|
return self._input_widget:getText()
|
|
|
|
end
|
|
|
|
|
2016-09-22 06:52:40 +00:00
|
|
|
function InputDialog:getInputValue()
|
|
|
|
local text = self:getInputText()
|
|
|
|
if self.input_type == "number" then
|
|
|
|
return tonumber(text)
|
|
|
|
else
|
|
|
|
return text
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-06-08 18:47:31 +00:00
|
|
|
function InputDialog:setInputText(text, edited_state)
|
2016-02-17 17:41:17 +00:00
|
|
|
self._input_widget:setText(text)
|
2020-06-08 18:47:31 +00:00
|
|
|
if edited_state ~= nil and self._buttons_edit_callback then
|
|
|
|
self._buttons_edit_callback(edited_state)
|
|
|
|
end
|
2016-02-17 17:41:17 +00:00
|
|
|
end
|
|
|
|
|
2018-08-01 16:33:52 +00:00
|
|
|
function InputDialog:isTextEditable()
|
|
|
|
return self._input_widget:isTextEditable()
|
|
|
|
end
|
|
|
|
|
|
|
|
function InputDialog:isTextEdited()
|
|
|
|
return self._input_widget:isTextEdited()
|
|
|
|
end
|
|
|
|
|
2014-12-01 14:39:41 +00:00
|
|
|
function InputDialog:onShow()
|
|
|
|
UIManager:setDirty(self, function()
|
2015-04-26 18:07:17 +00:00
|
|
|
return "ui", self.dialog_frame.dimen
|
2014-12-01 14:39:41 +00:00
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
|
|
|
function InputDialog:onCloseWidget()
|
2016-05-02 02:39:31 +00:00
|
|
|
self:onClose()
|
2020-08-29 16:25:38 +00:00
|
|
|
UIManager:setDirty(nil, self.fullscreen and "full" or function()
|
Tame some ButtonTable users into re-using Buttontable instances if possible (#7166)
* QuickDictLookup, ImageViewer, NumberPicker: Smarter `update` that will re-use most of the widget's layout instead of re-instantiating all the things.
* SpinWidget/DoubleSpinWidget: The NumberPicker change above renders a hack to preserve alpha on these widgets almost unnecessary. Also fixed said hack to also apply to the center, value button.
* Button: Don't re-instantiate the frame in setText/setIcon when unnecessary (e.g., no change at all, or no layout change).
* Button: Add a refresh method that repaints and refreshes a *specific* Button (provided it's been painted once) all on its lonesome.
* ConfigDialog: Free everything that's going to be re-instatiated on update
* A few more post #7118 fixes:
* SkimTo: Always flag the chapter nav buttons as vsync
* Button: Fix the highlight on rounded buttons when vsync is enabled (e.g., it's now entirely visible, instead of showing a weird inverted corner glitch).
* Some more heuristic tweaks in Menu/TouchMenu/Button/IconButton
* ButtonTable: fix the annoying rounding issue I'd noticed in #7054 ;).
* Enable dithering in TextBoxWidget (e.g., in the Wikipedia full view). This involved moving the HW dithering align fixup to base, where it always ought to have been ;).
* Switch a few widgets that were using "partial" on close to "ui", or, more rarely, "flashui". The intent being to limit "partial" purely to the Reader, because it has a latency cost when mixed with other refreshes, which happens often enough in UI ;).
* Minor documentation tweaks around UIManager's `setDirty` to reflect that change.
* ReaderFooter: Force a footer repaint on resume if it is visible (otherwise, just update it).
* ReaderBookmark: In the same vein, don't repaint an invisible footer on bookmark count changes.
2021-01-28 23:20:15 +00:00
|
|
|
return "ui", self.dialog_frame.dimen
|
2014-12-01 14:39:41 +00:00
|
|
|
end)
|
2013-07-30 15:07:33 +00:00
|
|
|
end
|
|
|
|
|
2019-05-08 08:13:44 +00:00
|
|
|
function InputDialog:onShowKeyboard(ignore_first_hold_release)
|
2018-08-06 19:16:30 +00:00
|
|
|
if not self.readonly and not self.keyboard_hidden then
|
2019-05-08 08:13:44 +00:00
|
|
|
self._input_widget:onShowKeyboard(ignore_first_hold_release)
|
2018-08-06 19:16:30 +00:00
|
|
|
end
|
2013-07-30 15:07:33 +00:00
|
|
|
end
|
|
|
|
|
2021-09-02 20:53:54 +00:00
|
|
|
function InputDialog:toggleKeyboard(force_hide)
|
|
|
|
if force_hide and self.keyboard_hidden then return end
|
|
|
|
self.keyboard_hidden = not self.keyboard_hidden
|
|
|
|
self.input = self:getInputText() -- re-init with up-to-date text
|
|
|
|
self:onClose() -- will close keyboard and save view position
|
|
|
|
self:free()
|
|
|
|
self:init()
|
|
|
|
if not self.keyboard_hidden then
|
|
|
|
self:onShowKeyboard()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-11-25 13:31:54 +00:00
|
|
|
function InputDialog:onKeyboardHeightChanged()
|
|
|
|
self.input = self:getInputText() -- re-init with up-to-date text
|
|
|
|
self:onClose() -- will close keyboard and save view position
|
|
|
|
self._input_widget:onCloseWidget() -- proper cleanup of InputText and its keyboard
|
2021-09-02 20:53:54 +00:00
|
|
|
if self._added_widgets then
|
|
|
|
-- prevent these externally added widgets from being freed as :init() will re-add them
|
|
|
|
for i = 1, #self._added_widgets do
|
|
|
|
table.remove(self.vgroup, #self.vgroup-2)
|
|
|
|
end
|
|
|
|
end
|
2019-11-25 13:31:54 +00:00
|
|
|
self:free()
|
|
|
|
-- Restore original text_height (or reset it if none to force recomputing it)
|
|
|
|
self.text_height = self.orig_text_height or nil
|
|
|
|
self:init()
|
|
|
|
if not self.keyboard_hidden then
|
|
|
|
self:onShowKeyboard()
|
|
|
|
end
|
|
|
|
-- Our position on screen has probably changed, so have the full screen refreshed
|
|
|
|
UIManager:setDirty("all", "flashui")
|
|
|
|
end
|
|
|
|
|
2022-03-04 20:20:00 +00:00
|
|
|
function InputDialog:onCloseDialog()
|
|
|
|
local close_button = self.button_table:getButtonById("close")
|
|
|
|
if close_button and close_button.enabled then
|
|
|
|
close_button.callback()
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2013-07-30 15:07:33 +00:00
|
|
|
function InputDialog:onClose()
|
2018-08-06 19:16:30 +00:00
|
|
|
-- Remember current view & position in case of re-init
|
|
|
|
self._top_line_num = self._input_widget.top_line_num
|
|
|
|
self._charpos = self._input_widget.charpos
|
|
|
|
if self.view_pos_callback then
|
|
|
|
-- Give back top line num and cursor position
|
|
|
|
self.view_pos_callback(self._top_line_num, self._charpos)
|
|
|
|
end
|
2016-02-17 17:41:17 +00:00
|
|
|
self._input_widget:onCloseKeyboard()
|
2013-07-30 15:07:33 +00:00
|
|
|
end
|
2013-10-18 20:38:07 +00:00
|
|
|
|
2018-08-06 19:16:30 +00:00
|
|
|
function InputDialog:refreshButtons()
|
|
|
|
-- Using what ought to be enough:
|
|
|
|
-- return "ui", self.button_table.dimen
|
|
|
|
-- causes 2 non-intersecting refreshes (because if our buttons
|
|
|
|
-- change, the text widget did) that may sometimes cause
|
|
|
|
-- the button_table to become white.
|
|
|
|
-- Safer to refresh the whole widget so the refreshes can
|
|
|
|
-- be merged into one.
|
|
|
|
UIManager:setDirty(self, function()
|
|
|
|
return "ui", self.dialog_frame.dimen
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
|
|
|
function InputDialog:_backupRestoreButtons()
|
|
|
|
-- In case of re-init(), keep backup of original buttons and restore them
|
|
|
|
if self._buttons_backup_done then
|
|
|
|
-- Move backup and override current, and re-create backup from original,
|
|
|
|
-- to avoid duplicating the copy code)
|
|
|
|
self.buttons = self._buttons_backup -- restore (we may restore 'nil')
|
|
|
|
end
|
|
|
|
if self.buttons then -- (re-)create backup
|
|
|
|
self._buttons_backup = {} -- deep copy, except for the buttons themselves
|
|
|
|
for i, row in ipairs(self.buttons) do
|
|
|
|
if row then
|
|
|
|
local row_copy = {}
|
|
|
|
self._buttons_backup[i] = row_copy
|
|
|
|
for j, b in ipairs(row) do
|
|
|
|
row_copy[j] = b
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
self._buttons_backup_done = true
|
|
|
|
end
|
|
|
|
|
|
|
|
function InputDialog:_addSaveCloseButtons()
|
|
|
|
if not self.buttons then
|
|
|
|
self.buttons = {{}}
|
|
|
|
end
|
|
|
|
-- Add them to the end of first row
|
|
|
|
local row = self.buttons[1]
|
|
|
|
local button = function(id) -- shortcut for more readable code
|
|
|
|
return self.button_table:getButtonById(id)
|
|
|
|
end
|
|
|
|
-- Callback to enable/disable Reset/Save buttons, for feedback when text modified
|
|
|
|
self._buttons_edit_callback = function(edited)
|
|
|
|
if self._text_modified and not edited then
|
|
|
|
self._text_modified = false
|
|
|
|
button("save"):disable()
|
|
|
|
if button("reset") then button("reset"):disable() end
|
|
|
|
self:refreshButtons()
|
|
|
|
elseif edited and not self._text_modified then
|
|
|
|
self._text_modified = true
|
|
|
|
button("save"):enable()
|
|
|
|
if button("reset") then button("reset"):enable() end
|
|
|
|
self:refreshButtons()
|
|
|
|
end
|
2020-06-08 18:47:31 +00:00
|
|
|
if self.edited_callback then
|
|
|
|
self.edited_callback()
|
|
|
|
end
|
2018-08-06 19:16:30 +00:00
|
|
|
end
|
|
|
|
if self.reset_callback then
|
|
|
|
-- if reset_callback provided, add button to restore
|
|
|
|
-- test to some previous state
|
|
|
|
table.insert(row, {
|
|
|
|
text = self.reset_button_text or _("Reset"),
|
|
|
|
id = "reset",
|
|
|
|
enabled = self._text_modified,
|
|
|
|
callback = function()
|
|
|
|
-- Wrapped via Trapper, to allow reset_callback to use Trapper
|
|
|
|
-- to show progress or ask questions while getting original content
|
|
|
|
require("ui/trapper"):wrap(function()
|
|
|
|
local content, msg = self.reset_callback()
|
|
|
|
if content then
|
|
|
|
self:setInputText(content)
|
|
|
|
self._buttons_edit_callback(false)
|
|
|
|
UIManager:show(Notification:new{
|
|
|
|
text = msg or _("Text reset"),
|
|
|
|
})
|
|
|
|
else -- nil content, assume failure and show msg
|
|
|
|
if msg ~= false then -- false allows for no InfoMessage
|
|
|
|
UIManager:show(InfoMessage:new{
|
|
|
|
text = msg or _("Resetting failed."),
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
table.insert(row, {
|
|
|
|
text = self.save_button_text or _("Save"),
|
|
|
|
id = "save",
|
|
|
|
enabled = self._text_modified,
|
|
|
|
callback = function()
|
|
|
|
-- Wrapped via Trapper, to allow save_callback to use Trapper
|
|
|
|
-- to show progress or ask questions while saving
|
|
|
|
require("ui/trapper"):wrap(function()
|
|
|
|
if self._text_modified then
|
|
|
|
local success, msg = self.save_callback(self:getInputText())
|
|
|
|
if success == false then
|
|
|
|
if msg ~= false then -- false allows for no InfoMessage
|
|
|
|
UIManager:show(InfoMessage:new{
|
|
|
|
text = msg or _("Saving failed."),
|
|
|
|
})
|
|
|
|
end
|
|
|
|
else -- nil or true
|
|
|
|
self._buttons_edit_callback(false)
|
|
|
|
UIManager:show(Notification:new{
|
|
|
|
text = msg or _("Saved"),
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
table.insert(row, {
|
|
|
|
text = self.close_button_text or _("Close"),
|
|
|
|
id = "close",
|
|
|
|
callback = function()
|
|
|
|
if self._text_modified then
|
|
|
|
UIManager:show(MultiConfirmBox:new{
|
|
|
|
text = self.close_unsaved_confirm_text or _("You have unsaved changes."),
|
|
|
|
cancel_text = self.close_cancel_button_text or _("Cancel"),
|
|
|
|
choice1_text = self.close_discard_button_text or _("Discard"),
|
|
|
|
choice1_callback = function()
|
2018-09-04 21:55:58 +00:00
|
|
|
if self.close_callback then self.close_callback() end
|
2018-08-06 19:16:30 +00:00
|
|
|
UIManager:close(self)
|
|
|
|
UIManager:show(Notification:new{
|
|
|
|
text = self.close_discarded_notif_text or _("Changes discarded"),
|
|
|
|
})
|
|
|
|
end,
|
|
|
|
choice2_text = self.close_save_button_text or _("Save"),
|
|
|
|
choice2_callback = function()
|
|
|
|
-- Wrapped via Trapper, to allow save_callback to use Trapper
|
|
|
|
-- to show progress or ask questions while saving
|
|
|
|
require("ui/trapper"):wrap(function()
|
|
|
|
local success, msg = self.save_callback(self:getInputText(), true)
|
|
|
|
if success == false then
|
|
|
|
if msg ~= false then -- false allows for no InfoMessage
|
|
|
|
UIManager:show(InfoMessage:new{
|
|
|
|
text = msg or _("Saving failed."),
|
|
|
|
})
|
|
|
|
end
|
|
|
|
else -- nil or true
|
2018-09-04 21:55:58 +00:00
|
|
|
if self.close_callback then self.close_callback() end
|
2018-08-06 19:16:30 +00:00
|
|
|
UIManager:close(self)
|
|
|
|
UIManager:show(Notification:new{
|
|
|
|
text = msg or _("Saved"),
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
else
|
|
|
|
-- Not modified, exit without any message
|
2018-09-04 21:55:58 +00:00
|
|
|
if self.close_callback then self.close_callback() end
|
2018-08-06 19:16:30 +00:00
|
|
|
UIManager:close(self)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
function InputDialog:_addScrollButtons(nav_bar)
|
|
|
|
local row
|
|
|
|
if nav_bar then -- Add Home / End / Up / Down buttons as a last row
|
|
|
|
if not self.buttons then
|
|
|
|
self.buttons = {}
|
|
|
|
end
|
|
|
|
row = {} -- Empty additional buttons row
|
|
|
|
table.insert(self.buttons, row)
|
|
|
|
else -- Add the Up / Down buttons to the first row
|
|
|
|
if not self.buttons then
|
|
|
|
self.buttons = {{}}
|
|
|
|
end
|
|
|
|
row = self.buttons[1]
|
|
|
|
end
|
|
|
|
if nav_bar then -- Add the Home & End buttons
|
|
|
|
-- Also add Keyboard hide/show button if we can
|
|
|
|
if self.fullscreen and not self.readonly then
|
|
|
|
table.insert(row, {
|
|
|
|
text = self.keyboard_hidden and "↑⌨" or "↓⌨",
|
|
|
|
id = "keyboard",
|
|
|
|
callback = function()
|
2021-09-02 20:53:54 +00:00
|
|
|
self:toggleKeyboard()
|
2018-08-06 19:16:30 +00:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
end
|
2021-05-16 10:45:36 +00:00
|
|
|
if self.fullscreen then
|
2021-05-19 16:05:16 +00:00
|
|
|
-- Add a button to search for a string in the edited text
|
|
|
|
table.insert(row, {
|
|
|
|
text = _("Find"),
|
|
|
|
callback = function()
|
2021-09-02 20:53:54 +00:00
|
|
|
local keyboard_hidden_state = not self.keyboard_hidden
|
|
|
|
self:toggleKeyboard(true) -- hide text editor keyboard
|
2021-05-19 16:05:16 +00:00
|
|
|
local input_dialog
|
|
|
|
input_dialog = InputDialog:new{
|
|
|
|
title = _("Enter text to search for"),
|
|
|
|
stop_events_propagation = true, -- avoid interactions with upper InputDialog
|
|
|
|
input = self.search_value,
|
|
|
|
buttons = {
|
|
|
|
{
|
|
|
|
{
|
|
|
|
text = _("Cancel"),
|
2022-03-04 20:20:00 +00:00
|
|
|
id = "close",
|
2021-05-19 16:05:16 +00:00
|
|
|
callback = function()
|
|
|
|
UIManager:close(input_dialog)
|
2021-09-02 20:53:54 +00:00
|
|
|
self.keyboard_hidden = keyboard_hidden_state
|
|
|
|
self:toggleKeyboard()
|
2021-05-19 16:05:16 +00:00
|
|
|
end,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text = _("Find first"),
|
|
|
|
callback = function()
|
2022-09-13 21:09:49 +00:00
|
|
|
self:findCallback(keyboard_hidden_state, input_dialog, true)
|
2021-05-19 16:05:16 +00:00
|
|
|
end,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text = _("Find next"),
|
|
|
|
is_enter_default = true,
|
|
|
|
callback = function()
|
2022-09-13 21:09:49 +00:00
|
|
|
self:findCallback(keyboard_hidden_state, input_dialog)
|
2021-05-19 16:05:16 +00:00
|
|
|
end,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2021-07-15 14:28:54 +00:00
|
|
|
|
|
|
|
self.check_button_case = CheckButton:new{
|
|
|
|
text = _("Case sensitive"),
|
|
|
|
checked = self.case_sensitive,
|
|
|
|
parent = input_dialog,
|
|
|
|
callback = function()
|
2021-08-27 19:21:14 +00:00
|
|
|
self.case_sensitive = self.check_button_case.checked
|
2021-07-15 14:28:54 +00:00
|
|
|
end,
|
|
|
|
}
|
2021-09-02 20:53:54 +00:00
|
|
|
input_dialog:addWidget(self.check_button_case)
|
2021-07-15 14:28:54 +00:00
|
|
|
|
2021-05-19 16:05:16 +00:00
|
|
|
UIManager:show(input_dialog)
|
|
|
|
input_dialog:onShowKeyboard()
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
-- Add a button to go to the line by its number in the file
|
2021-05-16 10:45:36 +00:00
|
|
|
table.insert(row, {
|
|
|
|
text = _("Go"),
|
|
|
|
callback = function()
|
2021-09-02 20:53:54 +00:00
|
|
|
local keyboard_hidden_state = not self.keyboard_hidden
|
|
|
|
self:toggleKeyboard(true) -- hide text editor keyboard
|
2021-05-16 10:45:36 +00:00
|
|
|
local cur_line_num, last_line_num = self._input_widget:getLineNums()
|
|
|
|
local input_dialog
|
|
|
|
input_dialog = InputDialog:new{
|
|
|
|
title = _("Enter line number"),
|
|
|
|
-- @translators %1 is the current line number, %2 is the last line number
|
|
|
|
input_hint = T(_("%1 (1 - %2)"), cur_line_num, last_line_num),
|
|
|
|
input_type = "number",
|
|
|
|
stop_events_propagation = true, -- avoid interactions with upper InputDialog
|
|
|
|
buttons = {
|
|
|
|
{
|
|
|
|
{
|
|
|
|
text = _("Cancel"),
|
2022-03-04 20:20:00 +00:00
|
|
|
id = "close",
|
2021-05-16 10:45:36 +00:00
|
|
|
callback = function()
|
|
|
|
UIManager:close(input_dialog)
|
2021-09-02 20:53:54 +00:00
|
|
|
self.keyboard_hidden = keyboard_hidden_state
|
|
|
|
self:toggleKeyboard()
|
2021-05-16 10:45:36 +00:00
|
|
|
end,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text = _("Go to line"),
|
|
|
|
is_enter_default = true,
|
|
|
|
callback = function()
|
|
|
|
local new_line_num = tonumber(input_dialog:getInputText())
|
|
|
|
if new_line_num and new_line_num >= 1 and new_line_num <= last_line_num then
|
|
|
|
UIManager:close(input_dialog)
|
2021-09-02 20:53:54 +00:00
|
|
|
self.keyboard_hidden = keyboard_hidden_state
|
|
|
|
self:toggleKeyboard()
|
2021-05-16 10:45:36 +00:00
|
|
|
self._input_widget:moveCursorToCharPos(self._input_widget:getLineCharPos(new_line_num))
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
UIManager:show(input_dialog)
|
|
|
|
input_dialog:onShowKeyboard()
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
end
|
2018-08-06 19:16:30 +00:00
|
|
|
table.insert(row, {
|
|
|
|
text = "⇱",
|
|
|
|
id = "top",
|
Assorted fixes after #7118 (#7161)
* I'd failed to notice that ButtonTable *also* instantiates seven billion Buttons on each update. Unfortunately, that one is way trickier to fix properly, so, work around its behavior in Button. (This fixes multiple issues with stuff using ButtonTable, which is basically anything with a persistent set of buttons. A good and easy test-case is the dictionary popup, e.g., the Highlight button changes text, and the next/prev dic buttons change state. All that, and more, was broken ;p).
* Handle corner-cases related to VirtualKeyboard (e.g., Terminal & Text Editor), which screwed with both TouchMenu & Button heuristics because it's weird.
* Flag a the dictionary switch buttons as vsync
(They trigger a partial repaint of the dictionary content).
* Flag the ReaderSearch buttons as vsync
They very obviously trigger a partial repaint, much like SkimTo ;p.
2021-01-18 15:51:25 +00:00
|
|
|
vsync = true,
|
2018-08-06 19:16:30 +00:00
|
|
|
callback = function()
|
|
|
|
self._input_widget:scrollToTop()
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
table.insert(row, {
|
|
|
|
text = "⇲",
|
|
|
|
id = "bottom",
|
Assorted fixes after #7118 (#7161)
* I'd failed to notice that ButtonTable *also* instantiates seven billion Buttons on each update. Unfortunately, that one is way trickier to fix properly, so, work around its behavior in Button. (This fixes multiple issues with stuff using ButtonTable, which is basically anything with a persistent set of buttons. A good and easy test-case is the dictionary popup, e.g., the Highlight button changes text, and the next/prev dic buttons change state. All that, and more, was broken ;p).
* Handle corner-cases related to VirtualKeyboard (e.g., Terminal & Text Editor), which screwed with both TouchMenu & Button heuristics because it's weird.
* Flag a the dictionary switch buttons as vsync
(They trigger a partial repaint of the dictionary content).
* Flag the ReaderSearch buttons as vsync
They very obviously trigger a partial repaint, much like SkimTo ;p.
2021-01-18 15:51:25 +00:00
|
|
|
vsync = true,
|
2018-08-06 19:16:30 +00:00
|
|
|
callback = function()
|
|
|
|
self._input_widget:scrollToBottom()
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
-- Add the Up & Down buttons
|
|
|
|
table.insert(row, {
|
|
|
|
text = "△",
|
|
|
|
id = "up",
|
|
|
|
callback = function()
|
|
|
|
self._input_widget:scrollUp()
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
table.insert(row, {
|
|
|
|
text = "▽",
|
|
|
|
id = "down",
|
|
|
|
callback = function()
|
|
|
|
self._input_widget:scrollDown()
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
-- Callback to enable/disable buttons, for at-top/at-bottom feedback
|
|
|
|
local prev_at_top = false -- Buttons were created enabled
|
|
|
|
local prev_at_bottom = false
|
|
|
|
local button = function(id) -- shortcut for more readable code
|
|
|
|
return self.button_table:getButtonById(id)
|
|
|
|
end
|
|
|
|
self._buttons_scroll_callback = function(low, high)
|
|
|
|
local changed = false
|
|
|
|
if prev_at_top and low > 0 then
|
|
|
|
button("up"):enable()
|
|
|
|
if button("top") then button("top"):enable() end
|
|
|
|
prev_at_top = false
|
|
|
|
changed = true
|
|
|
|
elseif not prev_at_top and low <= 0 then
|
|
|
|
button("up"):disable()
|
|
|
|
if button("top") then button("top"):disable() end
|
|
|
|
prev_at_top = true
|
|
|
|
changed = true
|
|
|
|
end
|
|
|
|
if prev_at_bottom and high < 1 then
|
|
|
|
button("down"):enable()
|
|
|
|
if button("bottom") then button("bottom"):enable() end
|
|
|
|
prev_at_bottom = false
|
|
|
|
changed = true
|
|
|
|
elseif not prev_at_bottom and high >= 1 then
|
|
|
|
button("down"):disable()
|
|
|
|
if button("bottom") then button("bottom"):disable() end
|
|
|
|
prev_at_bottom = true
|
|
|
|
changed = true
|
|
|
|
end
|
|
|
|
if changed then
|
|
|
|
self:refreshButtons()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-09-13 21:09:49 +00:00
|
|
|
function InputDialog:findCallback(keyboard_hidden_state, input_dialog, find_first)
|
|
|
|
self.search_value = input_dialog:getInputText()
|
|
|
|
if self.search_value == "" then return end
|
|
|
|
UIManager:close(input_dialog)
|
|
|
|
self.keyboard_hidden = keyboard_hidden_state
|
|
|
|
self:toggleKeyboard()
|
|
|
|
local start_pos = find_first and 1 or self._charpos + 1
|
|
|
|
local char_pos = util.stringSearch(self.input, self.search_value, self.case_sensitive, start_pos)
|
|
|
|
local msg
|
|
|
|
if char_pos > 0 then
|
|
|
|
self._input_widget:moveCursorToCharPos(char_pos)
|
|
|
|
msg = T(_("Found in line %1."), self._input_widget:getLineNums())
|
|
|
|
else
|
|
|
|
msg = _("Not found.")
|
|
|
|
end
|
|
|
|
UIManager:show(Notification:new{
|
|
|
|
text = msg,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
return InputDialog
|