Camino only - Bug 360345: Bookmarks code style cleanup. r=stridey sr=pink

This commit is contained in:
stuart.morgan%alumni.case.edu 2006-11-11 20:58:49 +00:00
parent 64f11e7c3f
commit d86c5d6038
29 changed files with 1403 additions and 1600 deletions

View File

@ -49,9 +49,9 @@ extern NSString* const kAddBookmarkItemPrimaryTabKey; // NSNumber with book, t
IBOutlet NSTextField* mTitleField;
IBOutlet NSPopUpButton* mParentFolderPopup;
IBOutlet NSButton* mTabGroupCheckbox;
BookmarkViewController* mBookmarkViewController; // not retained
BookmarkFolder* mInitialParentFolder;
int mInitialParentFolderIndex;
NSArray* mBookmarkItems; // array of NSDictionary

View File

@ -72,12 +72,11 @@ NSString* const kAddBookmarkItemPrimaryTabKey = @"primary";
+ (AddBookmarkDialogController*)sharedAddBookmarkDialogController
{
static AddBookmarkDialogController* sSharedController = nil;
if (!sSharedController)
{
if (!sSharedController) {
sSharedController = [[AddBookmarkDialogController alloc] initWithWindowNibName:@"AddBookmark"];
[sSharedController window]; // force nib loading
}
return sSharedController;
}
@ -90,7 +89,7 @@ NSString* const kAddBookmarkItemPrimaryTabKey = @"primary";
- (void)dealloc
{
[mTabGroupCheckbox release];
[super dealloc];
}
@ -98,7 +97,7 @@ NSString* const kAddBookmarkItemPrimaryTabKey = @"primary";
{
[[self window] orderOut:self];
[NSApp endSheet:[self window] returnCode:1];
[self createBookmarks];
[self clearState];
}
@ -129,7 +128,9 @@ NSString* const kAddBookmarkItemPrimaryTabKey = @"primary";
- (void)updateTitle:(BOOL)isTabGroup
{
NSString* defaultGroupTitle = [NSString stringWithFormat:NSLocalizedString(@"defaultTabGroupTitle", @"[%d tabs] %@"), [mBookmarkItems count], mDefaultTitle];
NSString* defaultGroupTitle = [NSString stringWithFormat:NSLocalizedString(@"defaultTabGroupTitle", @"[%d tabs] %@"),
[mBookmarkItems count],
mDefaultTitle];
// If the title is unedited, update to the default name
if ([[mTitleField stringValue] isEqualToString:mDefaultTitle] ||
@ -163,27 +164,25 @@ NSString* const kAddBookmarkItemPrimaryTabKey = @"primary";
[mBookmarkItems autorelease];
mBookmarkItems = [inItems retain];
mCreatingFolder = inIsFolder;
// set title field
if (mCreatingFolder)
[self setDefaultTitle:NSLocalizedString(@"NewBookmarkFolder", @"")];
[self setDefaultTitle:NSLocalizedString(@"NewBookmarkFolder", nil)];
else
[self setDefaultTitle:[AddBookmarkDialogController bookmarkTitleForItem:[AddBookmarkDialogController primaryBookmarkItem:inItems]]];
[mTitleField setStringValue:mDefaultTitle];
// setup tab checkbox
if (!mCreatingFolder)
{
if (!mCreatingFolder) {
if (![mTabGroupCheckbox superview])
[[[self window] contentView] addSubview:mTabGroupCheckbox];
[mTabGroupCheckbox setEnabled:([inItems count] > 1)];
}
else
{
else {
[mTabGroupCheckbox removeFromSuperview];
}
@ -216,15 +215,14 @@ NSString* const kAddBookmarkItemPrimaryTabKey = @"primary";
{
NSEnumerator* itemsEnum = [inItems objectEnumerator];
id curItem;
while ((curItem = [itemsEnum nextObject]))
{
while ((curItem = [itemsEnum nextObject])) {
if ([[curItem objectForKey:kAddBookmarkItemPrimaryTabKey] boolValue])
return curItem;
}
if ([inItems count] > 0)
return [inItems objectAtIndex:0];
return nil;
}
@ -233,7 +231,7 @@ NSString* const kAddBookmarkItemPrimaryTabKey = @"primary";
BookmarkManager* bookmarkManager = [BookmarkManager sharedBookmarkManager];
[mParentFolderPopup removeAllItems];
[[bookmarkManager rootBookmarks] buildFlatFolderList:[mParentFolderPopup menu] depth:1];
BookmarkFolder* initialFolder = mInitialParentFolder;
if (!initialFolder)
initialFolder = [bookmarkManager lastUsedBookmarkFolder];
@ -252,21 +250,17 @@ NSString* const kAddBookmarkItemPrimaryTabKey = @"primary";
BookmarkItem* newItem = nil;
unsigned int folderPosition = (mInitialParentFolderIndex != -1) ? mInitialParentFolderIndex : [parentFolder count];
if (mCreatingFolder)
{
if (mCreatingFolder) {
newItem = [parentFolder addBookmarkFolder:titleString inPosition:folderPosition isGroup:NO];
}
else
{
if (([mBookmarkItems count] > 1) && ([mTabGroupCheckbox state] == NSOnState))
{
else {
if (([mBookmarkItems count] > 1) && ([mTabGroupCheckbox state] == NSOnState)) {
// bookmark all tabs
BookmarkFolder* newGroup = [parentFolder addBookmarkFolder:titleString inPosition:folderPosition isGroup:YES];
unsigned int numItems = [mBookmarkItems count];
for (unsigned int i = 0; i < numItems; i++)
{
for (unsigned int i = 0; i < numItems; i++) {
id curItem = [mBookmarkItems objectAtIndex:i];
NSString* itemURL = [AddBookmarkDialogController bookmarkUrlForItem:curItem];
NSString* itemTitle = [AddBookmarkDialogController bookmarkTitleForItem:curItem];
@ -274,16 +268,15 @@ NSString* const kAddBookmarkItemPrimaryTabKey = @"primary";
newItem = [newGroup addBookmark:itemTitle url:itemURL inPosition:i isSeparator:NO];
}
}
else
{
else {
id curItem = [AddBookmarkDialogController primaryBookmarkItem:mBookmarkItems];
NSString* itemURL = [AddBookmarkDialogController bookmarkUrlForItem:curItem];
newItem = [parentFolder addBookmark:titleString url:itemURL inPosition:folderPosition isSeparator:NO];
}
}
}
[mBookmarkViewController revealItem:newItem scrollIntoView:YES selecting:YES byExtendingSelection:NO];
[[BookmarkManager sharedBookmarkManager] setLastUsedBookmarkFolder:parentFolder];
}

View File

@ -53,7 +53,7 @@
id mAddressBookFolder;
}
-(id)initWithFolder:(id)folder;
-(void)fillAddressBook:(NSNotification *)note;
- (id)initWithFolder:(id)folder;
- (void)fillAddressBook:(NSNotification *)note;
@end

View File

@ -52,21 +52,21 @@
NSString* mFaviconURL; // only used for <link> favicons
}
-(NSString *) url;
-(NSDate *) lastVisit;
-(unsigned) numberOfVisits;
-(unsigned) status;
- (NSString *)url;
- (NSDate *)lastVisit;
- (unsigned)numberOfVisits;
- (unsigned)status;
-(NSString*) faviconURL;
-(void) setFaviconURL:(NSString*)inURL;
- (NSString*)faviconURL;
- (void)setFaviconURL:(NSString*)inURL;
-(void) setUrl:(NSString *)aURL;
-(void) setLastVisit:(NSDate *)aLastVisit;
-(void) setStatus:(unsigned)aStatus;
-(void) setIsSeparator:(BOOL)aSeparatorFlag;
-(void) setNumberOfVisits:(unsigned)aNumber;
- (void)setUrl:(NSString *)aURL;
- (void)setLastVisit:(NSDate *)aLastVisit;
- (void)setStatus:(unsigned)aStatus;
- (void)setIsSeparator:(BOOL)aSeparatorFlag;
- (void)setNumberOfVisits:(unsigned)aNumber;
-(void) notePageLoadedWithSuccess:(BOOL)inSuccess;
- (void)notePageLoadedWithSuccess:(BOOL)inSuccess;
// methods used for saving to files; are guaranteed never to return nil
- (id)savedURL;

View File

@ -54,10 +54,9 @@ NSString* const URLLoadSuccessKey = @"url_bool";
@implementation Bookmark
-(id) init
- (id)init
{
if ((self = [super init]))
{
if ((self = [super init])) {
mURL = [[NSString alloc] init];
mStatus = kBookmarkOKStatus;
mNumberOfVisits = 0;
@ -66,7 +65,7 @@ NSString* const URLLoadSuccessKey = @"url_bool";
return self;
}
-(id) copyWithZone:(NSZone *)zone
- (id)copyWithZone:(NSZone *)zone
{
id bookmarkCopy = [super copyWithZone:zone];
[bookmarkCopy setUrl:[self url]];
@ -76,10 +75,10 @@ NSString* const URLLoadSuccessKey = @"url_bool";
return bookmarkCopy;
}
- (void) dealloc
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
mParent = NULL; // not retained, so just set to null
mParent = NULL; // not retained, so just set to null
[mURL release];
[mLastVisit release];
[super dealloc];
@ -92,54 +91,53 @@ NSString* const URLLoadSuccessKey = @"url_bool";
// set/get properties
-(NSString *) url
- (NSString *)url
{
return mURL;
}
-(NSImage *)icon
- (NSImage *)icon
{
if (!mIcon)
{
if (!mIcon) {
mIcon = [[NSImage imageNamed:@"smallbookmark"] retain];
[self refreshIcon];
}
return mIcon;
}
-(NSDate *) lastVisit
- (NSDate *)lastVisit
{
return mLastVisit;
}
-(unsigned) status
- (unsigned)status
{
return mStatus;
}
-(unsigned) numberOfVisits
- (unsigned)numberOfVisits
{
return mNumberOfVisits;
}
-(BOOL) isSeparator
- (BOOL)isSeparator
{
return (mStatus == kBookmarkSpacerStatus);
}
-(NSString*) faviconURL
- (NSString*)faviconURL
{
return mFaviconURL;
}
-(void)setFaviconURL:(NSString*)inURL
- (void)setFaviconURL:(NSString*)inURL
{
[inURL retain];
[mFaviconURL release];
mFaviconURL = inURL;
}
-(void) setStatus:(unsigned)aStatus
- (void)setStatus:(unsigned)aStatus
{
if (aStatus != mStatus) {
// There used to be more than two possible status states.
@ -147,41 +145,37 @@ NSString* const URLLoadSuccessKey = @"url_bool";
// as kBookmarkOKStatus.
if (aStatus != kBookmarkSpacerStatus)
aStatus = kBookmarkOKStatus;
mStatus = aStatus;
[self itemUpdatedNote:kBookmarkItemStatusChangedMask];
if (aStatus == kBookmarkSpacerStatus)
{
[self setTitle:NSLocalizedString(@"<Menu Spacer>", @"")];
}
[self setTitle:NSLocalizedString(@"<Menu Spacer>", nil)];
}
}
- (void) setUrl:(NSString *)aURL
- (void)setUrl:(NSString *)aURL
{
if (!aURL)
return;
if (![mURL isEqualToString:aURL])
{
if (![mURL isEqualToString:aURL]) {
[aURL retain];
[mURL release];
mURL = aURL;
[self setStatus:kBookmarkOKStatus];
// clear the icon, so we'll refresh it next time someone asks for it
[mIcon release];
mIcon = nil;
[self itemUpdatedNote:kBookmarkItemURLChangedMask];
}
}
- (void) setLastVisit:(NSDate *)aDate
- (void)setLastVisit:(NSDate *)aDate
{
if (aDate && ![mLastVisit isEqual:aDate])
{
if (aDate && ![mLastVisit isEqual:aDate]) {
[aDate retain];
[mLastVisit release];
mLastVisit = aDate;
@ -190,16 +184,15 @@ NSString* const URLLoadSuccessKey = @"url_bool";
}
}
-(void) setNumberOfVisits:(unsigned)aNumber
- (void)setNumberOfVisits:(unsigned)aNumber
{
if (mNumberOfVisits != aNumber)
{
if (mNumberOfVisits != aNumber) {
mNumberOfVisits = aNumber;
[self itemUpdatedNote:kBookmarkItemNumVisitsChangedMask];
}
}
-(void) setIsSeparator:(BOOL)aBool
- (void)setIsSeparator:(BOOL)aBool
{
if (aBool)
[self setStatus:kBookmarkSpacerStatus];
@ -207,16 +200,14 @@ NSString* const URLLoadSuccessKey = @"url_bool";
[self setStatus:kBookmarkOKStatus];
}
-(void) refreshIcon
- (void)refreshIcon
{
// don't invoke loads from the non-main thread (e.g. while loading bookmarks on a thread)
if ([NSThread inMainThread])
{
if ([NSThread inMainThread]) {
NSImage* siteIcon = [[SiteIconProvider sharedFavoriteIconProvider] favoriteIconForPage:[self url]];
if (siteIcon)
[self setIcon:siteIcon];
else if ([[BookmarkManager sharedBookmarkManager] showSiteIcons])
{
else if ([[BookmarkManager sharedBookmarkManager] showSiteIcons]) {
[[SiteIconProvider sharedFavoriteIconProvider] fetchFavoriteIconForPage:[self url]
withIconLocation:nil
allowNetwork:NO
@ -225,7 +216,7 @@ NSString* const URLLoadSuccessKey = @"url_bool";
}
}
-(void) notePageLoadedWithSuccess:(BOOL)inSuccess
- (void)notePageLoadedWithSuccess:(BOOL)inSuccess
{
[self setLastVisit:[NSDate date]];
if (inSuccess)
@ -234,14 +225,13 @@ NSString* const URLLoadSuccessKey = @"url_bool";
// rather than overriding this, it might be better to have a stub for
// -url in the base class
-(BOOL)matchesString:(NSString*)searchString inFieldWithTag:(int)tag
- (BOOL)matchesString:(NSString*)searchString inFieldWithTag:(int)tag
{
switch (tag)
{
switch (tag) {
case eBookmarksSearchFieldAll:
return (([[self url] rangeOfString:searchString options:NSCaseInsensitiveSearch].location != NSNotFound) ||
[super matchesString:searchString inFieldWithTag:tag]);
case eBookmarksSearchFieldURL:
return ([[self url] rangeOfString:searchString options:NSCaseInsensitiveSearch].location != NSNotFound);
}
@ -282,11 +272,11 @@ NSString* const URLLoadSuccessKey = @"url_bool";
// for reading/writing from/to disk
//
-(BOOL) readNativeDictionary:(NSDictionary *)aDict
- (BOOL)readNativeDictionary:(NSDictionary *)aDict
{
//gather the redundant update notifications
[self setAccumulateUpdateNotifications:YES];
[self setTitle:[aDict objectForKey:BMTitleKey]];
[self setItemDescription:[aDict objectForKey:BMDescKey]];
[self setKeyword:[aDict objectForKey:BMKeywordKey]];
@ -296,27 +286,27 @@ NSString* const URLLoadSuccessKey = @"url_bool";
[self setNumberOfVisits:[[aDict objectForKey:BMNumberVisitsKey] unsignedIntValue]];
[self setStatus:[[aDict objectForKey:BMStatusKey] unsignedIntValue]];
[self setFaviconURL:[aDict objectForKey:BMLinkedFaviconURLKey]];
//fire an update notification
[self setAccumulateUpdateNotifications:NO];
return YES;
}
-(BOOL) readSafariDictionary:(NSDictionary *)aDict
- (BOOL)readSafariDictionary:(NSDictionary *)aDict
{
//gather the redundant update notifications
[self setAccumulateUpdateNotifications:YES];
NSDictionary *uriDict = [aDict objectForKey:SafariURIDictKey];
[self setTitle:[uriDict objectForKey:SafariBookmarkTitleKey]];
[self setUrl:[aDict objectForKey:SafariURLStringKey]];
//fire an update notification
[self setAccumulateUpdateNotifications:NO];
return YES;
}
-(BOOL) readCaminoXML:(CFXMLTreeRef)aTreeRef settingToolbar:(BOOL)setupToolbar
- (BOOL)readCaminoXML:(CFXMLTreeRef)aTreeRef settingToolbar:(BOOL)setupToolbar
{
CFXMLNodeRef myNode;
CFXMLElementInfo* elementInfoPtr;
@ -335,15 +325,18 @@ NSString* const URLLoadSuccessKey = @"url_bool";
[self setUrl:[[attribDict objectForKey:CaminoURLKey] stringByRemovingAmpEscapes]];
//fire an update notification
[self setAccumulateUpdateNotifications:NO];
} else {
}
else {
NSLog(@"Bookmark:readCaminoXML - elementInfoPtr null, load failed");
return NO;
}
} else {
}
else {
NSLog(@"Bookmark:readCaminoXML - node not kCFXMLNodeTypeElement, load failed");
return NO;
}
} else {
}
else {
NSLog(@"Bookmark:readCaminoXML - urk! CFXMLTreeGetNode null, load failed");
return NO;
}
@ -357,9 +350,9 @@ NSString* const URLLoadSuccessKey = @"url_bool";
// in the given path. Using the suffix "webbookmark" allows us to pick up on the Spotlight
// importer already on Tiger for Safari.
//
-(void)writeBookmarksMetadataToPath:(NSString*)inPath
- (void)writeBookmarksMetadataToPath:(NSString*)inPath
{
NSDictionary* dict = [NSDictionary dictionaryWithObjectsAndKeys:
NSDictionary* dict = [NSDictionary dictionaryWithObjectsAndKeys:
[self savedTitle], @"Name",
[self savedURL], @"URL",
nil];
@ -374,7 +367,7 @@ NSString* const URLLoadSuccessKey = @"url_bool";
// Delete the meta data for this bookmark from the cache, which consists of a file with
// this item's UUID.
//
-(void)removeBookmarksMetadataFromPath:(NSString*)inPath
- (void)removeBookmarksMetadataFromPath:(NSString*)inPath
{
NSString* file = [self UUID];
NSString* path = [NSString stringWithFormat:@"%@/%@.webbookmark", inPath, file];
@ -382,7 +375,7 @@ NSString* const URLLoadSuccessKey = @"url_bool";
}
// for plist in native format
-(NSDictionary *)writeNativeDictionary
- (NSDictionary *)writeNativeDictionary
{
if ([self isSeparator])
return [NSDictionary dictionaryWithObject:[self savedStatus] forKey:BMStatusKey];
@ -396,21 +389,21 @@ NSString* const URLLoadSuccessKey = @"url_bool";
nil];
if ([[self itemDescription] length])
[itemDict setObject:[self itemDescription] forKey:BMDescKey];
[itemDict setObject:[self itemDescription] forKey:BMDescKey];
if ([[self keyword] length])
[itemDict setObject:[self keyword] forKey:BMKeywordKey];
[itemDict setObject:[self keyword] forKey:BMKeywordKey];
if ([mUUID length]) // don't call -UUID to avoid generating one
[itemDict setObject:mUUID forKey:BMUUIDKey];
[itemDict setObject:mUUID forKey:BMUUIDKey];
if ([[self faviconURL] length])
[itemDict setObject:[self faviconURL] forKey:BMLinkedFaviconURLKey];
[itemDict setObject:[self faviconURL] forKey:BMLinkedFaviconURLKey];
return itemDict;
}
-(NSDictionary *)writeSafariDictionary
- (NSDictionary *)writeSafariDictionary
{
NSDictionary* dict = nil;
if (![self isSeparator]) {
@ -432,7 +425,7 @@ NSString* const URLLoadSuccessKey = @"url_bool";
return dict;
}
-(NSString *)writeHTML:(unsigned int)aPad
- (NSString *)writeHTML:(unsigned int)aPad
{
NSMutableString *padString = [NSMutableString string];
for (unsigned i = 0; i < aPad; i++)
@ -470,8 +463,12 @@ NSString* const URLLoadSuccessKey = @"url_bool";
// DHBookmarks always contained in BookmarkFolder - so make
// sure we set that as the container class description.
NSScriptClassDescription *aRef = (NSScriptClassDescription*)[NSClassDescription classDescriptionForClass:[BookmarkFolder class]];
return [[[NSIndexSpecifier allocWithZone:[self zone]] initWithContainerClassDescription:aRef containerSpecifier:containerRef key:@"childArray" index:index] autorelease];
} else
return [[[NSIndexSpecifier allocWithZone:[self zone]] initWithContainerClassDescription:aRef
containerSpecifier:containerRef
key:@"childArray"
index:index] autorelease];
}
else
return nil;
}
@ -511,8 +508,7 @@ NSString* const URLLoadSuccessKey = @"url_bool";
// sort folders before other stuff
if ([aItem isKindOfClass:[BookmarkFolder class]])
result = NSOrderedDescending;
else
{
else {
int myVisits = [self numberOfVisits];
int otherVisits = [(Bookmark*)aItem numberOfVisits];
if (myVisits == otherVisits)
@ -520,7 +516,7 @@ NSString* const URLLoadSuccessKey = @"url_bool";
else
result = (otherVisits > myVisits) ? NSOrderedAscending : NSOrderedDescending;
}
return [inDescending boolValue] ? (NSComparisonResult)(-1 * (int)result) : result;
}
@ -542,8 +538,7 @@ NSString* const URLLoadSuccessKey = @"url_bool";
// sort folders before other stuff
if ([aItem isKindOfClass:[BookmarkFolder class]])
result = NSOrderedDescending;
else
{
else {
int myVisits = [self numberOfVisits];
int otherVisits = [(Bookmark*)aItem numberOfVisits];
if (myVisits == otherVisits)
@ -551,11 +546,11 @@ NSString* const URLLoadSuccessKey = @"url_bool";
else
result = (otherVisits > myVisits) ? NSOrderedAscending : NSOrderedDescending;
}
return [inDescending boolValue] ? (NSComparisonResult)(-1 * (int)result) : result;
}
@end
@end
#pragma mark -
@ -563,8 +558,7 @@ NSString* const URLLoadSuccessKey = @"url_bool";
- (id)initWithServiceID:(int)inServiceID
{
if ((self = [super init]))
{
if ((self = [super init])) {
mServiceID = inServiceID;
mResolved = NO;
}
@ -593,11 +587,11 @@ NSString* const URLLoadSuccessKey = @"url_bool";
// We don't want to write metadata files for rendezvous bookmarks,
// as they come and go all the time, and we don't correctly clean them up.
-(void)writeBookmarksMetadataToPath:(NSString*)inPath
- (void)writeBookmarksMetadataToPath:(NSString*)inPath
{
}
-(void)removeBookmarksMetadataFromPath:(NSString*)inPath
- (void)removeBookmarksMetadataFromPath:(NSString*)inPath
{
}

View File

@ -47,18 +47,18 @@
BOOL mLastEventWasMenu;
}
-(id)initWithFrame:(NSRect)frame item:(BookmarkItem*)item;
- (id)initWithFrame:(NSRect)frame item:(BookmarkItem*)item;
- (void)setBookmarkItem:(BookmarkItem*)anItem;
- (BookmarkItem*)bookmarkItem;
- (void)bookmarkChanged:(BOOL*)outNeedsReflow;
-(IBAction)openBookmark:(id)aSender;
-(IBAction)openBookmarkInNewTab:(id)aSender;
-(IBAction)openBookmarkInNewWindow:(id)aSender;
-(IBAction)showBookmarkInfo:(id)aSender;
-(IBAction)deleteBookmarks: (id)aSender;
-(IBAction)addFolder:(id)aSender;
- (IBAction)openBookmark:(id)aSender;
- (IBAction)openBookmarkInNewTab:(id)aSender;
- (IBAction)openBookmarkInNewWindow:(id)aSender;
- (IBAction)showBookmarkInfo:(id)aSender;
- (IBAction)deleteBookmarks:(id)aSender;
- (IBAction)addFolder:(id)aSender;
@end

View File

@ -63,28 +63,26 @@
- (id)initWithFrame:(NSRect)frame
{
if ( (self = [super initWithFrame:frame]) )
{
if ((self = [super initWithFrame:frame])) {
DraggableImageAndTextCell* newCell = [[[DraggableImageAndTextCell alloc] init] autorelease];
[newCell setDraggable:YES];
[self setCell:newCell];
[self setBezelStyle: NSRegularSquareBezelStyle];
[self setButtonType: NSMomentaryChangeButton];
[self setBordered: NO];
[self setImagePosition: NSImageLeft];
[self setRefusesFirstResponder: YES];
[self setFont: [NSFont labelFontOfSize: 11.0]];
[self setBezelStyle:NSRegularSquareBezelStyle];
[self setButtonType:NSMomentaryChangeButton];
[self setBordered:NO];
[self setImagePosition:NSImageLeft];
[self setRefusesFirstResponder:YES];
[self setFont:[NSFont labelFontOfSize:11.0]];
mLastEventWasMenu = NO;
}
return self;
}
-(id)initWithFrame:(NSRect)frame item:(BookmarkItem*)item
- (id)initWithFrame:(NSRect)frame item:(BookmarkItem*)item
{
if ( (self = [self initWithFrame:frame]) )
{
if ((self = [self initWithFrame:frame])) {
[self setBookmarkItem:item];
}
return self;
@ -110,8 +108,8 @@
return;
}
[self setAction:@selector(openBookmark:)];
NSString* tooltipString = [NSString stringWithFormat:NSLocalizedString(@"BookmarkButtonTooltipFormat", @""),
NSString* tooltipString = [NSString stringWithFormat:NSLocalizedString(@"BookmarkButtonTooltipFormat", nil),
[bookmarkItem title],
[bookmarkItem url]];
// using "\n\n" as a tooltip string causes Cocoa to hang when displaying the tooltip,
@ -123,7 +121,7 @@
[[self cell] setClickHoldTimeout:0.5];
if ([(BookmarkFolder *)aItem isGroup])
[self setAction:@selector(openBookmark:)];
else
else
[self setAction:@selector(showFolderPopupAction:)];
}
[self setTitle:[aItem title]];
@ -133,25 +131,22 @@
- (void)bookmarkChanged:(BOOL*)outNeedsReflow
{
if (![[self title] isEqualToString:[mItem title]])
{
if (![[self title] isEqualToString:[mItem title]]) {
*outNeedsReflow = YES; // assume title width changed
[self setTitle:[mItem title]];
}
if ([self image] != [mItem icon])
{
if ([self image] != [mItem icon]) {
// all images are the same size, so this won't trigger reflows
*outNeedsReflow = !NSEqualSizes([[self image] size], [[mItem icon] size]);
[self setImage:[mItem icon]];
}
// folder items can be toggled between folders and tab groups
if ([mItem isKindOfClass:[BookmarkFolder class]])
{
if ([mItem isKindOfClass:[BookmarkFolder class]]) {
if ([(BookmarkFolder *)mItem isGroup])
[self setAction:@selector(openBookmark:)];
else
else
[self setAction:@selector(showFolderPopupAction:)];
}
}
@ -161,7 +156,7 @@
return mItem;
}
-(IBAction)openBookmark:(id)aSender
- (IBAction)openBookmark:(id)aSender
{
BrowserWindowController* brController = [[self window] windowController];
BookmarkItem *item = [self bookmarkItem];
@ -173,7 +168,7 @@
[[NSApp delegate] loadBookmark:item withBWC:brController openBehavior:openBehavior reverseBgToggle:reverseBGPref];
}
-(IBAction)openBookmarkInNewTab:(id)aSender
- (IBAction)openBookmarkInNewTab:(id)aSender
{
BrowserWindowController* brController = [[self window] windowController];
BookmarkItem *item = [self bookmarkItem];
@ -182,7 +177,7 @@
[[NSApp delegate] loadBookmark:item withBWC:brController openBehavior:eBookmarkOpenBehavior_NewTab reverseBgToggle:reverseBGPref];
}
-(IBAction)openBookmarkInNewWindow:(id)aSender
- (IBAction)openBookmarkInNewWindow:(id)aSender
{
BrowserWindowController* brController = [[self window] windowController];
BookmarkItem *item = [self bookmarkItem];
@ -193,17 +188,18 @@
- (IBAction)copyURLs:(id)aSender
{
[[BookmarkManager sharedBookmarkManager] copyBookmarksURLs:[NSArray arrayWithObject:[self bookmarkItem]] toPasteboard:[NSPasteboard generalPasteboard]];
[[BookmarkManager sharedBookmarkManager] copyBookmarksURLs:[NSArray arrayWithObject:[self bookmarkItem]]
toPasteboard:[NSPasteboard generalPasteboard]];
}
-(IBAction)showBookmarkInfo:(id)aSender
- (IBAction)showBookmarkInfo:(id)aSender
{
BookmarkInfoController *bic = [BookmarkInfoController sharedBookmarkInfoController];
[bic setBookmark:[self bookmarkItem]];
[bic showWindow:self];
}
-(IBAction)deleteBookmarks: (id)aSender
- (IBAction)deleteBookmarks:(id)aSender
{
BookmarkItem *item = [self bookmarkItem];
BOOL deleted = [[item parent] deleteChild:item];
@ -211,20 +207,20 @@
[self removeFromSuperview];
}
-(IBAction)addFolder:(id)aSender
- (IBAction)addFolder:(id)aSender
{
BookmarkManager* bmManager = [BookmarkManager sharedBookmarkManager];
BookmarkFolder* toolbarFolder = [bmManager toolbarFolder];
BookmarkFolder* aFolder = [toolbarFolder addBookmarkFolder];
[aFolder setTitle:NSLocalizedString(@"NewBookmarkFolder", @"New Folder")];
[aFolder setTitle:NSLocalizedString(@"NewBookmarkFolder", nil)];
}
-(void)drawRect:(NSRect)aRect
- (void)drawRect:(NSRect)aRect
{
[super drawRect:aRect];
}
-(NSMenu*)menuForEvent:(NSEvent*)aEvent
- (NSMenu*)menuForEvent:(NSEvent*)aEvent
{
mLastEventWasMenu = YES;
NSArray* theItemArray = [NSArray arrayWithObject:[self bookmarkItem]];
@ -234,7 +230,7 @@
//
// context menu has only what we need
//
-(BOOL)validateMenuItem:(NSMenuItem*)aMenuItem
- (BOOL)validateMenuItem:(NSMenuItem*)aMenuItem
{
if ([[self bookmarkItem] isKindOfClass:[Bookmark class]] && [(Bookmark *)[self bookmarkItem] isSeparator]) {
SEL action = [aMenuItem action];
@ -264,16 +260,16 @@
// dummy first item
id dummyItem = [bmMenu addItemWithTitle:@"" action:NULL keyEquivalent:@""];
[bmMenu setItemBeforeCustomItems:dummyItem];
// use a temporary NSPopUpButtonCell to display the menu.
NSPopUpButtonCell *popupCell = [[NSPopUpButtonCell alloc] initTextCell:@"" pullsDown:YES];
[popupCell setMenu: bmMenu];
NSPopUpButtonCell *popupCell = [[NSPopUpButtonCell alloc] initTextCell:@"" pullsDown:YES];
[popupCell setMenu:bmMenu];
[popupCell trackMouse:event inRect:[self bounds] ofView:self untilMouseUp:YES];
mLastEventWasMenu = YES;
[popupCell release];
}
-(void)mouseDown:(NSEvent*)aEvent
- (void)mouseDown:(NSEvent*)aEvent
{
mLastEventWasMenu = NO;
[super mouseDown:aEvent];
@ -289,7 +285,7 @@
return (NSDragOperationDelete | NSDragOperationGeneric);
}
- (void) mouseDragged: (NSEvent*) aEvent
- (void)mouseDragged:(NSEvent*)aEvent
{
// hack to prevent a drag while viewing a popup or context menu from moving the folder unexpectedly
// (unless the drag happens on the folder itself)
@ -300,42 +296,41 @@
BOOL isSingleBookmark = [item isKindOfClass:[Bookmark class]];
NSPasteboard *pboard = [NSPasteboard pasteboardWithName:NSDragPboard];
NSString *title = [item title];
if (isSingleBookmark)
{
if (isSingleBookmark) {
[pboard declareURLPasteboardWithAdditionalTypes:[NSArray arrayWithObject:kCaminoBookmarkListPBoardType] owner:self];
NSString *url = [(Bookmark *)item url];
NSString *cleanedTitle = [title stringByReplacingCharactersInSet:[NSCharacterSet controlCharacterSet] withString:@" "];
NSString *url = [(Bookmark *)item url];
NSString *cleanedTitle = [title stringByReplacingCharactersInSet:[NSCharacterSet controlCharacterSet] withString:@" "];
[pboard setDataForURL:url title:cleanedTitle];
}
else
{
else {
[pboard declareTypes:[NSArray arrayWithObject:kCaminoBookmarkListPBoardType] owner:self];
}
// kCaminoBookmarkListPBoardType
NSArray *pointerArray = [BookmarkManager serializableArrayWithBookmarkItems:[NSArray arrayWithObject:item]];
[pboard setPropertyList:pointerArray forType: kCaminoBookmarkListPBoardType];
[pboard setPropertyList:pointerArray forType:kCaminoBookmarkListPBoardType];
// If the drag results in the bookmark button being (re)moved, it could get
// deallocated too soon. This occurs with SDK >= 10.3, but not earlier.
// Change in cleanup strategy? Hold on tight.
[[self retain] autorelease];
[self dragImage: [MainController createImageForDragging:[self image]
title:([item isSeparator] ? @"" : title)]
at: NSMakePoint(0,NSHeight([self bounds])) offset: NSMakeSize(0,0)
event: aEvent pasteboard: pboard source: self slideBack: YES];
[self dragImage:[MainController createImageForDragging:[self image]
title:([item isSeparator] ? @"" : title)]
at:NSMakePoint(0, NSHeight([self bounds]))
offset:NSMakeSize(0, 0)
event:aEvent
pasteboard:pboard
source:self
slideBack:YES];
}
- (void)draggedImage:(NSImage *)anImage endedAt:(NSPoint)aPoint operation:(NSDragOperation)operation
{
if (operation == NSDragOperationDelete)
{
if (operation == NSDragOperationDelete) {
NSPasteboard* pboard = [NSPasteboard pasteboardWithName:NSDragPboard];
NSArray* bookmarks = [BookmarkManager bookmarkItemsFromSerializableArray:[pboard propertyListForType: kCaminoBookmarkListPBoardType]];
if (bookmarks)
{
for (unsigned int i = 0; i < [bookmarks count]; ++i)
{
NSArray* bookmarks = [BookmarkManager bookmarkItemsFromSerializableArray:[pboard propertyListForType:kCaminoBookmarkListPBoardType]];
if (bookmarks) {
for (unsigned int i = 0; i < [bookmarks count]; ++i) {
BookmarkItem* item = [bookmarks objectAtIndex:i];
[[item parent] deleteChild:item];
}

View File

@ -60,72 +60,79 @@ enum {
NSString* mIdentifier; // only non-nil for "special" collection folders. not saved (yet)
}
-(id) init; // designated initializer
-(id) initWithIdentifier:(NSString*)inIdentifier; // will get used for special folders
-(NSMutableArray *) childArray;
-(NSArray *) childURLs;
-(NSArray *) allChildBookmarks;
- (id)init; // designated initializer
- (id)initWithIdentifier:(NSString*)inIdentifier; // will get used for special folders
- (NSMutableArray *)childArray;
- (NSArray *)childURLs;
- (NSArray *)allChildBookmarks;
// enumerator for this folder and all its children (in depth-first order). not safe under
// tree changes during enumeration
-(NSEnumerator*)objectEnumerator;
- (NSEnumerator*)objectEnumerator;
-(void)setIdentifier:(NSString*)inIdentifier;
-(NSString*)identifier;
- (void)setIdentifier:(NSString*)inIdentifier;
- (NSString*)identifier;
-(BOOL) isSpecial;
-(BOOL) isToolbar;
-(BOOL) isRoot;
-(BOOL) isGroup;
-(BOOL) isSmartFolder;
-(BOOL) isDockMenu;
- (BOOL)isSpecial;
- (BOOL)isToolbar;
- (BOOL)isRoot;
- (BOOL)isGroup;
- (BOOL)isSmartFolder;
- (BOOL)isDockMenu;
-(void) setChildArray:(NSMutableArray *)aChildArray; //should be private?
-(void) setIsGroup:(BOOL)aGroupFlag; //AE code: DBAg
-(void) setIsRoot:(BOOL)aFlag;
-(void) setIsToolbar:(BOOL)aFlag;
-(void) setIsSmartFolder:(BOOL)aFlag;
-(void) setIsDockMenu:(BOOL)aFlag;
-(void) makeDockMenu:(id)sender;
- (void)setChildArray:(NSMutableArray *)aChildArray; //should be private?
- (void)setIsGroup:(BOOL)aGroupFlag; //AE code: DBAg
- (void)setIsRoot:(BOOL)aFlag;
- (void)setIsToolbar:(BOOL)aFlag;
- (void)setIsSmartFolder:(BOOL)aFlag;
- (void)setIsDockMenu:(BOOL)aFlag;
- (void)makeDockMenu:(id)sender;
// Things added to make it work sort of like an array
-(unsigned) count;
-(id) objectAtIndex:(unsigned)index;
-(unsigned)indexOfObject:(id)object;
-(unsigned)indexOfObjectIdenticalTo:(id)object;
- (unsigned)count;
- (id)objectAtIndex:(unsigned)index;
- (unsigned)indexOfObject:(id)object;
- (unsigned)indexOfObjectIdenticalTo:(id)object;
// methods used for saving to files; are guaranteed never to return nil
- (id)savedSpecialFlag;
// ways to add a new bookmark
-(Bookmark *) addBookmark; //adds to end
-(Bookmark *) addBookmark:(NSString *)aTitle url:(NSString *)aURL inPosition:(unsigned)aIndex isSeparator:(BOOL)aBool;
-(Bookmark *) addBookmark:(NSString *)aTitle inPosition:(unsigned)aIndex keyword:(NSString *)aKeyword url:(NSString *)aURL description:(NSString *)aDescription lastVisit:(NSDate *)aDate status:(unsigned)aStatus isSeparator:(BOOL)aBool;
- (Bookmark *)addBookmark; //adds to end
- (Bookmark *)addBookmark:(NSString *)aTitle url:(NSString *)aURL inPosition:(unsigned)aIndex isSeparator:(BOOL)aBool;
- (Bookmark *)addBookmark:(NSString *)aTitle
inPosition:(unsigned)aIndex
keyword:(NSString *)aKeyword
url:(NSString *)aURL
description:(NSString *)aDescription
lastVisit:(NSDate *)aDate
status:(unsigned)aStatus
isSeparator:(BOOL)aBool;
// ways to add a new bookmark array
-(BookmarkFolder *) addBookmarkFolder; //adds to end
-(BookmarkFolder *) addBookmarkFolder:(NSString *)aTitle inPosition:(unsigned)aIndex isGroup:(BOOL)aFlag;
- (BookmarkFolder *)addBookmarkFolder; //adds to end
- (BookmarkFolder *)addBookmarkFolder:(NSString *)aTitle inPosition:(unsigned)aIndex isGroup:(BOOL)aFlag;
// finding items by uuid
-(BookmarkItem *)itemWithUUID:(NSString*)uuid;
- (BookmarkItem *)itemWithUUID:(NSString*)uuid;
// Moving & Copying & inserting bookmarks/bookmark arrays
-(void) appendChild:(BookmarkItem *)aChild;
-(void) insertChild:(BookmarkItem *)aChild atIndex:(unsigned)aIndex isMove:(BOOL)aBool;
-(void) moveChild:(BookmarkItem *)aChild toBookmarkFolder:(BookmarkFolder *)aNewParent atIndex:(unsigned)aIndex;
- (void)appendChild:(BookmarkItem *)aChild;
- (void)insertChild:(BookmarkItem *)aChild atIndex:(unsigned)aIndex isMove:(BOOL)aBool;
- (void)moveChild:(BookmarkItem *)aChild toBookmarkFolder:(BookmarkFolder *)aNewParent atIndex:(unsigned)aIndex;
// returns the new child
-(BookmarkItem*) copyChild:(BookmarkItem *)aChild toBookmarkFolder:(BookmarkFolder *)aNewParent atIndex:(unsigned)aIndex;
- (BookmarkItem*)copyChild:(BookmarkItem *)aChild toBookmarkFolder:(BookmarkFolder *)aNewParent atIndex:(unsigned)aIndex;
// Used for deleting bookmarks/bookmark arrays
-(BOOL) deleteChild:(BookmarkItem *)aChild;
- (BOOL)deleteChild:(BookmarkItem *)aChild;
// used for batch notifying about changes to this folder's children (and descendants)
-(void) notifyChildrenChanged;
- (void)notifyChildrenChanged;
// Smart Folder only methods
-(void) insertIntoSmartFolderChild:(BookmarkItem *)aItem;
-(void) insertIntoSmartFolderChild:(BookmarkItem *)aItem atIndex:(unsigned)inIndex;
-(void) deleteFromSmartFolderChildAtIndex:(unsigned)index;
- (void)insertIntoSmartFolderChild:(BookmarkItem *)aItem;
- (void)insertIntoSmartFolderChild:(BookmarkItem *)aItem atIndex:(unsigned)inIndex;
- (void)deleteFromSmartFolderChildAtIndex:(unsigned)index;
// sorting
// Arrange the given items (which must be children of this folder) next to eachother and in
@ -135,17 +142,17 @@ enum {
- (void)sortChildrenUsingSelector:(SEL)inSelector reverseSort:(BOOL)inReverse sortDeep:(BOOL)inDeep undoable:(BOOL)inUndoable;
// generation menus
-(void) buildFlatFolderList:(NSMenu *)menu depth:(unsigned)pad;
- (void)buildFlatFolderList:(NSMenu *)menu depth:(unsigned)pad;
// searching
-(NSArray*)resolveKeyword:(NSString *)keyword withArgs:(NSString *)args;
-(NSSet *) bookmarksWithString:(NSString *)searchString inFieldWithTag:(int)tag;
- (NSArray*)resolveKeyword:(NSString *)keyword withArgs:(NSString *)args;
- (NSSet *)bookmarksWithString:(NSString *)searchString inFieldWithTag:(int)tag;
- (BOOL)containsChildItem:(BookmarkItem*)inItem;
// Scripting - should be a protocol we could use for these
// two, but i'm not sure which one, so we'll declare them here
// and avoid the compiler warning
-(NSArray *) indicesOfObjectsByEvaluatingRelativeSpecifier:(NSRelativeSpecifier *)relSpec;
-(NSArray *) indicesOfObjectsByEvaluatingRangeSpecifier:(NSRangeSpecifier *)rangeSpec;
- (NSArray *)indicesOfObjectsByEvaluatingRelativeSpecifier:(NSRelativeSpecifier *)relSpec;
- (NSArray *)indicesOfObjectsByEvaluatingRangeSpecifier:(NSRangeSpecifier *)rangeSpec;
@end

File diff suppressed because it is too large Load Diff

View File

@ -42,18 +42,18 @@
@interface BookmarkImportDlgController : NSWindowController {
IBOutlet NSPopUpButton* mBrowserListButton;
IBOutlet NSButton* mCancelButton;
IBOutlet NSButton* mImportButton;
IBOutlet NSProgressIndicator* mImportProgressBar;
IBOutlet NSView* mImportView;
IBOutlet NSView* mProgressView;
IBOutlet NSButton* mImportButton;
IBOutlet NSProgressIndicator* mImportProgressBar;
IBOutlet NSView* mImportView;
IBOutlet NSView* mProgressView;
}
-(void) buildAvailableFileList;
-(IBAction) cancel:(id)aSender;
-(IBAction) import:(id)aSender;
-(IBAction) loadOpenPanel:(id)aSender;
-(IBAction) nullAction:(id)aSender;
-(void) alertSheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo;
-(void) finishThreadedImport:(BOOL)success fromFile:(NSString *)aFile;
- (void)buildAvailableFileList;
- (IBAction)cancel:(id)aSender;
- (IBAction)import:(id)aSender;
- (IBAction)loadOpenPanel:(id)aSender;
- (IBAction)nullAction:(id)aSender;
- (void)alertSheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo;
- (void)finishThreadedImport:(BOOL)success fromFile:(NSString *)aFile;
@end

View File

@ -45,16 +45,16 @@
@interface BookmarkImportDlgController (Private)
-(void) tryAddImportFromBrowser: (NSString *) aBrowserName withBookmarkPath: (NSString *) aPath;
-(void) tryOmniWeb5Import;
-(void) buildButtonForBrowser:(NSString *) aBrowserName withPathArray:(NSArray *)anArray;
-(NSString *) getSaltedBookmarkPathForProfile: (NSString *) aPath;
-(void) beginImportFrom:(NSArray *)aPath withTitles:(NSArray *)anArray;
-(void) beginOmniWeb5ImportFrom:(NSArray *)anArray;
-(void) finishImport:(BOOL)success fromFiles:(NSArray *)anArray;
-(void) finishThreadedImport:(BOOL)success fromFiles:(NSArray *)anArray;
-(void) showProgressView;
-(void) showImportView;
- (void)tryAddImportFromBrowser:(NSString *)aBrowserName withBookmarkPath:(NSString *)aPath;
- (void)tryOmniWeb5Import;
- (void)buildButtonForBrowser:(NSString *)aBrowserName withPathArray:(NSArray *)anArray;
- (NSString *)getSaltedBookmarkPathForProfile:(NSString *)aPath;
- (void)beginImportFrom:(NSArray *)aPath withTitles:(NSArray *)anArray;
- (void)beginOmniWeb5ImportFrom:(NSArray *)anArray;
- (void)finishImport:(BOOL)success fromFiles:(NSArray *)anArray;
- (void)finishThreadedImport:(BOOL)success fromFiles:(NSArray *)anArray;
- (void)showProgressView;
- (void)showImportView;
@end
@ -62,22 +62,22 @@
@implementation BookmarkImportDlgController
-(void) windowDidLoad
- (void)windowDidLoad
{
[self showImportView];
[self buildAvailableFileList];
}
// Check for common webbrower bookmark files and, if they exist, add import buttons.
-(void) buildAvailableFileList
- (void)buildAvailableFileList
{
NSString *mozPath;
// Remove everything but the separator and "Select a file..." option, on the off-chance that someone brings
// up the import dialog, throws away a profile, then brings up the import dialog again
while ([mBrowserListButton numberOfItems] > 2)
[mBrowserListButton removeItemAtIndex:0];
[self tryAddImportFromBrowser:@"iCab" withBookmarkPath:@"~/Library/Preferences/iCab Preferences/Hotlist.html"];
[self tryAddImportFromBrowser:@"Opera" withBookmarkPath:@"~/Library/Preferences/Opera Preferences/Bookmarks"];
[self tryAddImportFromBrowser:@"OmniWeb 4" withBookmarkPath:@"~/Library/Application Support/Omniweb/Bookmarks.html"];
@ -85,11 +85,11 @@
[self tryOmniWeb5Import];
[self tryAddImportFromBrowser:@"Internet Explorer" withBookmarkPath:@"~/Library/Preferences/Explorer/Favorites.html"];
[self tryAddImportFromBrowser:@"Safari" withBookmarkPath:@"~/Library/Safari/Bookmarks.plist"];
mozPath = [self getSaltedBookmarkPathForProfile:@"~/Library/Mozilla/Profiles/default/"];
if (mozPath)
[self tryAddImportFromBrowser:@"Netscape/Mozilla" withBookmarkPath:mozPath];
// Try Firefox from different locations in the reverse order of their introduction
mozPath = [self getSaltedBookmarkPathForProfile:@"~/Library/Application Support/Firefox/Profiles/"];
if (!mozPath)
@ -98,14 +98,14 @@
mozPath = [self getSaltedBookmarkPathForProfile:@"~/Library/Phoenix/Profiles/default/"];
if (mozPath)
[self tryAddImportFromBrowser:@"Mozilla Firefox" withBookmarkPath:mozPath];
[mBrowserListButton selectItemAtIndex:0];
[mBrowserListButton synchronizeTitleAndSelectedItem];
}
// Checks for the existence of the specified bookmarks file, and adds an import option for
// the given browser if the file is found.
-(void) tryAddImportFromBrowser: (NSString *) aBrowserName withBookmarkPath: (NSString *) aPath
- (void)tryAddImportFromBrowser:(NSString *)aBrowserName withBookmarkPath:(NSString *)aPath
{
NSFileManager *fm = [NSFileManager defaultManager];
NSString *fullPathString = [aPath stringByStandardizingPath];
@ -115,10 +115,10 @@
}
// Special treatment for OmniWeb 5
-(void) tryOmniWeb5Import
- (void)tryOmniWeb5Import
{
NSArray *owFiles = [NSArray arrayWithObjects:
@"~/Library/Application Support/OmniWeb 5/Bookmarks.html",
@"~/Library/Application Support/OmniWeb 5/Bookmarks.html",
@"~/Library/Application Support/OmniWeb 5/Favorites.html",
@"~/Library/Application Support/OmniWeb 5/Published.html",
nil];
@ -126,21 +126,19 @@
NSEnumerator *enumerator = [owFiles objectEnumerator];
NSFileManager *fm = [NSFileManager defaultManager];
NSString *aPath, *fullPathString;
while ( (aPath = [enumerator nextObject]) ) {
while ((aPath = [enumerator nextObject])) {
fullPathString = [aPath stringByStandardizingPath];
if ([fm fileExistsAtPath:fullPathString]) {
[haveFiles addObject:fullPathString];
}
}
if ([haveFiles count] > 0)
{
[self buildButtonForBrowser:@"OmniWeb 5" withPathArray:haveFiles];
}
}
// Given a Mozilla-like profile, returns the bookmarks.html file in the salt directory,
// or nil if no salt directory is found
-(NSString *) getSaltedBookmarkPathForProfile: (NSString *) aPath
- (NSString *)getSaltedBookmarkPathForProfile:(NSString *)aPath
{
NSFileManager *fm = [NSFileManager defaultManager];
id aTempItem;
@ -150,42 +148,42 @@
NSEnumerator *enumerator = [saltArray objectEnumerator];
while ((aTempItem = [enumerator nextObject])) {
if (![aTempItem hasPrefix:@"."])
return [fullPathString stringByAppendingFormat:@"/%@/bookmarks.html",aTempItem];
return [fullPathString stringByAppendingFormat:@"/%@/bookmarks.html", aTempItem];
}
}
return nil;
}
-(void) buildButtonForBrowser:(NSString *) aBrowserName withPathArray:(NSArray *)anArray
- (void)buildButtonForBrowser:(NSString *)aBrowserName withPathArray:(NSArray *)anArray
{
[mBrowserListButton insertItemWithTitle:aBrowserName atIndex:0];
NSMenuItem *browserItem = [mBrowserListButton itemAtIndex:0];
[browserItem setTarget:self];
[browserItem setAction:@selector(nullAction:)];
[browserItem setRepresentedObject:anArray];
[browserItem setRepresentedObject:anArray];
}
// keeps browsers turned on
-(IBAction) nullAction:(id)aSender
- (IBAction)nullAction:(id)aSender
{
}
-(IBAction) cancel:(id)aSender
- (IBAction)cancel:(id)aSender
{
[[self window] orderOut:self];
}
-(IBAction) import:(id)aSender
- (IBAction)import:(id)aSender
{
NSMenuItem *selectedItem = [mBrowserListButton selectedItem];
NSString *titleString;
if ([[selectedItem title] isEqualToString:@"Internet Explorer"])
titleString = [NSString stringWithString:NSLocalizedString(@"Imported IE Favorites", @"")];
titleString = [NSString stringWithString:NSLocalizedString(@"Imported IE Favorites", nil)];
else
titleString = [NSString stringWithFormat:NSLocalizedString(@"Imported %@ Bookmarks", @""), [selectedItem title]];
titleString = [NSString stringWithFormat:NSLocalizedString(@"Imported %@ Bookmarks", nil), [selectedItem title]];
// Stupid OmniWeb 5 gets its own import function
if ( [[selectedItem title] isEqualToString:@"OmniWeb 5"] ) {
if ([[selectedItem title] isEqualToString:@"OmniWeb 5"]) {
[self beginOmniWeb5ImportFrom:[selectedItem representedObject]];
}
else {
@ -193,73 +191,67 @@
}
}
-(IBAction) loadOpenPanel:(id)aSender
- (IBAction)loadOpenPanel:(id)aSender
{
NSOpenPanel* openPanel = [NSOpenPanel openPanel];
[openPanel setCanChooseFiles: YES];
[openPanel setCanChooseDirectories: NO];
[openPanel setAllowsMultipleSelection: NO];
[openPanel setPrompt: @"Import"];
NSArray* array = [NSArray arrayWithObjects: @"htm",@"html",@"xml", @"plist",nil];
int result = [openPanel runModalForDirectory: nil
file: nil
types: array];
[openPanel setCanChooseFiles:YES];
[openPanel setCanChooseDirectories:NO];
[openPanel setAllowsMultipleSelection:NO];
[openPanel setPrompt:@"Import"];
NSArray* array = [NSArray arrayWithObjects:@"htm", @"html", @"xml", @"plist", nil];
int result = [openPanel runModalForDirectory:nil
file:nil
types:array];
if (result == NSOKButton) {
NSString *pathToFile = [[openPanel filenames] objectAtIndex:0];
[self beginImportFrom:[NSArray arrayWithObject:pathToFile]
withTitles:[NSArray arrayWithObject:NSLocalizedString(@"Imported Bookmarks",@"Imported Bookmarks")]];
[self beginImportFrom:[NSArray arrayWithObject:pathToFile]
withTitles:[NSArray arrayWithObject:NSLocalizedString(@"Imported Bookmarks", nil)]];
}
}
-(void) beginOmniWeb5ImportFrom:(NSArray *)anArray
- (void)beginOmniWeb5ImportFrom:(NSArray *)anArray
{
NSEnumerator *enumerator = [anArray objectEnumerator];
NSMutableArray *titleArray= [NSMutableArray array];
NSString* curFilename = nil;
NSString *curPath = nil;
while ( curPath = [enumerator nextObject] )
{
while (curPath = [enumerator nextObject]) {
curFilename = [curPath lastPathComponent];
// What folder we import into depends on what OmniWeb file we're importing.
if ([curFilename isEqualToString:@"Bookmarks.html"] )
{
[titleArray addObject:NSLocalizedString(@"Imported OmniWeb 5 Bookmarks", @"Imported OmniWeb 5 Bookmarks")];
}
else if ([curFilename isEqualToString:@"Favorites.html"] )
{
[titleArray addObject:NSLocalizedString(@"OmniWeb Favorites", @"OmniWeb Favorites")];
}
if ([curFilename isEqualToString:@"Bookmarks.html"])
[titleArray addObject:NSLocalizedString(@"Imported OmniWeb 5 Bookmarks", nil)];
else if ([curFilename isEqualToString:@"Favorites.html"])
[titleArray addObject:NSLocalizedString(@"OmniWeb Favorites", nil)];
else if ([curFilename isEqualToString:@"Published.html"])
{
[titleArray addObject:NSLocalizedString(@"OmniWeb Published", @"OmniWeb Published")];
}
[titleArray addObject:NSLocalizedString(@"OmniWeb Published", nil)];
}
[self beginImportFrom:anArray withTitles:titleArray];
}
-(void) beginImportFrom:(NSArray *) aPathArray withTitles:(NSArray *)aTitleArray
- (void)beginImportFrom:(NSArray *)aPathArray withTitles:(NSArray *)aTitleArray
{
[self showProgressView];
NSDictionary *aDict = [NSDictionary dictionaryWithObjectsAndKeys: aPathArray, kBookmarkImportPathIndentifier,
NSDictionary *aDict = [NSDictionary dictionaryWithObjectsAndKeys:aPathArray, kBookmarkImportPathIndentifier,
aTitleArray, kBookmarkImportNewFolderNameIdentifier, nil];
[NSThread detachNewThreadSelector:@selector(importBookmarksThreadEntry:)
toTarget:[BookmarkManager sharedBookmarkManager]
withObject:aDict];
withObject:aDict];
}
-(void) finishThreadedImport:(BOOL)success fromFile:(NSString *)aFile
- (void)finishThreadedImport:(BOOL)success fromFile:(NSString *)aFile
{
if (success)
{
BrowserWindowController* windowController = [(MainController *)[NSApp delegate] openBrowserWindowWithURL:@"about:bookmarks" andReferrer:nil behind:nil allowPopups:NO];
if (success) {
BrowserWindowController* windowController = [(MainController *)[NSApp delegate] openBrowserWindowWithURL:@"about:bookmarks"
andReferrer:nil
behind:nil
allowPopups:NO];
BookmarkViewController* bmController = [windowController bookmarkViewController];
BookmarkFolder *rootFolder = [[BookmarkManager sharedBookmarkManager] rootBookmarks];
BookmarkFolder *newFolder = [rootFolder objectAtIndex:([rootFolder count] - 1)];
[bmController setItemToRevealOnLoad:newFolder];
}
else
{
NSBeginAlertSheet(NSLocalizedString(@"ImportFailureTitle", @"Import Failed"), // title
else {
NSBeginAlertSheet(NSLocalizedString(@"ImportFailureTitle", nil), // title
@"", // default button
nil, // no cancel buttton
nil, // no third button
@ -268,29 +260,29 @@
@selector(alertSheetDidEnd:returnCode:contextInfo:),
nil, // no dismiss sel
(void *)NULL, // no context
[NSString stringWithFormat:NSLocalizedString(@"ImportFailureMessage", @"The file '%@' is not a supported bookmark file type."), aFile]
[NSString stringWithFormat:NSLocalizedString(@"ImportFailureMessage", nil), aFile]
);
}
[[self window] orderOut:self];
[self showImportView];
}
-(void) alertSheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
- (void)alertSheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
{
[[self window] orderOut:self];
}
-(void) showProgressView
- (void)showProgressView
{
NSSize viewSize = [mProgressView frame].size;
[[self window] setContentView:mProgressView];
[[self window] setContentSize:viewSize];
[[self window] center];
[mImportProgressBar setUsesThreadedAnimation:YES];
[mImportProgressBar startAnimation:self];
[mImportProgressBar startAnimation:self];
}
-(void) showImportView
- (void)showImportView
{
[mImportProgressBar stopAnimation:self];
NSSize viewSize = [mImportView frame].size;

View File

@ -47,7 +47,7 @@
{
IBOutlet NSView* mBookmarkView;
IBOutlet NSView* mFolderView;
IBOutlet NSTabView* mTabView;
IBOutlet NSTextField* mBookmarkNameField;
IBOutlet NSTextField* mBookmarkLocationField;
@ -74,8 +74,8 @@
+ (id)existingSharedBookmarkInfoController;
+ (void)closeBookmarkInfoController;
-(void)setBookmark:(BookmarkItem*)aBookmark;
-(BookmarkItem*)bookmark;
- (void)setBookmark:(BookmarkItem*)aBookmark;
- (BookmarkItem*)bookmark;
- (IBAction)tabGroupCheckboxClicked:(id)sender;
- (IBAction)dockMenuCheckboxClicked:(id)sender;

View File

@ -88,8 +88,7 @@ static BookmarkInfoController* gSharedBookmarkInfoController = nil;
- (id)initWithWindowNibName:(NSString *)windowNibName
{
if ((self = [super initWithWindowNibName:@"BookmarkInfoPanel"]))
{
if ((self = [super initWithWindowNibName:@"BookmarkInfoPanel"])) {
//custom field editor lets us undo our changes
mFieldEditor = [[NSTextView alloc] init];
[mFieldEditor setAllowsUndo:YES];
@ -118,7 +117,7 @@ static BookmarkInfoController* gSharedBookmarkInfoController = nil;
[nc addObserver:self selector:@selector(dockMenuChanged:) name:BookmarkFolderDockMenuChangeNotificaton object:nil];
}
-(void)dealloc
- (void)dealloc
{
// this is never called
if (self == gSharedBookmarkInfoController)
@ -127,32 +126,32 @@ static BookmarkInfoController* gSharedBookmarkInfoController = nil;
[[NSNotificationCenter defaultCenter] removeObserver:self];
[mBookmarkItem release];
[mFieldEditor release];
// balance retains of top-level nib items
[mBookmarkView release];
[mFolderView release];
[super dealloc];
}
// We intercept the tab key in order to let the user tab to/from the bookmark
// We intercept the tab key in order to let the user tab to/from the bookmark
// description textfield (even though it's a textview)
-(BOOL)textView:(NSTextView *)textView doCommandBySelector:(SEL)command
- (BOOL)textView:(NSTextView *)textView doCommandBySelector:(SEL)command
{
if (command == @selector(insertTab:)) {
[[self window] selectNextKeyView:nil];
return YES;
}
if (command == @selector(insertBacktab:)) {
[[self window] selectPreviousKeyView:nil];
return YES;
}
return NO;
}
// for the NSTextFields
-(void)controlTextDidEndEditing:(NSNotification *)aNotification
- (void)controlTextDidEndEditing:(NSNotification *)aNotification
{
[self commitChanges:[aNotification object]];
[[mFieldEditor undoManager] removeAllActions];
@ -165,7 +164,7 @@ static BookmarkInfoController* gSharedBookmarkInfoController = nil;
[[mFieldEditor undoManager] removeAllActions];
}
-(void)windowDidBecomeKey:(NSNotification*) aNotification
- (void)windowDidBecomeKey:(NSNotification*)aNotification
{
if ([[self window] contentView] == mBookmarkView) {
NSTabViewItem *tabViewItem = [mTabView selectedTabViewItem];
@ -179,7 +178,7 @@ static BookmarkInfoController* gSharedBookmarkInfoController = nil;
}
}
-(void)windowDidResignKey:(NSNotification*) aNotification
- (void)windowDidResignKey:(NSNotification*)aNotification
{
[[self window] makeFirstResponder:[self window]]; // why?
if (![[self window] isVisible])
@ -200,24 +199,20 @@ static BookmarkInfoController* gSharedBookmarkInfoController = nil;
// could this be any more long-winded?
BOOL isBookmark;
if ((isBookmark = [mBookmarkItem isKindOfClass:[Bookmark class]]))
{
if ((isBookmark = [mBookmarkItem isKindOfClass:[Bookmark class]])) {
// why do we check the parent's type?
if ([(Bookmark *)mBookmarkItem isSeparator] || ![[mBookmarkItem parent] isKindOfClass:[BookmarkItem class]])
return;
}
if (!changedField)
{
if ((tabViewItem == mBookmarkInfoTabView) && isBookmark)
{
if (!changedField) {
if ((tabViewItem == mBookmarkInfoTabView) && isBookmark) {
[mBookmarkItem setTitle:[mBookmarkNameField stringValue]];
[mBookmarkItem setItemDescription:[NSString stringWithString:[mBookmarkDescField stringValue]]];
[mBookmarkItem setKeyword:[mBookmarkKeywordField stringValue]];
[(Bookmark *)mBookmarkItem setUrl:[mBookmarkLocationField stringValue]];
}
else if ([[self window] contentView] == mFolderView && !isBookmark)
{
else if ([[self window] contentView] == mFolderView && !isBookmark) {
[mBookmarkItem setTitle:[mFolderNameField stringValue]];
[mBookmarkItem setItemDescription:[NSString stringWithString:[mFolderDescField stringValue]]];
if ([(BookmarkFolder *)mBookmarkItem isGroup])
@ -232,7 +227,7 @@ static BookmarkInfoController* gSharedBookmarkInfoController = nil;
[mBookmarkItem setItemDescription:[NSString stringWithString:[changedField stringValue]]];
else if ((changedField == mBookmarkLocationField) && isBookmark)
[(Bookmark *)mBookmarkItem setUrl:[changedField stringValue]];
[[mFieldEditor undoManager] removeAllActions];
}
@ -256,7 +251,7 @@ static BookmarkInfoController* gSharedBookmarkInfoController = nil;
[mNumberVisitsField setIntValue:0];
}
-(void)setBookmark:(BookmarkItem*) aBookmark
- (void)setBookmark:(BookmarkItem*)aBookmark
{
// register for changes on the new bookmark
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
@ -274,8 +269,7 @@ static BookmarkInfoController* gSharedBookmarkInfoController = nil;
{
NSView* newView = nil;
switch (inViewType)
{
switch (inViewType) {
case eFolderInfoView:
newView = mFolderView;
break;
@ -290,20 +284,21 @@ static BookmarkInfoController* gSharedBookmarkInfoController = nil;
[[self window] setContentView:newView];
}
-(void)updateUI
- (void)updateUI
{
[self window]; // make sure the window has loaded
// setup for bookmarks
if (mBookmarkItem && [mBookmarkItem isKindOfClass:[Bookmark class]])
{
if (mBookmarkItem && [mBookmarkItem isKindOfClass:[Bookmark class]]) {
[self configureWindowForView:eBookmarkInfoView];
[mBookmarkNameField setStringValue:[mBookmarkItem title]];
[mBookmarkDescField setStringValue:[mBookmarkItem itemDescription]];
[mBookmarkKeywordField setStringValue:[mBookmarkItem keyword]];
[mBookmarkLocationField setStringValue:[(Bookmark *)mBookmarkItem url]];
[mNumberVisitsField setIntValue:[(Bookmark *)mBookmarkItem numberOfVisits]];
[mLastVisitField setStringValue: [[(Bookmark *)mBookmarkItem lastVisit] descriptionWithCalendarFormat:[[mLastVisitField formatter] dateFormat] timeZone:[NSTimeZone localTimeZone] locale:nil]];
[mLastVisitField setStringValue:[[(Bookmark *)mBookmarkItem lastVisit] descriptionWithCalendarFormat:[[mLastVisitField formatter] dateFormat]
timeZone:[NSTimeZone localTimeZone]
locale:nil]];
// if its parent is a smart folder or it's a menu separator,
// we turn off all the fields. if it isn't, then we turn them all on
@ -317,8 +312,7 @@ static BookmarkInfoController* gSharedBookmarkInfoController = nil;
[mBookmarkLocationField setEditable:canEdit];
}
// Folders
else if (mBookmarkItem && [mBookmarkItem isKindOfClass:[BookmarkFolder class]])
{
else if (mBookmarkItem && [mBookmarkItem isKindOfClass:[BookmarkFolder class]]) {
[self configureWindowForView:eFolderInfoView];
[mTabgroupCheckbox setState:[(BookmarkFolder *)mBookmarkItem isGroup] ? NSOnState : NSOffState];
@ -333,8 +327,7 @@ static BookmarkInfoController* gSharedBookmarkInfoController = nil;
else
[mDockMenuCheckbox setState:NSOffState];
}
else
{
else {
[self configureWindowForView:eBookmarkInfoView];
// clear stuff
[mBookmarkNameField setStringValue:@""];
@ -350,28 +343,26 @@ static BookmarkInfoController* gSharedBookmarkInfoController = nil;
[mNumberVisitsField setIntValue:0];
[mLastVisitField setStringValue:@""];
}
// Header
if (mBookmarkItem)
{
if (mBookmarkItem) {
NSMutableString *truncatedTitle = [NSMutableString stringWithString:[mBookmarkItem title]];
[truncatedTitle truncateTo:kMaxLengthOfWindowTitle at:kTruncateAtEnd];
NSString* infoForString = [NSString stringWithFormat:NSLocalizedString(@"BookmarkInfoTitle", @"Info for "), truncatedTitle];
NSString* infoForString = [NSString stringWithFormat:NSLocalizedString(@"BookmarkInfoTitle", nil), truncatedTitle];
[[self window] setTitle:infoForString];
}
else
{
[[self window] setTitle:NSLocalizedString(@"BlankBookmarkInfoTitle", @"")];
else {
[[self window] setTitle:NSLocalizedString(@"BlankBookmarkInfoTitle", nil)];
}
}
-(BookmarkItem *)bookmark
- (BookmarkItem *)bookmark
{
return mBookmarkItem;
}
-(NSText *)windowWillReturnFieldEditor:(NSWindow *)aPanel toObject:(id)aObject
- (NSText *)windowWillReturnFieldEditor:(NSWindow *)aPanel toObject:(id)aObject
{
return mFieldEditor;
}
@ -398,7 +389,9 @@ static BookmarkInfoController* gSharedBookmarkInfoController = nil;
BookmarkItem *item = [aNote object];
if ([item isKindOfClass:[Bookmark class]]) {
[mNumberVisitsField setIntValue:[(Bookmark *)item numberOfVisits]];
[mLastVisitField setStringValue: [[(Bookmark *)item lastVisit] descriptionWithCalendarFormat:[[mLastVisitField formatter] dateFormat] timeZone:[NSTimeZone localTimeZone] locale:nil]];
[mLastVisitField setStringValue:[[(Bookmark *)item lastVisit] descriptionWithCalendarFormat:[[mLastVisitField formatter] dateFormat]
timeZone:[NSTimeZone localTimeZone]
locale:nil]];
}
}

View File

@ -44,7 +44,7 @@
enum
{
kBookmarkItemAccumulateChangesMask = (1 << 0),
kBookmarkItemTitleChangedMask = (1 << 1),
kBookmarkItemDescriptionChangedMask = (1 << 2),
kBookmarkItemKeywordChangedMask = (1 << 3),
@ -56,7 +56,7 @@ enum
// flags for bookmark folder changes
kBookmarkItemChildrenChangedMask = (1 << 9),
// mask of flags that require a save of the bookmarks
kBookmarkItemSignificantChangeFlagsMask = kBookmarkItemTitleChangedMask |
kBookmarkItemDescriptionChangedMask |
@ -65,7 +65,7 @@ enum
kBookmarkItemLastVisitChangedMask |
kBookmarkItemStatusChangedMask |
kBookmarkItemNumVisitsChangedMask,
kBookmarkItemEverythingChangedMask = 0xFFFFFFFE
};
@ -78,10 +78,10 @@ enum
@interface BookmarkItem : NSObject <NSCopying>
{
id mParent; //subclasses will use a BookmarkFolder
NSString* mTitle;
id mParent; //subclasses will use a BookmarkFolder
NSString* mTitle;
NSString* mDescription;
NSString* mKeyword;
NSString* mKeyword;
NSString* mUUID;
NSImage* mIcon;
unsigned int mPendingChangeFlags;
@ -91,19 +91,19 @@ enum
+ (BOOL)bookmarkChangedNotificationUserInfo:(NSDictionary*)inUserInfo containsFlags:(unsigned int)inFlags;
// Setters/Getters
-(id) parent;
-(NSString *) title;
-(NSString *) itemDescription; // don't use "description"
-(NSString *) keyword;
-(NSImage *) icon;
-(NSString *) UUID;
- (id)parent;
- (NSString *)title;
- (NSString *)itemDescription; // don't use "description"
- (NSString *)keyword;
- (NSImage *)icon;
- (NSString *)UUID;
-(void) setParent:(id)aParent; // note that the parent of root items is the BookmarksManager, for some reason
-(void) setTitle:(NSString *)aString;
-(void) setItemDescription:(NSString *)aString;
-(void) setKeyword:(NSString *)aKeyword;
-(void) setIcon:(NSImage *)aIcon;
-(void) setUUID:(NSString*)aUUID;
- (void)setParent:(id)aParent; // note that the parent of root items is the BookmarksManager, for some reason
- (void)setTitle:(NSString *)aString;
- (void)setItemDescription:(NSString *)aString;
- (void)setKeyword:(NSString *)aKeyword;
- (void)setIcon:(NSImage *)aIcon;
- (void)setUUID:(NSString*)aUUID;
// Status checks
- (BOOL)isChildOfItem:(BookmarkItem *)anItem;
@ -122,25 +122,25 @@ enum
eBookmarksSearchFieldDescription
};
-(BOOL)matchesString:(NSString*)searchString inFieldWithTag:(int)tag;
- (BOOL)matchesString:(NSString*)searchString inFieldWithTag:(int)tag;
// Notification of Change
-(void) setAccumulateUpdateNotifications:(BOOL)suppressUpdates; // does not nest
-(void) itemUpdatedNote:(unsigned int)inChangeMask; // not everything triggers an item update, only certain properties changing
- (void)setAccumulateUpdateNotifications:(BOOL)suppressUpdates; // does not nest
- (void)itemUpdatedNote:(unsigned int)inChangeMask; // not everything triggers an item update, only certain properties changing
// Methods called on startup for both bookmark & folder
-(void) refreshIcon;
- (void)refreshIcon;
// for reading/writing to disk - unimplemented in BookmarkItem.
-(BOOL) readNativeDictionary:(NSDictionary *)aDict;
-(BOOL) readSafariDictionary:(NSDictionary *)aDict;
-(BOOL) readCaminoXML:(CFXMLTreeRef)aTreeRef settingToolbar:(BOOL)setupToolbar;
- (BOOL)readNativeDictionary:(NSDictionary *)aDict;
- (BOOL)readSafariDictionary:(NSDictionary *)aDict;
- (BOOL)readCaminoXML:(CFXMLTreeRef)aTreeRef settingToolbar:(BOOL)setupToolbar;
-(void)writeBookmarksMetadataToPath:(NSString*)inPath;
-(void)removeBookmarksMetadataFromPath:(NSString*)inPath;
-(NSDictionary *)writeNativeDictionary;
-(NSDictionary *)writeSafariDictionary;
-(NSString *)writeHTML:(unsigned)aPad;
- (void)writeBookmarksMetadataToPath:(NSString*)inPath;
- (void)removeBookmarksMetadataFromPath:(NSString*)inPath;
- (NSDictionary *)writeNativeDictionary;
- (NSDictionary *)writeSafariDictionary;
- (NSString *)writeHTML:(unsigned)aPad;
// methods used for saving to files; are guaranteed never to return nil
- (id)savedTitle;

View File

@ -127,10 +127,9 @@ NSString* const CaminoTrueKey = @"true";
//Initialization
-(id) init
- (id)init
{
if ((self = [super init]))
{
if ((self = [super init])) {
mParent = nil;
mTitle = [[NSString alloc] init]; //retain count +1
mKeyword = [mTitle retain]; //retain count +2
@ -140,8 +139,8 @@ NSString* const CaminoTrueKey = @"true";
}
return self;
}
-(id) copyWithZone:(NSZone *)zone
- (id)copyWithZone:(NSZone *)zone
{
//descend from NSObject - so don't call super
id bmItemCopy = [[[self class] allocWithZone:zone] init];
@ -154,7 +153,7 @@ NSString* const CaminoTrueKey = @"true";
return bmItemCopy;
}
-(void)dealloc
- (void)dealloc
{
[mTitle release];
[mDescription release];
@ -166,29 +165,29 @@ NSString* const CaminoTrueKey = @"true";
}
// Basic properties
-(id) parent
- (id)parent
{
return mParent;
}
-(NSString *) title
- (NSString *)title
{
return mTitle;
}
-(NSString *) itemDescription
- (NSString *)itemDescription
{
return mDescription;
}
-(NSString *) keyword
- (NSString *)keyword
{
return mKeyword;
}
// if we ask for a UUID, it means we need
// one. So generate it if it doesn't exist.
-(NSString *) UUID
// one. So generate it if it doesn't exist.
- (NSString *)UUID
{
if (!mUUID)
mUUID = [[NSString stringWithUUID] retain];
@ -197,7 +196,7 @@ NSString* const CaminoTrueKey = @"true";
return mUUID;
}
-(NSImage *)icon
- (NSImage *)icon
{
return mIcon;
}
@ -225,25 +224,22 @@ NSString* const CaminoTrueKey = @"true";
id myParent = [self parent];
if (myParent && [myParent isKindOfClass:[BookmarkItem class]])
{
return [myParent hasAncestor:inItem];
}
return NO;
}
-(void) setParent:(id) aParent
- (void)setParent:(id)aParent
{
mParent = aParent; // no reference on the parent, so it better not disappear on us.
mParent = aParent; // no reference on the parent, so it better not disappear on us.
}
-(void) setTitle:(NSString *)aTitle
- (void)setTitle:(NSString *)aTitle
{
if (!aTitle)
return;
if (![mTitle isEqualToString:aTitle])
{
if (![mTitle isEqualToString:aTitle]) {
[aTitle retain];
[mTitle release];
mTitle = aTitle;
@ -251,13 +247,12 @@ NSString* const CaminoTrueKey = @"true";
}
}
-(void) setItemDescription:(NSString *)aDescription
- (void)setItemDescription:(NSString *)aDescription
{
if (!aDescription)
return;
if (![mDescription isEqualToString:aDescription])
{
if (![mDescription isEqualToString:aDescription]) {
[aDescription retain];
[mDescription release];
mDescription = aDescription;
@ -265,13 +260,12 @@ NSString* const CaminoTrueKey = @"true";
}
}
- (void) setKeyword:(NSString *)aKeyword
- (void)setKeyword:(NSString *)aKeyword
{
if (!aKeyword)
return;
if (![mKeyword isEqualToString:aKeyword])
{
if (![mKeyword isEqualToString:aKeyword]) {
[aKeyword retain];
[mKeyword release];
mKeyword = aKeyword;
@ -279,7 +273,7 @@ NSString* const CaminoTrueKey = @"true";
}
}
-(void) setIcon:(NSImage *)aIcon
- (void)setIcon:(NSImage *)aIcon
{
if (!aIcon)
return; // XXX should be allowed to just remove the icon
@ -291,29 +285,28 @@ NSString* const CaminoTrueKey = @"true";
[self itemUpdatedNote:kBookmarkItemIconChangedMask];
}
-(void) setUUID:(NSString*)aUUID
- (void)setUUID:(NSString*)aUUID
{
// ignore nil or empty strings
if (!aUUID || [aUUID length] == 0)
return;
[aUUID retain];
[mUUID release];
mUUID = aUUID;
}
-(BOOL)matchesString:(NSString*)searchString inFieldWithTag:(int)tag
- (BOOL)matchesString:(NSString*)searchString inFieldWithTag:(int)tag
{
switch (tag)
{
switch (tag) {
case eBookmarksSearchFieldAll:
return (([[self title] rangeOfString:searchString options:NSCaseInsensitiveSearch].location != NSNotFound) ||
([[self keyword] rangeOfString:searchString options:NSCaseInsensitiveSearch].location != NSNotFound) ||
([[self itemDescription] rangeOfString:searchString options:NSCaseInsensitiveSearch].location != NSNotFound));
case eBookmarksSearchFieldTitle:
return ([[self title] rangeOfString:searchString options:NSCaseInsensitiveSearch].location != NSNotFound);
// case eBookmarksSearchFieldURL: // Bookmark subclass has to check this
case eBookmarksSearchFieldKeyword:
return ([[self keyword] rangeOfString:searchString options:NSCaseInsensitiveSearch].location != NSNotFound);
@ -328,40 +321,41 @@ NSString* const CaminoTrueKey = @"true";
// Helps prevent spamming from itemUpdatedNote:
// calling with YES will prevent itemUpdatedNote from doing anything
// and calling with NO will restore itemUpdatedNote and then call it.
-(void) setAccumulateUpdateNotifications:(BOOL)accumulateUpdates
- (void)setAccumulateUpdateNotifications:(BOOL)accumulateUpdates
{
if (accumulateUpdates)
{
if (accumulateUpdates) {
mPendingChangeFlags |= kBookmarkItemAccumulateChangesMask;
}
else
{
else {
mPendingChangeFlags &= ~kBookmarkItemAccumulateChangesMask;
[self itemUpdatedNote:mPendingChangeFlags]; //fire an update to cover the updates that weren't sent
}
}
-(void) itemUpdatedNote:(unsigned int)inChangeMask
- (void)itemUpdatedNote:(unsigned int)inChangeMask
{
if ([[BookmarkManager sharedBookmarkManager] areChangeNotificationsSuppressed])
return; // don't even accumulate the flags. caller is expected to update stuff manually
// don't let 'em change the pending flag
mPendingChangeFlags |= (inChangeMask & kBookmarkItemEverythingChangedMask);
// if we're just accumulating, return
if (mPendingChangeFlags & kBookmarkItemAccumulateChangesMask)
return;
NSDictionary* flagsInfo = [NSDictionary dictionaryWithObject:[NSNumber numberWithUnsignedInt:mPendingChangeFlags] forKey:BookmarkItemChangedFlagsKey];
NSNotification* note = [NSNotification notificationWithName:BookmarkItemChangedNotification object:self userInfo:flagsInfo];
NSDictionary* flagsInfo = [NSDictionary dictionaryWithObject:[NSNumber numberWithUnsignedInt:mPendingChangeFlags]
forKey:BookmarkItemChangedFlagsKey];
NSNotification* note = [NSNotification notificationWithName:BookmarkItemChangedNotification
object:self
userInfo:flagsInfo];
[[NSNotificationCenter defaultCenter] postNotification:note];
mPendingChangeFlags = 0;
}
// stub functions to avoid warning
-(void) refreshIcon
- (void)refreshIcon
{
}
@ -369,42 +363,42 @@ NSString* const CaminoTrueKey = @"true";
//Reading/writing to & from disk - all just stubs.
-(BOOL) readNativeDictionary:(NSDictionary *)aDict
- (BOOL)readNativeDictionary:(NSDictionary *)aDict
{
return NO;
}
-(BOOL) readSafariDictionary:(NSDictionary *)aDict
- (BOOL)readSafariDictionary:(NSDictionary *)aDict
{
return NO;
}
-(BOOL) readCaminoXML:(CFXMLTreeRef)aTreeRef settingToolbar:(BOOL)setupToolbar
- (BOOL)readCaminoXML:(CFXMLTreeRef)aTreeRef settingToolbar:(BOOL)setupToolbar
{
return NO;
}
-(void)writeBookmarksMetadataToPath:(NSString*)inPath
- (void)writeBookmarksMetadataToPath:(NSString*)inPath
{
// do nothing, subclasses must override
}
-(void)removeBookmarksMetadataFromPath:(NSString*)inPath
- (void)removeBookmarksMetadataFromPath:(NSString*)inPath
{
// do nothing, subclasses must override
}
-(NSDictionary *)writeNativeDictionary
- (NSDictionary *)writeNativeDictionary
{
return [NSDictionary dictionary];
}
-(NSDictionary *)writeSafariDictionary
- (NSDictionary *)writeSafariDictionary
{
return [NSDictionary dictionary];
}
-(NSString *)writeHTML:(unsigned)aPad
- (NSString *)writeHTML:(unsigned)aPad
{
return @"";
}

View File

@ -64,20 +64,20 @@ const int kBookmarksContextMenuArrangeSeparatorTag = 100;
BookmarkImportDlgController* mImportDlgController;
NSString* mPathToBookmarkFile;
NSString* mMetadataPath; // where we store spotlight cache (strong)
NSMutableDictionary* mBookmarkURLMap; // map of cleaned bookmark url to bookmark item set
NSMutableDictionary* mBookmarkFaviconURLMap; // map of cleaned bookmark favicon url to bookmark item set
// smart folders
BookmarkFolder* mTop10Container;
BookmarkFolder* mRendezvousContainer;
BookmarkFolder* mAddressBookContainer;
BookmarkFolder* mLastUsedFolder;
BOOL mBookmarksLoaded;
BOOL mShowSiteIcons;
int mNotificationsSuppressedCount;
NSRecursiveLock* mNotificationsSuppressedLock; // make mNotificationsSuppressedCount threadsafe
}
@ -98,14 +98,14 @@ const int kBookmarksContextMenuArrangeSeparatorTag = 100;
+ (NSArray*)bookmarkItemsFromSerializableArray:(NSArray*)bmArray;
// Getters/Setters
-(BookmarkFolder *) rootBookmarks;
-(BookmarkFolder *) toolbarFolder;
-(BookmarkFolder *) bookmarkMenuFolder;
-(BookmarkFolder *) dockMenuFolder;
-(BookmarkFolder *) top10Folder;
-(BookmarkFolder *) rendezvousFolder;
-(BookmarkFolder *) addressBookFolder;
-(BookmarkFolder *) historyFolder;
- (BookmarkFolder *)rootBookmarks;
- (BookmarkFolder *)toolbarFolder;
- (BookmarkFolder *)bookmarkMenuFolder;
- (BookmarkFolder *)dockMenuFolder;
- (BookmarkFolder *)top10Folder;
- (BookmarkFolder *)rendezvousFolder;
- (BookmarkFolder *)addressBookFolder;
- (BookmarkFolder *)historyFolder;
- (BOOL)isUserCollection:(BookmarkFolder *)inFolder;
@ -126,18 +126,18 @@ const int kBookmarksContextMenuArrangeSeparatorTag = 100;
- (BookmarkFolder*)lastUsedBookmarkFolder;
- (void)setLastUsedBookmarkFolder:(BookmarkFolder*)inFolder;
-(BookmarkItem*) itemWithUUID:(NSString*)uuid;
-(NSUndoManager *) undoManager;
-(void) setRootBookmarks:(BookmarkFolder *)anArray;
- (BookmarkItem*)itemWithUUID:(NSString*)uuid;
- (NSUndoManager *)undoManager;
- (void)setRootBookmarks:(BookmarkFolder *)anArray;
// clear visit count on all bookmarks
-(void)clearAllVisits;
- (void)clearAllVisits;
// Informational things
-(NSArray *)resolveBookmarksKeyword:(NSString *)keyword;
-(NSArray *)searchBookmarksContainer:(BookmarkFolder*)container forString:(NSString *)searchString inFieldWithTag:(int)tag;
-(BOOL) isDropValid:(NSArray *)items toFolder:(BookmarkFolder *)parent;
-(NSMenu *)contextMenuForItems:(NSArray*)items fromView:(BookmarkOutlineView *)outlineView target:(id)target;
- (NSArray *)resolveBookmarksKeyword:(NSString *)keyword;
- (NSArray *)searchBookmarksContainer:(BookmarkFolder*)container forString:(NSString *)searchString inFieldWithTag:(int)tag;
- (BOOL)isDropValid:(NSArray *)items toFolder:(BookmarkFolder *)parent;
- (NSMenu *)contextMenuForItems:(NSArray*)items fromView:(BookmarkOutlineView *)outlineView target:(id)target;
// Utilities
- (void)copyBookmarksURLs:(NSArray*)bookmarkItems toPasteboard:(NSPasteboard*)aPasteboard;

File diff suppressed because it is too large Load Diff

View File

@ -21,7 +21,7 @@
* Contributor(s):
* Simon Fraser <smfr@smfr.org>
* David Haas <haasd@cae.wisc.edu>
*
*
* 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"),

View File

@ -68,8 +68,7 @@ const long kOpenInTabsTag = 0xBEEF;
- (id)initWithTitle:(NSString *)inTitle bookmarkFolder:(BookmarkFolder*)inFolder
{
if ((self = [super initWithTitle:inTitle]))
{
if ((self = [super initWithTitle:inTitle])) {
mFolder = [inFolder retain];
mDirty = YES;
mAppendTabsItem = YES;
@ -142,8 +141,7 @@ const long kOpenInTabsTag = 0xBEEF;
- (void)menuWillDisplay:(NSNotification*)inNotification
{
if ([self isTargetOfMenuDisplayNotification:[inNotification object]])
{
if ([self isTargetOfMenuDisplayNotification:[inNotification object]]) {
[self menuWillBeDisplayed];
}
}
@ -155,30 +153,25 @@ const long kOpenInTabsTag = 0xBEEF;
- (void)rebuildMenuIncludingSubmenus:(BOOL)includeSubmenus withAlternates:(BOOL)includeAlternates
{
if (mDirty)
{
if (mDirty) {
// remove everything after the "before" item
[self removeItemsAfterItem:mItemBeforeCustomItems];
NSEnumerator* childEnum = [[mFolder childArray] objectEnumerator];
BookmarkItem* curItem;
while ((curItem = [childEnum nextObject]))
{
while ((curItem = [childEnum nextObject])) {
[self appendBookmarkItem:curItem buildingSubmenus:includeSubmenus withAlternates:includeAlternates];
}
[self addLastItems];
mDirty = NO;
}
else if (includeSubmenus) // even if we're not dirty, submenus might be
{
else if (includeSubmenus) { // even if we're not dirty, submenus might be
int firstCustomItemIndex = [self indexOfItem:mItemBeforeCustomItems] + 1;
for (int i = firstCustomItemIndex; i < [self numberOfItems]; i ++)
{
for (int i = firstCustomItemIndex; i < [self numberOfItems]; i++) {
NSMenuItem* curItem = [self itemAtIndex:i];
if ([curItem hasSubmenu] && [[curItem submenu] isKindOfClass:[BookmarkMenu class]])
{
if ([curItem hasSubmenu] && [[curItem submenu] isKindOfClass:[BookmarkMenu class]]) {
[(BookmarkMenu*)[curItem submenu] rebuildMenuIncludingSubmenus:includeSubmenus withAlternates:includeAlternates];
}
}
@ -190,10 +183,8 @@ const long kOpenInTabsTag = 0xBEEF;
NSString *title = [[inItem title] stringByTruncatingTo:MENU_TRUNCATION_CHARS at:kTruncateAtMiddle];
NSMenuItem *menuItem = nil;
if ([inItem isKindOfClass:[Bookmark class]])
{
if (![(Bookmark *)inItem isSeparator]) // normal bookmark
{
if ([inItem isKindOfClass:[Bookmark class]]) {
if (![(Bookmark *)inItem isSeparator]) { // normal bookmark
menuItem = [[NSMenuItem alloc] initWithTitle:title action:NULL keyEquivalent:@""];
[menuItem setTarget:[NSApp delegate]];
[menuItem setAction:@selector(openMenuBookmark:)];
@ -210,7 +201,7 @@ const long kOpenInTabsTag = 0xBEEF;
[altMenuItem setRepresentedObject:inItem];
[altMenuItem setImage:[inItem icon]];
[self addItem:altMenuItem];
altMenuItem = [NSMenu alternateMenuItemWithTitle:title
action:@selector(openMenuBookmark:)
target:[NSApp delegate]
@ -220,18 +211,15 @@ const long kOpenInTabsTag = 0xBEEF;
[self addItem:altMenuItem];
}
}
else //separator
{
else { //separator
menuItem = [[NSMenuItem separatorItem] retain];
[self addItem:menuItem];
}
}
else if ([inItem isKindOfClass:[BookmarkFolder class]])
{
else if ([inItem isKindOfClass:[BookmarkFolder class]]) {
BookmarkFolder* curFolder = (BookmarkFolder*)inItem;
if (![curFolder isGroup]) // normal folder
{
menuItem = [[NSMenuItem alloc] initWithTitle:title action: NULL keyEquivalent: @""];
if (![curFolder isGroup]) { // normal folder
menuItem = [[NSMenuItem alloc] initWithTitle:title action:NULL keyEquivalent:@""];
[menuItem setImage:[inItem icon]];
BookmarkMenu* subMenu = [[BookmarkMenu alloc] initWithTitle:title bookmarkFolder:curFolder];
@ -242,12 +230,11 @@ const long kOpenInTabsTag = 0xBEEF;
[menuItem setSubmenu:subMenu];
[subMenu release];
}
else // group
{
menuItem = [[NSMenuItem alloc] initWithTitle:title action: NULL keyEquivalent: @""];
else { // group
menuItem = [[NSMenuItem alloc] initWithTitle:title action:NULL keyEquivalent:@""];
[menuItem setTarget:[NSApp delegate]];
[menuItem setAction:@selector(openMenuBookmark:)];
[menuItem setImage:[inItem icon]];
[menuItem setImage:[inItem icon]];
}
[self addItem:menuItem];
@ -261,8 +248,7 @@ const long kOpenInTabsTag = 0xBEEF;
- (void)addLastItems
{
// add the "Open In Tabs" option to open all items in this subfolder
if (mAppendTabsItem && [[mFolder childURLs] count] > 0)
{
if (mAppendTabsItem && [[mFolder childURLs] count] > 0) {
[self addItem:[NSMenuItem separatorItem]];
NSMenuItem* menuItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Open in Tabs", nil)
@ -330,15 +316,13 @@ const long kOpenInTabsTag = 0xBEEF;
changeFlags = [noteChangeFlags unsignedIntValue];
// if it changed to or from a separator (or everything changed), just do a rebuild later
if (changeFlags & kBookmarkItemStatusChangedMask)
{
if (changeFlags & kBookmarkItemStatusChangedMask) {
mDirty = YES;
return;
}
NSMenuItem* theMenuItem = [self itemAtIndex:itemIndex];
if (changeFlags & kBookmarkItemTitleChangedMask)
{
if (changeFlags & kBookmarkItemTitleChangedMask) {
NSString *title = [[changedItem title] stringByTruncatingTo:MENU_TRUNCATION_CHARS at:kTruncateAtMiddle];
[theMenuItem setTitle:title];
}

View File

@ -46,7 +46,7 @@
}
// Actions for the edit menu
-(BOOL)validateMenuItem:(id)aMenuItem;
-(IBAction)delete:(id)aSender;
- (BOOL)validateMenuItem:(id)aMenuItem;
- (IBAction)delete:(id)aSender;
@end

View File

@ -49,10 +49,14 @@
- (void)awakeFromNib
{
[self registerForDraggedTypes:[NSArray arrayWithObjects:kCaminoBookmarkListPBoardType, kWebURLsWithTitlesPboardType, NSStringPboardType, NSURLPboardType, nil]];
[self registerForDraggedTypes:[NSArray arrayWithObjects:kCaminoBookmarkListPBoardType,
kWebURLsWithTitlesPboardType,
NSStringPboardType,
NSURLPboardType,
nil]];
}
-(NSMenu*)menu
- (NSMenu*)menu
{
BookmarkManager *bm = [BookmarkManager sharedBookmarkManager];
BookmarkFolder *activeCollection = [(BookmarkViewController*)[self delegate] activeCollection];
@ -60,7 +64,7 @@
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...", @"")
NSMenuItem *menuItem = [[[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Create New Folder...", nil)
action:@selector(addBookmarkFolder:)
keyEquivalent:@""] autorelease];
[menuItem setTarget:[self delegate]];
@ -74,7 +78,7 @@
{
if (operation == NSDragOperationDelete) {
NSPasteboard* pboard = [NSPasteboard pasteboardWithName:NSDragPboard];
NSArray* bookmarks = [BookmarkManager bookmarkItemsFromSerializableArray:[pboard propertyListForType: kCaminoBookmarkListPBoardType]];
NSArray* bookmarks = [BookmarkManager bookmarkItemsFromSerializableArray:[pboard propertyListForType:kCaminoBookmarkListPBoardType]];
if (bookmarks) {
for (unsigned int i = 0; i < [bookmarks count]; ++i) {
BookmarkItem* item = [bookmarks objectAtIndex:i];
@ -93,7 +97,8 @@
[super _cancelEditItem];
return;
}
} else if ([itemToEdit isKindOfClass:[Bookmark class]]) {
}
else if ([itemToEdit isKindOfClass:[Bookmark class]]) {
if ([(Bookmark *)itemToEdit isSeparator]) {
[super _cancelEditItem];
return;

View File

@ -55,19 +55,19 @@
}
// Called to construct & edit the initial set of personal toolbar buttons.
-(void)rebuildButtonList;
-(void)addButton:(BookmarkItem*)aItem atIndex:(int)aIndex;
-(void)updateButton:(BookmarkItem*)aItem;
-(void)removeButton:(BookmarkItem*)aItem;
- (void)rebuildButtonList;
- (void)addButton:(BookmarkItem*)aItem atIndex:(int)aIndex;
- (void)updateButton:(BookmarkItem*)aItem;
- (void)removeButton:(BookmarkItem*)aItem;
// Called to lay out the buttons on the toolbar.
-(void)reflowButtons;
-(void)reflowButtonsStartingAtIndex: (int)aIndex;
- (void)reflowButtons;
- (void)reflowButtonsStartingAtIndex:(int)aIndex;
-(BOOL)isShown;
-(void)setDrawBottomBorder:(BOOL)drawBorder;
-(void)showBookmarksToolbar: (BOOL)aShow;
- (BOOL)isShown;
- (void)setDrawBottomBorder:(BOOL)drawBorder;
- (void)showBookmarksToolbar:(BOOL)aShow;
-(IBAction)addFolder:(id)aSender;
- (IBAction)addFolder:(id)aSender;
@end

View File

@ -62,7 +62,7 @@ static const float kButtonRectVPadding = 4.0f;
@interface BookmarkToolbar(Private)
-(void)rebuildButtonList;
- (void)rebuildButtonList;
- (void)setButtonInsertionPoint:(id <NSDraggingInfo>)sender;
- (NSRect)insertionHiliteRectForButton:(NSView*)aButton position:(int)aPosition;
- (BookmarkButton*)makeNewButtonWithItem:(BookmarkItem*)aItem;
@ -80,24 +80,27 @@ static const int kBMBarScanningStep = 5;
- (id)initWithFrame:(NSRect)frame
{
if ( (self = [super initWithFrame:frame]) )
{
if ((self = [super initWithFrame:frame])) {
mButtons = [[NSMutableArray alloc] init];
mDragInsertionButton = nil;
mDragInsertionPosition = CHInsertNone;
mDrawBorder = YES;
[self registerForDraggedTypes:[NSArray arrayWithObjects: kCaminoBookmarkListPBoardType, kWebURLsWithTitlesPboardType, NSStringPboardType, NSURLPboardType, nil]];
[self registerForDraggedTypes:[NSArray arrayWithObjects:kCaminoBookmarkListPBoardType,
kWebURLsWithTitlesPboardType,
NSStringPboardType,
NSURLPboardType,
nil]];
mIsShowing = YES;
mButtonListDirty = YES;
// Generic notifications for Bookmark Client
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(bookmarkAdded:) name:BookmarkFolderAdditionNotification object:nil];
[nc addObserver:self selector:@selector(bookmarkRemoved:) name:BookmarkFolderDeletionNotification object:nil];
[nc addObserver:self selector:@selector(bookmarkChanged:) name:BookmarkItemChangedNotification object:nil];
// register for notifications of when the BM manager starts up. Since it does it on a separate thread,
// it can be created after we are and if we don't update ourselves, the bar will be blank. This
// happens most notably when the app is launched with a 'odoc' or 'GURL' appleEvent.
@ -167,22 +170,19 @@ static void VerticalGrayGradient(void* inInfo, float const* inData, float* outDa
CGFunctionRelease(function);
}
if (mDrawBorder)
{
if (mDrawBorder) {
[[NSColor controlShadowColor] set];
float height = [self bounds].size.height;
NSRectFill(NSMakeRect(aRect.origin.x, height - 1.0, aRect.size.width, height));
}
// The buttons will paint themselves. Just call our base class method.
[super drawRect: aRect];
[super drawRect:aRect];
// draw a separator at drag n drop insertion point if there is one
if (mDragInsertionPosition)
{
if (mDragInsertionPosition) {
NSRect buttonRect = [self insertionHiliteRectForButton:mDragInsertionButton position:mDragInsertionPosition];
if (mDragInsertionPosition == CHInsertInto)
{
if (mDragInsertionPosition == CHInsertInto) {
buttonRect = NSInsetRect(buttonRect, kButtonRectHPadding - 1.0f, kButtonRectVPadding - 1.0f);
NSBezierPath* dropTargetOutline = [NSBezierPath bezierPathWithRoundCorneredRect:buttonRect cornerRadius:3.0f];
@ -193,8 +193,7 @@ static void VerticalGrayGradient(void* inInfo, float const* inData, float* outDa
[[[NSColor colorForControlTint:NSDefaultControlTint] colorWithAlphaComponent:0.5] set];
[dropTargetOutline fill];
}
else
{
else {
// rect is a 5-pixel rect before or after the button, offset a little so this draws
// in the right place. We take care to keep our drawing inside the rect returned from
// -insertionHiliteRectForButton, since that rect is used to do invalidations.
@ -217,7 +216,7 @@ static void VerticalGrayGradient(void* inInfo, float const* inData, float* outDa
[insertionPointPath moveToPoint:NSMakePoint(insertionPos - kTipsXOffset, NSMaxY(buttonRect))];
[insertionPointPath lineToPoint:NSMakePoint(insertionPos, NSMaxY(buttonRect) - kTipsYOffset)];
[insertionPointPath lineToPoint:NSMakePoint(insertionPos + kTipsXOffset, NSMaxY(buttonRect))];
[[NSColor colorWithCalibratedRed:0.12 green:0.36 blue:0.81 alpha:1.0f] set];
[insertionPointPath setLineCapStyle:NSRoundLineCapStyle];
[insertionPointPath setLineWidth:2.0f];
@ -232,8 +231,8 @@ static void VerticalGrayGradient(void* inInfo, float const* inData, float* outDa
// this only gets called on startup OR window creation. on the off chance that
// we're starting due to an appleevent from another program, we might call it twice.
// make sure nothing bad happens if we do that.
//
-(void)rebuildButtonList
//
- (void)rebuildButtonList
{
if (!mButtonListDirty)
return;
@ -245,8 +244,7 @@ static void VerticalGrayGradient(void* inInfo, float const* inData, float* outDa
[self removeAllSubviews];
unsigned int numItems = [toolbarFolder count];
for (unsigned int i = 0; i < numItems; i++)
{
for (unsigned int i = 0; i < numItems; i++) {
BookmarkButton* button = [self makeNewButtonWithItem:[toolbarFolder objectAtIndex:i]];
if (button) {
[self addSubview:button];
@ -260,55 +258,53 @@ static void VerticalGrayGradient(void* inInfo, float const* inData, float* outDa
[self reflowButtons];
}
-(void)addButton:(BookmarkItem*)aItem atIndex:(int)aIndex
- (void)addButton:(BookmarkItem*)aItem atIndex:(int)aIndex
{
BookmarkButton* button = [self makeNewButtonWithItem:aItem];
if (!button)
return;
[self addSubview: button];
[mButtons insertObject: button atIndex: aIndex];
[self addSubview:button];
[mButtons insertObject:button atIndex:aIndex];
if ([self isShown])
[self reflowButtonsStartingAtIndex: aIndex];
[self reflowButtonsStartingAtIndex:aIndex];
}
-(void)updateButton:(BookmarkItem*)aItem
- (void)updateButton:(BookmarkItem*)aItem
{
int count = [mButtons count];
// XXX nasty linear search
for (int i = 0; i < count; i++)
{
BookmarkButton* button = [mButtons objectAtIndex: i];
if ([button bookmarkItem] == aItem)
{
for (int i = 0; i < count; i++) {
BookmarkButton* button = [mButtons objectAtIndex:i];
if ([button bookmarkItem] == aItem) {
BOOL needsReflow = NO;
[button bookmarkChanged:&needsReflow];
if (needsReflow && count > i && [self isShown])
[self reflowButtonsStartingAtIndex: i];
[self reflowButtonsStartingAtIndex:i];
break;
}
}
[self setNeedsDisplay:YES];
}
-(void)removeButton:(BookmarkItem*)aItem
- (void)removeButton:(BookmarkItem*)aItem
{
int count = [mButtons count];
for (int i = 0; i < count; i++) {
BookmarkButton* button = [mButtons objectAtIndex: i];
BookmarkButton* button = [mButtons objectAtIndex:i];
if ([button bookmarkItem] == aItem) {
[mButtons removeObjectAtIndex: i];
[mButtons removeObjectAtIndex:i];
[button removeFromSuperview];
if (count > i && [self isShown])
[self reflowButtonsStartingAtIndex: i];
[self reflowButtonsStartingAtIndex:i];
break;
}
}
[self setNeedsDisplay:YES];
}
-(void)reflowButtons
- (void)reflowButtons
{
[self reflowButtonsStartingAtIndex: 0];
[self reflowButtonsStartingAtIndex:0];
}
#define kBookmarkButtonHeight 16.0
@ -319,7 +315,7 @@ static void VerticalGrayGradient(void* inInfo, float const* inData, float* outDa
#define kBookmarkButtonVerticalPadding 1.0
#define kBookmarkToolbarBottomPadding 2.0
-(void)reflowButtonsStartingAtIndex:(int)aIndex
- (void)reflowButtonsStartingAtIndex:(int)aIndex
{
if (![self isShown])
return;
@ -366,8 +362,8 @@ static void VerticalGrayGradient(void* inInfo, float const* inData, float* outDa
// our size has changed, readjust our view's frame and the content area
if (computedHeight != oldHeight) {
[super setFrame: NSMakeRect([self frame].origin.x, [self frame].origin.y + (oldHeight - computedHeight),
[self frame].size.width, computedHeight)];
[super setFrame:NSMakeRect([self frame].origin.x, [self frame].origin.y + (oldHeight - computedHeight),
[self frame].size.width, computedHeight)];
// tell the superview to resize its subviews
[[self superview] resizeSubviewsWithOldSize:[[self superview] frame].size];
@ -376,12 +372,12 @@ static void VerticalGrayGradient(void* inInfo, float const* inData, float* outDa
[self setNeedsDisplay:YES];
}
-(BOOL)isFlipped
- (BOOL)isFlipped
{
return YES; // Use flipped coords, so we can layout out from top row to bottom row.
}
-(void)setFrame:(NSRect)aRect
- (void)setFrame:(NSRect)aRect
{
NSRect oldFrame = [self frame];
[super setFrame:aRect];
@ -393,8 +389,7 @@ static void VerticalGrayGradient(void* inInfo, float const* inData, float* outDa
int reflowStart = 0;
// find out where we need to start reflowing
for (int i = 0; i < count; i ++)
{
for (int i = 0; i < count; i++) {
BookmarkButton* button = [mButtons objectAtIndex:i];
NSRect buttonFrame = [button frame];
@ -409,15 +404,14 @@ static void VerticalGrayGradient(void* inInfo, float const* inData, float* outDa
[self reflowButtonsStartingAtIndex:reflowStart];
}
-(BOOL)isShown
- (BOOL)isShown
{
return mIsShowing;
}
-(void)setDrawBottomBorder:(BOOL)drawBorder
- (void)setDrawBottomBorder:(BOOL)drawBorder
{
if (mDrawBorder != drawBorder)
{
if (mDrawBorder != drawBorder) {
mDrawBorder = drawBorder;
NSRect dirtyRect = [self bounds];
dirtyRect.origin.y = dirtyRect.size.height - 1.0;
@ -429,10 +423,10 @@ static void VerticalGrayGradient(void* inInfo, float const* inData, float* outDa
// if the toolbar gets the message, we can only make a new folder.
// kinda dull. but we'll do this on the fly.
//
-(NSMenu*)menuForEvent:(NSEvent*)aEvent
- (NSMenu*)menuForEvent:(NSEvent*)aEvent
{
NSMenu* myMenu = [[NSMenu alloc] initWithTitle:@"snookums"];
NSMenuItem *menuItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Create New Folder", @"")
NSMenuItem *menuItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Create New Folder", nil)
action:@selector(addFolder:)
keyEquivalent:@""];
[menuItem setTarget:self];
@ -444,35 +438,33 @@ static void VerticalGrayGradient(void* inInfo, float const* inData, float* outDa
//
// context menu has only what we need
//
-(BOOL)validateMenuItem:(NSMenuItem*)aMenuItem
- (BOOL)validateMenuItem:(NSMenuItem*)aMenuItem
{
return YES;
}
-(IBAction)addFolder:(id)aSender
- (IBAction)addFolder:(id)aSender
{
BookmarkFolder* toolbar = [[BookmarkManager sharedBookmarkManager] toolbarFolder];
BookmarkFolder* aFolder = [toolbar addBookmarkFolder];
[aFolder setTitle:NSLocalizedString(@"NewBookmarkFolder", @"")];
[aFolder setTitle:NSLocalizedString(@"NewBookmarkFolder", nil)];
}
-(void)showBookmarksToolbar: (BOOL)aShow
- (void)showBookmarksToolbar:(BOOL)aShow
{
mIsShowing = aShow;
if (!aShow)
{
if (!aShow) {
[[self superview] setNeedsDisplayInRect:[self frame]];
NSRect newFrame = [self frame];
newFrame.origin.y += newFrame.size.height;
newFrame.size.height = 0;
[self setFrame: newFrame];
[self setFrame:newFrame];
// tell the superview to resize its subviews
[[self superview] resizeSubviewsWithOldSize:[[self superview] frame].size];
}
else
{
else {
[self reflowButtons];
[self setNeedsDisplay:YES];
}
@ -487,20 +479,20 @@ static void VerticalGrayGradient(void* inInfo, float const* inData, float* outDa
mDragInsertionButton = nil;
mDragInsertionPosition = CHInsertAfter;
// check for a button at current location to use as an anchor
if ([self anchorFoundAtPoint:superviewLoc forButton:sourceButton]) return;
// otherwise see if there's a view around it to use as an anchor point
if ([self anchorFoundScanningFromPoint:superviewLoc withStep:(kBMBarScanningStep * -1)]) return;
if ([self anchorFoundScanningFromPoint:superviewLoc withStep:kBMBarScanningStep]) return;
// if neither worked, it's probably the dead zone between lines.
// treat that zone as the line above, and try everything again
superviewLoc.y += kBMBarScanningStep;
if ([self anchorFoundAtPoint:superviewLoc forButton:sourceButton]) return;
if ([self anchorFoundScanningFromPoint:superviewLoc withStep:(kBMBarScanningStep * -1)]) return;
if ([self anchorFoundScanningFromPoint:superviewLoc withStep:kBMBarScanningStep]) return;
// if nothing works, just throw it in at the end
mDragInsertionButton = ([mButtons count] > 0) ? [mButtons objectAtIndex:[mButtons count] - 1] : 0;
mDragInsertionPosition = CHInsertAfter;
@ -511,11 +503,11 @@ static void VerticalGrayGradient(void* inInfo, float const* inData, float* outDa
NSView* foundView = [self hitTest:testPoint];
if (foundView && [foundView isMemberOfClass:[BookmarkButton class]]) {
BookmarkButton* targetButton = (BookmarkButton*)foundView;
// if over current position, leave mDragInsertButton unset but return success so nothing happens
if (targetButton == sourceButton)
return YES;
mDragInsertionButton = targetButton;
if ([[targetButton bookmarkItem] isKindOfClass:[BookmarkFolder class]])
mDragInsertionPosition = CHInsertInto;
@ -554,8 +546,8 @@ static void VerticalGrayGradient(void* inInfo, float const* inData, float* outDa
if (!toolbar)
return NO;
if ([types containsObject: kCaminoBookmarkListPBoardType]) {
NSArray *draggedItems = [BookmarkManager bookmarkItemsFromSerializableArray:[draggingPasteboard propertyListForType: kCaminoBookmarkListPBoardType]];
if ([types containsObject:kCaminoBookmarkListPBoardType]) {
NSArray *draggedItems = [BookmarkManager bookmarkItemsFromSerializableArray:[draggingPasteboard propertyListForType:kCaminoBookmarkListPBoardType]];
BookmarkFolder* destFolder = nil;
if (mDragInsertionButton == nil) {
@ -569,7 +561,7 @@ static void VerticalGrayGradient(void* inInfo, float const* inData, float* outDa
mDragInsertionPosition == CHInsertAfter) { // drop onto toolbar
destFolder = toolbar;
}
return [bmManager isDropValid:draggedItems toFolder:destFolder];
}
@ -595,7 +587,7 @@ static void VerticalGrayGradient(void* inInfo, float const* inData, float* outDa
return NSDragOperationCopy;
if (dragOpMask & NSDragOperationGeneric)
return NSDragOperationGeneric;
return NSDragOperationNone;
}
@ -631,8 +623,8 @@ static void VerticalGrayGradient(void* inInfo, float const* inData, float* outDa
return NSDragOperationCopy;
if (dragOpMask & NSDragOperationGeneric)
return NSDragOperationGeneric;
return NSDragOperationNone;
return NSDragOperationNone;
}
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
@ -672,7 +664,7 @@ static void VerticalGrayGradient(void* inInfo, float const* inData, float* outDa
NSArray *draggedTypes = [[sender draggingPasteboard] types];
if ([draggedTypes containsObject:kCaminoBookmarkListPBoardType]) {
NSArray *draggedItems = [BookmarkManager bookmarkItemsFromSerializableArray:[[sender draggingPasteboard] propertyListForType: kCaminoBookmarkListPBoardType]];
NSArray *draggedItems = [BookmarkManager bookmarkItemsFromSerializableArray:[[sender draggingPasteboard] propertyListForType:kCaminoBookmarkListPBoardType]];
// added sequentially, so use reverse object enumerator to preserve order.
NSEnumerator *enumerator = [draggedItems reverseObjectEnumerator];
id aKid;
@ -688,9 +680,9 @@ static void VerticalGrayGradient(void* inInfo, float const* inData, float* outDa
NSArray* urls = nil;
NSArray* titles = nil;
[[sender draggingPasteboard] getURLs:&urls andTitles:&titles];
// Add in reverse order to preserve order
for ( int i = [urls count] - 1; i >= 0; --i )
for (int i = [urls count] - 1; i >= 0; --i)
[toolbar addBookmark:[titles objectAtIndex:i] url:[urls objectAtIndex:i] inPosition:index isSeparator:NO];
dropHandled = YES;
}
@ -701,13 +693,13 @@ static void VerticalGrayGradient(void* inInfo, float const* inData, float* outDa
return dropHandled;
}
- (NSRect)insertionHiliteRectForButton:(NSView*)aButton position:(int) aPosition
- (NSRect)insertionHiliteRectForButton:(NSView*)aButton position:(int)aPosition
{
NSRect buttonFrame = [aButton frame];
if (aPosition == CHInsertInto)
return NSInsetRect(buttonFrame, -kButtonRectHPadding, -kButtonRectVPadding);
// we fudge the rect for before/after so that it's equivalent to the space between buttons,
// and covers the insertion indicate that we draw (since we use this rect to refresh)
NSRect gapRect;
@ -715,14 +707,15 @@ static void VerticalGrayGradient(void* inInfo, float const* inData, float* outDa
gapRect = NSMakeRect(buttonFrame.origin.x + buttonFrame.size.width, buttonFrame.origin.y, kBookmarkButtonHorizPadding, buttonFrame.size.height);
else
gapRect = NSMakeRect(buttonFrame.origin.x - kBookmarkButtonHorizPadding, buttonFrame.origin.y, kBookmarkButtonHorizPadding, buttonFrame.size.height);
gapRect.origin.x -= 1.0f; // tweak to prevent the insertion point drawing over favicons
return NSInsetRect(gapRect, -2.0f, -2.0f);
}
- (BookmarkButton*)makeNewButtonWithItem:(BookmarkItem*)aItem
{
return [[[BookmarkButton alloc] initWithFrame: NSMakeRect(0.0f, 0.0f, kMaxBookmarkButtonWidth, kBookmarkButtonHeight) item:aItem] autorelease];
return [[[BookmarkButton alloc] initWithFrame:NSMakeRect(0.0f, 0.0f, kMaxBookmarkButtonWidth, kBookmarkButtonHeight)
item:aItem] autorelease];
}
#pragma mark -
@ -751,31 +744,27 @@ static void VerticalGrayGradient(void* inInfo, float const* inData, float* outDa
{
BookmarkItem* changedItem = [aNote object];
BookmarkFolder* toolbarFolder = [[BookmarkManager sharedBookmarkManager] toolbarFolder];
if (!toolbarFolder)
return; // haven't finished loading bookmarks yet
if (changedItem == toolbarFolder)
{
if (changedItem == toolbarFolder) {
const unsigned int kSignificantRootChangeFlags = (kBookmarkItemTitleChangedMask |
kBookmarkItemStatusChangedMask |
kBookmarkItemChildrenChangedMask);
if ([BookmarkItem bookmarkChangedNotificationUserInfo:[aNote userInfo] containsFlags:kSignificantRootChangeFlags])
{
if ([BookmarkItem bookmarkChangedNotificationUserInfo:[aNote userInfo] containsFlags:kSignificantRootChangeFlags]) {
mButtonListDirty = YES;
[self rebuildButtonList];
}
}
else if ([changedItem parent] == toolbarFolder)
{
else if ([changedItem parent] == toolbarFolder) {
const unsigned int kSignificantItemChangeFlags = (kBookmarkItemTitleChangedMask |
kBookmarkItemIconChangedMask |
kBookmarkItemStatusChangedMask |
kBookmarkItemChildrenChangedMask);
if ([BookmarkItem bookmarkChangedNotificationUserInfo:[aNote userInfo] containsFlags:kSignificantItemChangeFlags])
{
if ([BookmarkItem bookmarkChangedNotificationUserInfo:[aNote userInfo] containsFlags:kSignificantItemChangeFlags]) {
// note that this gets called as we're building the toolbar for the first time, since that's
// setting the icons on the bookmarks. It's slightly expensive, but harmless.
[self updateButton:changedItem];

View File

@ -118,13 +118,13 @@ enum
IBOutlet NSMenu* mQuickSearchMenuBookmarks;
IBOutlet NSMenu* mQuickSearchMenuHistory;
IBOutlet NSSearchField* mSearchField;
IBOutlet NSSplitView* mContainersSplit;
IBOutlet ExtendedTableView* mContainersTableView;
// the bookmarks and history outliners are swapped in and out of this container
IBOutlet NSView* mOutlinerHostView;
@ -141,9 +141,9 @@ enum
BOOL mSetupComplete; // have we been fully initialized?
BOOL mSplittersRestored; // splitters can only be positioned after we resize to fit the window
BOOL mBookmarkUpdatesDisabled;
NSMutableDictionary* mExpandedStates;
BookmarkFolder* mActiveRootCollection;
@ -151,11 +151,11 @@ enum
NSArray* mSearchResultArray;
int mSearchTag;
int mOpenActionFlag;
BookmarkItem* mItemToReveal;
HistoryDataSource* mHistoryDataSource;
NSImage* mSeparatorImage;
}
@ -166,51 +166,51 @@ enum
//
// IBActions
//
-(IBAction) setAsDockMenuFolder:(id)aSender;
-(IBAction) addCollection:(id)aSender;
-(IBAction) addBookmarkSeparator:(id)aSender;
-(IBAction) addBookmarkFolder:(id)aSender;
-(IBAction) openBookmark: (id)aSender;
-(IBAction) openBookmarkInNewTab:(id)aSender;
-(IBAction) openBookmarkInNewWindow:(id)aSender;
-(IBAction) openBookmarksInTabsInNewWindow:(id)aSender;
-(IBAction) deleteBookmarks:(id)aSender;
-(IBAction) showBookmarkInfo:(id)aSender;
-(IBAction) locateBookmark:(id)aSender;
-(IBAction) cut:(id)aSender;
-(IBAction) copy:(id)aSender;
-(IBAction) paste:(id)aSender;
-(IBAction) delete:(id)aSender;
-(IBAction) searchStringChanged:(id)aSender;
- (IBAction)setAsDockMenuFolder:(id)aSender;
- (IBAction)addCollection:(id)aSender;
- (IBAction)addBookmarkSeparator:(id)aSender;
- (IBAction)addBookmarkFolder:(id)aSender;
- (IBAction)openBookmark:(id)aSender;
- (IBAction)openBookmarkInNewTab:(id)aSender;
- (IBAction)openBookmarkInNewWindow:(id)aSender;
- (IBAction)openBookmarksInTabsInNewWindow:(id)aSender;
- (IBAction)deleteBookmarks:(id)aSender;
- (IBAction)showBookmarkInfo:(id)aSender;
- (IBAction)locateBookmark:(id)aSender;
- (IBAction)cut:(id)aSender;
- (IBAction)copy:(id)aSender;
- (IBAction)paste:(id)aSender;
- (IBAction)delete:(id)aSender;
- (IBAction)searchStringChanged:(id)aSender;
// uses the tag of the sender to determine the sort order
-(IBAction) arrange:(id)aSender;
- (IBAction)arrange:(id)aSender;
-(IBAction) copyURLs:(id)aSender;
- (IBAction)copyURLs:(id)aSender;
-(IBAction) quicksearchPopupChanged:(id)aSender;
- (IBAction)quicksearchPopupChanged:(id)aSender;
- (void)resetSearchField;
-(NSView*)bookmarksEditingView;
- (NSView*)bookmarksEditingView;
-(int) containerCount;
-(void) selectLastContainer;
-(BOOL) haveSelectedRow;
-(int)numberOfSelectedRows;
- (int)containerCount;
- (void)selectLastContainer;
- (BOOL)haveSelectedRow;
- (int)numberOfSelectedRows;
-(void) setActiveCollection:(BookmarkFolder *)aFolder;
-(BookmarkFolder *)activeCollection;
- (void)setActiveCollection:(BookmarkFolder *)aFolder;
- (BookmarkFolder *)activeCollection;
- (BookmarkFolder *)selectedItemFolderAndIndex:(int*)outIndex;
- (void)revealItem:(BookmarkItem*)item scrollIntoView:(BOOL)inScroll selecting:(BOOL)inSelectItem byExtendingSelection:(BOOL)inExtendSelection;
- (void)setItemToRevealOnLoad:(BookmarkItem*)inItem;
-(void)deleteCollection:(id)aSender;
-(void)completeSetup;
-(void)ensureBookmarks;
- (void)deleteCollection:(id)aSender;
- (void)completeSetup;
- (void)ensureBookmarks;
-(BOOL) canPasteFromPasteboard:(NSPasteboard*)aPasteboard;
-(void) copyBookmarks:(NSArray*)bookmarkItemsToCopy toPasteboard:(NSPasteboard*)aPasteboard;
- (BOOL)canPasteFromPasteboard:(NSPasteboard*)aPasteboard;
- (void)copyBookmarks:(NSArray*)bookmarkItemsToCopy toPasteboard:(NSPasteboard*)aPasteboard;
@end

File diff suppressed because it is too large Load Diff

View File

@ -56,7 +56,7 @@
AddressBookManager* mAddressBookManager;
}
-(id)initWithBookmarkManager:(BookmarkManager *)manager;
-(void)postStartupInitialization:(BookmarkManager *)manager;
- (id)initWithBookmarkManager:(BookmarkManager *)manager;
- (void)postStartupInitialization:(BookmarkManager *)manager;
@end

View File

@ -48,19 +48,19 @@
#import "NetworkServices.h"
#import "BookmarksClient.h"
@interface KindaSmartFolderManager (Private) <NetworkServicesClient, BookmarksClient>
-(void)addBookmark:(Bookmark *)aBookmark toSmartFolder:(BookmarkFolder *)aFolder;
-(void)removeBookmark:(Bookmark *)aBookmark fromSmartFolder:(BookmarkFolder *)aFolder;
-(void)checkForNewTop10:(Bookmark *)aBookmark;
-(void)setupAddressBook;
-(void)rebuildTop10List;
@interface KindaSmartFolderManager (Private) <NetworkServicesClient, BookmarksClient>
- (void)addBookmark:(Bookmark *)aBookmark toSmartFolder:(BookmarkFolder *)aFolder;
- (void)removeBookmark:(Bookmark *)aBookmark fromSmartFolder:(BookmarkFolder *)aFolder;
- (void)checkForNewTop10:(Bookmark *)aBookmark;
- (void)setupAddressBook;
- (void)rebuildTop10List;
@end
const unsigned kNumTop10Items = 10; // well, 10, duh!
@implementation KindaSmartFolderManager
-(id)initWithBookmarkManager:(BookmarkManager *)manager
- (id)initWithBookmarkManager:(BookmarkManager *)manager
{
if ((self = [super init])) {
// retain all our smart folders, just to be safe
@ -76,7 +76,7 @@ const unsigned kNumTop10Items = 10; // well, 10, duh!
return self;
}
-(void) dealloc
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[mTop10Folder release];
@ -86,7 +86,7 @@ const unsigned kNumTop10Items = 10; // well, 10, duh!
[super dealloc];
}
-(void)postStartupInitialization:(BookmarkManager *)manager
- (void)postStartupInitialization:(BookmarkManager *)manager
{
// register for Rendezvous - if we need to
if (mRendezvousFolder) {
@ -102,7 +102,7 @@ const unsigned kNumTop10Items = 10; // well, 10, duh!
[self rebuildTop10List];
}
-(void) setupAddressBook
- (void)setupAddressBook
{
mAddressBookManager = [[AddressBookManager alloc] initWithFolder:mAddressBookFolder];
if (mAddressBookManager)
@ -112,7 +112,7 @@ const unsigned kNumTop10Items = 10; // well, 10, duh!
//
// flush top 10 list & rebuild from scratch
//
-(void)rebuildTop10List
- (void)rebuildTop10List
{
unsigned i, count = [mTop10Folder count];
for (i = 0; i < count; i++)
@ -127,21 +127,19 @@ const unsigned kNumTop10Items = 10; // well, 10, duh!
// visit counts anyway. However, we will skip any other custom bookmark
// container folders that the user has created.
NSEnumerator* bookmarksEnum = [[manager bookmarkMenuFolder] objectEnumerator];
while ((curItem = [bookmarksEnum nextObject]))
{
while ((curItem = [bookmarksEnum nextObject])) {
if ([curItem isKindOfClass:[Bookmark class]])
[self checkForNewTop10:(Bookmark *)curItem];
}
bookmarksEnum = [[manager toolbarFolder] objectEnumerator];
while ((curItem = [bookmarksEnum nextObject]))
{
while ((curItem = [bookmarksEnum nextObject])) {
if ([curItem isKindOfClass:[Bookmark class]])
[self checkForNewTop10:(Bookmark *)curItem];
}
}
-(void)checkForNewTop10:(Bookmark *)aBookmark
- (void)checkForNewTop10:(Bookmark *)aBookmark
{
NSMutableArray* top10ItemsArray = [mTop10Folder childArray];
@ -159,16 +157,13 @@ const unsigned kNumTop10Items = 10; // well, 10, duh!
if ([top10ItemsArray count] == kNumTop10Items)
currentMinVisits = [[top10ItemsArray lastObject] numberOfVisits];
if (curIndex != NSNotFound) // it's already in the list
{
if (visitCount < currentMinVisits)
{
if (curIndex != NSNotFound) { // it's already in the list
if (visitCount < currentMinVisits) {
// the item dropped off the list. rather than grovel for the next highest item, just rebuild the list
// (this could be optimized)
[self rebuildTop10List]; // XXX potential recursion!
}
else
{
else {
// just resort
[mTop10Folder sortChildrenUsingSelector:@selector(compareForTop10:sortDescending:)
reverseSort:YES
@ -176,8 +171,7 @@ const unsigned kNumTop10Items = 10; // well, 10, duh!
undoable:NO];
}
}
else if (visitCount >= currentMinVisits)
{
else if (visitCount >= currentMinVisits) {
NSString* newItemURL = [aBookmark url];
if ([newItemURL hasPrefix:@"about:"])
@ -191,8 +185,7 @@ const unsigned kNumTop10Items = 10; // well, 10, duh!
NSNumber* reverseSort = [NSNumber numberWithBool:YES];
// we check the entire list to look for items with a duplicate url
for (unsigned i = 0; i < numItems; i ++)
{
for (unsigned i = 0; i < numItems; i++) {
Bookmark* curChild = [top10ItemsArray objectAtIndex:i];
if ([newItemURL isEqualToString:[curChild url]])
return;
@ -205,8 +198,7 @@ const unsigned kNumTop10Items = 10; // well, 10, duh!
if (insertionIndex == -1 && [top10ItemsArray count] < kNumTop10Items)
insertionIndex = [top10ItemsArray count];
if (insertionIndex != -1)
{
if (insertionIndex != -1) {
[mTop10Folder insertIntoSmartFolderChild:aBookmark atIndex:insertionIndex];
if ([top10ItemsArray count] > kNumTop10Items)
[mTop10Folder deleteFromSmartFolderChildAtIndex:[top10ItemsArray count] - 1];
@ -218,7 +210,7 @@ const unsigned kNumTop10Items = 10; // well, 10, duh!
//
// if we don't already have it, add it
//
-(void)addBookmark:(Bookmark *)aBookmark toSmartFolder:(BookmarkFolder *)aFolder
- (void)addBookmark:(Bookmark *)aBookmark toSmartFolder:(BookmarkFolder *)aFolder
{
if (aFolder == nil) return; //if the smart folder isn't enabled, we're done
unsigned index = [aFolder indexOfObjectIdenticalTo:aBookmark];
@ -228,8 +220,8 @@ const unsigned kNumTop10Items = 10; // well, 10, duh!
//
// if we have this item, remove it
//
-(void)removeBookmark:(Bookmark *)anItem fromSmartFolder:(BookmarkFolder *)aFolder
//
- (void)removeBookmark:(Bookmark *)anItem fromSmartFolder:(BookmarkFolder *)aFolder
{
if (aFolder == nil) return; //if the smart folder isn't enabled, we're done
unsigned index = [aFolder indexOfObjectIdenticalTo:anItem];
@ -241,11 +233,13 @@ const unsigned kNumTop10Items = 10; // well, 10, duh!
static int SortByProtocolAndName(NSDictionary* item1, NSDictionary* item2, void *context)
{
NSComparisonResult protocolCompare = [[item1 objectForKey:@"name"] compare:[item2 objectForKey:@"name"] options:NSCaseInsensitiveSearch];
NSComparisonResult protocolCompare = [[item1 objectForKey:@"name"] compare:[item2 objectForKey:@"name"]
options:NSCaseInsensitiveSearch];
if (protocolCompare != NSOrderedSame)
return protocolCompare;
return [[item1 objectForKey:@"protocol"] compare:[item2 objectForKey:@"protocol"] options:NSCaseInsensitiveSearch];
return [[item1 objectForKey:@"protocol"] compare:[item2 objectForKey:@"protocol"]
options:NSCaseInsensitiveSearch];
}
- (void)availableServicesChanged:(NSNotification *)note
@ -261,8 +255,7 @@ static int SortByProtocolAndName(NSDictionary* item1, NSDictionary* item2, void
NSEnumerator* keysEnumerator = [netserv serviceEnumerator];
NSMutableArray* servicesArray = [[NSMutableArray alloc] initWithCapacity:10];
id key;
while ((key = [keysEnumerator nextObject]))
{
while ((key = [keysEnumerator nextObject])) {
NSDictionary* serviceDict = [NSDictionary dictionaryWithObjectsAndKeys:
key, @"id",
[netserv serviceName:[key intValue]], @"name",
@ -271,18 +264,16 @@ static int SortByProtocolAndName(NSDictionary* item1, NSDictionary* item2, void
[servicesArray addObject:serviceDict];
}
if ([servicesArray count] != 0)
{
if ([servicesArray count] != 0) {
// sort on protocol, then name
[servicesArray sortUsingFunction:SortByProtocolAndName context:NULL];
// make bookmarks
unsigned int numServices = [servicesArray count];
for (i = 0; i < numServices; i ++)
{
for (i = 0; i < numServices; i++) {
NSDictionary* serviceDict = [servicesArray objectAtIndex:i];
NSString* itemName = [[serviceDict objectForKey:@"name"] stringByAppendingString:NSLocalizedString([serviceDict objectForKey:@"protocol"], @"")];
NSString* itemName = [[serviceDict objectForKey:@"name"] stringByAppendingString:NSLocalizedString([serviceDict objectForKey:@"protocol"], nil)];
RendezvousBookmark* serviceBookmark = [[RendezvousBookmark alloc] initWithServiceID:[[serviceDict objectForKey:@"id"] intValue]];
[serviceBookmark setTitle:itemName];
[mRendezvousFolder appendChild:serviceBookmark];
@ -298,16 +289,13 @@ static int SortByProtocolAndName(NSDictionary* item1, NSDictionary* item2, void
{
NSDictionary *dict = [note userInfo];
id client = [dict objectForKey:NetworkServicesClientKey];
if ([client isKindOfClass:[Bookmark class]])
{
if ([client isKindOfClass:[Bookmark class]]) {
// I'm not sure why we have to check to see that the client is a child
// of the rendezvous folder. Maybe just see if it's a RendezvousBookmark?
NSEnumerator* enumerator = [[mRendezvousFolder childArray] objectEnumerator];
Bookmark *curChild;
while ((curChild = [enumerator nextObject]))
{
if (curChild == client)
{
while ((curChild = [enumerator nextObject])) {
if (curChild == client) {
[client setUrl:[dict objectForKey:NetworkServicesResolvedURLKey]];
[client setResolved:YES];
}
@ -344,9 +332,9 @@ static int SortByProtocolAndName(NSDictionary* item1, NSDictionary* item2, void
- (void)bookmarkChanged:(NSNotification *)note
{
BOOL visitCountChanged = [BookmarkItem bookmarkChangedNotificationUserInfo:[note userInfo] containsFlags:kBookmarkItemNumVisitsChangedMask];
if (visitCountChanged)
{
BOOL visitCountChanged = [BookmarkItem bookmarkChangedNotificationUserInfo:[note userInfo]
containsFlags:kBookmarkItemNumVisitsChangedMask];
if (visitCountChanged) {
BookmarkItem *anItem = [note object];
if ([anItem isKindOfClass:[Bookmark class]])
[self checkForNewTop10:(Bookmark *)anItem];

View File

@ -40,7 +40,7 @@
#include "nsIAboutModule.h"
class nsAboutBookmarks : public nsIAboutModule
class nsAboutBookmarks : public nsIAboutModule
{
public:
NS_DECL_ISUPPORTS

View File

@ -60,13 +60,13 @@ nsAboutBookmarks::NewChannel(nsIURI *aURI, nsIChannel **result)
nsresult rv;
nsIChannel* channel;
NSString* windowTitle = mIsBookmarks ? NSLocalizedString(@"BookmarksWindowTitle", @"")
: NSLocalizedString(@"HistoryWindowTitle", @"");
NSString* windowTitle = mIsBookmarks ? NSLocalizedString(@"BookmarksWindowTitle", nil)
: NSLocalizedString(@"HistoryWindowTitle", nil);
NSString* sourceString = [NSString stringWithFormat:kBlankPageHTML, windowTitle];
nsAutoString pageSource;
[sourceString assignTo_nsAString:pageSource];
nsCOMPtr<nsIInputStream> in;
rv = NS_NewCStringInputStream(getter_AddRefs(in),
NS_ConvertUTF16toUTF8(pageSource));