Diff for /chimera/BookmarksService.mm between versions 1.5 and 1.8

version 1.5, 2002/02/09 08:12:33 version 1.8, 2002/02/10 00:29:08
Line 20 Line 20
 #include "nsIFile.h"  #include "nsIFile.h"
 #include "nsAppDirectoryServiceDefs.h"  #include "nsAppDirectoryServiceDefs.h"
 #include "nsIXMLHttpRequest.h"  #include "nsIXMLHttpRequest.h"
   #include "nsIDOMSerializer.h"
 #include "nsNetUtil.h"  #include "nsNetUtil.h"
 #include "nsINamespaceManager.h"  #include "nsINamespaceManager.h"
 #include "nsIXBLService.h"  #include "nsIXBLService.h"
Line 68 Line 69
     nsCOMPtr<nsIContent> content;      nsCOMPtr<nsIContent> content;
     int index = [mOutlineView selectedRow];      int index = [mOutlineView selectedRow];
         
    if (index > 0) {    if (index >= 0) {
         BookmarkItem* item = [mOutlineView itemAtRow: index];          BookmarkItem* item = [mOutlineView itemAtRow: index];
         if ([mOutlineView isExpandable: item])           if ([mOutlineView isExpandable: item]) 
             content = [item contentNode];              content = [item contentNode];
Line 119 Line 120
   
 -(IBAction)deleteBookmark: (id)aSender  -(IBAction)deleteBookmark: (id)aSender
 {  {
       if (!mBookmarks)
           return;
       
       int index = [mOutlineView selectedRow];
       if (index == -1)
           return;
           
       BookmarkItem* item = [mOutlineView itemAtRow: index];
       nsCOMPtr<nsIContent> content = [item contentNode];
       nsCOMPtr<nsIDOMElement> child(do_QueryInterface(content));
       nsCOMPtr<nsIDOMNode> parent;
       child->GetParentNode(getter_AddRefs(parent));
       nsCOMPtr<nsIDOMNode> dummy;
       parent->RemoveChild(child, getter_AddRefs(dummy));
       nsCOMPtr<nsIContent> parentContent(do_QueryInterface(parent));
       mBookmarks->NotifyObservers(parentContent, PR_TRUE);
       
       int total = [mOutlineView numberOfRows];
       if (index == total)
           index--;
           
       [mOutlineView selectRow: index byExtendingSelection: NO];
 }  }
   
 -(IBAction)openBookmark: (id)aSender  -(IBAction)openBookmark: (id)aSender
Line 240 Line 263
 {  {
     mContentNode = aContentNode;      mContentNode = aContentNode;
 }  }
   
   - (id)copyWithZone:(NSZone *)aZone
   {
       BookmarkItem* copy = [[[self class] allocWithZone: aZone] init];
       [copy setContentNode: mContentNode];
       return copy;
   }
   
 @end  @end
   
 // Helper for stripping whitespace  // Helper for stripping whitespace
Line 270  StripWhitespaceNodes(nsIContent* aElemen Line 301  StripWhitespaceNodes(nsIContent* aElemen
 PRUint32 BookmarksService::gRefCnt = 0;  PRUint32 BookmarksService::gRefCnt = 0;
 nsIDocument* BookmarksService::gBookmarks = nsnull;  nsIDocument* BookmarksService::gBookmarks = nsnull;
 NSMutableDictionary* BookmarksService::gDictionary = nil;  NSMutableDictionary* BookmarksService::gDictionary = nil;
   MainController* BookmarksService::gMainController = nil;
 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 329  BookmarksService::NotifyObservers(nsICon Line 361  BookmarksService::NotifyObservers(nsICon
         BookmarksService* instance = (BookmarksService*)gInstances->ElementAt(i);          BookmarksService* instance = (BookmarksService*)gInstances->ElementAt(i);
         instance->NotifyObserver(aContainer, aReloadChildren);          instance->NotifyObserver(aContainer, aReloadChildren);
     }      }
       
       FlushBookmarks();
 }  }
   
   
Line 337  BookmarksService::NotifyObserver(nsICont Line 371  BookmarksService::NotifyObserver(nsICont
 {  {
     if (!gDictionary)      if (!gDictionary)
         return;          return;
          
    printf("uh. appended!\n"); 
     
     nsCOMPtr<nsIContent> parent;      nsCOMPtr<nsIContent> parent;
     aContainer->GetParent(*getter_AddRefs(parent));      aContainer->GetParent(*getter_AddRefs(parent));
           
Line 361  BookmarksService::AddObserver() Line 393  BookmarksService::AddObserver()
         gNameAtom = NS_NewAtom("name");          gNameAtom = NS_NewAtom("name");
         gHrefAtom = NS_NewAtom("href");          gHrefAtom = NS_NewAtom("href");
         gInstances = new nsVoidArray();          gInstances = new nsVoidArray();
                        
         nsCOMPtr<nsIFile> profileDir;          nsCOMPtr<nsIFile> profileDir;
         NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(profileDir));          NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(profileDir));
         profileDir->Append("bookmarks.xml");          profileDir->Append("bookmarks.xml");
Line 402  BookmarksService::RemoveObserver() Line 434  BookmarksService::RemoveObserver()
     }      }
 }  }
   
   void
   BookmarksService::FlushBookmarks()
   {
       nsCOMPtr<nsIFile> bookmarksFile;
       NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(bookmarksFile));
       bookmarksFile->Append("bookmarks.xml");
   
       nsCOMPtr<nsIOutputStream> outputStream;
       NS_NewLocalFileOutputStream(getter_AddRefs(outputStream), bookmarksFile);
   
       nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(gBookmarks));
       
       nsCOMPtr<nsIDOMSerializer> domSerializer(do_CreateInstance(NS_XMLSERIALIZER_CONTRACTID));
       domSerializer->SerializeToStream(domDoc, outputStream, nsnull);
   }
   
   void
   BookmarksService::ConstructBookmarksMenu(NSMenu* aMenu, nsIContent* aContent)
   {
       nsCOMPtr<nsIContent> content = aContent;
       if (!content) {
           GetRootContent(getter_AddRefs(content));
           GetWrapperFor(content);
       }
       
       // Now walk our children, and for folders also recur into them.
       PRInt32 childCount;
       content->ChildCount(childCount);
       
       for (PRInt32 i = 0; i < childCount; i++) {
           nsCOMPtr<nsIContent> child;
           content->ChildAt(i, *getter_AddRefs(child));
           
           // Obtain our name attribute.
           nsAutoString name;
           child->GetAttr(kNameSpaceID_None, gNameAtom, name);
           nsCAutoString nameCStr; nameCStr.AssignWithConversion(name);
           NSString* title = [NSString stringWithCString: nameCStr.get()];
                   
           // Create a menu or menu item for the child.
           NSMenuItem* menuItem = [[[NSMenuItem alloc] initWithTitle: title action: NULL keyEquivalent: @""] autorelease];
           GetWrapperFor(child);
           [aMenu addItem: menuItem];
           
           nsCOMPtr<nsIAtom> tag;
           child->GetTag(*getter_AddRefs(tag));
           
           if (tag == gFolderAtom) {
               NSMenu* menu = [[[NSMenu alloc] initWithTitle: title] autorelease];
               [aMenu setSubmenu: menu forItem: menuItem];
               [menu setAutoenablesItems: NO];
               ConstructBookmarksMenu(menu, child);
           }
           else {
               [menuItem setTarget: gMainController];
               [menuItem setAction: @selector(openMenuBookmark:)];
           }
           
           PRUint32 contentID;
           child->GetContentID(&contentID);
           [menuItem setTag: contentID];
       }
   }
   
   void 
   BookmarksService::OpenMenuBookmark(BrowserWindowController* aController, id aMenuItem)
   {
       // Get the corresponding bookmark item.
       BookmarkItem* item = [gDictionary objectForKey: [NSNumber numberWithInt: [aMenuItem tag]]];
           
       // Get the content node.
       nsIContent* content = [item contentNode];
           
       // Get the href attribute.  This is the URL we want to load.
       nsAutoString href;
       content->GetAttr(kNameSpaceID_None, gHrefAtom, href);
       nsCAutoString cref; cref.AssignWithConversion(href);
       if (cref.IsEmpty())
           return;
           
       NSString* url = [NSString stringWithCString: cref.get()];
       
       // Now load the URL in the window.
       [aController loadURL:[NSURL URLWithString: url]];
   }
   

Removed from v.1.5  
changed lines
  Added in v.1.8


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