forked from pkulchenko/ZeroBranePackage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuniquetabname.lua
48 lines (44 loc) · 1.49 KB
/
uniquetabname.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
local sep = GetPathSeparator()
local function makeUnique(exeditor)
local docs = {}
for id, doc in pairs(ide:GetDocuments()) do
if doc:GetEditor() ~= exeditor and doc:GetFileName() and doc:GetFilePath() then
local fn = doc:GetFileName()
docs[fn] = docs[fn] or {}
table.insert(docs[fn], {doc = doc, parts = wx.wxFileName(doc:GetFilePath()):GetDirs()})
end
end
while true do
local updated = false
for fn, tabs in pairs(docs) do
if #tabs > 1 then -- conflicting name
updated = true
docs[fn] = nil
for _, tab in ipairs(tabs) do
local fn = (table.remove(tab.parts) or '?').. sep .. fn
docs[fn] = docs[fn] or {}
table.insert(docs[fn], tab)
end
end
end
if not updated then break end
end
-- update all labels as some might have lost their conflicts
for fn, tabs in pairs(docs) do
for _, tab in ipairs(tabs) do tab.doc:SetTabText(fn) end end
end
return {
name = "Unique tabname",
description = "Updates editor tab names to always stay unique.",
author = "Paul Kulchenko",
version = 0.1,
onEditorLoad = function(self) makeUnique() end,
onEditorSave = function(self) makeUnique() end,
onEditorClose = function(self, editor) makeUnique(editor) end,
onAppClose = function(self, app)
-- restore "original" names back before saving configuration
for _, doc in pairs(ide:GetDocuments()) do
if doc:GetFileName() then doc:SetTabText(doc:GetFileName()) end
end
end
}