@@ -12,9 +12,12 @@ import CodeMirror_SwiftUI
1212
1313struct ContentView : View {
1414 @Binding var document : Note_it_iOSDocument
15+
1516 @Environment ( \. undoManager) var undoManager
17+
1618 @State var editor = EditorSettings ( )
1719 @State var themes = ThemesSettings ( )
20+
1821 @State var fileURL : URL
1922 @State var fileTypeAttribute : String
2023 @State var fileSizeAttribute : Int64
@@ -31,11 +34,10 @@ struct ContentView: View {
3134 bcf. countStyle = . file
3235 return bcf
3336 } ( )
34- @State var showingExport = false
35- @State var contentTypeSelection = UTType . plainText
36- @State var pickerExportSelection = 1
37+
3738 @State var activeSheet : ActiveSheet ?
3839 @AppStorage ( " selectedAppearance " ) var selectedAppearance = 3
40+
3941 @State var isShowingSwiftSourceExport = false
4042 @State var isShowingPlainTextExport = false
4143 @State var isShowingXMLExport = false
@@ -56,19 +58,15 @@ struct ContentView: View {
5658 @State var isShowingRubyScriptExport = false
5759 @State var isShowingPerlScriptExport = false
5860 @State var isShowingPHPScriptExport = false
59- @State var exportAsSelection = 1
60- @State var showingPrinting = false
6161 var body : some View {
6262 CodeView ( theme: themes. theme, code: $document. text, mode: themes. syntax. mode ( ) , fontSize: editor. fontSize, showInvisibleCharacters: editor. showInvisibleCharacters, lineWrapping: editor. lineWrapping)
6363 . onLoadSuccess {
64- getDirList ( )
6564 getAttributes ( )
6665 }
6766 . onLoadFail { error in
6867 print ( " Load Failed: \( error. localizedDescription) " )
6968 }
7069 . onContentChange { change in
71- getDirList ( )
7270 getAttributes ( )
7371 }
7472 . onAppear {
@@ -168,27 +166,20 @@ struct ContentView: View {
168166 }
169167 var metadata : some View {
170168 Form {
171- Label ( " Title - \( fileNameAttribute) " , systemImage: " textformat " )
172- Label ( " Extension - \( fileExtensionAttribute) " , systemImage: " square.grid.3x1.folder.badge.plus " )
173- Label ( " Size - \( fileByteCountFormatter. string ( fromByteCount: fileSizeAttribute) ) " , systemImage: " externaldrive " )
174- Label ( " Path - \( filePathAttribute) " , systemImage: " point.topleft.down.curvedto.point.bottomright.up " )
175- Label ( " Owner - \( fileOwnerAttribute) " , systemImage: " person " )
176- Label ( " Created - \( fileCreatedAttribute. formatted ( . dateTime) ) " , systemImage: " calendar.badge.plus " )
177- Label ( " Modified - \( fileModifiedAttribute. formatted ( . dateTime) ) " , systemImage: " calendar.badge.clock " )
178- Label ( " File Type - \( fileTypeAttribute) " , systemImage: " doc " )
179- }
180- . navigationTitle ( " Metadata " )
181- . toolbar {
182- ToolbarItem ( placement: . navigationBarTrailing) {
183- Button ( action: {
184- getDirList ( )
185- getAttributes ( )
186- } ) {
187- Label ( " Update Metadata " , systemImage: " arrow.counterclockwise " )
188- }
189- . help ( " Update Metadata " )
169+ Section {
170+ Label ( " Title - \( fileNameAttribute) " , systemImage: " textformat " )
171+ Label ( " Extension - \( fileExtensionAttribute) " , systemImage: " square.grid.3x1.folder.badge.plus " )
172+ Label ( " Size - \( fileByteCountFormatter. string ( fromByteCount: fileSizeAttribute) ) " , systemImage: " externaldrive " )
173+ Label ( " Path - \( filePathAttribute) " , systemImage: " point.topleft.down.curvedto.point.bottomright.up " )
174+ Label ( " Owner - \( fileOwnerAttribute) " , systemImage: " person " )
175+ Label ( " Created - \( fileCreatedAttribute. formatted ( . dateTime) ) " , systemImage: " calendar.badge.plus " )
176+ Label ( " Modified - \( fileModifiedAttribute. formatted ( . dateTime) ) " , systemImage: " calendar.badge.clock " )
177+ Label ( " File Type - \( fileTypeAttribute) " , systemImage: " doc " )
178+ } footer: {
179+ Text ( " Metadata Generated From Last Time The File Was Opened " )
190180 }
191181 }
182+ . navigationTitle ( " Metadata " )
192183 }
193184 var export : some View {
194185 Form {
@@ -420,11 +411,7 @@ struct ContentView: View {
420411 . navigationTitle ( " Export " )
421412 . toolbar {
422413 ToolbarItem ( placement: . navigationBarTrailing) {
423- Button ( action: { showingPrinting = true } ) {
424- Image ( systemName: " printer " )
425- }
426- . sheet ( isPresented: $showingPrinting) {
427- SamplePrintSetup ( page:
414+ PrintSetup ( page:
428415 VStack {
429416 HStack {
430417 Text ( document. text)
@@ -433,8 +420,8 @@ struct ContentView: View {
433420 Spacer ( )
434421 }
435422 . padding ( )
436- )
437- }
423+ )
424+ . help ( " Print " )
438425 }
439426 }
440427 }
@@ -447,6 +434,7 @@ struct ContentView: View {
447434 let fileextension = fileURL. pathExtension
448435 let filePath = fileURL. path
449436 let fileName = fileURL. deletingPathExtension ( ) . lastPathComponent
437+
450438 fileNameAttribute = fileName
451439 filePathAttribute = filePath
452440 fileExtensionAttribute = fileextension
@@ -456,26 +444,6 @@ struct ContentView: View {
456444 fileModifiedAttribute = modificationDate!
457445 fileCreatedAttribute = creationDate!
458446 }
459- func getDirList( ) {
460- let paths = FileManager . default. urls ( for: . documentDirectory, in: . userDomainMask) . first!
461- guard let directoryURL = URL ( string: paths. path) else { return }
462- do {
463- let contents = try FileManager . default. contentsOfDirectory ( at: directoryURL, includingPropertiesForKeys: [ . contentAccessDateKey] , options: [ . skipsHiddenFiles] )
464- . sorted ( by: {
465- let date0 = try $0. promisedItemResourceValues ( forKeys: [ . contentAccessDateKey] ) . contentAccessDate!
466- let date1 = try $1. promisedItemResourceValues ( forKeys: [ . contentAccessDateKey] ) . contentAccessDate!
467- return date0. compare ( date1) == . orderedAscending
468- } )
469-
470- for item in contents {
471- guard let t = try ? item. promisedItemResourceValues ( forKeys: [ . contentAccessDateKey] ) . contentAccessDate else { return }
472- print ( " \( t) \( item. lastPathComponent) " )
473- fileURL = item
474- }
475- } catch {
476- print ( error)
477- }
478- }
479447 private func copyToClipBoard( textToCopy: String ) {
480448 let paste = UIPasteboard . general
481449 paste. string = textToCopy
@@ -540,3 +508,12 @@ extension UIApplication {
540508 . first ( where: \. isKeyWindow)
541509 }
542510}
511+
512+ struct PrintSetup < Page> : View where Page: View {
513+ let page : Page
514+ var body : some View {
515+ Button ( action: { presentPrintInteractionController ( page: page) } ) {
516+ Image ( systemName: " printer " )
517+ }
518+ }
519+ }
0 commit comments