summaryrefslogtreecommitdiff
path: root/mpv/scripts/file-browser/modules/controls.lua
diff options
context:
space:
mode:
authorryukamish <[email protected]>2026-04-11 16:06:45 +0530
committerryukamish <[email protected]>2026-04-11 16:06:45 +0530
commit607891801fbf2051a0c9062d15a445dd238c1e1b (patch)
tree33b8cfba2355b498addea05e385b06d46cced30f /mpv/scripts/file-browser/modules/controls.lua
parent6fbde2906e3bb2d4d1df23f6374d8a6a0aef870f (diff)
add: mako and mpv configs
Diffstat (limited to 'mpv/scripts/file-browser/modules/controls.lua')
-rw-r--r--mpv/scripts/file-browser/modules/controls.lua94
1 files changed, 94 insertions, 0 deletions
diff --git a/mpv/scripts/file-browser/modules/controls.lua b/mpv/scripts/file-browser/modules/controls.lua
new file mode 100644
index 0000000..6b124c2
--- /dev/null
+++ b/mpv/scripts/file-browser/modules/controls.lua
@@ -0,0 +1,94 @@
+
+local mp = require 'mp'
+local msg = require 'mp.msg'
+local utils = require 'mp.utils'
+
+local o = require 'modules.options'
+local g = require 'modules.globals'
+local fb_utils = require 'modules.utils'
+local movement = require 'modules.navigation.directory-movement'
+local ass = require 'modules.ass'
+local cursor = require 'modules.navigation.cursor'
+
+---@class controls
+local controls = {}
+
+--opens the browser
+function controls.open()
+ if not g.state.hidden then return end
+
+ for _,v in ipairs(g.state.keybinds) do
+ mp.add_forced_key_binding(v[1], 'dynamic/'..v[2], v[3], v[4])
+ end
+
+ if o.set_shared_script_properties then utils.shared_script_property_set('file_browser-open', 'yes') end ---@diagnostic disable-line deprecated
+ if o.set_user_data then mp.set_property_bool('user-data/file_browser/open', true) end
+
+ if o.toggle_idlescreen then mp.commandv('script-message', 'osc-idlescreen', 'no', 'no_osd') end
+ g.state.hidden = false
+ if g.state.directory == nil then
+ local path = mp.get_property('path')
+ if path or o.default_to_working_directory then movement.goto_current_dir() else movement.goto_root() end
+ return
+ end
+
+ if not g.state.flag_update then ass.draw()
+ else g.state.flag_update = false ; ass.update_ass() end
+end
+
+--closes the list and sets the hidden flag
+function controls.close()
+ if g.state.hidden then return end
+
+ for _,v in ipairs(g.state.keybinds) do
+ mp.remove_key_binding('dynamic/'..v[2])
+ end
+
+ if o.set_shared_script_properties then utils.shared_script_property_set("file_browser-open", "no") end ---@diagnostic disable-line deprecated
+ if o.set_user_data then mp.set_property_bool('user-data/file_browser/open', false) end
+
+ if o.toggle_idlescreen then mp.commandv('script-message', 'osc-idlescreen', 'yes', 'no_osd') end
+ g.state.hidden = true
+ ass.remove()
+end
+
+--toggles the list
+function controls.toggle()
+ if g.state.hidden then controls.open()
+ else controls.close() end
+end
+
+--run when the escape key is used
+function controls.escape()
+ --if multiple items are selection cancel the
+ --selection instead of closing the browser
+ if next(g.state.selection) or g.state.multiselect_start then
+ g.state.selection = {}
+ cursor.disable_select_mode()
+ ass.update_ass()
+ return
+ end
+ controls.close()
+end
+
+---opens a specific directory
+---@param directory string
+---@param open_browser? boolean
+---@return thread|nil
+function controls.browse_directory(directory, open_browser)
+ if not directory then return end
+ if open_browser == nil then open_browser = true end
+
+ directory = mp.command_native({"expand-path", directory}, '') --[[@as string]]
+ -- directory = join_path( mp.get_property("working-directory", ""), directory )
+
+ if directory ~= "" then directory = fb_utils.fix_path(directory, true) end
+ msg.verbose('recieved directory from script message: '..directory)
+
+ directory = fb_utils.resolve_directory_mapping(directory)
+ local co = movement.goto_directory(directory, nil, nil, {cache={use=false}})
+ if open_browser then controls.open() end
+ return co
+end
+
+return controls