diff options
Diffstat (limited to 'Hotline/macOS/FileDetailsView.swift')
| -rw-r--r-- | Hotline/macOS/FileDetailsView.swift | 62 |
1 files changed, 32 insertions, 30 deletions
diff --git a/Hotline/macOS/FileDetailsView.swift b/Hotline/macOS/FileDetailsView.swift index 34e083b..16b7a60 100644 --- a/Hotline/macOS/FileDetailsView.swift +++ b/Hotline/macOS/FileDetailsView.swift @@ -6,45 +6,45 @@ struct FileDetailsView: View { @Environment(\.presentationMode) var presentationMode var fd: FileDetails - + @State private var comment: String = "" @State private var filename: String = "" - + var body: some View { - VStack (alignment: .leading){ + VStack(alignment: .leading) { Form { - HStack(alignment: .center){ + HStack(alignment: .center) { FileIconView(filename: fd.name, fileType: nil) .frame(width: 32, height: 32) TextField("", text: $filename) .disabled(!self.canRename()) } - HStack(alignment: .center){ + HStack(alignment: .center) { Text("Type:").bold().padding(.leading, 43) Text(fd.type) } - HStack(alignment: .center){ + HStack(alignment: .center) { Text("Creator:").bold().padding(.leading, 26) Text(fd.creator) } - HStack(alignment: .center){ + HStack(alignment: .center) { Text("Size:").bold().bold().padding(.leading, 48) Text(self.formattedSize(byteCount: fd.size)) } - HStack(alignment: .center){ + HStack(alignment: .center) { Text("Created:").bold().padding(.leading, 24) Text("\(FileDetailsView.dateFormatter.string(from: fd.created))") } - HStack(alignment: .center){ + HStack(alignment: .center) { Text("Modified:").bold().padding(.leading, 19) Text("\(FileDetailsView.dateFormatter.string(from: fd.modified))") } - HStack(alignment: .center){ + HStack(alignment: .center) { Text("Comments:").bold().padding(.top, 8) .padding(.leading, 5) } - - VStack(alignment: .trailing){ + + VStack(alignment: .trailing) { TextEditor(text: $comment) .padding(.leading, 2) .padding(.top, 1) @@ -61,22 +61,23 @@ struct FileDetailsView: View { presentationMode.wrappedValue.dismiss() } } - + ToolbarItem(placement: .primaryAction) { - Button{ + Button { var editedFilename: String? if filename != fd.name { editedFilename = filename } - + var editedComment: String? if comment != fd.comment { editedComment = comment } - - model.client.sendSetFileInfo(fileName: fd.name, path: fd.path, fileNewName: editedFilename, comment: editedComment) + + model.client.sendSetFileInfo( + fileName: fd.name, path: fd.path, fileNewName: editedFilename, comment: editedComment) presentationMode.wrappedValue.dismiss() - + // TODO: Update the file list if the filename was changed } label: { Text("Save") @@ -92,48 +93,49 @@ struct FileDetailsView: View { } .frame(minWidth: 400, minHeight: 400) } - - + static var dateFormatter: DateFormatter = { var dateFormatter = DateFormatter() dateFormatter.dateStyle = .long dateFormatter.timeStyle = .short - + // Original format: Fri, Aug 20, 2021, 5:14:07 PM return dateFormatter }() - + static var byteCountSizeFormatter: NumberFormatter = { let numberFormatter = NumberFormatter() numberFormatter.numberStyle = .decimal return numberFormatter }() - + static let byteFormatter = ByteCountFormatter() - + private func formattedFileSize(_ fileSize: UInt) -> String { FileView.byteFormatter.allowedUnits = [.useAll] FileView.byteFormatter.countStyle = .file return FileView.byteFormatter.string(fromByteCount: Int64(fileSize)) } - + // Format byte count Int into string like: 23.4M (24,601,664 bytes) private func formattedSize(byteCount: Int) -> String { - let formattedByteCount = FileDetailsView.byteCountSizeFormatter.string(from: NSNumber(value:byteCount)) ?? "0" - return "\(FileView.byteFormatter.string(fromByteCount: Int64(byteCount))) (\(formattedByteCount) bytes)" + let formattedByteCount = + FileDetailsView.byteCountSizeFormatter.string(from: NSNumber(value: byteCount)) ?? "0" + return + "\(FileView.byteFormatter.string(fromByteCount: Int64(byteCount))) (\(formattedByteCount) bytes)" } - + private func isEdited() -> Bool { return self.filename != fd.name || self.comment != fd.comment } - + private func canRename() -> Bool { if self.fd.type == "fldr" { return model.access?.contains(.canRenameFolders) == true } return model.access?.contains(.canRenameFiles) == true } - + private func canSetComment() -> Bool { if self.fd.type == "fldr" { return model.access?.contains(.canSetFolderComment) == true |