|
|
@ -127,8 +127,11 @@ function Exporter:isReady()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function Exporter:isDocReady()
|
|
|
|
function Exporter:isDocReady()
|
|
|
|
local docless = self.ui == nil or self.ui.document == nil or self.view == nil
|
|
|
|
return self.ui and self.ui.document and self.view
|
|
|
|
return not docless and self:isReady()
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function Exporter:isReadyToExport()
|
|
|
|
|
|
|
|
return self:isDocReady() and self:isReady()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function Exporter:requiresNetwork()
|
|
|
|
function Exporter:requiresNetwork()
|
|
|
@ -141,8 +144,12 @@ function Exporter:requiresNetwork()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function Exporter:getDocumentClippings()
|
|
|
|
|
|
|
|
return self.parser:parseCurrentDoc(self.view) or {}
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function Exporter:exportCurrentNotes()
|
|
|
|
function Exporter:exportCurrentNotes()
|
|
|
|
local clippings = self.parser:parseCurrentDoc(self.view)
|
|
|
|
local clippings = self:getDocumentClippings()
|
|
|
|
self:exportClippings(clippings)
|
|
|
|
self:exportClippings(clippings)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
@ -193,20 +200,34 @@ end
|
|
|
|
|
|
|
|
|
|
|
|
function Exporter:addToMainMenu(menu_items)
|
|
|
|
function Exporter:addToMainMenu(menu_items)
|
|
|
|
local submenu = {}
|
|
|
|
local submenu = {}
|
|
|
|
|
|
|
|
local sharemenu = {}
|
|
|
|
for k, v in pairs(self.targets) do
|
|
|
|
for k, v in pairs(self.targets) do
|
|
|
|
submenu[#submenu + 1] = v:getMenuTable()
|
|
|
|
submenu[#submenu + 1] = v:getMenuTable()
|
|
|
|
|
|
|
|
if v.shareable then
|
|
|
|
|
|
|
|
sharemenu[#sharemenu + 1] = { text = _("Share as " .. v.name), callback = function()
|
|
|
|
|
|
|
|
local clippings = self:getDocumentClippings()
|
|
|
|
|
|
|
|
local document
|
|
|
|
|
|
|
|
for _, notes in pairs(clippings) do
|
|
|
|
|
|
|
|
document = notes or {}
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if #document > 0 then
|
|
|
|
|
|
|
|
v:share(document)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
table.sort(submenu, function(v1, v2)
|
|
|
|
table.sort(submenu, function(v1, v2)
|
|
|
|
return v1.text < v2.text
|
|
|
|
return v1.text < v2.text
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
local menu = {
|
|
|
|
menu_items.exporter = {
|
|
|
|
|
|
|
|
text = _("Export highlights"),
|
|
|
|
text = _("Export highlights"),
|
|
|
|
sub_item_table = {
|
|
|
|
sub_item_table = {
|
|
|
|
{
|
|
|
|
{
|
|
|
|
text = _("Export all notes in this book"),
|
|
|
|
text = _("Export all notes in this book"),
|
|
|
|
enabled_func = function()
|
|
|
|
enabled_func = function()
|
|
|
|
return self:isDocReady()
|
|
|
|
return self:isReadyToExport()
|
|
|
|
end,
|
|
|
|
end,
|
|
|
|
callback = function()
|
|
|
|
callback = function()
|
|
|
|
self:exportCurrentNotes()
|
|
|
|
self:exportCurrentNotes()
|
|
|
@ -220,7 +241,7 @@ function Exporter:addToMainMenu(menu_items)
|
|
|
|
callback = function()
|
|
|
|
callback = function()
|
|
|
|
self:exportAllNotes()
|
|
|
|
self:exportAllNotes()
|
|
|
|
end,
|
|
|
|
end,
|
|
|
|
separator = true,
|
|
|
|
separator = #sharemenu == 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
|
|
|
text = _("Choose formats and services"),
|
|
|
|
text = _("Choose formats and services"),
|
|
|
@ -229,6 +250,20 @@ function Exporter:addToMainMenu(menu_items)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if #sharemenu > 0 then
|
|
|
|
|
|
|
|
table.sort(sharemenu, function(v1, v2)
|
|
|
|
|
|
|
|
return v1.text < v2.text
|
|
|
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
table.insert(menu.sub_item_table, 3, {
|
|
|
|
|
|
|
|
text = _("Share all notes in this book"),
|
|
|
|
|
|
|
|
enabled_func = function()
|
|
|
|
|
|
|
|
return self:isDocReady()
|
|
|
|
|
|
|
|
end,
|
|
|
|
|
|
|
|
sub_item_table = sharemenu,
|
|
|
|
|
|
|
|
separator = true,
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
menu_items.exporter = menu
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
return Exporter
|
|
|
|
return Exporter
|
|
|
|