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

version 1.23, 2002/04/17 22:57:07 version 1.27, 2002/04/19 08:45:57
Line 60 Line 60
 {  {
     [super init];      [super init];
     mBookmarks = nsnull;      mBookmarks = nsnull;
     mCachedParent = nsnull;  
     mCachedHref = nil;      mCachedHref = nil;
     return self;      return self;
 }  }
Line 88 Line 87
           
     [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];
 }  }
   
-(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;
   
  nsCOMPtr<nsIContent> content;  BookmarkItem* item = nil;
   if (aUseSel) {    if (aUseSel) {
     int index = [mOutlineView selectedRow];      int index = [mOutlineView selectedRow];
   
     if (index >= 0) {      if (index >= 0) {
      BookmarkItem* item = [mOutlineView itemAtRow: index];      item = [mOutlineView itemAtRow: index];
      if ([mOutlineView isExpandable: item])      if ([mOutlineView numberOfSelectedRows] != 1 || ![mOutlineView isExpandable: item])
        content = [item contentNode];        item = nil;
     }      }
   }    }
   
   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]);  
   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())]];
   
   [mBrowserWindowController cacheBookmarkDS: self];    [mBrowserWindowController cacheBookmarkDS: self];
   
     // 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 166 Line 177
   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);
   }
 
   // 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
Line 697  void BookmarksService::EnsureToolbarRoot Line 756  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  void
 BookmarksService::ConstructBookmarksMenu(NSMenu* aMenu, nsIContent* aContent)  BookmarksService::ConstructBookmarksMenu(NSMenu* aMenu, nsIContent* aContent)
 {  {

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


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