The Omni Group
These forums are now read-only. Please visit our new forums to participate in discussion. A new account will be required to post in the new forums. For more info on the switch, see this post. Thank you!

Go Back   The Omni Group Forums > OmniOutliner > OmniOutliner 3 for Mac
FAQ Members List Calendar Today's Posts

 
Hierarchical List of Cells Matching a Condition Thread Tools Search this Thread Display Modes
I will go off and think about this some more. My first concern is that this doesn't really help, because now I have a flat list of ancestors that is unique, but I don't know the hierarchy of the ancestors, so I'll have to process them all again to figure out the hierarchy. Might as well to have just built up my own tree...?

Code:
class TreeObj: 
  """Hold a pointer to a row object and its children. Create a tree mirroring OmniOutliner structs"""

  def __init__(self, o, is_row=0):
    self.obj = o
    self.children = []
    self.hidden = 0
    self.is_row = is_row

  def init_tree(self):
    """Recursively initialize a tree of python objects initialized from OmniOutliner doc"""
    for c_apple in self.obj.children():
      c = TreeObj(c_apple, 1) 
      c.init_tree()
      self.children.append(c)

  def find_row(self, pattern):
    retval = 0
    if (self.is_row and not self.hidden):
      for cell in self.obj.cells():
        if (re.search(pattern, str(cell.value()))):
          #print "found pattern " + pattern
          return 1

    for child in self.children:
      if (1 == child.find_row(pattern)):
        retval = 1

    if (retval == 0):
      self.hidden = 1

    return retval

# ... etc
 
Quote:
Originally Posted by JLGray View Post
I don't know the hierarchy of the ancestors, so I'll have to process them all again to figure out the hierarchy. Might as well to have just built up my own tree...?
You do know the hierarchy. No need to process them again :-)

As before, the rows property of each ancestor is an ordered top-down left-right traversal, ready for printing. Each ancestor is a unique top level node. All you need to do is supply the indentations from the level of each row, using the function which I supplied in the first posting.

--

Last edited by RobTrew; 2011-04-08 at 11:01 AM..
 
Signing off now for the weekend, but here is a sketch:

Code:
SubTreeMatch("bob")

on SubTreeMatch(strSearch)
	tell application id "OOut"
		tell front document
			set lstRows to rows where topic contains strSearch
			set lstAncestors to my GetAncestors(lstRows)
		end tell
		
		-- Process unique list of ancestors
		set strTree to ""
		repeat with oAncestor in lstAncestors
			tell oAncestor
				set strTree to strTree & topic & return
				set {lstLevel, lstTopic} to {level, topic} of rows
				repeat with i from 1 to length of lstLevel
					set strTree to strTree & my LevelTabs(item i of lstLevel) & item i of lstTopic & return
				end repeat
			end tell
			set strTree to strTree & return
		end repeat
	end tell
	return strTree
end SubTreeMatch

on LevelTabs(n)
	if n < 2 then return ""
	set str to ""
	repeat with i from 2 to n
		set str to str & tab
	end repeat
	str
end LevelTabs

-- Purge any duplicate ancestors
on GetAncestors(lstRows)
	set lstUnion to {}
	tell application id "OOut"
		repeat with oRow in lstRows
			tell oRow
				if level > 1 then
					set strID to id of (last ancestor)
				else
					set strID to id of it
				end if
			end tell
			if not (lstUnion contains strID) then set end of lstUnion to strID
		end repeat
		if lstUnion ≠ {} then
			tell front document
				repeat with i from 1 to length of lstUnion
					set item i of lstUnion to row id (item i of lstUnion)
				end repeat
			end tell
			lstUnion
		else
			{}
		end if
	end tell
end GetAncestors
 
Thanks, Rob. All the info you're providing is sinking in... just not quite as fast as I'd like. Thanks for your patience!

JL
 
 




Similar Threads
Thread Thread Starter Forum Replies Last Post
Completion Cells leanda OmniFocus 2 for Mac (Private Test) 1 2013-04-08 09:17 PM
Selecting projects from a hierarchical list Stephen Brown OmniFocus for iPad 5 2012-09-03 08:50 PM
Merging Cells ktozawa OmniGraffle General 2 2011-04-29 12:52 PM
Merge cells in a row sauron93 OmniOutliner 3 for Mac 0 2009-03-05 03:22 PM
Bug or feature?: Non-matching items eronel OmniFocus 1 for Mac 8 2007-11-26 05:38 PM


All times are GMT -8. The time now is 01:40 AM.


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