Skip to content

Commit

Permalink
Use the same order for standard filters as MSVS itself
Browse files Browse the repository at this point in the history
Recognize the standard "Source", "Header" and "Resource Files" filters
and put them in the same order as that used by MSVS in the project files
it creates.

This avoids gratuitous differences between Premake-generated and the
existing manually created MSVS projects.
  • Loading branch information
vadz committed Sep 2, 2023
1 parent f2d8c4d commit 2593a59
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
6 changes: 3 additions & 3 deletions modules/vstudio/tests/vc2010/test_filter_ids.lua
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@
prepare()
test.capture [[
<ItemGroup>
<Filter Include="Header Files">
<UniqueIdentifier>{21EB8090-0D4E-1035-B6D3-48EBA215DCB7}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files">
<UniqueIdentifier>{E9C7FDCE-D52A-8D73-7EB0-C5296AF258F6}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{21EB8090-0D4E-1035-B6D3-48EBA215DCB7}</UniqueIdentifier>
</Filter>
</ItemGroup>
]]
end
27 changes: 26 additions & 1 deletion modules/vstudio/vs2010_vcxproj_filters.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,32 @@
--

function m.uniqueIdentifiers(prj)
local tr = project.getsourcetree(prj)
-- This map contains the sort key for the known filters.
local knownFilters = {
['Source Files'] = 1,
['Header Files'] = 2,
['Resource Files'] = 3,
}

local sortInFilterOrder = function (a,b)
if #a.children > 0 or #b.children > 0 then
local orderA = knownFilters[a.name] or 999
local orderB = knownFilters[b.name] or 999
if orderA < orderB then
return true
end
if orderA > orderB then
return false
end
-- This can only happen if both filters are
-- unknown, fall back on default comparison.
end

-- Use default order
return a.name < b.name
end

local tr = project.getsourcetree(prj, sortInFilterOrder)
local contents = p.capture(function()
p.push()
tree.traverse(tr, {
Expand Down

0 comments on commit 2593a59

Please sign in to comment.