123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- //
- // KMBookmark.swift
- // PDF Reader Pro
- //
- // Created by lizhe on 2024/2/5.
- //
- import Cocoa
- enum KMBookmarkType: Int {
- case bookmark = 0
- case folder
- case session
- case separator
- }
- class KMBookmark: NSObject {
- var properties: NSDictionary?
- var bookmarkType: KMBookmarkType = .bookmark
- var label: String = ""
- var icon: NSImage = NSImage()
- var alternateIcon: NSImage = NSImage()
- var fileURL: URL?
- var pageIndex: UInt = 0
- var pageNumber: NSNumber = 0
-
- var documentSetup: [String: String] = [:]//文档
- var parent: KMBookmark?
- var children: [KMBookmark] = [] //子
-
- static func bookmark(url: URL, pageIndex: UInt, label: String) -> KMBookmark {
- var bookmark = KMBookmark()
- bookmark.fileURL = url
- bookmark.pageIndex = pageIndex
- bookmark.label = label
- return bookmark
- }
-
- func initWithProperties(properties: NSDictionary) -> KMBookmark {
-
- return KMBookmark()
- }
-
- static func bookmark(properties: NSDictionary) -> KMBookmark {
- return KMBookmark()
- }
-
- // - (id)initWithProperties:(NSDictionary *)dictionary {
- // NSString *type = [dictionary objectForKey:TYPE_KEY];
- // if ([type isEqualToString:SEPARATOR_STRING]) {
- // return (id)[[SKSeparatorBookmark alloc] init];
- // } else if ([type isEqualToString:FOLDER_STRING] || [type isEqualToString:SESSION_STRING]) {
- // Class bookmarkClass = [type isEqualToString:FOLDER_STRING] ? [SKFolderBookmark class] : [SKSessionBookmark class];
- // NSMutableArray *newChildren = [NSMutableArray array];
- // SKBookmark *child;
- // for (NSDictionary *dict in [dictionary objectForKey:CHILDREN_KEY]) {
- // if ((child = [[SKBookmark alloc] initWithProperties:dict])) {
- // [newChildren addObject:child];
- // [child release];
- // } else
- // NSLog(@"Failed to read child bookmark: %@", dict);
- // }
- // return (id)[[bookmarkClass alloc] initFolderWithChildren:newChildren label:[dictionary objectForKey:LABEL_KEY]];
- // } else if ([dictionary objectForKey:@"windowFrame"]) {
- // return (id)[[SKFileBookmark alloc] initWithSetup:dictionary label:[dictionary objectForKey:LABEL_KEY]];
- // } else {
- // NSNumber *pageIndex = [dictionary objectForKey:PAGEINDEX_KEY];
- // return (id)[[SKFileBookmark alloc] initWithAliasData:[dictionary objectForKey:ALIASDATA_KEY] pageIndex:(pageIndex ? [pageIndex unsignedIntegerValue] : NSNotFound) label:[dictionary objectForKey:LABEL_KEY]];
- // }
- // }
- }
- //MARK: Folder
- class KMFolderBookmark: KMBookmark {
- override var bookmarkType: KMBookmarkType {
- get {
- return .folder
- }
- set {
-
- }
- }
-
- override func initWithProperties(properties: NSDictionary) -> KMBookmark {
- return KMFolderBookmark()
- }
-
- static func bookmarkRoot(childrenProperties: NSArray) -> KMFolderBookmark {
- var bookmark = KMFolderBookmark()
- var childs: [KMBookmark] = []
- for setup in childrenProperties {
- let bookmark = KMBookmark()
- bookmark.documentSetup = setup as! [String : String]
- childs.append(bookmark)
- }
- bookmark.children = childs
- bookmark.label = NSLocalizedString("Bookmarks Menu", comment: "")
- return bookmark
- }
-
- // - (id)initRootWithChildrenProperties:(NSArray *)childrenProperties {
- // NSMutableArray *aChildren = [NSMutableArray array];
- // SKBookmark *child;
- // for (NSDictionary *dict in childrenProperties) {
- // if ((child = [[SKBookmark alloc] initWithProperties:dict])) {
- // [aChildren addObject:child];
- // [child release];
- // }
- // }
- // return (id)[[SKRootBookmark alloc] initFolderWithChildren:aChildren label:NSLocalizedString(@"Bookmarks Menu", @"Menu item title")];
- // }
- }
- //MARK: Session
- class KMSessionBookmark: KMBookmark {
- override var bookmarkType: KMBookmarkType {
- get {
- return .session
- }
- set {
-
- }
- }
-
- static func bookmarkSession(setups: NSArray, label: String) -> KMSessionBookmark {
- var bookmark = KMSessionBookmark()
- var childs: [KMBookmark] = []
- for setup in setups {
- let bookmark = KMBookmark()
- bookmark.documentSetup = setup as! [String : String]
- childs.append(bookmark)
- }
- bookmark.children = childs
- bookmark.label = label
- return bookmark
- }
-
- override func initWithProperties(properties: NSDictionary) -> KMBookmark {
- return KMSessionBookmark()
- }
- }
- //MARK: Separator
- class KMSeparatorBookmark: KMBookmark {
- override var bookmarkType: KMBookmarkType {
- get {
- return .separator
- }
- set {
-
- }
- }
-
- override func initWithProperties(properties: NSDictionary) -> KMBookmark {
- return KMSeparatorBookmark()
- }
- }
|