Work on cutting and pasting bookmarks
This commit is contained in:
parent
96d06abdd2
commit
0157ab1322
|
@ -22,6 +22,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#define TAG_MENU_REMOVE 206
|
#define TAG_MENU_REMOVE 206
|
||||||
#define TAG_MENU_CANCEL 204
|
#define TAG_MENU_CANCEL 204
|
||||||
#define TAG_MENU_OPEN 104
|
#define TAG_MENU_OPEN 104
|
||||||
|
#define TAG_MENU_COPY 202
|
||||||
|
#define TAG_MENU_CUT 201
|
||||||
|
#define TAG_MENU_PASTE 203
|
||||||
#define TAG_SUBMENU_HISTORY 500
|
#define TAG_SUBMENU_HISTORY 500
|
||||||
|
|
||||||
@interface AppDelegate: NSResponder<NSApplicationDelegate> {
|
@interface AppDelegate: NSResponder<NSApplicationDelegate> {
|
||||||
|
|
|
@ -90,6 +90,7 @@ lazy-loaded when requested.
|
||||||
NSString *destPath = [path stringByAppendingPathComponent: filename];
|
NSString *destPath = [path stringByAppendingPathComponent: filename];
|
||||||
ok = [[child asDictionary] writeToFile: destPath atomically: YES];
|
ok = [[child asDictionary] writeToFile: destPath atomically: YES];
|
||||||
[child setFilename: filename];
|
[child setFilename: filename];
|
||||||
|
[child setParentFolder: self];
|
||||||
} else if ([child isKindOfClass: [BookmarkFolder class]]) {
|
} else if ([child isKindOfClass: [BookmarkFolder class]]) {
|
||||||
ok = [[NSFileManager defaultManager] createDirectoryAtPath: path
|
ok = [[NSFileManager defaultManager] createDirectoryAtPath: path
|
||||||
attributes: nil];
|
attributes: nil];
|
||||||
|
@ -227,6 +228,7 @@ lazy-loaded when requested.
|
||||||
chDict = [NSDictionary dictionaryWithContentsOfFile: chPath];
|
chDict = [NSDictionary dictionaryWithContentsOfFile: chPath];
|
||||||
child = [[Website alloc] initWithDictionary: chDict fromFileNamed:
|
child = [[Website alloc] initWithDictionary: chDict fromFileNamed:
|
||||||
fileName];
|
fileName];
|
||||||
|
[child setParentFolder: self];
|
||||||
[newChildren addObject: [child autorelease]];
|
[newChildren addObject: [child autorelease]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,14 @@
|
||||||
id outlineView;
|
id outlineView;
|
||||||
id searchBar;
|
id searchBar;
|
||||||
NSArray *topLevelFolders;
|
NSArray *topLevelFolders;
|
||||||
|
BOOL isCutting;
|
||||||
|
NSArray *copiedItems;
|
||||||
}
|
}
|
||||||
-(void)search: (id)sender;
|
-(void)search: (id)sender;
|
||||||
-(void)clearSearch: (id)sender;
|
-(void)clearSearch: (id)sender;
|
||||||
-(void)newFolder: (id)sender;
|
-(void)newFolder: (id)sender;
|
||||||
|
-(void)cut: (id)sender;
|
||||||
|
-(void)copy: (id)sender;
|
||||||
|
-(void)paste: (id)sender;
|
||||||
|
-(void)remove: (id)sender;
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -2,6 +2,11 @@
|
||||||
#import "BookmarksWindowController.h"
|
#import "BookmarksWindowController.h"
|
||||||
#import "BookmarkFolder.h"
|
#import "BookmarkFolder.h"
|
||||||
#import "Website.h"
|
#import "Website.h"
|
||||||
|
#import "AppDelegate.h"
|
||||||
|
|
||||||
|
@interface BookmarksWindowController (Private)
|
||||||
|
-(void)copySelectedItems;
|
||||||
|
@end
|
||||||
|
|
||||||
@implementation BookmarksWindowController
|
@implementation BookmarksWindowController
|
||||||
|
|
||||||
|
@ -12,6 +17,12 @@
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-(void)dealloc {
|
||||||
|
[copiedItems release];
|
||||||
|
[topLevelFolders release];
|
||||||
|
[super dealloc];
|
||||||
|
}
|
||||||
|
|
||||||
-(BOOL)windowShouldClose: (id)sender {
|
-(BOOL)windowShouldClose: (id)sender {
|
||||||
[topLevelFolders release];
|
[topLevelFolders release];
|
||||||
topLevelFolders = nil;
|
topLevelFolders = nil;
|
||||||
|
@ -32,6 +43,55 @@
|
||||||
[self onWindowAppeared];
|
[self onWindowAppeared];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-(void)cut: (id)sender {
|
||||||
|
isCutting = YES;
|
||||||
|
[self copySelectedItems];
|
||||||
|
}
|
||||||
|
|
||||||
|
-(void)copy: (id)sender {
|
||||||
|
isCutting = NO;
|
||||||
|
[self copySelectedItems];
|
||||||
|
}
|
||||||
|
|
||||||
|
-(void)paste: (id)sender {
|
||||||
|
NSEnumerator *selected = [outlineView selectedRowEnumerator];
|
||||||
|
NSNumber *row = [selected nextObject];
|
||||||
|
if (row == nil) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
id item = [outlineView itemAtRow: [row integerValue]];
|
||||||
|
if (row == nil) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
BookmarkFolder *destinationFolder = nil;
|
||||||
|
if ([item isKindOfClass: [Website class]]) {
|
||||||
|
destinationFolder = [item parentFolder];
|
||||||
|
} else if ([item isKindOfClass: [BookmarkFolder class]]) {
|
||||||
|
destinationFolder = item;
|
||||||
|
}
|
||||||
|
if (destinationFolder == nil) {
|
||||||
|
NSLog(@"Couldn't find destination for paste");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (NSUInteger i = 0; i < [copiedItems count]; i++) {
|
||||||
|
item = [copiedItems objectAtIndex: i];
|
||||||
|
if (isCutting) {
|
||||||
|
[[item parentFolder] removeChild: item];
|
||||||
|
}
|
||||||
|
[destinationFolder addChild: item];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isCutting) {
|
||||||
|
isCutting = NO;
|
||||||
|
[copiedItems release];
|
||||||
|
copiedItems = nil;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
-(void)remove: (id)sender {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
-(void)newFolder: (id)sender {
|
-(void)newFolder: (id)sender {
|
||||||
NSLog(@"create new folder");
|
NSLog(@"create new folder");
|
||||||
}
|
}
|
||||||
|
@ -50,6 +110,17 @@
|
||||||
NSLog(@"Clear bookmarks search");
|
NSLog(@"Clear bookmarks search");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-(BOOL)validateMenuItem: (NSMenuItem*)aMenuItem {
|
||||||
|
NSInteger tag = [aMenuItem tag];
|
||||||
|
if (tag == TAG_MENU_REMOVE || tag == TAG_MENU_OPEN || tag == TAG_MENU_COPY ||
|
||||||
|
tag == TAG_MENU_CUT) {
|
||||||
|
return [outlineView numberOfSelectedRows] > 0;
|
||||||
|
} else if (tag == TAG_MENU_PASTE) {
|
||||||
|
return copiedItems != nil;
|
||||||
|
}
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
-(id)outlineView: (NSOutlineView*)outlineView child: (NSInteger)index ofItem: (id)item {
|
-(id)outlineView: (NSOutlineView*)outlineView child: (NSInteger)index ofItem: (id)item {
|
||||||
if (item == nil) {
|
if (item == nil) {
|
||||||
|
@ -101,4 +172,29 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-(void)copySelectedItems {
|
||||||
|
NSEnumerator *selected = [outlineView selectedRowEnumerator];
|
||||||
|
NSMutableArray *copiedFolders = [NSMutableArray array];
|
||||||
|
NSMutableArray *toCopy = [NSMutableArray array];
|
||||||
|
BOOL addedToPB = NO;
|
||||||
|
id row, item;
|
||||||
|
while ((row = [selected nextObject]) != NULL) {
|
||||||
|
item = [outlineView itemAtRow: [row integerValue]];
|
||||||
|
if (!addedToPB && [item isKindOfClass: [Website class]]) {
|
||||||
|
[[NSPasteboard generalPasteboard] setString: [item url]
|
||||||
|
forType: NSStringPboardType];
|
||||||
|
addedToPB = YES;
|
||||||
|
}
|
||||||
|
if ([item isKindOfClass: [BookmarkFolder class]]) {
|
||||||
|
[copiedFolders addObject: item];
|
||||||
|
}
|
||||||
|
if ([copiedFolders containsObject: [item parentFolder]]) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
[toCopy addObject: item];
|
||||||
|
}
|
||||||
|
[copiedItems release];
|
||||||
|
copiedItems = [toCopy retain];
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -14,6 +14,7 @@ struct website_data {
|
||||||
|
|
||||||
@class BookmarkFolder;
|
@class BookmarkFolder;
|
||||||
@interface Website: NSObject {
|
@interface Website: NSObject {
|
||||||
|
BookmarkFolder *parentFolder;
|
||||||
NSString *filename;
|
NSString *filename;
|
||||||
long fileOffset;
|
long fileOffset;
|
||||||
struct website_data *data;
|
struct website_data *data;
|
||||||
|
@ -28,7 +29,8 @@ struct website_data {
|
||||||
-(long)fileOffset;
|
-(long)fileOffset;
|
||||||
-(NSString*)filename;
|
-(NSString*)filename;
|
||||||
-(void)setFilename: (NSString*)aFilename;
|
-(void)setFilename: (NSString*)aFilename;
|
||||||
|
-(BookmarkFolder*)parentFolder;
|
||||||
|
-(void)setParentFolder: (BookmarkFolder*)aBookmarkFolder;
|
||||||
-(NSDictionary*)asDictionary;
|
-(NSDictionary*)asDictionary;
|
||||||
|
|
||||||
-(void)open;
|
-(void)open;
|
||||||
|
|
|
@ -41,6 +41,7 @@
|
||||||
|
|
||||||
-(void)dealloc {
|
-(void)dealloc {
|
||||||
free(data);
|
free(data);
|
||||||
|
[parentFolder release];
|
||||||
[filename release];
|
[filename release];
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
@ -74,6 +75,16 @@
|
||||||
filename = [aFilename retain];
|
filename = [aFilename retain];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set when init from bookmarks or added to folder
|
||||||
|
-(BookmarkFolder*)parentFolder {
|
||||||
|
return parentFolder;
|
||||||
|
}
|
||||||
|
|
||||||
|
-(void)setParentFolder: (BookmarkFolder*)aBookmarkFolder {
|
||||||
|
[parentFolder release];
|
||||||
|
parentFolder = [aBookmarkFolder retain];
|
||||||
|
}
|
||||||
|
|
||||||
-(NSDictionary*)asDictionary {
|
-(NSDictionary*)asDictionary {
|
||||||
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
|
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
|
||||||
[dict setObject: [self name] forKey: @"name"];
|
[dict setObject: [self name] forKey: @"name"];
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue