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

Commit 8b9f997

Browse files
authored
Merge pull request #29 from markydoodled/code-comments
Code Comments
2 parents 83de1c9 + ad76a5e commit 8b9f997

File tree

8 files changed

+87
-0
lines changed

8 files changed

+87
-0
lines changed

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@ import SwiftUIPrint
1111
import CodeMirror_SwiftUI
1212

1313
struct ContentView: View {
14+
//Load In Document
1415
@Binding var document: Note_it_iOSDocument
1516

17+
//Load Undo/Redo Manager
1618
@Environment(\.undoManager) var undoManager
1719

20+
//Load In Editor And Theme Settings
1821
@State var editor = EditorSettings()
1922
@State var themes = ThemesSettings()
2023

24+
//Create Metadata Stores
2125
@State var fileURL: URL
2226
@State var fileTypeAttribute: String
2327
@State var fileSizeAttribute: Int64
@@ -35,9 +39,12 @@ struct ContentView: View {
3539
return bcf
3640
}()
3741

42+
//Setup The Multi Sheet Tracker
3843
@State var activeSheet: ActiveSheet?
44+
//Setup Appearance Tracker
3945
@AppStorage("selectedAppearance") var selectedAppearance = 3
4046

47+
//Setup File Exporter Sheet Trackers
4148
@State var isShowingSwiftSourceExport = false
4249
@State var isShowingPlainTextExport = false
4350
@State var isShowingXMLExport = false
@@ -59,16 +66,21 @@ struct ContentView: View {
5966
@State var isShowingPerlScriptExport = false
6067
@State var isShowingPHPScriptExport = false
6168
var body: some View {
69+
//Code Editor View
6270
CodeView(theme: themes.theme, code: $document.text, mode: themes.syntax.mode(), fontSize: editor.fontSize, showInvisibleCharacters: editor.showInvisibleCharacters, lineWrapping: editor.lineWrapping)
71+
//On Editor Load Get File Attributes
6372
.onLoadSuccess {
6473
getAttributes()
6574
}
75+
//Error If The Editor Fails To Load
6676
.onLoadFail { error in
6777
print("Load Failed: \(error.localizedDescription)")
6878
}
79+
//Refetch The Attributes If The Document Contents Is Changed
6980
.onContentChange { change in
7081
getAttributes()
7182
}
83+
//Set The Appearance On View Load
7284
.onAppear {
7385
if selectedAppearance == 1 {
7486
UIApplication.shared.keyWindow?.overrideUserInterfaceStyle = .light
@@ -78,6 +90,7 @@ struct ContentView: View {
7890
UIApplication.shared.keyWindow?.overrideUserInterfaceStyle = .unspecified
7991
}
8092
}
93+
//Change The App Appearance If The Picker Changes
8194
.onChange(of: selectedAppearance) { app in
8295
if selectedAppearance == 1 {
8396
UIApplication.shared.keyWindow?.overrideUserInterfaceStyle = .light
@@ -87,6 +100,7 @@ struct ContentView: View {
87100
UIApplication.shared.keyWindow?.overrideUserInterfaceStyle = .unspecified
88101
}
89102
}
103+
//Toolbar Of Quick Actions
90104
.toolbar(id: "quick-actions") {
91105
ToolbarItem(id: "settings", placement: .primaryAction) {
92106
Button(action: {activeSheet = .settings}) {
@@ -145,6 +159,7 @@ struct ContentView: View {
145159
.keyboardShortcut("c", modifiers: [.command, .shift])
146160
}
147161
}
162+
//Sheet That Swaps Between Settings, Metadata And File Export When Differnent Buttons Pressed
148163
.sheet(item: $activeSheet) { item in
149164
switch item {
150165
case .settings:
@@ -164,6 +179,7 @@ struct ContentView: View {
164179
.toolbarRole(.editor)
165180
.navigationBarTitleDisplayMode(.inline)
166181
}
182+
//Form Showing File Metadata
167183
var metadata: some View {
168184
Form {
169185
Section {
@@ -181,6 +197,7 @@ struct ContentView: View {
181197
}
182198
.navigationTitle("Metadata")
183199
}
200+
//Form Showing Export Options, File Print Button And File Exporters
184201
var export: some View {
185202
Form {
186203
Group {
@@ -425,6 +442,7 @@ struct ContentView: View {
425442
}
426443
}
427444
}
445+
//Fetch The File Attributes For The Open Document
428446
func getAttributes() {
429447
let creationDate = fileURL.creationDate
430448
let modificationDate = fileURL.modificationDate
@@ -444,6 +462,7 @@ struct ContentView: View {
444462
fileModifiedAttribute = modificationDate!
445463
fileCreatedAttribute = creationDate!
446464
}
465+
//Copy The Whole Document To The Clipboard
447466
private func copyToClipBoard(textToCopy: String) {
448467
let paste = UIPasteboard.general
449468
paste.string = textToCopy
@@ -456,6 +475,7 @@ struct ContentView_Previews: PreviewProvider {
456475
}
457476
}
458477

478+
//Fetch The File Attribute Keys From An Extension To URL
459479
extension URL {
460480
var attributes: [FileAttributeKey : Any]? {
461481
do {
@@ -491,6 +511,7 @@ extension URL {
491511
}
492512
}
493513

514+
//Setup Multi Sheet Swapping Variables
494515
enum ActiveSheet: Identifiable {
495516
case settings, metadata, export
496517

@@ -499,6 +520,7 @@ enum ActiveSheet: Identifiable {
499520
}
500521
}
501522

523+
//Implement keyWindow For Appearance Changes
502524
extension UIApplication {
503525
var keyWindow: UIWindow? {
504526
return self.connectedScenes
@@ -509,6 +531,7 @@ extension UIApplication {
509531
}
510532
}
511533

534+
//Setup The Print File Button View
512535
struct PrintSetup<Page>: View where Page: View {
513536
let page: Page
514537
var body: some View {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import SwiftUI
1010
@main
1111
struct Note_it_iOSApp: App {
1212
var body: some Scene {
13+
//Create Document Window For Editor
1314
DocumentGroup(newDocument: Note_it_iOSDocument()) { file in
1415
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")
1516
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import SwiftUI
99
import UniformTypeIdentifiers
1010

11+
//Get Custom Type For Document Creation
1112
extension UTType {
1213
static var noteitText: UTType {
1314
UTType(importedAs: "com.MSJ.Note-it.text")
@@ -17,12 +18,15 @@ extension UTType {
1718
struct Note_it_iOSDocument: FileDocument {
1819
var text: String
1920

21+
//Set Text As Blank When Creating A New Document
2022
init(text: String = "") {
2123
self.text = text
2224
}
2325

26+
//Set Readable File Types
2427
static var readableContentTypes: [UTType] { [.noteitText, .swiftSource, .plainText, .utf8PlainText, .utf16PlainText, .utf16ExternalPlainText, .utf8TabSeparatedText, .xml, .yaml, .json, .html, .assemblyLanguageSource, .cHeader, .cSource, .cPlusPlusHeader, .cPlusPlusSource, .objectiveCPlusPlusSource, .objectiveCSource, .appleScript, .javaScript, .shellScript, .pythonScript, .rubyScript, .perlScript, .phpScript] }
2528

29+
//Set How To Read Documents
2630
init(configuration: ReadConfiguration) throws {
2731
guard let data = configuration.file.regularFileContents,
2832
let string = String(data: data, encoding: .utf8)
@@ -32,6 +36,7 @@ struct Note_it_iOSDocument: FileDocument {
3236
text = string
3337
}
3438

39+
//Set How To Write Documents
3540
func fileWrapper(configuration: WriteConfiguration) throws -> FileWrapper {
3641
let data = text.data(using: .utf8)!
3742
return .init(regularFileWithContents: data)

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,30 @@ import CodeMirror_SwiftUI
1010
import MessageUI
1111

1212
struct SettingsView: View {
13+
//Setup Mail Sheet View And Result Trackers
1314
@State var result: Result<MFMailComposeResult, Error>? = nil
1415
@State var isShowingMailView = false
1516
var body: some View {
17+
//Show Settings Sections In A Form
1618
Form {
1719
EditorSettings()
1820
ThemesSettings()
1921
misc
2022
}
2123
.navigationTitle("Settings")
2224
}
25+
//Misc Settings Section
2326
var misc: some View {
2427
Section {
28+
//Version Text
2529
LabeledContent("Version", value: "2.0")
30+
//Build Text
2631
LabeledContent("Build", value: "5")
32+
//Button To Send Feedback
2733
Button(action: {isShowingMailView.toggle()}) {
2834
Text("Send Feedback")
2935
}
36+
//Feedback Mail View Sheet
3037
.sheet(isPresented: $isShowingMailView) {
3138
MailView(isShowing: self.$isShowingMailView, result: self.$result)
3239
}
@@ -43,11 +50,17 @@ struct SettingsView_Previews: PreviewProvider {
4350
}
4451

4552
struct ThemesSettings: View {
53+
//Store Editor Syntax And Theme Selection
4654
@AppStorage("selectedSyntax") var selectedSyntax = 51
4755
@AppStorage("selectedTheme") var selectedTheme = 80
4856
@AppStorage("syntax") var syntax: CodeMode = CodeMode.text
4957
@AppStorage("theme") var theme: CodeViewTheme = CodeViewTheme.zenburnesque
5058
var body: some View {
59+
//Example Code Editor View
60+
Section {
61+
CodeView(theme: theme, code: .constant("Hello World"), mode: syntax.mode(), fontSize: 12, showInvisibleCharacters: false, lineWrapping: false)
62+
}
63+
//Theme Picker
5164
Section {
5265
Picker(selection: $selectedTheme, label: Text("Theme")) {
5366
Group {
@@ -504,6 +517,7 @@ struct ThemesSettings: View {
504517
}
505518
}
506519
.pickerStyle(.menu)
520+
//Detect Changes In The Theme Picker
507521
.onChange(of: selectedTheme) { themeValue in
508522
if themeValue == 1 {
509523
self.theme = CodeViewTheme.bbedit
@@ -827,6 +841,7 @@ struct ThemesSettings: View {
827841
self.theme = CodeViewTheme.irWhite
828842
}
829843
}
844+
//Syntax Picker
830845
Picker(selection: $selectedSyntax, label: Text("Syntax")) {
831846
Group {
832847
Button(action: {}) {
@@ -1082,6 +1097,7 @@ struct ThemesSettings: View {
10821097
}
10831098
}
10841099
.pickerStyle(.menu)
1100+
//Detect Changes In The Syntax Picker
10851101
.onChange(of: selectedSyntax) { syntax in
10861102
if syntax == 1 {
10871103
self.syntax = CodeMode.apl
@@ -1271,16 +1287,20 @@ struct ThemesSettings: View {
12711287
}
12721288

12731289
struct EditorSettings: View {
1290+
//Store Editor Settings
12741291
@AppStorage("lineWrapping") var lineWrapping = true
12751292
@AppStorage("showInvisibleCharacters") var showInvisibleCharacters = false
12761293
@AppStorage("fontSize") var fontSize = 12
12771294
var body: some View {
12781295
Section {
1296+
//Font Size Stepper
12791297
Stepper("Font Size - \(fontSize)", value: $fontSize, in: 1...120)
1298+
//Toggle Line Wrapping
12801299
Toggle(isOn: $lineWrapping) {
12811300
Text("Line Wrapping")
12821301
}
12831302
.toggleStyle(.switch)
1303+
//Toggle Showing Invisible Characters
12841304
Toggle(isOn: $showInvisibleCharacters) {
12851305
Text("Show Invisible Characters")
12861306
}
@@ -1291,6 +1311,7 @@ struct EditorSettings: View {
12911311
}
12921312
}
12931313

1314+
//Create Mail View To Send Feedback
12941315
struct MailView: UIViewControllerRepresentable {
12951316
@Binding var isShowing: Bool
12961317
@Binding var result: Result<MFMailComposeResult, Error>?

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

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

1212
struct ContentView: View {
13+
//Load In Document
1314
@Binding var document: Note_itDocument
1415

16+
//Load In Settings
1517
@State var editor = EditorSettings()
1618
@State var themes = ThemeSettings()
1719

20+
//Create Metadata Stores
1821
@State var fileURL: URL
1922
@State var fileTypeAttribute: String
2023
@State var fileSizeAttribute: Int64
@@ -31,9 +34,11 @@ struct ContentView: View {
3134
return bcf
3235
}()
3336

37+
//Store Forced App Appearance
3438
@AppStorage("selectedAppearance") var selectedAppearance = 3
3539
var body: some View {
3640
NavigationSplitView {
41+
//Sidebar Of File Metadata
3742
List {
3843
Section {
3944
Text("\(NSDocumentController().currentDocument?.displayName ?? "None")")
@@ -86,6 +91,7 @@ struct ContentView: View {
8691
}
8792
.frame(minWidth: 250)
8893
} detail: {
94+
//Code Editor View
8995
GeometryReader { reader in
9096
ScrollView {
9197
CodeView(theme: themes.theme, code: $document.text, mode: themes.syntax.mode(), fontSize: editor.fontSize, showInvisibleCharacters: editor.showInvisibleCharacters, lineWrapping: editor.lineWrapping)
@@ -104,6 +110,7 @@ struct ContentView: View {
104110
}
105111
.frame(height: reader.size.height)
106112
}
113+
//Customisable Toolbar Of Quick Actions
107114
.toolbar(id: "quick-actions") {
108115
ToolbarItem(id: "update-metadata", placement: .status) {
109116
Button(action: {
@@ -171,6 +178,7 @@ struct ContentView: View {
171178
}
172179
.toolbarRole(.editor)
173180
}
181+
//TouchBar Of Quick Actions
174182
.touchBar {
175183
Button(action: {
176184
fileURL = NSDocumentController().currentDocument?.fileURL ?? URL(string: "/")!
@@ -197,6 +205,7 @@ struct ContentView: View {
197205
Label("Duplicate", systemImage: "doc.on.doc")
198206
}
199207
}
208+
//Set The Appearance When The App Window Is Loaded
200209
.onAppear() {
201210
if selectedAppearance == 1 {
202211
NSApp.appearance = NSAppearance(named: .aqua)
@@ -208,6 +217,7 @@ struct ContentView: View {
208217
fileURL = NSDocumentController().currentDocument?.fileURL ?? URL(string: "/")!
209218
getAttributes()
210219
}
220+
//Chance The App Window Appearance When The Toggle Is Changed
211221
.onChange(of: selectedAppearance) { appearance in
212222
if selectedAppearance == 1 {
213223
NSApp.appearance = NSAppearance(named: .aqua)
@@ -218,6 +228,7 @@ struct ContentView: View {
218228
}
219229
}
220230
}
231+
//Fetch The File Metadata Attributes
221232
func getAttributes() {
222233
let creationDate = fileURL.creationDate
223234
let modificationDate = fileURL.modificationDate
@@ -235,6 +246,7 @@ struct ContentView: View {
235246
fileModifiedAttribute = modificationDate!
236247
fileCreatedAttribute = creationDate!
237248
}
249+
//Copy The Whole Document To The Clipboard
238250
private func copyToClipBoard(textToCopy: String) {
239251
let pasteBoard = NSPasteboard.general
240252
pasteBoard.clearContents()
@@ -248,6 +260,7 @@ struct ContentView_Previews: PreviewProvider {
248260
}
249261
}
250262

263+
//Fetch Metadata Keys Through URL Extension
251264
extension URL {
252265
var attributes: [FileAttributeKey : Any]? {
253266
do {

0 commit comments

Comments
 (0)