Skip to content

Commit

Permalink
Show a dialog for export destination selection
Browse files Browse the repository at this point in the history
Improves the UX by showing a dialog to users before exporting.
  • Loading branch information
yamadapc committed Jul 12, 2015
1 parent c93fd55 commit f1b6c7b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion iBooks Export/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@
</subviews>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
</clipView>
<scroller key="horizontalScroller" verticalHuggingPriority="750" doubleValue="0.019230769230769232" horizontal="YES" id="ihM-xV-aUc">
<scroller key="horizontalScroller" verticalHuggingPriority="750" doubleValue="0.019155557487833565" horizontal="YES" id="ihM-xV-aUc">
<rect key="frame" x="1" y="119" width="223" height="15"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
Expand Down
29 changes: 27 additions & 2 deletions iBooks Export/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,29 @@ class ViewController: NSViewController, NSTableViewDataSource {

@IBAction func onClickExtractButton(sender: AnyObject) {
self.progressIndicator.startAnimation(self)

let exportDir = self.getExportDirectory()?.path
if exportDir == nil {
return
}

dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0)) {
let filemanager = NSFileManager()
var error: NSError?
filemanager.createDirectoryAtPath(NSHomeDirectory() + "/Documents/iBooks-exported", withIntermediateDirectories: false, attributes: nil, error: &error)

var isDir = UnsafeMutablePointer<ObjCBool>.alloc(1)
var exists = filemanager.fileExistsAtPath(exportDir!, isDirectory: isDir)
if exists && isDir.memory {
filemanager.createDirectoryAtPath(exportDir!, withIntermediateDirectories: false, attributes: nil, error: &error)
}

if error != nil {
println(error)
}

for book in self.books {
if let targetPath = self.targetPath(book) {
filemanager.copyItemAtPath(book.path, toPath: NSHomeDirectory() + "/Documents/iBooks-exported/" + targetPath, error: &error)
filemanager.copyItemAtPath(book.path, toPath: exportDir! + "/" + targetPath, error: &error)
if error != nil {
println(error)
}
Expand Down Expand Up @@ -96,6 +107,20 @@ class ViewController: NSViewController, NSTableViewDataSource {
}
}

func getExportDirectory() -> NSURL? {
let openDlg = NSOpenPanel()
openDlg.canChooseDirectories = true
openDlg.canChooseFiles = false
openDlg.prompt = "Select export destination"
openDlg.canCreateDirectories = true

if openDlg.runModal() == NSModalResponseOK {
return openDlg.directoryURL
}

return nil
}

private func targetPath(book: Book) -> String? {
if book.displayName != "" {
if let itemName = book.itemName {
Expand Down

0 comments on commit f1b6c7b

Please sign in to comment.