@@ -7,6 +7,7 @@ local events = require("neo-tree.events")
7
7
local log = require (" neo-tree.log" )
8
8
local popups = require (" neo-tree.ui.popups" )
9
9
local highlights = require (" neo-tree.ui.highlights" )
10
+ local manager = require (" neo-tree.sources.manager" )
10
11
11
12
-- If you add a new source, you need to add it to the sources table.
12
13
-- Each source should have a defaults module that contains the default values
@@ -19,7 +20,7 @@ local sources = {
19
20
20
21
local M = {}
21
22
22
- -- Adding this as a shortcut because the module path is so long.
23
+ -- TODO: DEPRECATED in 1.19, remove in 2.0
23
24
M .fs = require (" neo-tree.sources.filesystem" )
24
25
25
26
local normalize_mappings = function (config )
@@ -68,80 +69,81 @@ local define_events = function()
68
69
events_setup = true
69
70
end
70
71
71
- local src = function (source_name )
72
+ local check_source = function (source_name )
72
73
if source_name == nil or source_name == " " then
73
74
source_name = M .config .default_source
74
75
end
75
- local success , source = pcall (require , " neo-tree.sources." .. source_name )
76
+ local success , result = pcall (require , " neo-tree.sources." .. source_name )
76
77
if not success then
77
- error (" Source " .. source_name .. " not found. " )
78
+ error (" Source " .. source_name .. " could not be loaded: " , result )
78
79
end
79
- source .name = source_name
80
- return source
80
+ return source_name
81
81
end
82
82
83
83
M .close_all_except = function (source_name )
84
- local source = src (source_name )
85
- local target_pos = utils .get_value (M , " config." .. source . name .. " .window.position" , " left" )
84
+ source_name = check_source (source_name )
85
+ local target_pos = utils .get_value (M , " config." .. source_name .. " .window.position" , " left" )
86
86
for _ , name in ipairs (sources ) do
87
87
if name ~= source_name then
88
88
local pos = utils .get_value (M , " config." .. name .. " .window.position" , " left" )
89
89
if pos == target_pos then
90
- M .close (name )
90
+ manager .close (source_name )
91
91
end
92
92
end
93
93
end
94
- M . close_all ( " float " )
94
+ renderer . close_all_floating_windows ( )
95
95
end
96
96
97
- M .close = function (source_name )
98
- return src (source_name ).close ()
99
- end
97
+ M .close = manager .close
100
98
101
99
M .close_all = function (at_position )
102
100
renderer .close_all_floating_windows ()
103
101
if type (at_position ) == " string" and at_position > " " then
104
102
for _ , name in ipairs (sources ) do
105
103
local pos = utils .get_value (M , " config." .. name .. " .window.position" , " left" )
106
104
if pos == at_position then
107
- M .close (name )
105
+ manager .close (name )
108
106
end
109
107
end
110
108
else
111
109
for _ , name in ipairs (sources ) do
112
- M .close (name )
110
+ manager .close (name )
113
111
end
114
112
end
115
113
end
116
114
117
115
M .float = function (source_name , toggle_if_open )
118
- source_name = src (source_name ). name
116
+ source_name = check_source (source_name )
119
117
if toggle_if_open then
120
118
if renderer .close_floating_window (source_name ) then
121
119
-- It was open, and now it's not.
122
120
return
123
121
end
124
122
end
125
- M . close_all ( " float " )
126
- M .close (source_name ) -- in case this source is open in a sidebar
127
- src ( source_name ) .float ()
123
+ renderer . close_all_floating_windows ( )
124
+ manager .close (source_name ) -- in case this source is open in a sidebar
125
+ manager .float (source_name )
128
126
end
129
127
130
128
M .focus = function (source_name , close_others , toggle_if_open )
129
+ source_name = check_source (source_name )
131
130
if toggle_if_open then
132
- if M .close (source_name ) then
131
+ if manager .close (source_name ) then
133
132
-- It was open, and now it's not.
134
133
return
135
134
end
136
135
end
137
136
if close_others == nil then
138
137
close_others = true
139
138
end
140
- local source = src (source_name )
141
139
if close_others then
142
- M .close_all_except (source . name )
140
+ M .close_all_except (source_name )
143
141
end
144
- source .focus ()
142
+ manager .focus (source_name )
143
+ end
144
+
145
+ M .reveal_current_file = function (source_name , toggle_if_open )
146
+ manager .reveal_current_file (source_name , toggle_if_open )
145
147
end
146
148
147
149
M .get_prior_window = function ()
@@ -200,26 +202,26 @@ M.win_enter_event = function()
200
202
end
201
203
202
204
M .show = function (source_name , do_not_focus , close_others , toggle_if_open )
205
+ source_name = check_source (source_name )
203
206
if toggle_if_open then
204
- if M .close (source_name ) then
207
+ if manager .close (source_name ) then
205
208
-- It was open, and now it's not.
206
209
return
207
210
end
208
211
end
209
212
if close_others == nil then
210
213
close_others = true
211
214
end
212
- local source = src (source_name )
213
215
if close_others then
214
- M .close_all_except (source . name )
216
+ M .close_all_except (source_name )
215
217
end
216
218
if do_not_focus then
217
219
local current_win = vim .api .nvim_get_current_win ()
218
- source .show (function ()
220
+ manager .show (source_name , function ()
219
221
vim .api .nvim_set_current_win (current_win )
220
222
end )
221
223
else
222
- source .show ()
224
+ manager .show (source_name )
223
225
end
224
226
end
225
227
@@ -308,7 +310,7 @@ M.setup = function(config)
308
310
309
311
-- setup the sources with the combined config
310
312
for _ , source_name in ipairs (sources ) do
311
- src ( source_name ) .setup (M .config [source_name ], M .config )
313
+ manager .setup (source_name , M .config [source_name ], M .config )
312
314
end
313
315
314
316
local event_handler = {
0 commit comments