@@ -35,8 +35,6 @@ struct ContentView: View {
3535 return bcf
3636 } ( )
3737
38- @State var showingExport = false
39- @State var showingPrinting = false
4038 @State var activeSheet : ActiveSheet ?
4139 @AppStorage ( " selectedAppearance " ) var selectedAppearance = 3
4240
@@ -63,14 +61,12 @@ struct ContentView: View {
6361 var body : some View {
6462 CodeView ( theme: themes. theme, code: $document. text, mode: themes. syntax. mode ( ) , fontSize: editor. fontSize, showInvisibleCharacters: editor. showInvisibleCharacters, lineWrapping: editor. lineWrapping)
6563 . onLoadSuccess {
66- getDirList ( )
6764 getAttributes ( )
6865 }
6966 . onLoadFail { error in
7067 print ( " Load Failed: \( error. localizedDescription) " )
7168 }
7269 . onContentChange { change in
73- getDirList ( )
7470 getAttributes ( )
7571 }
7672 . onAppear {
@@ -170,27 +166,20 @@ struct ContentView: View {
170166 }
171167 var metadata : some View {
172168 Form {
173- Label ( " Title - \( fileNameAttribute) " , systemImage: " textformat " )
174- Label ( " Extension - \( fileExtensionAttribute) " , systemImage: " square.grid.3x1.folder.badge.plus " )
175- Label ( " Size - \( fileByteCountFormatter. string ( fromByteCount: fileSizeAttribute) ) " , systemImage: " externaldrive " )
176- Label ( " Path - \( filePathAttribute) " , systemImage: " point.topleft.down.curvedto.point.bottomright.up " )
177- Label ( " Owner - \( fileOwnerAttribute) " , systemImage: " person " )
178- Label ( " Created - \( fileCreatedAttribute. formatted ( . dateTime) ) " , systemImage: " calendar.badge.plus " )
179- Label ( " Modified - \( fileModifiedAttribute. formatted ( . dateTime) ) " , systemImage: " calendar.badge.clock " )
180- Label ( " File Type - \( fileTypeAttribute) " , systemImage: " doc " )
181- }
182- . navigationTitle ( " Metadata " )
183- . toolbar {
184- ToolbarItem ( placement: . navigationBarTrailing) {
185- Button ( action: {
186- getDirList ( )
187- getAttributes ( )
188- } ) {
189- Label ( " Update Metadata " , systemImage: " arrow.counterclockwise " )
190- }
191- . 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 " )
192180 }
193181 }
182+ . navigationTitle ( " Metadata " )
194183 }
195184 var export : some View {
196185 Form {
@@ -422,33 +411,17 @@ struct ContentView: View {
422411 . navigationTitle ( " Export " )
423412 . toolbar {
424413 ToolbarItem ( placement: . navigationBarTrailing) {
425- Button ( action: { showingPrinting = true } ) {
426- Image ( systemName: " printer " )
427- }
428- . help ( " Print " )
429- . sheet ( isPresented: $showingPrinting) {
430- NavigationStack {
431- SamplePrintSetup ( page:
432- VStack {
433- HStack {
434- Text ( document. text)
435- Spacer ( )
436- }
414+ PrintSetup ( page:
415+ VStack {
416+ HStack {
417+ Text ( document. text)
437418 Spacer ( )
438419 }
439- . padding ( )
440- )
441- . navigationTitle ( " Print " )
442- . navigationBarTitleDisplayMode ( . inline)
443- . toolbar {
444- ToolbarItem ( placement: . navigationBarTrailing) {
445- Button ( action: { showingPrinting = false } ) {
446- Text ( " Done " )
447- }
448- }
420+ Spacer ( )
449421 }
450- }
451- }
422+ . padding ( )
423+ )
424+ . help ( " Print " )
452425 }
453426 }
454427 }
@@ -471,28 +444,6 @@ struct ContentView: View {
471444 fileModifiedAttribute = modificationDate!
472445 fileCreatedAttribute = creationDate!
473446 }
474- func getDirList( ) {
475- let paths = FileManager . default. urls ( for: . documentDirectory, in: . userDomainMask) . first!
476-
477- guard let directoryURL = URL ( string: paths. path) else { return }
478-
479- do {
480- let contents = try FileManager . default. contentsOfDirectory ( at: directoryURL, includingPropertiesForKeys: [ . contentAccessDateKey] , options: [ . skipsHiddenFiles] )
481- . sorted ( by: {
482- let date0 = try $0. promisedItemResourceValues ( forKeys: [ . contentAccessDateKey] ) . contentAccessDate!
483- let date1 = try $1. promisedItemResourceValues ( forKeys: [ . contentAccessDateKey] ) . contentAccessDate!
484- return date0. compare ( date1) == . orderedAscending
485- } )
486-
487- for item in contents {
488- guard let t = try ? item. promisedItemResourceValues ( forKeys: [ . contentAccessDateKey] ) . contentAccessDate else { return }
489- print ( " \( t) \( item. lastPathComponent) " )
490- fileURL = item
491- }
492- } catch {
493- print ( error)
494- }
495- }
496447 private func copyToClipBoard( textToCopy: String ) {
497448 let paste = UIPasteboard . general
498449 paste. string = textToCopy
@@ -557,3 +508,12 @@ extension UIApplication {
557508 . first ( where: \. isKeyWindow)
558509 }
559510}
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