File:  [mozdev] / chimera / BookmarksService.h
Revision 1.17: download - view: text, annotated - select for diffs - revision graph
Fri Apr 19 08:45:57 2002 UTC (17 years, 6 months ago) by hyatt
Branches: MAIN
CVS tags: HEAD
add support for additional keys to the outline view used by bookmarks.  adding delete support, return support, and left/right arrow support.

    1: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
    2: /* ***** BEGIN LICENSE BLOCK *****
    3:  * Version: NPL 1.1/GPL 2.0/LGPL 2.1
    4:  *
    5:  * The contents of this file are subject to the Netscape Public License
    6:  * Version 1.1 (the "License"); you may not use this file except in
    7:  * compliance with the License. You may obtain a copy of the License at
    8:  * http://www.mozilla.org/NPL/
    9:  *
   10:  * Software distributed under the License is distributed on an "AS IS" basis,
   11:  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
   12:  * for the specific language governing rights and limitations under the
   13:  * License.
   14:  *
   15:  * The Original Code is mozilla.org code.
   16:  *
   17:  * The Initial Developer of the Original Code is 
   18:  * Netscape Communications Corporation.
   19:  * Portions created by the Initial Developer are Copyright (C) 2002
   20:  * the Initial Developer. All Rights Reserved.
   21:  *
   22:  * Contributor(s):
   23:  *
   24:  * Alternatively, the contents of this file may be used under the terms of
   25:  * either the GNU General Public License Version 2 or later (the "GPL"), or 
   26:  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
   27:  * in which case the provisions of the GPL or the LGPL are applicable instead
   28:  * of those above. If you wish to allow use of your version of this file only
   29:  * under the terms of either the GPL or the LGPL, and not to allow others to
   30:  * use your version of this file under the terms of the NPL, indicate your
   31:  * decision by deleting the provisions above and replace them with the notice
   32:  * and other provisions required by the GPL or the LGPL. If you do not delete
   33:  * the provisions above, a recipient may use your version of this file under
   34:  * the terms of any one of the NPL, the GPL or the LGPL.
   35:  *
   36:  * ***** END LICENSE BLOCK ***** */
   37: 
   38: #include <Appkit/Appkit.h>
   39: #include <Carbon/Carbon.h>
   40: #include "nsCOMPtr.h"
   41: #include "nsIDocument.h"
   42: #include "nsIDocumentObserver.h"
   43: #include "nsVoidArray.h"
   44: #import "MainController.h"
   45: #import "BookmarksToolbar.h"
   46: #import "ExtendedOutlineView.h"
   47: 
   48: class BookmarksService;
   49: class nsIAtom;
   50: 
   51: @interface BookmarksDataSource : NSObject
   52: {
   53:   BookmarksService* mBookmarks;
   54: 
   55:   IBOutlet id mOutlineView;	
   56:   IBOutlet id mBrowserWindowController;
   57:   IBOutlet id mAddButton;	
   58:   IBOutlet id mDeleteButton;
   59: 
   60:   NSString* mCachedHref;
   61: }
   62: 
   63: -(id) init;
   64: -(void) dealloc;
   65: -(void) windowClosing;
   66: 
   67: -(void) ensureBookmarks;
   68: 
   69: -(IBAction)addBookmark:(id)aSender;
   70: -(void)endAddBookmark: (int)aCode;
   71: 
   72: -(IBAction)deleteBookmarks: (id)aSender;
   73: -(void)deleteBookmark: (id)aItem;
   74: 
   75: -(IBAction)addFolder:(id)aSender;
   76: 
   77: -(void)addBookmark:(id)aSender useSelection:(BOOL)aSel isFolder:(BOOL)aIsFolder;
   78: 
   79: // Datasource methods.
   80: - (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item;
   81: - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item;
   82: - (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item;
   83: - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item;
   84: - (void)outlineView:(NSOutlineView *)outlineView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item;
   85: 
   86: - (void)reloadDataForItem:(id)item reloadChildren: (BOOL)aReloadChildren;
   87: 
   88: @end
   89: 
   90: @interface BookmarkItem : NSObject
   91: {
   92:   nsIContent* mContentNode;
   93: }
   94: 
   95: -(nsIContent*)contentNode;
   96: -(void)setContentNode: (nsIContent*)aContentNode;
   97: - (id)copyWithZone:(NSZone *)aZone;
   98: @end
   99: 
  100: class BookmarksService
  101: {
  102: public:
  103:   BookmarksService(BookmarksDataSource* aDataSource);
  104:   BookmarksService(BookmarksToolbar* aToolbar);
  105:   virtual ~BookmarksService();
  106: 
  107:   void AddObserver();
  108:   void RemoveObserver();
  109: 
  110:   static void BookmarkAdded(nsIContent* aContainer, nsIContent* aChild);
  111:   static void BookmarkChanged(nsIContent* aItem);
  112:   static void BookmarkRemoved(nsIContent* aContainer, nsIContent* aChild);
  113:   
  114: public:
  115:   static void GetRootContent(nsIContent** aResult);
  116:   static BookmarkItem* GetWrapperFor(nsIContent* aItem);
  117:   static void FlushBookmarks();
  118: 
  119:   static void ConstructBookmarksMenu(NSMenu* aMenu, nsIContent* aContent);
  120:   static void OpenMenuBookmark(BrowserWindowController* aController, id aMenuItem);
  121:   static void AddMenuBookmark(NSMenu* aMenu, nsIContent* aParent, nsIContent* aChild, PRInt32 aIndex);
  122:   static NSMenu* LocateMenu(nsIContent* aContent);
  123: 
  124:   static void ConstructAddBookmarkFolderList(NSPopUpButton* aPopup, BookmarkItem* aItem);
  125:   
  126:   static void EnsureToolbarRoot();
  127:   
  128: public:
  129:   // Global counter and pointers to our singletons.
  130:   static PRUint32 gRefCnt;
  131: 
  132:   // A dictionary that maps from content IDs (which uniquely identify content nodes)
  133:   // to Obj-C bookmarkItem objects.  These objects are handed back to UI elements like
  134:   // the outline view.
  135:   static NSMutableDictionary* gDictionary;
  136:   static MainController* gMainController;
  137:   static NSMenu* gBookmarksMenu;
  138:   static nsIDOMElement* gToolbarRoot;
  139:   static nsIAtom* gFolderAtom;
  140:   static nsIAtom* gNameAtom;
  141:   static nsIAtom* gHrefAtom;
  142:   static nsIAtom* gBookmarkAtom;
  143:   static nsIDocument* gBookmarks;
  144:   static nsVoidArray* gInstances;
  145:   
  146: private:
  147:   // There are three kinds of bookmarks data sources:
  148:   // tree views (mDataSource), the personal toolbar (mToolbar)
  149:   // and menus (gBookmarksMenu).
  150:   BookmarksToolbar* mToolbar;
  151:   BookmarksDataSource* mDataSource;
  152: };

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