[UX] Search dialogs: don't close when searching with nothing entered (#7501)

File search, Fulltext search, Search dictionary, Search Wikipedia, DictQuickLookup: do nothing when nothing entered and search is pressed.
reviewable/pr7505/r1
hius07 3 years ago committed by GitHub
parent 10922561dd
commit aef1e271b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -23,10 +23,6 @@ local FileSearcher = InputContainer:new{
results = {},
items = 0,
commands = nil,
--filemanagersearch
use_previous_search_results = false,
lastsearch = nil,
}
function FileSearcher:readDir()
@ -74,28 +70,22 @@ function FileSearcher:setSearchResults()
end
function FileSearcher:close()
if self.search_value then
UIManager:close(self.search_dialog)
if string.len(self.search_value) > 0 then
self:readDir() --- @todo this probably doesn't need to be repeated once it's been done
self:setSearchResults() --- @todo doesn't have to be repeated if the search term is the same
if #self.results > 0 then
self:showSearchResults() --- @todo something about no results
else
UIManager:show(
InfoMessage:new{
text = BaseUtil.template(_("No results for '%1'."),
self.search_value)
}
)
end
end
UIManager:close(self.search_dialog)
self:readDir() --- @todo this probably doesn't need to be repeated once it's been done
self:setSearchResults() --- @todo doesn't have to be repeated if the search term is the same
if #self.results > 0 then
self:showSearchResults()
else
UIManager:show(
InfoMessage:new{
text = BaseUtil.template(_("No results for '%1'."),
self.search_value)
}
)
end
end
function FileSearcher:onShowFileSearch()
local dummy = self.search_value
local enabled_search_home_dir = G_reader_settings:has("home_dir")
self.search_dialog = InputDialog:new{
title = _("Enter filename to search for"),
input = self.search_value,
@ -111,30 +101,23 @@ function FileSearcher:onShowFileSearch()
end,
},
{
text = _("Current folder"),
enabled = true,
text = _("Home folder"),
enabled = G_reader_settings:has("home_dir"),
callback = function()
self.path = self.ui.file_chooser and self.ui.file_chooser.path or self.ui:getLastDirFile()
self.search_value = self.search_dialog:getInputText()
if self.search_value == dummy then -- probably DELETE this if/else block
self.use_previous_search_results = true
else
self.use_previous_search_results = false
end
if self.search_value == "" then return end
self.path = G_reader_settings:readSetting("home_dir")
self:close()
end,
},
{
text = _("Home folder"),
enabled = enabled_search_home_dir,
text = _("Current folder"),
enabled = true,
is_enter_default = true,
callback = function()
self.path = G_reader_settings:readSetting("home_dir")
self.search_value = self.search_dialog:getInputText()
if self.search_value == dummy then -- probably DELETE this if/else block
self.use_previous_search_results = true
else
self.use_previous_search_results = false
end
if self.search_value == "" then return end
self.path = self.ui.file_chooser and self.ui.file_chooser.path or self.ui:getLastDirFile()
self:close()
end,
},

@ -693,6 +693,7 @@ function ReaderDictionary:onShowDictionaryLookup()
text = _("Search dictionary"),
is_enter_default = true,
callback = function()
if self.dictionary_lookup_dialog:getInputText() == "" then return end
UIManager:close(self.dictionary_lookup_dialog)
-- Trust that input text does not need any cleaning (allows querying for "-suffix")
self:onLookupWord(self.dictionary_lookup_dialog:getInputText(), true)

@ -50,6 +50,7 @@ function ReaderSearch:onShowFulltextSearchInput()
{
text = backward_text,
callback = function()
if self.input_dialog:getInputText() == "" then return end
UIManager:close(self.input_dialog)
self:onShowSearchDialog(self.input_dialog:getInputText(), 1)
end,
@ -58,6 +59,7 @@ function ReaderSearch:onShowFulltextSearchInput()
text = forward_text,
is_enter_default = true,
callback = function()
if self.input_dialog:getInputText() == "" then return end
UIManager:close(self.input_dialog)
self:onShowSearchDialog(self.input_dialog:getInputText(), 0)
end,
@ -212,7 +214,6 @@ end
function ReaderSearch:search(pattern, origin)
logger.dbg("search pattern", pattern)
if pattern == nil or pattern == '' then return end
local direction = self.direction
local case = self.case_insensitive
local page = self.view.state.page

@ -52,6 +52,7 @@ function ReaderWikipedia:lookupInput()
text = _("Search Wikipedia"),
is_enter_default = true,
callback = function()
if self.input_dialog:getInputText() == "" then return end
UIManager:close(self.input_dialog)
-- Trust that input text does not need any cleaning (allows querying for "-suffix")
self:onLookupWikipedia(self.input_dialog:getInputText(), true)

@ -1222,6 +1222,7 @@ function DictQuickLookup:lookupInputWord(hint)
text = self.is_wiki and _("Search Wikipedia") or _("Search dictionary"),
is_enter_default = true,
callback = function()
if self.input_dialog:getInputText() == "" then return end
self:closeInputDialog()
self:onClose()
self:inputLookup()

Loading…
Cancel
Save