diff --git a/FSNotes.xcodeproj/project.pbxproj b/FSNotes.xcodeproj/project.pbxproj index 33db78fa3..a790b2186 100644 --- a/FSNotes.xcodeproj/project.pbxproj +++ b/FSNotes.xcodeproj/project.pbxproj @@ -8,7 +8,6 @@ /* Begin PBXBuildFile section */ 275592971F3AE9B5006B8988 /* MainWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 275592961F3AE9B5006B8988 /* MainWindowController.swift */; }; - 6F2592741F39913200307D71 /* SourceCodePro-Regular.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 6F2592731F39913200307D71 /* SourceCodePro-Regular.ttf */; }; A6BB525ADACCB8B7AD00BF5E /* libPods-FSNotes.a in Frameworks */ = {isa = PBXBuildFile; fileRef = B1958E38FE51AAED6005C898 /* libPods-FSNotes.a */; }; D7166F531F32F751001A883F /* icons.icns in Resources */ = {isa = PBXBuildFile; fileRef = D735E5B81F2E45CC00173215 /* icons.icns */; }; D7166F541F32F75E001A883F /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D7793C781F211C6000CA39B7 /* Main.storyboard */; }; @@ -29,6 +28,9 @@ D7A415141F2FBDA00099B82C /* NotesTableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7A415131F2FBDA00099B82C /* NotesTableView.swift */; }; D7D3D5181F44799400D152FE /* makeNote.png in Resources */ = {isa = PBXBuildFile; fileRef = D7D3D5171F44794A00D152FE /* makeNote.png */; }; D7D3D51A1F4483F500D152FE /* pin.png in Resources */ = {isa = PBXBuildFile; fileRef = D7D3D5191F4483EA00D152FE /* pin.png */; }; + D7DD79581F4E60D000D5724B /* SourceCodePro-Black.ttf in Resources */ = {isa = PBXBuildFile; fileRef = D7DD79561F4E606600D5724B /* SourceCodePro-Black.ttf */; }; + D7DD79591F4E60D000D5724B /* SourceCodePro-It.ttf in Resources */ = {isa = PBXBuildFile; fileRef = D7DD79551F4E606600D5724B /* SourceCodePro-It.ttf */; }; + D7DD795B1F4E611D00D5724B /* SourceCodePro-Regular.ttf in Resources */ = {isa = PBXBuildFile; fileRef = D7DD795A1F4E611200D5724B /* SourceCodePro-Regular.ttf */; }; D7E025081F3B6DDB00EDDA32 /* Storage.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7E025071F3B6DDB00EDDA32 /* Storage.swift */; }; /* End PBXBuildFile section */ @@ -53,9 +55,7 @@ 119660667AFC00E2FC48D23C /* Pods-FSNotes.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FSNotes.debug.xcconfig"; path = "Pods/Target Support Files/Pods-FSNotes/Pods-FSNotes.debug.xcconfig"; sourceTree = ""; }; 275592961F3AE9B5006B8988 /* MainWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainWindowController.swift; sourceTree = ""; }; 310C5FB081DABFC536EC197F /* Pods-FSNotes.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FSNotes.release.xcconfig"; path = "Pods/Target Support Files/Pods-FSNotes/Pods-FSNotes.release.xcconfig"; sourceTree = ""; }; - 6F2592731F39913200307D71 /* SourceCodePro-Regular.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; name = "SourceCodePro-Regular.ttf"; path = "Resources/SourceCodePro-Regular.ttf"; sourceTree = ""; }; B1958E38FE51AAED6005C898 /* libPods-FSNotes.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-FSNotes.a"; sourceTree = BUILT_PRODUCTS_DIR; }; - D7166F871F330A64001A883F /* SourceCodePro-Regular.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; name = "SourceCodePro-Regular.ttf"; path = "../../../Downloads/source-code-pro-2.030R-ro-1-2.050R-it/TTF/SourceCodePro-Regular.ttf"; sourceTree = ""; }; D735E5AB1F2E027D00173215 /* Note.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Note.swift; sourceTree = ""; }; D735E5B81F2E45CC00173215 /* icons.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = icons.icns; sourceTree = ""; }; D735E5BC1F2EF66000173215 /* NoteCellView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoteCellView.swift; sourceTree = ""; }; @@ -83,6 +83,9 @@ D7A415131F2FBDA00099B82C /* NotesTableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotesTableView.swift; sourceTree = ""; }; D7D3D5171F44794A00D152FE /* makeNote.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = makeNote.png; sourceTree = ""; }; D7D3D5191F4483EA00D152FE /* pin.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = pin.png; sourceTree = ""; }; + D7DD79551F4E606600D5724B /* SourceCodePro-It.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "SourceCodePro-It.ttf"; sourceTree = ""; }; + D7DD79561F4E606600D5724B /* SourceCodePro-Black.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "SourceCodePro-Black.ttf"; sourceTree = ""; }; + D7DD795A1F4E611200D5724B /* SourceCodePro-Regular.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "SourceCodePro-Regular.ttf"; sourceTree = ""; }; D7E025071F3B6DDB00EDDA32 /* Storage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Storage.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -144,7 +147,6 @@ D7793C661F211C6000CA39B7 = { isa = PBXGroup; children = ( - 6F2592731F39913200307D71 /* SourceCodePro-Regular.ttf */, D7D61FCC1F32EEA1004357C2 /* Resources */, D7793C711F211C6000CA39B7 /* FSNotes */, D7793C841F211C6000CA39B7 /* FSNotesTests */, @@ -208,7 +210,9 @@ D7D61FCC1F32EEA1004357C2 /* Resources */ = { isa = PBXGroup; children = ( - D7166F871F330A64001A883F /* SourceCodePro-Regular.ttf */, + D7DD79561F4E606600D5724B /* SourceCodePro-Black.ttf */, + D7DD79551F4E606600D5724B /* SourceCodePro-It.ttf */, + D7DD795A1F4E611200D5724B /* SourceCodePro-Regular.ttf */, D735E5B81F2E45CC00173215 /* icons.icns */, D7D3D5191F4483EA00D152FE /* pin.png */, D7D3D5171F44794A00D152FE /* makeNote.png */, @@ -331,10 +335,12 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + D7DD795B1F4E611D00D5724B /* SourceCodePro-Regular.ttf in Resources */, + D7DD79581F4E60D000D5724B /* SourceCodePro-Black.ttf in Resources */, + D7DD79591F4E60D000D5724B /* SourceCodePro-It.ttf in Resources */, D7D3D51A1F4483F500D152FE /* pin.png in Resources */, D7D3D5181F44799400D152FE /* makeNote.png in Resources */, D7166F541F32F75E001A883F /* Main.storyboard in Resources */, - 6F2592741F39913200307D71 /* SourceCodePro-Regular.ttf in Resources */, D7166F531F32F751001A883F /* icons.icns in Resources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/FSNotes/Base.lproj/Main.storyboard b/FSNotes/Base.lproj/Main.storyboard index 89871e244..631bf67e5 100644 --- a/FSNotes/Base.lproj/Main.storyboard +++ b/FSNotes/Base.lproj/Main.storyboard @@ -359,260 +359,67 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Default - - - - - - - Left to Right - - - - - - - Right to Left - - - - - - - - - - - Default - - - - - - - Left to Right - - - - - - - Right to Left - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -694,7 +501,9 @@ + + @@ -1171,7 +980,7 @@ - + diff --git a/FSNotes/EditTextView.swift b/FSNotes/EditTextView.swift index f371b708b..e9016e2e2 100644 --- a/FSNotes/EditTextView.swift +++ b/FSNotes/EditTextView.swift @@ -12,6 +12,13 @@ class EditTextView: NSTextView { override func draw(_ dirtyRect: NSRect) { super.draw(dirtyRect) } + + func getSelectedNote() -> Note { + let mainWindow = NSApplication.shared().windows.first + let viewController = mainWindow?.contentViewController as! ViewController + let note = viewController.notesTableView.getNoteFromSelectedRow() + return note + } func fill(note: Note) { self.isEditable = true @@ -19,7 +26,10 @@ class EditTextView: NSTextView { let attrString = createAttributedString(note: note) self.textStorage?.setAttributedString(attrString) - self.textStorage?.font = UserDefaultsManagement.noteFont + + if (!getSelectedNote().isRTF()) { + self.textStorage?.font = UserDefaultsManagement.noteFont + } let viewController = self.window?.contentViewController as! ViewController viewController.emptyEditAreaImage.isHidden = true @@ -81,4 +91,143 @@ class EditTextView: NSTextView { } return super.mouseDown(with: event) } + + override func performKeyEquivalent(with event: NSEvent) -> Bool { + if (event.modifierFlags.contains(.command) && isEditable) { + if (formatter(keyCode: event.keyCode)) { + return true + } + } + + return super.performKeyEquivalent(with: event) + } + + func formatter(keyCode: UInt16) -> Bool { + let mainWindow = NSApplication.shared().windows.first + let viewController = mainWindow?.contentViewController as! ViewController + let editArea = viewController.editArea! + + let currentNote = getSelectedNote() + let range = editArea.selectedRange() + let text = editArea.textStorage!.string as NSString + let selectedText = text.substring(with: range) as NSString + + let attributedText = NSMutableAttributedString(string: selectedText as String) + let options = DocumentAttributes.getDocumentAttributes(fileExtension: currentNote.url.pathExtension) + + attributedText.addAttributes(options, range: NSMakeRange(0, selectedText.length)) + + if (!editArea.isEditable) { + return false + } + + switch keyCode { + case 11: // cmd-b + if (!currentNote.isRTF()) { + attributedText.mutableString.setString("**" + attributedText.string + "**") + } else { + editArea.textStorage?.applyFontTraits(NSFontTraitMask(rawValue: NSFontTraitMask.RawValue(NSFontBoldTrait)), range: range) + } + break + case 34: // cmd-i + if (!currentNote.isRTF()) { + attributedText.mutableString.setString("_" + attributedText.string + "_") + } else { + editArea.textStorage?.applyFontTraits(NSFontTraitMask(rawValue: NSFontTraitMask.RawValue(NSFontItalicTrait)), range: range) + } + break + case 32: // cmd-u + if (currentNote.isRTF()) { + attributedText.addAttribute(NSUnderlineStyleAttributeName, value: NSUnderlineStyle.styleSingle.rawValue, range: NSMakeRange(0, selectedText.length)) + } + break + case 16: // cmd-y + if (currentNote.isRTF()) { + attributedText.addAttribute(NSStrikethroughStyleAttributeName, value: 2, range: NSMakeRange(0, selectedText.length)) + } else { + attributedText.mutableString.setString("~~" + attributedText.string + "~~") + } + case (18...23): // cmd-1/6 (headers 1/6) + if (!currentNote.isRTF()) { + var string = "" + var offset = 2 + + for index in [18,19,20,21,23,22] { + string = string + "#" + if keyCode == index { + break + } + offset = offset + 1 + } + + attributedText.mutableString.setString(string + " " + attributedText.string) + } + break + case 4: // cmd-h (image) + if (!currentNote.isRTF()) { + attributedText.mutableString.setString("![](" + attributedText.string + ")") + } + case 38: // cmd-j (link) + if (!currentNote.isRTF()) { + attributedText.mutableString.setString("[](" + attributedText.string + ")") + } + default: + return false + } + + if (![11, 34].contains(keyCode) || !currentNote.isRTF()) { + editArea.textStorage!.replaceCharacters(in: range, with: attributedText) + } + + return save(note: currentNote) + } + + @IBAction func editorBold(_ sender: Any) { + formatter(keyCode: 11) + } + + @IBAction func editorItalic(_ sender: Any) { + formatter(keyCode: 34) + } + + @IBAction func editorStrike(_ sender: Any) { + formatter(keyCode: 16) + } + + @IBAction func editorUnderline(_ sender: Any) { + formatter(keyCode: 32) + } + + @IBAction func editorHeader1(_ sender: Any) { + formatter(keyCode: 18) + } + + @IBAction func editorHeader2(_ sender: Any) { + formatter(keyCode: 19) + } + + @IBAction func editorHeader3(_ sender: Any) { + formatter(keyCode: 20) + } + + @IBAction func editorHeader4(_ sender: Any) { + formatter(keyCode: 21) + } + + @IBAction func editorHeader5(_ sender: Any) { + formatter(keyCode: 23) + } + + @IBAction func editorHeader6(_ sender: Any) { + formatter(keyCode: 22) + } + + @IBAction func editorImage(_ sender: Any) { + formatter(keyCode: 4) + } + + @IBAction func editorLink(_ sender: Any) { + formatter(keyCode: 38) + } + } diff --git a/FSNotes/Model/DocumentAttributes.swift b/FSNotes/Model/DocumentAttributes.swift index 1250328ee..6fbdb1e4e 100644 --- a/FSNotes/Model/DocumentAttributes.swift +++ b/FSNotes/Model/DocumentAttributes.swift @@ -13,12 +13,14 @@ class DocumentAttributes { static func getDocumentAttributes(fileExtension: String) -> [String : Any] { var options: [String : Any] + let font = NSFont(name: UserDefaultsManagement.fontName, size: CGFloat(UserDefaultsManagement.fontSize)) + if (fileExtension == "rtf") { options = [ - NSDocumentTypeDocumentAttribute : NSRTFTextDocumentType] + NSDocumentTypeDocumentAttribute : NSRTFTextDocumentType, + NSFontAttributeName: font + ] } else { - let font = NSFont(name: UserDefaultsManagement.fontName, size: CGFloat(UserDefaultsManagement.fontSize)) - options = [ NSDocumentTypeDocumentAttribute : NSPlainTextDocumentType, NSFontAttributeName: font diff --git a/FSNotes/Model/UserDefaultsManagement.swift b/FSNotes/Model/UserDefaultsManagement.swift index 9502a0a0d..418db6a62 100644 --- a/FSNotes/Model/UserDefaultsManagement.swift +++ b/FSNotes/Model/UserDefaultsManagement.swift @@ -53,7 +53,7 @@ public class UserDefaultsManagement { } } - static var noteFont: NSFont? { + static var noteFont: NSFont! { get { return NSFont(name: self.fontName, size: CGFloat(self.fontSize)) } diff --git a/FSNotes/NotesTableView.swift b/FSNotes/NotesTableView.swift index 382d5cc6b..06de5b85a 100644 --- a/FSNotes/NotesTableView.swift +++ b/FSNotes/NotesTableView.swift @@ -87,7 +87,7 @@ class NotesTableView: NSTableView, NSTableViewDataSource, override func performKeyEquivalent(with event: NSEvent) -> Bool { if ( - event.keyCode == 16 + event.keyCode == 28 && event.modifierFlags.contains(.command)) { return true } diff --git a/FSNotes/ViewController.swift b/FSNotes/ViewController.swift index 415be3c2a..f86f6c941 100644 --- a/FSNotes/ViewController.swift +++ b/FSNotes/ViewController.swift @@ -111,7 +111,7 @@ class ViewController: NSViewController, } // Pin note shortcut (cmd-y) - if (event.keyCode == 16 && event.modifierFlags.contains(.command)) { + if (event.keyCode == 28 && event.modifierFlags.contains(.command)) { pin(selectedRow: notesTableView.selectedRow) } } @@ -314,11 +314,7 @@ class ViewController: NSViewController, moveAtTop(id: selected) cell.renderPin() } - - func deleteNote() { - } - func renameNote(selectedRow: Int) { if (!notesTableView.noteList.indices.contains(selectedRow)) { return diff --git a/Resources/SourceCodePro-Black.ttf b/Resources/SourceCodePro-Black.ttf new file mode 100755 index 000000000..0bcfec63c Binary files /dev/null and b/Resources/SourceCodePro-Black.ttf differ diff --git a/Resources/SourceCodePro-It.ttf b/Resources/SourceCodePro-It.ttf new file mode 100755 index 000000000..437cbe16d Binary files /dev/null and b/Resources/SourceCodePro-It.ttf differ