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_CANCEL 204
|
||||
#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
|
||||
|
||||
@interface AppDelegate: NSResponder<NSApplicationDelegate> {
|
||||
|
|
|
@ -90,6 +90,7 @@ lazy-loaded when requested.
|
|||
NSString *destPath = [path stringByAppendingPathComponent: filename];
|
||||
ok = [[child asDictionary] writeToFile: destPath atomically: YES];
|
||||
[child setFilename: filename];
|
||||
[child setParentFolder: self];
|
||||
} else if ([child isKindOfClass: [BookmarkFolder class]]) {
|
||||
ok = [[NSFileManager defaultManager] createDirectoryAtPath: path
|
||||
attributes: nil];
|
||||
|
@ -227,6 +228,7 @@ lazy-loaded when requested.
|
|||
chDict = [NSDictionary dictionaryWithContentsOfFile: chPath];
|
||||
child = [[Website alloc] initWithDictionary: chDict fromFileNamed:
|
||||
fileName];
|
||||
[child setParentFolder: self];
|
||||
[newChildren addObject: [child autorelease]];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,8 +5,14 @@
|
|||
id outlineView;
|
||||
id searchBar;
|
||||
NSArray *topLevelFolders;
|
||||
BOOL isCutting;
|
||||
NSArray *copiedItems;
|
||||
}
|
||||
-(void)search: (id)sender;
|
||||
-(void)clearSearch: (id)sender;
|
||||
-(void)newFolder: (id)sender;
|
||||
-(void)cut: (id)sender;
|
||||
-(void)copy: (id)sender;
|
||||
-(void)paste: (id)sender;
|
||||
-(void)remove: (id)sender;
|
||||
@end
|
||||
|
|
|
@ -2,6 +2,11 @@
|
|||
#import "BookmarksWindowController.h"
|
||||
#import "BookmarkFolder.h"
|
||||
#import "Website.h"
|
||||
#import "AppDelegate.h"
|
||||
|
||||
@interface BookmarksWindowController (Private)
|
||||
-(void)copySelectedItems;
|
||||
@end
|
||||
|
||||
@implementation BookmarksWindowController
|
||||
|
||||
|
@ -12,6 +17,12 @@
|
|||
return self;
|
||||
}
|
||||
|
||||
-(void)dealloc {
|
||||
[copiedItems release];
|
||||
[topLevelFolders release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
-(BOOL)windowShouldClose: (id)sender {
|
||||
[topLevelFolders release];
|
||||
topLevelFolders = nil;
|
||||
|
@ -32,6 +43,55 @@
|
|||
[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 {
|
||||
NSLog(@"create new folder");
|
||||
}
|
||||
|
@ -50,6 +110,17 @@
|
|||
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 {
|
||||
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
|
||||
|
|
|
@ -14,6 +14,7 @@ struct website_data {
|
|||
|
||||
@class BookmarkFolder;
|
||||
@interface Website: NSObject {
|
||||
BookmarkFolder *parentFolder;
|
||||
NSString *filename;
|
||||
long fileOffset;
|
||||
struct website_data *data;
|
||||
|
@ -28,7 +29,8 @@ struct website_data {
|
|||
-(long)fileOffset;
|
||||
-(NSString*)filename;
|
||||
-(void)setFilename: (NSString*)aFilename;
|
||||
|
||||
-(BookmarkFolder*)parentFolder;
|
||||
-(void)setParentFolder: (BookmarkFolder*)aBookmarkFolder;
|
||||
-(NSDictionary*)asDictionary;
|
||||
|
||||
-(void)open;
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
|
||||
-(void)dealloc {
|
||||
free(data);
|
||||
[parentFolder release];
|
||||
[filename release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
@ -74,6 +75,16 @@
|
|||
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 {
|
||||
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
|
||||
[dict setObject: [self name] forKey: @"name"];
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue