Diff for /chimera/BookmarksService.mm between versions 1.6 and 1.11

version 1.6, 2002/02/09 20:31:06 version 1.11, 2002/02/11 10:23:03
Line 69 Line 69
     nsCOMPtr<nsIContent> content;      nsCOMPtr<nsIContent> content;
     int index = [mOutlineView selectedRow];      int index = [mOutlineView selectedRow];
         
    if (index > 0) {    if (index >= 0) {
         BookmarkItem* item = [mOutlineView itemAtRow: index];          BookmarkItem* item = [mOutlineView itemAtRow: index];
         if ([mOutlineView isExpandable: item])           if ([mOutlineView isExpandable: item]) 
             content = [item contentNode];              content = [item contentNode];
Line 172 Line 172
     }       } 
 }  }
   
   - (BOOL)outlineView:(NSOutlineView *)outlineView shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item
   {
       return NO;
   }
   
 - (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item  - (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item
 {  {
     if (!mBookmarks)      if (!mBookmarks)
Line 222 Line 227
   
 - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item  - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
 {  {
    if (!item)    NSMutableAttributedString   *cellValue = [[NSMutableAttributedString alloc] init];
     NSMutableAttributedString   *attachmentAttrString = nil;
     NSString                                    *columnName = [tableColumn identifier];
     NSCell                                              *attachmentCell;
 
     if ( item ) {
         NSLog(@"%@", item);
         if ([columnName isEqualToString: @"name"]) {
             nsIContent* content = [item contentNode];
             nsAutoString nameAttr;
             content->GetAttr(kNameSpaceID_None, BookmarksService::gNameAtom, nameAttr);
             nsCAutoString cStr; cStr.AssignWithConversion(nameAttr);
             
         //set cell's textual contents
             [cellValue replaceCharactersInRange:NSMakeRange(0, [cellValue length])
                                      withString:[NSString stringWithCString: cStr.get()]];
             
         //Add image to cell's text in front of the text.
             NSFileWrapper *wrapper = [[NSFileWrapper alloc] initRegularFileWithContents:nil];
             NSTextAttachment *attachment = [[NSTextAttachment allocWithZone:NULL] initWithFileWrapper:wrapper];
             attachmentAttrString = [[NSMutableAttributedString attributedStringWithAttachment:attachment] retain];
             [attachment release];
             [wrapper release];
 
             attachmentCell = (NSCell *)[(NSTextAttachment *)[attachmentAttrString attribute:NSAttachmentAttributeName
                                                                                     atIndex:0
                                                                              effectiveRange:NULL] attachmentCell];
 
             [attachmentCell setImage:[NSImage imageNamed:@"folder"]];
             [cellValue replaceCharactersInRange:NSMakeRange(0, 0) withAttributedString:attachmentAttrString];
             [cellValue addAttribute:NSBaselineOffsetAttributeName
                               value:[NSNumber numberWithFloat:-3.0]
                               range:NSMakeRange(0, 1)];
         //Done adding image. 
         }
         return cellValue;
     } else {
         return nil;          return nil;
       
     NSString* columnName = [tableColumn identifier];  
         
     if ([columnName isEqualToString: @"name"]) {  
         nsIContent* content = [item contentNode];  
         nsAutoString nameAttr;  
         content->GetAttr(kNameSpaceID_None, BookmarksService::gNameAtom, nameAttr);  
         nsCAutoString cStr; cStr.AssignWithConversion(nameAttr);  
         return [NSString stringWithCString: cStr.get()];  
     }      }
       
     return nil;  
 }  }
   
 - (void)outlineView:(NSOutlineView *)outlineView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item  - (void)outlineView:(NSOutlineView *)outlineView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
Line 263 Line 293
 {  {
     mContentNode = aContentNode;      mContentNode = aContentNode;
 }  }
   
   - (id)copyWithZone:(NSZone *)aZone
   {
       BookmarkItem* copy = [[[self class] allocWithZone: aZone] init];
       [copy setContentNode: mContentNode];
       return copy;
   }
   
 @end  @end
   
 // Helper for stripping whitespace  // Helper for stripping whitespace
Line 293  StripWhitespaceNodes(nsIContent* aElemen Line 331  StripWhitespaceNodes(nsIContent* aElemen
 PRUint32 BookmarksService::gRefCnt = 0;  PRUint32 BookmarksService::gRefCnt = 0;
 nsIDocument* BookmarksService::gBookmarks = nsnull;  nsIDocument* BookmarksService::gBookmarks = nsnull;
 NSMutableDictionary* BookmarksService::gDictionary = nil;  NSMutableDictionary* BookmarksService::gDictionary = nil;
   MainController* BookmarksService::gMainController = nil;
 nsIAtom* BookmarksService::gFolderAtom = nsnull;  nsIAtom* BookmarksService::gFolderAtom = nsnull;
 nsIAtom* BookmarksService::gBookmarkAtom = nsnull;  nsIAtom* BookmarksService::gBookmarkAtom = nsnull;
 nsIAtom* BookmarksService::gHrefAtom = nsnull;  nsIAtom* BookmarksService::gHrefAtom = nsnull;
Line 384  BookmarksService::AddObserver() Line 423  BookmarksService::AddObserver()
         gNameAtom = NS_NewAtom("name");          gNameAtom = NS_NewAtom("name");
         gHrefAtom = NS_NewAtom("href");          gHrefAtom = NS_NewAtom("href");
         gInstances = new nsVoidArray();          gInstances = new nsVoidArray();
                        
         nsCOMPtr<nsIFile> profileDir;          nsCOMPtr<nsIFile> profileDir;
         NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(profileDir));          NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(profileDir));
         profileDir->Append("bookmarks.xml");          profileDir->Append("bookmarks.xml");
Line 440  BookmarksService::FlushBookmarks() Line 479  BookmarksService::FlushBookmarks()
     nsCOMPtr<nsIDOMSerializer> domSerializer(do_CreateInstance(NS_XMLSERIALIZER_CONTRACTID));      nsCOMPtr<nsIDOMSerializer> domSerializer(do_CreateInstance(NS_XMLSERIALIZER_CONTRACTID));
     domSerializer->SerializeToStream(domDoc, outputStream, nsnull);      domSerializer->SerializeToStream(domDoc, outputStream, nsnull);
 }  }
   
   void
   BookmarksService::ConstructBookmarksMenu(NSMenu* aMenu, nsIContent* aContent)
   {
       nsCOMPtr<nsIContent> content = aContent;
       if (!content) {
           GetRootContent(getter_AddRefs(content));
           GetWrapperFor(content);
       }
       
       // Now walk our children, and for folders also recur into them.
       PRInt32 childCount;
       content->ChildCount(childCount);
       
       for (PRInt32 i = 0; i < childCount; i++) {
           nsCOMPtr<nsIContent> child;
           content->ChildAt(i, *getter_AddRefs(child));
           
           // Obtain our name attribute.
           nsAutoString name;
           child->GetAttr(kNameSpaceID_None, gNameAtom, name);
           nsCAutoString nameCStr; nameCStr.AssignWithConversion(name);
           NSString* title = [NSString stringWithCString: nameCStr.get()];
                   
           // Create a menu or menu item for the child.
           NSMenuItem* menuItem = [[[NSMenuItem alloc] initWithTitle: title action: NULL keyEquivalent: @""] autorelease];
           GetWrapperFor(child);
           [aMenu addItem: menuItem];
           
           nsCOMPtr<nsIAtom> tag;
           child->GetTag(*getter_AddRefs(tag));
           
           if (tag == gFolderAtom) {
               NSMenu* menu = [[[NSMenu alloc] initWithTitle: title] autorelease];
               [aMenu setSubmenu: menu forItem: menuItem];
               [menu setAutoenablesItems: NO];
               ConstructBookmarksMenu(menu, child);
           }
           else {
               [menuItem setTarget: gMainController];
               [menuItem setAction: @selector(openMenuBookmark:)];
           }
           
           PRUint32 contentID;
           child->GetContentID(&contentID);
           [menuItem setTag: contentID];
       }
   }
   
   void 
   BookmarksService::OpenMenuBookmark(BrowserWindowController* aController, id aMenuItem)
   {
       // Get the corresponding bookmark item.
       BookmarkItem* item = [gDictionary objectForKey: [NSNumber numberWithInt: [aMenuItem tag]]];
           
       // Get the content node.
       nsIContent* content = [item contentNode];
           
       // Get the href attribute.  This is the URL we want to load.
       nsAutoString href;
       content->GetAttr(kNameSpaceID_None, gHrefAtom, href);
       nsCAutoString cref; cref.AssignWithConversion(href);
       if (cref.IsEmpty())
           return;
           
       NSString* url = [NSString stringWithCString: cref.get()];
       
       // Now load the URL in the window.
       [aController loadURL:[NSURL URLWithString: url]];
   }
   

Removed from v.1.6  
changed lines
  Added in v.1.11


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>