Diff for /chimera/BookmarksService.mm between versions 1.22 and 1.24

version 1.22, 2002/04/17 08:31:11 version 1.24, 2002/04/17 23:55:25
Line 93 Line 93
   
 -(IBAction)addBookmark:(id)aSender  -(IBAction)addBookmark:(id)aSender
 {  {
  [self addBookmark: aSender useSelection: YES];  [self addBookmark: aSender useSelection: YES isFolder: NO];
 }  }
   
-(void)addBookmark:(id)aSender useSelection:(BOOL)aUseSel-(IBAction)addFolder:(id)aSender
 {
   [self addBookmark: aSender useSelection: YES isFolder: YES];
 }
 
 -(void)addBookmark:(id)aSender useSelection:(BOOL)aUseSel isFolder:(BOOL)aIsFolder
 {  {
   if (!mBookmarks)    if (!mBookmarks)
     return;      return;
Line 115 Line 120
   if (!content)    if (!content)
     mBookmarks->GetRootContent(getter_AddRefs(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.
   nsCOMPtr<nsIWebBrowser> webBrowser = getter_AddRefs([[[mBrowserWindowController getMyBrowserView] getBrowserView] getWebBrowser]);  
   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 retain];  
     
   mCachedParent = content;  
     
   nsAutoString title;    nsAutoString title;
  nsCOMPtr<nsIDOMHTMLDocument> htmlDocument(do_QueryInterface(htmlDoc));  if (!aIsFolder) {
  if (htmlDocument)    nsCOMPtr<nsIWebBrowser> webBrowser = getter_AddRefs([[[mBrowserWindowController getMyBrowserView]
    htmlDocument->GetTitle(title);      getBrowserView] getWebBrowser]);
  if (title.IsEmpty())    nsCOMPtr<nsIDOMWindow> window;
    title = href;    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 retain];
   
     nsCOMPtr<nsIDOMHTMLDocument> htmlDocument(do_QueryInterface(htmlDoc));
     if (htmlDocument)
       htmlDocument->GetTitle(title);
     if (title.IsEmpty())
       title = href;
   }
   else {
     mCachedHref = nil;
     title = NS_LITERAL_STRING("New Folder");
   }
       
   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())]];
Line 166 Line 178
   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);  
   
     if (mCachedHref) {
       nsAutoString href; href.AssignWithConversion([mCachedHref cString]);
       [mCachedHref release];
       elt->SetAttribute(NS_LITERAL_STRING("href"), href);
     }
     
   nsCOMPtr<nsIDOMElement> parent(do_QueryInterface(mCachedParent));    nsCOMPtr<nsIDOMElement> parent(do_QueryInterface(mCachedParent));
   nsCOMPtr<nsIDOMNode> dummy;    nsCOMPtr<nsIDOMNode> dummy;
   parent->AppendChild(elt, getter_AddRefs(dummy));    parent->AppendChild(elt, getter_AddRefs(dummy));
Line 466  BookmarksService::LocateMenu(nsIContent* Line 486  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 500  BookmarksService::BookmarkAdded(nsIConte Line 521  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 553  BookmarksService::BookmarkRemoved(nsICon Line 586  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);

Removed from v.1.22  
changed lines
  Added in v.1.24


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