Skip to content

Commit

Permalink
Added support for browsing documentation set class hierarchy within t…
Browse files Browse the repository at this point in the history
…he Xcode documentation window.
  • Loading branch information
tomaz committed Jun 5, 2009
1 parent fe4e023 commit e6cf82b
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 2 deletions.
15 changes: 15 additions & 0 deletions DoxygenConverter+DocSet.h
Expand Up @@ -50,6 +50,7 @@ This message is automatically sent from @c DoxygenConverter::convert() in the pr
@see createDocSetSourcePlistFile @see createDocSetSourcePlistFile
@see createDocSetTokesFile @see createDocSetTokesFile
@see createDocSetBundle @see createDocSetBundle
@see addDocSetNodeToElement:fromHierarchyData:
*/ */
- (void) createDocSetNodesFile; - (void) createDocSetNodesFile;


Expand Down Expand Up @@ -83,4 +84,18 @@ This message is automatically sent from @c DoxygenConverter::convert() in the pr
*/ */
- (void) createDocSetBundle; - (void) createDocSetBundle;


/** Adds a new DocSet node as the child of the given parent element.
The given hierarchy data contains the description of the node to add. The added node is
either of the type folder if it contains children or it is a leaf otherwise. The methods
will recursively add all subnodes as well.
@param parent The Nodes.xml element to which to add new node.
@param data The hierarchy object data that describes the node.
@exception NSException Thrown if adding fails.
@see createDocSetNodesFile
*/
- (void) addDocSetNodeToElement:(NSXMLElement*) parent
fromHierarchyData:(NSDictionary*) data;

@end @end
56 changes: 56 additions & 0 deletions DoxygenConverter+DocSet.m
Expand Up @@ -145,6 +145,25 @@ - (void) createDocSetNodesFile
} }
} }


// At the end of the directories create class hierarchy.
NSXMLElement* hierarchyNodeElement = [NSXMLNode elementWithName:@"Node"];
[hierarchyNodeElement addAttribute:[NSXMLNode attributeWithName:@"type" stringValue:@"folder"]];
[indexSubnodesElement addChild:hierarchyNodeElement];
NSXMLElement* hierarchyNameElement = [NSXMLNode elementWithName:@"Name" stringValue:@"Class hierarchy"];
[hierarchyNodeElement addChild:hierarchyNameElement];
NSXMLElement* hierarchyPathElement = [NSXMLNode elementWithName:@"Path" stringValue:@"hierarchy.html"];
[hierarchyNodeElement addChild:hierarchyPathElement];
NSXMLElement* hierarchySubnodesElement = [NSXMLNode elementWithName:@"Subnodes"];
[hierarchyNodeElement addChild:hierarchySubnodesElement];

// Scan for all classes in the hierarchy.
NSMutableDictionary* hierarchies = [database objectForKey:kTKDataMainHierarchiesKey];
for (NSString* objectName in hierarchies)
{
NSDictionary* hierarchyData = [hierarchies objectForKey:objectName];
[self addDocSetNodeToElement:hierarchySubnodesElement fromHierarchyData:hierarchyData];
}

// Save the document. // Save the document.
NSError* error = nil; NSError* error = nil;
NSString* filename = [cmd.outputDocSetResourcesPath stringByAppendingPathComponent:@"Nodes.xml"]; NSString* filename = [cmd.outputDocSetResourcesPath stringByAppendingPathComponent:@"Nodes.xml"];
Expand Down Expand Up @@ -354,4 +373,41 @@ - (void) createDocSetBundle
logInfo(@"Finished creating DocSet bundle."); logInfo(@"Finished creating DocSet bundle.");
} }


//----------------------------------------------------------------------------------------
- (void) addDocSetNodeToElement:(NSXMLElement*) parent
fromHierarchyData:(NSDictionary*) data
{
NSDictionary* children = [data objectForKey:kTKDataHierarchyChildrenKey];
NSDictionary* objectData = [data objectForKey:kTKDataHierarchyObjectDataKey];
NSString* objectName = [data objectForKey:kTKDataHierarchyObjectNameKey];
NSString* objectPath = [objectData objectForKey:kTKDataObjectRelPathKey];
if (!objectPath) objectPath = @"hierarchy.html";

// Create the main node that will represent the object.
NSXMLElement* node = [NSXMLNode elementWithName:@"Node"];
[parent addChild:node];

// Create the name and path subnodes. Note that the path will be the main hierarchy
// index file if the node is not documented.
NSXMLElement* nameElement = [NSXMLNode elementWithName:@"Name" stringValue:objectName];
[node addChild:nameElement];
NSXMLElement* pathElement = [NSXMLNode elementWithName:@"Path" stringValue:objectPath];
[node addChild:pathElement];

// If there are children, set the node type to folder and add subnodes.
if ([children count] > 0)
{
[node addAttribute:[NSXMLNode attributeWithName:@"type" stringValue:@"folder"]];

NSXMLElement* subnodesElement = [NSXMLNode elementWithName:@"Subnodes"];
[node addChild:subnodesElement];

for (NSString* childName in children)
{
NSDictionary* childHierarchyData = [children objectForKey:childName];
[self addDocSetNodeToElement:subnodesElement fromHierarchyData:childHierarchyData];
}
}
}

@end @end
10 changes: 8 additions & 2 deletions DoxygenConverter.h
Expand Up @@ -69,10 +69,16 @@ is a standard @c NSDictionary of the following layout:
- @c "Hierarchy" key: contains a @c NSXMLDocument with clean hierarchy XML. - @c "Hierarchy" key: contains a @c NSXMLDocument with clean hierarchy XML.
- @c "Hierarchies" key: contains a @c NSMutableDictionary with classes hierarchy tree. - @c "Hierarchies" key: contains a @c NSMutableDictionary with classes hierarchy tree.
- @c "<ObjectName>" key: contains a @c NSMutableDictionary describing the object: - @c "<ObjectName>" key: contains a @c NSMutableDictionary describing the object:
- @c "ObjectName" key: contains the object name. This is the same name as used
for the key in the parent dictionary. It still serves a purpose for the
non-documented objects which are part of the hierarchy - for there we can't
use the @c "ObjectData" key since we have no entry...
- @c "ObjectData" key: contains a pointer to the object's data under the main - @c "ObjectData" key: contains a pointer to the object's data under the main
@c "Objects" key list. @c "Objects" key list. Note that this is @c nil if the object is not
documented.
- @c "Children" key: contains a @c NSMutableDictionary with all children of - @c "Children" key: contains a @c NSMutableDictionary with all children of
this object. The dictionary has the same structure as the main @c "Hierarchy" this object. If the object doesn't have any children, empty dictionary is
used. The dictionary has the same structure as the main @c "Hierarchies"
dictionary: dictionary:
- @c "<ObjectName>"... - @c "<ObjectName>"...
- ... - ...
Expand Down

0 comments on commit e6cf82b

Please sign in to comment.