Fix several bookmarks issues. Bug 154698 -- avoid nuking all existing bookmarks when importing a bad html bookmarks file. We now validate the imported bookmarks before saving, warn the user if they are bad, and don't import them. We also now validate the bookmarks.xml file when it is read in. Bug 154853 -- we were adding new items to the main bookmarks menu in the wrong place, since we failed to take the static items into account. Fixed.

This commit is contained in:
sfraser%netscape.com 2002-06-28 23:47:49 +00:00
Родитель f5aae179f6
Коммит 7972c4aa0a
70 изменённых файлов: 4892 добавлений и 3530 удалений

Просмотреть файл

@ -22,6 +22,8 @@
*/
#import "BookmarkInfoController.h"
#import "BookmarksDataSource.h"
#include "nsIContent.h"
#include "nsINamespaceManager.h"

Просмотреть файл

@ -0,0 +1,118 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Simon Fraser <sfraser@netscape.com>
*
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#import <Foundation/Foundation.h>
#import <Appkit/Appkit.h>
#import "MainController.h"
#import "CHBookmarksToolbar.h"
#import "CHExtendedOutlineView.h"
class nsIContent;
class BookmarksService;
@class BookmarkInfoController;
@interface BookmarksDataSource : NSObject
{
BookmarksService* mBookmarks;
IBOutlet id mOutlineView;
IBOutlet id mBrowserWindowController;
NSString* mCachedHref;
BookmarkInfoController* mBookmarkInfoController;
}
-(id) init;
-(void) dealloc;
-(void) windowClosing;
-(void) ensureBookmarks;
-(IBAction)addBookmark:(id)aSender;
-(void)endAddBookmark: (int)aCode;
-(IBAction)deleteBookmarks: (id)aSender;
-(void)deleteBookmark: (id)aItem;
-(IBAction)addFolder:(id)aSender;
-(void)addBookmark:(id)aSender useSelection:(BOOL)aSel isFolder:(BOOL)aIsFolder;
-(NSString*)resolveKeyword:(NSString*)aKeyword;
-(IBAction)openBookmarkInNewTab:(id)aSender;
-(IBAction)openBookmarkInNewWindow:(id)aSender;
-(void)openBookmarkGroup:(id)aTabView groupElement:(nsIDOMElement*)aFolder;
-(IBAction)showBookmarkInfo:(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;
- (BOOL)outlineView:(NSOutlineView *)ov writeItems:(NSArray*)items toPasteboard:(NSPasteboard*)pboard;
- (NSDragOperation)outlineView:(NSOutlineView*)ov validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(int)index;
- (BOOL)outlineView:(NSOutlineView*)ov acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(int)index;
- (void)reloadDataForItem:(id)item reloadChildren: (BOOL)aReloadChildren;
// Delegate methods
- (void)outlineViewItemWillExpand:(NSNotification *)notification;
- (void)outlineViewItemWillCollapse:(NSNotification *)notification;
@end
@interface BookmarkItem : NSObject
{
nsIContent* mContentNode;
}
- (nsIContent*)contentNode;
- (void)setContentNode: (nsIContent*)aContentNode;
- (NSNumber*)contentID;
- (id)copyWithZone:(NSZone *)aZone;
@end

Просмотреть файл

@ -0,0 +1,764 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Simon Fraser <sfraser@netscape.com>
*
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#import "BookmarksDataSource.h"
#import "BookmarkInfoController.h"
#include "nsCOMPtr.h"
#include "nsIContent.h"
#include "nsIDocument.h"
#include "nsIDocumentObserver.h"
#include "nsIDOMDocument.h"
#include "nsIDOMElement.h"
#include "nsINamespaceManager.h"
#include "nsIPrefBranch.h"
#include "nsIServiceManager.h"
#include "nsVoidArray.h"
#import "BookmarksService.h"
@implementation BookmarksDataSource
-(id) init
{
if ( (self = [super init]) ) {
mBookmarks = nsnull;
mCachedHref = nil;
}
return self;
}
-(void) dealloc
{
[mBookmarkInfoController release];
[super dealloc];
}
-(void) windowClosing
{
if (mBookmarks) {
mBookmarks->RemoveObserver();
delete mBookmarks;
}
}
-(void) ensureBookmarks
{
if (mBookmarks)
return;
mBookmarks = new BookmarksService(self);
mBookmarks->AddObserver();
[mOutlineView setTarget: self];
[mOutlineView setDoubleAction: @selector(openBookmark:)];
[mOutlineView setDeleteAction: @selector(deleteBookmarks:)];
[mOutlineView reloadData];
}
-(IBAction)addBookmark:(id)aSender
{
[self addBookmark: aSender useSelection: YES isFolder: NO];
}
-(IBAction)addFolder:(id)aSender
{
[self addBookmark: aSender useSelection: YES isFolder: YES];
}
-(void)addBookmark:(id)aSender useSelection:(BOOL)aUseSel isFolder:(BOOL)aIsFolder
{
if (!mBookmarks)
return;
// We use the selected item to determine the parent only if aUseSel is YES.
BookmarkItem* item = nil;
if (aUseSel && ([mOutlineView numberOfSelectedRows] == 1)) {
// There is only one selected row. If it is a folder, use it as our parent.
// Otherwise, use our parent,
int index = [mOutlineView selectedRow];
item = [mOutlineView itemAtRow: index];
if (![mOutlineView isExpandable: item]) {
// We can't be used as the parent. Try our parent.
nsIContent* content = [item contentNode];
if (!content)
return;
nsCOMPtr<nsIContent> parentContent;
content->GetParent(*getter_AddRefs(parentContent));
nsCOMPtr<nsIContent> root;
mBookmarks->GetRootContent(getter_AddRefs(root));
// The root has no item, so we don't need to do a lookup unless we
// aren't the root.
if (parentContent != root) {
PRUint32 contentID;
parentContent->GetContentID(&contentID);
item = [(BookmarksService::gDictionary) objectForKey: [NSNumber numberWithInt: contentID]];
}
}
}
nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(mBookmarks->gBookmarks));
// Fetch the title of the current page and the URL.
nsAutoString title, href;
if (!aIsFolder) {
BookmarksService::GetTitleAndHrefForBrowserView([[mBrowserWindowController getBrowserWrapper] getBrowserView],
title, href);
mCachedHref = [NSString stringWithCharacters: href.get() length: href.Length()];
[mCachedHref retain];
}
else {
mCachedHref = nil;
title = NS_LITERAL_STRING("New Folder");
}
NSTextField* textField = [mBrowserWindowController getAddBookmarkTitle];
[textField setStringValue: [NSString stringWithCharacters: title.get() length: title.Length()]];
[mBrowserWindowController cacheBookmarkDS: self];
// Show/hide the bookmark all tabs checkbox as appropriate.
NSTabView* tabView = [mBrowserWindowController getTabBrowser];
id checkbox = [mBrowserWindowController getAddBookmarkCheckbox];
BOOL hasSuperview = [checkbox superview] != nil;
if (aIsFolder && hasSuperview) {
// Just don't show it at all.
[checkbox removeFromSuperview];
[checkbox retain];
}
else if (!aIsFolder && !hasSuperview) {
// Put it back in.
[[[mBrowserWindowController getAddBookmarkSheetWindow] contentView] addSubview: checkbox];
[checkbox autorelease];
}
// Enable the bookmark all tabs checkbox if appropriate.
if (!aIsFolder)
[[mBrowserWindowController getAddBookmarkCheckbox] setEnabled: ([tabView numberOfTabViewItems] > 1)];
// Build up the folder list.
NSPopUpButton* popup = [mBrowserWindowController getAddBookmarkFolder];
BookmarksService::ConstructAddBookmarkFolderList(popup, item);
[NSApp beginSheet: [mBrowserWindowController getAddBookmarkSheetWindow]
modalForWindow: [mBrowserWindowController window]
modalDelegate: nil //self
didEndSelector: nil //@selector(sheetDidEnd:)
contextInfo: nil];
}
-(void)endAddBookmark: (int)aCode
{
if (aCode == 0)
return;
BOOL isGroup = NO;
id checkbox = [mBrowserWindowController getAddBookmarkCheckbox];
if (([checkbox superview] != nil) && [checkbox isEnabled] && ([checkbox state] == NSOnState)) {
mCachedHref = nil;
isGroup = YES;
}
const char* titleC = [[[mBrowserWindowController getAddBookmarkTitle] stringValue] cString];
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<nsIDOMElement> elt;
domDoc->CreateElementNS(NS_LITERAL_STRING("http://chimera.mozdev.org/bookmarks/"),
tagName,
getter_AddRefs(elt));
elt->SetAttribute(NS_LITERAL_STRING("name"), title);
if (mCachedHref) {
nsAutoString href; href.AssignWithConversion([mCachedHref cString]);
[mCachedHref release];
elt->SetAttribute(NS_LITERAL_STRING("href"), href);
}
if (isGroup) {
// We have to iterate over each tab and create content nodes using the
// title/href of all the pages. They are inserted underneath the parent.
elt->SetAttribute(NS_LITERAL_STRING("group"), NS_LITERAL_STRING("true"));
id tabBrowser = [mBrowserWindowController getTabBrowser];
int count = [tabBrowser numberOfTabViewItems];
for (int i = 0; i < count; i++) {
id browserView = [[[tabBrowser tabViewItemAtIndex: i] view] getBrowserView];
nsAutoString title, href;
BookmarksService::GetTitleAndHrefForBrowserView(browserView, title, href);
nsCOMPtr<nsIDOMElement> childElt;
domDoc->CreateElementNS(NS_LITERAL_STRING("http://chimera.mozdev.org/bookmarks/"),
NS_LITERAL_STRING("bookmark"),
getter_AddRefs(childElt));
childElt->SetAttribute(NS_LITERAL_STRING("name"), title);
childElt->SetAttribute(NS_LITERAL_STRING("href"), href);
nsCOMPtr<nsIDOMNode> dummy;
elt->AppendChild(childElt, getter_AddRefs(dummy));
}
}
// 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;
parentElt->AppendChild(elt, getter_AddRefs(dummy));
nsCOMPtr<nsIContent> childContent(do_QueryInterface(elt));
mBookmarks->BookmarkAdded(parentContent, childContent);
}
-(IBAction)deleteBookmarks: (id)aSender
{
if (!mBookmarks)
return;
int index = [mOutlineView selectedRow];
if (index == -1)
return;
// we'll run into problems if a parent item and one if its children are both selected.
// A cheap way of having to avoid scanning the list to remove children is to have the
// outliner collapse all items that are being deleted. This will cull the selection
// for us and eliminate any children that happened to be selected.
NSEnumerator* selRows = [mOutlineView selectedRowEnumerator];
for (NSNumber* currIndex = [selRows nextObject];
currIndex != nil;
currIndex = [selRows nextObject]) {
index = [currIndex intValue];
BookmarkItem* item = [mOutlineView itemAtRow: index];
[mOutlineView collapseItem: item];
}
// create array of items we need to delete. Deleting items out of of the
// selection array is problematic for some reason.
NSMutableArray* itemsToDelete = [[[NSMutableArray alloc] init] autorelease];
selRows = [mOutlineView selectedRowEnumerator];
for (NSNumber* currIndex = [selRows nextObject];
currIndex != nil;
currIndex = [selRows nextObject]) {
index = [currIndex intValue];
BookmarkItem* item = [mOutlineView itemAtRow: index];
[itemsToDelete addObject: item];
}
// delete all bookmarks that are in our array
int count = [itemsToDelete count];
for (int i = 0; i < count; i++) {
BookmarkItem* item = [itemsToDelete objectAtIndex: i];
[self deleteBookmark: item];
}
// restore selection to location near last item deleted
int total = [mOutlineView numberOfRows];
if (index == total)
index--;
[mOutlineView selectRow: index byExtendingSelection: NO];
}
-(void)deleteBookmark:(id)aItem
{
nsCOMPtr<nsIContent> content = [aItem contentNode];
nsCOMPtr<nsIDOMElement> child(do_QueryInterface(content));
if (!child)
return;
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;
if (parent)
parent->RemoveChild(child, getter_AddRefs(dummy));
mBookmarks->BookmarkRemoved(parentContent, content);
}
-(IBAction)openBookmark: (id)aSender
{
int index = [mOutlineView selectedRow];
if (index == -1)
return;
id item = [mOutlineView itemAtRow: index];
if (!item)
return;
nsIContent* content = [item contentNode];
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(content));
nsAutoString group;
content->GetAttr(kNameSpaceID_None, BookmarksService::gGroupAtom, group);
if (!group.IsEmpty())
mBookmarks->OpenBookmarkGroup([mBrowserWindowController getTabBrowser], elt);
else if ([mOutlineView isExpandable: item]) {
if ([mOutlineView isItemExpanded: item])
[mOutlineView collapseItem: item];
else
[mOutlineView expandItem: item];
}
else {
nsAutoString href;
content->GetAttr(kNameSpaceID_None, BookmarksService::gHrefAtom, href);
if (!href.IsEmpty()) {
NSString* url = [NSString stringWithCharacters: href.get() length: href.Length()];
[[[mBrowserWindowController getBrowserWrapper] getBrowserView] loadURI: url flags: NSLoadFlagsNone];
// Focus and activate our content area.
[[[mBrowserWindowController getBrowserWrapper] getBrowserView] setActive: YES];
}
}
}
-(NSString*) resolveKeyword: (NSString*) aKeyword
{
return BookmarksService::ResolveKeyword(aKeyword);
}
//
// outlineView:shouldEditTableColumn:item: (delegate method)
//
// Called by the outliner to determine whether or not we should allow the
// user to edit this item. For now, Cocoa doesn't correctly handle editing
// of attributed strings with icons, so we can't turn this on. :(
//
- (BOOL)outlineView:(NSOutlineView *)outlineView shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item
{
return NO;
}
- (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item
{
if (!mBookmarks)
return nil;
nsCOMPtr<nsIContent> content;
if (!item)
mBookmarks->GetRootContent(getter_AddRefs(content));
else
content = [item contentNode];
nsCOMPtr<nsIContent> child;
content->ChildAt(index, *getter_AddRefs(child));
if ( child )
return mBookmarks->GetWrapperFor(child);
return nil;
}
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
{
if (!mBookmarks)
return NO;
if (!item)
return YES; // The root node is always open.
nsCOMPtr<nsIAtom> tagName;
nsIContent* content = [item contentNode];
content->GetTag(*getter_AddRefs(tagName));
BOOL isExpandable = (tagName == BookmarksService::gFolderAtom);
// XXXben - persistence of folder open state
// I'm adding this code, turned off, until I can figure out how to refresh the NSOutlineView's
// row count. Currently the items are expanded, but the outline view continues to believe it had
// the number of rows it had before the item was opened visible, until the view is resized.
#if 0
if (isExpandable) {
PRBool isOpen = content->HasAttr(kNameSpaceID_None, BookmarksService::gOpenAtom);
if (isOpen)
[mOutlineView expandItem: item];
else
[mOutlineView collapseItem: item];
}
#endif
return isExpandable;
}
- (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
{
if (!mBookmarks)
return 0;
nsCOMPtr<nsIContent> content;
if (!item)
mBookmarks->GetRootContent(getter_AddRefs(content));
else
content = [item contentNode];
PRInt32 childCount;
content->ChildCount(childCount);
return childCount;
}
- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
{
NSString *columnName = [tableColumn identifier];
NSMutableAttributedString *cellValue = [[NSMutableAttributedString alloc] init];
NSFileWrapper *fileWrapper = [[NSFileWrapper alloc] initRegularFileWithContents:nil];
NSTextAttachment *textAttachment = [[NSTextAttachment alloc] initWithFileWrapper:fileWrapper];
NSMutableAttributedString *attachmentAttrString = nil;
NSCell *attachmentAttrStringCell;
if ([columnName isEqualToString: @"name"]) {
nsIContent* content = [item contentNode];
nsAutoString nameAttr;
content->GetAttr(kNameSpaceID_None, BookmarksService::gNameAtom, nameAttr);
//Set cell's textual contents
[cellValue replaceCharactersInRange:NSMakeRange(0, [cellValue length]) withString:[NSString stringWithCharacters: nameAttr.get() length: nameAttr.Length()]];
//Create an attributed string to hold the empty attachment, then release the components.
attachmentAttrString = [[NSMutableAttributedString attributedStringWithAttachment:textAttachment] retain];
[textAttachment release];
[fileWrapper release];
//Get the cell of the text attachment.
attachmentAttrStringCell = (NSCell *)[(NSTextAttachment *)[attachmentAttrString attribute:NSAttachmentAttributeName atIndex:0 effectiveRange:nil] attachmentCell];
//Figure out which image to add, and set the cell's image.
// Use the bookmark groups image for groups.
if ([self outlineView:outlineView isItemExpandable:item]) {
nsIContent* content = [item contentNode];
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(content));
nsAutoString group;
content->GetAttr(kNameSpaceID_None, BookmarksService::gGroupAtom, group);
if (!group.IsEmpty())
[attachmentAttrStringCell setImage:[NSImage imageNamed:@"groupbookmark"]];
else
[attachmentAttrStringCell setImage:[NSImage imageNamed:@"folder"]];
}
else
[attachmentAttrStringCell setImage:[NSImage imageNamed:@"smallbookmark"]];
//Insert the image
[cellValue replaceCharactersInRange:NSMakeRange(0, 0) withAttributedString:attachmentAttrString];
//Tweak the baseline to vertically center the text.
[cellValue addAttribute:NSBaselineOffsetAttributeName
value:[NSNumber numberWithFloat:-3.0]
range:NSMakeRange(0, 1)];
}
return cellValue;
}
- (void)outlineView:(NSOutlineView *)outlineView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
{
#if NOT_USED
// ignore all this. It doesn't work, but i'm leaving it here just in case we ever try to turn
// this code back on. We have to remove the attributes from the string in order to correctly
// set it in the DOM.
NSString *columnName = [tableColumn identifier];
if ( [columnName isEqualTo:@"name"] ) {
// remove the attributes
int strLen = [object length];
NSMutableAttributedString *cellValue = [[NSMutableAttributedString alloc] initWithAttributedString:object];
[cellValue removeAttribute:NSBaselineOffsetAttributeName range:NSMakeRange(0,1)];
[cellValue removeAttribute:NSAttachmentAttributeName range:NSMakeRange(0,strLen)];
// extract the unicode
strLen = [cellValue length];
PRUnichar* buffer = new PRUnichar[strLen + 1];
buffer[strLen] = '\0';
if ( !buffer )
return;
[cellValue getCharacters: buffer];
nsAutoString nameAttr;
nameAttr.Adopt(buffer);
// stash it into the dom.
nsIContent* content = [item contentNode];
content->SetAttr(kNameSpaceID_None, BookmarksService::gNameAtom, nameAttr, PR_TRUE);
[cellValue release];
}
#endif
}
- (BOOL)outlineView:(NSOutlineView *)ov writeItems:(NSArray*)items toPasteboard:(NSPasteboard*)pboard
{
if (!mBookmarks || [mOutlineView selectedRow] == -1) {
return NO;
}
#ifdef FILTER_DESCENDANT_ON_DRAG
NSArray *toDrag = BookmarksService::FilterOutDescendantsForDrag(items);
#else
NSArray *toDrag = items;
#endif
int count = [toDrag count];
if (count > 0) {
// Create Pasteboard Data
NSMutableArray *draggedID = [NSMutableArray arrayWithCapacity: count];
for (int i = 0; i < count; i++)
[draggedID addObject: [[toDrag objectAtIndex: i] contentID]];
[pboard declareTypes: [NSArray arrayWithObject: @"MozBookmarkType"] owner: self];
[pboard setPropertyList: draggedID forType: @"MozBookmarkType"];
return YES;
}
return NO;
}
- (NSDragOperation)outlineView:(NSOutlineView*)ov validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(int)index
{
NSArray* types = [[info draggingPasteboard] types];
// if the index is -1, deny the drop
if (index == NSOutlineViewDropOnItemIndex)
return NSDragOperationNone;
if ([types containsObject: @"MozBookmarkType"]) {
NSArray *draggedIDs = [[info draggingPasteboard] propertyListForType: @"MozBookmarkType"];
BookmarkItem* parent;
parent = (item) ? item : BookmarksService::GetRootItem();
return (BookmarksService::IsBookmarkDropValid(parent, index, draggedIDs)) ? NSDragOperationGeneric : NSDragOperationNone;
} else if ([types containsObject: @"MozURLType"]) {
return NSDragOperationGeneric;
}
return NSDragOperationNone;
}
- (BOOL)outlineView:(NSOutlineView*)ov acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(int)index {
NSArray *types = [[info draggingPasteboard] types];
BookmarkItem* parent = (item) ? item : BookmarksService::GetRootItem();
if ([types containsObject: @"MozBookmarkType"]) {
NSArray *draggedItems = [[info draggingPasteboard] propertyListForType: @"MozBookmarkType"];
BookmarksService::PerformBookmarkDrop(parent, index, draggedItems);
return YES;
}
else if ([types containsObject: @"MozURLType"]) {
NSDictionary* proxy = [[info draggingPasteboard] propertyListForType: @"MozURLType"];
BookmarkItem* beforeItem = [self outlineView:ov child:index ofItem:item];
return BookmarksService::PerformProxyDrop(parent, beforeItem, proxy);
}
return NO;
}
- (void)reloadDataForItem:(id)item reloadChildren: (BOOL)aReloadChildren
{
if (!item)
[mOutlineView reloadData];
else if ([mOutlineView isItemExpanded: item])
[mOutlineView reloadItem: item reloadChildren: aReloadChildren];
}
-(IBAction)openBookmarkInNewTab:(id)aSender
{
int index = [mOutlineView selectedRow];
if (index == -1)
return;
if ([mOutlineView numberOfSelectedRows] == 1) {
nsCOMPtr<nsIPrefBranch> pref(do_GetService("@mozilla.org/preferences-service;1"));
if (!pref)
return; // Something bad happened if we can't get prefs.
BookmarkItem* item = [mOutlineView itemAtRow: index];
nsAutoString hrefAttr;
[item contentNode]->GetAttr(kNameSpaceID_None, BookmarksService::gHrefAtom, hrefAttr);
// stuff it into the string
NSString* hrefStr = [NSString stringWithCharacters:hrefAttr.get() length:hrefAttr.Length()];
PRBool loadInBackground;
pref->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground);
[mBrowserWindowController openNewTabWithURL: hrefStr loadInBackground: loadInBackground];
}
}
-(IBAction)openBookmarkInNewWindow:(id)aSender
{
int index = [mOutlineView selectedRow];
if (index == -1)
return;
if ([mOutlineView numberOfSelectedRows] == 1) {
BookmarkItem* item = [mOutlineView itemAtRow: index];
nsAutoString hrefAttr;
[item contentNode]->GetAttr(kNameSpaceID_None, BookmarksService::gHrefAtom, hrefAttr);
// stuff it into the string
NSString* hrefStr = [NSString stringWithCharacters:hrefAttr.get() length:hrefAttr.Length()];
nsAutoString group;
[item contentNode]->GetAttr(kNameSpaceID_None, BookmarksService::gGroupAtom, group);
if (group.IsEmpty())
[mBrowserWindowController openNewWindowWithURL: hrefStr loadInBackground: NO];
else {
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface([item contentNode]));
[mBrowserWindowController openNewWindowWithGroup: elt loadInBackground: NO];
}
}
}
-(void)openBookmarkGroup:(id)aTabView groupElement:(nsIDOMElement*)aFolder
{
mBookmarks->OpenBookmarkGroup(aTabView, aFolder);
}
-(IBAction)showBookmarkInfo:(id)aSender
{
if (!mBookmarkInfoController)
mBookmarkInfoController = [[BookmarkInfoController alloc] initWithOutlineView: mOutlineView];
[mBookmarkInfoController showWindow:mBookmarkInfoController];
int index = [mOutlineView selectedRow];
BookmarkItem* item = [mOutlineView itemAtRow: index];
[mBookmarkInfoController setBookmark:item];
}
-(void)outlineViewSelectionDidChange: (NSNotification*) aNotification
{
int index = [mOutlineView selectedRow];
if (index == -1) {
if (mBookmarkInfoController)
[mBookmarkInfoController setBookmark:NULL];
}
else {
BookmarkItem* item = [mOutlineView itemAtRow:index];
if (mBookmarkInfoController)
[mBookmarkInfoController setBookmark:item];
}
}
-(BOOL)validateMenuItem:(NSMenuItem*)aMenuItem
{
int index = [mOutlineView selectedRow];
if (index == -1)
return NO;
BookmarkItem* item = [mOutlineView itemAtRow: index];
BOOL isBookmark = [mOutlineView isExpandable:item] == NO;
nsAutoString group;
[item contentNode]->GetAttr(kNameSpaceID_None, BookmarksService::gGroupAtom, group);
BOOL isGroup = !group.IsEmpty();
if (([aMenuItem action] == @selector(openBookmarkInNewWindow:))) {
// Bookmarks and Bookmark Groups can be opened in a new window
return (isBookmark || isGroup);
}
else if (([aMenuItem action] == @selector(openBookmarkInNewTab:))) {
// Only Bookmarks can be opened in new tabs
return isBookmark;
}
return YES;
}
- (void)outlineViewItemWillExpand:(NSNotification *)notification
{
BookmarkItem* item = [[notification userInfo] objectForKey:[[[notification userInfo] allKeys] objectAtIndex: 0]];
[item contentNode]->SetAttr(kNameSpaceID_None, BookmarksService::gOpenAtom, NS_LITERAL_STRING("true"), PR_FALSE);
}
- (void)outlineViewItemWillCollapse:(NSNotification *)notification
{
BookmarkItem* item = [[notification userInfo] objectForKey:[[[notification userInfo] allKeys] objectAtIndex: 0]];
[item contentNode]->UnsetAttr(kNameSpaceID_None, BookmarksService::gOpenAtom, PR_FALSE);
}
@end
@implementation BookmarkItem
-(nsIContent*)contentNode
{
return mContentNode;
}
- (NSNumber*)contentID
{
PRUint32 contentID = 0;
mContentNode->GetContentID(&contentID);
return [NSNumber numberWithInt: contentID];
}
- (NSString *)description
{
nsCOMPtr<nsIContent> item = [self contentNode];
nsCOMPtr<nsIDOMElement> element(do_QueryInterface(item));
nsAutoString href;
element->GetAttribute(NS_LITERAL_STRING("name"), href);
NSString* info = [NSString stringWithCharacters: href.get() length: href.Length()];
return [NSString stringWithFormat:@"<BookmarkItem, name = \"%@\">", info];
}
-(void)setContentNode: (nsIContent*)aContentNode
{
mContentNode = aContentNode;
}
- (id)copyWithZone:(NSZone *)aZone
{
BookmarkItem* copy = [[[self class] allocWithZone: aZone] init];
[copy setContentNode: mContentNode];
return copy;
}
@end

Просмотреть файл

@ -37,88 +37,22 @@
#include <Appkit/Appkit.h>
#include <Carbon/Carbon.h>
#include "nsCOMPtr.h"
#include "nsIDocument.h"
#include "nsIDocumentObserver.h"
#include "nsVoidArray.h"
#import "MainController.h"
#import "CHBookmarksToolbar.h"
#import "CHExtendedOutlineView.h"
@class BookmarkItem;
class BookmarksService;
class nsIAtom;
@class BookmarkInfoController;
@interface BookmarksDataSource : NSObject
{
BookmarksService* mBookmarks;
IBOutlet id mOutlineView;
IBOutlet id mBrowserWindowController;
NSString* mCachedHref;
BookmarkInfoController* mBookmarkInfoController;
}
-(id) init;
-(void) dealloc;
-(void) windowClosing;
-(void) ensureBookmarks;
-(IBAction)addBookmark:(id)aSender;
-(void)endAddBookmark: (int)aCode;
-(IBAction)deleteBookmarks: (id)aSender;
-(void)deleteBookmark: (id)aItem;
-(IBAction)addFolder:(id)aSender;
-(void)addBookmark:(id)aSender useSelection:(BOOL)aSel isFolder:(BOOL)aIsFolder;
-(NSString*)resolveKeyword:(NSString*)aKeyword;
-(IBAction)openBookmarkInNewTab:(id)aSender;
-(IBAction)openBookmarkInNewWindow:(id)aSender;
-(void)openBookmarkGroup:(id)aTabView groupElement:(nsIDOMElement*)aFolder;
-(IBAction)showBookmarkInfo:(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;
- (BOOL)outlineView:(NSOutlineView *)ov writeItems:(NSArray*)items toPasteboard:(NSPasteboard*)pboard;
- (NSDragOperation)outlineView:(NSOutlineView*)ov validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(int)index;
- (BOOL)outlineView:(NSOutlineView*)ov acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(int)index;
- (void)reloadDataForItem:(id)item reloadChildren: (BOOL)aReloadChildren;
// Delegate methods
- (void)outlineViewItemWillExpand:(NSNotification *)notification;
- (void)outlineViewItemWillCollapse:(NSNotification *)notification;
@end
@interface BookmarkItem : NSObject
{
nsIContent* mContentNode;
}
- (nsIContent*)contentNode;
- (void)setContentNode: (nsIContent*)aContentNode;
- (NSNumber*)contentID;
- (id)copyWithZone:(NSZone *)aZone;
@end
class nsIDOMHTMLDocument;
@class BookmarksDataSource;
@class BookmarkItem;
class BookmarksService
{
public:
@ -142,6 +76,8 @@ public:
static BookmarkItem* GetRootItem();
static BookmarkItem* GetWrapperFor(nsIContent* aItem);
static BookmarkItem* GetWrapperFor(PRUint32 contentID);
static void ReadBookmarks();
static void FlushBookmarks();
static void ConstructBookmarksMenu(NSMenu* aMenu, nsIContent* aContent);
@ -189,6 +125,7 @@ public:
static nsIAtom* gOpenAtom;
static nsIAtom* gGroupAtom;
static nsIDocument* gBookmarks;
static BOOL gBookmarksFileReadOK;
static nsVoidArray* gInstances;
static int CHInsertNone;
static int CHInsertInto;

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -584,6 +584,9 @@ static NSString *SearchToolbarItemIdentifier = @"Search Toolbar Item";
[newView setIsBookmarksImport: YES];
[[[self window] contentView] addSubview: newView];
[[newView getBrowserView] loadURI:aURLSpec flags:NSLoadFlagsNone];
// XXX force reload
//[mSidebarBookmarksDataSource reloadDataForItem: nil reloadChildren: YES];
}
- (IBAction)goToLocationFromToolbarURLField:(id)sender

Просмотреть файл

@ -23,6 +23,8 @@
#import "CHBookmarksOutlineView.h"
#import "BookmarksService.h"
#import "BookmarksDataSource.h"
#include "nsCOMPtr.h"
#include "nsIDOMElement.h"
#include "nsIContent.h"

Просмотреть файл

@ -25,6 +25,8 @@
#import "CHBookmarksButton.h"
#import "CHBookmarksToolbar.h"
#import "BookmarksService.h"
#import "BookmarksDataSource.h"
#include "nsIDOMElement.h"
#include "nsIContent.h"

Просмотреть файл

@ -17,6 +17,8 @@
#import "CHExtendedTabView.h"
#import "BookmarksService.h"
#import "BookmarksDataSource.h"
#include "nsCOMPtr.h"
#include "nsIDOMElement.h"
#include "nsIContent.h"

Просмотреть файл

@ -7,6 +7,9 @@
objects = {
080E96DDFE201D6D7F000001 = {
children = (
F5A3669402CCFAF601DC3354,
F5A3669602CCFAF601DC3354,
F5A3669702CCFAF601DC3354,
F5DE10E90209DC0601A967DF,
F517395B020CE3740189DA0C,
F528E21A020FD9620168DE43,
@ -18,18 +21,10 @@
F52D5CD8027D3D5001A80166,
F6BA6D4E01B2F8A601A962F7,
F56769FB0208F74A010001CA,
F507BA4C0213AFF701D93544,
F57074B6026BA85F01A80166,
F57074BA026BFD0101A80166,
F57074BE026D80DF01A80166,
2E2939FF027F33604B000102,
F59E9F3F0237E43401A967DF,
F52D5CD0027A887001A80166,
F52D5CD4027A88C601A80166,
F52F87CD027D75C301A80165,
F52F87CE027D75C301A80165,
2E748B73029A448D4B000102,
F53E012C02AEE93601A967F3,
);
isa = PBXGroup;
name = Classes;
@ -452,6 +447,7 @@
F53E013302AEEA2901A967F3,
F632AF8502B9AEBB01000103,
F59236C202C89ACA0100012B,
F5A3669802CCFAF601DC3354,
);
isa = PBXHeadersBuildPhase;
name = Headers;
@ -538,6 +534,7 @@
F517395D020CE3750189DA0C,
F528E21B020FD9620168DE43,
F507BA4D0213AFF701D93544,
F5A3669902CCFAF601DC3354,
F53F220E022B7C78010001CA,
F53F220F022B7C78010001CA,
F53F2210022B7C78010001CA,
@ -646,13 +643,6 @@
settings = {
};
};
2EEC3E6002810B184B000102 = {
indentWidth = 2;
isa = PBXFileReference;
path = CHExtendedTabView.m;
refType = 4;
usesTabs = 0;
};
2EEC3E61028138714B000102 = {
isa = PBXFileReference;
path = CHBookmarksOutlineView.h;
@ -948,6 +938,8 @@
};
F50E1BC90207F99201F281DF = {
children = (
F5C321D402CBD01C014E7D56,
F5C321D002CBCEF7014E7D56,
F50E1BCA0207F99201F281DF,
F51D9B0A020940C101A80166,
);
@ -1216,6 +1208,7 @@
2E748B72029A448D4B000102,
F53E012902AEE91C01A967F3,
F53E013202AEEA2801A967F3,
F5A3669302CCFAF601DC3354,
);
isa = PBXGroup;
name = Headers;
@ -1287,6 +1280,7 @@
children = (
F51D9B0B020940C101A80166,
F51D9B0D0209421401A80166,
F5C321D702CBD0CE014E7D56,
);
isa = PBXGroup;
name = xul;
@ -2681,14 +2675,11 @@
F5571935022B401B010001CA = {
children = (
F5BF71450231B8BC010001CA,
2EEC3E6002810B184B000102,
F5BF71460231B8BC010001CA,
F5648739023C3857010001CA,
F564873A023C3857010001CA,
F5C3AB810270072A01A80166,
F5C3AB820270072A01A80166,
2EEC3E61028138714B000102,
2EEC3E62028138714B000102,
F541495A02711A8301A80166,
F541495B02711A8301A80166,
F541495E02711B0001A80166,
@ -4183,6 +4174,79 @@
settings = {
};
};
F5A3669302CCFAF601DC3354 = {
isa = PBXFileReference;
path = BookmarksDataSource.h;
refType = 4;
};
F5A3669402CCFAF601DC3354 = {
children = (
F507BA4C0213AFF701D93544,
F5A3669502CCFAF601DC3354,
F57074B6026BA85F01A80166,
F57074BA026BFD0101A80166,
F53E012C02AEE93601A967F3,
2EEC3E61028138714B000102,
2EEC3E62028138714B000102,
);
isa = PBXGroup;
name = Bookmarks;
refType = 4;
};
F5A3669502CCFAF601DC3354 = {
isa = PBXFileReference;
path = BookmarksDataSource.mm;
refType = 4;
};
F5A3669602CCFAF601DC3354 = {
children = (
F52F87CD027D75C301A80165,
F52F87CE027D75C301A80165,
);
isa = PBXGroup;
name = History;
path = "";
refType = 4;
};
F5A3669702CCFAF601DC3354 = {
children = (
F52D5CD0027A887001A80166,
F52D5CD4027A88C601A80166,
);
isa = PBXGroup;
name = Autocomplete;
refType = 4;
};
F5A3669802CCFAF601DC3354 = {
fileRef = F5A3669302CCFAF601DC3354;
isa = PBXBuildFile;
settings = {
};
};
F5A3669902CCFAF601DC3354 = {
fileRef = F5A3669502CCFAF601DC3354;
isa = PBXBuildFile;
settings = {
};
};
F5A3669A02CCFB7A01DC3354 = {
fileRef = F5A3669302CCFAF601DC3354;
isa = PBXBuildFile;
settings = {
};
};
F5A3669B02CCFB7A01DC3354 = {
fileRef = F632AF8402B9AEBB01000103;
isa = PBXBuildFile;
settings = {
};
};
F5A3669C02CCFB7A01DC3354 = {
fileRef = F5A3669502CCFAF601DC3354;
isa = PBXBuildFile;
settings = {
};
};
F5AC38BA02AD8E7B01A967F3 = {
fileRef = F5C2CDA702383CE601A967DF;
isa = PBXBuildFile;
@ -4426,6 +4490,7 @@
F53E012B02AEE91D01A967F3,
F53E013402AEEA2901A967F3,
F59236C402C89ACA0100012B,
F5A3669A02CCFB7A01DC3354,
);
isa = PBXHeadersBuildPhase;
name = Headers;
@ -4538,6 +4603,8 @@
F56F242102AC6D0401A967F3,
F53E012E02AEE93701A967F3,
F59236C502C89ACA0100012B,
F5A3669B02CCFB7A01DC3354,
F5A3669C02CCFB7A01DC3354,
);
isa = PBXSourcesBuildPhase;
name = Sources;
@ -6259,6 +6326,24 @@
settings = {
};
};
F5C321D002CBCEF7014E7D56 = {
isa = PBXFileReference;
name = nsXBLService.cpp;
path = /Volumes/Development/Projects/Mozilla/Chimera/mozilla/content/xbl/src/nsXBLService.cpp;
refType = 0;
};
F5C321D402CBD01C014E7D56 = {
isa = PBXFileReference;
name = xmlparse.c;
path = /Volumes/Development/Projects/Mozilla/Chimera/mozilla/expat/xmlparse/xmlparse.c;
refType = 0;
};
F5C321D702CBD0CE014E7D56 = {
isa = PBXFileReference;
name = nsXMLContentSink.cpp;
path = /Volumes/Development/Projects/Mozilla/Chimera/mozilla/content/xml/document/src/nsXMLContentSink.cpp;
refType = 0;
};
F5C3AB810270072A01A80166 = {
isa = PBXFileReference;
path = CHExtendedOutlineView.h;

Двоичные данные
camino/English.lproj/Localizable.strings

Двоичный файл не отображается.

4
camino/English.lproj/MainMenu.nib/info.nib сгенерированный
Просмотреть файл

@ -3,13 +3,13 @@
<plist version="0.9">
<dict>
<key>IBDocumentLocation</key>
<string>85 201 356 240 0 0 1280 1002 </string>
<string>73 133 356 240 0 0 1152 746 </string>
<key>IBEditorPositions</key>
<dict>
<key>266</key>
<string>418 452 277 90 0 0 1152 746 </string>
<key>29</key>
<string>11 957 446 44 0 0 1280 1002 </string>
<string>9 701 446 44 0 0 1152 746 </string>
</dict>
<key>IBFramework Version</key>
<string>248.0</string>

Двоичные данные
camino/English.lproj/MainMenu.nib/objects.nib сгенерированный

Двоичный файл не отображается.

4
camino/MainMenu.nib/info.nib сгенерированный
Просмотреть файл

@ -3,13 +3,13 @@
<plist version="0.9">
<dict>
<key>IBDocumentLocation</key>
<string>85 201 356 240 0 0 1280 1002 </string>
<string>73 133 356 240 0 0 1152 746 </string>
<key>IBEditorPositions</key>
<dict>
<key>266</key>
<string>418 452 277 90 0 0 1152 746 </string>
<key>29</key>
<string>11 957 446 44 0 0 1280 1002 </string>
<string>9 701 446 44 0 0 1152 746 </string>
</dict>
<key>IBFramework Version</key>
<string>248.0</string>

Двоичные данные
camino/MainMenu.nib/objects.nib сгенерированный

Двоичный файл не отображается.

Просмотреть файл

@ -16,6 +16,7 @@
ACTIONS = {
checkboxClicked = id;
checkboxStartPageClicked = id;
checkboxUseSystemHomePageClicked = id;
clearGlobalHistory = id;
historyDaysModified = id;
openSystemInternetPanel = id;
@ -23,12 +24,13 @@
CLASS = OrgMozillaChimeraPreferenceNavigation;
LANGUAGE = ObjC;
OUTLETS = {
buttonSystemPreferences = NSButton;
checkboxNewTabBlank = NSButton;
checkboxNewWindowBlank = NSButton;
checkboxOpenTabs = NSButton;
checkboxUseSystemHomePage = NSButton;
sliderHistoryDays = NSSlider;
textFieldHistoryDays = NSTextField;
textFieldHomePage = NSTextField;
};
SUPERCLASS = NSPreferencePane;
}

Просмотреть файл

@ -3,7 +3,7 @@
<plist version="0.9">
<dict>
<key>IBDocumentLocation</key>
<string>56 65 356 240 0 0 1152 848 </string>
<string>36 50 356 240 0 0 1152 746 </string>
<key>IBFramework Version</key>
<string>248.0</string>
<key>IBGroupedObjects</key>
@ -22,6 +22,6 @@
<integer>5</integer>
</array>
<key>IBSystem Version</key>
<string>5Q125</string>
<string>5S66</string>
</dict>
</plist>

Двоичные данные
camino/PreferencePanes/Navigation/English.lproj/Navigation.nib/objects.nib сгенерированный

Двоичный файл не отображается.

Просмотреть файл

@ -28,7 +28,9 @@ class nsIPref;
@interface OrgMozillaChimeraPreferenceNavigation : NSPreferencePane
{
IBOutlet NSButton *buttonSystemPreferences;
// IBOutlet NSButton *buttonSystemPreferences;
IBOutlet NSTextField *textFieldHomePage;
IBOutlet NSButton *checkboxUseSystemHomePage;
IBOutlet NSButton *checkboxNewTabBlank;
IBOutlet NSButton *checkboxNewWindowBlank;
IBOutlet NSButton *checkboxOpenTabs;
@ -37,9 +39,12 @@ class nsIPref;
nsIPref* mPrefService; // strong, but can't use a comptr here
}
- (IBAction)openSystemInternetPanel:(id)sender;
- (IBAction)checkboxClicked:(id)sender;
- (IBAction)checkboxUseSystemHomePageClicked:(id)sender;
- (IBAction)checkboxStartPageClicked:(id)sender;
- (IBAction)historyDaysModified:(id)sender;
- (IBAction)clearGlobalHistory:(id)sender;
@end

Просмотреть файл

@ -74,6 +74,15 @@ const int kDefaultExpireDays = 9;
rv = mPrefService->GetBoolPref("browser.tabs.opentabfor.middleclick", &boolPref);
if (NS_SUCCEEDED(rv) && boolPref == PR_TRUE)
[checkboxOpenTabs setState:YES];
char *buf = nsnull;
rv = mPrefService->GetCharPref("browser.startup.homepage", &buf);
if (NS_SUCCEEDED(rv) && buf)
{
[textFieldHomePage setStringValue:[NSString stringWithCString:buf]];
free(buf);
}
}
- (IBAction)openSystemInternetPanel:(id)sender
@ -92,6 +101,11 @@ const int kDefaultExpireDays = 9;
mPrefService->SetBoolPref("browser.tabs.opentabfor.middleclick", [sender state] ? PR_TRUE : PR_FALSE);
}
- (IBAction)checkboxUseSystemHomePageClicked:(id)sender
{
NSLog(@"Homepage clicked");
}
- (IBAction)checkboxStartPageClicked:(id)sender
{
if (!mPrefService)

Просмотреть файл

@ -16,6 +16,7 @@
ACTIONS = {
checkboxClicked = id;
checkboxStartPageClicked = id;
checkboxUseSystemHomePageClicked = id;
clearGlobalHistory = id;
historyDaysModified = id;
openSystemInternetPanel = id;
@ -23,12 +24,13 @@
CLASS = OrgMozillaChimeraPreferenceNavigation;
LANGUAGE = ObjC;
OUTLETS = {
buttonSystemPreferences = NSButton;
checkboxNewTabBlank = NSButton;
checkboxNewWindowBlank = NSButton;
checkboxOpenTabs = NSButton;
checkboxUseSystemHomePage = NSButton;
sliderHistoryDays = NSSlider;
textFieldHistoryDays = NSTextField;
textFieldHomePage = NSTextField;
};
SUPERCLASS = NSPreferencePane;
}

Просмотреть файл

@ -3,7 +3,7 @@
<plist version="0.9">
<dict>
<key>IBDocumentLocation</key>
<string>56 65 356 240 0 0 1152 848 </string>
<string>36 50 356 240 0 0 1152 746 </string>
<key>IBFramework Version</key>
<string>248.0</string>
<key>IBGroupedObjects</key>
@ -22,6 +22,6 @@
<integer>5</integer>
</array>
<key>IBSystem Version</key>
<string>5Q125</string>
<string>5S66</string>
</dict>
</plist>

Двоичные данные
camino/PreferencePanes/Navigation/Navigation.nib/objects.nib сгенерированный

Двоичный файл не отображается.

Просмотреть файл

@ -7,6 +7,9 @@
objects = {
080E96DDFE201D6D7F000001 = {
children = (
F5A3669402CCFAF601DC3354,
F5A3669602CCFAF601DC3354,
F5A3669702CCFAF601DC3354,
F5DE10E90209DC0601A967DF,
F517395B020CE3740189DA0C,
F528E21A020FD9620168DE43,
@ -18,18 +21,10 @@
F52D5CD8027D3D5001A80166,
F6BA6D4E01B2F8A601A962F7,
F56769FB0208F74A010001CA,
F507BA4C0213AFF701D93544,
F57074B6026BA85F01A80166,
F57074BA026BFD0101A80166,
F57074BE026D80DF01A80166,
2E2939FF027F33604B000102,
F59E9F3F0237E43401A967DF,
F52D5CD0027A887001A80166,
F52D5CD4027A88C601A80166,
F52F87CD027D75C301A80165,
F52F87CE027D75C301A80165,
2E748B73029A448D4B000102,
F53E012C02AEE93601A967F3,
);
isa = PBXGroup;
name = Classes;
@ -452,6 +447,7 @@
F53E013302AEEA2901A967F3,
F632AF8502B9AEBB01000103,
F59236C202C89ACA0100012B,
F5A3669802CCFAF601DC3354,
);
isa = PBXHeadersBuildPhase;
name = Headers;
@ -538,6 +534,7 @@
F517395D020CE3750189DA0C,
F528E21B020FD9620168DE43,
F507BA4D0213AFF701D93544,
F5A3669902CCFAF601DC3354,
F53F220E022B7C78010001CA,
F53F220F022B7C78010001CA,
F53F2210022B7C78010001CA,
@ -646,13 +643,6 @@
settings = {
};
};
2EEC3E6002810B184B000102 = {
indentWidth = 2;
isa = PBXFileReference;
path = CHExtendedTabView.m;
refType = 4;
usesTabs = 0;
};
2EEC3E61028138714B000102 = {
isa = PBXFileReference;
path = CHBookmarksOutlineView.h;
@ -948,6 +938,8 @@
};
F50E1BC90207F99201F281DF = {
children = (
F5C321D402CBD01C014E7D56,
F5C321D002CBCEF7014E7D56,
F50E1BCA0207F99201F281DF,
F51D9B0A020940C101A80166,
);
@ -1216,6 +1208,7 @@
2E748B72029A448D4B000102,
F53E012902AEE91C01A967F3,
F53E013202AEEA2801A967F3,
F5A3669302CCFAF601DC3354,
);
isa = PBXGroup;
name = Headers;
@ -1287,6 +1280,7 @@
children = (
F51D9B0B020940C101A80166,
F51D9B0D0209421401A80166,
F5C321D702CBD0CE014E7D56,
);
isa = PBXGroup;
name = xul;
@ -2681,14 +2675,11 @@
F5571935022B401B010001CA = {
children = (
F5BF71450231B8BC010001CA,
2EEC3E6002810B184B000102,
F5BF71460231B8BC010001CA,
F5648739023C3857010001CA,
F564873A023C3857010001CA,
F5C3AB810270072A01A80166,
F5C3AB820270072A01A80166,
2EEC3E61028138714B000102,
2EEC3E62028138714B000102,
F541495A02711A8301A80166,
F541495B02711A8301A80166,
F541495E02711B0001A80166,
@ -4183,6 +4174,79 @@
settings = {
};
};
F5A3669302CCFAF601DC3354 = {
isa = PBXFileReference;
path = BookmarksDataSource.h;
refType = 4;
};
F5A3669402CCFAF601DC3354 = {
children = (
F507BA4C0213AFF701D93544,
F5A3669502CCFAF601DC3354,
F57074B6026BA85F01A80166,
F57074BA026BFD0101A80166,
F53E012C02AEE93601A967F3,
2EEC3E61028138714B000102,
2EEC3E62028138714B000102,
);
isa = PBXGroup;
name = Bookmarks;
refType = 4;
};
F5A3669502CCFAF601DC3354 = {
isa = PBXFileReference;
path = BookmarksDataSource.mm;
refType = 4;
};
F5A3669602CCFAF601DC3354 = {
children = (
F52F87CD027D75C301A80165,
F52F87CE027D75C301A80165,
);
isa = PBXGroup;
name = History;
path = "";
refType = 4;
};
F5A3669702CCFAF601DC3354 = {
children = (
F52D5CD0027A887001A80166,
F52D5CD4027A88C601A80166,
);
isa = PBXGroup;
name = Autocomplete;
refType = 4;
};
F5A3669802CCFAF601DC3354 = {
fileRef = F5A3669302CCFAF601DC3354;
isa = PBXBuildFile;
settings = {
};
};
F5A3669902CCFAF601DC3354 = {
fileRef = F5A3669502CCFAF601DC3354;
isa = PBXBuildFile;
settings = {
};
};
F5A3669A02CCFB7A01DC3354 = {
fileRef = F5A3669302CCFAF601DC3354;
isa = PBXBuildFile;
settings = {
};
};
F5A3669B02CCFB7A01DC3354 = {
fileRef = F632AF8402B9AEBB01000103;
isa = PBXBuildFile;
settings = {
};
};
F5A3669C02CCFB7A01DC3354 = {
fileRef = F5A3669502CCFAF601DC3354;
isa = PBXBuildFile;
settings = {
};
};
F5AC38BA02AD8E7B01A967F3 = {
fileRef = F5C2CDA702383CE601A967DF;
isa = PBXBuildFile;
@ -4426,6 +4490,7 @@
F53E012B02AEE91D01A967F3,
F53E013402AEEA2901A967F3,
F59236C402C89ACA0100012B,
F5A3669A02CCFB7A01DC3354,
);
isa = PBXHeadersBuildPhase;
name = Headers;
@ -4538,6 +4603,8 @@
F56F242102AC6D0401A967F3,
F53E012E02AEE93701A967F3,
F59236C502C89ACA0100012B,
F5A3669B02CCFB7A01DC3354,
F5A3669C02CCFB7A01DC3354,
);
isa = PBXSourcesBuildPhase;
name = Sources;
@ -6259,6 +6326,24 @@
settings = {
};
};
F5C321D002CBCEF7014E7D56 = {
isa = PBXFileReference;
name = nsXBLService.cpp;
path = /Volumes/Development/Projects/Mozilla/Chimera/mozilla/content/xbl/src/nsXBLService.cpp;
refType = 0;
};
F5C321D402CBD01C014E7D56 = {
isa = PBXFileReference;
name = xmlparse.c;
path = /Volumes/Development/Projects/Mozilla/Chimera/mozilla/expat/xmlparse/xmlparse.c;
refType = 0;
};
F5C321D702CBD0CE014E7D56 = {
isa = PBXFileReference;
name = nsXMLContentSink.cpp;
path = /Volumes/Development/Projects/Mozilla/Chimera/mozilla/content/xml/document/src/nsXMLContentSink.cpp;
refType = 0;
};
F5C3AB810270072A01A80166 = {
isa = PBXFileReference;
path = CHExtendedOutlineView.h;

Двоичный файл не отображается.

Просмотреть файл

@ -3,13 +3,13 @@
<plist version="0.9">
<dict>
<key>IBDocumentLocation</key>
<string>85 201 356 240 0 0 1280 1002 </string>
<string>73 133 356 240 0 0 1152 746 </string>
<key>IBEditorPositions</key>
<dict>
<key>266</key>
<string>418 452 277 90 0 0 1152 746 </string>
<key>29</key>
<string>11 957 446 44 0 0 1280 1002 </string>
<string>9 701 446 44 0 0 1152 746 </string>
</dict>
<key>IBFramework Version</key>
<string>248.0</string>

Двоичные данные
camino/resources/localized/English.lproj/MainMenu.nib/objects.nib сгенерированный

Двоичный файл не отображается.

Просмотреть файл

@ -22,6 +22,8 @@
*/
#import "BookmarkInfoController.h"
#import "BookmarksDataSource.h"
#include "nsIContent.h"
#include "nsINamespaceManager.h"

Просмотреть файл

@ -0,0 +1,118 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Simon Fraser <sfraser@netscape.com>
*
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#import <Foundation/Foundation.h>
#import <Appkit/Appkit.h>
#import "MainController.h"
#import "CHBookmarksToolbar.h"
#import "CHExtendedOutlineView.h"
class nsIContent;
class BookmarksService;
@class BookmarkInfoController;
@interface BookmarksDataSource : NSObject
{
BookmarksService* mBookmarks;
IBOutlet id mOutlineView;
IBOutlet id mBrowserWindowController;
NSString* mCachedHref;
BookmarkInfoController* mBookmarkInfoController;
}
-(id) init;
-(void) dealloc;
-(void) windowClosing;
-(void) ensureBookmarks;
-(IBAction)addBookmark:(id)aSender;
-(void)endAddBookmark: (int)aCode;
-(IBAction)deleteBookmarks: (id)aSender;
-(void)deleteBookmark: (id)aItem;
-(IBAction)addFolder:(id)aSender;
-(void)addBookmark:(id)aSender useSelection:(BOOL)aSel isFolder:(BOOL)aIsFolder;
-(NSString*)resolveKeyword:(NSString*)aKeyword;
-(IBAction)openBookmarkInNewTab:(id)aSender;
-(IBAction)openBookmarkInNewWindow:(id)aSender;
-(void)openBookmarkGroup:(id)aTabView groupElement:(nsIDOMElement*)aFolder;
-(IBAction)showBookmarkInfo:(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;
- (BOOL)outlineView:(NSOutlineView *)ov writeItems:(NSArray*)items toPasteboard:(NSPasteboard*)pboard;
- (NSDragOperation)outlineView:(NSOutlineView*)ov validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(int)index;
- (BOOL)outlineView:(NSOutlineView*)ov acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(int)index;
- (void)reloadDataForItem:(id)item reloadChildren: (BOOL)aReloadChildren;
// Delegate methods
- (void)outlineViewItemWillExpand:(NSNotification *)notification;
- (void)outlineViewItemWillCollapse:(NSNotification *)notification;
@end
@interface BookmarkItem : NSObject
{
nsIContent* mContentNode;
}
- (nsIContent*)contentNode;
- (void)setContentNode: (nsIContent*)aContentNode;
- (NSNumber*)contentID;
- (id)copyWithZone:(NSZone *)aZone;
@end

Просмотреть файл

@ -0,0 +1,764 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Simon Fraser <sfraser@netscape.com>
*
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#import "BookmarksDataSource.h"
#import "BookmarkInfoController.h"
#include "nsCOMPtr.h"
#include "nsIContent.h"
#include "nsIDocument.h"
#include "nsIDocumentObserver.h"
#include "nsIDOMDocument.h"
#include "nsIDOMElement.h"
#include "nsINamespaceManager.h"
#include "nsIPrefBranch.h"
#include "nsIServiceManager.h"
#include "nsVoidArray.h"
#import "BookmarksService.h"
@implementation BookmarksDataSource
-(id) init
{
if ( (self = [super init]) ) {
mBookmarks = nsnull;
mCachedHref = nil;
}
return self;
}
-(void) dealloc
{
[mBookmarkInfoController release];
[super dealloc];
}
-(void) windowClosing
{
if (mBookmarks) {
mBookmarks->RemoveObserver();
delete mBookmarks;
}
}
-(void) ensureBookmarks
{
if (mBookmarks)
return;
mBookmarks = new BookmarksService(self);
mBookmarks->AddObserver();
[mOutlineView setTarget: self];
[mOutlineView setDoubleAction: @selector(openBookmark:)];
[mOutlineView setDeleteAction: @selector(deleteBookmarks:)];
[mOutlineView reloadData];
}
-(IBAction)addBookmark:(id)aSender
{
[self addBookmark: aSender useSelection: YES isFolder: NO];
}
-(IBAction)addFolder:(id)aSender
{
[self addBookmark: aSender useSelection: YES isFolder: YES];
}
-(void)addBookmark:(id)aSender useSelection:(BOOL)aUseSel isFolder:(BOOL)aIsFolder
{
if (!mBookmarks)
return;
// We use the selected item to determine the parent only if aUseSel is YES.
BookmarkItem* item = nil;
if (aUseSel && ([mOutlineView numberOfSelectedRows] == 1)) {
// There is only one selected row. If it is a folder, use it as our parent.
// Otherwise, use our parent,
int index = [mOutlineView selectedRow];
item = [mOutlineView itemAtRow: index];
if (![mOutlineView isExpandable: item]) {
// We can't be used as the parent. Try our parent.
nsIContent* content = [item contentNode];
if (!content)
return;
nsCOMPtr<nsIContent> parentContent;
content->GetParent(*getter_AddRefs(parentContent));
nsCOMPtr<nsIContent> root;
mBookmarks->GetRootContent(getter_AddRefs(root));
// The root has no item, so we don't need to do a lookup unless we
// aren't the root.
if (parentContent != root) {
PRUint32 contentID;
parentContent->GetContentID(&contentID);
item = [(BookmarksService::gDictionary) objectForKey: [NSNumber numberWithInt: contentID]];
}
}
}
nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(mBookmarks->gBookmarks));
// Fetch the title of the current page and the URL.
nsAutoString title, href;
if (!aIsFolder) {
BookmarksService::GetTitleAndHrefForBrowserView([[mBrowserWindowController getBrowserWrapper] getBrowserView],
title, href);
mCachedHref = [NSString stringWithCharacters: href.get() length: href.Length()];
[mCachedHref retain];
}
else {
mCachedHref = nil;
title = NS_LITERAL_STRING("New Folder");
}
NSTextField* textField = [mBrowserWindowController getAddBookmarkTitle];
[textField setStringValue: [NSString stringWithCharacters: title.get() length: title.Length()]];
[mBrowserWindowController cacheBookmarkDS: self];
// Show/hide the bookmark all tabs checkbox as appropriate.
NSTabView* tabView = [mBrowserWindowController getTabBrowser];
id checkbox = [mBrowserWindowController getAddBookmarkCheckbox];
BOOL hasSuperview = [checkbox superview] != nil;
if (aIsFolder && hasSuperview) {
// Just don't show it at all.
[checkbox removeFromSuperview];
[checkbox retain];
}
else if (!aIsFolder && !hasSuperview) {
// Put it back in.
[[[mBrowserWindowController getAddBookmarkSheetWindow] contentView] addSubview: checkbox];
[checkbox autorelease];
}
// Enable the bookmark all tabs checkbox if appropriate.
if (!aIsFolder)
[[mBrowserWindowController getAddBookmarkCheckbox] setEnabled: ([tabView numberOfTabViewItems] > 1)];
// Build up the folder list.
NSPopUpButton* popup = [mBrowserWindowController getAddBookmarkFolder];
BookmarksService::ConstructAddBookmarkFolderList(popup, item);
[NSApp beginSheet: [mBrowserWindowController getAddBookmarkSheetWindow]
modalForWindow: [mBrowserWindowController window]
modalDelegate: nil //self
didEndSelector: nil //@selector(sheetDidEnd:)
contextInfo: nil];
}
-(void)endAddBookmark: (int)aCode
{
if (aCode == 0)
return;
BOOL isGroup = NO;
id checkbox = [mBrowserWindowController getAddBookmarkCheckbox];
if (([checkbox superview] != nil) && [checkbox isEnabled] && ([checkbox state] == NSOnState)) {
mCachedHref = nil;
isGroup = YES;
}
const char* titleC = [[[mBrowserWindowController getAddBookmarkTitle] stringValue] cString];
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<nsIDOMElement> elt;
domDoc->CreateElementNS(NS_LITERAL_STRING("http://chimera.mozdev.org/bookmarks/"),
tagName,
getter_AddRefs(elt));
elt->SetAttribute(NS_LITERAL_STRING("name"), title);
if (mCachedHref) {
nsAutoString href; href.AssignWithConversion([mCachedHref cString]);
[mCachedHref release];
elt->SetAttribute(NS_LITERAL_STRING("href"), href);
}
if (isGroup) {
// We have to iterate over each tab and create content nodes using the
// title/href of all the pages. They are inserted underneath the parent.
elt->SetAttribute(NS_LITERAL_STRING("group"), NS_LITERAL_STRING("true"));
id tabBrowser = [mBrowserWindowController getTabBrowser];
int count = [tabBrowser numberOfTabViewItems];
for (int i = 0; i < count; i++) {
id browserView = [[[tabBrowser tabViewItemAtIndex: i] view] getBrowserView];
nsAutoString title, href;
BookmarksService::GetTitleAndHrefForBrowserView(browserView, title, href);
nsCOMPtr<nsIDOMElement> childElt;
domDoc->CreateElementNS(NS_LITERAL_STRING("http://chimera.mozdev.org/bookmarks/"),
NS_LITERAL_STRING("bookmark"),
getter_AddRefs(childElt));
childElt->SetAttribute(NS_LITERAL_STRING("name"), title);
childElt->SetAttribute(NS_LITERAL_STRING("href"), href);
nsCOMPtr<nsIDOMNode> dummy;
elt->AppendChild(childElt, getter_AddRefs(dummy));
}
}
// 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;
parentElt->AppendChild(elt, getter_AddRefs(dummy));
nsCOMPtr<nsIContent> childContent(do_QueryInterface(elt));
mBookmarks->BookmarkAdded(parentContent, childContent);
}
-(IBAction)deleteBookmarks: (id)aSender
{
if (!mBookmarks)
return;
int index = [mOutlineView selectedRow];
if (index == -1)
return;
// we'll run into problems if a parent item and one if its children are both selected.
// A cheap way of having to avoid scanning the list to remove children is to have the
// outliner collapse all items that are being deleted. This will cull the selection
// for us and eliminate any children that happened to be selected.
NSEnumerator* selRows = [mOutlineView selectedRowEnumerator];
for (NSNumber* currIndex = [selRows nextObject];
currIndex != nil;
currIndex = [selRows nextObject]) {
index = [currIndex intValue];
BookmarkItem* item = [mOutlineView itemAtRow: index];
[mOutlineView collapseItem: item];
}
// create array of items we need to delete. Deleting items out of of the
// selection array is problematic for some reason.
NSMutableArray* itemsToDelete = [[[NSMutableArray alloc] init] autorelease];
selRows = [mOutlineView selectedRowEnumerator];
for (NSNumber* currIndex = [selRows nextObject];
currIndex != nil;
currIndex = [selRows nextObject]) {
index = [currIndex intValue];
BookmarkItem* item = [mOutlineView itemAtRow: index];
[itemsToDelete addObject: item];
}
// delete all bookmarks that are in our array
int count = [itemsToDelete count];
for (int i = 0; i < count; i++) {
BookmarkItem* item = [itemsToDelete objectAtIndex: i];
[self deleteBookmark: item];
}
// restore selection to location near last item deleted
int total = [mOutlineView numberOfRows];
if (index == total)
index--;
[mOutlineView selectRow: index byExtendingSelection: NO];
}
-(void)deleteBookmark:(id)aItem
{
nsCOMPtr<nsIContent> content = [aItem contentNode];
nsCOMPtr<nsIDOMElement> child(do_QueryInterface(content));
if (!child)
return;
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;
if (parent)
parent->RemoveChild(child, getter_AddRefs(dummy));
mBookmarks->BookmarkRemoved(parentContent, content);
}
-(IBAction)openBookmark: (id)aSender
{
int index = [mOutlineView selectedRow];
if (index == -1)
return;
id item = [mOutlineView itemAtRow: index];
if (!item)
return;
nsIContent* content = [item contentNode];
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(content));
nsAutoString group;
content->GetAttr(kNameSpaceID_None, BookmarksService::gGroupAtom, group);
if (!group.IsEmpty())
mBookmarks->OpenBookmarkGroup([mBrowserWindowController getTabBrowser], elt);
else if ([mOutlineView isExpandable: item]) {
if ([mOutlineView isItemExpanded: item])
[mOutlineView collapseItem: item];
else
[mOutlineView expandItem: item];
}
else {
nsAutoString href;
content->GetAttr(kNameSpaceID_None, BookmarksService::gHrefAtom, href);
if (!href.IsEmpty()) {
NSString* url = [NSString stringWithCharacters: href.get() length: href.Length()];
[[[mBrowserWindowController getBrowserWrapper] getBrowserView] loadURI: url flags: NSLoadFlagsNone];
// Focus and activate our content area.
[[[mBrowserWindowController getBrowserWrapper] getBrowserView] setActive: YES];
}
}
}
-(NSString*) resolveKeyword: (NSString*) aKeyword
{
return BookmarksService::ResolveKeyword(aKeyword);
}
//
// outlineView:shouldEditTableColumn:item: (delegate method)
//
// Called by the outliner to determine whether or not we should allow the
// user to edit this item. For now, Cocoa doesn't correctly handle editing
// of attributed strings with icons, so we can't turn this on. :(
//
- (BOOL)outlineView:(NSOutlineView *)outlineView shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item
{
return NO;
}
- (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item
{
if (!mBookmarks)
return nil;
nsCOMPtr<nsIContent> content;
if (!item)
mBookmarks->GetRootContent(getter_AddRefs(content));
else
content = [item contentNode];
nsCOMPtr<nsIContent> child;
content->ChildAt(index, *getter_AddRefs(child));
if ( child )
return mBookmarks->GetWrapperFor(child);
return nil;
}
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
{
if (!mBookmarks)
return NO;
if (!item)
return YES; // The root node is always open.
nsCOMPtr<nsIAtom> tagName;
nsIContent* content = [item contentNode];
content->GetTag(*getter_AddRefs(tagName));
BOOL isExpandable = (tagName == BookmarksService::gFolderAtom);
// XXXben - persistence of folder open state
// I'm adding this code, turned off, until I can figure out how to refresh the NSOutlineView's
// row count. Currently the items are expanded, but the outline view continues to believe it had
// the number of rows it had before the item was opened visible, until the view is resized.
#if 0
if (isExpandable) {
PRBool isOpen = content->HasAttr(kNameSpaceID_None, BookmarksService::gOpenAtom);
if (isOpen)
[mOutlineView expandItem: item];
else
[mOutlineView collapseItem: item];
}
#endif
return isExpandable;
}
- (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
{
if (!mBookmarks)
return 0;
nsCOMPtr<nsIContent> content;
if (!item)
mBookmarks->GetRootContent(getter_AddRefs(content));
else
content = [item contentNode];
PRInt32 childCount;
content->ChildCount(childCount);
return childCount;
}
- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
{
NSString *columnName = [tableColumn identifier];
NSMutableAttributedString *cellValue = [[NSMutableAttributedString alloc] init];
NSFileWrapper *fileWrapper = [[NSFileWrapper alloc] initRegularFileWithContents:nil];
NSTextAttachment *textAttachment = [[NSTextAttachment alloc] initWithFileWrapper:fileWrapper];
NSMutableAttributedString *attachmentAttrString = nil;
NSCell *attachmentAttrStringCell;
if ([columnName isEqualToString: @"name"]) {
nsIContent* content = [item contentNode];
nsAutoString nameAttr;
content->GetAttr(kNameSpaceID_None, BookmarksService::gNameAtom, nameAttr);
//Set cell's textual contents
[cellValue replaceCharactersInRange:NSMakeRange(0, [cellValue length]) withString:[NSString stringWithCharacters: nameAttr.get() length: nameAttr.Length()]];
//Create an attributed string to hold the empty attachment, then release the components.
attachmentAttrString = [[NSMutableAttributedString attributedStringWithAttachment:textAttachment] retain];
[textAttachment release];
[fileWrapper release];
//Get the cell of the text attachment.
attachmentAttrStringCell = (NSCell *)[(NSTextAttachment *)[attachmentAttrString attribute:NSAttachmentAttributeName atIndex:0 effectiveRange:nil] attachmentCell];
//Figure out which image to add, and set the cell's image.
// Use the bookmark groups image for groups.
if ([self outlineView:outlineView isItemExpandable:item]) {
nsIContent* content = [item contentNode];
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(content));
nsAutoString group;
content->GetAttr(kNameSpaceID_None, BookmarksService::gGroupAtom, group);
if (!group.IsEmpty())
[attachmentAttrStringCell setImage:[NSImage imageNamed:@"groupbookmark"]];
else
[attachmentAttrStringCell setImage:[NSImage imageNamed:@"folder"]];
}
else
[attachmentAttrStringCell setImage:[NSImage imageNamed:@"smallbookmark"]];
//Insert the image
[cellValue replaceCharactersInRange:NSMakeRange(0, 0) withAttributedString:attachmentAttrString];
//Tweak the baseline to vertically center the text.
[cellValue addAttribute:NSBaselineOffsetAttributeName
value:[NSNumber numberWithFloat:-3.0]
range:NSMakeRange(0, 1)];
}
return cellValue;
}
- (void)outlineView:(NSOutlineView *)outlineView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
{
#if NOT_USED
// ignore all this. It doesn't work, but i'm leaving it here just in case we ever try to turn
// this code back on. We have to remove the attributes from the string in order to correctly
// set it in the DOM.
NSString *columnName = [tableColumn identifier];
if ( [columnName isEqualTo:@"name"] ) {
// remove the attributes
int strLen = [object length];
NSMutableAttributedString *cellValue = [[NSMutableAttributedString alloc] initWithAttributedString:object];
[cellValue removeAttribute:NSBaselineOffsetAttributeName range:NSMakeRange(0,1)];
[cellValue removeAttribute:NSAttachmentAttributeName range:NSMakeRange(0,strLen)];
// extract the unicode
strLen = [cellValue length];
PRUnichar* buffer = new PRUnichar[strLen + 1];
buffer[strLen] = '\0';
if ( !buffer )
return;
[cellValue getCharacters: buffer];
nsAutoString nameAttr;
nameAttr.Adopt(buffer);
// stash it into the dom.
nsIContent* content = [item contentNode];
content->SetAttr(kNameSpaceID_None, BookmarksService::gNameAtom, nameAttr, PR_TRUE);
[cellValue release];
}
#endif
}
- (BOOL)outlineView:(NSOutlineView *)ov writeItems:(NSArray*)items toPasteboard:(NSPasteboard*)pboard
{
if (!mBookmarks || [mOutlineView selectedRow] == -1) {
return NO;
}
#ifdef FILTER_DESCENDANT_ON_DRAG
NSArray *toDrag = BookmarksService::FilterOutDescendantsForDrag(items);
#else
NSArray *toDrag = items;
#endif
int count = [toDrag count];
if (count > 0) {
// Create Pasteboard Data
NSMutableArray *draggedID = [NSMutableArray arrayWithCapacity: count];
for (int i = 0; i < count; i++)
[draggedID addObject: [[toDrag objectAtIndex: i] contentID]];
[pboard declareTypes: [NSArray arrayWithObject: @"MozBookmarkType"] owner: self];
[pboard setPropertyList: draggedID forType: @"MozBookmarkType"];
return YES;
}
return NO;
}
- (NSDragOperation)outlineView:(NSOutlineView*)ov validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(int)index
{
NSArray* types = [[info draggingPasteboard] types];
// if the index is -1, deny the drop
if (index == NSOutlineViewDropOnItemIndex)
return NSDragOperationNone;
if ([types containsObject: @"MozBookmarkType"]) {
NSArray *draggedIDs = [[info draggingPasteboard] propertyListForType: @"MozBookmarkType"];
BookmarkItem* parent;
parent = (item) ? item : BookmarksService::GetRootItem();
return (BookmarksService::IsBookmarkDropValid(parent, index, draggedIDs)) ? NSDragOperationGeneric : NSDragOperationNone;
} else if ([types containsObject: @"MozURLType"]) {
return NSDragOperationGeneric;
}
return NSDragOperationNone;
}
- (BOOL)outlineView:(NSOutlineView*)ov acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(int)index {
NSArray *types = [[info draggingPasteboard] types];
BookmarkItem* parent = (item) ? item : BookmarksService::GetRootItem();
if ([types containsObject: @"MozBookmarkType"]) {
NSArray *draggedItems = [[info draggingPasteboard] propertyListForType: @"MozBookmarkType"];
BookmarksService::PerformBookmarkDrop(parent, index, draggedItems);
return YES;
}
else if ([types containsObject: @"MozURLType"]) {
NSDictionary* proxy = [[info draggingPasteboard] propertyListForType: @"MozURLType"];
BookmarkItem* beforeItem = [self outlineView:ov child:index ofItem:item];
return BookmarksService::PerformProxyDrop(parent, beforeItem, proxy);
}
return NO;
}
- (void)reloadDataForItem:(id)item reloadChildren: (BOOL)aReloadChildren
{
if (!item)
[mOutlineView reloadData];
else if ([mOutlineView isItemExpanded: item])
[mOutlineView reloadItem: item reloadChildren: aReloadChildren];
}
-(IBAction)openBookmarkInNewTab:(id)aSender
{
int index = [mOutlineView selectedRow];
if (index == -1)
return;
if ([mOutlineView numberOfSelectedRows] == 1) {
nsCOMPtr<nsIPrefBranch> pref(do_GetService("@mozilla.org/preferences-service;1"));
if (!pref)
return; // Something bad happened if we can't get prefs.
BookmarkItem* item = [mOutlineView itemAtRow: index];
nsAutoString hrefAttr;
[item contentNode]->GetAttr(kNameSpaceID_None, BookmarksService::gHrefAtom, hrefAttr);
// stuff it into the string
NSString* hrefStr = [NSString stringWithCharacters:hrefAttr.get() length:hrefAttr.Length()];
PRBool loadInBackground;
pref->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground);
[mBrowserWindowController openNewTabWithURL: hrefStr loadInBackground: loadInBackground];
}
}
-(IBAction)openBookmarkInNewWindow:(id)aSender
{
int index = [mOutlineView selectedRow];
if (index == -1)
return;
if ([mOutlineView numberOfSelectedRows] == 1) {
BookmarkItem* item = [mOutlineView itemAtRow: index];
nsAutoString hrefAttr;
[item contentNode]->GetAttr(kNameSpaceID_None, BookmarksService::gHrefAtom, hrefAttr);
// stuff it into the string
NSString* hrefStr = [NSString stringWithCharacters:hrefAttr.get() length:hrefAttr.Length()];
nsAutoString group;
[item contentNode]->GetAttr(kNameSpaceID_None, BookmarksService::gGroupAtom, group);
if (group.IsEmpty())
[mBrowserWindowController openNewWindowWithURL: hrefStr loadInBackground: NO];
else {
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface([item contentNode]));
[mBrowserWindowController openNewWindowWithGroup: elt loadInBackground: NO];
}
}
}
-(void)openBookmarkGroup:(id)aTabView groupElement:(nsIDOMElement*)aFolder
{
mBookmarks->OpenBookmarkGroup(aTabView, aFolder);
}
-(IBAction)showBookmarkInfo:(id)aSender
{
if (!mBookmarkInfoController)
mBookmarkInfoController = [[BookmarkInfoController alloc] initWithOutlineView: mOutlineView];
[mBookmarkInfoController showWindow:mBookmarkInfoController];
int index = [mOutlineView selectedRow];
BookmarkItem* item = [mOutlineView itemAtRow: index];
[mBookmarkInfoController setBookmark:item];
}
-(void)outlineViewSelectionDidChange: (NSNotification*) aNotification
{
int index = [mOutlineView selectedRow];
if (index == -1) {
if (mBookmarkInfoController)
[mBookmarkInfoController setBookmark:NULL];
}
else {
BookmarkItem* item = [mOutlineView itemAtRow:index];
if (mBookmarkInfoController)
[mBookmarkInfoController setBookmark:item];
}
}
-(BOOL)validateMenuItem:(NSMenuItem*)aMenuItem
{
int index = [mOutlineView selectedRow];
if (index == -1)
return NO;
BookmarkItem* item = [mOutlineView itemAtRow: index];
BOOL isBookmark = [mOutlineView isExpandable:item] == NO;
nsAutoString group;
[item contentNode]->GetAttr(kNameSpaceID_None, BookmarksService::gGroupAtom, group);
BOOL isGroup = !group.IsEmpty();
if (([aMenuItem action] == @selector(openBookmarkInNewWindow:))) {
// Bookmarks and Bookmark Groups can be opened in a new window
return (isBookmark || isGroup);
}
else if (([aMenuItem action] == @selector(openBookmarkInNewTab:))) {
// Only Bookmarks can be opened in new tabs
return isBookmark;
}
return YES;
}
- (void)outlineViewItemWillExpand:(NSNotification *)notification
{
BookmarkItem* item = [[notification userInfo] objectForKey:[[[notification userInfo] allKeys] objectAtIndex: 0]];
[item contentNode]->SetAttr(kNameSpaceID_None, BookmarksService::gOpenAtom, NS_LITERAL_STRING("true"), PR_FALSE);
}
- (void)outlineViewItemWillCollapse:(NSNotification *)notification
{
BookmarkItem* item = [[notification userInfo] objectForKey:[[[notification userInfo] allKeys] objectAtIndex: 0]];
[item contentNode]->UnsetAttr(kNameSpaceID_None, BookmarksService::gOpenAtom, PR_FALSE);
}
@end
@implementation BookmarkItem
-(nsIContent*)contentNode
{
return mContentNode;
}
- (NSNumber*)contentID
{
PRUint32 contentID = 0;
mContentNode->GetContentID(&contentID);
return [NSNumber numberWithInt: contentID];
}
- (NSString *)description
{
nsCOMPtr<nsIContent> item = [self contentNode];
nsCOMPtr<nsIDOMElement> element(do_QueryInterface(item));
nsAutoString href;
element->GetAttribute(NS_LITERAL_STRING("name"), href);
NSString* info = [NSString stringWithCharacters: href.get() length: href.Length()];
return [NSString stringWithFormat:@"<BookmarkItem, name = \"%@\">", info];
}
-(void)setContentNode: (nsIContent*)aContentNode
{
mContentNode = aContentNode;
}
- (id)copyWithZone:(NSZone *)aZone
{
BookmarkItem* copy = [[[self class] allocWithZone: aZone] init];
[copy setContentNode: mContentNode];
return copy;
}
@end

Просмотреть файл

@ -23,6 +23,8 @@
#import "CHBookmarksOutlineView.h"
#import "BookmarksService.h"
#import "BookmarksDataSource.h"
#include "nsCOMPtr.h"
#include "nsIDOMElement.h"
#include "nsIContent.h"

Просмотреть файл

@ -37,88 +37,22 @@
#include <Appkit/Appkit.h>
#include <Carbon/Carbon.h>
#include "nsCOMPtr.h"
#include "nsIDocument.h"
#include "nsIDocumentObserver.h"
#include "nsVoidArray.h"
#import "MainController.h"
#import "CHBookmarksToolbar.h"
#import "CHExtendedOutlineView.h"
@class BookmarkItem;
class BookmarksService;
class nsIAtom;
@class BookmarkInfoController;
@interface BookmarksDataSource : NSObject
{
BookmarksService* mBookmarks;
IBOutlet id mOutlineView;
IBOutlet id mBrowserWindowController;
NSString* mCachedHref;
BookmarkInfoController* mBookmarkInfoController;
}
-(id) init;
-(void) dealloc;
-(void) windowClosing;
-(void) ensureBookmarks;
-(IBAction)addBookmark:(id)aSender;
-(void)endAddBookmark: (int)aCode;
-(IBAction)deleteBookmarks: (id)aSender;
-(void)deleteBookmark: (id)aItem;
-(IBAction)addFolder:(id)aSender;
-(void)addBookmark:(id)aSender useSelection:(BOOL)aSel isFolder:(BOOL)aIsFolder;
-(NSString*)resolveKeyword:(NSString*)aKeyword;
-(IBAction)openBookmarkInNewTab:(id)aSender;
-(IBAction)openBookmarkInNewWindow:(id)aSender;
-(void)openBookmarkGroup:(id)aTabView groupElement:(nsIDOMElement*)aFolder;
-(IBAction)showBookmarkInfo:(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;
- (BOOL)outlineView:(NSOutlineView *)ov writeItems:(NSArray*)items toPasteboard:(NSPasteboard*)pboard;
- (NSDragOperation)outlineView:(NSOutlineView*)ov validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(int)index;
- (BOOL)outlineView:(NSOutlineView*)ov acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(int)index;
- (void)reloadDataForItem:(id)item reloadChildren: (BOOL)aReloadChildren;
// Delegate methods
- (void)outlineViewItemWillExpand:(NSNotification *)notification;
- (void)outlineViewItemWillCollapse:(NSNotification *)notification;
@end
@interface BookmarkItem : NSObject
{
nsIContent* mContentNode;
}
- (nsIContent*)contentNode;
- (void)setContentNode: (nsIContent*)aContentNode;
- (NSNumber*)contentID;
- (id)copyWithZone:(NSZone *)aZone;
@end
class nsIDOMHTMLDocument;
@class BookmarksDataSource;
@class BookmarkItem;
class BookmarksService
{
public:
@ -142,6 +76,8 @@ public:
static BookmarkItem* GetRootItem();
static BookmarkItem* GetWrapperFor(nsIContent* aItem);
static BookmarkItem* GetWrapperFor(PRUint32 contentID);
static void ReadBookmarks();
static void FlushBookmarks();
static void ConstructBookmarksMenu(NSMenu* aMenu, nsIContent* aContent);
@ -189,6 +125,7 @@ public:
static nsIAtom* gOpenAtom;
static nsIAtom* gGroupAtom;
static nsIDocument* gBookmarks;
static BOOL gBookmarksFileReadOK;
static nsVoidArray* gInstances;
static int CHInsertNone;
static int CHInsertInto;

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -25,6 +25,8 @@
#import "CHBookmarksButton.h"
#import "CHBookmarksToolbar.h"
#import "BookmarksService.h"
#import "BookmarksDataSource.h"
#include "nsIDOMElement.h"
#include "nsIContent.h"

Просмотреть файл

@ -584,6 +584,9 @@ static NSString *SearchToolbarItemIdentifier = @"Search Toolbar Item";
[newView setIsBookmarksImport: YES];
[[[self window] contentView] addSubview: newView];
[[newView getBrowserView] loadURI:aURLSpec flags:NSLoadFlagsNone];
// XXX force reload
//[mSidebarBookmarksDataSource reloadDataForItem: nil reloadChildren: YES];
}
- (IBAction)goToLocationFromToolbarURLField:(id)sender

Просмотреть файл

@ -22,6 +22,8 @@
*/
#import "BookmarkInfoController.h"
#import "BookmarksDataSource.h"
#include "nsIContent.h"
#include "nsINamespaceManager.h"

Просмотреть файл

@ -0,0 +1,118 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Simon Fraser <sfraser@netscape.com>
*
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#import <Foundation/Foundation.h>
#import <Appkit/Appkit.h>
#import "MainController.h"
#import "CHBookmarksToolbar.h"
#import "CHExtendedOutlineView.h"
class nsIContent;
class BookmarksService;
@class BookmarkInfoController;
@interface BookmarksDataSource : NSObject
{
BookmarksService* mBookmarks;
IBOutlet id mOutlineView;
IBOutlet id mBrowserWindowController;
NSString* mCachedHref;
BookmarkInfoController* mBookmarkInfoController;
}
-(id) init;
-(void) dealloc;
-(void) windowClosing;
-(void) ensureBookmarks;
-(IBAction)addBookmark:(id)aSender;
-(void)endAddBookmark: (int)aCode;
-(IBAction)deleteBookmarks: (id)aSender;
-(void)deleteBookmark: (id)aItem;
-(IBAction)addFolder:(id)aSender;
-(void)addBookmark:(id)aSender useSelection:(BOOL)aSel isFolder:(BOOL)aIsFolder;
-(NSString*)resolveKeyword:(NSString*)aKeyword;
-(IBAction)openBookmarkInNewTab:(id)aSender;
-(IBAction)openBookmarkInNewWindow:(id)aSender;
-(void)openBookmarkGroup:(id)aTabView groupElement:(nsIDOMElement*)aFolder;
-(IBAction)showBookmarkInfo:(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;
- (BOOL)outlineView:(NSOutlineView *)ov writeItems:(NSArray*)items toPasteboard:(NSPasteboard*)pboard;
- (NSDragOperation)outlineView:(NSOutlineView*)ov validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(int)index;
- (BOOL)outlineView:(NSOutlineView*)ov acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(int)index;
- (void)reloadDataForItem:(id)item reloadChildren: (BOOL)aReloadChildren;
// Delegate methods
- (void)outlineViewItemWillExpand:(NSNotification *)notification;
- (void)outlineViewItemWillCollapse:(NSNotification *)notification;
@end
@interface BookmarkItem : NSObject
{
nsIContent* mContentNode;
}
- (nsIContent*)contentNode;
- (void)setContentNode: (nsIContent*)aContentNode;
- (NSNumber*)contentID;
- (id)copyWithZone:(NSZone *)aZone;
@end

Просмотреть файл

@ -0,0 +1,764 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Simon Fraser <sfraser@netscape.com>
*
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#import "BookmarksDataSource.h"
#import "BookmarkInfoController.h"
#include "nsCOMPtr.h"
#include "nsIContent.h"
#include "nsIDocument.h"
#include "nsIDocumentObserver.h"
#include "nsIDOMDocument.h"
#include "nsIDOMElement.h"
#include "nsINamespaceManager.h"
#include "nsIPrefBranch.h"
#include "nsIServiceManager.h"
#include "nsVoidArray.h"
#import "BookmarksService.h"
@implementation BookmarksDataSource
-(id) init
{
if ( (self = [super init]) ) {
mBookmarks = nsnull;
mCachedHref = nil;
}
return self;
}
-(void) dealloc
{
[mBookmarkInfoController release];
[super dealloc];
}
-(void) windowClosing
{
if (mBookmarks) {
mBookmarks->RemoveObserver();
delete mBookmarks;
}
}
-(void) ensureBookmarks
{
if (mBookmarks)
return;
mBookmarks = new BookmarksService(self);
mBookmarks->AddObserver();
[mOutlineView setTarget: self];
[mOutlineView setDoubleAction: @selector(openBookmark:)];
[mOutlineView setDeleteAction: @selector(deleteBookmarks:)];
[mOutlineView reloadData];
}
-(IBAction)addBookmark:(id)aSender
{
[self addBookmark: aSender useSelection: YES isFolder: NO];
}
-(IBAction)addFolder:(id)aSender
{
[self addBookmark: aSender useSelection: YES isFolder: YES];
}
-(void)addBookmark:(id)aSender useSelection:(BOOL)aUseSel isFolder:(BOOL)aIsFolder
{
if (!mBookmarks)
return;
// We use the selected item to determine the parent only if aUseSel is YES.
BookmarkItem* item = nil;
if (aUseSel && ([mOutlineView numberOfSelectedRows] == 1)) {
// There is only one selected row. If it is a folder, use it as our parent.
// Otherwise, use our parent,
int index = [mOutlineView selectedRow];
item = [mOutlineView itemAtRow: index];
if (![mOutlineView isExpandable: item]) {
// We can't be used as the parent. Try our parent.
nsIContent* content = [item contentNode];
if (!content)
return;
nsCOMPtr<nsIContent> parentContent;
content->GetParent(*getter_AddRefs(parentContent));
nsCOMPtr<nsIContent> root;
mBookmarks->GetRootContent(getter_AddRefs(root));
// The root has no item, so we don't need to do a lookup unless we
// aren't the root.
if (parentContent != root) {
PRUint32 contentID;
parentContent->GetContentID(&contentID);
item = [(BookmarksService::gDictionary) objectForKey: [NSNumber numberWithInt: contentID]];
}
}
}
nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(mBookmarks->gBookmarks));
// Fetch the title of the current page and the URL.
nsAutoString title, href;
if (!aIsFolder) {
BookmarksService::GetTitleAndHrefForBrowserView([[mBrowserWindowController getBrowserWrapper] getBrowserView],
title, href);
mCachedHref = [NSString stringWithCharacters: href.get() length: href.Length()];
[mCachedHref retain];
}
else {
mCachedHref = nil;
title = NS_LITERAL_STRING("New Folder");
}
NSTextField* textField = [mBrowserWindowController getAddBookmarkTitle];
[textField setStringValue: [NSString stringWithCharacters: title.get() length: title.Length()]];
[mBrowserWindowController cacheBookmarkDS: self];
// Show/hide the bookmark all tabs checkbox as appropriate.
NSTabView* tabView = [mBrowserWindowController getTabBrowser];
id checkbox = [mBrowserWindowController getAddBookmarkCheckbox];
BOOL hasSuperview = [checkbox superview] != nil;
if (aIsFolder && hasSuperview) {
// Just don't show it at all.
[checkbox removeFromSuperview];
[checkbox retain];
}
else if (!aIsFolder && !hasSuperview) {
// Put it back in.
[[[mBrowserWindowController getAddBookmarkSheetWindow] contentView] addSubview: checkbox];
[checkbox autorelease];
}
// Enable the bookmark all tabs checkbox if appropriate.
if (!aIsFolder)
[[mBrowserWindowController getAddBookmarkCheckbox] setEnabled: ([tabView numberOfTabViewItems] > 1)];
// Build up the folder list.
NSPopUpButton* popup = [mBrowserWindowController getAddBookmarkFolder];
BookmarksService::ConstructAddBookmarkFolderList(popup, item);
[NSApp beginSheet: [mBrowserWindowController getAddBookmarkSheetWindow]
modalForWindow: [mBrowserWindowController window]
modalDelegate: nil //self
didEndSelector: nil //@selector(sheetDidEnd:)
contextInfo: nil];
}
-(void)endAddBookmark: (int)aCode
{
if (aCode == 0)
return;
BOOL isGroup = NO;
id checkbox = [mBrowserWindowController getAddBookmarkCheckbox];
if (([checkbox superview] != nil) && [checkbox isEnabled] && ([checkbox state] == NSOnState)) {
mCachedHref = nil;
isGroup = YES;
}
const char* titleC = [[[mBrowserWindowController getAddBookmarkTitle] stringValue] cString];
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<nsIDOMElement> elt;
domDoc->CreateElementNS(NS_LITERAL_STRING("http://chimera.mozdev.org/bookmarks/"),
tagName,
getter_AddRefs(elt));
elt->SetAttribute(NS_LITERAL_STRING("name"), title);
if (mCachedHref) {
nsAutoString href; href.AssignWithConversion([mCachedHref cString]);
[mCachedHref release];
elt->SetAttribute(NS_LITERAL_STRING("href"), href);
}
if (isGroup) {
// We have to iterate over each tab and create content nodes using the
// title/href of all the pages. They are inserted underneath the parent.
elt->SetAttribute(NS_LITERAL_STRING("group"), NS_LITERAL_STRING("true"));
id tabBrowser = [mBrowserWindowController getTabBrowser];
int count = [tabBrowser numberOfTabViewItems];
for (int i = 0; i < count; i++) {
id browserView = [[[tabBrowser tabViewItemAtIndex: i] view] getBrowserView];
nsAutoString title, href;
BookmarksService::GetTitleAndHrefForBrowserView(browserView, title, href);
nsCOMPtr<nsIDOMElement> childElt;
domDoc->CreateElementNS(NS_LITERAL_STRING("http://chimera.mozdev.org/bookmarks/"),
NS_LITERAL_STRING("bookmark"),
getter_AddRefs(childElt));
childElt->SetAttribute(NS_LITERAL_STRING("name"), title);
childElt->SetAttribute(NS_LITERAL_STRING("href"), href);
nsCOMPtr<nsIDOMNode> dummy;
elt->AppendChild(childElt, getter_AddRefs(dummy));
}
}
// 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;
parentElt->AppendChild(elt, getter_AddRefs(dummy));
nsCOMPtr<nsIContent> childContent(do_QueryInterface(elt));
mBookmarks->BookmarkAdded(parentContent, childContent);
}
-(IBAction)deleteBookmarks: (id)aSender
{
if (!mBookmarks)
return;
int index = [mOutlineView selectedRow];
if (index == -1)
return;
// we'll run into problems if a parent item and one if its children are both selected.
// A cheap way of having to avoid scanning the list to remove children is to have the
// outliner collapse all items that are being deleted. This will cull the selection
// for us and eliminate any children that happened to be selected.
NSEnumerator* selRows = [mOutlineView selectedRowEnumerator];
for (NSNumber* currIndex = [selRows nextObject];
currIndex != nil;
currIndex = [selRows nextObject]) {
index = [currIndex intValue];
BookmarkItem* item = [mOutlineView itemAtRow: index];
[mOutlineView collapseItem: item];
}
// create array of items we need to delete. Deleting items out of of the
// selection array is problematic for some reason.
NSMutableArray* itemsToDelete = [[[NSMutableArray alloc] init] autorelease];
selRows = [mOutlineView selectedRowEnumerator];
for (NSNumber* currIndex = [selRows nextObject];
currIndex != nil;
currIndex = [selRows nextObject]) {
index = [currIndex intValue];
BookmarkItem* item = [mOutlineView itemAtRow: index];
[itemsToDelete addObject: item];
}
// delete all bookmarks that are in our array
int count = [itemsToDelete count];
for (int i = 0; i < count; i++) {
BookmarkItem* item = [itemsToDelete objectAtIndex: i];
[self deleteBookmark: item];
}
// restore selection to location near last item deleted
int total = [mOutlineView numberOfRows];
if (index == total)
index--;
[mOutlineView selectRow: index byExtendingSelection: NO];
}
-(void)deleteBookmark:(id)aItem
{
nsCOMPtr<nsIContent> content = [aItem contentNode];
nsCOMPtr<nsIDOMElement> child(do_QueryInterface(content));
if (!child)
return;
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;
if (parent)
parent->RemoveChild(child, getter_AddRefs(dummy));
mBookmarks->BookmarkRemoved(parentContent, content);
}
-(IBAction)openBookmark: (id)aSender
{
int index = [mOutlineView selectedRow];
if (index == -1)
return;
id item = [mOutlineView itemAtRow: index];
if (!item)
return;
nsIContent* content = [item contentNode];
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(content));
nsAutoString group;
content->GetAttr(kNameSpaceID_None, BookmarksService::gGroupAtom, group);
if (!group.IsEmpty())
mBookmarks->OpenBookmarkGroup([mBrowserWindowController getTabBrowser], elt);
else if ([mOutlineView isExpandable: item]) {
if ([mOutlineView isItemExpanded: item])
[mOutlineView collapseItem: item];
else
[mOutlineView expandItem: item];
}
else {
nsAutoString href;
content->GetAttr(kNameSpaceID_None, BookmarksService::gHrefAtom, href);
if (!href.IsEmpty()) {
NSString* url = [NSString stringWithCharacters: href.get() length: href.Length()];
[[[mBrowserWindowController getBrowserWrapper] getBrowserView] loadURI: url flags: NSLoadFlagsNone];
// Focus and activate our content area.
[[[mBrowserWindowController getBrowserWrapper] getBrowserView] setActive: YES];
}
}
}
-(NSString*) resolveKeyword: (NSString*) aKeyword
{
return BookmarksService::ResolveKeyword(aKeyword);
}
//
// outlineView:shouldEditTableColumn:item: (delegate method)
//
// Called by the outliner to determine whether or not we should allow the
// user to edit this item. For now, Cocoa doesn't correctly handle editing
// of attributed strings with icons, so we can't turn this on. :(
//
- (BOOL)outlineView:(NSOutlineView *)outlineView shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item
{
return NO;
}
- (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item
{
if (!mBookmarks)
return nil;
nsCOMPtr<nsIContent> content;
if (!item)
mBookmarks->GetRootContent(getter_AddRefs(content));
else
content = [item contentNode];
nsCOMPtr<nsIContent> child;
content->ChildAt(index, *getter_AddRefs(child));
if ( child )
return mBookmarks->GetWrapperFor(child);
return nil;
}
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
{
if (!mBookmarks)
return NO;
if (!item)
return YES; // The root node is always open.
nsCOMPtr<nsIAtom> tagName;
nsIContent* content = [item contentNode];
content->GetTag(*getter_AddRefs(tagName));
BOOL isExpandable = (tagName == BookmarksService::gFolderAtom);
// XXXben - persistence of folder open state
// I'm adding this code, turned off, until I can figure out how to refresh the NSOutlineView's
// row count. Currently the items are expanded, but the outline view continues to believe it had
// the number of rows it had before the item was opened visible, until the view is resized.
#if 0
if (isExpandable) {
PRBool isOpen = content->HasAttr(kNameSpaceID_None, BookmarksService::gOpenAtom);
if (isOpen)
[mOutlineView expandItem: item];
else
[mOutlineView collapseItem: item];
}
#endif
return isExpandable;
}
- (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
{
if (!mBookmarks)
return 0;
nsCOMPtr<nsIContent> content;
if (!item)
mBookmarks->GetRootContent(getter_AddRefs(content));
else
content = [item contentNode];
PRInt32 childCount;
content->ChildCount(childCount);
return childCount;
}
- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
{
NSString *columnName = [tableColumn identifier];
NSMutableAttributedString *cellValue = [[NSMutableAttributedString alloc] init];
NSFileWrapper *fileWrapper = [[NSFileWrapper alloc] initRegularFileWithContents:nil];
NSTextAttachment *textAttachment = [[NSTextAttachment alloc] initWithFileWrapper:fileWrapper];
NSMutableAttributedString *attachmentAttrString = nil;
NSCell *attachmentAttrStringCell;
if ([columnName isEqualToString: @"name"]) {
nsIContent* content = [item contentNode];
nsAutoString nameAttr;
content->GetAttr(kNameSpaceID_None, BookmarksService::gNameAtom, nameAttr);
//Set cell's textual contents
[cellValue replaceCharactersInRange:NSMakeRange(0, [cellValue length]) withString:[NSString stringWithCharacters: nameAttr.get() length: nameAttr.Length()]];
//Create an attributed string to hold the empty attachment, then release the components.
attachmentAttrString = [[NSMutableAttributedString attributedStringWithAttachment:textAttachment] retain];
[textAttachment release];
[fileWrapper release];
//Get the cell of the text attachment.
attachmentAttrStringCell = (NSCell *)[(NSTextAttachment *)[attachmentAttrString attribute:NSAttachmentAttributeName atIndex:0 effectiveRange:nil] attachmentCell];
//Figure out which image to add, and set the cell's image.
// Use the bookmark groups image for groups.
if ([self outlineView:outlineView isItemExpandable:item]) {
nsIContent* content = [item contentNode];
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(content));
nsAutoString group;
content->GetAttr(kNameSpaceID_None, BookmarksService::gGroupAtom, group);
if (!group.IsEmpty())
[attachmentAttrStringCell setImage:[NSImage imageNamed:@"groupbookmark"]];
else
[attachmentAttrStringCell setImage:[NSImage imageNamed:@"folder"]];
}
else
[attachmentAttrStringCell setImage:[NSImage imageNamed:@"smallbookmark"]];
//Insert the image
[cellValue replaceCharactersInRange:NSMakeRange(0, 0) withAttributedString:attachmentAttrString];
//Tweak the baseline to vertically center the text.
[cellValue addAttribute:NSBaselineOffsetAttributeName
value:[NSNumber numberWithFloat:-3.0]
range:NSMakeRange(0, 1)];
}
return cellValue;
}
- (void)outlineView:(NSOutlineView *)outlineView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
{
#if NOT_USED
// ignore all this. It doesn't work, but i'm leaving it here just in case we ever try to turn
// this code back on. We have to remove the attributes from the string in order to correctly
// set it in the DOM.
NSString *columnName = [tableColumn identifier];
if ( [columnName isEqualTo:@"name"] ) {
// remove the attributes
int strLen = [object length];
NSMutableAttributedString *cellValue = [[NSMutableAttributedString alloc] initWithAttributedString:object];
[cellValue removeAttribute:NSBaselineOffsetAttributeName range:NSMakeRange(0,1)];
[cellValue removeAttribute:NSAttachmentAttributeName range:NSMakeRange(0,strLen)];
// extract the unicode
strLen = [cellValue length];
PRUnichar* buffer = new PRUnichar[strLen + 1];
buffer[strLen] = '\0';
if ( !buffer )
return;
[cellValue getCharacters: buffer];
nsAutoString nameAttr;
nameAttr.Adopt(buffer);
// stash it into the dom.
nsIContent* content = [item contentNode];
content->SetAttr(kNameSpaceID_None, BookmarksService::gNameAtom, nameAttr, PR_TRUE);
[cellValue release];
}
#endif
}
- (BOOL)outlineView:(NSOutlineView *)ov writeItems:(NSArray*)items toPasteboard:(NSPasteboard*)pboard
{
if (!mBookmarks || [mOutlineView selectedRow] == -1) {
return NO;
}
#ifdef FILTER_DESCENDANT_ON_DRAG
NSArray *toDrag = BookmarksService::FilterOutDescendantsForDrag(items);
#else
NSArray *toDrag = items;
#endif
int count = [toDrag count];
if (count > 0) {
// Create Pasteboard Data
NSMutableArray *draggedID = [NSMutableArray arrayWithCapacity: count];
for (int i = 0; i < count; i++)
[draggedID addObject: [[toDrag objectAtIndex: i] contentID]];
[pboard declareTypes: [NSArray arrayWithObject: @"MozBookmarkType"] owner: self];
[pboard setPropertyList: draggedID forType: @"MozBookmarkType"];
return YES;
}
return NO;
}
- (NSDragOperation)outlineView:(NSOutlineView*)ov validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(int)index
{
NSArray* types = [[info draggingPasteboard] types];
// if the index is -1, deny the drop
if (index == NSOutlineViewDropOnItemIndex)
return NSDragOperationNone;
if ([types containsObject: @"MozBookmarkType"]) {
NSArray *draggedIDs = [[info draggingPasteboard] propertyListForType: @"MozBookmarkType"];
BookmarkItem* parent;
parent = (item) ? item : BookmarksService::GetRootItem();
return (BookmarksService::IsBookmarkDropValid(parent, index, draggedIDs)) ? NSDragOperationGeneric : NSDragOperationNone;
} else if ([types containsObject: @"MozURLType"]) {
return NSDragOperationGeneric;
}
return NSDragOperationNone;
}
- (BOOL)outlineView:(NSOutlineView*)ov acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(int)index {
NSArray *types = [[info draggingPasteboard] types];
BookmarkItem* parent = (item) ? item : BookmarksService::GetRootItem();
if ([types containsObject: @"MozBookmarkType"]) {
NSArray *draggedItems = [[info draggingPasteboard] propertyListForType: @"MozBookmarkType"];
BookmarksService::PerformBookmarkDrop(parent, index, draggedItems);
return YES;
}
else if ([types containsObject: @"MozURLType"]) {
NSDictionary* proxy = [[info draggingPasteboard] propertyListForType: @"MozURLType"];
BookmarkItem* beforeItem = [self outlineView:ov child:index ofItem:item];
return BookmarksService::PerformProxyDrop(parent, beforeItem, proxy);
}
return NO;
}
- (void)reloadDataForItem:(id)item reloadChildren: (BOOL)aReloadChildren
{
if (!item)
[mOutlineView reloadData];
else if ([mOutlineView isItemExpanded: item])
[mOutlineView reloadItem: item reloadChildren: aReloadChildren];
}
-(IBAction)openBookmarkInNewTab:(id)aSender
{
int index = [mOutlineView selectedRow];
if (index == -1)
return;
if ([mOutlineView numberOfSelectedRows] == 1) {
nsCOMPtr<nsIPrefBranch> pref(do_GetService("@mozilla.org/preferences-service;1"));
if (!pref)
return; // Something bad happened if we can't get prefs.
BookmarkItem* item = [mOutlineView itemAtRow: index];
nsAutoString hrefAttr;
[item contentNode]->GetAttr(kNameSpaceID_None, BookmarksService::gHrefAtom, hrefAttr);
// stuff it into the string
NSString* hrefStr = [NSString stringWithCharacters:hrefAttr.get() length:hrefAttr.Length()];
PRBool loadInBackground;
pref->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground);
[mBrowserWindowController openNewTabWithURL: hrefStr loadInBackground: loadInBackground];
}
}
-(IBAction)openBookmarkInNewWindow:(id)aSender
{
int index = [mOutlineView selectedRow];
if (index == -1)
return;
if ([mOutlineView numberOfSelectedRows] == 1) {
BookmarkItem* item = [mOutlineView itemAtRow: index];
nsAutoString hrefAttr;
[item contentNode]->GetAttr(kNameSpaceID_None, BookmarksService::gHrefAtom, hrefAttr);
// stuff it into the string
NSString* hrefStr = [NSString stringWithCharacters:hrefAttr.get() length:hrefAttr.Length()];
nsAutoString group;
[item contentNode]->GetAttr(kNameSpaceID_None, BookmarksService::gGroupAtom, group);
if (group.IsEmpty())
[mBrowserWindowController openNewWindowWithURL: hrefStr loadInBackground: NO];
else {
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface([item contentNode]));
[mBrowserWindowController openNewWindowWithGroup: elt loadInBackground: NO];
}
}
}
-(void)openBookmarkGroup:(id)aTabView groupElement:(nsIDOMElement*)aFolder
{
mBookmarks->OpenBookmarkGroup(aTabView, aFolder);
}
-(IBAction)showBookmarkInfo:(id)aSender
{
if (!mBookmarkInfoController)
mBookmarkInfoController = [[BookmarkInfoController alloc] initWithOutlineView: mOutlineView];
[mBookmarkInfoController showWindow:mBookmarkInfoController];
int index = [mOutlineView selectedRow];
BookmarkItem* item = [mOutlineView itemAtRow: index];
[mBookmarkInfoController setBookmark:item];
}
-(void)outlineViewSelectionDidChange: (NSNotification*) aNotification
{
int index = [mOutlineView selectedRow];
if (index == -1) {
if (mBookmarkInfoController)
[mBookmarkInfoController setBookmark:NULL];
}
else {
BookmarkItem* item = [mOutlineView itemAtRow:index];
if (mBookmarkInfoController)
[mBookmarkInfoController setBookmark:item];
}
}
-(BOOL)validateMenuItem:(NSMenuItem*)aMenuItem
{
int index = [mOutlineView selectedRow];
if (index == -1)
return NO;
BookmarkItem* item = [mOutlineView itemAtRow: index];
BOOL isBookmark = [mOutlineView isExpandable:item] == NO;
nsAutoString group;
[item contentNode]->GetAttr(kNameSpaceID_None, BookmarksService::gGroupAtom, group);
BOOL isGroup = !group.IsEmpty();
if (([aMenuItem action] == @selector(openBookmarkInNewWindow:))) {
// Bookmarks and Bookmark Groups can be opened in a new window
return (isBookmark || isGroup);
}
else if (([aMenuItem action] == @selector(openBookmarkInNewTab:))) {
// Only Bookmarks can be opened in new tabs
return isBookmark;
}
return YES;
}
- (void)outlineViewItemWillExpand:(NSNotification *)notification
{
BookmarkItem* item = [[notification userInfo] objectForKey:[[[notification userInfo] allKeys] objectAtIndex: 0]];
[item contentNode]->SetAttr(kNameSpaceID_None, BookmarksService::gOpenAtom, NS_LITERAL_STRING("true"), PR_FALSE);
}
- (void)outlineViewItemWillCollapse:(NSNotification *)notification
{
BookmarkItem* item = [[notification userInfo] objectForKey:[[[notification userInfo] allKeys] objectAtIndex: 0]];
[item contentNode]->UnsetAttr(kNameSpaceID_None, BookmarksService::gOpenAtom, PR_FALSE);
}
@end
@implementation BookmarkItem
-(nsIContent*)contentNode
{
return mContentNode;
}
- (NSNumber*)contentID
{
PRUint32 contentID = 0;
mContentNode->GetContentID(&contentID);
return [NSNumber numberWithInt: contentID];
}
- (NSString *)description
{
nsCOMPtr<nsIContent> item = [self contentNode];
nsCOMPtr<nsIDOMElement> element(do_QueryInterface(item));
nsAutoString href;
element->GetAttribute(NS_LITERAL_STRING("name"), href);
NSString* info = [NSString stringWithCharacters: href.get() length: href.Length()];
return [NSString stringWithFormat:@"<BookmarkItem, name = \"%@\">", info];
}
-(void)setContentNode: (nsIContent*)aContentNode
{
mContentNode = aContentNode;
}
- (id)copyWithZone:(NSZone *)aZone
{
BookmarkItem* copy = [[[self class] allocWithZone: aZone] init];
[copy setContentNode: mContentNode];
return copy;
}
@end

Просмотреть файл

@ -37,88 +37,22 @@
#include <Appkit/Appkit.h>
#include <Carbon/Carbon.h>
#include "nsCOMPtr.h"
#include "nsIDocument.h"
#include "nsIDocumentObserver.h"
#include "nsVoidArray.h"
#import "MainController.h"
#import "CHBookmarksToolbar.h"
#import "CHExtendedOutlineView.h"
@class BookmarkItem;
class BookmarksService;
class nsIAtom;
@class BookmarkInfoController;
@interface BookmarksDataSource : NSObject
{
BookmarksService* mBookmarks;
IBOutlet id mOutlineView;
IBOutlet id mBrowserWindowController;
NSString* mCachedHref;
BookmarkInfoController* mBookmarkInfoController;
}
-(id) init;
-(void) dealloc;
-(void) windowClosing;
-(void) ensureBookmarks;
-(IBAction)addBookmark:(id)aSender;
-(void)endAddBookmark: (int)aCode;
-(IBAction)deleteBookmarks: (id)aSender;
-(void)deleteBookmark: (id)aItem;
-(IBAction)addFolder:(id)aSender;
-(void)addBookmark:(id)aSender useSelection:(BOOL)aSel isFolder:(BOOL)aIsFolder;
-(NSString*)resolveKeyword:(NSString*)aKeyword;
-(IBAction)openBookmarkInNewTab:(id)aSender;
-(IBAction)openBookmarkInNewWindow:(id)aSender;
-(void)openBookmarkGroup:(id)aTabView groupElement:(nsIDOMElement*)aFolder;
-(IBAction)showBookmarkInfo:(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;
- (BOOL)outlineView:(NSOutlineView *)ov writeItems:(NSArray*)items toPasteboard:(NSPasteboard*)pboard;
- (NSDragOperation)outlineView:(NSOutlineView*)ov validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(int)index;
- (BOOL)outlineView:(NSOutlineView*)ov acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(int)index;
- (void)reloadDataForItem:(id)item reloadChildren: (BOOL)aReloadChildren;
// Delegate methods
- (void)outlineViewItemWillExpand:(NSNotification *)notification;
- (void)outlineViewItemWillCollapse:(NSNotification *)notification;
@end
@interface BookmarkItem : NSObject
{
nsIContent* mContentNode;
}
- (nsIContent*)contentNode;
- (void)setContentNode: (nsIContent*)aContentNode;
- (NSNumber*)contentID;
- (id)copyWithZone:(NSZone *)aZone;
@end
class nsIDOMHTMLDocument;
@class BookmarksDataSource;
@class BookmarkItem;
class BookmarksService
{
public:
@ -142,6 +76,8 @@ public:
static BookmarkItem* GetRootItem();
static BookmarkItem* GetWrapperFor(nsIContent* aItem);
static BookmarkItem* GetWrapperFor(PRUint32 contentID);
static void ReadBookmarks();
static void FlushBookmarks();
static void ConstructBookmarksMenu(NSMenu* aMenu, nsIContent* aContent);
@ -189,6 +125,7 @@ public:
static nsIAtom* gOpenAtom;
static nsIAtom* gGroupAtom;
static nsIDocument* gBookmarks;
static BOOL gBookmarksFileReadOK;
static nsVoidArray* gInstances;
static int CHInsertNone;
static int CHInsertInto;

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -584,6 +584,9 @@ static NSString *SearchToolbarItemIdentifier = @"Search Toolbar Item";
[newView setIsBookmarksImport: YES];
[[[self window] contentView] addSubview: newView];
[[newView getBrowserView] loadURI:aURLSpec flags:NSLoadFlagsNone];
// XXX force reload
//[mSidebarBookmarksDataSource reloadDataForItem: nil reloadChildren: YES];
}
- (IBAction)goToLocationFromToolbarURLField:(id)sender

Просмотреть файл

@ -23,6 +23,8 @@
#import "CHBookmarksOutlineView.h"
#import "BookmarksService.h"
#import "BookmarksDataSource.h"
#include "nsCOMPtr.h"
#include "nsIDOMElement.h"
#include "nsIContent.h"

Просмотреть файл

@ -25,6 +25,8 @@
#import "CHBookmarksButton.h"
#import "CHBookmarksToolbar.h"
#import "BookmarksService.h"
#import "BookmarksDataSource.h"
#include "nsIDOMElement.h"
#include "nsIContent.h"

Просмотреть файл

@ -17,6 +17,8 @@
#import "CHExtendedTabView.h"
#import "BookmarksService.h"
#import "BookmarksDataSource.h"
#include "nsCOMPtr.h"
#include "nsIDOMElement.h"
#include "nsIContent.h"

Просмотреть файл

@ -7,6 +7,9 @@
objects = {
080E96DDFE201D6D7F000001 = {
children = (
F5A3669402CCFAF601DC3354,
F5A3669602CCFAF601DC3354,
F5A3669702CCFAF601DC3354,
F5DE10E90209DC0601A967DF,
F517395B020CE3740189DA0C,
F528E21A020FD9620168DE43,
@ -18,18 +21,10 @@
F52D5CD8027D3D5001A80166,
F6BA6D4E01B2F8A601A962F7,
F56769FB0208F74A010001CA,
F507BA4C0213AFF701D93544,
F57074B6026BA85F01A80166,
F57074BA026BFD0101A80166,
F57074BE026D80DF01A80166,
2E2939FF027F33604B000102,
F59E9F3F0237E43401A967DF,
F52D5CD0027A887001A80166,
F52D5CD4027A88C601A80166,
F52F87CD027D75C301A80165,
F52F87CE027D75C301A80165,
2E748B73029A448D4B000102,
F53E012C02AEE93601A967F3,
);
isa = PBXGroup;
name = Classes;
@ -452,6 +447,7 @@
F53E013302AEEA2901A967F3,
F632AF8502B9AEBB01000103,
F59236C202C89ACA0100012B,
F5A3669802CCFAF601DC3354,
);
isa = PBXHeadersBuildPhase;
name = Headers;
@ -538,6 +534,7 @@
F517395D020CE3750189DA0C,
F528E21B020FD9620168DE43,
F507BA4D0213AFF701D93544,
F5A3669902CCFAF601DC3354,
F53F220E022B7C78010001CA,
F53F220F022B7C78010001CA,
F53F2210022B7C78010001CA,
@ -646,13 +643,6 @@
settings = {
};
};
2EEC3E6002810B184B000102 = {
indentWidth = 2;
isa = PBXFileReference;
path = CHExtendedTabView.m;
refType = 4;
usesTabs = 0;
};
2EEC3E61028138714B000102 = {
isa = PBXFileReference;
path = CHBookmarksOutlineView.h;
@ -948,6 +938,8 @@
};
F50E1BC90207F99201F281DF = {
children = (
F5C321D402CBD01C014E7D56,
F5C321D002CBCEF7014E7D56,
F50E1BCA0207F99201F281DF,
F51D9B0A020940C101A80166,
);
@ -1216,6 +1208,7 @@
2E748B72029A448D4B000102,
F53E012902AEE91C01A967F3,
F53E013202AEEA2801A967F3,
F5A3669302CCFAF601DC3354,
);
isa = PBXGroup;
name = Headers;
@ -1287,6 +1280,7 @@
children = (
F51D9B0B020940C101A80166,
F51D9B0D0209421401A80166,
F5C321D702CBD0CE014E7D56,
);
isa = PBXGroup;
name = xul;
@ -2681,14 +2675,11 @@
F5571935022B401B010001CA = {
children = (
F5BF71450231B8BC010001CA,
2EEC3E6002810B184B000102,
F5BF71460231B8BC010001CA,
F5648739023C3857010001CA,
F564873A023C3857010001CA,
F5C3AB810270072A01A80166,
F5C3AB820270072A01A80166,
2EEC3E61028138714B000102,
2EEC3E62028138714B000102,
F541495A02711A8301A80166,
F541495B02711A8301A80166,
F541495E02711B0001A80166,
@ -4183,6 +4174,79 @@
settings = {
};
};
F5A3669302CCFAF601DC3354 = {
isa = PBXFileReference;
path = BookmarksDataSource.h;
refType = 4;
};
F5A3669402CCFAF601DC3354 = {
children = (
F507BA4C0213AFF701D93544,
F5A3669502CCFAF601DC3354,
F57074B6026BA85F01A80166,
F57074BA026BFD0101A80166,
F53E012C02AEE93601A967F3,
2EEC3E61028138714B000102,
2EEC3E62028138714B000102,
);
isa = PBXGroup;
name = Bookmarks;
refType = 4;
};
F5A3669502CCFAF601DC3354 = {
isa = PBXFileReference;
path = BookmarksDataSource.mm;
refType = 4;
};
F5A3669602CCFAF601DC3354 = {
children = (
F52F87CD027D75C301A80165,
F52F87CE027D75C301A80165,
);
isa = PBXGroup;
name = History;
path = "";
refType = 4;
};
F5A3669702CCFAF601DC3354 = {
children = (
F52D5CD0027A887001A80166,
F52D5CD4027A88C601A80166,
);
isa = PBXGroup;
name = Autocomplete;
refType = 4;
};
F5A3669802CCFAF601DC3354 = {
fileRef = F5A3669302CCFAF601DC3354;
isa = PBXBuildFile;
settings = {
};
};
F5A3669902CCFAF601DC3354 = {
fileRef = F5A3669502CCFAF601DC3354;
isa = PBXBuildFile;
settings = {
};
};
F5A3669A02CCFB7A01DC3354 = {
fileRef = F5A3669302CCFAF601DC3354;
isa = PBXBuildFile;
settings = {
};
};
F5A3669B02CCFB7A01DC3354 = {
fileRef = F632AF8402B9AEBB01000103;
isa = PBXBuildFile;
settings = {
};
};
F5A3669C02CCFB7A01DC3354 = {
fileRef = F5A3669502CCFAF601DC3354;
isa = PBXBuildFile;
settings = {
};
};
F5AC38BA02AD8E7B01A967F3 = {
fileRef = F5C2CDA702383CE601A967DF;
isa = PBXBuildFile;
@ -4426,6 +4490,7 @@
F53E012B02AEE91D01A967F3,
F53E013402AEEA2901A967F3,
F59236C402C89ACA0100012B,
F5A3669A02CCFB7A01DC3354,
);
isa = PBXHeadersBuildPhase;
name = Headers;
@ -4538,6 +4603,8 @@
F56F242102AC6D0401A967F3,
F53E012E02AEE93701A967F3,
F59236C502C89ACA0100012B,
F5A3669B02CCFB7A01DC3354,
F5A3669C02CCFB7A01DC3354,
);
isa = PBXSourcesBuildPhase;
name = Sources;
@ -6259,6 +6326,24 @@
settings = {
};
};
F5C321D002CBCEF7014E7D56 = {
isa = PBXFileReference;
name = nsXBLService.cpp;
path = /Volumes/Development/Projects/Mozilla/Chimera/mozilla/content/xbl/src/nsXBLService.cpp;
refType = 0;
};
F5C321D402CBD01C014E7D56 = {
isa = PBXFileReference;
name = xmlparse.c;
path = /Volumes/Development/Projects/Mozilla/Chimera/mozilla/expat/xmlparse/xmlparse.c;
refType = 0;
};
F5C321D702CBD0CE014E7D56 = {
isa = PBXFileReference;
name = nsXMLContentSink.cpp;
path = /Volumes/Development/Projects/Mozilla/Chimera/mozilla/content/xml/document/src/nsXMLContentSink.cpp;
refType = 0;
};
F5C3AB810270072A01A80166 = {
isa = PBXFileReference;
path = CHExtendedOutlineView.h;

Двоичные данные
chimera/English.lproj/Localizable.strings

Двоичный файл не отображается.

4
chimera/English.lproj/MainMenu.nib/info.nib сгенерированный
Просмотреть файл

@ -3,13 +3,13 @@
<plist version="0.9">
<dict>
<key>IBDocumentLocation</key>
<string>85 201 356 240 0 0 1280 1002 </string>
<string>73 133 356 240 0 0 1152 746 </string>
<key>IBEditorPositions</key>
<dict>
<key>266</key>
<string>418 452 277 90 0 0 1152 746 </string>
<key>29</key>
<string>11 957 446 44 0 0 1280 1002 </string>
<string>9 701 446 44 0 0 1152 746 </string>
</dict>
<key>IBFramework Version</key>
<string>248.0</string>

Двоичные данные
chimera/English.lproj/MainMenu.nib/objects.nib сгенерированный

Двоичный файл не отображается.

4
chimera/MainMenu.nib/info.nib сгенерированный
Просмотреть файл

@ -3,13 +3,13 @@
<plist version="0.9">
<dict>
<key>IBDocumentLocation</key>
<string>85 201 356 240 0 0 1280 1002 </string>
<string>73 133 356 240 0 0 1152 746 </string>
<key>IBEditorPositions</key>
<dict>
<key>266</key>
<string>418 452 277 90 0 0 1152 746 </string>
<key>29</key>
<string>11 957 446 44 0 0 1280 1002 </string>
<string>9 701 446 44 0 0 1152 746 </string>
</dict>
<key>IBFramework Version</key>
<string>248.0</string>

Двоичные данные
chimera/MainMenu.nib/objects.nib сгенерированный

Двоичный файл не отображается.

Просмотреть файл

@ -16,6 +16,7 @@
ACTIONS = {
checkboxClicked = id;
checkboxStartPageClicked = id;
checkboxUseSystemHomePageClicked = id;
clearGlobalHistory = id;
historyDaysModified = id;
openSystemInternetPanel = id;
@ -23,12 +24,13 @@
CLASS = OrgMozillaChimeraPreferenceNavigation;
LANGUAGE = ObjC;
OUTLETS = {
buttonSystemPreferences = NSButton;
checkboxNewTabBlank = NSButton;
checkboxNewWindowBlank = NSButton;
checkboxOpenTabs = NSButton;
checkboxUseSystemHomePage = NSButton;
sliderHistoryDays = NSSlider;
textFieldHistoryDays = NSTextField;
textFieldHomePage = NSTextField;
};
SUPERCLASS = NSPreferencePane;
}

Просмотреть файл

@ -3,7 +3,7 @@
<plist version="0.9">
<dict>
<key>IBDocumentLocation</key>
<string>56 65 356 240 0 0 1152 848 </string>
<string>36 50 356 240 0 0 1152 746 </string>
<key>IBFramework Version</key>
<string>248.0</string>
<key>IBGroupedObjects</key>
@ -22,6 +22,6 @@
<integer>5</integer>
</array>
<key>IBSystem Version</key>
<string>5Q125</string>
<string>5S66</string>
</dict>
</plist>

Двоичные данные
chimera/PreferencePanes/Navigation/English.lproj/Navigation.nib/objects.nib сгенерированный

Двоичный файл не отображается.

Просмотреть файл

@ -28,7 +28,9 @@ class nsIPref;
@interface OrgMozillaChimeraPreferenceNavigation : NSPreferencePane
{
IBOutlet NSButton *buttonSystemPreferences;
// IBOutlet NSButton *buttonSystemPreferences;
IBOutlet NSTextField *textFieldHomePage;
IBOutlet NSButton *checkboxUseSystemHomePage;
IBOutlet NSButton *checkboxNewTabBlank;
IBOutlet NSButton *checkboxNewWindowBlank;
IBOutlet NSButton *checkboxOpenTabs;
@ -37,9 +39,12 @@ class nsIPref;
nsIPref* mPrefService; // strong, but can't use a comptr here
}
- (IBAction)openSystemInternetPanel:(id)sender;
- (IBAction)checkboxClicked:(id)sender;
- (IBAction)checkboxUseSystemHomePageClicked:(id)sender;
- (IBAction)checkboxStartPageClicked:(id)sender;
- (IBAction)historyDaysModified:(id)sender;
- (IBAction)clearGlobalHistory:(id)sender;
@end

Просмотреть файл

@ -74,6 +74,15 @@ const int kDefaultExpireDays = 9;
rv = mPrefService->GetBoolPref("browser.tabs.opentabfor.middleclick", &boolPref);
if (NS_SUCCEEDED(rv) && boolPref == PR_TRUE)
[checkboxOpenTabs setState:YES];
char *buf = nsnull;
rv = mPrefService->GetCharPref("browser.startup.homepage", &buf);
if (NS_SUCCEEDED(rv) && buf)
{
[textFieldHomePage setStringValue:[NSString stringWithCString:buf]];
free(buf);
}
}
- (IBAction)openSystemInternetPanel:(id)sender
@ -92,6 +101,11 @@ const int kDefaultExpireDays = 9;
mPrefService->SetBoolPref("browser.tabs.opentabfor.middleclick", [sender state] ? PR_TRUE : PR_FALSE);
}
- (IBAction)checkboxUseSystemHomePageClicked:(id)sender
{
NSLog(@"Homepage clicked");
}
- (IBAction)checkboxStartPageClicked:(id)sender
{
if (!mPrefService)

Просмотреть файл

@ -16,6 +16,7 @@
ACTIONS = {
checkboxClicked = id;
checkboxStartPageClicked = id;
checkboxUseSystemHomePageClicked = id;
clearGlobalHistory = id;
historyDaysModified = id;
openSystemInternetPanel = id;
@ -23,12 +24,13 @@
CLASS = OrgMozillaChimeraPreferenceNavigation;
LANGUAGE = ObjC;
OUTLETS = {
buttonSystemPreferences = NSButton;
checkboxNewTabBlank = NSButton;
checkboxNewWindowBlank = NSButton;
checkboxOpenTabs = NSButton;
checkboxUseSystemHomePage = NSButton;
sliderHistoryDays = NSSlider;
textFieldHistoryDays = NSTextField;
textFieldHomePage = NSTextField;
};
SUPERCLASS = NSPreferencePane;
}

Просмотреть файл

@ -3,7 +3,7 @@
<plist version="0.9">
<dict>
<key>IBDocumentLocation</key>
<string>56 65 356 240 0 0 1152 848 </string>
<string>36 50 356 240 0 0 1152 746 </string>
<key>IBFramework Version</key>
<string>248.0</string>
<key>IBGroupedObjects</key>
@ -22,6 +22,6 @@
<integer>5</integer>
</array>
<key>IBSystem Version</key>
<string>5Q125</string>
<string>5S66</string>
</dict>
</plist>

Двоичные данные
chimera/PreferencePanes/Navigation/Navigation.nib/objects.nib сгенерированный

Двоичный файл не отображается.

Просмотреть файл

@ -7,6 +7,9 @@
objects = {
080E96DDFE201D6D7F000001 = {
children = (
F5A3669402CCFAF601DC3354,
F5A3669602CCFAF601DC3354,
F5A3669702CCFAF601DC3354,
F5DE10E90209DC0601A967DF,
F517395B020CE3740189DA0C,
F528E21A020FD9620168DE43,
@ -18,18 +21,10 @@
F52D5CD8027D3D5001A80166,
F6BA6D4E01B2F8A601A962F7,
F56769FB0208F74A010001CA,
F507BA4C0213AFF701D93544,
F57074B6026BA85F01A80166,
F57074BA026BFD0101A80166,
F57074BE026D80DF01A80166,
2E2939FF027F33604B000102,
F59E9F3F0237E43401A967DF,
F52D5CD0027A887001A80166,
F52D5CD4027A88C601A80166,
F52F87CD027D75C301A80165,
F52F87CE027D75C301A80165,
2E748B73029A448D4B000102,
F53E012C02AEE93601A967F3,
);
isa = PBXGroup;
name = Classes;
@ -452,6 +447,7 @@
F53E013302AEEA2901A967F3,
F632AF8502B9AEBB01000103,
F59236C202C89ACA0100012B,
F5A3669802CCFAF601DC3354,
);
isa = PBXHeadersBuildPhase;
name = Headers;
@ -538,6 +534,7 @@
F517395D020CE3750189DA0C,
F528E21B020FD9620168DE43,
F507BA4D0213AFF701D93544,
F5A3669902CCFAF601DC3354,
F53F220E022B7C78010001CA,
F53F220F022B7C78010001CA,
F53F2210022B7C78010001CA,
@ -646,13 +643,6 @@
settings = {
};
};
2EEC3E6002810B184B000102 = {
indentWidth = 2;
isa = PBXFileReference;
path = CHExtendedTabView.m;
refType = 4;
usesTabs = 0;
};
2EEC3E61028138714B000102 = {
isa = PBXFileReference;
path = CHBookmarksOutlineView.h;
@ -948,6 +938,8 @@
};
F50E1BC90207F99201F281DF = {
children = (
F5C321D402CBD01C014E7D56,
F5C321D002CBCEF7014E7D56,
F50E1BCA0207F99201F281DF,
F51D9B0A020940C101A80166,
);
@ -1216,6 +1208,7 @@
2E748B72029A448D4B000102,
F53E012902AEE91C01A967F3,
F53E013202AEEA2801A967F3,
F5A3669302CCFAF601DC3354,
);
isa = PBXGroup;
name = Headers;
@ -1287,6 +1280,7 @@
children = (
F51D9B0B020940C101A80166,
F51D9B0D0209421401A80166,
F5C321D702CBD0CE014E7D56,
);
isa = PBXGroup;
name = xul;
@ -2681,14 +2675,11 @@
F5571935022B401B010001CA = {
children = (
F5BF71450231B8BC010001CA,
2EEC3E6002810B184B000102,
F5BF71460231B8BC010001CA,
F5648739023C3857010001CA,
F564873A023C3857010001CA,
F5C3AB810270072A01A80166,
F5C3AB820270072A01A80166,
2EEC3E61028138714B000102,
2EEC3E62028138714B000102,
F541495A02711A8301A80166,
F541495B02711A8301A80166,
F541495E02711B0001A80166,
@ -4183,6 +4174,79 @@
settings = {
};
};
F5A3669302CCFAF601DC3354 = {
isa = PBXFileReference;
path = BookmarksDataSource.h;
refType = 4;
};
F5A3669402CCFAF601DC3354 = {
children = (
F507BA4C0213AFF701D93544,
F5A3669502CCFAF601DC3354,
F57074B6026BA85F01A80166,
F57074BA026BFD0101A80166,
F53E012C02AEE93601A967F3,
2EEC3E61028138714B000102,
2EEC3E62028138714B000102,
);
isa = PBXGroup;
name = Bookmarks;
refType = 4;
};
F5A3669502CCFAF601DC3354 = {
isa = PBXFileReference;
path = BookmarksDataSource.mm;
refType = 4;
};
F5A3669602CCFAF601DC3354 = {
children = (
F52F87CD027D75C301A80165,
F52F87CE027D75C301A80165,
);
isa = PBXGroup;
name = History;
path = "";
refType = 4;
};
F5A3669702CCFAF601DC3354 = {
children = (
F52D5CD0027A887001A80166,
F52D5CD4027A88C601A80166,
);
isa = PBXGroup;
name = Autocomplete;
refType = 4;
};
F5A3669802CCFAF601DC3354 = {
fileRef = F5A3669302CCFAF601DC3354;
isa = PBXBuildFile;
settings = {
};
};
F5A3669902CCFAF601DC3354 = {
fileRef = F5A3669502CCFAF601DC3354;
isa = PBXBuildFile;
settings = {
};
};
F5A3669A02CCFB7A01DC3354 = {
fileRef = F5A3669302CCFAF601DC3354;
isa = PBXBuildFile;
settings = {
};
};
F5A3669B02CCFB7A01DC3354 = {
fileRef = F632AF8402B9AEBB01000103;
isa = PBXBuildFile;
settings = {
};
};
F5A3669C02CCFB7A01DC3354 = {
fileRef = F5A3669502CCFAF601DC3354;
isa = PBXBuildFile;
settings = {
};
};
F5AC38BA02AD8E7B01A967F3 = {
fileRef = F5C2CDA702383CE601A967DF;
isa = PBXBuildFile;
@ -4426,6 +4490,7 @@
F53E012B02AEE91D01A967F3,
F53E013402AEEA2901A967F3,
F59236C402C89ACA0100012B,
F5A3669A02CCFB7A01DC3354,
);
isa = PBXHeadersBuildPhase;
name = Headers;
@ -4538,6 +4603,8 @@
F56F242102AC6D0401A967F3,
F53E012E02AEE93701A967F3,
F59236C502C89ACA0100012B,
F5A3669B02CCFB7A01DC3354,
F5A3669C02CCFB7A01DC3354,
);
isa = PBXSourcesBuildPhase;
name = Sources;
@ -6259,6 +6326,24 @@
settings = {
};
};
F5C321D002CBCEF7014E7D56 = {
isa = PBXFileReference;
name = nsXBLService.cpp;
path = /Volumes/Development/Projects/Mozilla/Chimera/mozilla/content/xbl/src/nsXBLService.cpp;
refType = 0;
};
F5C321D402CBD01C014E7D56 = {
isa = PBXFileReference;
name = xmlparse.c;
path = /Volumes/Development/Projects/Mozilla/Chimera/mozilla/expat/xmlparse/xmlparse.c;
refType = 0;
};
F5C321D702CBD0CE014E7D56 = {
isa = PBXFileReference;
name = nsXMLContentSink.cpp;
path = /Volumes/Development/Projects/Mozilla/Chimera/mozilla/content/xml/document/src/nsXMLContentSink.cpp;
refType = 0;
};
F5C3AB810270072A01A80166 = {
isa = PBXFileReference;
path = CHExtendedOutlineView.h;

Двоичный файл не отображается.

Просмотреть файл

@ -3,13 +3,13 @@
<plist version="0.9">
<dict>
<key>IBDocumentLocation</key>
<string>85 201 356 240 0 0 1280 1002 </string>
<string>73 133 356 240 0 0 1152 746 </string>
<key>IBEditorPositions</key>
<dict>
<key>266</key>
<string>418 452 277 90 0 0 1152 746 </string>
<key>29</key>
<string>11 957 446 44 0 0 1280 1002 </string>
<string>9 701 446 44 0 0 1152 746 </string>
</dict>
<key>IBFramework Version</key>
<string>248.0</string>

Двоичные данные
chimera/resources/localized/English.lproj/MainMenu.nib/objects.nib сгенерированный

Двоичный файл не отображается.

Просмотреть файл

@ -22,6 +22,8 @@
*/
#import "BookmarkInfoController.h"
#import "BookmarksDataSource.h"
#include "nsIContent.h"
#include "nsINamespaceManager.h"

Просмотреть файл

@ -0,0 +1,118 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Simon Fraser <sfraser@netscape.com>
*
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#import <Foundation/Foundation.h>
#import <Appkit/Appkit.h>
#import "MainController.h"
#import "CHBookmarksToolbar.h"
#import "CHExtendedOutlineView.h"
class nsIContent;
class BookmarksService;
@class BookmarkInfoController;
@interface BookmarksDataSource : NSObject
{
BookmarksService* mBookmarks;
IBOutlet id mOutlineView;
IBOutlet id mBrowserWindowController;
NSString* mCachedHref;
BookmarkInfoController* mBookmarkInfoController;
}
-(id) init;
-(void) dealloc;
-(void) windowClosing;
-(void) ensureBookmarks;
-(IBAction)addBookmark:(id)aSender;
-(void)endAddBookmark: (int)aCode;
-(IBAction)deleteBookmarks: (id)aSender;
-(void)deleteBookmark: (id)aItem;
-(IBAction)addFolder:(id)aSender;
-(void)addBookmark:(id)aSender useSelection:(BOOL)aSel isFolder:(BOOL)aIsFolder;
-(NSString*)resolveKeyword:(NSString*)aKeyword;
-(IBAction)openBookmarkInNewTab:(id)aSender;
-(IBAction)openBookmarkInNewWindow:(id)aSender;
-(void)openBookmarkGroup:(id)aTabView groupElement:(nsIDOMElement*)aFolder;
-(IBAction)showBookmarkInfo:(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;
- (BOOL)outlineView:(NSOutlineView *)ov writeItems:(NSArray*)items toPasteboard:(NSPasteboard*)pboard;
- (NSDragOperation)outlineView:(NSOutlineView*)ov validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(int)index;
- (BOOL)outlineView:(NSOutlineView*)ov acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(int)index;
- (void)reloadDataForItem:(id)item reloadChildren: (BOOL)aReloadChildren;
// Delegate methods
- (void)outlineViewItemWillExpand:(NSNotification *)notification;
- (void)outlineViewItemWillCollapse:(NSNotification *)notification;
@end
@interface BookmarkItem : NSObject
{
nsIContent* mContentNode;
}
- (nsIContent*)contentNode;
- (void)setContentNode: (nsIContent*)aContentNode;
- (NSNumber*)contentID;
- (id)copyWithZone:(NSZone *)aZone;
@end

Просмотреть файл

@ -0,0 +1,764 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Simon Fraser <sfraser@netscape.com>
*
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#import "BookmarksDataSource.h"
#import "BookmarkInfoController.h"
#include "nsCOMPtr.h"
#include "nsIContent.h"
#include "nsIDocument.h"
#include "nsIDocumentObserver.h"
#include "nsIDOMDocument.h"
#include "nsIDOMElement.h"
#include "nsINamespaceManager.h"
#include "nsIPrefBranch.h"
#include "nsIServiceManager.h"
#include "nsVoidArray.h"
#import "BookmarksService.h"
@implementation BookmarksDataSource
-(id) init
{
if ( (self = [super init]) ) {
mBookmarks = nsnull;
mCachedHref = nil;
}
return self;
}
-(void) dealloc
{
[mBookmarkInfoController release];
[super dealloc];
}
-(void) windowClosing
{
if (mBookmarks) {
mBookmarks->RemoveObserver();
delete mBookmarks;
}
}
-(void) ensureBookmarks
{
if (mBookmarks)
return;
mBookmarks = new BookmarksService(self);
mBookmarks->AddObserver();
[mOutlineView setTarget: self];
[mOutlineView setDoubleAction: @selector(openBookmark:)];
[mOutlineView setDeleteAction: @selector(deleteBookmarks:)];
[mOutlineView reloadData];
}
-(IBAction)addBookmark:(id)aSender
{
[self addBookmark: aSender useSelection: YES isFolder: NO];
}
-(IBAction)addFolder:(id)aSender
{
[self addBookmark: aSender useSelection: YES isFolder: YES];
}
-(void)addBookmark:(id)aSender useSelection:(BOOL)aUseSel isFolder:(BOOL)aIsFolder
{
if (!mBookmarks)
return;
// We use the selected item to determine the parent only if aUseSel is YES.
BookmarkItem* item = nil;
if (aUseSel && ([mOutlineView numberOfSelectedRows] == 1)) {
// There is only one selected row. If it is a folder, use it as our parent.
// Otherwise, use our parent,
int index = [mOutlineView selectedRow];
item = [mOutlineView itemAtRow: index];
if (![mOutlineView isExpandable: item]) {
// We can't be used as the parent. Try our parent.
nsIContent* content = [item contentNode];
if (!content)
return;
nsCOMPtr<nsIContent> parentContent;
content->GetParent(*getter_AddRefs(parentContent));
nsCOMPtr<nsIContent> root;
mBookmarks->GetRootContent(getter_AddRefs(root));
// The root has no item, so we don't need to do a lookup unless we
// aren't the root.
if (parentContent != root) {
PRUint32 contentID;
parentContent->GetContentID(&contentID);
item = [(BookmarksService::gDictionary) objectForKey: [NSNumber numberWithInt: contentID]];
}
}
}
nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(mBookmarks->gBookmarks));
// Fetch the title of the current page and the URL.
nsAutoString title, href;
if (!aIsFolder) {
BookmarksService::GetTitleAndHrefForBrowserView([[mBrowserWindowController getBrowserWrapper] getBrowserView],
title, href);
mCachedHref = [NSString stringWithCharacters: href.get() length: href.Length()];
[mCachedHref retain];
}
else {
mCachedHref = nil;
title = NS_LITERAL_STRING("New Folder");
}
NSTextField* textField = [mBrowserWindowController getAddBookmarkTitle];
[textField setStringValue: [NSString stringWithCharacters: title.get() length: title.Length()]];
[mBrowserWindowController cacheBookmarkDS: self];
// Show/hide the bookmark all tabs checkbox as appropriate.
NSTabView* tabView = [mBrowserWindowController getTabBrowser];
id checkbox = [mBrowserWindowController getAddBookmarkCheckbox];
BOOL hasSuperview = [checkbox superview] != nil;
if (aIsFolder && hasSuperview) {
// Just don't show it at all.
[checkbox removeFromSuperview];
[checkbox retain];
}
else if (!aIsFolder && !hasSuperview) {
// Put it back in.
[[[mBrowserWindowController getAddBookmarkSheetWindow] contentView] addSubview: checkbox];
[checkbox autorelease];
}
// Enable the bookmark all tabs checkbox if appropriate.
if (!aIsFolder)
[[mBrowserWindowController getAddBookmarkCheckbox] setEnabled: ([tabView numberOfTabViewItems] > 1)];
// Build up the folder list.
NSPopUpButton* popup = [mBrowserWindowController getAddBookmarkFolder];
BookmarksService::ConstructAddBookmarkFolderList(popup, item);
[NSApp beginSheet: [mBrowserWindowController getAddBookmarkSheetWindow]
modalForWindow: [mBrowserWindowController window]
modalDelegate: nil //self
didEndSelector: nil //@selector(sheetDidEnd:)
contextInfo: nil];
}
-(void)endAddBookmark: (int)aCode
{
if (aCode == 0)
return;
BOOL isGroup = NO;
id checkbox = [mBrowserWindowController getAddBookmarkCheckbox];
if (([checkbox superview] != nil) && [checkbox isEnabled] && ([checkbox state] == NSOnState)) {
mCachedHref = nil;
isGroup = YES;
}
const char* titleC = [[[mBrowserWindowController getAddBookmarkTitle] stringValue] cString];
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<nsIDOMElement> elt;
domDoc->CreateElementNS(NS_LITERAL_STRING("http://chimera.mozdev.org/bookmarks/"),
tagName,
getter_AddRefs(elt));
elt->SetAttribute(NS_LITERAL_STRING("name"), title);
if (mCachedHref) {
nsAutoString href; href.AssignWithConversion([mCachedHref cString]);
[mCachedHref release];
elt->SetAttribute(NS_LITERAL_STRING("href"), href);
}
if (isGroup) {
// We have to iterate over each tab and create content nodes using the
// title/href of all the pages. They are inserted underneath the parent.
elt->SetAttribute(NS_LITERAL_STRING("group"), NS_LITERAL_STRING("true"));
id tabBrowser = [mBrowserWindowController getTabBrowser];
int count = [tabBrowser numberOfTabViewItems];
for (int i = 0; i < count; i++) {
id browserView = [[[tabBrowser tabViewItemAtIndex: i] view] getBrowserView];
nsAutoString title, href;
BookmarksService::GetTitleAndHrefForBrowserView(browserView, title, href);
nsCOMPtr<nsIDOMElement> childElt;
domDoc->CreateElementNS(NS_LITERAL_STRING("http://chimera.mozdev.org/bookmarks/"),
NS_LITERAL_STRING("bookmark"),
getter_AddRefs(childElt));
childElt->SetAttribute(NS_LITERAL_STRING("name"), title);
childElt->SetAttribute(NS_LITERAL_STRING("href"), href);
nsCOMPtr<nsIDOMNode> dummy;
elt->AppendChild(childElt, getter_AddRefs(dummy));
}
}
// 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;
parentElt->AppendChild(elt, getter_AddRefs(dummy));
nsCOMPtr<nsIContent> childContent(do_QueryInterface(elt));
mBookmarks->BookmarkAdded(parentContent, childContent);
}
-(IBAction)deleteBookmarks: (id)aSender
{
if (!mBookmarks)
return;
int index = [mOutlineView selectedRow];
if (index == -1)
return;
// we'll run into problems if a parent item and one if its children are both selected.
// A cheap way of having to avoid scanning the list to remove children is to have the
// outliner collapse all items that are being deleted. This will cull the selection
// for us and eliminate any children that happened to be selected.
NSEnumerator* selRows = [mOutlineView selectedRowEnumerator];
for (NSNumber* currIndex = [selRows nextObject];
currIndex != nil;
currIndex = [selRows nextObject]) {
index = [currIndex intValue];
BookmarkItem* item = [mOutlineView itemAtRow: index];
[mOutlineView collapseItem: item];
}
// create array of items we need to delete. Deleting items out of of the
// selection array is problematic for some reason.
NSMutableArray* itemsToDelete = [[[NSMutableArray alloc] init] autorelease];
selRows = [mOutlineView selectedRowEnumerator];
for (NSNumber* currIndex = [selRows nextObject];
currIndex != nil;
currIndex = [selRows nextObject]) {
index = [currIndex intValue];
BookmarkItem* item = [mOutlineView itemAtRow: index];
[itemsToDelete addObject: item];
}
// delete all bookmarks that are in our array
int count = [itemsToDelete count];
for (int i = 0; i < count; i++) {
BookmarkItem* item = [itemsToDelete objectAtIndex: i];
[self deleteBookmark: item];
}
// restore selection to location near last item deleted
int total = [mOutlineView numberOfRows];
if (index == total)
index--;
[mOutlineView selectRow: index byExtendingSelection: NO];
}
-(void)deleteBookmark:(id)aItem
{
nsCOMPtr<nsIContent> content = [aItem contentNode];
nsCOMPtr<nsIDOMElement> child(do_QueryInterface(content));
if (!child)
return;
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;
if (parent)
parent->RemoveChild(child, getter_AddRefs(dummy));
mBookmarks->BookmarkRemoved(parentContent, content);
}
-(IBAction)openBookmark: (id)aSender
{
int index = [mOutlineView selectedRow];
if (index == -1)
return;
id item = [mOutlineView itemAtRow: index];
if (!item)
return;
nsIContent* content = [item contentNode];
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(content));
nsAutoString group;
content->GetAttr(kNameSpaceID_None, BookmarksService::gGroupAtom, group);
if (!group.IsEmpty())
mBookmarks->OpenBookmarkGroup([mBrowserWindowController getTabBrowser], elt);
else if ([mOutlineView isExpandable: item]) {
if ([mOutlineView isItemExpanded: item])
[mOutlineView collapseItem: item];
else
[mOutlineView expandItem: item];
}
else {
nsAutoString href;
content->GetAttr(kNameSpaceID_None, BookmarksService::gHrefAtom, href);
if (!href.IsEmpty()) {
NSString* url = [NSString stringWithCharacters: href.get() length: href.Length()];
[[[mBrowserWindowController getBrowserWrapper] getBrowserView] loadURI: url flags: NSLoadFlagsNone];
// Focus and activate our content area.
[[[mBrowserWindowController getBrowserWrapper] getBrowserView] setActive: YES];
}
}
}
-(NSString*) resolveKeyword: (NSString*) aKeyword
{
return BookmarksService::ResolveKeyword(aKeyword);
}
//
// outlineView:shouldEditTableColumn:item: (delegate method)
//
// Called by the outliner to determine whether or not we should allow the
// user to edit this item. For now, Cocoa doesn't correctly handle editing
// of attributed strings with icons, so we can't turn this on. :(
//
- (BOOL)outlineView:(NSOutlineView *)outlineView shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item
{
return NO;
}
- (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item
{
if (!mBookmarks)
return nil;
nsCOMPtr<nsIContent> content;
if (!item)
mBookmarks->GetRootContent(getter_AddRefs(content));
else
content = [item contentNode];
nsCOMPtr<nsIContent> child;
content->ChildAt(index, *getter_AddRefs(child));
if ( child )
return mBookmarks->GetWrapperFor(child);
return nil;
}
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
{
if (!mBookmarks)
return NO;
if (!item)
return YES; // The root node is always open.
nsCOMPtr<nsIAtom> tagName;
nsIContent* content = [item contentNode];
content->GetTag(*getter_AddRefs(tagName));
BOOL isExpandable = (tagName == BookmarksService::gFolderAtom);
// XXXben - persistence of folder open state
// I'm adding this code, turned off, until I can figure out how to refresh the NSOutlineView's
// row count. Currently the items are expanded, but the outline view continues to believe it had
// the number of rows it had before the item was opened visible, until the view is resized.
#if 0
if (isExpandable) {
PRBool isOpen = content->HasAttr(kNameSpaceID_None, BookmarksService::gOpenAtom);
if (isOpen)
[mOutlineView expandItem: item];
else
[mOutlineView collapseItem: item];
}
#endif
return isExpandable;
}
- (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
{
if (!mBookmarks)
return 0;
nsCOMPtr<nsIContent> content;
if (!item)
mBookmarks->GetRootContent(getter_AddRefs(content));
else
content = [item contentNode];
PRInt32 childCount;
content->ChildCount(childCount);
return childCount;
}
- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
{
NSString *columnName = [tableColumn identifier];
NSMutableAttributedString *cellValue = [[NSMutableAttributedString alloc] init];
NSFileWrapper *fileWrapper = [[NSFileWrapper alloc] initRegularFileWithContents:nil];
NSTextAttachment *textAttachment = [[NSTextAttachment alloc] initWithFileWrapper:fileWrapper];
NSMutableAttributedString *attachmentAttrString = nil;
NSCell *attachmentAttrStringCell;
if ([columnName isEqualToString: @"name"]) {
nsIContent* content = [item contentNode];
nsAutoString nameAttr;
content->GetAttr(kNameSpaceID_None, BookmarksService::gNameAtom, nameAttr);
//Set cell's textual contents
[cellValue replaceCharactersInRange:NSMakeRange(0, [cellValue length]) withString:[NSString stringWithCharacters: nameAttr.get() length: nameAttr.Length()]];
//Create an attributed string to hold the empty attachment, then release the components.
attachmentAttrString = [[NSMutableAttributedString attributedStringWithAttachment:textAttachment] retain];
[textAttachment release];
[fileWrapper release];
//Get the cell of the text attachment.
attachmentAttrStringCell = (NSCell *)[(NSTextAttachment *)[attachmentAttrString attribute:NSAttachmentAttributeName atIndex:0 effectiveRange:nil] attachmentCell];
//Figure out which image to add, and set the cell's image.
// Use the bookmark groups image for groups.
if ([self outlineView:outlineView isItemExpandable:item]) {
nsIContent* content = [item contentNode];
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(content));
nsAutoString group;
content->GetAttr(kNameSpaceID_None, BookmarksService::gGroupAtom, group);
if (!group.IsEmpty())
[attachmentAttrStringCell setImage:[NSImage imageNamed:@"groupbookmark"]];
else
[attachmentAttrStringCell setImage:[NSImage imageNamed:@"folder"]];
}
else
[attachmentAttrStringCell setImage:[NSImage imageNamed:@"smallbookmark"]];
//Insert the image
[cellValue replaceCharactersInRange:NSMakeRange(0, 0) withAttributedString:attachmentAttrString];
//Tweak the baseline to vertically center the text.
[cellValue addAttribute:NSBaselineOffsetAttributeName
value:[NSNumber numberWithFloat:-3.0]
range:NSMakeRange(0, 1)];
}
return cellValue;
}
- (void)outlineView:(NSOutlineView *)outlineView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
{
#if NOT_USED
// ignore all this. It doesn't work, but i'm leaving it here just in case we ever try to turn
// this code back on. We have to remove the attributes from the string in order to correctly
// set it in the DOM.
NSString *columnName = [tableColumn identifier];
if ( [columnName isEqualTo:@"name"] ) {
// remove the attributes
int strLen = [object length];
NSMutableAttributedString *cellValue = [[NSMutableAttributedString alloc] initWithAttributedString:object];
[cellValue removeAttribute:NSBaselineOffsetAttributeName range:NSMakeRange(0,1)];
[cellValue removeAttribute:NSAttachmentAttributeName range:NSMakeRange(0,strLen)];
// extract the unicode
strLen = [cellValue length];
PRUnichar* buffer = new PRUnichar[strLen + 1];
buffer[strLen] = '\0';
if ( !buffer )
return;
[cellValue getCharacters: buffer];
nsAutoString nameAttr;
nameAttr.Adopt(buffer);
// stash it into the dom.
nsIContent* content = [item contentNode];
content->SetAttr(kNameSpaceID_None, BookmarksService::gNameAtom, nameAttr, PR_TRUE);
[cellValue release];
}
#endif
}
- (BOOL)outlineView:(NSOutlineView *)ov writeItems:(NSArray*)items toPasteboard:(NSPasteboard*)pboard
{
if (!mBookmarks || [mOutlineView selectedRow] == -1) {
return NO;
}
#ifdef FILTER_DESCENDANT_ON_DRAG
NSArray *toDrag = BookmarksService::FilterOutDescendantsForDrag(items);
#else
NSArray *toDrag = items;
#endif
int count = [toDrag count];
if (count > 0) {
// Create Pasteboard Data
NSMutableArray *draggedID = [NSMutableArray arrayWithCapacity: count];
for (int i = 0; i < count; i++)
[draggedID addObject: [[toDrag objectAtIndex: i] contentID]];
[pboard declareTypes: [NSArray arrayWithObject: @"MozBookmarkType"] owner: self];
[pboard setPropertyList: draggedID forType: @"MozBookmarkType"];
return YES;
}
return NO;
}
- (NSDragOperation)outlineView:(NSOutlineView*)ov validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(int)index
{
NSArray* types = [[info draggingPasteboard] types];
// if the index is -1, deny the drop
if (index == NSOutlineViewDropOnItemIndex)
return NSDragOperationNone;
if ([types containsObject: @"MozBookmarkType"]) {
NSArray *draggedIDs = [[info draggingPasteboard] propertyListForType: @"MozBookmarkType"];
BookmarkItem* parent;
parent = (item) ? item : BookmarksService::GetRootItem();
return (BookmarksService::IsBookmarkDropValid(parent, index, draggedIDs)) ? NSDragOperationGeneric : NSDragOperationNone;
} else if ([types containsObject: @"MozURLType"]) {
return NSDragOperationGeneric;
}
return NSDragOperationNone;
}
- (BOOL)outlineView:(NSOutlineView*)ov acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(int)index {
NSArray *types = [[info draggingPasteboard] types];
BookmarkItem* parent = (item) ? item : BookmarksService::GetRootItem();
if ([types containsObject: @"MozBookmarkType"]) {
NSArray *draggedItems = [[info draggingPasteboard] propertyListForType: @"MozBookmarkType"];
BookmarksService::PerformBookmarkDrop(parent, index, draggedItems);
return YES;
}
else if ([types containsObject: @"MozURLType"]) {
NSDictionary* proxy = [[info draggingPasteboard] propertyListForType: @"MozURLType"];
BookmarkItem* beforeItem = [self outlineView:ov child:index ofItem:item];
return BookmarksService::PerformProxyDrop(parent, beforeItem, proxy);
}
return NO;
}
- (void)reloadDataForItem:(id)item reloadChildren: (BOOL)aReloadChildren
{
if (!item)
[mOutlineView reloadData];
else if ([mOutlineView isItemExpanded: item])
[mOutlineView reloadItem: item reloadChildren: aReloadChildren];
}
-(IBAction)openBookmarkInNewTab:(id)aSender
{
int index = [mOutlineView selectedRow];
if (index == -1)
return;
if ([mOutlineView numberOfSelectedRows] == 1) {
nsCOMPtr<nsIPrefBranch> pref(do_GetService("@mozilla.org/preferences-service;1"));
if (!pref)
return; // Something bad happened if we can't get prefs.
BookmarkItem* item = [mOutlineView itemAtRow: index];
nsAutoString hrefAttr;
[item contentNode]->GetAttr(kNameSpaceID_None, BookmarksService::gHrefAtom, hrefAttr);
// stuff it into the string
NSString* hrefStr = [NSString stringWithCharacters:hrefAttr.get() length:hrefAttr.Length()];
PRBool loadInBackground;
pref->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground);
[mBrowserWindowController openNewTabWithURL: hrefStr loadInBackground: loadInBackground];
}
}
-(IBAction)openBookmarkInNewWindow:(id)aSender
{
int index = [mOutlineView selectedRow];
if (index == -1)
return;
if ([mOutlineView numberOfSelectedRows] == 1) {
BookmarkItem* item = [mOutlineView itemAtRow: index];
nsAutoString hrefAttr;
[item contentNode]->GetAttr(kNameSpaceID_None, BookmarksService::gHrefAtom, hrefAttr);
// stuff it into the string
NSString* hrefStr = [NSString stringWithCharacters:hrefAttr.get() length:hrefAttr.Length()];
nsAutoString group;
[item contentNode]->GetAttr(kNameSpaceID_None, BookmarksService::gGroupAtom, group);
if (group.IsEmpty())
[mBrowserWindowController openNewWindowWithURL: hrefStr loadInBackground: NO];
else {
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface([item contentNode]));
[mBrowserWindowController openNewWindowWithGroup: elt loadInBackground: NO];
}
}
}
-(void)openBookmarkGroup:(id)aTabView groupElement:(nsIDOMElement*)aFolder
{
mBookmarks->OpenBookmarkGroup(aTabView, aFolder);
}
-(IBAction)showBookmarkInfo:(id)aSender
{
if (!mBookmarkInfoController)
mBookmarkInfoController = [[BookmarkInfoController alloc] initWithOutlineView: mOutlineView];
[mBookmarkInfoController showWindow:mBookmarkInfoController];
int index = [mOutlineView selectedRow];
BookmarkItem* item = [mOutlineView itemAtRow: index];
[mBookmarkInfoController setBookmark:item];
}
-(void)outlineViewSelectionDidChange: (NSNotification*) aNotification
{
int index = [mOutlineView selectedRow];
if (index == -1) {
if (mBookmarkInfoController)
[mBookmarkInfoController setBookmark:NULL];
}
else {
BookmarkItem* item = [mOutlineView itemAtRow:index];
if (mBookmarkInfoController)
[mBookmarkInfoController setBookmark:item];
}
}
-(BOOL)validateMenuItem:(NSMenuItem*)aMenuItem
{
int index = [mOutlineView selectedRow];
if (index == -1)
return NO;
BookmarkItem* item = [mOutlineView itemAtRow: index];
BOOL isBookmark = [mOutlineView isExpandable:item] == NO;
nsAutoString group;
[item contentNode]->GetAttr(kNameSpaceID_None, BookmarksService::gGroupAtom, group);
BOOL isGroup = !group.IsEmpty();
if (([aMenuItem action] == @selector(openBookmarkInNewWindow:))) {
// Bookmarks and Bookmark Groups can be opened in a new window
return (isBookmark || isGroup);
}
else if (([aMenuItem action] == @selector(openBookmarkInNewTab:))) {
// Only Bookmarks can be opened in new tabs
return isBookmark;
}
return YES;
}
- (void)outlineViewItemWillExpand:(NSNotification *)notification
{
BookmarkItem* item = [[notification userInfo] objectForKey:[[[notification userInfo] allKeys] objectAtIndex: 0]];
[item contentNode]->SetAttr(kNameSpaceID_None, BookmarksService::gOpenAtom, NS_LITERAL_STRING("true"), PR_FALSE);
}
- (void)outlineViewItemWillCollapse:(NSNotification *)notification
{
BookmarkItem* item = [[notification userInfo] objectForKey:[[[notification userInfo] allKeys] objectAtIndex: 0]];
[item contentNode]->UnsetAttr(kNameSpaceID_None, BookmarksService::gOpenAtom, PR_FALSE);
}
@end
@implementation BookmarkItem
-(nsIContent*)contentNode
{
return mContentNode;
}
- (NSNumber*)contentID
{
PRUint32 contentID = 0;
mContentNode->GetContentID(&contentID);
return [NSNumber numberWithInt: contentID];
}
- (NSString *)description
{
nsCOMPtr<nsIContent> item = [self contentNode];
nsCOMPtr<nsIDOMElement> element(do_QueryInterface(item));
nsAutoString href;
element->GetAttribute(NS_LITERAL_STRING("name"), href);
NSString* info = [NSString stringWithCharacters: href.get() length: href.Length()];
return [NSString stringWithFormat:@"<BookmarkItem, name = \"%@\">", info];
}
-(void)setContentNode: (nsIContent*)aContentNode
{
mContentNode = aContentNode;
}
- (id)copyWithZone:(NSZone *)aZone
{
BookmarkItem* copy = [[[self class] allocWithZone: aZone] init];
[copy setContentNode: mContentNode];
return copy;
}
@end

Просмотреть файл

@ -23,6 +23,8 @@
#import "CHBookmarksOutlineView.h"
#import "BookmarksService.h"
#import "BookmarksDataSource.h"
#include "nsCOMPtr.h"
#include "nsIDOMElement.h"
#include "nsIContent.h"

Просмотреть файл

@ -37,88 +37,22 @@
#include <Appkit/Appkit.h>
#include <Carbon/Carbon.h>
#include "nsCOMPtr.h"
#include "nsIDocument.h"
#include "nsIDocumentObserver.h"
#include "nsVoidArray.h"
#import "MainController.h"
#import "CHBookmarksToolbar.h"
#import "CHExtendedOutlineView.h"
@class BookmarkItem;
class BookmarksService;
class nsIAtom;
@class BookmarkInfoController;
@interface BookmarksDataSource : NSObject
{
BookmarksService* mBookmarks;
IBOutlet id mOutlineView;
IBOutlet id mBrowserWindowController;
NSString* mCachedHref;
BookmarkInfoController* mBookmarkInfoController;
}
-(id) init;
-(void) dealloc;
-(void) windowClosing;
-(void) ensureBookmarks;
-(IBAction)addBookmark:(id)aSender;
-(void)endAddBookmark: (int)aCode;
-(IBAction)deleteBookmarks: (id)aSender;
-(void)deleteBookmark: (id)aItem;
-(IBAction)addFolder:(id)aSender;
-(void)addBookmark:(id)aSender useSelection:(BOOL)aSel isFolder:(BOOL)aIsFolder;
-(NSString*)resolveKeyword:(NSString*)aKeyword;
-(IBAction)openBookmarkInNewTab:(id)aSender;
-(IBAction)openBookmarkInNewWindow:(id)aSender;
-(void)openBookmarkGroup:(id)aTabView groupElement:(nsIDOMElement*)aFolder;
-(IBAction)showBookmarkInfo:(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;
- (BOOL)outlineView:(NSOutlineView *)ov writeItems:(NSArray*)items toPasteboard:(NSPasteboard*)pboard;
- (NSDragOperation)outlineView:(NSOutlineView*)ov validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(int)index;
- (BOOL)outlineView:(NSOutlineView*)ov acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(int)index;
- (void)reloadDataForItem:(id)item reloadChildren: (BOOL)aReloadChildren;
// Delegate methods
- (void)outlineViewItemWillExpand:(NSNotification *)notification;
- (void)outlineViewItemWillCollapse:(NSNotification *)notification;
@end
@interface BookmarkItem : NSObject
{
nsIContent* mContentNode;
}
- (nsIContent*)contentNode;
- (void)setContentNode: (nsIContent*)aContentNode;
- (NSNumber*)contentID;
- (id)copyWithZone:(NSZone *)aZone;
@end
class nsIDOMHTMLDocument;
@class BookmarksDataSource;
@class BookmarkItem;
class BookmarksService
{
public:
@ -142,6 +76,8 @@ public:
static BookmarkItem* GetRootItem();
static BookmarkItem* GetWrapperFor(nsIContent* aItem);
static BookmarkItem* GetWrapperFor(PRUint32 contentID);
static void ReadBookmarks();
static void FlushBookmarks();
static void ConstructBookmarksMenu(NSMenu* aMenu, nsIContent* aContent);
@ -189,6 +125,7 @@ public:
static nsIAtom* gOpenAtom;
static nsIAtom* gGroupAtom;
static nsIDocument* gBookmarks;
static BOOL gBookmarksFileReadOK;
static nsVoidArray* gInstances;
static int CHInsertNone;
static int CHInsertInto;

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -25,6 +25,8 @@
#import "CHBookmarksButton.h"
#import "CHBookmarksToolbar.h"
#import "BookmarksService.h"
#import "BookmarksDataSource.h"
#include "nsIDOMElement.h"
#include "nsIContent.h"

Просмотреть файл

@ -584,6 +584,9 @@ static NSString *SearchToolbarItemIdentifier = @"Search Toolbar Item";
[newView setIsBookmarksImport: YES];
[[[self window] contentView] addSubview: newView];
[[newView getBrowserView] loadURI:aURLSpec flags:NSLoadFlagsNone];
// XXX force reload
//[mSidebarBookmarksDataSource reloadDataForItem: nil reloadChildren: YES];
}
- (IBAction)goToLocationFromToolbarURLField:(id)sender