Diff for /chimera/BookmarksService.mm between versions 1.25 and 1.30

version 1.25, 2002/04/18 00:27:51 version 1.30, 2002/04/20 00:44:56
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];
 }  }
   
Line 106 Line 107
   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));  
   
   mCachedParent = 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.
  nsAutoString title;  nsAutoString title, href;
   if (!aIsFolder) {    if (!aIsFolder) {
    nsCOMPtr<nsIWebBrowser> webBrowser = getter_AddRefs([[[mBrowserWindowController getMyBrowserView]    BookmarksService::GetTitleAndHrefForBrowserView([[mBrowserWindowController getMyBrowserView] getBrowserView],
      getBrowserView] getWebBrowser]);                                                    title, href);
    nsCOMPtr<nsIDOMWindow> window; 
    webBrowser->GetContentDOMWindow(getter_AddRefs(window)); 
    nsCOMPtr<nsIDOMDocument> htmlDoc; 
    window->GetDocument(getter_AddRefs(htmlDoc)); 
    nsCOMPtr<nsIDocument> pageDoc(do_QueryInterface(htmlDoc)); 
 
    nsAutoString href; 
    if (pageDoc) { 
      nsCOMPtr<nsIURI> url; 
      pageDoc->GetDocumentURL(getter_AddRefs(url)); 
      nsCAutoString spec; 
      url->GetSpec(spec); 
      href.AssignWithConversion(spec.get()); 
    } 
   
     mCachedHref = [NSString stringWithCharacters: href.get() length: nsCRT::strlen(href.get())];      mCachedHref = [NSString stringWithCharacters: href.get() length: nsCRT::strlen(href.get())];
     [mCachedHref retain];      [mCachedHref retain];
     
     nsCOMPtr<nsIDOMHTMLDocument> htmlDocument(do_QueryInterface(htmlDoc));  
     if (htmlDocument)  
       htmlDocument->GetTitle(title);  
     if (title.IsEmpty())  
       title = href;  
   }    }
   else {    else {
     mCachedHref = nil;      mCachedHref = nil;
Line 162 Line 152
   [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 174 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);
Line 197 Line 217
     [mCachedHref release];      [mCachedHref release];
     elt->SetAttribute(NS_LITERAL_STRING("href"), href);      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<nsIDOMElement> parent(do_QueryInterface(mCachedParent));  
   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)deleteBookmarks: (id)aSender  -(IBAction)deleteBookmarks: (id)aSender
Line 258 Line 315
   
 -(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 741  void BookmarksService::EnsureToolbarRoot Line 803  void BookmarksService::EnsureToolbarRoot
   }    }
 }  }
   
   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
 BookmarksService::ConstructBookmarksMenu(NSMenu* aMenu, nsIContent* aContent)  BookmarksService::ConstructBookmarksMenu(NSMenu* aMenu, nsIContent* aContent)
 {  {
Line 821  BookmarksService::OpenMenuBookmark(Brows Line 951  BookmarksService::OpenMenuBookmark(Brows
           
     // Focus and activate our content area.      // Focus and activate our content area.
     [[[aController getMyBrowserView] getBrowserView] setActive: YES];      [[[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];
         }
       }
       
       nsCOMPtr<nsIDOMNode> temp = child;
       temp->GetNextSibling(getter_AddRefs(child));
       currentIndex++;
     }
   
     // XXXdwh Select and activate the first tab.
   }

Removed from v.1.25  
changed lines
  Added in v.1.30


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