|
@@ -26,9 +26,13 @@ class KMBookmark: NSObject {
|
|
var properties: [String: Any]? {
|
|
var properties: [String: Any]? {
|
|
get {
|
|
get {
|
|
var data: [String: Any] = documentSetup
|
|
var data: [String: Any] = documentSetup
|
|
|
|
+ var bdAlias: SKAlias?
|
|
|
|
+ if self.fileURL != nil {
|
|
|
|
+ bdAlias = SKAlias.init(url: self.fileURL)
|
|
|
|
+ }
|
|
let tempSetup = [kType: bookmarkType.rawValue,
|
|
let tempSetup = [kType: bookmarkType.rawValue,
|
|
- kBDAlias: self.aliasData ?? SKAlias.init(url: self.fileURL).data,
|
|
|
|
- kPageIndex: pageIndex.description,
|
|
|
|
|
|
+ kBDAlias: self.aliasData ?? (bdAlias != nil ? bdAlias?.data: NSData()),
|
|
|
|
+ kPageIndex: NSNumber(integerLiteral: Int(pageIndex)),
|
|
kLabel: self.label
|
|
kLabel: self.label
|
|
] as [String : Any]
|
|
] as [String : Any]
|
|
data.merge(tempSetup) { (_, new) in new }
|
|
data.merge(tempSetup) { (_, new) in new }
|
|
@@ -51,8 +55,11 @@ class KMBookmark: NSObject {
|
|
if documentSetup[kType] != nil {
|
|
if documentSetup[kType] != nil {
|
|
self.bookmarkType = KMBookmarkType(rawValue: documentSetup[kType] as! String ) ?? .bookmark
|
|
self.bookmarkType = KMBookmarkType(rawValue: documentSetup[kType] as! String ) ?? .bookmark
|
|
}
|
|
}
|
|
|
|
+ let string: String = documentSetup[kPageIndex] as? String ?? "0"
|
|
|
|
+ let intValue: UInt = UInt(string) ?? 0
|
|
|
|
+
|
|
self.aliasData = documentSetup[kBDAlias] as? NSData
|
|
self.aliasData = documentSetup[kBDAlias] as? NSData
|
|
- self.pageIndex = UInt(documentSetup[kPageIndex] as! String) ?? 0
|
|
|
|
|
|
+ self.pageIndex = intValue
|
|
if documentSetup[kLabel] != nil {
|
|
if documentSetup[kLabel] != nil {
|
|
self.label = documentSetup[kLabel] as! String
|
|
self.label = documentSetup[kLabel] as! String
|
|
}
|
|
}
|
|
@@ -266,26 +273,26 @@ class KMBookmark: NSObject {
|
|
}
|
|
}
|
|
|
|
|
|
func open() {
|
|
func open() {
|
|
- var document: Any?
|
|
|
|
- var error: Error?
|
|
|
|
-// if documentSetup != nil {
|
|
|
|
-// document = try? NSDocumentController.shared.openDocument(nil)
|
|
|
|
-// if document == nil {
|
|
|
|
-// NSApp.presentError(NSError(domain: "File not found", code: -1, userInfo: nil))
|
|
|
|
-// }
|
|
|
|
-//// document = [[NSDocumentController sharedDocumentController] openDocumentWithSetup:[self properties] error:&error];
|
|
|
|
-// } else {
|
|
|
|
- guard let fileURL = fileURL else { return }
|
|
|
|
- NSDocumentController.shared.openDocument(withContentsOf: fileURL, display: true, completionHandler: { document, result, error in
|
|
|
|
- if (error != nil) {
|
|
|
|
- NSApp.presentError(error!)
|
|
|
|
- } else {
|
|
|
|
- if self.pageIndex > 1 {
|
|
|
|
- (document as! KMMainDocument).mainViewController?.setPageNumber = self.pageIndex + 1
|
|
|
|
- }
|
|
|
|
|
|
+ var tempFileURL = fileURL
|
|
|
|
+ if tempFileURL == nil {
|
|
|
|
+ if documentSetup[kBDAlias] != nil {
|
|
|
|
+ tempFileURL = SKAlias.init(data: documentSetup[kBDAlias] as? Data).fileURL
|
|
|
|
+ }
|
|
|
|
+ if tempFileURL == nil && documentSetup[KMDocumentSetupFileNameKey] != nil {
|
|
|
|
+ tempFileURL = NSURL.fileURL(withPath: documentSetup[KMDocumentSetupFileNameKey] as? String ?? "")
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ guard let tempFileURL = tempFileURL else { return }
|
|
|
|
+ NSDocumentController.shared.openDocument(withContentsOf: tempFileURL, display: true, completionHandler: { document, result, error in
|
|
|
|
+ if (error != nil) {
|
|
|
|
+ NSApp.presentError(error!)
|
|
|
|
+ } else {
|
|
|
|
+ if self.pageIndex > 1 {
|
|
|
|
+ (document as! KMMainDocument).mainViewController?.setPageNumber = self.pageIndex + 1
|
|
}
|
|
}
|
|
- })
|
|
|
|
-// }
|
|
|
|
|
|
+ }
|
|
|
|
+ })
|
|
}
|
|
}
|
|
|
|
|
|
func objectOfChidren(index: Int) -> KMBookmark{
|
|
func objectOfChidren(index: Int) -> KMBookmark{
|
|
@@ -331,6 +338,14 @@ class KMFolderBookmark: KMBookmark {
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ override func open() {
|
|
|
|
+ var count = children.count
|
|
|
|
+ while (count != 0) {
|
|
|
|
+ count = count - 1
|
|
|
|
+ children[count].open()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
class KMRootBookmark: KMFolderBookmark {
|
|
class KMRootBookmark: KMFolderBookmark {
|
|
@@ -401,7 +416,7 @@ class KMRootBookmark: KMFolderBookmark {
|
|
}
|
|
}
|
|
|
|
|
|
//MARK: Session
|
|
//MARK: Session
|
|
-class KMSessionBookmark: KMBookmark {
|
|
|
|
|
|
+class KMSessionBookmark: KMFolderBookmark {
|
|
override var bookmarkType: KMBookmarkType {
|
|
override var bookmarkType: KMBookmarkType {
|
|
get {
|
|
get {
|
|
return .session
|
|
return .session
|