|
1 | 1 | local vim = vim
|
2 | 2 | local utils = require("neo-tree.utils")
|
3 |
| -local renderer = require("neo-tree.ui.renderer") |
4 | 3 | local log = require("neo-tree.log")
|
5 |
| -local manager = require("neo-tree.sources.manager") |
6 |
| -local setup = require("neo-tree.setup") |
7 |
| - |
8 |
| --- If you add a new source, you need to add it to the sources table. |
9 |
| --- Each source should have a defaults module that contains the default values |
10 |
| --- for the source config, and a setup function that takes that config. |
11 |
| -local sources = { |
12 |
| - "filesystem", |
13 |
| - "buffers", |
14 |
| - "git_status", |
15 |
| -} |
16 |
| - |
17 | 4 | local M = {}
|
18 | 5 |
|
19 |
| -local check_source = function(source_name) |
20 |
| - if not utils.truthy(source_name) then |
21 |
| - source_name = M.config.default_source |
22 |
| - end |
23 |
| - local success, result = pcall(require, "neo-tree.sources." .. source_name) |
24 |
| - if not success then |
25 |
| - error("Source " .. source_name .. " could not be loaded: ", result) |
26 |
| - end |
27 |
| - return source_name |
28 |
| -end |
29 |
| - |
30 |
| -local get_position = function(source_name) |
31 |
| - local pos = utils.get_value(M, "config." .. source_name .. ".window.position", "left", false) |
32 |
| - return pos |
33 |
| -end |
34 |
| - |
35 | 6 | M.ensure_config = function()
|
36 | 7 | if not M.config then
|
37 | 8 | M.setup({ log_to_file = false }, true)
|
38 | 9 | end
|
39 | 10 | end
|
40 | 11 |
|
41 |
| ---DEPRECATED in v2.x |
42 |
| -M.close_all_except = function(source_name) |
43 |
| - -- this entire function is faulty now that position can be overriden at runtime |
44 |
| - source_name = check_source(source_name) |
45 |
| - local target_pos = get_position(source_name) |
46 |
| - for _, name in ipairs(sources) do |
47 |
| - if name ~= source_name then |
48 |
| - local pos = utils.get_value(M, "config." .. name .. ".window.position", "left", false) |
49 |
| - if pos == target_pos then |
50 |
| - manager.close(name) |
51 |
| - end |
52 |
| - end |
53 |
| - end |
54 |
| - renderer.close_all_floating_windows() |
55 |
| -end |
56 |
| - |
57 |
| ---DEPRECATED in v2.x |
58 |
| -M.close = manager.close |
59 |
| - |
60 |
| ---DEPRECATED in v2.x, use manager.close_all() |
61 |
| -M.close_all = function(at_position) |
62 |
| - renderer.close_all_floating_windows() |
63 |
| - if type(at_position) == "string" and at_position > "" then |
64 |
| - for _, name in ipairs(sources) do |
65 |
| - local pos = get_position(name) |
66 |
| - if pos == at_position then |
67 |
| - manager.close(name) |
68 |
| - end |
69 |
| - end |
70 |
| - else |
71 |
| - for _, name in ipairs(sources) do |
72 |
| - manager.close(name) |
73 |
| - end |
74 |
| - end |
75 |
| -end |
76 |
| - |
77 |
| ---DEPRECATED in v2.x, use commands.execute() |
78 |
| -M.float = function(source_name, toggle_if_open) |
79 |
| - M.ensure_config() |
80 |
| - source_name = check_source(source_name) |
81 |
| - if toggle_if_open then |
82 |
| - if renderer.close_floating_window(source_name) then |
83 |
| - -- It was open, and now it's not. |
84 |
| - return |
85 |
| - end |
86 |
| - end |
87 |
| - renderer.close_all_floating_windows() |
88 |
| - manager.close(source_name) -- in case this source is open in a sidebar |
89 |
| - manager.float(source_name) |
90 |
| -end |
91 |
| - |
92 |
| ---DEPRECATED in v2.x, use commands.execute() |
93 |
| -M.focus = function(source_name, close_others, toggle_if_open) |
94 |
| - M.ensure_config() |
95 |
| - source_name = check_source(source_name) |
96 |
| - if get_position(source_name) == "current" then |
97 |
| - M.show_in_split(source_name, toggle_if_open) |
98 |
| - return |
99 |
| - end |
100 |
| - |
101 |
| - if toggle_if_open then |
102 |
| - if manager.close(source_name) then |
103 |
| - -- It was open, and now it's not. |
104 |
| - return |
105 |
| - end |
106 |
| - end |
107 |
| - if close_others == nil then |
108 |
| - close_others = true |
109 |
| - end |
110 |
| - if close_others then |
111 |
| - M.close_all_except(source_name) |
112 |
| - end |
113 |
| - manager.focus(source_name) |
114 |
| -end |
115 |
| - |
116 |
| ---DEPRECATED in v2.x, use commands.execute() |
117 |
| -M.reveal_current_file = function(source_name, toggle_if_open, force_cwd) |
118 |
| - M.ensure_config() |
119 |
| - source_name = check_source(source_name) |
120 |
| - if get_position(source_name) == "current" then |
121 |
| - M.reveal_in_split(source_name, toggle_if_open) |
122 |
| - return |
123 |
| - end |
124 |
| - if toggle_if_open then |
125 |
| - if manager.close(source_name) then |
126 |
| - -- It was open, and now it's not. |
127 |
| - return |
128 |
| - end |
129 |
| - end |
130 |
| - manager.reveal_current_file(source_name, nil, force_cwd) |
131 |
| -end |
132 |
| - |
133 |
| ---DEPRECATED in v2.x, use commands.execute() |
134 |
| -M.reveal_in_split = function(source_name, toggle_if_open) |
135 |
| - M.ensure_config() |
136 |
| - source_name = check_source(source_name) |
137 |
| - if toggle_if_open then |
138 |
| - local state = manager.get_state(source_name, nil, vim.api.nvim_get_current_win()) |
139 |
| - if renderer.close(state) then |
140 |
| - -- It was open, and now it's not. |
141 |
| - return |
142 |
| - end |
143 |
| - end |
144 |
| - --TODO: if we are currently in a sidebar, don't replace it with a split style |
145 |
| - manager.reveal_in_split(source_name) |
146 |
| -end |
147 |
| - |
148 |
| ---DEPRECATED in v2.x, use commands.execute() |
149 |
| -M.show_in_split = function(source_name, toggle_if_open) |
150 |
| - M.ensure_config() |
151 |
| - source_name = check_source(source_name) |
152 |
| - if toggle_if_open then |
153 |
| - local state = manager.get_state(source_name, nil, vim.api.nvim_get_current_win()) |
154 |
| - if renderer.close(state) then |
155 |
| - -- It was open, and now it's not. |
156 |
| - return |
157 |
| - end |
158 |
| - end |
159 |
| - --TODO: if we are currently in a sidebar, don't replace it with a split style |
160 |
| - manager.show_in_split(source_name) |
161 |
| -end |
162 |
| - |
163 | 12 | M.get_prior_window = function(ignore_filetypes)
|
164 | 13 | ignore_filetypes = ignore_filetypes or {}
|
165 | 14 | local ignore = utils.list_to_dict(ignore_filetypes)
|
@@ -212,31 +61,6 @@ M.paste_default_config = function()
|
212 | 61 | end)
|
213 | 62 | end
|
214 | 63 |
|
215 |
| -M.buffer_enter_event = setup.buffer_enter_event |
216 |
| -M.win_enter_event = setup.win_enter_event |
217 |
| - |
218 |
| ---DEPRECATED in v2.x |
219 |
| ---BREAKING CHANGE: Removed the do_not_focus and close_others options in 2.0 |
220 |
| ---M.show = function(source_name, do_not_focus, close_others, toggle_if_open) |
221 |
| -M.show = function(source_name, toggle_if_open) |
222 |
| - M.ensure_config() |
223 |
| - source_name = check_source(source_name) |
224 |
| - if get_position(source_name) == "current" then |
225 |
| - M.show_in_split(source_name, toggle_if_open) |
226 |
| - return |
227 |
| - end |
228 |
| - |
229 |
| - if toggle_if_open then |
230 |
| - if manager.close(source_name) then |
231 |
| - -- It was open, and now it's not. |
232 |
| - return |
233 |
| - end |
234 |
| - end |
235 |
| - |
236 |
| - M.close_all_except(source_name) |
237 |
| - manager.show(source_name) |
238 |
| -end |
239 |
| - |
240 | 64 | M.set_log_level = function(level)
|
241 | 65 | log.set_level(level)
|
242 | 66 | end
|
|
0 commit comments