diff --git a/FastCoster/FastCoster.xcodeproj/project.pbxproj b/FastCoster/FastCoster.xcodeproj/project.pbxproj index cf052ca..d2840f2 100644 --- a/FastCoster/FastCoster.xcodeproj/project.pbxproj +++ b/FastCoster/FastCoster.xcodeproj/project.pbxproj @@ -12,7 +12,6 @@ 5A1986FB2996502C00FA0471 /* FileButtonSelector.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A1986FA2996502C00FA0471 /* FileButtonSelector.swift */; }; 5A450751298CE6D500E3D402 /* CsvDocument.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A450750298CE6D500E3D402 /* CsvDocument.swift */; }; 5A45075B298D01EF00E3D402 /* libcoster_rs.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5A45075A298D01EF00E3D402 /* libcoster_rs.a */; }; - 5A4995C829BC423900A1A107 /* TempFileDocument.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A4995C729BC423900A1A107 /* TempFileDocument.swift */; }; 5ADD9F2D298A713300F998F5 /* FastCosterApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5ADD9F2C298A713300F998F5 /* FastCosterApp.swift */; }; 5ADD9F2F298A713300F998F5 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5ADD9F2E298A713300F998F5 /* ContentView.swift */; }; 5ADD9F31298A713400F998F5 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 5ADD9F30298A713400F998F5 /* Assets.xcassets */; }; @@ -49,7 +48,6 @@ 5A450755298CFFE400E3D402 /* create-lib.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = "create-lib.sh"; sourceTree = ""; }; 5A450756298D00AE00E3D402 /* remove-lib.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = "remove-lib.sh"; sourceTree = ""; }; 5A45075A298D01EF00E3D402 /* libcoster_rs.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libcoster_rs.a; path = "../costerrs/target/aarch64-apple-ios/release/libcoster_rs.a"; sourceTree = ""; }; - 5A4995C729BC423900A1A107 /* TempFileDocument.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TempFileDocument.swift; sourceTree = ""; }; 5ADD9F29298A713300F998F5 /* FastCoster.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = FastCoster.app; sourceTree = BUILT_PRODUCTS_DIR; }; 5ADD9F2C298A713300F998F5 /* FastCosterApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FastCosterApp.swift; sourceTree = ""; }; 5ADD9F2E298A713300F998F5 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; @@ -142,7 +140,6 @@ 5A1986F62996436500FA0471 /* OverheadAllocation.swift */, 5A1986F82996436D00FA0471 /* MoveMoney.swift */, 5A1986FA2996502C00FA0471 /* FileButtonSelector.swift */, - 5A4995C729BC423900A1A107 /* TempFileDocument.swift */, ); path = FastCoster; sourceTree = ""; @@ -351,7 +348,6 @@ 5A1986F92996436D00FA0471 /* MoveMoney.swift in Sources */, 5ADD9F2D298A713300F998F5 /* FastCosterApp.swift in Sources */, 5A450751298CE6D500E3D402 /* CsvDocument.swift in Sources */, - 5A4995C829BC423900A1A107 /* TempFileDocument.swift in Sources */, 5A1986F72996436500FA0471 /* OverheadAllocation.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/FastCoster/FastCoster/OverheadAllocation.swift b/FastCoster/FastCoster/OverheadAllocation.swift index d7ddbc2..532575f 100644 --- a/FastCoster/FastCoster/OverheadAllocation.swift +++ b/FastCoster/FastCoster/OverheadAllocation.swift @@ -13,12 +13,10 @@ struct OverheadAllocation: View { @State private var areas: String? @State private var allocationStatistics: String? @State private var costCentres: String? - @State private var showExportPicker = false - @State private var document: TempFileDocument? + @State private var showMovePicker = false @State private var accountType = "E" - @State private var show_from = false - - private let tempPath = FileManager.default.temporaryDirectory.appendingPathComponent("OverheadAllocation.csv", conformingTo: .commaSeparatedText) + @State private var showFrom = false + @State private var tempPath: URL?; var body: some View { VStack { @@ -38,7 +36,7 @@ struct OverheadAllocation: View { costCentres = result } TextField("Account Type", text: $accountType) - Toggle(isOn: $show_from) { + Toggle(isOn: $showFrom) { Text("Show from cc movements") } Button { @@ -46,34 +44,31 @@ struct OverheadAllocation: View { } label: { Text("Allocate Overheads") }.padding() - .fileExporter(isPresented: $showExportPicker, document: document, contentType: .commaSeparatedText) { result in - + .fileMover(isPresented: $showMovePicker, file: tempPath) { result in if case .success = result { do { - try FileManager.default.removeItem(at: tempPath) + try FileManager.default.removeItem(at: tempPath!) } catch { } }else { - + print(result) } - } }.padding() .textFieldStyle(.roundedBorder) } func allocate_overheads() { + tempPath = FileManager.default.temporaryDirectory.appendingPathComponent("OverheadAllocation.csv", conformingTo: .commaSeparatedText) + // Cut off file:// + // TODO: There has to be a better way to do string slicing right? + let tempPathString = String(tempPath!.absoluteString.dropFirst(7)) DispatchQueue.global(qos: .userInitiated).async { - // Cut off file:// - // TODO: There has to be a better way to do string slicing right? - let tempPathString = String(tempPath.absoluteString.dropFirst(7)) - - allocate_overheads_from_text_to_file(lines, accounts, allocationStatistics, areas, costCentres, accountType, tempPathString, false, show_from) + allocate_overheads_from_text_to_file(lines, accounts, allocationStatistics, areas, costCentres, accountType, tempPathString, false, showFrom) DispatchQueue.main.async { - document = TempFileDocument(url: tempPath) - showExportPicker = true; + showMovePicker = true; } } } diff --git a/FastCoster/FastCoster/TempFileDocument.swift b/FastCoster/FastCoster/TempFileDocument.swift deleted file mode 100644 index 4c50734..0000000 --- a/FastCoster/FastCoster/TempFileDocument.swift +++ /dev/null @@ -1,32 +0,0 @@ -// -// TempFileDocument.swift -// FastCoster -// -// Created by Michael Pivato on 11/3/2023. -// - - -import Foundation -import SwiftUI -import UniformTypeIdentifiers - -struct TempFileDocument: FileDocument { - var tempFileUrl: URL? - var wrapper: FileWrapper? - - static var readableContentTypes: [UTType] {[.commaSeparatedText]} - - init(configuration: ReadConfiguration) throws { - wrapper = configuration.file - } - - init(url: URL) { - tempFileUrl = url - } - - func fileWrapper(configuration: WriteConfiguration) throws -> FileWrapper { - return try wrapper ?? FileWrapper(url: tempFileUrl!) - } - - -} diff --git a/src/lib.rs b/src/lib.rs index f6a2283..14e3685 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -45,7 +45,7 @@ pub extern "C" fn move_money_from_text( &mut csv::Reader::from_reader(safe_cost_centres.to_bytes()), &mut output_writer, use_numeric_accounts, - true, + false, ) .expect("Failed to move money"); // TODO: Replace all these unwraps with something more elegant