The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniOutliner 3 for Mac (http://forums.omnigroup.com/forumdisplay.php?f=9)
-   -   can children inherit text from parent? (http://forums.omnigroup.com/showthread.php?t=18582)

antowelik 2010-10-16 04:41 PM

can children inherit text from parent?
 
Say I have a parent topic named "Opportunities"

And it has the following children:

Jobs
Grants
Offers


Is there a way I can make these children automatically include the parent's name? something like this--

Opportunities: Jobs
Opportunities: Grants
Opportunities: Offers

without having to type in opportunities.


Thanks for your help

RobTrew 2010-10-16 09:22 PM

You can run this simple script while selecting the parent rows.

(It will, however, remove any text formatting from the children which receive the prefix ...)

[CODE]tell application id "com.omnigroup.OmniOutlinerPro3"
tell front document
set lstSeldParents to (selected rows where its children is not children of its children)
repeat with oRow in lstSeldParents
set strTopic to (topic of oRow)
repeat with oChild in children of oRow
set strChildTopic to topic of oChild
if strChildTopic does not start with strTopic then
set the topic of oChild to strTopic & ": " & strChildTopic
end if
end repeat
end repeat
end tell
end tell[/CODE]

whpalmer4 2010-10-17 10:53 AM

[QUOTE=RobTrew;87585]You can run this simple script while selecting the parent rows.

(It will, however, remove any text formatting from the children which receive the prefix ...)
[/QUOTE]

It's a pretty rare opportunity to improve on a script by RobTrew, so I'm going to grab it :-)

If you want your children to retain their formatting, and have the prefix from the parent rows retain its formatting as well, this mashup of Rob's script and the Merge Selected Rows script should do the trick. It won't win any programming style competitions, though!

[code]
tell application id "com.omnigroup.OmniOutlinerPro3"
tell front document
set lstSeldParents to (selected rows where its children is not children of its children)
if ((count of lstSeldParents) < 1) then
display dialog "You need to select at least one parent row to use this script." buttons "Cancel" default button "Cancel"
end if
repeat with oRow in lstSeldParents
set strTopic to (topic of oRow)
if ((count of characters of (topic of oRow)) > 0) then
duplicate last character of (topic of oRow) to after last character of (topic of oRow)
set text of last character of (topic of oRow) to ":"
duplicate last character of (topic of oRow) to after last character of (topic of oRow)
set text of last character of (topic of oRow) to " "
end if

repeat with oChild in children of oRow
set strChildTopic to topic of oChild
if strChildTopic does not start with strTopic then
duplicate topic of oRow to before first character of topic of oChild
end if
end repeat
delete last character of (topic of oRow)
delete last character of (topic of oRow)
end repeat
end tell
end tell[/code]

RobTrew 2010-10-17 01:34 PM

Thank you ! (I tried and failed to find the right target for the duplication - a relief to see that it is possible).

I shall add it to my list of enlightening scripts :-)

RobTrew 2010-10-17 10:44 PM

As a PS, if formatting is an issue, and the parent format differs from the child format, you can choose between copying the formatting of the parent row to the prefix for the child, or preserving the formatting of the child.

Whpalmer4 's script already works very well for the former option. (A bold row with italic children will confer a bold prefix on each child, preserving the italic formatting of their main text).

If, however, you wanted the children to simply inherit the prefix text from the parent row, preserving their own formatting for prefix as well as main text, you could try the following variant on whpalmer's script:

[CODE]-- Variant in which both prefix and main text of each child row preserve child row formatting
-- (For cases where parent and child row formatting differ)

tell application id "com.omnigroup.OmniOutlinerPro3"
tell front document
set refSeldParents to (a reference to (selected rows where its children is not children of its children))
if ((count of refSeldParents) < 1) then
display dialog "You need to select at least one parent row to use this script." buttons "Cancel" default button "Cancel"
end if

repeat with oRow in refSeldParents
set strTopic to (topic of oRow as string) & ": "
set lngChars to length of strTopic

-- Duplicate the parent text as a prefix for first child
-- (character by character retaining child formatting)
set refChiln to children of oRow
set oChild to first item of refChiln
set refChildTopic to (a reference to topic of oChild)
if refChildTopic does not start with strTopic then
set refFirst to (a reference to first character of refChildTopic)
repeat with iChar from lngChars to 1 by -1
duplicate refFirst to before refFirst
set text of refFirst to character iChar of strTopic
end repeat
end if

-- Now duplicate the prefix of the first child to the start of any siblings
-- (a bit faster)
set lngChildren to count of refChiln
if lngChildren > 1 then
set refTemplate to (a reference to characters 1 thru lngChars of refChildTopic)
repeat with iSibling from 2 to lngChildren
set refSibTopic to (a reference to topic of item iSibling of refChiln)
if refSibTopic does not start with strTopic then ¬
duplicate refTemplate to before first character of refSibTopic
end repeat
end if
end repeat
end tell
end tell
[/CODE]

antowelik 2010-10-18 10:46 AM

i haven't had a chance to try these yet, but damn guys. impressive! thank you very much for the help.


All times are GMT -8. The time now is 06:29 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.