From 8ff01612a86019241a9513db7ba9f112b1a5437e Mon Sep 17 00:00:00 2001 From: Gerrit Linnemann Date: Wed, 12 Aug 2020 20:19:24 +0200 Subject: [PATCH] List focusable --- YAPS/YAPS/ContentView.swift | 37 ++++++++++++++++++------------------ YAPS/YAPS/FinderHelper.swift | 4 ++-- YAPS/YAPS/Shared.swift | 1 + 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/YAPS/YAPS/ContentView.swift b/YAPS/YAPS/ContentView.swift index bf36450..d57fac4 100644 --- a/YAPS/YAPS/ContentView.swift +++ b/YAPS/YAPS/ContentView.swift @@ -42,26 +42,27 @@ 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)") - }) - .onTapGesture(perform: { - let selectedImageURL: URL = yapsFile.file - - print("pressed \(yapsFile.name)") - - self.previewImg = FinderHelper.shared.getImageByURL(source: selectedImageURL) - .resizable() - - Shared.shared.currentFile = yapsFile - }) - .onMoveCommand { (direction) in - print("direction: \(direction)") - } + .focusable(true, onFocusChange: { (focusChanged) in + //self.focused = focusChanged + print("focus changed \(focusChanged)") + }) + .onTapGesture(perform: { + let selectedImageURL: URL = yapsFile.file + + print("pressed \(yapsFile.name)") + + self.previewImg = FinderHelper.shared.getImageByURL(source: selectedImageURL) + .resizable() + + Shared.shared.currentFile = yapsFile + }) } } .listStyle(SidebarListStyle()) + .focusable() + .onMoveCommand { (direction) in + print("direction: \(direction)") + } } .frame(width: 200.0) @@ -73,7 +74,7 @@ struct ContentView: View { } } - Text("\(Shared.shared.currentFile.file.absoluteString)") + Text("\(Shared.shared.currentFile.file.path)") .multilineTextAlignment(.leading) .lineLimit(1) } diff --git a/YAPS/YAPS/FinderHelper.swift b/YAPS/YAPS/FinderHelper.swift index 4b29e32..afe9348 100644 --- a/YAPS/YAPS/FinderHelper.swift +++ b/YAPS/YAPS/FinderHelper.swift @@ -22,8 +22,8 @@ class FinderHelper { dialog.showsResizeIndicator = true dialog.showsHiddenFiles = false dialog.allowsMultipleSelection = false - dialog.canChooseFiles = false - dialog.canChooseDirectories = true + dialog.canChooseFiles = false + dialog.canChooseDirectories = true if(dialog.runModal() == NSApplication.ModalResponse.OK) { let result = dialog.url diff --git a/YAPS/YAPS/Shared.swift b/YAPS/YAPS/Shared.swift index 427f8db..31e4e2a 100644 --- a/YAPS/YAPS/Shared.swift +++ b/YAPS/YAPS/Shared.swift @@ -10,6 +10,7 @@ import Foundation class Shared: ObservableObject { static let shared = Shared() + var currentFile: YapsFile = YapsFile(name: "EMPTY", file: .init(fileURLWithPath: "Y")) var destination: URL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0] var destinationDefined: Bool = false