Script grammar for "all rows which have named style x"
Timothy J.Wood
tjw at omnigroup.com
Fri Jan 7 10:51:45 PST 2005
Finding all the rows that are impacted by a named style is not
currently easy. We have a bug open on this (more general than the
named style case).
On Jan 7, 2005, at 9:47 AM, Michael Terry wrote:
[...]
> tell app "OmniOutliner Professional" to tell front document
> get container of every named style of style of every row where its
> name is "Some Style Name"
> end
This won't work since 'container' on the 'named style' will always be
a document. Per-section (or per-row) named styles is interesting, but
it would probably be confusing for a lot of people.
> I've only been able to have a row inherit styles defined in a named
> style that belongs to the document and I don't see an easy way to
> figure out if an inherited style has been applied to a row in
> AppleScript. Is there a way? Is this what you're talking about?
How the OO3 style system works in a nutshell:
- Level styles
- Each row has a list of level styles that form the basis for its
children's styles.
- The document as a whole has a list of level style. Consider the
document an invisible root row (in fact, that's part of the
implementation!)
- Named styles
- Owned by the document
- Each style has an ordered list of inherited styles (which are always
named styles; can't inherit from some other row's style)
- Cells
- Each row has a style
- Each column has a style
- Each cell has a style formed by considering first its row (most
specific since rows are more numerous) and then column.
- Styles attribute lookup
- locally in the style itself
- in the ordered list of inherited styles for this style
- recursively in the ordered list of styles implied by the structure
(row and column as mentioned above).
- cells have special logic to ensure that all level styles are
considered prior to the column style
This seems complicated to some people at first glance and natural to
others. Hopefully our upcoming SDK documentation will spell this out
more clearly than I have here (it'll likely have pictures at least :)
So, to get back to your question -- how do you tell if a row is
impacted by a named style? The following steps need to be done (I
haven't tested this code!)
if (named styles of style of MyRow contains MyNamedStyle)
-- yes
else
repeat with MyLevel from 1 to level of MyRow
set MyLevelStyle to level style MyLevel of ancestor MyLevel of MyRow
if (named styles of style of MyLevelStyle contains MyNamedStyle)
-- yes
end
end
end
-- Check the "Whole Document" style too
if (named styles of style of MyDocument contains MyNamedStyle)
-- yes
end
-- no
Now, this is really much more complicated than you really want in
your scripts (and slow, too). In fact, our ObjC model can do this
computation in one method call:
return [myStyle isInfluencedByStyle:someOtherStyle];
So, the bug in our tracking system is that we need to expose this
feature in a way that lets people write scripts like:
if MyStyle is infuenced by MyOtherStyle
...
end
or
every row of MyDocument whose style is influenced by SomeStyle
There are a couple issues here:
- The terminology is vague. "influenced" in this case means
"potentially has a visual effect, but maybe not". For example, if the
named style has "font-fill=red" but the row itself has
"font-fill=blue", we'd still say 'influenced' is true in this case,
even though the row covers up all the stuff the named style defines.
- I haven't had time to research how to write a qualifier like this --
the line may or may not work (probably not, but I'm not sure since I
haven't had the time yet).
Anyway, I hope this helps clear the murk instead of increasing it.
We definitely have plans to add more complex AppleScript accessors that
manage the complexities of styles, but we didn't have time up front and
we wanted to see what people actually wanted for their scripts :)
-tim
More information about the OmniOutliner-Users
mailing list