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

version 1.20, 2002/04/14 21:41:21 version 1.25, 2002/04/18 00:27:51
Line 67 Line 67
   
 -(void) dealloc  -(void) dealloc
 {  {
    [super dealloc];  [super dealloc];
 }  }
   
 -(void) windowClosing  -(void) windowClosing
 {  {
    if (mBookmarks) {  if (mBookmarks) {
        mBookmarks->RemoveObserver();    mBookmarks->RemoveObserver();
        delete mBookmarks;    delete mBookmarks;
    }  }
 }  }
   
 -(void) ensureBookmarks  -(void) ensureBookmarks
Line 93 Line 93
   
 -(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;
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 186 Line 206
   mBookmarks->BookmarkAdded(mCachedParent, childContent);    mBookmarks->BookmarkAdded(mCachedParent, 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
Line 405  nsIDocument* BookmarksService::gBookmark Line 449  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 413  nsVoidArray* BookmarksService::gInstance Line 458  nsVoidArray* BookmarksService::gInstance
   
 BookmarksService::BookmarksService(BookmarksDataSource* aDataSource)  BookmarksService::BookmarksService(BookmarksDataSource* aDataSource)
 {  {
    mDataSource = aDataSource;  mDataSource = aDataSource;
   mToolbar = nil;
 }
 
 BookmarksService::BookmarksService(BookmarksToolbar* aToolbar)
 {
   mDataSource = nil;
   mToolbar = aToolbar;
 }  }
   
 BookmarksService::~BookmarksService()  BookmarksService::~BookmarksService()
Line 458  BookmarksService::LocateMenu(nsIContent* Line 510  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 492  BookmarksService::BookmarkAdded(nsIConte Line 545  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 545  BookmarksService::BookmarkRemoved(nsICon Line 610  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 625  BookmarksService::FlushBookmarks() Line 700  BookmarksService::FlushBookmarks()
     domSerializer->SerializeToStream(domDoc, outputStream, nsnull);      domSerializer->SerializeToStream(domDoc, outputStream, nsnull);
 }  }
   
   void BookmarksService::EnsureToolbarRoot()
   {
     if (gToolbarRoot)
       return;
   
     nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(gBookmarks));
     nsCOMPtr<nsIDOMElement> rootElt;
     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;
     }
   }
   
 void  void
 BookmarksService::ConstructBookmarksMenu(NSMenu* aMenu, nsIContent* aContent)  BookmarksService::ConstructBookmarksMenu(NSMenu* aMenu, nsIContent* aContent)
 {  {

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


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