Diff for /chimera/BookmarksService.mm between versions 1.27 and 1.28

version 1.27, 2002/04/19 08:45:57 version 1.28, 2002/04/19 19:28:43
Line 106 Line 106
   if (!mBookmarks)    if (!mBookmarks)
     return;      return;
   
     // We use the selected item to determine the parent only if aUseSel is YES.
   BookmarkItem* item = nil;    BookmarkItem* item = nil;
  if (aUseSel) {  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]) {
      item = [mOutlineView itemAtRow: index];      // We can't be used as the parent.  Try our parent.
      if ([mOutlineView numberOfSelectedRows] != 1 || ![mOutlineView isExpandable: item])      nsIContent* content = [item contentNode];
        item = nil;      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]];
       }
     }      }
   }    }
   
   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 158 Line 152
   
   [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.    // Build up the folder list.
   NSPopUpButton* popup = [mBrowserWindowController getAddBookmarkFolder];    NSPopUpButton* popup = [mBrowserWindowController getAddBookmarkFolder];
   BookmarksService::ConstructAddBookmarkFolderList(popup, item);    BookmarksService::ConstructAddBookmarkFolderList(popup, item);
Line 173 Line 186
 {  {
   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
     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.    // Figure out the parent element.
   nsCOMPtr<nsIDOMElement> parentElt;    nsCOMPtr<nsIDOMElement> parentElt;
   nsCOMPtr<nsIContent> parentContent;    nsCOMPtr<nsIContent> parentContent;
Line 800  BookmarksService::ConstructAddBookmarkFo Line 841  BookmarksService::ConstructAddBookmarkFo
 }  }
   
 void  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
 BookmarksService::ConstructBookmarksMenu(NSMenu* aMenu, nsIContent* aContent)  BookmarksService::ConstructBookmarksMenu(NSMenu* aMenu, nsIContent* aContent)
 {  {
     nsCOMPtr<nsIContent> content = aContent;      nsCOMPtr<nsIContent> content = aContent;

Removed from v.1.27  
changed lines
  Added in v.1.28


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