Diff for /chimera/BookmarksService.mm between versions 1.21 and 1.32

version 1.21, 2002/04/17 07:38:31 version 1.32, 2002/04/20 01:20:53
Line 58 Line 58
   
 -(id) init  -(id) init
 {  {
    [super init];    if ( (self = [super init]) ) {
    mBookmarks = nsnull;        mBookmarks = nsnull;
    mCachedParent = nsnull;        mCachedHref = nil;
    mCachedHref = nil;    }
     return self;      return self;
 }  }
   
Line 88 Line 88
           
     [mOutlineView setTarget: self];      [mOutlineView setTarget: self];
     [mOutlineView setDoubleAction: @selector(openBookmark:)];      [mOutlineView setDoubleAction: @selector(openBookmark:)];
       [mOutlineView setDeleteAction: @selector(deleteBookmarks:)];
     [mOutlineView reloadData];      [mOutlineView reloadData];
 }  }
   
 -(IBAction)addBookmark:(id)aSender  -(IBAction)addBookmark:(id)aSender
 {  {
  [self addBookmark: aSender useSelection: YES];  [self addBookmark: aSender useSelection: YES isFolder: NO];
 }
 
 -(IBAction)addFolder:(id)aSender
 {
   [self addBookmark: aSender useSelection: YES isFolder: YES];
 }  }
   
-(void)addBookmark:(id)aSender useSelection:(BOOL)aUseSel-(void)addBookmark:(id)aSender useSelection:(BOOL)aUseSel isFolder:(BOOL)aIsFolder
 {  {
   if (!mBookmarks)    if (!mBookmarks)
     return;      return;
   
  nsCOMPtr<nsIContent> content;  // We use the selected item to determine the parent only if aUseSel is YES.
  if (aUseSel) {  BookmarkItem* item = nil;
   if (aUseSel && ([mOutlineView numberOfSelectedRows] == 1)) {
     // There is only one selected row.  If it is a folder, use it as our parent.
     // Otherwise, use our parent,
     int index = [mOutlineView selectedRow];      int index = [mOutlineView selectedRow];
    item = [mOutlineView itemAtRow: index];
    if (index >= 0) {    if (![mOutlineView isExpandable: item]) {
      BookmarkItem* item = [mOutlineView itemAtRow: index];      // We can't be used as the parent.  Try our parent.
      if ([mOutlineView isExpandable: item])      nsIContent* content = [item contentNode];
        content = [item contentNode];      nsCOMPtr<nsIContent> parentContent;
       content->GetParent(*getter_AddRefs(parentContent));
       nsCOMPtr<nsIContent> root;
       mBookmarks->GetRootContent(getter_AddRefs(root));
       
       // The root has no item, so we don't need to do a lookup unless we
       // aren't the root.
       if (parentContent != root) {
         PRUint32 contentID;
         parentContent->GetContentID(&contentID);
         item = [(BookmarksService::gDictionary) objectForKey: [NSNumber numberWithInt: contentID]];
       }
     }      }
   }    }
   
   if (!content)  
     mBookmarks->GetRootContent(getter_AddRefs(content));  
   
   nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(mBookmarks->gBookmarks));    nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(mBookmarks->gBookmarks));
       
   // Fetch the title of the current page and the URL.    // Fetch the title of the current page and the URL.
  nsCOMPtr<nsIWebBrowser> webBrowser = getter_AddRefs([[[mBrowserWindowController getMyBrowserView] getBrowserView] getWebBrowser]);  nsAutoString title, href;
  nsCOMPtr<nsIDOMWindow> window;  if (!aIsFolder) {
  webBrowser->GetContentDOMWindow(getter_AddRefs(window));    BookmarksService::GetTitleAndHrefForBrowserView([[mBrowserWindowController getMyBrowserView] getBrowserView],
  nsCOMPtr<nsIDOMDocument> htmlDoc;                                                    title, href);
  window->GetDocument(getter_AddRefs(htmlDoc)); 
  nsCOMPtr<nsIDocument> pageDoc(do_QueryInterface(htmlDoc)); 
   
  nsAutoString href;    mCachedHref = [NSString stringWithCharacters: href.get() length: nsCRT::strlen(href.get())];
  if (pageDoc) {    [mCachedHref retain];
    nsCOMPtr<nsIURI> url;  }
    pageDoc->GetDocumentURL(getter_AddRefs(url));  else {
    nsCAutoString spec;    mCachedHref = nil;
    url->GetSpec(spec);    title = NS_LITERAL_STRING("New Folder");
    href.AssignWithConversion(spec.get()); 
   }    }
   
   mCachedHref = [NSString stringWithCharacters: href.get() length: nsCRT::strlen(href.get())];  
   [mCachedHref retain];  
     
   mCachedParent = content;  
     
   nsAutoString title;  
   nsCOMPtr<nsIDOMHTMLDocument> htmlDocument(do_QueryInterface(htmlDoc));  
   if (htmlDocument)  
     htmlDocument->GetTitle(title);  
   if (title.IsEmpty())  
     title = href;  
       
   NSTextField* textField = [mBrowserWindowController getAddBookmarkTitle];    NSTextField* textField = [mBrowserWindowController getAddBookmarkTitle];
   [textField setStringValue: [NSString stringWithCharacters: title.get() length: nsCRT::strlen(title.get())]];    [textField setStringValue: [NSString stringWithCharacters: title.get() length: nsCRT::strlen(title.get())]];
   
   [mBrowserWindowController cacheBookmarkDS: self];    [mBrowserWindowController cacheBookmarkDS: self];
   
     // Show/hide the bookmark all tabs checkbox as appropriate.
     NSTabView* tabView = [mBrowserWindowController getTabBrowser];
     id checkbox = [mBrowserWindowController getAddBookmarkCheckbox];
     BOOL hasSuperview = [checkbox superview] != nil;
     if (aIsFolder && hasSuperview) {
       // Just don't show it at all.
       [checkbox removeFromSuperview];
       [checkbox retain];
     }
     else if (!aIsFolder && !hasSuperview) {
       // Put it back in.
       [[[mBrowserWindowController getAddBookmarkSheetWindow] contentView] addSubview: checkbox];
       [checkbox autorelease];
     }
   
     // Enable the bookmark all tabs checkbox if appropriate.
     if (!aIsFolder)
       [[mBrowserWindowController getAddBookmarkCheckbox] setEnabled: ([tabView numberOfTabViewItems] > 1)];
     
     // Build up the folder list.
     NSPopUpButton* popup = [mBrowserWindowController getAddBookmarkFolder];
     BookmarksService::ConstructAddBookmarkFolderList(popup, item);
       
   [NSApp beginSheet:    [mBrowserWindowController getAddBookmarkSheetWindow]    [NSApp beginSheet:    [mBrowserWindowController getAddBookmarkSheetWindow]
      modalForWindow:    [mBrowserWindowController window]       modalForWindow:    [mBrowserWindowController window]
Line 162 Line 187
 {  {
   if (aCode == 0)    if (aCode == 0)
     return;      return;
   
     BOOL isGroup = NO;
     id checkbox = [mBrowserWindowController getAddBookmarkCheckbox];
     if (([checkbox superview] != nil) && [checkbox isEnabled] && ([checkbox state] == NSOnState)) {
       mCachedHref = nil;
       isGroup = YES;
     }
       
   const char* titleC = [[[mBrowserWindowController getAddBookmarkTitle] stringValue] cString];    const char* titleC = [[[mBrowserWindowController getAddBookmarkTitle] stringValue] cString];
   nsAutoString title; title.AssignWithConversion(titleC);    nsAutoString title; title.AssignWithConversion(titleC);
   
     nsAutoString tagName;
     if (mCachedHref)
       tagName = NS_LITERAL_STRING("bookmark");
     else
       tagName = NS_LITERAL_STRING("folder");
     
   nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(mBookmarks->gBookmarks));    nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(mBookmarks->gBookmarks));
   nsCOMPtr<nsIDOMElement> elt;    nsCOMPtr<nsIDOMElement> elt;
  domDoc->CreateElementNS(NS_LITERAL_STRING("http://chimera.mozdev.org/bookmarks"),  domDoc->CreateElementNS(NS_LITERAL_STRING("http://chimera.mozdev.org/bookmarks/"),
                          NS_LITERAL_STRING("bookmark"),                          tagName,
                           getter_AddRefs(elt));                            getter_AddRefs(elt));
   
   elt->SetAttribute(NS_LITERAL_STRING("name"), title);    elt->SetAttribute(NS_LITERAL_STRING("name"), title);
   nsAutoString href; href.AssignWithConversion([mCachedHref cString]);  
   [mCachedHref release];  
     
   elt->SetAttribute(NS_LITERAL_STRING("href"), href);  
   
  nsCOMPtr<nsIDOMElement> parent(do_QueryInterface(mCachedParent));  if (mCachedHref) {
     nsAutoString href; href.AssignWithConversion([mCachedHref cString]);
     [mCachedHref release];
     elt->SetAttribute(NS_LITERAL_STRING("href"), href);
   }
 
   if (isGroup) {
     // We have to iterate over each tab and create content nodes using the
     // title/href of all the pages.  They are inserted underneath the parent.
     elt->SetAttribute(NS_LITERAL_STRING("group"), NS_LITERAL_STRING("true"));
     id tabBrowser = [mBrowserWindowController getTabBrowser];
     int count = [tabBrowser numberOfTabViewItems];
     for (int i = 0; i < count; i++) {
       id browserView = [[[tabBrowser tabViewItemAtIndex: i] view] getBrowserView];
       nsAutoString title, href;
       BookmarksService::GetTitleAndHrefForBrowserView(browserView, title, href);
       nsCOMPtr<nsIDOMElement> childElt;
       domDoc->CreateElementNS(NS_LITERAL_STRING("http://chimera.mozdev.org/bookmarks/"),
                               NS_LITERAL_STRING("bookmark"),
                               getter_AddRefs(childElt));
       childElt->SetAttribute(NS_LITERAL_STRING("name"), title);
       childElt->SetAttribute(NS_LITERAL_STRING("href"), href);
       nsCOMPtr<nsIDOMNode> dummy;
       elt->AppendChild(childElt, getter_AddRefs(dummy));
     }
   }
   
   // Figure out the parent element.
   nsCOMPtr<nsIDOMElement> parentElt;
   nsCOMPtr<nsIContent> parentContent;
   NSPopUpButton* popup = [mBrowserWindowController getAddBookmarkFolder];
   NSMenuItem* selectedItem = [popup selectedItem];
   int tag = [selectedItem tag];
   if (tag == -1) {
     mBookmarks->GetRootContent(getter_AddRefs(parentContent));
     parentElt = do_QueryInterface(parentContent);
   }
   else {
     BookmarkItem* item = [(BookmarksService::gDictionary) objectForKey: [NSNumber numberWithInt: tag]];
     // Get the content node.
     parentContent = [item contentNode];
     parentElt = do_QueryInterface(parentContent);
   }
   
   nsCOMPtr<nsIDOMNode> dummy;    nsCOMPtr<nsIDOMNode> dummy;
  parent->AppendChild(elt, getter_AddRefs(dummy));  parentElt->AppendChild(elt, getter_AddRefs(dummy));
   
   nsCOMPtr<nsIContent> childContent(do_QueryInterface(elt));    nsCOMPtr<nsIContent> childContent(do_QueryInterface(elt));
  mBookmarks->BookmarkAdded(mCachedParent, childContent);  mBookmarks->BookmarkAdded(parentContent, childContent);
 }  }
   
-(IBAction)deleteBookmark: (id)aSender-(IBAction)deleteBookmarks: (id)aSender
 {  {
    if (!mBookmarks)  if (!mBookmarks)
        return;    return;
    
    int index = [mOutlineView selectedRow];  int index = [mOutlineView selectedRow];
    if (index == -1)  if (index == -1)
        return;    return;
          if ([mOutlineView numberOfSelectedRows] == 1) {
     BookmarkItem* item = [mOutlineView itemAtRow: index];      BookmarkItem* item = [mOutlineView itemAtRow: index];
    nsCOMPtr<nsIContent> content = [item contentNode];    [self deleteBookmark: item];
    nsCOMPtr<nsIDOMElement> child(do_QueryInterface(content)); 
    nsCOMPtr<nsIDOMNode> parent; 
    child->GetParentNode(getter_AddRefs(parent)); 
    nsCOMPtr<nsIContent> parentContent(do_QueryInterface(parent)); 
    nsCOMPtr<nsIDOMNode> dummy; 
    parent->RemoveChild(child, getter_AddRefs(dummy)); 
    mBookmarks->BookmarkRemoved(parentContent, content); 
     
     int total = [mOutlineView numberOfRows];      int total = [mOutlineView numberOfRows];
     if (index == total)      if (index == total)
        index--;      index--;
         
     [mOutlineView selectRow: index byExtendingSelection: NO];      [mOutlineView selectRow: index byExtendingSelection: NO];
     }
     else {
       NSMutableArray* itemsToDelete = [[[NSMutableArray alloc] init] autorelease];
       NSEnumerator* selRows = [mOutlineView selectedRowEnumerator];
       for (NSNumber* currIndex = [selRows nextObject];
            currIndex != nil;
            currIndex = [selRows nextObject]) {
         index = [currIndex intValue];
         BookmarkItem* item = [mOutlineView itemAtRow: index];
         [itemsToDelete addObject: item];
       }
   
       int count = [itemsToDelete count];
       for (int i = 0; i < count; i++) {
         BookmarkItem* item = [itemsToDelete objectAtIndex: i];
         [self deleteBookmark: item];      
       }
     }
   }       
   
   -(void)deleteBookmark:(id)aItem
   {
     nsCOMPtr<nsIContent> content = [aItem contentNode];
     nsCOMPtr<nsIDOMElement> child(do_QueryInterface(content));
     if (child == BookmarksService::gToolbarRoot)
       return; // Don't allow the personal toolbar to be deleted.
     
     nsCOMPtr<nsIDOMNode> parent;
     child->GetParentNode(getter_AddRefs(parent));
     nsCOMPtr<nsIContent> parentContent(do_QueryInterface(parent));
     nsCOMPtr<nsIDOMNode> dummy;
     parent->RemoveChild(child, getter_AddRefs(dummy));
     mBookmarks->BookmarkRemoved(parentContent, content);
 }  }
   
 -(IBAction)openBookmark: (id)aSender  -(IBAction)openBookmark: (id)aSender
 {  {
    int index = [mOutlineView selectedRow];  int index = [mOutlineView selectedRow];
    if (index == -1)  if (index == -1)
        return;    return;
    
    id item = [mOutlineView itemAtRow: index];  id item = [mOutlineView itemAtRow: index];
    if (!item)  if (!item)
        return;    return;
        
    if ([mOutlineView isExpandable: item]) {  nsIContent* content = [item contentNode];
        if ([mOutlineView isItemExpanded: item])  nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(content));
            [mOutlineView collapseItem: item];  nsAutoString group;
        else  elt->GetAttribute(NS_LITERAL_STRING("group"), group);
            [mOutlineView expandItem: item];  if (!group.IsEmpty())
     mBookmarks->OpenBookmarkGroup([mBrowserWindowController getTabBrowser], elt);
   else if ([mOutlineView isExpandable: item]) {
     if ([mOutlineView isItemExpanded: item])
       [mOutlineView collapseItem: item];
     else
       [mOutlineView expandItem: item];
   }
   else {
     nsAutoString href;
     content->GetAttr(kNameSpaceID_None, BookmarksService::gHrefAtom, href);
     if (!href.IsEmpty()) {
       nsCAutoString cstr; cstr.AssignWithConversion(href);
       NSString* url = [NSString stringWithCString: cstr.get()];
       [[[mBrowserWindowController getMyBrowserView] getBrowserView] loadURI:[NSURL URLWithString: url] flags:                   NSLoadFlagsNone];
       // Focus and activate our content area.
       [[[mBrowserWindowController getMyBrowserView] getBrowserView] setActive: YES];
     }      }
    else {  }
        nsIContent* content = [item contentNode]; 
        nsAutoString href; 
        content->GetAttr(kNameSpaceID_None, BookmarksService::gHrefAtom, href); 
        if (!href.IsEmpty()) { 
            nsCAutoString cstr; cstr.AssignWithConversion(href); 
            NSString* url = [NSString stringWithCString: cstr.get()]; 
            [[[mBrowserWindowController getMyBrowserView] getBrowserView] loadURI:[NSURL URLWithString: url] flags:NSLoadFlagsNone]; 
            // Focus and activate our content area. 
            [[[mBrowserWindowController getMyBrowserView] getBrowserView] setActive: YES]; 
        } 
    }  
 }  }
   
 - (BOOL)outlineView:(NSOutlineView *)outlineView shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item  - (BOOL)outlineView:(NSOutlineView *)outlineView shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item
Line 324 Line 430
                                                                                           atIndex:0                                                                                            atIndex:0
                                                                                    effectiveRange:nil] attachmentCell];                                                                                     effectiveRange:nil] attachmentCell];
         //Figure out which image to add, and set the cell's image.          //Figure out which image to add, and set the cell's image.
           // XXXdwh Use the bookmark groups image for groups.
         if ( [self outlineView:outlineView isItemExpandable:item] ) {          if ( [self outlineView:outlineView isItemExpandable:item] ) {
             [attachmentAttrStringCell setImage:[NSImage imageNamed:@"folder"]];              [attachmentAttrStringCell setImage:[NSImage imageNamed:@"folder"]];
         } else {          } else {
Line 405  nsIDocument* BookmarksService::gBookmark Line 512  nsIDocument* BookmarksService::gBookmark
 NSMutableDictionary* BookmarksService::gDictionary = nil;  NSMutableDictionary* BookmarksService::gDictionary = nil;
 MainController* BookmarksService::gMainController = nil;  MainController* BookmarksService::gMainController = nil;
 NSMenu* BookmarksService::gBookmarksMenu = nil;  NSMenu* BookmarksService::gBookmarksMenu = nil;
   nsIDOMElement* BookmarksService::gToolbarRoot = nsnull;
 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 465  BookmarksService::LocateMenu(nsIContent* Line 573  BookmarksService::LocateMenu(nsIContent*
 {  {
   nsCOMPtr<nsIContent> parent;    nsCOMPtr<nsIContent> parent;
   aContent->GetParent(*getter_AddRefs(parent));    aContent->GetParent(*getter_AddRefs(parent));
  if (!parent)  if (!parent) {
     return BookmarksService::gBookmarksMenu;      return BookmarksService::gBookmarksMenu;
  }
   
   NSMenu* parentMenu = LocateMenu(parent);    NSMenu* parentMenu = LocateMenu(parent);
       
   PRUint32 contentID;    PRUint32 contentID;
   aContent->GetContentID(&contentID);    aContent->GetContentID(&contentID);
   
   NSMenuItem* childMenu = [parentMenu itemWithTag: contentID];    NSMenuItem* childMenu = [parentMenu itemWithTag: contentID];
  return [childMenu menu];  return [childMenu submenu];
 }  }
   
 void  void
Line 499  BookmarksService::BookmarkAdded(nsIConte Line 608  BookmarksService::BookmarkAdded(nsIConte
   
       [(instance->mDataSource) reloadDataForItem: item reloadChildren: YES];        [(instance->mDataSource) reloadDataForItem: item reloadChildren: YES];
     }      }
       else if (instance->mToolbar) {
         // We're a personal toolbar.
         nsCOMPtr<nsIDOMElement> parentElt(do_QueryInterface(aContainer));
         if (parentElt == gToolbarRoot) {
           // We only care about changes that occur to the personal toolbar's immediate
           // children.
           PRInt32 index = -1;
           aContainer->IndexOf(aChild, index);
           nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(aChild));
           [(instance->mToolbar) addButton: elt atIndex: index];
         }
       }
     else {      else {
       // We're the menu.        // We're the menu.
       PRInt32 index = -1;        PRInt32 index = -1;
      aChild->IndexOf(aContainer, index);      aContainer->IndexOf(aChild, index);
       NSMenu* menu = LocateMenu(aContainer);        NSMenu* menu = LocateMenu(aContainer);
       AddMenuBookmark(menu, aContainer, aChild, index);        AddMenuBookmark(menu, aContainer, aChild, index);
     }      }
Line 552  BookmarksService::BookmarkRemoved(nsICon Line 673  BookmarksService::BookmarkRemoved(nsICon
   
       [(instance->mDataSource) reloadDataForItem: item reloadChildren: YES];        [(instance->mDataSource) reloadDataForItem: item reloadChildren: YES];
     }      }
       else if (instance->mToolbar) {
         // We're a personal toolbar.
         nsCOMPtr<nsIDOMElement> parentElt(do_QueryInterface(aContainer));
         if (parentElt == gToolbarRoot) {
           // We only care about changes that occur to the personal toolbar's immediate
           // children.
           nsCOMPtr<nsIDOMElement> childElt(do_QueryInterface(aChild));
           [(instance->mToolbar) removeButton: childElt];
         }
       }    
     else {      else {
       // We're the menu.        // We're the menu.
       NSMenu* menu = LocateMenu(aContainer);        NSMenu* menu = LocateMenu(aContainer);
Line 632  BookmarksService::FlushBookmarks() Line 763  BookmarksService::FlushBookmarks()
     domSerializer->SerializeToStream(domDoc, outputStream, nsnull);      domSerializer->SerializeToStream(domDoc, outputStream, nsnull);
 }  }
   
voidvoid BookmarksService::EnsureToolbarRoot()
BookmarksService::ConstructBookmarksToolbar() 
 {  {
     if (gToolbarRoot)
       return;
   
   nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(gBookmarks));    nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(gBookmarks));
  nsCOMPtr<nsIDOMElement> toolbarRoot;  nsCOMPtr<nsIDOMElement> rootElt;
  domDoc->GetElementById(NS_LITERAL_STRING("toolbar"), getter_AddRefs(toolbarRoot));  domDoc->GetDocumentElement(getter_AddRefs(rootElt));
       
     nsCOMPtr<nsIDOMNode> child;
     rootElt->GetFirstChild(getter_AddRefs(child));
     nsAutoString typeValue;
     while (child) {
       nsCOMPtr<nsIDOMElement> childElt(do_QueryInterface(child));
       if (childElt) {
         childElt->GetAttribute(NS_LITERAL_STRING("type"), typeValue);
         if (typeValue.Equals(NS_LITERAL_STRING("toolbar")))
           gToolbarRoot = childElt;
       }
       
       nsCOMPtr<nsIDOMNode> temp;
       child->GetNextSibling(getter_AddRefs(temp));
       child = temp;
     }
   
     if (!gToolbarRoot) {
       printf("Repairing personal toolbar.\n");
       nsCOMPtr<nsIDOMElement> elt;
       domDoc->CreateElementNS(NS_LITERAL_STRING("http://chimera.mozdev.org/bookmarks/"),
                               NS_LITERAL_STRING("folder"),
                               getter_AddRefs(elt));
   
       elt->SetAttribute(NS_LITERAL_STRING("name"), NS_LITERAL_STRING("Toolbar Bookmarks"));
       elt->SetAttribute(NS_LITERAL_STRING("type"), NS_LITERAL_STRING("toolbar"));
   
       nsCOMPtr<nsIDOMNode> dummy;
       rootElt->AppendChild(elt, getter_AddRefs(dummy));
       gToolbarRoot = elt;
     }
   }
   
   static
   void RecursiveAddBookmarkConstruct(NSPopUpButton* aPopup, NSMenu* aMenu, int aTagToMatch)
   {
     // Get the menu item children.
     NSArray* children = [aMenu itemArray];
     int startPosition = 0;
     if (aMenu == BookmarksService::gBookmarksMenu)
       startPosition = 3;
   
     int count = [children count];
     for (int i = startPosition; i < count; i++) {
       NSMenuItem* menuItem = [children objectAtIndex: i];
       NSMenu* submenu = [menuItem submenu];
       if (submenu) {
         // This is a folder.  Add it to our list and then recur.
         [aPopup addItemWithTitle: [menuItem title]];
         NSMenuItem* lastItem = [aPopup lastItem];
         if ([menuItem tag] == aTagToMatch)
           [aPopup selectItem: lastItem];
         
         [lastItem setTag: [menuItem tag]];
         RecursiveAddBookmarkConstruct(aPopup, submenu, aTagToMatch);
       }
     }
   }
   
   void
   BookmarksService::ConstructAddBookmarkFolderList(NSPopUpButton* aPopup, BookmarkItem* aItem)
   {
     [aPopup removeAllItems];
     [aPopup addItemWithTitle: [gBookmarksMenu title]];
     NSMenuItem* lastItem = [aPopup lastItem];
     [lastItem setTag: -1];
     int tag = -1;
     if (aItem) {
       nsIContent* content = [aItem contentNode];
       PRUint32 utag;
       content->GetContentID(&utag);
       tag = (int)utag;
     }
     RecursiveAddBookmarkConstruct(aPopup, gBookmarksMenu, tag);
   }
   
   void
   BookmarksService::GetTitleAndHrefForBrowserView(id aBrowserView, nsString& aTitle, nsString& aHref)
   {
     nsCOMPtr<nsIWebBrowser> webBrowser = getter_AddRefs([aBrowserView getWebBrowser]);
     nsCOMPtr<nsIDOMWindow> window;
     webBrowser->GetContentDOMWindow(getter_AddRefs(window));
     nsCOMPtr<nsIDOMDocument> htmlDoc;
     window->GetDocument(getter_AddRefs(htmlDoc));
     nsCOMPtr<nsIDocument> pageDoc(do_QueryInterface(htmlDoc));
   
     if (pageDoc) {
       nsCOMPtr<nsIURI> url;
       pageDoc->GetDocumentURL(getter_AddRefs(url));
       nsCAutoString spec;
       url->GetSpec(spec);
       aHref.AssignWithConversion(spec.get());
     }
   
     nsCOMPtr<nsIDOMHTMLDocument> htmlDocument(do_QueryInterface(htmlDoc));
     if (htmlDocument)
       htmlDocument->GetTitle(aTitle);
     if (aTitle.IsEmpty())
       aTitle = aHref;  
 }  }
   
 void  void
Line 682  BookmarksService::AddMenuBookmark(NSMenu Line 913  BookmarksService::AddMenuBookmark(NSMenu
   nsCOMPtr<nsIAtom> tagName;    nsCOMPtr<nsIAtom> tagName;
   aChild->GetTag(*getter_AddRefs(tagName));    aChild->GetTag(*getter_AddRefs(tagName));
   
  if (tagName == gFolderAtom) {  nsAutoString group;
   nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(aChild));
   elt->GetAttribute(NS_LITERAL_STRING("group"), group);
   
   if (group.IsEmpty() && tagName == gFolderAtom) {
     NSMenu* menu = [[[NSMenu alloc] initWithTitle: title] autorelease];      NSMenu* menu = [[[NSMenu alloc] initWithTitle: title] autorelease];
     [aMenu setSubmenu: menu forItem: menuItem];      [aMenu setSubmenu: menu forItem: menuItem];
     [menu setAutoenablesItems: NO];      [menu setAutoenablesItems: NO];
Line 701  BookmarksService::AddMenuBookmark(NSMenu Line 936  BookmarksService::AddMenuBookmark(NSMenu
 void   void 
 BookmarksService::OpenMenuBookmark(BrowserWindowController* aController, id aMenuItem)  BookmarksService::OpenMenuBookmark(BrowserWindowController* aController, id aMenuItem)
 {  {
    // Get the corresponding bookmark item.  // Get the corresponding bookmark item.
    BookmarkItem* item = [gDictionary objectForKey: [NSNumber numberWithInt: [aMenuItem tag]]];  BookmarkItem* item = [gDictionary objectForKey: [NSNumber numberWithInt: [aMenuItem tag]]];
        
    // Get the content node.  // Get the content node.
    nsIContent* content = [item contentNode];  nsIContent* content = [item contentNode];
          nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(content));
    // Get the href attribute.  This is the URL we want to load.  nsAutoString group;
    nsAutoString href;  elt->GetAttribute(NS_LITERAL_STRING("group"), group);
    content->GetAttr(kNameSpaceID_None, gHrefAtom, href);  if (!group.IsEmpty())
    nsCAutoString cref; cref.AssignWithConversion(href);    return OpenBookmarkGroup([aController getTabBrowser], elt);
    if (cref.IsEmpty())  
        return;  // Get the href attribute.  This is the URL we want to load.
          nsAutoString href;
    NSString* url = [NSString stringWithCString: cref.get()];  content->GetAttr(kNameSpaceID_None, gHrefAtom, href);
      nsCAutoString cref; cref.AssignWithConversion(href);
    // Now load the URL in the window.  if (cref.IsEmpty())
    [aController loadURL:[NSURL URLWithString: url]];    return;
 
   NSString* url = [NSString stringWithCString: cref.get()];
 
   // Now load the URL in the window.
   [aController loadURL:[NSURL URLWithString: url]];
 
   // Focus and activate our content area.
   [[[aController getMyBrowserView] getBrowserView] setActive: YES];
 }
 
 void
 BookmarksService::OpenBookmarkGroup(id aTabView, nsIDOMElement* aFolder)
 {
   // We might conceivably have to make new tabs in order to load all
   // the items in the group.
   int currentIndex = 0;
   int total = [aTabView numberOfTabViewItems];
   nsCOMPtr<nsIDOMNode> child;
   aFolder->GetFirstChild(getter_AddRefs(child));
   while (child) {
     nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(child));
     if (elt) {
       nsAutoString href;
       elt->GetAttribute(NS_LITERAL_STRING("href"), href);
       if (!href.IsEmpty()) {
         nsCAutoString cref; cref.AssignWithConversion(href);
         NSString* url = [NSString stringWithCString: cref.get()];
         NSTabViewItem* tabViewItem = nil;
         if (currentIndex >= total) {
           // We need to make a new tab.
           tabViewItem = [[[NSTabViewItem alloc] initWithIdentifier: nil] autorelease];
           MyBrowserView* newView = [[[MyBrowserView alloc] initWithTab: tabViewItem andWindow: [aTabView window]] autorelease];
           [tabViewItem setLabel: @"Untitled"];
           [tabViewItem setView: newView];
           [aTabView addTabViewItem: tabViewItem];
         }
         else
           tabViewItem = [aTabView tabViewItemAtIndex: currentIndex];
 
         [[[tabViewItem view] getBrowserView] loadURI:[NSURL URLWithString: url]
                                                flags: NSLoadFlagsNone];
       }
     }
           
     // Focus and activate our content area.  
     [[[aController getMyBrowserView] getBrowserView] setActive: YES];  
 }  
   
       nsCOMPtr<nsIDOMNode> temp = child;
       temp->GetNextSibling(getter_AddRefs(child));
       currentIndex++;
     }
   
     // Select and activate the first tab.
     [aTabView selectTabViewItemAtIndex: 0];
     [[[[aTabView tabViewItemAtIndex: 0] view] getBrowserView] setActive: YES];
   }

Removed from v.1.21  
changed lines
  Added in v.1.32


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