Skip to content

Commit

Permalink
support folder
Browse files Browse the repository at this point in the history
  • Loading branch information
kyleduo committed Sep 25, 2019
1 parent 058b8c9 commit f5abb79
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 27 deletions.
4 changes: 2 additions & 2 deletions source/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ DEPENDENCIES:
- SwiftyJSON (~> 5.0)

SPEC REPOS:
https://github.com/cocoapods/specs.git:
https://github.com/CocoaPods/Specs.git:
- Alamofire
- SwiftyJSON

Expand All @@ -17,4 +17,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 1e14da6108c97041b7daef307aaa48a8f180f7a4

COCOAPODS: 1.7.5
COCOAPODS: 1.8.0
4 changes: 4 additions & 0 deletions source/tinypng4mac.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,10 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = "$(inherited)";
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 10;
INFOPLIST_FILE = tinypng4mac/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MARKETING_VERSION = 1.0.3;
PRODUCT_BUNDLE_IDENTIFIER = com.kyleduo.tinypngmac;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand All @@ -466,8 +468,10 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = "$(inherited)";
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 10;
INFOPLIST_FILE = tinypng4mac/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MARKETING_VERSION = 1.0.3;
PRODUCT_BUNDLE_IDENTIFIER = com.kyleduo.tinypngmac;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand Down
4 changes: 2 additions & 2 deletions source/tinypng4mac/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0.2</string>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>9</string>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>NSHumanReadableCopyright</key>
Expand Down
7 changes: 7 additions & 0 deletions source/tinypng4mac/utils/IOHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,11 @@ class IOHeler {
try! fileManager.removeItem(at: file)
}
}

static func isDirectory(_ path: String) -> Bool {
let fileManager = FileManager.default
var isDirectory = ObjCBool(false)
let fileExists = fileManager.fileExists(atPath: path, isDirectory: &isDirectory)
return fileExists && isDirectory.boolValue
}
}
49 changes: 26 additions & 23 deletions source/tinypng4mac/views/DragContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,10 @@ class DragContainer: NSView {

override func draggingEntered(_ sender: NSDraggingInfo) -> NSDragOperation {
self.layer?.backgroundColor = NSColor(white: 1, alpha: highlightAlpha).cgColor;
let res = checkExtension(sender)
if let delegate = self.delegate {
delegate.draggingEntered();
}
if res {
return NSDragOperation.generic
}
return NSDragOperation()
return NSDragOperation.generic
}

override func draggingExited(_ sender: NSDraggingInfo?) {
Expand All @@ -64,11 +60,7 @@ class DragContainer: NSView {
var files = Array<URL>()
if let board = sender.draggingPasteboard.propertyList(forType: NSFilenamesPboardType) as? NSArray {
for path in board {
let url = URL(fileURLWithPath: path as! String)
let fileExtension = url.pathExtension.lowercased()
if acceptTypes.contains(fileExtension) {
files.append(url)
}
files.append(contentsOf: collectFiles(path as! String))
}
}

Expand All @@ -78,17 +70,28 @@ class DragContainer: NSView {

return true
}

func checkExtension(_ draggingInfo: NSDraggingInfo) -> Bool {
if let board = draggingInfo.draggingPasteboard.propertyList(forType: NSFilenamesPboardType) as? NSArray {
for path in board {
let url = URL(fileURLWithPath: path as! String)
let fileExtension = url.pathExtension.lowercased()
if acceptTypes.contains(fileExtension) {
return true
}
}
}
return false
}

func collectFiles(_ filePath: String) -> Array<URL> {
var files = Array<URL>()
let isDirectory = IOHeler.isDirectory(filePath)
if isDirectory {
let fileManager = FileManager.default
let enumerator = fileManager.enumerator(atPath: filePath)
while let fileName = enumerator?.nextObject() as? String {
let fullFilePath = filePath.appending("/\(fileName)")
if (fileIsAcceptable(fullFilePath)) {
files.append(URL(fileURLWithPath: fullFilePath))
}
}
} else if (fileIsAcceptable(filePath)) {
files.append(URL(fileURLWithPath: filePath))
}
return files
}

func fileIsAcceptable(_ path: String) -> Bool {
let url = URL(fileURLWithPath: path)
let fileExtension = url.pathExtension.lowercased()
return acceptTypes.contains(fileExtension)
}
}

0 comments on commit f5abb79

Please sign in to comment.