Skip to content
This repository was archived by the owner on Apr 1, 2024. It is now read-only.

Commit 83de1c9

Browse files
authored
Merge pull request #28 from markydoodled/reformat-code
Reformat Code
2 parents f72abda + 66a36ef commit 83de1c9

File tree

8 files changed

+53
-62
lines changed

8 files changed

+53
-62
lines changed

Source Code/Note.it/Note.it iOS/ContentView.swift

Lines changed: 30 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ import CodeMirror_SwiftUI
1212

1313
struct 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+
}

Source Code/Note.it/Note.it iOS/Info.plist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
<string>$(PRODUCT_BUNDLE_IDENTIFIER).example-document</string>
1818
</dict>
1919
</array>
20+
<key>UIFileSharingEnabled</key>
21+
<true/>
2022
<key>UTImportedTypeDeclarations</key>
2123
<array>
2224
<dict>

Source Code/Note.it/Note.it iOS/Note_it_iOSApp.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import SwiftUI
1111
struct Note_it_iOSApp: App {
1212
var body: some Scene {
1313
DocumentGroup(newDocument: Note_it_iOSDocument()) { file in
14-
ContentView(document: file.$document, fileURL: URL(string: "/")!, fileTypeAttribute: "N/A", fileSizeAttribute: 0, fileTitleAtribute: "N/A", fileCreatedAttribute: Date(), fileModifiedAttribute: Date(), fileExtensionAttribute: "N/A", fileOwnerAttribute: "N/A", fileNameAttribute: "N/A", filePathAttribute: "N/A")
14+
ContentView(document: file.$document, fileURL: file.fileURL!, fileTypeAttribute: "N/A", fileSizeAttribute: 0, fileTitleAtribute: "N/A", fileCreatedAttribute: Date(), fileModifiedAttribute: Date(), fileExtensionAttribute: "N/A", fileOwnerAttribute: "N/A", fileNameAttribute: "N/A", filePathAttribute: "N/A")
1515
}
1616
}
1717
}

Source Code/Note.it/Note.it iOS/SettingsView.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,6 +1298,7 @@ struct MailView: UIViewControllerRepresentable {
12981298
class Coordinator: NSObject, MFMailComposeViewControllerDelegate {
12991299
@Binding var isShowing: Bool
13001300
@Binding var result: Result<MFMailComposeResult, Error>?
1301+
13011302
init(isShowing: Binding<Bool>, result: Binding<Result<MFMailComposeResult, Error>?>) {
13021303
_isShowing = isShowing
13031304
_result = result
@@ -1307,10 +1308,12 @@ struct MailView: UIViewControllerRepresentable {
13071308
defer {
13081309
isShowing = false
13091310
}
1311+
13101312
guard error == nil else {
13111313
self.result = .failure(error!)
13121314
return
13131315
}
1316+
13141317
self.result = .success(result)
13151318
}
13161319
}

Source Code/Note.it/Note.it.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@
334334
CLANG_WARN_UNREACHABLE_CODE = YES;
335335
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
336336
COPY_PHASE_STRIP = NO;
337+
DEAD_CODE_STRIPPING = YES;
337338
DEBUG_INFORMATION_FORMAT = dwarf;
338339
ENABLE_STRICT_OBJC_MSGSEND = YES;
339340
ENABLE_TESTABILITY = YES;
@@ -395,6 +396,7 @@
395396
CLANG_WARN_UNREACHABLE_CODE = YES;
396397
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
397398
COPY_PHASE_STRIP = NO;
399+
DEAD_CODE_STRIPPING = YES;
398400
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
399401
ENABLE_NS_ASSERTIONS = NO;
400402
ENABLE_STRICT_OBJC_MSGSEND = YES;
@@ -425,6 +427,7 @@
425427
CODE_SIGN_STYLE = Automatic;
426428
COMBINE_HIDPI_IMAGES = YES;
427429
CURRENT_PROJECT_VERSION = 5;
430+
DEAD_CODE_STRIPPING = YES;
428431
DEVELOPMENT_ASSET_PATHS = "\"Note.it/Preview Content\"";
429432
DEVELOPMENT_TEAM = ZWASU9HFBU;
430433
ENABLE_HARDENED_RUNTIME = YES;
@@ -454,6 +457,7 @@
454457
CODE_SIGN_STYLE = Automatic;
455458
COMBINE_HIDPI_IMAGES = YES;
456459
CURRENT_PROJECT_VERSION = 5;
460+
DEAD_CODE_STRIPPING = YES;
457461
DEVELOPMENT_ASSET_PATHS = "\"Note.it/Preview Content\"";
458462
DEVELOPMENT_TEAM = ZWASU9HFBU;
459463
ENABLE_HARDENED_RUNTIME = YES;
@@ -488,6 +492,7 @@
488492
INFOPLIST_FILE = "Note.it iOS/Info.plist";
489493
INFOPLIST_KEY_CFBundleDisplayName = Note.it;
490494
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.developer-tools";
495+
INFOPLIST_KEY_LSSupportsOpeningDocumentsInPlace = YES;
491496
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
492497
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
493498
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
@@ -526,6 +531,7 @@
526531
INFOPLIST_FILE = "Note.it iOS/Info.plist";
527532
INFOPLIST_KEY_CFBundleDisplayName = Note.it;
528533
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.developer-tools";
534+
INFOPLIST_KEY_LSSupportsOpeningDocumentsInPlace = YES;
529535
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
530536
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
531537
INFOPLIST_KEY_UILaunchScreen_Generation = YES;

Source Code/Note.it/Note.it/ContentView.swift

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,10 @@ import CodeMirror_SwiftUI
1111

1212
struct ContentView: View {
1313
@Binding var document: Note_itDocument
14+
1415
@State var editor = EditorSettings()
1516
@State var themes = ThemeSettings()
16-
private let fileByteCountFormatter: ByteCountFormatter = {
17-
let bcf = ByteCountFormatter()
18-
bcf.allowedUnits = [.useAll]
19-
bcf.countStyle = .file
20-
return bcf
21-
}()
17+
2218
@State var fileURL: URL
2319
@State var fileTypeAttribute: String
2420
@State var fileSizeAttribute: Int64
@@ -28,6 +24,13 @@ struct ContentView: View {
2824
@State var fileExtensionAttribute: String
2925
@State var fileOwnerAttribute: String
3026
@State var filePathAttribute: String
27+
private let fileByteCountFormatter: ByteCountFormatter = {
28+
let bcf = ByteCountFormatter()
29+
bcf.allowedUnits = [.useAll]
30+
bcf.countStyle = .file
31+
return bcf
32+
}()
33+
3134
@AppStorage("selectedAppearance") var selectedAppearance = 3
3235
var body: some View {
3336
NavigationSplitView {
@@ -223,6 +226,7 @@ struct ContentView: View {
223226
let size = fileURL.fileSize
224227
let fileextension = fileURL.pathExtension
225228
let filePath = fileURL.path
229+
226230
filePathAttribute = filePath
227231
fileExtensionAttribute = fileextension
228232
fileSizeAttribute = Int64(size)
@@ -235,7 +239,6 @@ struct ContentView: View {
235239
let pasteBoard = NSPasteboard.general
236240
pasteBoard.clearContents()
237241
pasteBoard.setString(textToCopy, forType: .string)
238-
239242
}
240243
}
241244

Source Code/Note.it/Note.it/Note_itApp.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ struct Note_itApp: App {
3131

3232
struct ExportCommandView: View {
3333
@FocusedBinding(\.document) var document
34+
3435
@State var isShowingSwiftSourceExport = false
3536
@State var isShowingPlainTextExport = false
3637
@State var isShowingXMLExport = false

Source Code/Note.it/Note.it/SettingsView.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1337,7 +1337,6 @@ class SendEmail: NSObject {
13371337
let service = NSSharingService(named: NSSharingService.Name.composeEmail)!
13381338
service.recipients = ["markhoward2005@gmail.com"]
13391339
service.subject = "Note.it Feedback"
1340-
13411340
service.perform(withItems: ["Please Fill Out All Relevant Sections:", "Report A Bug - ", "Rate The App - ", "Suggest An Improvment - "])
13421341
}
13431342
}

0 commit comments

Comments
 (0)