-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTabBarMan.lua
144 lines (112 loc) · 3.38 KB
/
TabBarMan.lua
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
-- TabBarMan.lua, LPr 7/2019
----------------------------------------------------------------------------------------------------
local TBM = {}
--[[
keys.c5 = function()
local original_tabs = {}
for i = 1, #_BUFFERS do
local buffer = _BUFFERS[i]
local filename = buffer.filename or buffer._type
original_tabs[#original_tabs + 1] = filename
view:goto_buffer(buffer)
end
io.close_all_buffers()
io.open_file(original_tabs[#original_tabs])
for i = 1, #original_tabs - 1 do
io.open_file(original_tabs[i])
end
end
--]]
TBM.moveTab = function(buf, dir)
buf = buf or buffer
local idx = _BUFFERS[buf]
local lo
if dir == ">" then
lo = idx
elseif dir == ">>" then
lo = idx
elseif dir == "<" then
lo = idx - 1
elseif dir == "<<" then
lo = 1
end
if lo < 1 then return end
if lo < idx then
-- Ensure 'lo' to point after '._type' bufs
for i = lo, #_BUFFERS do
if _BUFFERS[i].filename then lo = i; break end
end
if lo == idx then return end
end
--ui.print("idx", idx, "lo", lo)
do
local mod_bufs = {}
for i = lo, #_BUFFERS do
local buf = _BUFFERS[i]
if buf.modify then table.insert(mod_bufs, buf) end
end
if #mod_bufs > 0 then
local ans = ui.dialogs.msgbox{ title = "Unsaved buffers",
text = _L["There are unsaved changes in"] .. " (... buffers ...).", -- TD: Better text
icon = "gtk-dialog-warning",
}
-- TD: Process 'ans'
do return end -- TD
end
end
local bufs = {}
for i = lo, #_BUFFERS do
local buf = _BUFFERS[i]
table.insert(bufs, buf)
end
for _, buf in ipairs(bufs) do
buf:delete()
end
do
if dir == ">" then
if #bufs > 0 then
bufs[1], bufs[2] = bufs[2], bufs[1]
else
-- No place to move
end
elseif dir == ">>" then
table.insert(bufs, table.remove(bufs, 1))
elseif dir == "<" then
bufs[1], bufs[2] = bufs[2], bufs[1]
elseif dir == "<<" then
table.insert(bufs, 1, table.remove(bufs, idx - lo + 1))
end
end
for _, buf in ipairs(bufs) do
if buf.filename then io.open_file(buf.filename)
elseif buf._type then
-- TD
else
-- Should not happen
end
end
end
--
local _L = setmetatable({}, {__index = function(t, k) return k end}) -- Opt. - when we don't want to use [missing] locale
--
local tb_menu = textadept.menu.tab_context_menu
--
table.insert(tb_menu, { "" })
--
for _, v in ipairs{ { _L["Move tab one position left"],
function() TBM.moveTab(nil, "<") end,
},
{ _L["Move tab one position right"],
function() TBM.moveTab(nil, ">") end,
},
{ _L["Move tab to the lefttmost position"],
function() TBM.moveTab(nil, "<<") end,
},
{ _L["Move tab to the rightmost position"],
function() TBM.moveTab(nil, ">>") end,
},
} do
table.insert(tb_menu, v)
end
----------------------------------------------------------------------------------------------------
--return TBM