Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
glushchenko committed Mar 27, 2018
1 parent a70c722 commit 574add2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions FSNotes/Model/StorageItem+CoreDataClass.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,14 @@ public class StorageItem: NSManagedObject {
}
return nil
}

func fileExist(fileName: String, ext: String) -> Bool {
guard let url = getUrl() else {
return false
}

let fileURL = url.appendingPathComponent(fileName + "." + ext)

return FileManager.default.fileExists(atPath: fileURL.path)
}
}
10 changes: 10 additions & 0 deletions FSNotes/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,16 @@ class ViewController: NSViewController,
return
}

guard let itemStorage = note.storage, !itemStorage.fileExist(fileName: value, ext: note.url.pathExtension) else {
let alert = NSAlert()
alert.messageText = "Hmm, something goes wrong 🙈"
alert.informativeText = "Note with name \(value) already exist in selected storage."
alert.runModal()

sender.stringValue = note.getTitleWithoutLabel()
return
}

guard value.count > 0 else {
sender.stringValue = note.getTitleWithoutLabel()
return
Expand Down

0 comments on commit 574add2

Please sign in to comment.