Markieren der aktuellen Auswahl
This commit is contained in:
parent
8ff01612a8
commit
9b276f55d2
@ -15,6 +15,7 @@ struct ContentView: View {
|
||||
var body: some View {
|
||||
VStack {
|
||||
HStack {
|
||||
NavigationView {
|
||||
VStack(alignment: .leading) {
|
||||
HStack {
|
||||
Button(action: {
|
||||
@ -22,6 +23,7 @@ struct ContentView: View {
|
||||
|
||||
if files.count > 0 {
|
||||
self.fileList.removeAll()
|
||||
|
||||
self.fileList.append(contentsOf: files)
|
||||
}
|
||||
}) {
|
||||
@ -41,30 +43,28 @@ struct ContentView: View {
|
||||
|
||||
List {
|
||||
ForEach(self.fileList, id: \.self) { yapsFile in
|
||||
YapsFileCell(yapsFile: yapsFile)
|
||||
.focusable(true, onFocusChange: { (focusChanged) in
|
||||
//self.focused = focusChanged
|
||||
print("focus changed \(focusChanged)")
|
||||
})
|
||||
YapsFileCell(focused: self.checkCurrentFile(yapsFile: yapsFile), yapsFile: yapsFile)
|
||||
.onTapGesture(perform: {
|
||||
let selectedImageURL: URL = yapsFile.file
|
||||
|
||||
print("pressed \(yapsFile.name)")
|
||||
|
||||
self.previewImg = FinderHelper.shared.getImageByURL(source: selectedImageURL)
|
||||
self.previewImg = FinderHelper.shared.getImageByURL(source: yapsFile.file)
|
||||
.resizable()
|
||||
|
||||
Shared.shared.currentFile = yapsFile
|
||||
|
||||
self.resetCurrentFile()
|
||||
self.fileList[yapsFile.index].current = true
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
.listStyle(SidebarListStyle())
|
||||
}
|
||||
.focusable()
|
||||
.onMoveCommand { (direction) in
|
||||
print("direction: \(direction)")
|
||||
print("#\(Shared.shared.currentFile.index) :: \(Shared.shared.currentFile.name)")
|
||||
}
|
||||
}
|
||||
.frame(width: 200.0)
|
||||
|
||||
GeometryReader { geo in
|
||||
self.previewImg.self
|
||||
@ -79,6 +79,20 @@ struct ContentView: View {
|
||||
.lineLimit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func checkCurrentFile(yapsFile: YapsFile) -> Bool {
|
||||
let result: Bool = (Shared.shared.currentFile.index == yapsFile.index)
|
||||
if result {
|
||||
print("current file \(yapsFile.name)")
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func resetCurrentFile() {
|
||||
for yapsFile in self.fileList {
|
||||
self.fileList[yapsFile.index].current = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct ContentView_Previews: PreviewProvider {
|
||||
|
||||
@ -41,19 +41,21 @@ class FinderHelper {
|
||||
func askForFolderAndGetFiles() -> [YapsFile] {
|
||||
let sourceFolder = selectFolder(modalTitle: "Select image folder")
|
||||
|
||||
return getFilesList(path: sourceFolder)
|
||||
return getFileList(path: sourceFolder)
|
||||
}
|
||||
|
||||
func getFilesList(path: URL) -> [YapsFile] {
|
||||
func getFileList(path: URL) -> [YapsFile] {
|
||||
let fm = FileManager.default
|
||||
var fileList = [YapsFile]()
|
||||
|
||||
do {
|
||||
let items = try fm.contentsOfDirectory(at: path, includingPropertiesForKeys: nil, options: .skipsHiddenFiles).filter{ $0.pathExtension == "jpg" || $0.pathExtension == "jpeg" }
|
||||
|
||||
var index = 0
|
||||
for item in items {
|
||||
let yapsFile: YapsFile = YapsFile(name: item.lastPathComponent, file: item)
|
||||
let yapsFile: YapsFile = YapsFile(index: index, name: item.lastPathComponent, file: item, current: false)
|
||||
fileList.append(yapsFile)
|
||||
index += 1
|
||||
}
|
||||
} catch {
|
||||
// failed to read directory – bad permissions, perhaps?
|
||||
|
||||
@ -10,7 +10,8 @@ import Foundation
|
||||
|
||||
struct YapsFile: Identifiable, Hashable {
|
||||
let id = UUID()
|
||||
|
||||
let index: Int
|
||||
let name: String
|
||||
let file: URL
|
||||
var current: Bool
|
||||
}
|
||||
|
||||
@ -11,7 +11,7 @@ import Foundation
|
||||
class Shared: ObservableObject {
|
||||
static let shared = Shared()
|
||||
|
||||
var currentFile: YapsFile = YapsFile(name: "EMPTY", file: .init(fileURLWithPath: "Y"))
|
||||
var currentFile: YapsFile = YapsFile(index: -1, name: "EMPTY", file: .init(fileURLWithPath: "Y"), current: false)
|
||||
var destination: URL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
|
||||
var destinationDefined: Bool = false
|
||||
|
||||
|
||||
@ -10,7 +10,7 @@ import Foundation
|
||||
import SwiftUI
|
||||
|
||||
struct YapsFileCell: View {
|
||||
@State var focused: Bool = false
|
||||
@State var focused: Bool
|
||||
|
||||
var yapsFile : YapsFile
|
||||
|
||||
@ -21,7 +21,7 @@ struct YapsFileCell: View {
|
||||
FinderHelper.shared.getImageByFiletype(file: yapsFile.file).resizable().frame(width: 20, height: 20)
|
||||
|
||||
// Text
|
||||
Text(yapsFile.name)
|
||||
Text("#\(yapsFile.index) \(yapsFile.name)")
|
||||
.foregroundColor(self.focused ? .blue : .gray)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user