mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Open with: add Text Editor plugin
This commit is contained in:
committed by
Martín Fernández
parent
cfa45f8d88
commit
85a16d0064
@@ -356,10 +356,19 @@ function FileManager:init()
|
||||
table.insert(buttons, {
|
||||
{
|
||||
text = _("Open with…"),
|
||||
enabled = DocumentRegistry:getProviders(file) == nil or #(DocumentRegistry:getProviders(file)) > 1,
|
||||
enabled = DocumentRegistry:getProviders(file) == nil or #(DocumentRegistry:getProviders(file)) > 1 or fileManager.texteditor,
|
||||
callback = function()
|
||||
UIManager:close(self.file_dialog)
|
||||
self:showSetProviderButtons(file, FileManager.instance, ReaderUI)
|
||||
local one_time_providers = {}
|
||||
if fileManager.texteditor then
|
||||
table.insert(one_time_providers, {
|
||||
provider_name = _("Text editor"),
|
||||
callback = function()
|
||||
fileManager.texteditor:checkEditFile(file)
|
||||
end,
|
||||
})
|
||||
end
|
||||
self:showSetProviderButtons(file, FileManager.instance, ReaderUI, one_time_providers)
|
||||
end,
|
||||
},
|
||||
{
|
||||
|
||||
@@ -14,6 +14,7 @@ Example:
|
||||
|
||||
]]
|
||||
|
||||
local Blitbuffer = require("ffi/blitbuffer")
|
||||
local CheckMark = require("ui/widget/checkmark")
|
||||
local Device = require("device")
|
||||
local Font = require("ui/font")
|
||||
@@ -50,6 +51,7 @@ function CheckButton:initCheckButton(checked)
|
||||
self.checked = checked
|
||||
self._checkmark = CheckMark:new{
|
||||
checked = self.checked,
|
||||
enabled = self.enabled,
|
||||
parent = self.parent or self,
|
||||
show_parent = self.show_parent or self,
|
||||
}
|
||||
@@ -57,6 +59,7 @@ function CheckButton:initCheckButton(checked)
|
||||
text = self.text,
|
||||
face = self.face,
|
||||
max_width = self.max_width,
|
||||
fgcolor = self.enabled and Blitbuffer.COLOR_BLACK or Blitbuffer.COLOR_DARK_GRAY,
|
||||
}
|
||||
self._horizontalgroup = HorizontalGroup:new{
|
||||
self._checkmark,
|
||||
@@ -143,4 +146,21 @@ function CheckButton:unCheck()
|
||||
end)
|
||||
end
|
||||
|
||||
function CheckButton:enable()
|
||||
self.enabled = true
|
||||
self:initCheckButton(self.checked)
|
||||
UIManager:setDirty(self.parent, function()
|
||||
return "ui", self.dimen
|
||||
end)
|
||||
end
|
||||
|
||||
function CheckButton:disable()
|
||||
self.enabled = false
|
||||
self:initCheckButton(false)
|
||||
UIManager:setDirty(self.parent, function()
|
||||
return "ui", self.dimen
|
||||
-- best to use "ui" instead of "fast" when we make things gray
|
||||
end)
|
||||
end
|
||||
|
||||
return CheckButton
|
||||
|
||||
@@ -455,7 +455,7 @@ function FileChooser:getNextFile(curr_file)
|
||||
return next_file
|
||||
end
|
||||
|
||||
function FileChooser:showSetProviderButtons(file, filemanager_instance, reader_ui)
|
||||
function FileChooser:showSetProviderButtons(file, filemanager_instance, reader_ui, one_time_providers)
|
||||
local __, filename_pure = util.splitFilePathName(file)
|
||||
local filename_suffix = util.getFileNameSuffix(file)
|
||||
|
||||
@@ -486,6 +486,17 @@ function FileChooser:showSetProviderButtons(file, filemanager_instance, reader_u
|
||||
},
|
||||
})
|
||||
end
|
||||
if one_time_providers and #one_time_providers > 0 then
|
||||
for ___, provider in ipairs(one_time_providers) do
|
||||
provider.one_time_provider = true
|
||||
table.insert(radio_buttons, {
|
||||
{
|
||||
text = provider.provider_name,
|
||||
provider = provider,
|
||||
},
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
table.insert(buttons, {
|
||||
{
|
||||
@@ -499,6 +510,11 @@ function FileChooser:showSetProviderButtons(file, filemanager_instance, reader_u
|
||||
is_enter_default = true,
|
||||
callback = function()
|
||||
local provider = self.set_provider_dialog.radio_button_table.checked_button.provider
|
||||
if provider.one_time_provider then
|
||||
UIManager:close(self.set_provider_dialog)
|
||||
provider.callback()
|
||||
return
|
||||
end
|
||||
|
||||
-- always for this file
|
||||
if self.set_provider_dialog._check_file_button.checked then
|
||||
|
||||
@@ -490,7 +490,7 @@ end
|
||||
|
||||
function InputDialog:onCloseWidget()
|
||||
self:onClose()
|
||||
UIManager:setDirty(nil, function()
|
||||
UIManager:setDirty(nil, self.fullscreen and "full" or function()
|
||||
return "partial", self.dialog_frame.dimen
|
||||
end)
|
||||
end
|
||||
|
||||
@@ -13,6 +13,7 @@ local LeftContainer = require("ui/widget/container/leftcontainer")
|
||||
local LineWidget = require("ui/widget/linewidget")
|
||||
local RadioButtonTable = require("ui/widget/radiobuttontable")
|
||||
local Size = require("ui/size")
|
||||
local TextBoxWidget = require("ui/widget/textboxwidget")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local VerticalGroup = require("ui/widget/verticalgroup")
|
||||
local VerticalSpan = require("ui/widget/verticalspan")
|
||||
@@ -24,6 +25,21 @@ local OpenWithDialog = InputDialog:extend{}
|
||||
function OpenWithDialog:init()
|
||||
-- init title and buttons in base class
|
||||
InputDialog.init(self)
|
||||
|
||||
-- replace single line title with a multiline one,
|
||||
-- as the filename might be long
|
||||
self.title_widget:free()
|
||||
self.title_widget = FrameContainer:new{
|
||||
padding = self.title_padding,
|
||||
margin = self.title_margin,
|
||||
bordersize = 0,
|
||||
TextBoxWidget:new{
|
||||
text = self.title,
|
||||
width = self.width - 2*self.title_padding - 2*self.title_margin,
|
||||
face = self.title_face,
|
||||
},
|
||||
}
|
||||
|
||||
self.face = Font:getFace("cfont", 22)
|
||||
|
||||
self.radio_button_table = RadioButtonTable:new{
|
||||
@@ -33,6 +49,15 @@ function OpenWithDialog:init()
|
||||
scroll = false,
|
||||
parent = self,
|
||||
face = self.face,
|
||||
button_select_callback = function(btn)
|
||||
if btn.provider.one_time_provider then
|
||||
self._check_file_button:disable()
|
||||
self._check_global_button:disable()
|
||||
else
|
||||
self._check_file_button:enable()
|
||||
self._check_global_button:enable()
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
self._check_file_button = self._check_file_button or CheckButton:new{
|
||||
|
||||
@@ -27,6 +27,7 @@ local RadioButtonTable = FocusManager:new{
|
||||
face = Font:getFace("cfont", 22),
|
||||
_first_button = nil,
|
||||
checked_button = nil,
|
||||
button_select_callback = nil,
|
||||
}
|
||||
|
||||
function RadioButtonTable:init()
|
||||
@@ -72,6 +73,9 @@ function RadioButtonTable:init()
|
||||
}
|
||||
local button_callback = function()
|
||||
self:_checkButton(button)
|
||||
if self.button_select_callback then
|
||||
self.button_select_callback(btn_entry)
|
||||
end
|
||||
end
|
||||
button.callback = button_callback
|
||||
|
||||
|
||||
@@ -329,6 +329,7 @@ function TextEditor:chooseFile()
|
||||
end
|
||||
|
||||
function TextEditor:checkEditFile(file_path, from_history, possibly_new_file)
|
||||
self:loadSettings()
|
||||
local attr = lfs.attributes(file_path)
|
||||
if not possibly_new_file and not attr then
|
||||
UIManager:show(ConfirmBox:new{
|
||||
|
||||
Reference in New Issue
Block a user