diff --git a/doc/type/field.txt b/doc/type/field.txt
index 7096b16c..0354edd9 100644
--- a/doc/type/field.txt
+++ b/doc/type/field.txt
@@ -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.
If the script evaluates to a constant (i.e. doesn't use @value@) then values in this field can effectively not be edited.
diff --git a/src/data/field/package_choice.cpp b/src/data/field/package_choice.cpp
index 318997cc..350d19b9 100644
--- a/src/data/field/package_choice.cpp
+++ b/src/data/field/package_choice.cpp
@@ -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) {
- // add a space to the name, to indicate the dependency doesn't have to be marked
- // see also SymbolFontRef::loadFont
- REFLECT_NAMELESS(_(" ") + package_name);
- } else {
+ 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 PackageManager::openFileFromPackage and SymbolFontRef::loadFont
+ REFLECT_NAMELESS(_("/:NO-WARN-DEP:") + package_name);
+ } else {
+ REFLECT_NAMELESS(_("/") + package_name);
}
}
void PackageChoiceValue::reflect(GetMember& tag) {}
diff --git a/src/data/field/package_choice.hpp b/src/data/field/package_choice.hpp
index 9457e273..9466a19e 100644
--- a/src/data/field/package_choice.hpp
+++ b/src/data/field/package_choice.hpp
@@ -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;
};
diff --git a/src/data/symbol_font.cpp b/src/data/symbol_font.cpp
index 3e7f1f70..5754cf65 100644
--- a/src/data/symbol_font.cpp
+++ b/src/data/symbol_font.cpp
@@ -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;
diff --git a/src/gui/value/package_choice.cpp b/src/gui/value/package_choice.cpp
index 0f59f38a..4c30a69c 100644
--- a/src/gui/value/package_choice.cpp
+++ b/src/gui/value/package_choice.cpp
@@ -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;
diff --git a/src/render/value/package_choice.cpp b/src/render/value/package_choice.cpp
index 289d1224..11be8421 100644
--- a/src/render/value/package_choice.cpp
+++ b/src/render/value/package_choice.cpp
@@ -47,15 +47,24 @@ void PackageChoiceValueViewer::initItems() {
void PackageChoiceValueViewer::draw(RotatedDC& dc) {
drawFieldBorder(dc);
// find item
- FOR_EACH(i, items) {
- if (i.package_name != value().package_name) continue;
- // draw image
- if (i.image.Ok()) {
- dc.DrawBitmap(i.image, RealPoint(0,0));
+ 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) {
+ text = i.name;
+ image = i.image;
+ }
}
- // 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);
}
+ // draw image
+ 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(text, style().font, pos);
}
diff --git a/src/util/io/package_manager.cpp b/src/util/io/package_manager.cpp
index f43cb180..fab3d8c7 100644
--- a/src/util/io/package_manager.cpp
+++ b/src/util/io/package_manager.cpp
@@ -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& 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();