📄 configtooldoc.cpp
字号:
bool ctConfigToolDoc::DoOpen(wxSimpleHtmlTag* tag, ctConfigItem* parent)
{
ctConfigItem* newItem = NULL;
if (tag->NameIs(wxT("setting")))
{
wxSimpleHtmlAttribute* attr = tag->FindAttribute(wxT("type"));
if (attr)
{
ctConfigType type = ctTypeUnknown;
wxString typeStr(attr->GetValue());
if (typeStr == wxT("group"))
type = ctTypeGroup;
else if (typeStr == wxT("option-group") || typeStr == wxT("check-group"))
type = ctTypeCheckGroup;
else if (typeStr == wxT("radio-group"))
type = ctTypeRadioGroup;
else if (typeStr == wxT("bool-check"))
type = ctTypeBoolCheck;
else if (typeStr == wxT("bool-radio"))
type = ctTypeBoolRadio;
else if (typeStr == wxT("string"))
type = ctTypeString;
else if (typeStr == wxT("integer"))
type = ctTypeInteger;
else
{
wxLogError(wxT("Unknown type %s"), (const wxChar*) typeStr);
}
if (type != ctTypeUnknown)
{
newItem = new ctConfigItem(parent, type, wxT(""));
newItem->InitProperties();
if (!parent)
SetTopItem(newItem);
}
}
}
wxSimpleHtmlTag* childTag = tag->GetChildren();
while (childTag)
{
if (childTag->GetType() == wxSimpleHtmlTag_Open)
{
if (childTag->GetName() == wxT("setting"))
{
DoOpen(childTag, newItem);
}
else if (childTag->GetName() == wxT("name"))
{
if (newItem)
{
wxString name(childTag->GetNext()->GetTagText());
newItem->SetName(name);
}
}
else if (childTag->GetName() == wxT("active"))
{
if (newItem)
newItem->SetActive(GetHtmlBoolValue(childTag->GetNext()->GetTagText()));
}
else if (childTag->GetName() == wxT("enabled"))
{
if (newItem)
newItem->Enable(GetHtmlBoolValue(childTag->GetNext()->GetTagText()));
}
else
{
if (newItem)
{
ctProperty* prop = newItem->GetProperties().FindProperty(childTag->GetName());
if (!prop)
{
// A custom property, else an obsolete
// property that we should ignore.
wxString isCustom;
if (childTag->GetAttributeValue(isCustom, wxT("custom")) &&
isCustom == wxT("true"))
{
prop = new ctProperty;
wxString name(childTag->GetName());
wxString type(wxT("string"));
wxString choices;
wxString editorType(wxT("string"));
wxString description;
childTag->GetAttributeValue(type, wxT("type"));
childTag->GetAttributeValue(type, wxT("editor-type"));
childTag->GetAttributeValue(type, wxT("choices"));
childTag->GetAttributeValue(description, wxT("description"));
if (type == wxT("bool"))
prop->GetVariant() = wxVariant(false, name);
else if (type == wxT("double"))
prop->GetVariant() = wxVariant((double) 0.0, name);
else if (type == wxT("long"))
prop->GetVariant() = wxVariant((long) 0, name);
else
prop->GetVariant() = wxVariant(wxEmptyString, name);
prop->SetDescription(description);
prop->SetCustom(true);
prop->SetEditorType(editorType);
if (!choices.IsEmpty())
{
wxArrayString arr;
ctConfigItem::StringToArray(choices, arr);
prop->SetChoices(arr);
}
newItem->GetProperties().AddProperty(prop);
}
}
if (prop)
{
if (prop->GetVariant().GetType() == wxT("string"))
prop->GetVariant() = childTag->GetNext()->GetTagText();
else if (prop->GetVariant().GetType() == wxT("long"))
prop->GetVariant() = (long) GetHtmlIntegerValue(childTag->GetNext()->GetTagText());
else if (prop->GetVariant().GetType() == wxT("bool"))
prop->GetVariant() = GetHtmlBoolValue(childTag->GetNext()->GetTagText());
else if (prop->GetVariant().GetType() == wxT("double"))
prop->GetVariant() = (double) GetHtmlDoubleValue(childTag->GetNext()->GetTagText());
}
}
}
}
childTag = childTag->GetNext();
}
return true;
}
/// Clear dependencies
void ctConfigToolDoc::ClearDependencies(ctConfigItem* item)
{
if (!item) {
item = GetTopItem();
if (!item)
return;
}
item->GetDependents().Clear();
for ( wxObjectList::compatibility_iterator node = item->GetChildren().GetFirst(); node; node = node->GetNext() )
{
ctConfigItem* child = (ctConfigItem*) node->GetData();
ClearDependencies(child);
}
}
/// Refresh dependencies
void ctConfigToolDoc::RefreshDependencies()
{
ClearDependencies(GetTopItem());
RefreshDependencies(GetTopItem());
}
/// Refresh dependencies
void ctConfigToolDoc::RefreshDependencies(ctConfigItem* item)
{
if (item==NULL)
return;
wxArrayString requiresArr;
wxString requires = item->GetPropertyString(wxT("requires"));
wxString precludes = item->GetPropertyString(wxT("precludes"));
wxString enabledIf = item->GetPropertyString(wxT("enabled-if"));
wxString enabledIfNot = item->GetPropertyString(wxT("enabled-if-not"));
wxString indeterminateIf = item->GetPropertyString(wxT("indeterminate-if"));
wxString context = item->GetPropertyString(wxT("context"));
if (!requires.IsEmpty())
item->StringToArray(requires, requiresArr);
if (!precludes.IsEmpty())
item->StringToArray(precludes, requiresArr);
if (!enabledIfNot.IsEmpty())
item->StringToArray(enabledIfNot, requiresArr);
if (!enabledIf.IsEmpty())
item->StringToArray(enabledIf, requiresArr);
if (!indeterminateIf.IsEmpty())
item->StringToArray(indeterminateIf, requiresArr);
// Add the parent to the list of dependencies, if the
// parent is a check or radio group.
ctConfigItem* parent = item->GetParent();
if (parent &&
(parent->GetType() == ctTypeCheckGroup ||
parent->GetType() == ctTypeRadioGroup))
requiresArr.Add(parent->GetName());
// Also look in 'context' since these items
// are another kind of dependency (switching to
// a different platform may cause the dependencies
// to be evaluated differently).
if (!context.IsEmpty())
item->StringToArray(context, requiresArr);
size_t i;
for (i = 0; i < requiresArr.GetCount(); i++)
{
wxString itemName(requiresArr[i]);
ctConfigItem* otherItem = GetTopItem()->FindItem(itemName);
if (otherItem && !otherItem->GetDependents().Member(item))
{
otherItem->GetDependents().Append(item);
}
}
for ( wxObjectList::compatibility_iterator node = item->GetChildren().GetFirst(); node; node = node->GetNext() )
{
ctConfigItem* child = (ctConfigItem*) node->GetData();
RefreshDependencies(child);
}
}
/// Generate the text of a setup.h
wxString ctConfigToolDoc::GenerateSetup()
{
wxString str;
str << wxT("/*\n * setup.h\n * Generated by wxConfigTool\n *\n */\n\n");
GenerateSetup(GetTopItem(), str);
return str;
}
/// Helper function
void ctConfigToolDoc::GenerateSetup(ctConfigItem* item, wxString& str)
{
// Generate the setup.h entries for this item
wxString name = item->GetName();
// We don't process the platform choice
if (item->GetName() == wxT("Target"))
return;
if (item->IsInActiveContext() &&
(item->GetType() == ctTypeCheckGroup ||
item->GetType() == ctTypeRadioGroup ||
item->GetType() == ctTypeBoolCheck ||
item->GetType() == ctTypeBoolRadio))
{
// TODO: write description
wxString name = item->GetName();
if (name.Left(6) == wxT("wxUSE_") ||
name == wxT("REMOVE_UNUSED_ARG") || // Hack alert: change to wxUSE_UNUSED_ARG_REMOVAL
name.Find(wxT("COMPATIBILITY")) != wxNOT_FOUND)
{
str << wxT("#define ") << name ;
if (item->IsEnabled())
str << wxT(" 1");
else
str << wxT(" 0");
str << wxT("\n\n");
}
}
for ( wxObjectList::compatibility_iterator node = item->GetChildren().GetFirst(); node; node = node->GetNext() )
{
ctConfigItem* child = (ctConfigItem*) node->GetData();
GenerateSetup(child, str);
}
}
/// Generate a configure command
wxString ctConfigToolDoc::GenerateConfigureCommand()
{
wxString str;
str << wxT("# configurewx\n# Generated by wxConfigTool\n\n");
wxString path = GetFrameworkDir(true);
bool makeUnix = true;
if (!path.IsEmpty())
{
if (makeUnix)
path += wxT("/");
else
path += wxFILE_SEP_PATH ;
}
str << path << wxT("configure");
// Find the target to use
ctConfigItem* platformsFolder = GetTopItem()->FindItem(wxT("Target"));
if (platformsFolder)
{
for ( wxObjectList::compatibility_iterator node = platformsFolder->GetChildren().GetFirst(); node; node = node->GetNext() )
{
ctConfigItem* child = (ctConfigItem*) node->GetData();
if (child->GetType() == ctTypeBoolRadio && child->IsEnabled())
{
wxString configureCommand = child->GetPropertyString(wxT("configure-command"));
if (!configureCommand.IsEmpty())
str << wxT(" ") << configureCommand;
}
}
}
GenerateConfigureCommand(GetTopItem(), str);
return str;
}
/// Helper function
void ctConfigToolDoc::GenerateConfigureCommand(ctConfigItem* item, wxString& str)
{
// We don't process the platform group, since we've
// already done so.
if (item->GetName() == wxT("Target"))
return;
if (item->IsInActiveContext() &&
(item->GetType() == ctTypeCheckGroup ||
item->GetType() == ctTypeRadioGroup ||
item->GetType() == ctTypeBoolCheck ||
item->GetType() == ctTypeBoolRadio))
{
wxString name = item->GetName();
wxString configureCommand = item->GetPropertyString(wxT("configure-command"));
if (!configureCommand.IsEmpty())
{
if (!item->IsEnabled())
{
// Replace 'enable' with 'disable' if this
// option is off.
configureCommand.Replace(wxT("--enable-"), wxT("--disable-"));
configureCommand.Replace(wxT("--with-"), wxT("--without-"));
}
ctProperty* prop = item->GetProperties().FindProperty(wxT("builtin"));
if (prop && prop->GetVariant().GetType() == wxT("bool"))
{
bool builtin = prop->GetVariant().GetBool();
str << wxT(" ") << configureCommand;
if (builtin)
str << wxT("=builtin");
else
str << wxT("=sys");
}
else
{
ctProperty* prop = item->GetProperties().FindProperty(wxT("value"));
if (prop && prop->GetVariant().GetType() == wxT("string"))
{
wxString val = prop->GetVariant().GetString();
if (item->IsEnabled() && !val.IsEmpty())
{
str << wxT(" ") << configureCommand;
str << wxT("=\"") << val << wxT("\"");
}
// If the string is empty, ignore this parameter,
// since it's obviously intended to be supplied
// only if there's a string to use and it's enabled.
}
else
{
str << wxT(" ") << configureCommand;
}
}
}
}
for ( wxObjectList::compatibility_iterator node = item->GetChildren().GetFirst(); node; node = node->GetNext() )
{
ctConfigItem* child = (ctConfigItem*) node->GetData();
GenerateConfigureCommand(child, str);
}
}
/// Gets the current framework directory
wxString ctConfigToolDoc::GetFrameworkDir(bool makeUnix)
{
wxString path = wxGetApp().GetSettings().m_frameworkDir;
if (wxGetApp().GetSettings().m_useEnvironmentVariable)
{
// Should probably allow other variables
// to be used, and maybe expand variables within m_frameworkDir
wxString pathEnv(wxGetenv(wxT("WXWIN")));
path = pathEnv;
#ifdef __WXMSW__
if (makeUnix)
path.Replace(wxT("\\"), wxT("/"));
#else
wxUnusedVar(makeUnix);
#endif
}
return path;
}
/// Finds the next item in the tree
ctConfigItem* ctConfigToolDoc::FindNextItem(ctConfigItem* item, bool wrap)
{
if (!item)
return GetTopItem();
// First, try to find the first child
if (item->GetChildCount() > 0)
{
return item->GetChild(0);
}
else
{
ctConfigItem* p = item;
while (p)
{
ctConfigItem* toFind = FindNextSibling(p);
if (toFind)
return toFind;
p = p->GetParent();
}
}
// Finally, wrap around to the root.
if (wrap)
return GetTopItem();
else
return NULL;
}
/// Finds the next sibling in the tree
ctConfigItem* ctConfigToolDoc::FindNextSibling(ctConfigItem* item)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -