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

version 1.7, 2002/02/09 23:17:02 version 1.11, 2002/02/11 10:23:03
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 301  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;
NSMutableDictionary* BookmarksService::gBookmarkToMenuMap = nil;MainController* BookmarksService::gMainController = nil;
NSMutableDictionary* BookmarksService::gMenuToBookmarkMap = 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 394  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 432  BookmarksService::RemoveObserver() Line 461  BookmarksService::RemoveObserver()
         NS_RELEASE(gNameAtom);          NS_RELEASE(gNameAtom);
         NS_RELEASE(gHrefAtom);          NS_RELEASE(gHrefAtom);
         [gDictionary release];          [gDictionary release];
         [gBookmarkToMenuMap release];  
         [gMenuToBookmarkMap release];  
     }      }
 }  }
   
Line 456  BookmarksService::FlushBookmarks() Line 483  BookmarksService::FlushBookmarks()
 void  void
 BookmarksService::ConstructBookmarksMenu(NSMenu* aMenu, nsIContent* aContent)  BookmarksService::ConstructBookmarksMenu(NSMenu* aMenu, nsIContent* aContent)
 {  {
     // Create our menu maps.  
     if (!gMenuToBookmarkMap)  
         gMenuToBookmarkMap = [[NSMutableDictionary alloc] initWithCapacity: 30];  
     if (!gBookmarkToMenuMap)  
         gBookmarkToMenuMap = [[NSMutableDictionary alloc] initWithCapacity: 30];  
       
     nsCOMPtr<nsIContent> content = aContent;      nsCOMPtr<nsIContent> content = aContent;
     if (!content) {      if (!content) {
         GetRootContent(getter_AddRefs(content));          GetRootContent(getter_AddRefs(content));
        // Add the root entry to our maps.        GetWrapperFor(content);
        BookmarkItem* item = GetWrapperFor(content); 
        [gMenuToBookmarkMap setObject: item forKey: aMenu]; 
        [gBookmarkToMenuMap setObject: aMenu forKey: item]; 
     }      }
           
     // Now walk our children, and for folders also recur into them.      // Now walk our children, and for folders also recur into them.
Line 486  BookmarksService::ConstructBookmarksMenu Line 504  BookmarksService::ConstructBookmarksMenu
         NSString* title = [NSString stringWithCString: nameCStr.get()];          NSString* title = [NSString stringWithCString: nameCStr.get()];
                                   
         // Create a menu or menu item for the child.          // 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;          nsCOMPtr<nsIAtom> tag;
        content->GetTag(*getter_AddRefs(tag));        child->GetTag(*getter_AddRefs(tag));
         
         if (tag == gFolderAtom) {          if (tag == gFolderAtom) {
             // We are building a menu.  
             NSMenu* menu = [[[NSMenu alloc] initWithTitle: title] autorelease];              NSMenu* menu = [[[NSMenu alloc] initWithTitle: title] autorelease];
            BookmarkItem* item = GetWrapperFor(child);            [aMenu setSubmenu: menu forItem: menuItem];
            [gMenuToBookmarkMap setObject: item forKey: menu];            [menu setAutoenablesItems: NO];
            [gBookmarkToMenuMap setObject: menu forKey: item]; 
             
            [aMenu addItem: menu]; 
                         
             ConstructBookmarksMenu(menu, child);              ConstructBookmarksMenu(menu, child);
         }          }
         else {          else {
            // We are building a menu item.            [menuItem setTarget: gMainController];
            NSMenuItem* menuItem = [[[NSMenuItem alloc] initWithTitle: title action: NULL keyEquivalent: @""] autorelease];            [menuItem setAction: @selector(openMenuBookmark:)];
            BookmarkItem* item = GetWrapperFor(child); 
            [gMenuToBookmarkMap setObject: item forKey: menuItem]; 
            [gBookmarkToMenuMap setObject: menuItem forKey: item]; 
             
            [aMenu addItem: menuItem]; 
         }          }
           
           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.7  
changed lines
  Added in v.1.11


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