Jason Perkins avatar Jason Perkins committed 16b64c1

Adjust source file ordering to better match Visual Studio 2008

Comments (0)

Files changed (2)

src/actions/vstudio/vs200x_vcproj.lua

 ---------------------------------------------------------------------------
 
 	function vc200x.files(prj)
+
+		-- Fetch the source tree, sorted how Visual Studio likes it: alpha
+		-- sorted, with any leading ../ sequences ignored. At the top level
+		-- of the tree, files go after folders, otherwise before.
+
 		local tr = project.getsourcetree(prj, function(a,b)
+			local istop = (a.parent.parent == nil)
+
 			local aSortName = a.name
 			local bSortName = b.name
 
 			-- Only file nodes have a relpath field; folder nodes do not
-			if a.relpath then aSortName = a.relpath:gsub("%.%.%/", "") end
-			if b.relpath then bSortName = b.relpath:gsub("%.%.%/", "") end
+			if a.relpath then
+				if not b.relpath then
+					return not istop
+				end
+				aSortName = a.relpath:gsub("%.%.%/", "")
+			end
+
+			if b.relpath then
+				if not a.relpath then
+					return istop
+				end
+				bSortName = b.relpath:gsub("%.%.%/", "")
+			end
 
 			return aSortName < bSortName
 		end)
 			end
 
 		}, false, 2)
+
 	end
 
 

tests/actions/vstudio/vc200x/test_files.lua

 -- Check the structure of a file contained in a folder.
 --
 
-	function suite.file_inSingleLevelFolder()
+	function suite.file_onSingleLevelFolder()
 		files { "src/hello.cpp", "so_long.cpp" }
 		prepare()
 		test.capture [[
-		<File
-			RelativePath="so_long.cpp"
-			>
-		</File>
 		<Filter
 			Name="src"
 			>
 				>
 			</File>
 		</Filter>
+		<File
+			RelativePath="so_long.cpp"
+			>
+		</File>
 		]]
 	end
 
 		files { "src/greetings/hello.cpp", "so_long.cpp" }
 		prepare()
 		test.capture [[
-		<File
-			RelativePath="so_long.cpp"
-			>
-		</File>
 		<Filter
 			Name="src"
 			>
 				</File>
 			</Filter>
 		</Filter>
+		<File
+			RelativePath="so_long.cpp"
+			>
+		</File>
 		]]
 	end
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.