Skip to content

Commit

Permalink
#13
Browse files Browse the repository at this point in the history
  • Loading branch information
glushchenko committed Aug 12, 2017
1 parent de86e29 commit 0095fce
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
16 changes: 16 additions & 0 deletions FSNotes/EditTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class EditTextView: NSTextView {
}

func fill(note: Note) {
isEditable = true
let attributedString = createAttributedString(note: note)
self.textStorage?.setAttributedString(attributedString)
self.textStorage?.font = NSFont(name: UserDefaultsManagement.fontName, size: 13.0)
Expand All @@ -38,6 +39,11 @@ class EditTextView: NSTextView {
return false
}

func clear() {
textStorage?.mutableString.setString("")
isEditable = false
}

func createAttributedString(note: Note) -> NSAttributedString {
let url = note.url!
let fileExtension = url.pathExtension
Expand All @@ -52,4 +58,14 @@ class EditTextView: NSTextView {

return attributedString
}

// Focus search field shortcut (cmd-L)
override func keyDown(with event: NSEvent) {
if (event.keyCode == 37 && event.modifierFlags.contains(.command)) {
let viewController = self.window?.contentViewController as? ViewController
viewController?.search.becomeFirstResponder()
}

super.keyDown(with: event)
}
}
9 changes: 8 additions & 1 deletion FSNotes/NotesTableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ class NotesTableView: NSTableView, NSTableViewDataSource,
super.draw(dirtyRect)
}

// Remove note

override func keyDown(with event: NSEvent) {

// Remove note (cmd-delete)
if (event.keyCode == 51 && event.modifierFlags.contains(.command)) {
if (!notesList.indices.contains(selectedRow)) {
return
Expand All @@ -45,6 +47,11 @@ class NotesTableView: NSTableView, NSTableViewDataSource,
}
}

// Rename note (cmd-R)
if (event.keyCode == 15 && event.modifierFlags.contains(.command)) {
// TODO
}

super.keyDown(with: event)
}

Expand Down
22 changes: 19 additions & 3 deletions FSNotes/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ class ViewController: NSViewController,
if (notesTableView.notesList.indices.contains(selected)) {
let note = notesTableView.notesList.remove(at: selected)
note.content = content!
//note.textStorage = editArea.textStorage!
note.date = Date.init()

if editArea.save(note: note) {
storage.noteList.remove(at: selected)
storage.noteList.insert(note, at: 0)
notesTableView.notesList.insert(note, at: 0)
notesTableView.moveRow(at: selected, to: 0)
notesTableView.reloadData(forRowIndexes: [0], columnIndexes: [0])
Expand All @@ -123,9 +123,10 @@ class ViewController: NSViewController,
self.updateTable(filter: search.stringValue)

if (notesTableView.notesList.count > 0) {
//attibutedString.string
editArea.fill(note: notesTableView.notesList[0])
self.selectNullTableRow()
} else {
editArea.clear()
}
}

Expand All @@ -150,7 +151,21 @@ class ViewController: NSViewController,
if (event.keyCode == 53) {
search.becomeFirstResponder()
notesTableView.selectRowIndexes(IndexSet(), byExtendingSelection: false)
search.stringValue = ""
editArea.clear()
updateTable(filter: "")
}

super.keyUp(with: event)
}

// Focus search field shortcut (cmd-L)
override func keyDown(with event: NSEvent) {
if (event.keyCode == 37 && event.modifierFlags.contains(.command)) {
search.becomeFirstResponder()
}

super.keyDown(with: event)
}

override func controlTextDidEndEditing(_ obj: Notification) {
Expand All @@ -163,6 +178,7 @@ class ViewController: NSViewController,
}

func focusEditArea() {
editArea.isEditable = true
DispatchQueue.main.async() {
self.editArea.window?.makeFirstResponder(self.editArea)
}
Expand Down

0 comments on commit 0095fce

Please sign in to comment.