From b1498aa664a550e274cdc797e30ed56456379e4e Mon Sep 17 00:00:00 2001 From: wpferguson Date: Wed, 10 Feb 2021 00:18:48 -0500 Subject: [PATCH] inline if didn't work. Added intermediate register_event function in transition library --- contrib/AutoGrouper.lua | 3 +- contrib/HDRMerge.lua | 3 +- contrib/LabelsToTags.lua | 3 +- contrib/OpenInExplorer.lua | 3 +- contrib/autostyle.lua | 5 +-- contrib/clear_GPS.lua | 3 +- contrib/copy_attach_detach_tags.lua | 11 ++++--- contrib/cr2hdr.lua | 7 ++-- contrib/exportLUT.lua | 3 +- contrib/ext_editor.lua | 5 +-- contrib/face_recognition.lua | 3 +- contrib/fujifilm_dynamic_range.lua | 3 +- contrib/fujifilm_ratings.lua | 3 +- contrib/geoToolbox.lua | 11 ++++--- contrib/gpx_export.lua | 3 +- contrib/image_time.lua | 3 +- contrib/photils.lua | 5 +-- contrib/quicktag.lua | 5 +-- contrib/rate_group.lua | 15 +++++---- contrib/rename-tags.lua | 3 +- contrib/slideshowMusic.lua | 3 +- contrib/transfer_hierarchy.lua | 3 +- examples/moduleExample.lua | 3 +- examples/multi_os.lua | 3 +- lib/darktable_transition.lua | 51 +++++++++++++++++++++++++++++ official/copy_paste_metadata.lua | 5 +-- official/enfuse.lua | 3 +- official/generate_image_txt.lua | 3 +- official/image_path_in_ui.lua | 5 +-- official/import_filter_manager.lua | 3 +- official/save_selection.lua | 8 ++--- tools/executable_manager.lua | 3 +- tools/script_manager.lua | 3 +- 33 files changed, 139 insertions(+), 57 deletions(-) create mode 100644 lib/darktable_transition.lua diff --git a/contrib/AutoGrouper.lua b/contrib/AutoGrouper.lua index 0f69e5d..849b881 100644 --- a/contrib/AutoGrouper.lua +++ b/contrib/AutoGrouper.lua @@ -37,6 +37,7 @@ selected images, the other button performs grouping on the entire active collect ]] local dt = require "darktable" + require "lib/darktable_transition" local MOD = 'autogrouper' local gettext = dt.gettext -- Tell gettext where to find the .mo file translating messages for a particular domain @@ -175,7 +176,7 @@ if dt.gui.current_view().id == "lighttable" then else if not Ag.event_registered then dt.register_event( - CURR_API_STRING >= "6.2.1" and "AutoGrouper", "view-changed" or "view-changed" , + "AutoGrouper", "view-changed", function(event, old_view, new_view) if new_view.name == "lighttable" and old_view.name == "darkroom" then install_module() diff --git a/contrib/HDRMerge.lua b/contrib/HDRMerge.lua index b35ea1c..5c1635a 100644 --- a/contrib/HDRMerge.lua +++ b/contrib/HDRMerge.lua @@ -46,6 +46,7 @@ Select a style, whether you want tags to be copied from the original, and any ad local dt = require 'darktable' local df = require 'lib/dtutils.file' + require "lib/darktable_transition" local dsys = require 'lib/dtutils.system' local mod = 'module_HDRMerge' local os_path_seperator = '/' @@ -438,7 +439,7 @@ if dt.gui.current_view().id == "lighttable" then else if not HDRM.event_registered then dt.register_event( - CURR_API_STRING >= "6.2.1" and "HDRmerge", "view-changed" or "view-changed" , + "HDRmerge", "view-changed", function(event, old_view, new_view) if new_view.name == "lighttable" and old_view.name == "darkroom" then install_module() diff --git a/contrib/LabelsToTags.lua b/contrib/LabelsToTags.lua index 5ab2395..e2dc5c4 100644 --- a/contrib/LabelsToTags.lua +++ b/contrib/LabelsToTags.lua @@ -49,6 +49,7 @@ local darktable = require("darktable") local du = require "lib/dtutils" + require "lib/darktable_transition" du.check_min_api_version("3.0.0", "LabelsToTags") @@ -248,7 +249,7 @@ if darktable.gui.current_view().id == "lighttable" then else if not ltt.event_registered then darktable.register_event( - CURR_API_STRING >= "6.2.1" and LIB_ID, "view-changed" or "view-changed" , + LIB_ID, "view-changed", function(event, old_view, new_view) if new_view.name == "lighttable" and old_view.name == "darkroom" then install_module() diff --git a/contrib/OpenInExplorer.lua b/contrib/OpenInExplorer.lua index cfc7d57..72ec15d 100644 --- a/contrib/OpenInExplorer.lua +++ b/contrib/OpenInExplorer.lua @@ -50,6 +50,7 @@ As an alternative option you can choose to show the image file names as symbolic local dt = require "darktable" local du = require "lib/dtutils" local df = require "lib/dtutils.file" + require "lib/darktable_transition" local dsys = require "lib/dtutils.system" local gettext = dt.gettext @@ -209,7 +210,7 @@ if act_os ~= "windows" then end dt.register_event( - CURR_API_STRING >= "6.2.1" and "OpenInExplorer", "shortcut" or "shortcut", + "OpenInExplorer", "shortcut", function(event, shortcut) open_in_fmanager() end, "OpenInExplorer" ) diff --git a/contrib/autostyle.lua b/contrib/autostyle.lua index a134b72..fc726a6 100644 --- a/contrib/autostyle.lua +++ b/contrib/autostyle.lua @@ -38,6 +38,7 @@ GPLv2 local darktable = require "darktable" local du = require "lib/dtutils" + require "lib/darktable_transition" local filelib = require "lib/dtutils.file" -- Forward declare the functions @@ -152,12 +153,12 @@ function get_stdout(cmd) end -- Registering events -darktable.register_event(CURR_API_STRING >= "6.2.1" and "autostyle", "shortcut" or "shortcut" ,autostyle_apply, +darktable.register_event("autostyle", "shortcut", autostyle_apply, "Apply your chosen style from exiftool tags") darktable.preferences.register("autostyle","exif_tag","string","Autostyle: EXIF_tag=value=>style","apply a style automatically if an EXIF_tag matches value. Find the tag with exiftool","") -darktable.register_event(CURR_API_STRING >= "6.2.1" and "autostyle", "post-import-image" or "post-import-image" , +darktable.register_event("autostyle", "post-import-image", autostyle_apply_one_image_event) diff --git a/contrib/clear_GPS.lua b/contrib/clear_GPS.lua index 08ed7f5..58404f9 100644 --- a/contrib/clear_GPS.lua +++ b/contrib/clear_GPS.lua @@ -38,6 +38,7 @@ local dt = require "darktable" local du = require "lib/dtutils" + require "lib/darktable_transition" local gettext = dt.gettext -- not a number @@ -71,7 +72,7 @@ dt.gui.libs.image.register_action( ) dt.register_event( - CURR_API_STRING >= "6.2.1" and "clearGPS", "shortcut" or "shortcut" , + "clearGPS", "shortcut", function(event, shortcut) clear_GPS(dt.gui.action_images) end, _("Clear GPS data") ) diff --git a/contrib/copy_attach_detach_tags.lua b/contrib/copy_attach_detach_tags.lua index 3af07d0..6f2b936 100644 --- a/contrib/copy_attach_detach_tags.lua +++ b/contrib/copy_attach_detach_tags.lua @@ -39,6 +39,7 @@ USAGE local dt = require "darktable" local du = require "lib/dtutils" local debug = require "darktable.debug" + require "lib/darktable_transition" local gettext = dt.gettext @@ -234,7 +235,7 @@ if dt.gui.current_view().id == "lighttable" then else if not cadt.event_registered then dt.register_event( - CURR_API_STRING >= "6.2.1" and "cadt", "view-changed" or "view-changed" , + "cadt", "view-changed", function(event, old_view, new_view) if new_view.name == "lighttable" and old_view.name == "darkroom" then install_module() @@ -247,22 +248,22 @@ end -- shortcut for copy -dt.register_event(CURR_API_STRING >= "6.2.1" and "cadt_ct", "shortcut" or "shortcut" , +dt.register_event("cadt_ct", "shortcut", mcopy_tags, _('copy tags from selected image(s)')) -- shortcut for attach -dt.register_event(CURR_API_STRING >= "6.2.1" and "cadt_at", "shortcut" or "shortcut" , +dt.register_event("cadt_at", "shortcut", attach_tags, _('paste tags to selected image(s)')) -- shortcut for detaching tags -dt.register_event(CURR_API_STRING >= "6.2.1" and "cadt_dt", "shortcut" or "shortcut" , +dt.register_event("cadt_dt", "shortcut", detach_tags, _('remove tags from selected image(s)')) -- shortcut for replace tags -dt.register_event(CURR_API_STRING >= "6.2.1" and "cadt_rt", "shortcut" or "shortcut" , +dt.register_event("cadt_rt", "shortcut", replace_tags, _('replace tags from selected image(s)')) diff --git a/contrib/cr2hdr.lua b/contrib/cr2hdr.lua index f7a5bcf..c27082e 100644 --- a/contrib/cr2hdr.lua +++ b/contrib/cr2hdr.lua @@ -34,6 +34,7 @@ USAGE local darktable = require "darktable" local du = require "lib/dtutils" + require "lib/darktable_transition" -- Tested with darktable 2.0.1 du.check_min_api_version("2.0.0", "cr2hdr") @@ -108,11 +109,11 @@ local function convert_action_images(shortcut) convert_images() end -darktable.register_event(CURR_API_STRING >= "6.2.1" and "cr2hdr", "shortcut" or "shortcut" , +darktable.register_event("cr2hdr", "shortcut", convert_action_images, "Run cr2hdr (Magic Lantern DualISO converter) on selected images") -darktable.register_event(CURR_API_STRING >= "6.2.1" and "cr2hdr", "post-import-image" or "post-import-image" , +darktable.register_event("cr2hdr", "post-import-image", file_imported) -darktable.register_event(CURR_API_STRING >= "6.2.1" and "cr2hdr", "post-import-film" or "post-import-film" , +darktable.register_event("cr2hdr", "post-import-film", film_imported) darktable.preferences.register("cr2hdr", "onimport", "bool", "Invoke on import", "If true then cr2hdr will try to proccess every file during importing. Warning: cr2hdr is quite slow even in figuring out on whether the file is Dual ISO or not.", false) diff --git a/contrib/exportLUT.lua b/contrib/exportLUT.lua index ca9288e..4b039a8 100644 --- a/contrib/exportLUT.lua +++ b/contrib/exportLUT.lua @@ -30,6 +30,7 @@ local dt = require "darktable" local du = require "lib/dtutils" local df = require("lib/dtutils.file") local ds = require("lib/dtutils.system") + require "lib/darktable_transition" local gettext = dt.gettext @@ -162,7 +163,7 @@ if dt.gui.current_view().id == "lighttable" then else if not eL.event_registered then dt.register_event( - CURR_API_STRING >= "6.2.1" and "exportLUT", "view-changed" or "view-changed" , + "exportLUT", "view-changed", function(event, old_view, new_view) if new_view.name == "lighttable" and old_view.name == "darkroom" then install_module() diff --git a/contrib/ext_editor.lua b/contrib/ext_editor.lua index 7e90362..2df2237 100644 --- a/contrib/ext_editor.lua +++ b/contrib/ext_editor.lua @@ -70,6 +70,7 @@ local dt = require "darktable" local du = require "lib/dtutils" local df = require "lib/dtutils.file" + require "lib/darktable_transition" local dtsys = require "lib/dtutils.system" @@ -417,7 +418,7 @@ if dt.gui.current_view().id == "lighttable" then else if not ee.event_registered then dt.register_event( - CURR_API_STRING >= "6.2.1" and MODULE_NAME, "view-changed" or "view-changed" , + MODULE_NAME, "view-changed", function(event, old_view, new_view) if new_view.name == "lighttable" and old_view.name == "darkroom" then install_module() @@ -452,7 +453,7 @@ for i = MAX_EDITORS, 1, -1 do -- register the new shortcuts ------------------------------------------------- for i = 1, MAX_EDITORS do - dt.register_event(CURR_API_STRING >= "6.2.1" and MODULE_NAME .. i, "shortcut" or "shortcut" , + dt.register_event(MODULE_NAME .. i, "shortcut", program_shortcut, _("edit with program ")..string.format("%02d", i)) end diff --git a/contrib/face_recognition.lua b/contrib/face_recognition.lua index d520453..77cd2ab 100644 --- a/contrib/face_recognition.lua +++ b/contrib/face_recognition.lua @@ -44,6 +44,7 @@ local dt = require "darktable" local du = require "lib/dtutils" local df = require "lib/dtutils.file" local dtsys = require "lib/dtutils.system" + require "lib/darktable_transition" local gettext = dt.gettext -- constants @@ -490,7 +491,7 @@ if dt.gui.current_view().id == "lighttable" then else if not fc.event_registered then dt.register_event( - CURR_API_STRING >= "6.2.1" and MODULE, "view-changed" or "view-changed" , + MODULE, "view-changed", function(event, old_view, new_view) if new_view.name == "lighttable" and old_view.name == "darkroom" then install_module() diff --git a/contrib/fujifilm_dynamic_range.lua b/contrib/fujifilm_dynamic_range.lua index 7f54195..4986675 100644 --- a/contrib/fujifilm_dynamic_range.lua +++ b/contrib/fujifilm_dynamic_range.lua @@ -60,6 +60,7 @@ cameras may behave in other ways. local dt = require "darktable" local du = require "lib/dtutils" local df = require "lib/dtutils.file" + require "lib/darktable_transition" du.check_min_api_version("4.0.0", "fujifilm_dynamic_range") local CURR_API_STRING = dt.configuration.api_version_string @@ -105,7 +106,7 @@ local function detect_dynamic_range(event, image) dt.print_log("[fujifilm_dynamic_range] raw exposure bias " .. tostring(raf_result)) end -dt.register_event(CURR_API_STRING >= "6.2.1" and "fujifilm_dr", "post-import-image" or "post-import-image" , +dt.register_event("fujifilm_dr", "post-import-image", detect_dynamic_range) dt.print_log("[fujifilm_dynamic_range] loaded") diff --git a/contrib/fujifilm_ratings.lua b/contrib/fujifilm_ratings.lua index 45da92d..05319d4 100644 --- a/contrib/fujifilm_ratings.lua +++ b/contrib/fujifilm_ratings.lua @@ -26,6 +26,7 @@ Dependencies: local dt = require "darktable" local du = require "lib/dtutils" local df = require "lib/dtutils.file" + require "lib/darktable_transition" local gettext = dt.gettext du.check_min_api_version("4.0.0", "fujifilm_ratings") @@ -67,7 +68,7 @@ local function detect_rating(event, image) end end -dt.register_event(CURR_API_STRING >= "6.2.1" and "fujifilm_rat", "post-import-image" or "post-import-image" , +dt.register_event("fujifilm_rat", "post-import-image", detect_rating) print(_("fujifilm_ratings loaded.")) diff --git a/contrib/geoToolbox.lua b/contrib/geoToolbox.lua index 9edad19..cdbc1c0 100644 --- a/contrib/geoToolbox.lua +++ b/contrib/geoToolbox.lua @@ -28,6 +28,7 @@ require "geoToolbox" local dt = require "darktable" local du = require "lib/dtutils" local df = require "lib/dtutils.file" + require "lib/darktable_transition" local gettext = dt.gettext du.check_min_api_version("3.0.0", "geoToolbox") @@ -688,7 +689,7 @@ if dt.gui.current_view().id == "lighttable" then else if not gT.event_registered then dt.register_event( - CURR_API_STRING >= "6.2.1" and "geoToolbox", "view-changed" or "view-chagned", + "geoToolbox", "view-changed", function(event, old_view, new_view) if new_view.name == "lighttable" and old_view.name == "darkroom" then install_module() @@ -708,14 +709,14 @@ dt.preferences.register("geoToolbox", '' ) -- Register -dt.register_event(CURR_API_STRING >= "6.2.1" and "geoToolbox_cd", "shortcut" or "shortcut" , +dt.register_event("geoToolbox_cd", "shortcut", print_calc_distance, _("Calculate the distance from latitude and longitude in km")) -dt.register_event(CURR_API_STRING >= "6.2.1" and "geoToolbox", "mouse-over-image-changed" or "mouse-over-image-changed" , +dt.register_event("geoToolbox", "mouse-over-image-changed", toolbox_calc_distance) -dt.register_event(CURR_API_STRING >= "6.2.1" and "geoToolbox_wg", "shortcut" or "shortcut" , +dt.register_event("geoToolbox_wg", "shortcut", select_with_gps, _("Select all images with GPS information")) -dt.register_event(CURR_API_STRING >= "6.2.1" and "geoToolbox_ng", "shortcut" or "shortcut" , +dt.register_event("geoToolbox_ng", "shortcut", select_without_gps, _("Select all images without GPS information")) -- vim: shiftwidth=2 expandtab tabstop=2 cindent syntax=lua diff --git a/contrib/gpx_export.lua b/contrib/gpx_export.lua index 45111ce..58e4147 100644 --- a/contrib/gpx_export.lua +++ b/contrib/gpx_export.lua @@ -25,6 +25,7 @@ For each source folder, a separate is generated in the gpx file. local dt = require "darktable" local df = require "lib/dtutils.file" local dl = require "lib/dtutils" + require "lib/darktable_transition" local gettext = dt.gettext dl.check_min_api_version("3.0.0", "gpx-export") @@ -174,7 +175,7 @@ if dt.gui.current_view().id == "lighttable" then else if not gpx.event_registered then dt.register_event( - CURR_API_STRING >= "6.2.1" and "gpx_export", "view-changed" or "view-changed" , + "gpx_export", "view-changed", function(event, old_view, new_view) if new_view.name == "lighttable" and old_view.name == "darkroom" then install_module() diff --git a/contrib/image_time.lua b/contrib/image_time.lua index 1af6f2d..0f09c2d 100644 --- a/contrib/image_time.lua +++ b/contrib/image_time.lua @@ -107,6 +107,7 @@ local dt = require "darktable" local du = require "lib/dtutils" local df = require "lib/dtutils.file" local ds = require "lib/dtutils.string" + require "lib/darktable_transition" local gettext = dt.gettext local img_time = {} @@ -552,7 +553,7 @@ if dt.gui.current_view().id == "lighttable" then else if not img_time.event_registered then dt.register_event( - CURR_API_STRING >= "6.2.1" and "image_time", "view-changed" or "view-changed" , + "image_time", "view-changed", function(event, old_view, new_view) if new_view.name == "lighttable" and old_view.name == "darkroom" then install_module() diff --git a/contrib/photils.lua b/contrib/photils.lua index d303a7b..69829be 100644 --- a/contrib/photils.lua +++ b/contrib/photils.lua @@ -39,6 +39,7 @@ local dt = require "darktable" local du = require "lib/dtutils" local df = require "lib/dtutils.file" + require "lib/darktable_transition" local dtsys = require "lib/dtutils.system" local MODULE_NAME = "photils" @@ -434,7 +435,7 @@ dt.preferences.register(MODULE_NAME, _("if enabled, the confidence value for each tag is displayed"), true) -dt.register_event(CURR_API_STRING >= "6.2.1" and "photils", "mouse-over-image-changed" or "mouse-over-image-changed" , +dt.register_event("photils", "mouse-over-image-changed", PHOTILS.image_changed) if dt.gui.current_view().id == "lighttable" then @@ -442,7 +443,7 @@ if dt.gui.current_view().id == "lighttable" then else if not PHOTILS.event_registered then dt.register_event( - CURR_API_STRING >= "6.2.1" and "photils", "view-changed" or "view-changed", + "photils", "view-changed", function(event, old_view, new_view) if new_view.name == "lighttable" and old_view.name == "darkroom" then install_module() diff --git a/contrib/quicktag.lua b/contrib/quicktag.lua index 8834b6e..34053c9 100644 --- a/contrib/quicktag.lua +++ b/contrib/quicktag.lua @@ -45,6 +45,7 @@ USAGE local dt = require "darktable" local du = require "lib/dtutils" + require "lib/darktable_transition" local debug = require "darktable.debug" local qt = {} @@ -257,7 +258,7 @@ if dt.gui.current_view().id == "lighttable" then else if not qt.event_registered then dt.register_event( - CURR_API_STRING >= "6.2.1" and "quicktag", "view-changed" or "view-changed" , + "quicktag", "view-changed", function(event, old_view, new_view) if new_view.name == "lighttable" and old_view.name == "darkroom" then install_module() @@ -270,7 +271,7 @@ end -- create shortcuts for i=1,qnr do - dt.register_event(CURR_API_STRING >= "6.2.1" and "quicktag", "shortcut" or "shortcut" , + dt.register_event("quicktag", "shortcut", function(event, shortcut) tagattach(tostring(quicktag_table[i])) end, string.format(_("quicktag %i"),i)) end diff --git a/contrib/rate_group.lua b/contrib/rate_group.lua index 0f9dcc1..80fb4a6 100644 --- a/contrib/rate_group.lua +++ b/contrib/rate_group.lua @@ -40,6 +40,7 @@ local dt = require "darktable" local du = require "lib/dtutils" + require "lib/darktable_transition" -- added version check du.check_min_api_version("3.0.0", "rate_group") @@ -60,37 +61,37 @@ local function apply_rating(rating) end end -dt.register_event(CURR_API_STRING >= "6.2.1" and "rg_reject", "shortcut" or "shortcut" , +dt.register_event("rg_reject", "shortcut", function(event, shortcut) apply_rating(-1) end, "Reject group") -dt.register_event(CURR_API_STRING >= "6.2.1" and "rg0", "shortcut" or "shortcut", +dt.register_event("rg0", "shortcut", function(event, shortcut) apply_rating(0) end, "Rate group 0") -dt.register_event(CURR_API_STRING >= "6.2.1" and "rg1", "shortcut" or "shortcut", +dt.register_event("rg1", "shortcut", function(event, shortcut) apply_rating(1) end, "Rate group 1") -dt.register_event(CURR_API_STRING >= "6.2.1" and "rg2", "shortcut" or "shortcut", +dt.register_event("rg2", "shortcut", function(event, shortcut) apply_rating(2) end, "Rate group 2") -dt.register_event(CURR_API_STRING >= "6.2.1" and "rg3", "shortcut" or "shortcut", +dt.register_event("rg3", "shortcut", function(event, shortcut) apply_rating(3) end, "Rate group 3") -dt.register_event(CURR_API_STRING >= "6.2.1" and "rg4", "shortcut" or "shortcut", +dt.register_event("rg4", "shortcut", function(event, shortcut) apply_rating(4) end, "Rate group 4") -dt.register_event(CURR_API_STRING >= "6.2.1" and "rg5", "shortcut" or "shortcut", +dt.register_event("rg5", "shortcut", function(event, shortcut) apply_rating(5) end, "Rate group 5") diff --git a/contrib/rename-tags.lua b/contrib/rename-tags.lua index 23510dc..e8a5c9e 100644 --- a/contrib/rename-tags.lua +++ b/contrib/rename-tags.lua @@ -30,6 +30,7 @@ Changes local darktable = require "darktable" local du = require "lib/dtutils" + require "lib/darktable_transition" local debug = require "darktable.debug" -- check API version @@ -137,7 +138,7 @@ if darktable.gui.current_view().id == "lighttable" then else if not rt.event_registered then darktable.register_event( - CURR_API_STRING >= "6.2.1" and "rename_tags", "view-changed" or "view-changed" , + "rename_tags", "view-changed", function(event, old_view, new_view) if new_view.name == "lighttable" and old_view.name == "darkroom" then install_module() diff --git a/contrib/slideshowMusic.lua b/contrib/slideshowMusic.lua index 74e1acd..ff216af 100644 --- a/contrib/slideshowMusic.lua +++ b/contrib/slideshowMusic.lua @@ -27,6 +27,7 @@ USAGE local dt = require "darktable" local du = require "lib/dtutils" local df = require "lib/dtutils.file" + require "lib/darktable_transition" local gettext = dt.gettext du.check_min_api_version("2.0.2", "slideshowMusic") @@ -78,5 +79,5 @@ dt.preferences.register("slideshowMusic", _("Plays music with rhythmbox if a slideshow starts"), true) -- Register -dt.register_event(CURR_API_STRING >= "6.2.1" and "slideshow_music", "view-changed" or "view-changed" , +dt.register_event("slideshow_music", "view-changed", playSlideshowMusic) diff --git a/contrib/transfer_hierarchy.lua b/contrib/transfer_hierarchy.lua index b7f7bd4..03c1523 100755 --- a/contrib/transfer_hierarchy.lua +++ b/contrib/transfer_hierarchy.lua @@ -76,6 +76,7 @@ local darktable = require("darktable") local dtutils = require("lib/dtutils") local dtutils_file = require("lib/dtutils.file") local dtutils_system = require("lib/dtutils.system") + require "lib/darktable_transition" local LIB_ID = "transfer_hierarchy" dtutils.check_min_api_version("5.0.0", LIB_ID) @@ -367,7 +368,7 @@ if darktable.gui.current_view().id == "lighttable" then else if not th.event_registered then darktable.register_event( - CURR_API_STRING >= "6.2.1" and LIB_ID, "view-changed" or "view-changed" , + LIB_ID, "view-changed", function(event, old_view, new_view) if new_view.name == "lighttable" and old_view.name == "darkroom" then install_module() diff --git a/examples/moduleExample.lua b/examples/moduleExample.lua index 0ef2cd6..b778dca 100644 --- a/examples/moduleExample.lua +++ b/examples/moduleExample.lua @@ -32,6 +32,7 @@ https://www.darktable.org/lua-api/index.html.php#darktable_new_widget local dt = require "darktable" local du = require "lib/dtutils" + require "lib/darktable_transition" du.check_min_api_version("3.0.0", "moduleExample") local CURR_API_STRING = dt.configuration.api_version_string @@ -148,7 +149,7 @@ else if not mE.event_registered then -- if we are not in lighttable view then register an event to signal when we might be -- https://www.darktable.org/lua-api/index.html#darktable_register_event dt.register_event( - CURR_API_STRING >= "6.2.1" and "mdouleExample", "view-changed" or "view-chagned" , -- we want to be informed when the view changes + "mdouleExample", "view-changed", -- we want to be informed when the view changes function(event, old_view, new_view) if new_view.name == "lighttable" and old_view.name == "darkroom" then -- if the view changes from darkroom to lighttable install_module() -- register the lib diff --git a/examples/multi_os.lua b/examples/multi_os.lua index cbca5f6..6ab356b 100644 --- a/examples/multi_os.lua +++ b/examples/multi_os.lua @@ -52,6 +52,7 @@ ]] local dt = require "darktable" + require "lib/darktable_transition" --[[ require "lib/..." provides access to functions that have been pulled from various @@ -241,7 +242,7 @@ dt.gui.libs.image.register_action( ]] dt.register_event( - CURR_API_STRING >= "6.2.1" and "multi_os", "shortcut" or "shortcut" , + "multi_os", "shortcut", function(event, shortcut) extract_embedded_jpeg(dt.gui.action_images) end, "extract embedded jpeg" ) diff --git a/lib/darktable_transition.lua b/lib/darktable_transition.lua new file mode 100644 index 0000000..da5a421 --- /dev/null +++ b/lib/darktable_transition.lua @@ -0,0 +1,51 @@ +--[[ + + darktable_transition.lua - temporary library to help with API transition + + Copyright (C) 2016 Bill Ferguson . + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +]] +--[[ + darktable_transition - routines to maintain compatibility with new and previous API versions + +]] + +local dt +for k,v in pairs(package.loaded) do + if string.match(k, "darktable") then + dt = v + break + end +end + +if dt then + dt.orig_register_event = dt.register_event + + function dt.register_event(name, event, callback, tooltip) + if dt.configuration.api_version_string >= "6.2.1" then + if tooltip then + dt.orig_register_event(name, event, callback, tooltip) + else + dt.orig_register_event(name, event, callback) + end + else + if tooltip then + dt.orig_register_event(event, callback, tooltip) + else + dt.orig_register_event(event, callback) + end + end + end +end diff --git a/official/copy_paste_metadata.lua b/official/copy_paste_metadata.lua index bce3c2b..1db3d62 100644 --- a/official/copy_paste_metadata.lua +++ b/official/copy_paste_metadata.lua @@ -27,6 +27,7 @@ USAGE local dt = require "darktable" local du = require "lib/dtutils" + require "lib/darktable_transition" local gettext = dt.gettext du.check_min_api_version("3.0.0", "copy_paste_metadata") @@ -126,13 +127,13 @@ dt.gui.libs.image.register_action( ) dt.register_event( - CURR_API_STRING >= "6.2.1" and "capmd1", "shortcut" or "shortcut" , + "capmd1", "shortcut", function(event, shortcut) copy(dt.gui.action_images[1]) end, "copy metadata" ) dt.register_event( - CURR_API_STRING >= "6.2.1" and "capmd2", "shortcut" or "shortcut" , + "capmd2", "shortcut", function(event, shortcut) paste(dt.gui.action_images) end, "paste metadata" ) diff --git a/official/enfuse.lua b/official/enfuse.lua index f8ce5ae..1f494d9 100644 --- a/official/enfuse.lua +++ b/official/enfuse.lua @@ -36,6 +36,7 @@ local dt = require "darktable" local du = require "lib/dtutils" local df = require "lib/dtutils.file" local dtsys = require "lib/dtutils.system" + require "lib/darktable_transition" local PS = dt.configuration.running_os == "windows" and "\\" or "/" local CURR_API_STRING = dt.configuration.api_version_string @@ -269,7 +270,7 @@ if enfuse_installed then else if not enf.event_registered then dt.register_event( - CURR_API_STRING >= "6.2.1" and "enfuse", "view-changed" or "view-chagned" , + "enfuse", "view-changed", function(event, old_view, new_view) if new_view.name == "lighttable" and old_view.name == "darkroom" then install_module() diff --git a/official/generate_image_txt.lua b/official/generate_image_txt.lua index 20b9d47..b4ea475 100644 --- a/official/generate_image_txt.lua +++ b/official/generate_image_txt.lua @@ -36,6 +36,7 @@ USAGE local dt = require "darktable" local du = require "lib/dtutils" + require "lib/darktable_transition" require "darktable.debug" du.check_min_api_version("2.1.0", "generate_image_txt") @@ -66,7 +67,7 @@ end local command_setting = dt.preferences.read("generate_image_txt", "command", "string") check_command(command_setting) -dt.register_event(CURR_API_STRING >= "6.2.1" and "gen_img_txt", "mouse-over-image-changed" or "mouse-over-image-chagned" , +dt.register_event("gen_img_txt", "mouse-over-image-changed", function(event, img) -- no need to waste processing time if the image has a txt file already if not img or img.has_txt or not dt.preferences.read("generate_image_txt", "enabled", "bool") then diff --git a/official/image_path_in_ui.lua b/official/image_path_in_ui.lua index 130ea13..d98e571 100644 --- a/official/image_path_in_ui.lua +++ b/official/image_path_in_ui.lua @@ -30,6 +30,7 @@ This plugin will add a widget at the bottom of the left column in lighttable mod ]] local dt = require "darktable" local du = require "lib/dtutils" + require "lib/darktable_transition" du.check_min_api_version("2.0.0", "image_path_in_ui") local CURR_API_STRING = dt.configuration.api_version_string @@ -74,7 +75,7 @@ if dt.gui.current_view().id == "lighttable" then else if not ipiu.event_registered then dt.register_event( - CURR_API_STRING >= "6.2.1" and "ipiu", "view-changed" or "view-changed" , + "ipiu", "view-changed", function(event, old_view, new_view) if new_view.name == "lighttable" and old_view.name == "darkroom" then install_module() @@ -85,7 +86,7 @@ else end end -dt.register_event(CURR_API_STRING >= "6.2.1" and "ipiu", "mouse-over-image-changed" or "mouse-over-image-changed" , reset_widget); +dt.register_event("ipiu", "mouse-over-image-changed", reset_widget); -- -- vim: shiftwidth=2 expandtab tabstop=2 cindent syntax=lua diff --git a/official/import_filter_manager.lua b/official/import_filter_manager.lua index 682593e..74b5027 100644 --- a/official/import_filter_manager.lua +++ b/official/import_filter_manager.lua @@ -31,6 +31,7 @@ USAGE ]] local dt = require "darktable" + require "lib/darktable_transition" local import_filter_list = {} local n_import_filters = 1 @@ -57,7 +58,7 @@ dt.gui.libs.import.register_widget(filter_dropdown) -- this is just a wrapper which calls the active import filter -dt.register_event(CURR_API_STRING >= "6.2.1" and "ifm", "pre-import" or "pre-import" , function(event, images) +dt.register_event("ifm", "pre-import", function(event, images) local active_filter = dt.preferences.read("import_filter_manager", "active_filter", "string") if active_filter == "" then return end local callback = import_filter_list[active_filter] diff --git a/official/save_selection.lua b/official/save_selection.lua index b1abd4a..ba229f2 100644 --- a/official/save_selection.lua +++ b/official/save_selection.lua @@ -35,7 +35,7 @@ increase it if you need more temporary selection buffers ]] local dt = require "darktable" local du = require "lib/dtutils" - + require "lib/darktable_transition" du.check_min_api_version("2.0.0", "save_selection") local CURR_API_STRING = dt.configuration.api_version_string @@ -43,16 +43,16 @@ local buffer_count = 5 for i=1,buffer_count do local saved_selection - dt.register_event(CURR_API_STRING >= "6.2.1" and "save_selection", "shortcut" or "shortcut" ,function() + dt.register_event("save_selection", "shortcut", function() saved_selection = dt.gui.selection() end,"save to buffer "..i) - dt.register_event(CURR_API_STRING >= "6.2.1" and "save_selection1", "shortcut" or "shortcut" ,function() + dt.register_event("save_selection1", "shortcut", function() dt.gui.selection(saved_selection) end,"restore from buffer "..i) end local bounce_buffer = {} -dt.register_event(CURR_API_STRING >= "6.2.1" and "save_selection2", "shortcut" or "shortcut" ,function() +dt.register_event("save_selection2", "shortcut", function() bounce_buffer = dt.gui.selection(bounce_buffer) end,"switch selection with temporary buffer") diff --git a/tools/executable_manager.lua b/tools/executable_manager.lua index dd67228..c2afcec 100644 --- a/tools/executable_manager.lua +++ b/tools/executable_manager.lua @@ -31,6 +31,7 @@ local dt = require "darktable" local du = require "lib/dtutils" local df = require "lib/dtutils.file" + require "lib/darktable_transition" du.check_min_api_version("5.0.0", "executable_manager") @@ -215,7 +216,7 @@ if dt.gui.current_view().id == "lighttable" then else if not exec_man.event_registered then dt.register_event( - CURR_API_STRING >= "6.2.1" and "executable_manager", "view-changed" or "view-changed" , + "executable_manager", "view-changed", function(event, old_view, new_view) if new_view.name == "lighttable" and old_view.name == "darkroom" then install_module() diff --git a/tools/script_manager.lua b/tools/script_manager.lua index 845bf75..39812a7 100644 --- a/tools/script_manager.lua +++ b/tools/script_manager.lua @@ -54,6 +54,7 @@ local df = require "lib/dtutils.file" local ds = require "lib/dtutils.string" local dtsys = require "lib/dtutils.system" local log = require "lib/dtutils.log" + require "lib/darktable_transition" local gettext = dt.gettext @@ -882,7 +883,7 @@ if dt.gui.current_view().id == "lighttable" then else if not sm.event_registered then dt.register_event( - CURR_API_STRING >= "6.2.1" and "script_manager", "view-changed" or "view-changed" , + "script_manager", "view-changed", function(event, old_view, new_view) if new_view.name == "lighttable" and old_view.name == "darkroom" then install_module()