Custom styles in palettes

• Sep 30, 2014 - 03:43
Reported version
S5 - Suggestion

With MuseScore f3f334f, say I want a palette item allowing to add a text formatted with a custom text style. Here's what I do:

  • I go to Style | Text... and create a new text style with custom properties.
  • In my score, I add staff text.
  • I select this text and change its style in the Inspector dialog, so my custom text style applies to it.
  • I add this text in a palette with Ctrl+Shift+Drag.
  • Now I can use my new item. I drag and drop it in the score.

Result: the text is added, but it's not formatted with my custom style. In the Inspector dialog, the style appearing in the list box is the first listed (that is Title). So I must manually choose my custom style in the list box, making the new palette item useless.

If we look at the score file (.mscx). we find that the tag <style></style> of the text added with the palette item is empty. Example:

<Measure number="18">
        <text>Staff Text</text>
        <duration z="4" n="4"/>

It's probably why the Inspector dialog falls back on the first style in the list box.

The reason why this tag is empty is likely because the palette item itself didn't register the name of the custom style (empty tag <style></style>) in the file workspace.xml. Example:

<Palette name="new Palette">
            <text>Staff Text</text>

So, right now, we obviously can't use custom styles in palettes.

I may be wrong (I didn't look at the code, so maybe there are good reasons to force exclusive use of predefined styles), but it seems trivial to add the custom style name in the tag <style></style> of the palette, so the drag and drop of the palette item would prevent the text to have an empty tag <style></style>.

By doing so, using custom styles in palettes would at least be functional sometimes (when the custom style is usable in the score itself or in a default style file automatically loaded), compared to right now, where it's never possible.


The downside would be, the semantics would be undefined if a style by that name does *not* exist. Which would be the case most of the time unless you only ever loaded scores that defined that custom style. Still, it could preumably be implemented so that the custom style is used if available, the default style for the element type otherwise.

Or, we could store the explicit properties in the palette and use those (see #42941: Text properties applied to elements not preserved on copy/paste, palette add).