mirror of
https://github.com/aseprite/aseprite.git
synced 2024-10-03 21:46:20 +00:00
Support for @.string reference to avoid duplicating section ID
This commit is contained in:
parent
bd4e5cfa50
commit
9e3a6f8fe2
@ -44,7 +44,6 @@ using namespace app::skin;
|
||||
|
||||
static int convert_align_value_to_flags(const char *value);
|
||||
static int int_attr(const TiXmlElement* elem, const char* attribute_name, int default_value);
|
||||
static std::string text_attr(const TiXmlElement* elem, const char* attribute_name);
|
||||
|
||||
WidgetLoader::WidgetLoader()
|
||||
: m_tooltipManager(NULL)
|
||||
@ -90,6 +89,7 @@ Widget* WidgetLoader::loadWidgetFromXmlFile(
|
||||
ui::Widget* widget)
|
||||
{
|
||||
m_tooltipManager = NULL;
|
||||
m_stringIdPrefix = widgetId;
|
||||
|
||||
XmlDocumentRef doc(open_xml(xmlFilename));
|
||||
TiXmlHandle handle(doc.get());
|
||||
@ -382,7 +382,7 @@ Widget* WidgetLoader::convertXmlElementToWidget(const TiXmlElement* elem, Widget
|
||||
(middle ? MIDDLE: (bottom ? BOTTOM: TOP));
|
||||
|
||||
if (!widget) {
|
||||
widget = new Separator(text_attr(elem, "text"), align);
|
||||
widget = new Separator(textAttr(elem, "text"), align);
|
||||
}
|
||||
else
|
||||
widget->setAlign(widget->align() | align);
|
||||
@ -417,7 +417,7 @@ Widget* WidgetLoader::convertXmlElementToWidget(const TiXmlElement* elem, Widget
|
||||
if (desktop)
|
||||
widget = new Window(Window::DesktopWindow);
|
||||
else if (elem->Attribute("text"))
|
||||
widget = new Window(Window::WithTitleBar, text_attr(elem, "text"));
|
||||
widget = new Window(Window::WithTitleBar, textAttr(elem, "text"));
|
||||
else
|
||||
widget = new Window(Window::WithoutTitleBar);
|
||||
}
|
||||
@ -428,7 +428,7 @@ Widget* WidgetLoader::convertXmlElementToWidget(const TiXmlElement* elem, Widget
|
||||
}
|
||||
else if (elem_name == "dropdownbutton") {
|
||||
if (!widget) {
|
||||
widget = new DropDownButton(text_attr(elem, "text").c_str());
|
||||
widget = new DropDownButton(textAttr(elem, "text").c_str());
|
||||
}
|
||||
}
|
||||
else if (elem_name == "buttonset") {
|
||||
@ -462,7 +462,7 @@ Widget* WidgetLoader::convertXmlElementToWidget(const TiXmlElement* elem, Widget
|
||||
}
|
||||
|
||||
if (text)
|
||||
item->setText(text_attr(elem, "text"));
|
||||
item->setText(textAttr(elem, "text"));
|
||||
|
||||
buttonset->addItem(item, hspan, vspan);
|
||||
fillWidgetWithXmlElementAttributes(elem, root, item);
|
||||
@ -535,7 +535,7 @@ void WidgetLoader::fillWidgetWithXmlElementAttributes(const TiXmlElement* elem,
|
||||
widget->setId(id);
|
||||
|
||||
if (elem->Attribute("text"))
|
||||
widget->setText(text_attr(elem, "text"));
|
||||
widget->setText(textAttr(elem, "text"));
|
||||
|
||||
if (elem->Attribute("tooltip") && root) {
|
||||
if (!m_tooltipManager) {
|
||||
@ -551,7 +551,7 @@ void WidgetLoader::fillWidgetWithXmlElementAttributes(const TiXmlElement* elem,
|
||||
else if (strcmp(tooltip_dir, "right") == 0) dir = RIGHT;
|
||||
}
|
||||
|
||||
m_tooltipManager->addTooltipFor(widget, text_attr(elem, "tooltip"), dir);
|
||||
m_tooltipManager->addTooltipFor(widget, textAttr(elem, "tooltip"), dir);
|
||||
}
|
||||
|
||||
if (selected)
|
||||
@ -701,13 +701,17 @@ static int int_attr(const TiXmlElement* elem, const char* attribute_name, int de
|
||||
return (value ? strtol(value, NULL, 10): default_value);
|
||||
}
|
||||
|
||||
static std::string text_attr(const TiXmlElement* elem, const char* attribute_name)
|
||||
std::string WidgetLoader::textAttr(const TiXmlElement* elem, const char* attrName)
|
||||
{
|
||||
const char* value = elem->Attribute(attribute_name);
|
||||
const char* value = elem->Attribute(attrName);
|
||||
if (!value)
|
||||
return std::string();
|
||||
else if (*value == '@')
|
||||
return Strings::instance()->translate(value+1);
|
||||
else if (value[0] == '@') {
|
||||
if (value[1] == '.')
|
||||
return Strings::instance()->translate((m_stringIdPrefix + (value+1)).c_str());
|
||||
else
|
||||
return Strings::instance()->translate(value+1);
|
||||
}
|
||||
else
|
||||
return std::string(value);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2001-2015 David Capello
|
||||
// Copyright (C) 2001-2016 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
@ -64,11 +64,13 @@ namespace app {
|
||||
ui::Widget* convertXmlElementToWidget(const TiXmlElement* elem, ui::Widget* root, ui::Widget* parent, ui::Widget* widget);
|
||||
void fillWidgetWithXmlElementAttributes(const TiXmlElement* elem, ui::Widget* root, ui::Widget* widget);
|
||||
void fillWidgetWithXmlElementAttributesWithChildren(const TiXmlElement* elem, ui::Widget* root, ui::Widget* widget);
|
||||
std::string textAttr(const TiXmlElement* elem, const char* attrName);
|
||||
|
||||
typedef std::map<std::string, IWidgetTypeCreator*> TypeCreatorsMap;
|
||||
|
||||
TypeCreatorsMap m_typeCreators;
|
||||
ui::TooltipManager* m_tooltipManager;
|
||||
std::string m_stringIdPrefix;
|
||||
};
|
||||
|
||||
} // namespace app
|
||||
|
Loading…
Reference in New Issue
Block a user