Commit 35ed0346 authored by twanvl's avatar twanvl

Added empty_name to PackageChoiceField;

Package choice fields now reflect in scripts as "/:NO-WARN-DEP:packagename". This suppresses warnings when loading files in that package or using the package as a symbol font.
parent afd042a6
......@@ -86,6 +86,7 @@ Additional properties are available, depending on the type of field:
| ^^^ @match@ [[type:string]] ''required'' Filenames of the pakcages to match, can include wildcards @"*"@. For example @"magic-mana-*.mse-symbol-font"@.
| ^^^ @initial@ [[type:string]] ''required'' Initial package for new values for this field.
| ^^^ @reqired@ [[type:boolean]] @true@ Must a package always be selected? Or is it allowed to select nothing?
| ^^^ @empty name@ [[type:string]] @"None"@ Name of the empty state. Applies only if @required: false@.
| @"color"@ @script@ [[type:script]] Script to apply to values of this field after each change.<br/>
If the script evaluates to a constant (i.e. doesn't use @value@) then values in this field can effectively not be edited.
......
......@@ -25,6 +25,7 @@ IMPLEMENT_REFLECTION(PackageChoiceField) {
REFLECT(match);
REFLECT(initial);
REFLECT(required);
REFLECT(empty_name);
}
// ----------------------------------------------------------------------------- : PackageChoiceStyle
......@@ -73,12 +74,14 @@ void PackageChoiceValue::reflect(Writer& tag) {
REFLECT_NAMELESS(package_name);
}
void PackageChoiceValue::reflect(GetDefaultMember& tag) {
if (!package_name.empty() && package_name != field().initial) {
if (package_name.empty()) {
REFLECT_NAMELESS(package_name);
} else if(package_name != field().initial) {
// add a space to the name, to indicate the dependency doesn't have to be marked
// see also SymbolFontRef::loadFont
REFLECT_NAMELESS(_(" ") + package_name);
// see also PackageManager::openFileFromPackage and SymbolFontRef::loadFont
REFLECT_NAMELESS(_("/:NO-WARN-DEP:") + package_name);
} else {
REFLECT_NAMELESS(package_name);
REFLECT_NAMELESS(_("/") + package_name);
}
}
void PackageChoiceValue::reflect(GetMember& tag) {}
......@@ -25,13 +25,14 @@ DECLARE_POINTER_TYPE(PackageChoiceValue);
/// A field for PackageChoice values, it contains a list of choices for PackageChoices
class PackageChoiceField : public Field {
public:
PackageChoiceField() : required(true) {}
PackageChoiceField() : required(true), empty_name(_("none")) {}
DECLARE_FIELD_TYPE(PackageChoice);
OptionalScript script; ///< Script to apply to all values
String match; ///< Package filenames to match
String initial; ///< Initial value
bool required; ///< Is selecting a package required?
String empty_name; ///< Displayed name for the empty value (if !required)
virtual void initDependencies(Context&, const Dependency&) const;
};
......
......@@ -577,7 +577,7 @@ void SymbolFontRef::loadFont(Context& ctx) {
font = SymbolFontP();
} else {
font = SymbolFont::byName(name);
if (name().GetChar(0) != _(' ')) {
if (starts_with(name(),_("/:NO-WARN-DEP:"))) {
// ensure the dependency on the font is present in the stylesheet this ref is in
// Getting this stylesheet from the context is a bit of a hack
// If the name starts with a ' ', no dependency is needed;
......
......@@ -46,7 +46,7 @@ size_t DropDownPackageChoiceList::itemCount() const {
return editor.items.size() + (editor.field().required ? 0 : 1);
}
String DropDownPackageChoiceList::itemText(size_t item) const {
if (item == 0 && !editor.field().required) return _("");
if (item == 0 && !editor.field().required) return editor.field().empty_name;
else {
size_t i = item - !editor.field().required;
return editor.items[i].name;
......
......@@ -47,15 +47,24 @@ void PackageChoiceValueViewer::initItems() {
void PackageChoiceValueViewer::draw(RotatedDC& dc) {
drawFieldBorder(dc);
// find item
String text = value().package_name;
Bitmap image;
if (value().package_name.empty()) {
text = field().empty_name;
} else {
FOR_EACH(i, items) {
if (i.package_name != value().package_name) continue;
if (i.package_name == value().package_name) {
text = i.name;
image = i.image;
}
}
}
// draw image
if (i.image.Ok()) {
dc.DrawBitmap(i.image, RealPoint(0,0));
if (image.Ok()) {
dc.DrawBitmap(image, RealPoint(0,0));
}
// draw text
dc.SetFont(style().font, 1.0);
RealPoint pos = align_in_rect(ALIGN_MIDDLE_LEFT, RealSize(0, dc.GetCharHeight()), dc.getInternalRect()) + RealSize(17., 0);
dc.DrawTextWithShadow(i.name, style().font, pos);
}
dc.DrawTextWithShadow(text, style().font, pos);
}
......@@ -41,6 +41,8 @@ void PackageManager::reset() {
PackagedP PackageManager::openAny(const String& name_, bool just_header) {
String name = trim(name_);
if (starts_with(name,_("/"))) name = name.substr(1);
if (starts_with(name,_(":NO-WARN-DEP:"))) name = name.substr(13);
// Attempt to load local data first.
String filename;
if (wxFileName(name).IsRelative()) {
......@@ -96,11 +98,12 @@ void PackageManager::findMatching(const String& pattern, vector<PackagedP>& out)
InputStreamP PackageManager::openFileFromPackage(Packaged*& package, const String& name) {
if (!name.empty() && name.GetChar(0) == _('/')) {
// absolute name; break name
size_t pos = name.find_first_of(_("/\\"), 1);
if (pos != String::npos) {
size_t start = name.find_first_not_of(_("/\\"), 1); // allow "//package/name" from incorrect scripts
size_t pos = name.find_first_of(_("/\\"), start);
if (start < pos && pos != String::npos) {
// open package
PackagedP p = openAny(name.substr(1, pos-1));
if (package) {
PackagedP p = openAny(name.substr(start, pos-start));
if (package && !is_substr(name,start,_(":NO-WARN-DEP:"))) {
package->requireDependency(p.get());
}
package = p.get();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment