Skip to content

Commit

Permalink
Made sorting case insensitive (#333)
Browse files Browse the repository at this point in the history
* Made sorting case insensitive

* Update file_browser.lua

* Update file_browser.lua
  • Loading branch information
thegrb93 authored Dec 3, 2020
1 parent 1ff38f8 commit 0c0d55f
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lua/advdupe2/file_browser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ local function NarrowHistory(txt, last)
Narrow = temp
end

local function tableSortNodes(tbl)
for k, v in ipairs(tbl) do tbl[k] = {string.lower(v.Label:GetText()), v} end
table.sort(tbl, function(a,b) return a[1]<b[1] end)
for k, v in ipairs(tbl) do tbl[k] = v[2] end
end

local BROWSERPNL = {}
AccessorFunc(BROWSERPNL, "m_bBackground", "PaintBackground", FORCE_BOOL)
AccessorFunc(BROWSERPNL, "m_bgColor", "BackgroundColor")
Expand Down Expand Up @@ -381,7 +387,7 @@ local function Search(node, name)
pnFileBr.Search.pnlCanvas.Search = true
pnFileBr.Browser:SetVisible(false)
local Files = SearchNodes(node, name)
table.sort(Files, function(a, b) return a.Label:GetText() < b.Label:GetText() end)
tableSortNodes(Files)
for k, v in pairs(Files) do
pnFileBr.Search.pnlCanvas:AddFile(v.Label:GetText()).Ref = v
end
Expand Down Expand Up @@ -782,8 +788,8 @@ function BROWSER:AddFile(text)
end

function BROWSER:Sort(node)
table.sort(node.Folders, function(a, b) return a.Label:GetText() < b.Label:GetText() end)
table.sort(node.Files , function(a, b) return a.Label:GetText() < b.Label:GetText() end)
tableSortNodes(node.Folders)
tableSortNodes(node.Files)

for i = 1, #node.Folders do
node.Folders[i]:SetParent(nil)
Expand Down

0 comments on commit 0c0d55f

Please sign in to comment.