Xcode: Refactor internal source file type selection
Choose the attribute name and file type and send them through a single attribute generation code path. Compute the file extension only when needed. Leave the file type selection logic indented in a block so it can be made conditional later.
This commit is contained in:
parent
032961c6ac
commit
ae80cb9f28
@ -848,35 +848,35 @@ cmGlobalXCodeGenerator::CreateXCodeFileReferenceFromPath(
|
|||||||
}
|
}
|
||||||
fileRef->AddAttribute("fileEncoding", this->CreateString("4"));
|
fileRef->AddAttribute("fileEncoding", this->CreateString("4"));
|
||||||
|
|
||||||
// Compute the extension.
|
bool useLastKnownFileType = false;
|
||||||
std::string ext;
|
std::string fileType;
|
||||||
std::string realExt =
|
|
||||||
cmSystemTools::GetFilenameLastExtension(fullpath);
|
|
||||||
if(!realExt.empty())
|
|
||||||
{
|
{
|
||||||
// Extension without the leading '.'.
|
// If fullpath references a directory, then we need to specify
|
||||||
ext = realExt.substr(1);
|
// lastKnownFileType as folder in order for Xcode to be able to
|
||||||
|
// open the contents of the folder.
|
||||||
|
// (Xcode 4.6 does not like explicitFileType=folder).
|
||||||
|
if(cmSystemTools::FileIsDirectory(fullpath.c_str()))
|
||||||
|
{
|
||||||
|
fileType = "folder";
|
||||||
|
useLastKnownFileType = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Compute the extension without leading '.'.
|
||||||
|
std::string ext = cmSystemTools::GetFilenameLastExtension(fullpath);
|
||||||
|
if(!ext.empty())
|
||||||
|
{
|
||||||
|
ext = ext.substr(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
fileType = GetSourcecodeValueFromFileExtension(
|
||||||
|
ext, lang, useLastKnownFileType);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If fullpath references a directory, then we need to specify
|
fileRef->AddAttribute(useLastKnownFileType? "lastKnownFileType"
|
||||||
// lastKnownFileType as folder in order for Xcode to be able to open the
|
: "explicitFileType",
|
||||||
// contents of the folder (Xcode 4.6 does not like explicitFileType=folder).
|
this->CreateString(fileType));
|
||||||
if(cmSystemTools::FileIsDirectory(fullpath.c_str()))
|
|
||||||
{
|
|
||||||
fileRef->AddAttribute("lastKnownFileType",
|
|
||||||
this->CreateString("folder"));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
bool keepLastKnownFileType = false;
|
|
||||||
std::string sourcecode = GetSourcecodeValueFromFileExtension(ext,
|
|
||||||
lang, keepLastKnownFileType);
|
|
||||||
const char* attribute = keepLastKnownFileType ?
|
|
||||||
"lastKnownFileType" :
|
|
||||||
"explicitFileType";
|
|
||||||
fileRef->AddAttribute(attribute,
|
|
||||||
this->CreateString(sourcecode.c_str()));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Store the file path relative to the top of the source tree.
|
// Store the file path relative to the top of the source tree.
|
||||||
std::string path = this->RelativeToSource(fullpath.c_str());
|
std::string path = this->RelativeToSource(fullpath.c_str());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user