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

version 1.19, 2002/04/14 08:43:03 version 1.22, 2002/04/17 08:31:11
Line 60 Line 60
 {  {
     [super init];      [super init];
     mBookmarks = nsnull;      mBookmarks = nsnull;
       mCachedParent = nsnull;
       mCachedHref = nil;
     return self;      return self;
 }  }
   
 -(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 114 Line 116
     mBookmarks->GetRootContent(getter_AddRefs(content));      mBookmarks->GetRootContent(getter_AddRefs(content));
   
   nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(mBookmarks->gBookmarks));    nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(mBookmarks->gBookmarks));
  nsCOMPtr<nsIDOMElement> elt;  
  domDoc->CreateElementNS(NS_LITERAL_STRING("http://chimera.mozdev.org/bookmarks"), 
                          NS_LITERAL_STRING("bookmark"), 
                          getter_AddRefs(elt)); 
 
   // 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<nsIWebBrowser> webBrowser = getter_AddRefs([[[mBrowserWindowController getMyBrowserView] getBrowserView] getWebBrowser]);
   nsCOMPtr<nsIDOMWindow> window;    nsCOMPtr<nsIDOMWindow> window;
Line 136 Line 134
     href.AssignWithConversion(spec.get());      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));    nsCOMPtr<nsIDOMHTMLDocument> htmlDocument(do_QueryInterface(htmlDoc));
   if (htmlDocument)    if (htmlDocument)
     htmlDocument->GetTitle(title);      htmlDocument->GetTitle(title);
   if (title.IsEmpty())    if (title.IsEmpty())
     title = href;      title = href;
     
     NSTextField* textField = [mBrowserWindowController getAddBookmarkTitle];
     [textField setStringValue: [NSString stringWithCharacters: title.get() length: nsCRT::strlen(title.get())]];
   
     [mBrowserWindowController cacheBookmarkDS: self];
     
     [NSApp beginSheet:    [mBrowserWindowController getAddBookmarkSheetWindow]
        modalForWindow:    [mBrowserWindowController window]
         modalDelegate:    nil //self
        didEndSelector:    nil //@selector(sheetDidEnd:)
           contextInfo:    nil];
   }
   
   -(void)endAddBookmark: (int)aCode
   {
     if (aCode == 0)
       return;
     
     const char* titleC = [[[mBrowserWindowController getAddBookmarkTitle] stringValue] cString];
     nsAutoString title; title.AssignWithConversion(titleC);
   
     nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(mBookmarks->gBookmarks));
     nsCOMPtr<nsIDOMElement> elt;
     domDoc->CreateElementNS(NS_LITERAL_STRING("http://chimera.mozdev.org/bookmarks"),
                             NS_LITERAL_STRING("bookmark"),
                             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);    elt->SetAttribute(NS_LITERAL_STRING("href"), href);
   
  nsCOMPtr<nsIDOMElement> parent(do_QueryInterface(content));  nsCOMPtr<nsIDOMElement> parent(do_QueryInterface(mCachedParent));
   nsCOMPtr<nsIDOMNode> dummy;    nsCOMPtr<nsIDOMNode> dummy;
   parent->AppendChild(elt, getter_AddRefs(dummy));    parent->AppendChild(elt, getter_AddRefs(dummy));
   
   nsCOMPtr<nsIContent> childContent(do_QueryInterface(elt));    nsCOMPtr<nsIContent> childContent(do_QueryInterface(elt));
  mBookmarks->BookmarkAdded(content, childContent);  mBookmarks->BookmarkAdded(mCachedParent, childContent);
 }  }
   
 -(IBAction)deleteBookmark: (id)aSender  -(IBAction)deleteBookmark: (id)aSender
Line 373  nsIDocument* BookmarksService::gBookmark Line 405  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 381  nsVoidArray* BookmarksService::gInstance Line 414  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 593  BookmarksService::FlushBookmarks() Line 633  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.19  
changed lines
  Added in v.1.22


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