-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject_browser.lua
More file actions
203 lines (160 loc) · 5.85 KB
/
project_browser.lua
File metadata and controls
203 lines (160 loc) · 5.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
-- @file project_browser.lua
-- Project Browser panel controller
local qt_constants = require("qt_constants")
local ui_constants = require("ui_constants")
local command_manager = require("command_manager")
local command_scope = require("command_scope")
local tag_service = require("tag_service")
local logger = require("logger")
local dkjson = require("dkjson")
local uuid = require("uuid")
local browser_state = require("ui.project_browser.browser_state")
local browser_tree = require("ui.project_browser.browser_tree")
local browser_actions = require("ui.project_browser.browser_actions")
local keymap = require("ui.project_browser.keymap")
local M = {}
local ACTIVATE_COMMAND = "project_browser.activate"
local tree_context
local tab_container
local tab_label
local layout
local is_restoring_selection = false
-- ============================================================================
-- Panel lifecycle & orchestration
-- ============================================================================
function M.create(parent)
layout = qt_constants.WIDGETS.CREATE_VBOX(parent)
tab_container = qt_constants.WIDGETS.CREATE_WIDGET(layout)
tab_label = qt_constants.WIDGETS.CREATE_LABEL(tab_container)
qt_constants.LAYOUT.ADD_WIDGET(layout, tab_container)
M.project_title_widget = tab_label
if M.pending_project_title then
local pending = M.pending_project_title
M.pending_project_title = nil
if qt_constants.PROPERTIES.SET_TEXT then
qt_constants.PROPERTIES.SET_TEXT(tab_label, pending)
end
end
tree_context = {
qt_constants = qt_constants,
ui_constants = ui_constants,
register_handler = register_handler,
resolve_tree_item = resolve_tree_item,
set_is_restoring_selection = function(v)
is_restoring_selection = v
end,
}
browser_tree.create_tree(tree_context)
browser_tree.populate_tree(tree_context)
browser_actions.setup(tree_context)
return layout
end
function M.refresh()
if not tree_context then return end
browser_tree.populate_tree(tree_context)
end
function M.get_focus_widgets()
return { tree_context.tree_widget }
end
-- ============================================================================
-- Selection & activation coordination
-- ============================================================================
local function selection_context()
return {
tree_widget = tree_context.tree_widget,
get_selected_item = M.get_selected_item,
focus_master_clip = M.focus_master_clip,
focus_sequence = M.focus_sequence,
focus_bin = M.focus_bin,
}
end
local function activate_item(item_info)
if not item_info then return end
browser_state.activate_item(item_info, selection_context())
end
local function apply_single_selection(info)
if not info then return end
browser_state.apply_single_selection(info, selection_context())
end
local function update_selection_state(info)
if is_restoring_selection then return end
browser_state.update_selection_state(info, selection_context())
end
function M.activate_selection()
local info = M.get_selected_item()
activate_item(info)
return true
end
-- ============================================================================
-- Rename / inline-edit workflow
-- ============================================================================
local function finalize_pending_rename(new_name)
browser_actions.finalize_pending_rename(new_name)
end
local function handle_tree_editor_closed(event)
finalize_pending_rename(event.text)
end
local function handle_tree_item_changed(event)
update_selection_state(event.info)
end
function M.start_inline_rename()
browser_actions.start_inline_rename()
end
-- ============================================================================
-- Cross-boundary handlers (tree ↔ state ↔ actions)
-- ============================================================================
handle_tree_drop = function(event)
local info = browser_tree.lookup_item_by_tree_id(tree_context, event.tree_id)
if not info then return end
browser_actions.handle_drop(info, event)
end
handle_tree_key_event = function(event)
local action = keymap.map_key_event(event)
if action then
browser_actions.handle_key_action(action)
return true
end
end
-- ============================================================================
-- Public module API
-- ============================================================================
function M.get_selected_item()
return browser_state.get_selected_item()
end
function M.get_selected_bin()
return browser_state.get_selected_bin()
end
function M.get_selected_master_clip()
return browser_state.get_selected_master_clip()
end
function M.get_selected_media()
return browser_state.get_selected_media()
end
function M.get_selection_snapshot()
return browser_state.get_selection_snapshot()
end
function M.set_project_title(name)
if M.project_title_widget and qt_constants.PROPERTIES.SET_TEXT then
qt_constants.PROPERTIES.SET_TEXT(M.project_title_widget, name)
else
M.pending_project_title = name
end
end
function M.focus_master_clip(master_clip_id, opts)
browser_state.focus_master_clip(master_clip_id, opts)
end
function M.focus_bin(bin_id, opts)
browser_state.focus_bin(bin_id, opts)
end
function M.focus_sequence(sequence_id, opts)
browser_state.focus_sequence(sequence_id, opts)
end
command_manager.register_executor(ACTIVATE_COMMAND, function()
local ok, err = M.activate_selection()
if not ok and err then
logger.warn("project_browser", tostring(err))
end
return ok and true or false
end)
command_scope.register(ACTIVATE_COMMAND, {scope = "panel", panel_id = "project_browser"})
return M