aboutsummaryrefslogtreecommitdiffstats
path: root/macros/garret.dupe-and-comment.lua
diff options
context:
space:
mode:
authorgarret <garret@airmail.cc>2021-10-09 15:20:50 +0100
committergarret <garret@airmail.cc>2021-10-09 15:20:50 +0100
commit472fc5337dc41abc9545256720f3265f466f9b16 (patch)
treed38b119d08cef1517ba70b1f56ca48aff201c959 /macros/garret.dupe-and-comment.lua
parent52f3a086f2ad7a3bbc9b8f8225a99e9e99120613 (diff)
downloadaegisub-scripts-472fc5337dc41abc9545256720f3265f466f9b16.tar.gz
aegisub-scripts-472fc5337dc41abc9545256720f3265f466f9b16.tar.bz2
aegisub-scripts-472fc5337dc41abc9545256720f3265f466f9b16.zip
add depctrl thing
no feed yet, will get round to it eventuallyâ„¢
Diffstat (limited to 'macros/garret.dupe-and-comment.lua')
-rw-r--r--macros/garret.dupe-and-comment.lua55
1 files changed, 55 insertions, 0 deletions
diff --git a/macros/garret.dupe-and-comment.lua b/macros/garret.dupe-and-comment.lua
new file mode 100644
index 0000000..c74d6c6
--- /dev/null
+++ b/macros/garret.dupe-and-comment.lua
@@ -0,0 +1,55 @@
+script_name="Dupe and Comment"
+script_description="Copies a line and comments out the original.\nbecause i like seeing the original while editing, and being able to go back to it easily"
+script_author = "garret"
+script_version = "2.1.0"
+script_namespace = "garret.dupe-and-comment"
+
+local haveDepCtrl, DependencyControl, depctrl = pcall(require, "l0.DependencyControl")
+local util
+if haveDepCtrl then
+ depctrl = DependencyControl {
+ --feed="TODO",
+ {"aegisub.util"}
+ }
+ util = depctrl:requireModules()
+else
+ util = require 'aegisub.util'
+end
+
+function comment(subs, sel)
+ for i=#sel,1,-1 do
+ local line=subs[sel[i]]
+ local dupe = util.copy(line)
+ line.comment = false -- going to edit it, so we probably want to see it on the video
+ dupe.comment = true -- this is the actual original one
+ subs.insert(sel[i]+1,dupe) -- putting it on the next line so i don't have to change line
+ end
+ aegisub.set_undo_point(script_name)
+end
+
+function undo(subs, sel)
+ for i=#sel,1,-1 do
+ local edit=subs[sel[i]]
+ local original=subs[sel[i]+1]
+ if edit.comment == false and original.comment == true then
+ original.comment = false
+ subs[sel[i]+1] = original
+ subs.delete(sel[i])
+ end
+ end
+ aegisub.set_undo_point("Undo "..script_name)
+end
+
+local macros = {
+ {"Do", script_description, comment},
+ {"Undo","Deletes selected line and restores the original", undo}
+}
+if haveDepCtrl then
+ depctrl:registerMacros(macros)
+else
+ for _,macro in ipairs(macros) do
+ local name, desc, fun = unpack(macro)
+ aegisub.register_macro(script_name .. '/' .. name, desc, fun)
+ end
+end
+-- i trust what petzku from the cartel has to say on adding multiple macros with depctrl