<commit_before>--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--                   C  O  M  M  A  N  D  P  O  S  T                          --
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

--- === plugins.core.action.activator ===
---
--- This module provides provides a way of activating choices provided by action handlers.
--- It also provide support for making a particular action a favourite, returning
--- results based on popularity, and completely hiding particular actions, or categories of action.
---
--- Activators are accessed via the [action manager](plugins.core.action.manager.md) like so:
---
--- ```lua
--- local activator = actionManager.getActivator("foobar")
--- activator:disableHandler("videoEffect")
--- activator:show()
--- ```
---
--- Any changes made to the settings of a finder (such as calling `disableHandler` above) will
--- be preserved for future loads of the finder with the same ID. They are also local
--- to instances of this activator, so disabling "videoEffect" in the "foobar" activator
--- will not affect the "yadayada" activator.
local log						= require("hs.logger").new("activator")
local bench						= require("cp.bench")

local _							= require("moses")
local prop						= require("cp.prop")
local config					= require("cp.config")
local just						= require("cp.just")
local chooser					= require("hs.chooser")
local drawing 					= require("hs.drawing")
local fnutils 					= require("hs.fnutils")
local menubar					= require("hs.menubar")
local mouse						= require("hs.mouse")
local screen					= require("hs.screen")
local timer						= require("hs.timer")
local application				= require("hs.application")
local fcp						= require("cp.apple.finalcutpro")
local idle						= require("cp.idle")

local setmetatable				= setmetatable
local sort, insert				= table.sort, table.insert
local concat, filter			= fnutils.concat, fnutils.filter
local format					= string.format

local activator = {}
activator.mt = {}
activator.mt.__index = activator.mt

local PACKAGE = "finalcutpro.action.activator."

local function applyHiddenTo(choice, hidden)
	if choice.oldText then
		choice.text = choice.oldText
	end

	if hidden then
		choice.oldText = choice.text
		choice.text = i18n("actionHiddenText", {text = choice.text})
		choice.hidden = true
	else
		choice.oldText = nil
		choice.hidden = nil
	end
end

-- plugins.core.action.activator.new(id, manager)
-- Constructor
-- Creates a new `activator` instance with the specified ID and action manager
function activator.new(id, manager)
	local o = {
		_id				= id,
		_manager		= manager,
		_chooser	= nil, 		-- the actual hs.chooser
	}

	prop.extend(o, activator.mt)

	local prefix = PACKAGE .. id .. "."

	--- plugins.core.action.activator.searchSubText <cp.prop: boolean>
	--- Field
	--- If `true`, allow users to search the subtext value.
	o.searchSubText = config.prop(prefix .. "searchSubText", true):bind(o)

	--- plugins.core.action.activator.lastQueryRemembered <cp.prop: boolean>
	--- Field
	--- If `true`, remember the last query.
	o.lastQueryRemembered = config.prop(prefix .. "lastQueryRemembered", true):bind(o)

	--- plugins.core.action.activator.lastQueryValue <cp.prop: string>
	--- Field
	--- The last query value.
	o.lastQueryValue = config.prop(prefix .. "lastQueryValue", ""):bind(o)

	--- plugins.core.action.activator.showHidden <cp.prop: boolean>
	--- Field
	--- If `true`, hidden items are shown.
	o.showHidden = config.prop(prefix .. "showHidden", false):bind(o)
	-- refresh the chooser list if this status changes.
	:watch(function() o:refreshChooser() end)

	-- plugins.core.action.activator._allowedHandlers <cp.prop: string>
	-- Field
	-- The ID of a single handler to source
	-- o._allowedHandlers = config.prop(prefix .. "allowedHandlers", nil):bind(o)
	o._allowedHandlers = prop.THIS(nil):bind(o)

--- plugins.core.action.activator:allowedHandlers <cp.prop: table of handlers; read-only>
--- Field
--- Contains all handlers that are allowed in this activator.
	o.allowedHandlers = o._manager.handlers:mutate(function(handlers)
		local allowed = {}
		local allowedIds = o:_allowedHandlers()

		for id,handler in pairs(handlers) do
			if allowedIds == nil or allowedIds[id] then
				allowed[id] = handler
			end
		end

		return allowed
	end):bind(o)

	-- plugins.core.action.activator._disabledHandlers <cp.prop: table of booleans>
	-- Field
	-- Table of disabled handlers. If the ID is present with a value of `true`, it's disabled.
	o._disabledHandlers = config.prop(prefix .. "disabledHandlers", {}):bind(o)
	:watch(function() o:refreshChooser() end)

--- plugins.core.action.activator.activeHandlers <cp.prop: table of handlers>
--- Field
--- Contains the table of active handlers. A handler is active if it is both allowed and enabled.
--- The handler ID is the key, so use `pairs` to iterate the list. E.g.:
---<commit_msg>Bug Fix<commit_after>--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--                   C  O  M  M  A  N  D  P  O  S  T                          --
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

--- === plugins.core.action.activator ===
---
--- This module provides provides a way of activating choices provided by action handlers.
--- It also provide support for making a particular action a favourite, returning
--- results based on popularity, and completely hiding particular actions, or categories of action.
---
--- Activators are accessed via the [action manager](plugins.core.action.manager.md) like so:
---
--- ```lua
--- local activator = actionManager.getActivator("foobar")
--- activator:disableHandler("videoEffect")
--- activator:show()
--- ```
---
--- Any changes made to the settings of a finder (such as calling `disableHandler` above) will
--- be preserved for future loads of the finder with the same ID. They are also local
--- to instances of this activator, so disabling "videoEffect" in the "foobar" activator
--- will not affect the "yadayada" activator.
local log						= require("hs.logger").new("activator")
local bench						= require("cp.bench")

local _							= require("moses")
local prop						= require("cp.prop")
local config					= require("cp.config")
local just						= require("cp.just")
local chooser					= require("hs.chooser")
local drawing 					= require("hs.drawing")
local fnutils 					= require("hs.fnutils")
local menubar					= require("hs.menubar")
local mouse						= require("hs.mouse")
local screen					= require("hs.screen")
local timer						= require("hs.timer")
local application				= require("hs.application")
local fcp						= require("cp.apple.finalcutpro")
local idle						= require("cp.idle")

local setmetatable				= setmetatable
local sort, insert				= table.sort, table.insert
local concat, filter			= fnutils.concat, fnutils.filter
local format					= string.format

local activator = {}
activator.mt = {}
activator.mt.__index = activator.mt

local PACKAGE = "finalcutpro.action.activator."

local function applyHiddenTo(choice, hidden)
	if choice.oldText then
		choice.text = choice.oldText
	end

	if hidden then
		choice.oldText = choice.text
		choice.text = i18n("actionHiddenText", {text = choice.text})
		choice.hidden = true
	else
		choice.oldText = nil
		choice.hidden = nil
	end
end

-- plugins.core.action.activator.new(id, manager)
-- Constructor
-- Creates a new `activator` instance with the specified ID and action manager
function activator.new(id, manager)
	local o = {
		_id				= id,
		_manager		= manager,
		_chooser	= nil, 		-- the actual hs.chooser
	}

	prop.extend(o, activator.mt)

	local prefix = PACKAGE .. id .. "."

	--- plugins.core.action.activator.searchSubText <cp.prop: boolean>
	--- Field
	--- If `true`, allow users to search the subtext value.
	o.searchSubText = config.prop(prefix .. "searchSubText", true):bind(o)

	--- plugins.core.action.activator.lastQueryRemembered <cp.prop: boolean>
	--- Field
	--- If `true`, remember the last query.
	o.lastQueryRemembered = config.prop(prefix .. "lastQueryRemembered", true):bind(o)

	--- plugins.core.action.activator.lastQueryValue <cp.prop: string>
	--- Field
	--- The last query value.
	o.lastQueryValue = config.prop(prefix .. "lastQueryValue", ""):bind(o)

	--- plugins.core.action.activator.showHidden <cp.prop: boolean>
	--- Field
	--- If `true`, hidden items are shown.
	o.showHidden = config.prop(prefix .. "showHidden", false):bind(o)
	-- refresh the chooser list if this status changes.
	:watch(function() o:refreshChooser() end)

	-- plugins.core.action.activator._allowedHandlers <cp.prop: string>
	-- Field
	-- The ID of a single handler to source
	--o._allowedHandlers = config.prop(prefix .. "allowedHandlers", nil):bind(o)
	--o._allowedHandlers = prop.THIS(nil):bind(o)
	o._allowedHandlers = prop.THIS({}):bind(o)

--- plugins.core.action.activator:allowedHandlers <cp.prop: table of handlers; read-only>
--- Field
--- Contains all handlers that are allowed in this activator.
	o.allowedHandlers = o._manager.handlers:mutate(function(handlers)
		local allowed = {}
		local allowedIds = o:_allowedHandlers()

		for id,handler in pairs(handlers) do
			if allowedIds == nil or allowedIds[id] then
				allowed[id] = handler
			end
		end

		return allowed
	end):bind(o)

	-- plugins.core.action.activator._disabledHandlers <cp.prop: table of booleans>
	-- Field
	-- Table of disabled handlers. If the ID is present with a value of `true`, it's disabled.
	o._disabledHandlers = config.prop(prefix .. "disabledHandlers", {}):bind(o)
	:watch(function() o:refreshChooser() end)

--- plugins.core.action.activator.activeHandlers <cp.prop: table of handlers>
--- Field
--- Contains the table of active handlers. A handler is active if it is both allowed and enabled.
--- The handler ID is the key, so use `pairs` to iterate the list. E.g.:
---
{'fraction_non_alphanumeric': 0.18690487876705605, 'fraction_numerical': 0.0003926573083341514, 'mean_word_length': 2.5911173775114555, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '666105', 'n_tokens_mistral': 3181, 'n_tokens_neox': 2922, 'n_words': 887}