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

version 1.7, 2002/02/09 23:17:02 version 1.8, 2002/02/10 00:29:08
Line 301  StripWhitespaceNodes(nsIContent* aElemen Line 301  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 393  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 431  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 453  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 474  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.8


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