Script grammar for "all rows which have named style x"
Michael Johnston
lastobelus at mac.com
Sat Feb 5 17:31:14 PST 2005
Here is a working handler. It allows you to specify how far up to=20
search. If you pass -1 for checkLevels, it will search exhaustively,=20
including checking level styles and named styles of the document. If=20
you pass 0, it will check only the named styles of the row. If you pass=20=
1, it will check named styles of the row + level styles of it's parent.=20=
The order of the checks is arranged to be most efficient for my=20
particular situation, others may want to rearrange them.
on rowHasStyle(theRow, styleName, checkLevels)
tell application "OmniOutliner Professional"
if checkLevels is -1 then
set checkLevels to level of theRow
end if
set hasStyle to false
set styleList to (id of named styles of document of =
theRow whose name=20
is styleName)
set styleId to item 1 of styleList
if (checkLevels =B3 (level of theRow)) then
if styleId is in (id of named styles of style of =
document of theRow)=20
then
set hasStyle to true
end if
end if
if hasStyle is false then
if styleId is in (id of named styles of style of =
theRow) then
set hasStyle to true
else if checkLevels is greater than 0 then
if checkLevels is greater than ((level =
of theRow) - 1) then
set checkLimit to ((level of =
theRow) - 1)
else
set checkLimit to checkLevels
end if
if (checkLevels is greater than =
checkLimit) then
set aLevel to level of theRow
if (styleId is in (id of named =
styles of level style aLevel of=20
document of theRow)) then
set hasStyle to true
end if
end if
if (hasStyle is false) then
repeat with aLevel from 1 to =
checkLimit
set myAncestor to (a =
reference to ancestor aLevel of theRow)
if (styleId is in (id of =
named styles of level style aLevel of=20
myAncestor)) then
set hasStyle to =
true
exit repeat
end if
end repeat
end if
end if
end if
hasStyle
end tell
end rowHasStyle
Michael Johnston
Planetactive
>
> So, to get back to your question -- how do you tell if a row is=20
> impacted by a named style? The following steps need to be done (I=20
> 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=20
> your scripts (and slow, too). In fact, our ObjC model can do this=20
> computation in one method call:
>
> -tim
>
> =09
>
>
More information about the OmniOutliner-Users
mailing list