Foto-Vorschau
This commit is contained in:
parent
893829d0e5
commit
0dce6e3988
21
YAPS/YAPS/Assets.xcassets/file_jpg.imageset/Contents.json
vendored
Normal file
21
YAPS/YAPS/Assets.xcassets/file_jpg.imageset/Contents.json
vendored
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"images" : [
|
||||||
|
{
|
||||||
|
"filename" : "file_jpg.png",
|
||||||
|
"idiom" : "universal",
|
||||||
|
"scale" : "1x"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idiom" : "universal",
|
||||||
|
"scale" : "2x"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idiom" : "universal",
|
||||||
|
"scale" : "3x"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"info" : {
|
||||||
|
"author" : "xcode",
|
||||||
|
"version" : 1
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
YAPS/YAPS/Assets.xcassets/file_jpg.imageset/file_jpg.png
vendored
Normal file
BIN
YAPS/YAPS/Assets.xcassets/file_jpg.imageset/file_jpg.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.2 KiB |
21
YAPS/YAPS/Assets.xcassets/placeholder-image.imageset/Contents.json
vendored
Normal file
21
YAPS/YAPS/Assets.xcassets/placeholder-image.imageset/Contents.json
vendored
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"images" : [
|
||||||
|
{
|
||||||
|
"filename" : "placeholder-image.png",
|
||||||
|
"idiom" : "universal",
|
||||||
|
"scale" : "1x"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idiom" : "universal",
|
||||||
|
"scale" : "2x"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idiom" : "universal",
|
||||||
|
"scale" : "3x"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"info" : {
|
||||||
|
"author" : "xcode",
|
||||||
|
"version" : 1
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
YAPS/YAPS/Assets.xcassets/placeholder-image.imageset/placeholder-image.png
vendored
Normal file
BIN
YAPS/YAPS/Assets.xcassets/placeholder-image.imageset/placeholder-image.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.0 KiB |
@ -11,14 +11,16 @@ import SwiftUI
|
|||||||
struct ContentView: View {
|
struct ContentView: View {
|
||||||
|
|
||||||
@State var fileList = [YapsFile]()
|
@State var fileList = [YapsFile]()
|
||||||
|
@State var previewImg = Image("placeholder-image")
|
||||||
|
|
||||||
var finderHelper: FinderHelper
|
var finderHelper: FinderHelper
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
HStack {
|
HStack {
|
||||||
VStack {
|
VStack(alignment: .leading) {
|
||||||
HStack {
|
HStack {
|
||||||
Button(action: {
|
Button(action: {
|
||||||
|
self.fileList.removeAll()
|
||||||
self.fileList.append(contentsOf: self.finderHelper.selectFolder())
|
self.fileList.append(contentsOf: self.finderHelper.selectFolder())
|
||||||
}) {
|
}) {
|
||||||
Text("Select Folder")
|
Text("Select Folder")
|
||||||
@ -28,21 +30,29 @@ struct ContentView: View {
|
|||||||
List {
|
List {
|
||||||
ForEach(self.fileList, id: \.self) { yapsFile in
|
ForEach(self.fileList, id: \.self) { yapsFile in
|
||||||
HStack {
|
HStack {
|
||||||
Image("file_raw").resizable().frame(width: 20, height: 20)
|
self.finderHelper.getImageByFiletype(file: yapsFile.file).resizable().frame(width: 20, height: 20)
|
||||||
Text(yapsFile.name)
|
Text(yapsFile.name)
|
||||||
}
|
}
|
||||||
.onTapGesture(perform: {
|
.onTapGesture(perform: {
|
||||||
|
let selectedImageURL: URL = yapsFile.file
|
||||||
|
|
||||||
print("pressed \(yapsFile.name)")
|
print("pressed \(yapsFile.name)")
|
||||||
|
|
||||||
|
self.previewImg = self.finderHelper.getImageByURL(source: selectedImageURL)
|
||||||
|
.resizable()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
.focusable()
|
||||||
Text("THUMBNAIL")
|
|
||||||
}
|
}
|
||||||
|
.frame(width: 150.0)
|
||||||
|
|
||||||
Text("Hello, World!")
|
GeometryReader { geo in
|
||||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
self.previewImg.self
|
||||||
|
.resizable()
|
||||||
|
.aspectRatio(contentMode: .fit)
|
||||||
|
.frame(width: geo.size.width)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,47 +11,70 @@ import SwiftUI
|
|||||||
|
|
||||||
class FinderHelper {
|
class FinderHelper {
|
||||||
|
|
||||||
func selectFolder() -> [YapsFile] {
|
func selectFolder() -> [YapsFile] {
|
||||||
let dialog = NSOpenPanel();
|
let dialog = NSOpenPanel();
|
||||||
var fileList = [YapsFile]()
|
var fileList = [YapsFile]()
|
||||||
|
|
||||||
dialog.title = "Select folder of images"
|
dialog.title = "Select folder of images"
|
||||||
dialog.showsResizeIndicator = true
|
dialog.showsResizeIndicator = true
|
||||||
dialog.showsHiddenFiles = false
|
dialog.showsHiddenFiles = false
|
||||||
dialog.allowsMultipleSelection = false
|
dialog.allowsMultipleSelection = false
|
||||||
dialog.canChooseFiles = false
|
dialog.canChooseFiles = false
|
||||||
dialog.canChooseDirectories = true
|
dialog.canChooseDirectories = true
|
||||||
|
|
||||||
if(dialog.runModal() == NSApplication.ModalResponse.OK) {
|
if(dialog.runModal() == NSApplication.ModalResponse.OK) {
|
||||||
let result = dialog.url
|
let result = dialog.url
|
||||||
|
|
||||||
if(result != nil) {
|
if(result != nil) {
|
||||||
let path: String = result!.path
|
let path: String = result!.path
|
||||||
print("Use \(path)")
|
print("Use \(path)")
|
||||||
fileList.append(contentsOf: getFilesList(path: result!))
|
fileList.append(contentsOf: getFilesList(path: result!))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// User clicked on "Cancel"
|
// User clicked on "Cancel"
|
||||||
}
|
|
||||||
|
|
||||||
return fileList
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getFilesList(path: URL) -> [YapsFile] {
|
return fileList
|
||||||
let fm = FileManager.default
|
}
|
||||||
var fileList = [YapsFile]()
|
|
||||||
|
|
||||||
do {
|
func getFilesList(path: URL) -> [YapsFile] {
|
||||||
let items = try fm.contentsOfDirectory(at: path, includingPropertiesForKeys: nil, options: .skipsHiddenFiles)
|
let fm = FileManager.default
|
||||||
|
var fileList = [YapsFile]()
|
||||||
|
|
||||||
for item in items {
|
do {
|
||||||
let yapsFile: YapsFile = YapsFile(name: item.lastPathComponent, file: item)
|
let items = try fm.contentsOfDirectory(at: path, includingPropertiesForKeys: nil, options: .skipsHiddenFiles).filter{ $0.pathExtension == "jpg" || $0.pathExtension == "jpeg" }
|
||||||
fileList.append(yapsFile)
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
// failed to read directory – bad permissions, perhaps?
|
|
||||||
}
|
|
||||||
|
|
||||||
return fileList
|
for item in items {
|
||||||
|
let yapsFile: YapsFile = YapsFile(name: item.lastPathComponent, file: item)
|
||||||
|
fileList.append(yapsFile)
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// failed to read directory – bad permissions, perhaps?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return fileList
|
||||||
|
}
|
||||||
|
|
||||||
|
func getImageByFiletype(file: URL) -> Image {
|
||||||
|
let fileExtension = file.pathExtension
|
||||||
|
var image = Image("file")
|
||||||
|
|
||||||
|
switch fileExtension {
|
||||||
|
case "jpg":
|
||||||
|
image = Image("file_jpg")
|
||||||
|
case "raw":
|
||||||
|
image = Image("file_raw")
|
||||||
|
default:
|
||||||
|
print("No image found for extenstion \(fileExtension)")
|
||||||
|
}
|
||||||
|
|
||||||
|
return image
|
||||||
|
}
|
||||||
|
|
||||||
|
func getImageByURL(source: URL) -> Image {
|
||||||
|
let imageData:NSData = NSData(contentsOf: source)!
|
||||||
|
let image = NSImage(data: imageData as Data)!
|
||||||
|
|
||||||
|
return Image(nsImage: image)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user