Reinstate dragging the proxy to the personal toolbar and the outliner as

well as fixing a crasher dragging to the end of the bookmarks list (bug 154460)


git-svn-id: svn://10.0.0.236/trunk@124194 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
pinkerton%netscape.com 2002-06-27 18:07:56 +00:00
parent 1a423ebcd7
commit 56fecb2acf
12 changed files with 228 additions and 304 deletions

View File

@ -165,6 +165,7 @@ public:
static BOOL DoAncestorsIncludeNode(BookmarkItem* bookmark, BookmarkItem* searchItem);
static bool IsBookmarkDropValid(BookmarkItem* proposedParent, int index, NSArray* draggedIDs);
static bool PerformBookmarkDrop(BookmarkItem* parent, int index, NSArray* draggedIDs);
static bool PerformProxyDrop(BookmarkItem* parentItem, BookmarkItem* beforeItem, NSDictionary* data);
static void DropURL(NSString* title, NSURL* url, BookmarkItem* parent, int index);

View File

@ -402,7 +402,10 @@
nsCOMPtr<nsIContent> child;
content->ChildAt(index, *getter_AddRefs(child));
return mBookmarks->GetWrapperFor(child);
if ( child )
return mBookmarks->GetWrapperFor(child);
return nil;
}
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
@ -592,30 +595,11 @@
NSArray *draggedItems = [[info draggingPasteboard] propertyListForType: @"MozBookmarkType"];
BookmarksService::PerformBookmarkDrop(parent, index, draggedItems);
return YES;
} else if ([types containsObject: @"MozURLType"]) {
NSDictionary* data = [[info draggingPasteboard] propertyListForType: @"MozURLType"];
nsCOMPtr<nsIDOMElement> parentElt;
parentElt = do_QueryInterface([parent contentNode]);
PRInt32 childCount = 0;
[item contentNode]->ChildCount(childCount);
if (index >= childCount)
return NO;
BookmarkItem* beforeItem;
beforeItem = [[ov dataSource] outlineView:ov child:index ofItem:item];
if (!beforeItem)
return NO;
nsCOMPtr<nsIDOMElement> beforeElt;
beforeElt = do_QueryInterface([beforeItem contentNode]);
nsAutoString url; url.AssignWithConversion([[data objectForKey:@"url"] cString]);
nsAutoString title; title.AssignWithConversion([[data objectForKey:@"title"] cString]);
BookmarksService::AddBookmarkToFolder(url, title, parentElt, beforeElt);
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;
@ -871,6 +855,9 @@ BookmarksService::GetRootItem() {
BookmarkItem*
BookmarksService::GetWrapperFor(nsIContent* aContent)
{
if ( !aContent )
return nil;
if (!gDictionary)
gDictionary = [[NSMutableDictionary alloc] initWithCapacity: 30];
@ -1670,7 +1657,8 @@ BookmarksService::CreateIconForBookmark(nsIDOMElement* aElement)
// Is searchItem equal to bookmark or bookmark's parent, grandparent, etc?
BOOL
BookmarksService::DoAncestorsIncludeNode(BookmarkItem* bookmark, BookmarkItem* searchItem) {
BookmarksService::DoAncestorsIncludeNode(BookmarkItem* bookmark, BookmarkItem* searchItem)
{
nsCOMPtr<nsIContent> search = [searchItem contentNode];
nsCOMPtr<nsIContent> current = [bookmark contentNode];
nsCOMPtr<nsIContent> root;
@ -1735,7 +1723,11 @@ BookmarksService::FilterOutDescendantsForDrag(NSArray* nodes)
#endif
bool
BookmarksService::IsBookmarkDropValid(BookmarkItem* proposedParent, int index, NSArray* draggedIDs) {
BookmarksService::IsBookmarkDropValid(BookmarkItem* proposedParent, int index, NSArray* draggedIDs)
{
if ( !draggedIDs )
return NO;
NSMutableArray *draggedItems = [NSMutableArray arrayWithCapacity: [draggedIDs count]];
BOOL toolbarRootMoving = NO;
@ -1775,7 +1767,27 @@ BookmarksService::IsBookmarkDropValid(BookmarkItem* proposedParent, int index, N
bool
BookmarksService::PerformBookmarkDrop(BookmarkItem* parent, int index, NSArray* draggedIDs) {
BookmarksService::PerformProxyDrop(BookmarkItem* parentItem, BookmarkItem* beforeItem, NSDictionary* data)
{
if ( !data )
return NO;
nsCOMPtr<nsIDOMElement> parentElt;
parentElt = do_QueryInterface([parentItem contentNode]);
nsCOMPtr<nsIDOMElement> beforeElt;
beforeElt = do_QueryInterface([beforeItem contentNode]);
nsAutoString url; url.AssignWithConversion([[data objectForKey:@"url"] cString]);
nsAutoString title; title.AssignWithConversion([[data objectForKey:@"title"] cString]);
BookmarksService::AddBookmarkToFolder(url, title, parentElt, beforeElt);
return YES;
}
bool
BookmarksService::PerformBookmarkDrop(BookmarkItem* parent, int index, NSArray* draggedIDs)
{
NSEnumerator *enumerator = [draggedIDs reverseObjectEnumerator];
NSNumber *contentID;

View File

@ -71,7 +71,7 @@
// The personal toolbar is 21 pixels tall. The bottom two pixels
// are a separator.
[[NSColor colorWithCalibratedWhite: 0.90 alpha: 1.0] set];
NSRectFill(NSMakeRect(aRect.origin.x, [self bounds].size.height-2, aRect.size.width, [self bounds].size.height));
//NSRectFill(NSMakeRect(aRect.origin.x, [self bounds].size.height-2, aRect.size.width, [self bounds].size.height));
}
// The buttons will paint themselves. Just call our base class method.
@ -103,7 +103,7 @@
}
if ([self isShown])
[self reflowButtons];
[self reflowButtons];
}
-(void)addButton: (nsIDOMElement*)aElt atIndex: (int)aIndex
@ -320,63 +320,22 @@
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
{
BookmarkItem* parent;
int index = 0;
NSArray *draggedItems = [[sender draggingPasteboard] propertyListForType: @"MozBookmarkType"];
// If we are dropping into a folder
if (mDragInsertionPosition == BookmarksService::CHInsertInto) {
nsCOMPtr<nsIDOMElement> parentElt = [mDragInsertionButton element];
nsCOMPtr<nsIContent> parentContent(do_QueryInterface(parentElt));
parent = BookmarksService::GetWrapperFor(parentContent);
index = 0;
}
// If we are dropping onto the toolbar directly
else if (mDragInsertionPosition == BookmarksService::CHInsertBefore ||
mDragInsertionPosition == BookmarksService::CHInsertAfter) {
nsCOMPtr<nsIDOMElement> rootElt = BookmarksService::gToolbarRoot;
nsCOMPtr<nsIContent> rootContent(do_QueryInterface(rootElt));
parent = BookmarksService::GetWrapperFor(rootContent);
index = [mButtons indexOfObject: mDragInsertionButton];
if (index == NSNotFound)
rootContent->ChildCount(index);
else if (mDragInsertionPosition == BookmarksService::CHInsertAfter)
index++;
} else {
mDragInsertionButton = nil;
mDragInsertionPosition = BookmarksService::CHInsertNone;
[self setNeedsDisplay:YES];
return NO;
}
bool valid = BookmarksService::IsBookmarkDropValid(parent, index, draggedItems);
if (!valid) {
mDragInsertionButton = nil;
mDragInsertionPosition = BookmarksService::CHInsertNone;
[self setNeedsDisplay:YES];
}
return valid;
return YES;
}
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
BookmarkItem* parent;
BookmarkItem* parent = nsnull;
int index = 0;
NSArray *draggedItems = [[sender draggingPasteboard] propertyListForType: @"MozBookmarkType"];
// If we are dropping into a folder
if (mDragInsertionPosition == BookmarksService::CHInsertInto) {
if (mDragInsertionPosition == BookmarksService::CHInsertInto) { // drop onto folder
nsCOMPtr<nsIDOMElement> parentElt = [mDragInsertionButton element];
nsCOMPtr<nsIContent> parentContent(do_QueryInterface(parentElt));
parent = BookmarksService::GetWrapperFor(parentContent);
index = 0;
}
// If we are dropping onto the toolbar directly
else if (mDragInsertionPosition == BookmarksService::CHInsertBefore ||
mDragInsertionPosition == BookmarksService::CHInsertAfter) {
mDragInsertionPosition == BookmarksService::CHInsertAfter) { // drop onto toolbar
nsCOMPtr<nsIDOMElement> rootElt = BookmarksService::gToolbarRoot;
nsCOMPtr<nsIContent> rootContent(do_QueryInterface(rootElt));
parent = BookmarksService::GetWrapperFor(rootContent);
@ -392,7 +351,16 @@
return NO;
}
BookmarksService::PerformBookmarkDrop(parent, index, draggedItems);
NSArray *draggedItems = [[sender draggingPasteboard] propertyListForType: @"MozBookmarkType"];
if ( draggedItems )
BookmarksService::PerformBookmarkDrop(parent, index, draggedItems);
else {
NSDictionary* proxy = [[sender draggingPasteboard] propertyListForType: @"MozURLType"];
nsCOMPtr<nsIContent> beforeContent;
[parent contentNode]->ChildAt(index, *getter_AddRefs(beforeContent));
BookmarkItem* beforeItem = mBookmarks->GetWrapperFor(beforeContent); // can handle nil content
BookmarksService::PerformProxyDrop(parent, beforeItem, proxy);
}
mDragInsertionButton = nil;
mDragInsertionPosition = BookmarksService::CHInsertNone;

View File

@ -165,6 +165,7 @@ public:
static BOOL DoAncestorsIncludeNode(BookmarkItem* bookmark, BookmarkItem* searchItem);
static bool IsBookmarkDropValid(BookmarkItem* proposedParent, int index, NSArray* draggedIDs);
static bool PerformBookmarkDrop(BookmarkItem* parent, int index, NSArray* draggedIDs);
static bool PerformProxyDrop(BookmarkItem* parentItem, BookmarkItem* beforeItem, NSDictionary* data);
static void DropURL(NSString* title, NSURL* url, BookmarkItem* parent, int index);

View File

@ -402,7 +402,10 @@
nsCOMPtr<nsIContent> child;
content->ChildAt(index, *getter_AddRefs(child));
return mBookmarks->GetWrapperFor(child);
if ( child )
return mBookmarks->GetWrapperFor(child);
return nil;
}
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
@ -592,30 +595,11 @@
NSArray *draggedItems = [[info draggingPasteboard] propertyListForType: @"MozBookmarkType"];
BookmarksService::PerformBookmarkDrop(parent, index, draggedItems);
return YES;
} else if ([types containsObject: @"MozURLType"]) {
NSDictionary* data = [[info draggingPasteboard] propertyListForType: @"MozURLType"];
nsCOMPtr<nsIDOMElement> parentElt;
parentElt = do_QueryInterface([parent contentNode]);
PRInt32 childCount = 0;
[item contentNode]->ChildCount(childCount);
if (index >= childCount)
return NO;
BookmarkItem* beforeItem;
beforeItem = [[ov dataSource] outlineView:ov child:index ofItem:item];
if (!beforeItem)
return NO;
nsCOMPtr<nsIDOMElement> beforeElt;
beforeElt = do_QueryInterface([beforeItem contentNode]);
nsAutoString url; url.AssignWithConversion([[data objectForKey:@"url"] cString]);
nsAutoString title; title.AssignWithConversion([[data objectForKey:@"title"] cString]);
BookmarksService::AddBookmarkToFolder(url, title, parentElt, beforeElt);
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;
@ -871,6 +855,9 @@ BookmarksService::GetRootItem() {
BookmarkItem*
BookmarksService::GetWrapperFor(nsIContent* aContent)
{
if ( !aContent )
return nil;
if (!gDictionary)
gDictionary = [[NSMutableDictionary alloc] initWithCapacity: 30];
@ -1670,7 +1657,8 @@ BookmarksService::CreateIconForBookmark(nsIDOMElement* aElement)
// Is searchItem equal to bookmark or bookmark's parent, grandparent, etc?
BOOL
BookmarksService::DoAncestorsIncludeNode(BookmarkItem* bookmark, BookmarkItem* searchItem) {
BookmarksService::DoAncestorsIncludeNode(BookmarkItem* bookmark, BookmarkItem* searchItem)
{
nsCOMPtr<nsIContent> search = [searchItem contentNode];
nsCOMPtr<nsIContent> current = [bookmark contentNode];
nsCOMPtr<nsIContent> root;
@ -1735,7 +1723,11 @@ BookmarksService::FilterOutDescendantsForDrag(NSArray* nodes)
#endif
bool
BookmarksService::IsBookmarkDropValid(BookmarkItem* proposedParent, int index, NSArray* draggedIDs) {
BookmarksService::IsBookmarkDropValid(BookmarkItem* proposedParent, int index, NSArray* draggedIDs)
{
if ( !draggedIDs )
return NO;
NSMutableArray *draggedItems = [NSMutableArray arrayWithCapacity: [draggedIDs count]];
BOOL toolbarRootMoving = NO;
@ -1775,7 +1767,27 @@ BookmarksService::IsBookmarkDropValid(BookmarkItem* proposedParent, int index, N
bool
BookmarksService::PerformBookmarkDrop(BookmarkItem* parent, int index, NSArray* draggedIDs) {
BookmarksService::PerformProxyDrop(BookmarkItem* parentItem, BookmarkItem* beforeItem, NSDictionary* data)
{
if ( !data )
return NO;
nsCOMPtr<nsIDOMElement> parentElt;
parentElt = do_QueryInterface([parentItem contentNode]);
nsCOMPtr<nsIDOMElement> beforeElt;
beforeElt = do_QueryInterface([beforeItem contentNode]);
nsAutoString url; url.AssignWithConversion([[data objectForKey:@"url"] cString]);
nsAutoString title; title.AssignWithConversion([[data objectForKey:@"title"] cString]);
BookmarksService::AddBookmarkToFolder(url, title, parentElt, beforeElt);
return YES;
}
bool
BookmarksService::PerformBookmarkDrop(BookmarkItem* parent, int index, NSArray* draggedIDs)
{
NSEnumerator *enumerator = [draggedIDs reverseObjectEnumerator];
NSNumber *contentID;

View File

@ -71,7 +71,7 @@
// The personal toolbar is 21 pixels tall. The bottom two pixels
// are a separator.
[[NSColor colorWithCalibratedWhite: 0.90 alpha: 1.0] set];
NSRectFill(NSMakeRect(aRect.origin.x, [self bounds].size.height-2, aRect.size.width, [self bounds].size.height));
//NSRectFill(NSMakeRect(aRect.origin.x, [self bounds].size.height-2, aRect.size.width, [self bounds].size.height));
}
// The buttons will paint themselves. Just call our base class method.
@ -103,7 +103,7 @@
}
if ([self isShown])
[self reflowButtons];
[self reflowButtons];
}
-(void)addButton: (nsIDOMElement*)aElt atIndex: (int)aIndex
@ -320,63 +320,22 @@
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
{
BookmarkItem* parent;
int index = 0;
NSArray *draggedItems = [[sender draggingPasteboard] propertyListForType: @"MozBookmarkType"];
// If we are dropping into a folder
if (mDragInsertionPosition == BookmarksService::CHInsertInto) {
nsCOMPtr<nsIDOMElement> parentElt = [mDragInsertionButton element];
nsCOMPtr<nsIContent> parentContent(do_QueryInterface(parentElt));
parent = BookmarksService::GetWrapperFor(parentContent);
index = 0;
}
// If we are dropping onto the toolbar directly
else if (mDragInsertionPosition == BookmarksService::CHInsertBefore ||
mDragInsertionPosition == BookmarksService::CHInsertAfter) {
nsCOMPtr<nsIDOMElement> rootElt = BookmarksService::gToolbarRoot;
nsCOMPtr<nsIContent> rootContent(do_QueryInterface(rootElt));
parent = BookmarksService::GetWrapperFor(rootContent);
index = [mButtons indexOfObject: mDragInsertionButton];
if (index == NSNotFound)
rootContent->ChildCount(index);
else if (mDragInsertionPosition == BookmarksService::CHInsertAfter)
index++;
} else {
mDragInsertionButton = nil;
mDragInsertionPosition = BookmarksService::CHInsertNone;
[self setNeedsDisplay:YES];
return NO;
}
bool valid = BookmarksService::IsBookmarkDropValid(parent, index, draggedItems);
if (!valid) {
mDragInsertionButton = nil;
mDragInsertionPosition = BookmarksService::CHInsertNone;
[self setNeedsDisplay:YES];
}
return valid;
return YES;
}
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
BookmarkItem* parent;
BookmarkItem* parent = nsnull;
int index = 0;
NSArray *draggedItems = [[sender draggingPasteboard] propertyListForType: @"MozBookmarkType"];
// If we are dropping into a folder
if (mDragInsertionPosition == BookmarksService::CHInsertInto) {
if (mDragInsertionPosition == BookmarksService::CHInsertInto) { // drop onto folder
nsCOMPtr<nsIDOMElement> parentElt = [mDragInsertionButton element];
nsCOMPtr<nsIContent> parentContent(do_QueryInterface(parentElt));
parent = BookmarksService::GetWrapperFor(parentContent);
index = 0;
}
// If we are dropping onto the toolbar directly
else if (mDragInsertionPosition == BookmarksService::CHInsertBefore ||
mDragInsertionPosition == BookmarksService::CHInsertAfter) {
mDragInsertionPosition == BookmarksService::CHInsertAfter) { // drop onto toolbar
nsCOMPtr<nsIDOMElement> rootElt = BookmarksService::gToolbarRoot;
nsCOMPtr<nsIContent> rootContent(do_QueryInterface(rootElt));
parent = BookmarksService::GetWrapperFor(rootContent);
@ -392,7 +351,16 @@
return NO;
}
BookmarksService::PerformBookmarkDrop(parent, index, draggedItems);
NSArray *draggedItems = [[sender draggingPasteboard] propertyListForType: @"MozBookmarkType"];
if ( draggedItems )
BookmarksService::PerformBookmarkDrop(parent, index, draggedItems);
else {
NSDictionary* proxy = [[sender draggingPasteboard] propertyListForType: @"MozURLType"];
nsCOMPtr<nsIContent> beforeContent;
[parent contentNode]->ChildAt(index, *getter_AddRefs(beforeContent));
BookmarkItem* beforeItem = mBookmarks->GetWrapperFor(beforeContent); // can handle nil content
BookmarksService::PerformProxyDrop(parent, beforeItem, proxy);
}
mDragInsertionButton = nil;
mDragInsertionPosition = BookmarksService::CHInsertNone;

View File

@ -165,6 +165,7 @@ public:
static BOOL DoAncestorsIncludeNode(BookmarkItem* bookmark, BookmarkItem* searchItem);
static bool IsBookmarkDropValid(BookmarkItem* proposedParent, int index, NSArray* draggedIDs);
static bool PerformBookmarkDrop(BookmarkItem* parent, int index, NSArray* draggedIDs);
static bool PerformProxyDrop(BookmarkItem* parentItem, BookmarkItem* beforeItem, NSDictionary* data);
static void DropURL(NSString* title, NSURL* url, BookmarkItem* parent, int index);

View File

@ -402,7 +402,10 @@
nsCOMPtr<nsIContent> child;
content->ChildAt(index, *getter_AddRefs(child));
return mBookmarks->GetWrapperFor(child);
if ( child )
return mBookmarks->GetWrapperFor(child);
return nil;
}
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
@ -592,30 +595,11 @@
NSArray *draggedItems = [[info draggingPasteboard] propertyListForType: @"MozBookmarkType"];
BookmarksService::PerformBookmarkDrop(parent, index, draggedItems);
return YES;
} else if ([types containsObject: @"MozURLType"]) {
NSDictionary* data = [[info draggingPasteboard] propertyListForType: @"MozURLType"];
nsCOMPtr<nsIDOMElement> parentElt;
parentElt = do_QueryInterface([parent contentNode]);
PRInt32 childCount = 0;
[item contentNode]->ChildCount(childCount);
if (index >= childCount)
return NO;
BookmarkItem* beforeItem;
beforeItem = [[ov dataSource] outlineView:ov child:index ofItem:item];
if (!beforeItem)
return NO;
nsCOMPtr<nsIDOMElement> beforeElt;
beforeElt = do_QueryInterface([beforeItem contentNode]);
nsAutoString url; url.AssignWithConversion([[data objectForKey:@"url"] cString]);
nsAutoString title; title.AssignWithConversion([[data objectForKey:@"title"] cString]);
BookmarksService::AddBookmarkToFolder(url, title, parentElt, beforeElt);
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;
@ -871,6 +855,9 @@ BookmarksService::GetRootItem() {
BookmarkItem*
BookmarksService::GetWrapperFor(nsIContent* aContent)
{
if ( !aContent )
return nil;
if (!gDictionary)
gDictionary = [[NSMutableDictionary alloc] initWithCapacity: 30];
@ -1670,7 +1657,8 @@ BookmarksService::CreateIconForBookmark(nsIDOMElement* aElement)
// Is searchItem equal to bookmark or bookmark's parent, grandparent, etc?
BOOL
BookmarksService::DoAncestorsIncludeNode(BookmarkItem* bookmark, BookmarkItem* searchItem) {
BookmarksService::DoAncestorsIncludeNode(BookmarkItem* bookmark, BookmarkItem* searchItem)
{
nsCOMPtr<nsIContent> search = [searchItem contentNode];
nsCOMPtr<nsIContent> current = [bookmark contentNode];
nsCOMPtr<nsIContent> root;
@ -1735,7 +1723,11 @@ BookmarksService::FilterOutDescendantsForDrag(NSArray* nodes)
#endif
bool
BookmarksService::IsBookmarkDropValid(BookmarkItem* proposedParent, int index, NSArray* draggedIDs) {
BookmarksService::IsBookmarkDropValid(BookmarkItem* proposedParent, int index, NSArray* draggedIDs)
{
if ( !draggedIDs )
return NO;
NSMutableArray *draggedItems = [NSMutableArray arrayWithCapacity: [draggedIDs count]];
BOOL toolbarRootMoving = NO;
@ -1775,7 +1767,27 @@ BookmarksService::IsBookmarkDropValid(BookmarkItem* proposedParent, int index, N
bool
BookmarksService::PerformBookmarkDrop(BookmarkItem* parent, int index, NSArray* draggedIDs) {
BookmarksService::PerformProxyDrop(BookmarkItem* parentItem, BookmarkItem* beforeItem, NSDictionary* data)
{
if ( !data )
return NO;
nsCOMPtr<nsIDOMElement> parentElt;
parentElt = do_QueryInterface([parentItem contentNode]);
nsCOMPtr<nsIDOMElement> beforeElt;
beforeElt = do_QueryInterface([beforeItem contentNode]);
nsAutoString url; url.AssignWithConversion([[data objectForKey:@"url"] cString]);
nsAutoString title; title.AssignWithConversion([[data objectForKey:@"title"] cString]);
BookmarksService::AddBookmarkToFolder(url, title, parentElt, beforeElt);
return YES;
}
bool
BookmarksService::PerformBookmarkDrop(BookmarkItem* parent, int index, NSArray* draggedIDs)
{
NSEnumerator *enumerator = [draggedIDs reverseObjectEnumerator];
NSNumber *contentID;

View File

@ -71,7 +71,7 @@
// The personal toolbar is 21 pixels tall. The bottom two pixels
// are a separator.
[[NSColor colorWithCalibratedWhite: 0.90 alpha: 1.0] set];
NSRectFill(NSMakeRect(aRect.origin.x, [self bounds].size.height-2, aRect.size.width, [self bounds].size.height));
//NSRectFill(NSMakeRect(aRect.origin.x, [self bounds].size.height-2, aRect.size.width, [self bounds].size.height));
}
// The buttons will paint themselves. Just call our base class method.
@ -103,7 +103,7 @@
}
if ([self isShown])
[self reflowButtons];
[self reflowButtons];
}
-(void)addButton: (nsIDOMElement*)aElt atIndex: (int)aIndex
@ -320,63 +320,22 @@
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
{
BookmarkItem* parent;
int index = 0;
NSArray *draggedItems = [[sender draggingPasteboard] propertyListForType: @"MozBookmarkType"];
// If we are dropping into a folder
if (mDragInsertionPosition == BookmarksService::CHInsertInto) {
nsCOMPtr<nsIDOMElement> parentElt = [mDragInsertionButton element];
nsCOMPtr<nsIContent> parentContent(do_QueryInterface(parentElt));
parent = BookmarksService::GetWrapperFor(parentContent);
index = 0;
}
// If we are dropping onto the toolbar directly
else if (mDragInsertionPosition == BookmarksService::CHInsertBefore ||
mDragInsertionPosition == BookmarksService::CHInsertAfter) {
nsCOMPtr<nsIDOMElement> rootElt = BookmarksService::gToolbarRoot;
nsCOMPtr<nsIContent> rootContent(do_QueryInterface(rootElt));
parent = BookmarksService::GetWrapperFor(rootContent);
index = [mButtons indexOfObject: mDragInsertionButton];
if (index == NSNotFound)
rootContent->ChildCount(index);
else if (mDragInsertionPosition == BookmarksService::CHInsertAfter)
index++;
} else {
mDragInsertionButton = nil;
mDragInsertionPosition = BookmarksService::CHInsertNone;
[self setNeedsDisplay:YES];
return NO;
}
bool valid = BookmarksService::IsBookmarkDropValid(parent, index, draggedItems);
if (!valid) {
mDragInsertionButton = nil;
mDragInsertionPosition = BookmarksService::CHInsertNone;
[self setNeedsDisplay:YES];
}
return valid;
return YES;
}
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
BookmarkItem* parent;
BookmarkItem* parent = nsnull;
int index = 0;
NSArray *draggedItems = [[sender draggingPasteboard] propertyListForType: @"MozBookmarkType"];
// If we are dropping into a folder
if (mDragInsertionPosition == BookmarksService::CHInsertInto) {
if (mDragInsertionPosition == BookmarksService::CHInsertInto) { // drop onto folder
nsCOMPtr<nsIDOMElement> parentElt = [mDragInsertionButton element];
nsCOMPtr<nsIContent> parentContent(do_QueryInterface(parentElt));
parent = BookmarksService::GetWrapperFor(parentContent);
index = 0;
}
// If we are dropping onto the toolbar directly
else if (mDragInsertionPosition == BookmarksService::CHInsertBefore ||
mDragInsertionPosition == BookmarksService::CHInsertAfter) {
mDragInsertionPosition == BookmarksService::CHInsertAfter) { // drop onto toolbar
nsCOMPtr<nsIDOMElement> rootElt = BookmarksService::gToolbarRoot;
nsCOMPtr<nsIContent> rootContent(do_QueryInterface(rootElt));
parent = BookmarksService::GetWrapperFor(rootContent);
@ -392,7 +351,16 @@
return NO;
}
BookmarksService::PerformBookmarkDrop(parent, index, draggedItems);
NSArray *draggedItems = [[sender draggingPasteboard] propertyListForType: @"MozBookmarkType"];
if ( draggedItems )
BookmarksService::PerformBookmarkDrop(parent, index, draggedItems);
else {
NSDictionary* proxy = [[sender draggingPasteboard] propertyListForType: @"MozURLType"];
nsCOMPtr<nsIContent> beforeContent;
[parent contentNode]->ChildAt(index, *getter_AddRefs(beforeContent));
BookmarkItem* beforeItem = mBookmarks->GetWrapperFor(beforeContent); // can handle nil content
BookmarksService::PerformProxyDrop(parent, beforeItem, proxy);
}
mDragInsertionButton = nil;
mDragInsertionPosition = BookmarksService::CHInsertNone;

View File

@ -165,6 +165,7 @@ public:
static BOOL DoAncestorsIncludeNode(BookmarkItem* bookmark, BookmarkItem* searchItem);
static bool IsBookmarkDropValid(BookmarkItem* proposedParent, int index, NSArray* draggedIDs);
static bool PerformBookmarkDrop(BookmarkItem* parent, int index, NSArray* draggedIDs);
static bool PerformProxyDrop(BookmarkItem* parentItem, BookmarkItem* beforeItem, NSDictionary* data);
static void DropURL(NSString* title, NSURL* url, BookmarkItem* parent, int index);

View File

@ -402,7 +402,10 @@
nsCOMPtr<nsIContent> child;
content->ChildAt(index, *getter_AddRefs(child));
return mBookmarks->GetWrapperFor(child);
if ( child )
return mBookmarks->GetWrapperFor(child);
return nil;
}
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
@ -592,30 +595,11 @@
NSArray *draggedItems = [[info draggingPasteboard] propertyListForType: @"MozBookmarkType"];
BookmarksService::PerformBookmarkDrop(parent, index, draggedItems);
return YES;
} else if ([types containsObject: @"MozURLType"]) {
NSDictionary* data = [[info draggingPasteboard] propertyListForType: @"MozURLType"];
nsCOMPtr<nsIDOMElement> parentElt;
parentElt = do_QueryInterface([parent contentNode]);
PRInt32 childCount = 0;
[item contentNode]->ChildCount(childCount);
if (index >= childCount)
return NO;
BookmarkItem* beforeItem;
beforeItem = [[ov dataSource] outlineView:ov child:index ofItem:item];
if (!beforeItem)
return NO;
nsCOMPtr<nsIDOMElement> beforeElt;
beforeElt = do_QueryInterface([beforeItem contentNode]);
nsAutoString url; url.AssignWithConversion([[data objectForKey:@"url"] cString]);
nsAutoString title; title.AssignWithConversion([[data objectForKey:@"title"] cString]);
BookmarksService::AddBookmarkToFolder(url, title, parentElt, beforeElt);
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;
@ -871,6 +855,9 @@ BookmarksService::GetRootItem() {
BookmarkItem*
BookmarksService::GetWrapperFor(nsIContent* aContent)
{
if ( !aContent )
return nil;
if (!gDictionary)
gDictionary = [[NSMutableDictionary alloc] initWithCapacity: 30];
@ -1670,7 +1657,8 @@ BookmarksService::CreateIconForBookmark(nsIDOMElement* aElement)
// Is searchItem equal to bookmark or bookmark's parent, grandparent, etc?
BOOL
BookmarksService::DoAncestorsIncludeNode(BookmarkItem* bookmark, BookmarkItem* searchItem) {
BookmarksService::DoAncestorsIncludeNode(BookmarkItem* bookmark, BookmarkItem* searchItem)
{
nsCOMPtr<nsIContent> search = [searchItem contentNode];
nsCOMPtr<nsIContent> current = [bookmark contentNode];
nsCOMPtr<nsIContent> root;
@ -1735,7 +1723,11 @@ BookmarksService::FilterOutDescendantsForDrag(NSArray* nodes)
#endif
bool
BookmarksService::IsBookmarkDropValid(BookmarkItem* proposedParent, int index, NSArray* draggedIDs) {
BookmarksService::IsBookmarkDropValid(BookmarkItem* proposedParent, int index, NSArray* draggedIDs)
{
if ( !draggedIDs )
return NO;
NSMutableArray *draggedItems = [NSMutableArray arrayWithCapacity: [draggedIDs count]];
BOOL toolbarRootMoving = NO;
@ -1775,7 +1767,27 @@ BookmarksService::IsBookmarkDropValid(BookmarkItem* proposedParent, int index, N
bool
BookmarksService::PerformBookmarkDrop(BookmarkItem* parent, int index, NSArray* draggedIDs) {
BookmarksService::PerformProxyDrop(BookmarkItem* parentItem, BookmarkItem* beforeItem, NSDictionary* data)
{
if ( !data )
return NO;
nsCOMPtr<nsIDOMElement> parentElt;
parentElt = do_QueryInterface([parentItem contentNode]);
nsCOMPtr<nsIDOMElement> beforeElt;
beforeElt = do_QueryInterface([beforeItem contentNode]);
nsAutoString url; url.AssignWithConversion([[data objectForKey:@"url"] cString]);
nsAutoString title; title.AssignWithConversion([[data objectForKey:@"title"] cString]);
BookmarksService::AddBookmarkToFolder(url, title, parentElt, beforeElt);
return YES;
}
bool
BookmarksService::PerformBookmarkDrop(BookmarkItem* parent, int index, NSArray* draggedIDs)
{
NSEnumerator *enumerator = [draggedIDs reverseObjectEnumerator];
NSNumber *contentID;

View File

@ -71,7 +71,7 @@
// The personal toolbar is 21 pixels tall. The bottom two pixels
// are a separator.
[[NSColor colorWithCalibratedWhite: 0.90 alpha: 1.0] set];
NSRectFill(NSMakeRect(aRect.origin.x, [self bounds].size.height-2, aRect.size.width, [self bounds].size.height));
//NSRectFill(NSMakeRect(aRect.origin.x, [self bounds].size.height-2, aRect.size.width, [self bounds].size.height));
}
// The buttons will paint themselves. Just call our base class method.
@ -103,7 +103,7 @@
}
if ([self isShown])
[self reflowButtons];
[self reflowButtons];
}
-(void)addButton: (nsIDOMElement*)aElt atIndex: (int)aIndex
@ -320,63 +320,22 @@
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
{
BookmarkItem* parent;
int index = 0;
NSArray *draggedItems = [[sender draggingPasteboard] propertyListForType: @"MozBookmarkType"];
// If we are dropping into a folder
if (mDragInsertionPosition == BookmarksService::CHInsertInto) {
nsCOMPtr<nsIDOMElement> parentElt = [mDragInsertionButton element];
nsCOMPtr<nsIContent> parentContent(do_QueryInterface(parentElt));
parent = BookmarksService::GetWrapperFor(parentContent);
index = 0;
}
// If we are dropping onto the toolbar directly
else if (mDragInsertionPosition == BookmarksService::CHInsertBefore ||
mDragInsertionPosition == BookmarksService::CHInsertAfter) {
nsCOMPtr<nsIDOMElement> rootElt = BookmarksService::gToolbarRoot;
nsCOMPtr<nsIContent> rootContent(do_QueryInterface(rootElt));
parent = BookmarksService::GetWrapperFor(rootContent);
index = [mButtons indexOfObject: mDragInsertionButton];
if (index == NSNotFound)
rootContent->ChildCount(index);
else if (mDragInsertionPosition == BookmarksService::CHInsertAfter)
index++;
} else {
mDragInsertionButton = nil;
mDragInsertionPosition = BookmarksService::CHInsertNone;
[self setNeedsDisplay:YES];
return NO;
}
bool valid = BookmarksService::IsBookmarkDropValid(parent, index, draggedItems);
if (!valid) {
mDragInsertionButton = nil;
mDragInsertionPosition = BookmarksService::CHInsertNone;
[self setNeedsDisplay:YES];
}
return valid;
return YES;
}
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
BookmarkItem* parent;
BookmarkItem* parent = nsnull;
int index = 0;
NSArray *draggedItems = [[sender draggingPasteboard] propertyListForType: @"MozBookmarkType"];
// If we are dropping into a folder
if (mDragInsertionPosition == BookmarksService::CHInsertInto) {
if (mDragInsertionPosition == BookmarksService::CHInsertInto) { // drop onto folder
nsCOMPtr<nsIDOMElement> parentElt = [mDragInsertionButton element];
nsCOMPtr<nsIContent> parentContent(do_QueryInterface(parentElt));
parent = BookmarksService::GetWrapperFor(parentContent);
index = 0;
}
// If we are dropping onto the toolbar directly
else if (mDragInsertionPosition == BookmarksService::CHInsertBefore ||
mDragInsertionPosition == BookmarksService::CHInsertAfter) {
mDragInsertionPosition == BookmarksService::CHInsertAfter) { // drop onto toolbar
nsCOMPtr<nsIDOMElement> rootElt = BookmarksService::gToolbarRoot;
nsCOMPtr<nsIContent> rootContent(do_QueryInterface(rootElt));
parent = BookmarksService::GetWrapperFor(rootContent);
@ -392,7 +351,16 @@
return NO;
}
BookmarksService::PerformBookmarkDrop(parent, index, draggedItems);
NSArray *draggedItems = [[sender draggingPasteboard] propertyListForType: @"MozBookmarkType"];
if ( draggedItems )
BookmarksService::PerformBookmarkDrop(parent, index, draggedItems);
else {
NSDictionary* proxy = [[sender draggingPasteboard] propertyListForType: @"MozURLType"];
nsCOMPtr<nsIContent> beforeContent;
[parent contentNode]->ChildAt(index, *getter_AddRefs(beforeContent));
BookmarkItem* beforeItem = mBookmarks->GetWrapperFor(beforeContent); // can handle nil content
BookmarksService::PerformProxyDrop(parent, beforeItem, proxy);
}
mDragInsertionButton = nil;
mDragInsertionPosition = BookmarksService::CHInsertNone;