Commit: ff245e754dbe5329f459f128bbf2b5dbf6c2c6be
Parent: 4f92f6d4ee5e28f832d474fef22da19a6fc64c8b
Author: Ren Tatsumoto
Date: Fri, 26 Feb 2021 09:52:38 +0300
rewrite clipboard autocopy
Diffstat:
M | subs2srs.lua | | | 60 | ++++++++++++++++++++++++++++++++++++++---------------------- |
1 file changed, 38 insertions(+), 22 deletions(-)
diff --git a/subs2srs.lua b/subs2srs.lua
@@ -1222,32 +1222,48 @@ end
------------------------------------------------------------
-- send subs to clipboard as they appear
-clip_autocopy = {}
+clip_autocopy = (function()
+ local enable = function()
+ mp.observe_property("sub-text", "string", copy_to_clipboard)
+ end
-clip_autocopy.enable = function()
- mp.observe_property("sub-text", "string", copy_to_clipboard)
- notify("Clipboard autocopy has been enabled.", "info", 1)
-end
+ local disable = function()
+ mp.unobserve_property(copy_to_clipboard)
+ end
-clip_autocopy.disable = function()
- mp.unobserve_property(copy_to_clipboard)
- notify("Clipboard autocopy has been disabled.", "info", 1)
-end
+ local state_notify = function()
+ notify(string.format("Clipboard autocopy has been %s.", config.autoclip and 'enabled' or 'disabled'))
+ end
-clip_autocopy.toggle = function()
- if config.autoclip == true then
- clip_autocopy.disable()
- config.autoclip = false
- else
- clip_autocopy.enable()
- config.autoclip = true
+ local toggle = function()
+ config.autoclip = not config.autoclip
+ if config.autoclip == true then
+ clip_autocopy.enable()
+ else
+ clip_autocopy.disable()
+ end
+ state_notify()
+ menu.update()
end
- menu.update()
-end
-clip_autocopy.is_enabled = function()
- return config.autoclip == true and 'enabled' or 'disabled'
-end
+ local is_enabled = function()
+ return config.autoclip == true and 'enabled' or 'disabled'
+ end
+
+ local init = function()
+ if config.autoclip == true then
+ clip_autocopy.enable()
+ end
+ end
+
+ return {
+ enable = enable,
+ disable = disable,
+ init = init,
+ toggle = toggle,
+ is_enabled = is_enabled,
+ }
+end)()
------------------------------------------------------------
-- Subtitle class provides methods for comparing subtitle lines
@@ -1450,7 +1466,7 @@ do
if main_executed then return end
validate_config()
ankiconnect.create_deck(config.deck_name)
- if config.autoclip == true then clip_autocopy.enable() end
+ clip_autocopy.init()
-- Key bindings
mp.add_forced_key_binding("ctrl+e", "mpvacious-export-note", export_to_anki)