diff --git a/YAPS/YAPS.xcodeproj/project.pbxproj b/YAPS/YAPS.xcodeproj/project.pbxproj index a4a2f01..22812ad 100644 --- a/YAPS/YAPS.xcodeproj/project.pbxproj +++ b/YAPS/YAPS.xcodeproj/project.pbxproj @@ -16,6 +16,7 @@ EC13307124DDB3F4008063CF /* FinderHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC13307024DDB3F4008063CF /* FinderHelper.swift */; }; EC13307424DF2B2D008063CF /* YapsFileCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC13307324DF2B2D008063CF /* YapsFileCell.swift */; }; ECF5A75824E070710010A11D /* RawFileExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECF5A75724E070710010A11D /* RawFileExtensions.swift */; }; + ECF5A76024E41AAC0010A11D /* Shared.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECF5A75F24E41AAC0010A11D /* Shared.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -31,6 +32,7 @@ EC13307024DDB3F4008063CF /* FinderHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FinderHelper.swift; sourceTree = ""; }; EC13307324DF2B2D008063CF /* YapsFileCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YapsFileCell.swift; sourceTree = ""; }; ECF5A75724E070710010A11D /* RawFileExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RawFileExtensions.swift; sourceTree = ""; }; + ECF5A75F24E41AAC0010A11D /* Shared.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Shared.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -73,6 +75,7 @@ EC13306724DAE92E008063CF /* YAPS.entitlements */, EC13306024DAE92E008063CF /* Preview Content */, EC13307024DDB3F4008063CF /* FinderHelper.swift */, + ECF5A75F24E41AAC0010A11D /* Shared.swift */, ); path = YAPS; sourceTree = ""; @@ -173,6 +176,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + ECF5A76024E41AAC0010A11D /* Shared.swift in Sources */, EC13305D24DAE92D008063CF /* ContentView.swift in Sources */, EC13307124DDB3F4008063CF /* FinderHelper.swift in Sources */, ECF5A75824E070710010A11D /* RawFileExtensions.swift in Sources */, diff --git a/YAPS/YAPS/AppDelegate.swift b/YAPS/YAPS/AppDelegate.swift index 2f56d9a..edfa3c8 100644 --- a/YAPS/YAPS/AppDelegate.swift +++ b/YAPS/YAPS/AppDelegate.swift @@ -34,6 +34,26 @@ class AppDelegate: NSObject, NSApplicationDelegate { // Insert code here to tear down your application } + /* + @IBAction func zoomIn(_ sender: Any) { + //scrollView.magnification += 0.25 + } + + @IBAction func zoomOut(_ sender: Any) { + scrollView.magnification -= 0.25 + } + + @IBAction func zoomToFit(_ sender: Any) { + scrollView.magnify(toFit: imageView.frame) + } + */ + @IBAction func getIt(_ sender: Any) { + if !Shared.shared.destinationDefined { + Shared.shared.destination = FinderHelper.shared.selectFolder(modalTitle: "Choose destination folder.") + Shared.shared.destinationDefined = true + } + FinderHelper.shared.iLikeThisImage(yapsFile: Shared.shared.currentFile, destination: Shared.shared.destination) + } } diff --git a/YAPS/YAPS/Base.lproj/Main.storyboard b/YAPS/YAPS/Base.lproj/Main.storyboard index ddab67a..bc8a578 100644 --- a/YAPS/YAPS/Base.lproj/Main.storyboard +++ b/YAPS/YAPS/Base.lproj/Main.storyboard @@ -1,7 +1,7 @@ - + - + @@ -630,6 +630,19 @@ + + + + + + + + + + + + + @@ -673,7 +686,7 @@ - + diff --git a/YAPS/YAPS/ContentView.swift b/YAPS/YAPS/ContentView.swift index 89d7dac..bf36450 100644 --- a/YAPS/YAPS/ContentView.swift +++ b/YAPS/YAPS/ContentView.swift @@ -10,13 +10,7 @@ import SwiftUI struct ContentView: View { @State var fileList = [YapsFile]() - @State var tabbedFile: YapsFile = YapsFile(name: "EMPTY", file: .init(fileURLWithPath: "Y")) @State var previewImg = Image("placeholder-image") - @State var destinationDefined: Bool = false - @State var destinationURL: URL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0] - - let finderHelper: FinderHelper = FinderHelper() - var body: some View { VStack { @@ -24,7 +18,7 @@ struct ContentView: View { VStack(alignment: .leading) { HStack { Button(action: { - let files = self.finderHelper.askForFolderAndGetFiles() + let files = FinderHelper.shared.askForFolderAndGetFiles() if files.count > 0 { self.fileList.removeAll() @@ -35,11 +29,11 @@ struct ContentView: View { } Button(action: { - if !self.destinationDefined { - self.destinationURL = self.finderHelper.selectFolder(modalTitle: "Choose destination folder.") - self.destinationDefined = true + if !Shared.shared.destinationDefined { + Shared.shared.destination = FinderHelper.shared.selectFolder(modalTitle: "Choose destination folder.") + Shared.shared.destinationDefined = true } - self.finderHelper.iLikeThisImage(yapsFile: self.tabbedFile, destination: self.destinationURL) + FinderHelper.shared.iLikeThisImage(yapsFile: Shared.shared.currentFile, destination: Shared.shared.destination) }) { Text("Get It!") } @@ -57,10 +51,10 @@ struct ContentView: View { print("pressed \(yapsFile.name)") - self.previewImg = FinderHelper().getImageByURL(source: selectedImageURL) + self.previewImg = FinderHelper.shared.getImageByURL(source: selectedImageURL) .resizable() - self.tabbedFile = yapsFile + Shared.shared.currentFile = yapsFile }) .onMoveCommand { (direction) in print("direction: \(direction)") @@ -79,7 +73,7 @@ struct ContentView: View { } } - Text("\(self.tabbedFile.file.absoluteString)") + Text("\(Shared.shared.currentFile.file.absoluteString)") .multilineTextAlignment(.leading) .lineLimit(1) } diff --git a/YAPS/YAPS/FinderHelper.swift b/YAPS/YAPS/FinderHelper.swift index 12abb5e..4b29e32 100644 --- a/YAPS/YAPS/FinderHelper.swift +++ b/YAPS/YAPS/FinderHelper.swift @@ -10,6 +10,9 @@ import Foundation import SwiftUI class FinderHelper { + static let shared = FinderHelper() + + private init() { } func selectFolder(modalTitle: String) -> URL { let dialog = NSOpenPanel(); diff --git a/YAPS/YAPS/Shared.swift b/YAPS/YAPS/Shared.swift new file mode 100644 index 0000000..427f8db --- /dev/null +++ b/YAPS/YAPS/Shared.swift @@ -0,0 +1,18 @@ +// +// Shared.swift +// YAPS +// +// Created by Gerrit Linnemann on 12.08.20. +// Copyright © 2020 Adawim UG (haftungsbeschränkt). All rights reserved. +// + +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 + + private init() { } +} diff --git a/YAPS/YAPS/Struct/YapsFileCell.swift b/YAPS/YAPS/Struct/YapsFileCell.swift index a8a09b6..21fd316 100644 --- a/YAPS/YAPS/Struct/YapsFileCell.swift +++ b/YAPS/YAPS/Struct/YapsFileCell.swift @@ -18,7 +18,7 @@ struct YapsFileCell: View { HStack { // Icon - FinderHelper().getImageByFiletype(file: yapsFile.file).resizable().frame(width: 20, height: 20) + FinderHelper.shared.getImageByFiletype(file: yapsFile.file).resizable().frame(width: 20, height: 20) // Text Text(yapsFile.name)