fix bookmark manager context menu so they are more consistent. don't show info

for folders. deselect when clicking an area where there is no row. (bug
223701)


git-svn-id: svn://10.0.0.236/trunk@156278 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
pinkerton%aol.net
2004-05-12 01:58:37 +00:00
parent f5c57b41d9
commit 35cc1fd3ae
15 changed files with 129 additions and 123 deletions

View File

@@ -6,8 +6,6 @@
<string>148 35 445 438 0 0 1280 938 </string>
<key>IBEditorPositions</key>
<dict>
<key>124</key>
<string>58 576 170 96 0 0 1152 746 </string>
<key>297</key>
<string>72 297 213 294 0 0 1152 746 </string>
<key>314</key>
@@ -32,17 +30,7 @@
<string>337 341 606 458 0 0 1280 832 </string>
</dict>
<key>IBFramework Version</key>
<string>362.0</string>
<key>IBGroupedObjects</key>
<dict>
<key>7</key>
<array>
<string>641</string>
<string>640</string>
</array>
</dict>
<key>IBLastGroupID</key>
<string>10</string>
<string>364.0</string>
<key>IBLockedObjects</key>
<array>
<integer>748</integer>
@@ -50,6 +38,6 @@
<integer>889</integer>
</array>
<key>IBSystem Version</key>
<string>7D24</string>
<string>7F44</string>
</dict>
</plist>

View File

@@ -434,9 +434,9 @@ const int kReuseWindowOnAE = 2;
if (openInNewWindow)
[self openBrowserWindowWithURLs:[(BookmarkFolder *)item childURLs] behind:behindWindow];
else if (openInNewTab)
[browserWindowController openTabGroup:[(BookmarkFolder *)item childURLs] replaceExistingTabs:NO];
[browserWindowController openURLArray:[(BookmarkFolder *)item childURLs] replaceExistingTabs:NO];
else
[browserWindowController openTabGroup:[(BookmarkFolder *)item childURLs] replaceExistingTabs:YES];
[browserWindowController openURLArray:[(BookmarkFolder *)item childURLs] replaceExistingTabs:YES];
}
}
@@ -831,7 +831,7 @@ const int kReuseWindowOnAE = 2;
[browser showWindow: self];
}
[browser openTabGroup:urlArray replaceExistingTabs:YES];
[browser openURLArray:urlArray replaceExistingTabs:YES];
return browser;
}

View File

@@ -94,7 +94,6 @@
[super dealloc];
}
- (void)setBookmarkItem:(BookmarkItem*)aItem
{
[aItem retain];
@@ -173,42 +172,7 @@
-(NSMenu*)menuForEvent:(NSEvent*)aEvent
{
BookmarkItem *item = [self BookmarkItem];
if (item) {
NSMenu* contextMenu = [[[self superview] menu] copy];
[[contextMenu itemArray] makeObjectsPerformSelector:@selector(setTarget:) withObject: self];
NSString *nulString = [NSString string];
// clean the menu out
int numItems = [contextMenu numberOfItems];
int itemIndex = [contextMenu indexOfItemWithTarget:self andAction:@selector(showBookmarkInfo:)];
while (numItems > (itemIndex+1))
[contextMenu removeItemAtIndex:(--numItems)];
// set up menu
if ([item isKindOfClass:[Bookmark class]]) {
itemIndex = [contextMenu indexOfItemWithTarget:self andAction:@selector(openBookmarkInNewWindow:)];
[[contextMenu itemAtIndex:itemIndex] setTitle:NSLocalizedString(@"Open in New Window",@"Open in New Window")];
itemIndex = [contextMenu indexOfItemWithTarget:self andAction:@selector(openBookmarkInNewTab:)];
[[contextMenu itemAtIndex:itemIndex] setTitle:NSLocalizedString(@"Open in New Tab",@"Open in New Tab")];
} else if ([item isKindOfClass:[BookmarkFolder class]]) {
itemIndex = [contextMenu indexOfItemWithTarget:self andAction:@selector(openBookmarkInNewWindow:)];
[[contextMenu itemAtIndex:itemIndex] setTitle:NSLocalizedString(@"Open Tabs in New Window",@"Open Tabs in New Window")];
itemIndex = [contextMenu indexOfItemWithTarget:self andAction:@selector(openBookmarkInNewTab:)];
[[contextMenu itemAtIndex:itemIndex] setTitle:NSLocalizedString(@"Open in Tabs",@"Open in Tabs")];
}
// if it's a button, it's got to be on toolbar folder, so we can delete & make new folders
NSMenuItem *menuItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Delete",@"Delete") action:@selector(deleteBookmarks:) keyEquivalent:nulString];
[menuItem setTarget:self];
[contextMenu addItem:menuItem];
[menuItem release];
[contextMenu addItem:[NSMenuItem separatorItem]];
// create new folder
menuItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Create New Folder...",@"Create New Folder...") action:@selector(addFolder:) keyEquivalent:nulString];
[menuItem setTarget:self];
[contextMenu addItem:menuItem];
[menuItem release];
return [contextMenu autorelease];
}
return nil;
return [[BookmarkManager sharedBookmarkManager] contextMenuForItem:[self BookmarkItem] fromView:nil target:self];
}
//

View File

@@ -42,6 +42,7 @@
@class BookmarkFolder;
@class BookmarkImportDlgController;
@class BookmarkOutlineView;
@class KindaSmartFolderManager;
@class RunLoopMessenger;
@@ -92,6 +93,7 @@
-(NSArray *)searchBookmarksForString:(NSString *)searchString;
-(unsigned) firstUserCollection;
-(BOOL) isDropValid:(NSArray *)items toFolder:(BookmarkFolder *)parent;
-(NSMenu *)contextMenuForItem:(id)item fromView:(BookmarkOutlineView *)outlineView target:(id)target;
// Reading bookmark files
-(BOOL) readBookmarks;

View File

@@ -21,6 +21,7 @@
*
* Contributor(s):
* David Haas <haasd@cae.wisc.edu>
* Josh Aas <josha@mac.com>
*
*
* Alternatively, the contents of this file may be used under the terms of
@@ -49,6 +50,8 @@
#import "BookmarkFolder.h"
#import "BookmarkToolbar.h"
#import "BookmarkImportDlgController.h"
#import "BookmarkOutlineView.h"
#import "BookmarkViewController.h"
#import "KindaSmartFolderManager.h"
#import "BrowserWindowController.h"
#import "MainController.h"
@@ -456,6 +459,82 @@ static unsigned gFirstUserCollection = 0;
return YES;
}
// unified context menu generator for all kinds of bookmarks
// this can be called from a bookmark outline view
// or from a bookmark button, which should pass a nil outlineView
- (NSMenu *)contextMenuForItem:(id)item fromView:(BookmarkOutlineView *)outlineView target:(id)target
{
// don't do anything if item == nil
if (!item)
return nil;
NSString * nulString = [NSString string];
NSMenu * contextMenu = [[[NSMenu alloc] initWithTitle:@"notitle"] autorelease];
BOOL isFolder = [item isKindOfClass:[BookmarkFolder class]];
NSString * menuTitle;
// open in new window
if (isFolder || (outlineView && ([outlineView numberOfSelectedRows] > 1)))
menuTitle = NSLocalizedString(@"Open Tabs in New Window", @"");
else
menuTitle = NSLocalizedString(@"Open in New Window", @"");
NSMenuItem *menuItem = [[NSMenuItem alloc] initWithTitle:menuTitle action:@selector(openBookmarkInNewWindow:) keyEquivalent:nulString];
[menuItem setTarget:target];
[contextMenu addItem:menuItem];
// open in new tab
if (isFolder || ([outlineView numberOfSelectedRows] > 1))
menuTitle = NSLocalizedString(@"Open in New Tabs", @"");
else
menuTitle = NSLocalizedString(@"Open in New Tab", @"");
menuItem = [[NSMenuItem alloc] initWithTitle:menuTitle action:@selector(openBookmarkInNewTab:) keyEquivalent:nulString];
[menuItem setTarget:target];
[contextMenu addItem:menuItem];
if (!outlineView || ([outlineView numberOfSelectedRows] == 1)) {
[contextMenu addItem:[NSMenuItem separatorItem]];
menuTitle = NSLocalizedString(@"Get Info", @"");
menuItem = [[NSMenuItem alloc] initWithTitle:menuTitle action:@selector(showBookmarkInfo:) keyEquivalent:nulString];
[menuItem setTarget:target];
[contextMenu addItem:menuItem];
}
if ([item isKindOfClass:[BookmarkFolder class]]) {
menuTitle = NSLocalizedString(@"Use as Dock Menu", @"");
menuItem = [[NSMenuItem alloc] initWithTitle:menuTitle action:@selector(makeDockMenu:) keyEquivalent:nulString];
[menuItem setTarget:item];
[contextMenu addItem:menuItem];
}
BOOL allowNewFolder = NO;
if ([target isKindOfClass:[BookmarkViewController class]]) {
if (![[target activeCollection] isSmartFolder])
allowNewFolder = YES;
} else
allowNewFolder = YES;
if (allowNewFolder) {
// space
[contextMenu addItem:[NSMenuItem separatorItem]];
// create new folder
menuTitle = NSLocalizedString(@"Create New Folder...", @"");
menuItem = [[NSMenuItem alloc] initWithTitle:menuTitle action:@selector(addFolder:) keyEquivalent:nulString];
[menuItem setTarget:target];
[contextMenu addItem:menuItem];
}
id parent = [item parent];
if ([parent isKindOfClass:[BookmarkFolder class]] && ![parent isSmartFolder]) {
// space
[contextMenu addItem:[NSMenuItem separatorItem]];
// delete
menuTitle = NSLocalizedString(@"Delete", @"");
menuItem = [[NSMenuItem alloc] initWithTitle:menuTitle action:@selector(deleteBookmarks:) keyEquivalent:nulString];
[menuItem setTarget:target];
[contextMenu addItem:menuItem];
}
return contextMenu;
}
#pragma mark -
//
// BookmarkClient protocol - so we know when to write out

View File

@@ -22,6 +22,7 @@
* Contributor(s):
* Joe Hewitt <hewitt@netscape.com> (Original Author)
* David Haas <haasd@cae.wisc.edu>
* Josh Aas <josha@mac.com>
*
*
* Alternatively, the contents of this file may be used under the terms of
@@ -41,6 +42,7 @@
#import "BookmarkOutlineView.h"
#import "BookmarkFolder.h"
#import "Bookmark.h"
#import "BookmarkManager.h"
#import "NSArray+Utils.h"
@@ -51,16 +53,30 @@
[self registerForDraggedTypes:[NSArray arrayWithObjects:@"MozURLType", @"MozBookmarkType", NSStringPboardType, NSURLPboardType, nil]];
}
-(NSMenu*)menu
{
BookmarkManager *bm = [BookmarkManager sharedBookmarkManager];
BookmarkFolder *activeCollection = [[self delegate] activeCollection];
// only give a default menu if its the bookmark menu or toolbar
if ((activeCollection == [bm bookmarkMenuFolder]) || (activeCollection == [bm toolbarFolder])) {
// set up default menu
NSMenu *menu = [[[NSMenu alloc] init] autorelease];
NSMenuItem *menuItem = [[[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Create New Folder...", @"")
action:@selector(addFolder:) keyEquivalent:[NSString string]] autorelease];
[menuItem setTarget:[self delegate]];
[menu addItem:menuItem];
return menu;
}
return nil;
}
- (void)draggedImage:(NSImage *)anImage endedAt:(NSPoint)aPoint operation:(NSDragOperation)operation
{
if (operation == NSDragOperationDelete)
{
if (operation == NSDragOperationDelete) {
NSPasteboard* pboard = [NSPasteboard pasteboardWithName:NSDragPboard];
NSArray* bookmarks = [NSArray pointerArrayFromDataArrayForMozBookmarkDrop:[pboard propertyListForType: @"MozBookmarkType"]];
if (bookmarks)
{
for (unsigned int i = 0; i < [bookmarks count]; ++i)
{
if (bookmarks) {
for (unsigned int i = 0; i < [bookmarks count]; ++i) {
BookmarkItem* item = [bookmarks objectAtIndex:i];
[[item parent] deleteChild:item];
}

View File

@@ -67,7 +67,7 @@
IBOutlet BookmarkOutlineView* mItemPane;
IBOutlet NSTableView* mSearchPane; // shows search results, can be hidden
IBOutlet HistoryDataSource* mHistorySource; //can swap to this for history data
IBOutlet HistoryDataSource* mHistorySource; // can swap to this for history data
BOOL mSetupComplete; // have we been fully initialized?
BOOL mSplittersRestored; // splitters can only be positioned after we resize to fit the window

View File

@@ -20,9 +20,10 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Simon Fraser <sfraser@netscape.com>
* Max Horn <max@quendi.de>
* David Haas <haasd@cae.wisc.edu>
* Simon Fraser <sfraser@netscape.com>
* Max Horn <max@quendi.de>
* David Haas <haasd@cae.wisc.edu>
* Simon Woodside <sbwoodside@yahoo.com>
*
*
* Alternatively, the contents of this file may be used under the terms of
@@ -1141,52 +1142,9 @@ const long kMinSearchPaneHeight = 80;
return nil;
}
- (NSMenu *)outlineView:(NSOutlineView *)outlineView contextMenuForItem:(id)item
- (NSMenu *)outlineView:(NSOutlineView *)outlineView contextMenuForItem:(id)item
{
NSMenu *contextMenu = nil;
if (item) {
NSString *nulString = [NSString string];
contextMenu = [mItemPane menu];
// clean the menu out
int numItems = [contextMenu numberOfItems];
int itemIndex = [contextMenu indexOfItemWithTarget:self andAction:@selector(showBookmarkInfo:)];
while (numItems > (itemIndex+1))
[contextMenu removeItemAtIndex:(--numItems)];
if ([item isKindOfClass:[Bookmark class]]) {
itemIndex = [contextMenu indexOfItemWithTarget:self andAction:@selector(openBookmarkInNewWindow:)];
[[contextMenu itemAtIndex:itemIndex] setTitle:NSLocalizedString(@"Open in New Window",@"Open in New Window")];
itemIndex = [contextMenu indexOfItemWithTarget:self andAction:@selector(openBookmarkInNewTab:)];
[[contextMenu itemAtIndex:itemIndex] setTitle:NSLocalizedString(@"Open in New Tab",@"Open in New Tab")];
} else if ([item isKindOfClass:[BookmarkFolder class]]) {
itemIndex = [contextMenu indexOfItemWithTarget:self andAction:@selector(openBookmarkInNewWindow:)];
[[contextMenu itemAtIndex:itemIndex] setTitle:NSLocalizedString(@"Open Tabs in New Window",@"Open Tabs in New Window")];
itemIndex = [contextMenu indexOfItemWithTarget:self andAction:@selector(openBookmarkInNewTab:)];
[[contextMenu itemAtIndex:itemIndex] setTitle:NSLocalizedString(@"Open in Tabs",@"Open in Tabs")];
NSMenuItem *menuItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Use as Dock Menu",@"Use as Dock Menu") action:@selector(makeDockMenu:) keyEquivalent:nulString];
[menuItem setTarget:item];
[contextMenu addItem:menuItem];
[menuItem release];
[contextMenu addItem:[NSMenuItem separatorItem]];
}
id parent = [item parent];
if ([parent isKindOfClass:[BookmarkFolder class]] && ![parent isSmartFolder]) {
// delete
NSMenuItem *menuItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Delete",@"Delete") action:@selector(deleteBookmarks:) keyEquivalent:nulString];
[menuItem setTarget:self];
[contextMenu addItem:menuItem];
[menuItem release];
}
if (![[self activeCollection] isSmartFolder]) {
// space
[contextMenu addItem:[NSMenuItem separatorItem]];
// create new folder
NSMenuItem *menuItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Create New Folder...",@"Create New Folder...") action:@selector(addFolder:) keyEquivalent:nulString];
[menuItem setTarget:self];
[contextMenu addItem:menuItem];
[menuItem release];
}
}
return contextMenu;
return [[BookmarkManager sharedBookmarkManager] contextMenuForItem:item fromView:outlineView target:self];
}
- (void)reloadDataForItem:(id)item reloadChildren: (BOOL)aReloadChildren

View File

@@ -383,7 +383,7 @@
if ([aBookmark isKindOfClass:[Bookmark class]])
return [self handleDropOnTab:overTabViewItem overContent:overContentArea withURL:[aBookmark url]];
else if ([aBookmark isKindOfClass:[BookmarkFolder class]]) {
[[[self window] windowController] openTabGroup:[aBookmark childURLs] replaceExistingTabs:YES];
[[[self window] windowController] openURLArray:[aBookmark childURLs] replaceExistingTabs:YES];
return YES;
}
} else if ([draggedItems count] > 1) {
@@ -395,7 +395,7 @@
else if ([aBookmark isKindOfClass:[BookmarkFolder class]])
[urlArray addObjectsFromArray:[aBookmark childURLs]];
}
[[[self window] windowController] openTabGroup:urlArray replaceExistingTabs:YES];
[[[self window] windowController] openURLArray:urlArray replaceExistingTabs:YES];
return YES;
}
}

View File

@@ -282,10 +282,9 @@ typedef enum
- (IBAction)frameToThisWindow:(id)sender;
- (void)openNewWindowWithURL: (NSString*)aURLSpec referrer:(NSString*)aReferrer loadInBackground: (BOOL)aLoadInBG;
- (void)openNewWindowWithGroupURLs: (NSArray *)urlArray loadInBackground: (BOOL)aLoadInBG;
- (void)openNewTabWithURL: (NSString*)aURLSpec referrer: (NSString*)aReferrer loadInBackground: (BOOL)aLoadInBG;
- (void)openTabGroup:(NSArray*)urlArray replaceExistingTabs:(BOOL)replaceExisting;
- (void)openURLArray:(NSArray*)urlArray replaceExistingTabs:(BOOL)replaceExisting;
-(BrowserTabViewItem*)createNewTabItem;

View File

@@ -1221,7 +1221,7 @@ static NSArray* sToolbarDefaults = nil;
}
else
{
[self openTabGroup:resolvedURLs replaceExistingTabs:YES];
[self openURLArray:resolvedURLs replaceExistingTabs:YES];
}
// global history needs to know the user typed this url so it can present it
@@ -2007,12 +2007,6 @@ static NSArray* sToolbarDefaults = nil;
[browser loadURL: aURLSpec referrer:aReferrer activate:!aLoadInBG];
}
- (void)openNewWindowWithGroupURLs: (NSArray *)urlArray loadInBackground: (BOOL)aLoadInBG
{
BrowserWindowController* browser = [self openNewWindow:aLoadInBG];
[browser openTabGroup:urlArray replaceExistingTabs:YES];
}
//
// -openNewWindow:
//
@@ -2091,8 +2085,7 @@ static NSArray* sToolbarDefaults = nil;
[[[newTab view] getBrowserView] setPageDescriptor:aDesc displayType:aDisplayType];
}
- (void)openTabGroup:(NSArray*)urlArray replaceExistingTabs:(BOOL)replaceExisting
- (void)openURLArray:(NSArray*)urlArray replaceExistingTabs:(BOOL)replaceExisting
{
// ensure the content area is visible. We can't rely on normal url loading
// to do this because for the new tabs we create below, they won't be connected

View File

@@ -22,6 +22,7 @@
* Contributor(s):
* David Hyatt <hyatt@netscape.com> (Original Author)
* Max Horn <max@quendi.de> (Context menu, tooltip code, and editing)
* Josh Aas <josha@mac.com> (contextual menu fixups)
*
*
* Alternatively, the contents of this file may be used under the terms of
@@ -208,9 +209,13 @@
if ([delegate respondsToSelector:@selector(outlineView:contextMenuForItem:)])
return [delegate outlineView:self contextMenuForItem:item];
} else
} else {
// no item, no context menu
return nil;
}
}
else {
[self deselectAll:self];
}
// Just return the default context menu

View File

@@ -445,6 +445,8 @@ HistoryRDFObserver::OnChange(nsIRDFDataSource*, nsIRDFResource*,
[contextMenu addItem:menuItem];
[menuItem release];
[contextMenu addItem:[NSMenuItem separatorItem]];
// delete
menuItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Delete",@"") action:@selector(deleteHistoryItems:) keyEquivalent:nulString];
[menuItem setTarget:self];