File:  [mozdev] / chimera / BookmarksService.h
Revision 1.7: download - view: text, annotated - select for diffs - revision graph
Sun Feb 10 00:29:08 2002 UTC (15 years, 10 months ago) by hyatt
Branches: MAIN
CVS tags: HEAD
Bookmarks in the menu bar work!

/*
 *  BookmarksService.h
 *  Chimera
 *
 *  Created by David Hyatt on Thu Feb 07 2002.
 *  Copyright (c) 2001 __MyCompanyName__. All rights reserved.
 *
 */

#include <Appkit/Appkit.h>
#include <Carbon/Carbon.h>
#include "nsCOMPtr.h"
#include "nsIDocument.h"
#include "nsIDocumentObserver.h"
#include "nsVoidArray.h"
#import "MainController.h"

class BookmarksService;
class nsIAtom;

@interface BookmarksDataSource : NSObject
{
    BookmarksService* mBookmarks;
    IBOutlet id mOutlineView;
    IBOutlet id mBrowserView;
    IBOutlet id mAddButton;
    IBOutlet id mDeleteButton;
}

-(id) init;
-(void) dealloc;
-(void) windowClosing;

-(void) ensureBookmarks;

-(IBAction)addBookmark:(id)aSender;
-(IBAction)deleteBookmark: (id)aSender;

// Datasource methods.
- (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item;
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item;
- (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item;
- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item;
- (void)outlineView:(NSOutlineView *)outlineView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item;

- (void)reloadDataForItem:(id)item reloadChildren: (BOOL)aReloadChildren;

@end

@interface BookmarkItem : NSObject
{
    nsIContent* mContentNode;
}

-(nsIContent*)contentNode;
-(void)setContentNode: (nsIContent*)aContentNode;
- (id)copyWithZone:(NSZone *)aZone;
@end

class BookmarksService
{
public:
    BookmarksService(BookmarksDataSource* aDataSource);
    virtual ~BookmarksService();
    
    void AddObserver();
    void RemoveObserver();

    void NotifyObserver(nsIContent* aContainer, PRBool aReloadChildren);
    static void NotifyObservers(nsIContent* aContainer, PRBool aReloadChildren);

public:
    static void GetRootContent(nsIContent** aResult);
    static BookmarkItem* GetWrapperFor(nsIContent* aItem);
    static void FlushBookmarks();
    
    static void ConstructBookmarksMenu(NSMenu* aMenu, nsIContent* aContent);
    static void OpenMenuBookmark(BrowserWindowController* aController, id aMenuItem);
    
private:
    // Global counter and pointers to our singletons.
    static PRUint32 gRefCnt;
    
    // A dictionary that maps from content IDs (which uniquely identify content nodes)
    // to Obj-C bookmarkItem objects.  These objects are handed back to UI elements like
    // the outline view.
    static NSMutableDictionary* gDictionary;
        
public:
    static MainController* gMainController;
    static nsIAtom* gFolderAtom;
    static nsIAtom* gNameAtom;
    static nsIAtom* gHrefAtom;
    static nsIAtom* gBookmarkAtom;
    static nsIDocument* gBookmarks;
    static nsVoidArray* gInstances;
        
private:
    BookmarksDataSource* mDataSource;
};

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