Bookmarks implemented
This commit is contained in:
parent
7adefe0a05
commit
b135147cbd
|
@ -20,11 +20,11 @@ unlike the cocoa port.
|
|||
|
||||
Current State
|
||||
----------------
|
||||
Works pretty well, has history and download management.
|
||||
Works pretty well, has history, download management, bookmarks.
|
||||
|
||||
What still needs doing
|
||||
----------------
|
||||
Tabs, bookmarks, other bits and bobs probably.
|
||||
Tabs, preferences, other bits and bobs probably.
|
||||
|
||||
|
||||
This has only been tested on OpenBSD macppc, there's probably issues with
|
||||
|
|
|
@ -85,10 +85,10 @@ static NSMenuItem *menuItemForItem(id item) {
|
|||
}
|
||||
|
||||
-(void)bookmarksUpdated: (NSNotification*)aNotification {
|
||||
NSLog(@"Updated bookmarks...");
|
||||
NSArray *bookmarks = [[BookmarkFolder rootBookmarkFolder] children];
|
||||
NSMenu *bookmarksMenu = [[[NSApp menu] itemWithTag: TAG_SUBMENU_BOOKMARKS] submenu];
|
||||
for (NSInteger i = 0; i < [bookmarksMenu numberOfItems] - 2; i++) {
|
||||
NSInteger nItems = [bookmarksMenu numberOfItems];
|
||||
for (NSInteger i = 0; i < nItems - 2; i++) {
|
||||
[bookmarksMenu removeItemAtIndex: 2];
|
||||
}
|
||||
id item;
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
-(NSString*)name;
|
||||
-(BOOL)isRootFolder;
|
||||
-(BOOL)isUnsortedFolder;
|
||||
-(void)addCopy: (id)item;
|
||||
-(void)addChild: (id)child;
|
||||
-(void)removeChild: (id)child;
|
||||
-(void)updateChild: (id)child;
|
||||
|
@ -33,4 +34,5 @@
|
|||
|
||||
+(BookmarkFolder*)rootBookmarkFolder;
|
||||
+(BookmarkFolder*)unsortedBookmarkFolder;
|
||||
+(NSArray*)allFolders;
|
||||
@end
|
|
@ -93,6 +93,28 @@ lazy-loaded when requested.
|
|||
return [name isEqual: UNSORTED_NAME];
|
||||
}
|
||||
|
||||
-(void)addCopy: (id)item {
|
||||
if ([item isKindOfClass: [BookmarkFolder class]]) {
|
||||
NSString *source = [item path];
|
||||
NSString *dest = [[self path] stringByAppendingPathComponent: [item
|
||||
name]];
|
||||
NSError *err = nil;
|
||||
BOOL ok = [[NSFileManager defaultManager] copyItemAtPath: source toPath: dest
|
||||
error: &err];
|
||||
if (ok) {
|
||||
BookmarkFolder *copy = [[BookmarkFolder alloc] initWithName: [item
|
||||
name] parent: self];
|
||||
[self initChildrenIfNeeded];
|
||||
[children addObject: copy];
|
||||
[copy release];
|
||||
} else {
|
||||
NSLog(@"Failed to add copy.");
|
||||
}
|
||||
} else {
|
||||
[self addChild: [item copy]];
|
||||
}
|
||||
}
|
||||
|
||||
-(void)moveChild: (id)child toOtherFolder: (BookmarkFolder*)otherFolder {
|
||||
NSString *source = nil;
|
||||
NSString *destination = nil;
|
||||
|
@ -239,6 +261,21 @@ lazy-loaded when requested.
|
|||
return nil;
|
||||
}
|
||||
|
||||
static NSArray *foldersOfFolder(BookmarkFolder *folder) {
|
||||
NSMutableArray *array = [NSMutableArray array];
|
||||
NSArray *childFolders = [folder childFolders];
|
||||
BookmarkFolder *childFolder;
|
||||
for (NSUInteger i = 0; i < [childFolders count]; i++) {
|
||||
childFolder = [childFolders objectAtIndex: i];
|
||||
[array addObject: childFolder];
|
||||
[array addObjectsFromArray: foldersOfFolder(childFolder)];
|
||||
}
|
||||
return array;
|
||||
}
|
||||
+(NSArray*)allFolders {
|
||||
return foldersOfFolder([BookmarkFolder rootBookmarkFolder]);
|
||||
}
|
||||
|
||||
-(NSString*)path {
|
||||
return path;
|
||||
}
|
||||
|
@ -293,5 +330,4 @@ lazy-loaded when requested.
|
|||
}
|
||||
children = newChildren;
|
||||
}
|
||||
|
||||
@end
|
|
@ -3,12 +3,14 @@
|
|||
#import "BookmarkFolder.h"
|
||||
#import "Website.h"
|
||||
#import "AppDelegate.h"
|
||||
#import "CreateBookmarkPanelController.h"
|
||||
|
||||
static NSString * const NEW_FOLDER_NAME = @"New Folder";
|
||||
|
||||
@interface BookmarksWindowController (Private)
|
||||
-(NSArray*)selectedItems;
|
||||
-(NSString*)getNewFolderNameForParent: (BookmarkFolder*)aFolder;
|
||||
-(void)bookmarksUpdated: (NSNotification*)notification;
|
||||
@end
|
||||
|
||||
@implementation BookmarksWindowController
|
||||
|
@ -33,6 +35,7 @@ static NSString * const NEW_FOLDER_NAME = @"New Folder";
|
|||
-(BOOL)windowShouldClose: (id)sender {
|
||||
[topLevelFolders release];
|
||||
topLevelFolders = nil;
|
||||
[[NSNotificationCenter defaultCenter] removeObserver: self];
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
@ -44,6 +47,10 @@ static NSString * const NEW_FOLDER_NAME = @"New Folder";
|
|||
[outlineView expandItem: [topLevelFolders objectAtIndex: i]
|
||||
expandChildren: YES];
|
||||
}
|
||||
[[NSNotificationCenter defaultCenter] addObserver: self
|
||||
selector: @selector(bookmarksUpdated:)
|
||||
name: BookmarksUpdatedNotificationName
|
||||
object: nil];
|
||||
}
|
||||
|
||||
-(void)awakeFromNib {
|
||||
|
@ -89,7 +96,7 @@ static NSString * const NEW_FOLDER_NAME = @"New Folder";
|
|||
[[item parentFolder] moveChild: item toOtherFolder:
|
||||
destinationFolder];
|
||||
} else {
|
||||
[destinationFolder addChild: item];
|
||||
[destinationFolder addCopy: item];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -293,4 +300,10 @@ static NSString * const NEW_FOLDER_NAME = @"New Folder";
|
|||
}
|
||||
}
|
||||
|
||||
-(void)bookmarksUpdated: (NSNotification*)notification {
|
||||
if ([[notification object] isKindOfClass: [CreateBookmarkPanelController class]]) {
|
||||
[outlineView reloadData];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -8,8 +8,7 @@
|
|||
-(id)initForWebsite: (Website*)aWebsite {
|
||||
if (self = [super initWithWindowNibName: @"CreateBookmark"]) {
|
||||
website = [aWebsite retain];
|
||||
bookmarkFolders = [[[BookmarkFolder rootBookmarkFolder] childFolders]
|
||||
retain];
|
||||
bookmarkFolders = [[BookmarkFolder allFolders] retain];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ struct website_data {
|
|||
-(void)setName: (NSString*)aName;
|
||||
-(long)fileOffset;
|
||||
-(NSString*)filename;
|
||||
-(Website*)copy;
|
||||
-(void)setFilename: (NSString*)aFilename;
|
||||
-(BookmarkFolder*)parentFolder;
|
||||
-(void)setParentFolder: (BookmarkFolder*)aBookmarkFolder;
|
||||
|
|
|
@ -102,6 +102,11 @@
|
|||
[[NSApp delegate] openWebsite: self];
|
||||
}
|
||||
|
||||
-(Website*)copy {
|
||||
Website *website = [[Website alloc] initWithName: [self name] url: [self url]];
|
||||
[website autorelease];
|
||||
return website;
|
||||
}
|
||||
// MARK: - History implementation
|
||||
|
||||
-(void)addToHistory {
|
||||
|
|
|
@ -38,7 +38,6 @@
|
|||
|
||||
// Create a new bitmap of width height
|
||||
static void *gnustep_bitmap_create(int width, int height, unsigned int state) {
|
||||
NSLog(@"gnustep_bitmap_create");
|
||||
NSBitmapImageRep *bmp = [[NSBitmapImageRep alloc]
|
||||
initWithBitmapDataPlanes: NULL
|
||||
pixelsWide: width
|
||||
|
@ -56,13 +55,11 @@ static void *gnustep_bitmap_create(int width, int height, unsigned int state) {
|
|||
|
||||
// Destroy the specified bitmap
|
||||
static void gnustep_bitmap_destroy(void *bitmap) {
|
||||
NSLog(@"gnustep_bitmap_destroy");
|
||||
[(id)bitmap dealloc];
|
||||
}
|
||||
|
||||
// Set whether it's opaque or not
|
||||
static void gnustep_bitmap_set_opaque(void *bitmap, bool opaque) {
|
||||
NSLog(@"gnustep_bitmap_set_opaque");
|
||||
if (opaque) {
|
||||
[(id)bitmap setOpaque: YES];
|
||||
} else {
|
||||
|
@ -72,13 +69,11 @@ static void gnustep_bitmap_set_opaque(void *bitmap, bool opaque) {
|
|||
|
||||
// Get whether it's opaque or not
|
||||
static bool gnustep_bitmap_get_opaque(void *bitmap) {
|
||||
NSLog(@"gnustep_bitmap_get_opaque");
|
||||
return [(id)bitmap isOpaque];
|
||||
}
|
||||
|
||||
// Test? whether it's opaque or not
|
||||
static bool gnustep_bitmap_test_opaque(void *bitmap) {
|
||||
NSLog(@"gnustep_bitmap_test_opaque");
|
||||
unsigned char *buf = [(id)bitmap bitmapData];
|
||||
|
||||
const size_t height = [(id)bitmap pixelsHigh];
|
||||
|
@ -99,49 +94,41 @@ static bool gnustep_bitmap_test_opaque(void *bitmap) {
|
|||
|
||||
// Get the image buffer for the bitmap
|
||||
static unsigned char *gnustep_bitmap_get_buffer(void *bitmap) {
|
||||
NSLog(@"gnustep_bitmap_get_buffer");
|
||||
return [(id)bitmap bitmapData];
|
||||
}
|
||||
|
||||
// Get the number of bytes per row of the bitmap
|
||||
static size_t gnustep_bitmap_get_rowstride(void *bitmap) {
|
||||
NSLog(@"gnustep_bitmap_get_rowstride");
|
||||
return [(id)bitmap bytesPerRow];
|
||||
}
|
||||
|
||||
// Get its width in pixels
|
||||
static int gnustep_bitmap_get_width(void *bitmap) {
|
||||
NSLog(@"gnustep_bitmap_get_width");
|
||||
return [(id)bitmap pixelsWide];
|
||||
}
|
||||
|
||||
// Get height in pixels
|
||||
static int gnustep_bitmap_get_height(void *bitmap) {
|
||||
NSLog(@"gnustep_bitmap_get_height");
|
||||
return [(id)bitmap pixelsHigh];
|
||||
}
|
||||
|
||||
// Get how many byytes pet pixel
|
||||
static size_t gnustep_bitmap_get_bpp(void *bitmap) {
|
||||
NSLog(@"gnustep_bitmap_get_bpp");
|
||||
return [(id)bitmap bitsPerPixel] / 8;
|
||||
}
|
||||
|
||||
// Save the bitmap to the specified path
|
||||
static bool gnustep_bitmap_save(void *bitmap, const char *path, unsigned flags) {
|
||||
NSLog(@"gnustep_bitmap_save");
|
||||
NSData *tiff = [(id)bitmap TIFFRepresentation];
|
||||
return [tiff writeToFile: [NSString stringWithUTF8String: path] atomically: YES];
|
||||
}
|
||||
|
||||
// Mark bitmap as modified
|
||||
static void gnustep_bitmap_modified(void *bitmap) {
|
||||
NSLog(@"gnustep_bitmap_modified");
|
||||
}
|
||||
|
||||
// Render content into the specified bitmap
|
||||
static nserror gnustep_bitmap_render(struct bitmap *bitmap, struct hlcache_handle *content) {
|
||||
NSLog(@"gnustep_bitmap_render");
|
||||
return NSERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue