Skip to content

Commit

Permalink
#79
Browse files Browse the repository at this point in the history
  • Loading branch information
glushchenko committed Jan 11, 2018
1 parent a0d0a87 commit afe9f63
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
1 change: 1 addition & 0 deletions FSNotes/EditTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class EditTextView: NSTextView {
viewController.emptyEditAreaImage.isHidden = true

EditTextView.note = note
UserDefaultsManagement.lastSelectedURL = note.url

subviews.removeAll()
undoManager?.removeAllActions()
Expand Down
15 changes: 15 additions & 0 deletions FSNotes/Model/UserDefaultsManagement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class UserDefaultsManagement {
static let SortBy = "sortBy"
static let codeBlockHighlight = "codeBlockHighlight"
static let codeTheme = "codeTheme"
static let LastSelectedPath = "lastSelectedPath"
}

static var fontName: String {
Expand Down Expand Up @@ -405,4 +406,18 @@ public class UserDefaultsManagement {
}
}

static var lastSelectedURL: URL? {
get {
if let path = UserDefaults.standard.object(forKey: Constants.LastSelectedPath) as? String, let encodedPath = path.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) {
return URL(string: "file://" + encodedPath)
}
return nil
}
set {
if let url = newValue {
UserDefaults.standard.set(url.path, forKey: Constants.LastSelectedPath)
}
}
}

}
11 changes: 5 additions & 6 deletions FSNotes/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ class ViewController: NSViewController,

if storage.noteList.count == 0 {
storage.loadDocuments()
updateTable(filter: "") {}
updateTable(filter: "") {
if let url = UserDefaultsManagement.lastSelectedURL, let lastNote = self.storage.getBy(url: url), let i = self.notesTableView.getIndex(lastNote) {
self.notesTableView.selectRowIndexes([i], byExtendingSelection: false)
}
}
}

let font = UserDefaultsManagement.noteFont
Expand Down Expand Up @@ -759,11 +763,6 @@ class ViewController: NSViewController,
}
}

func reloadStorage() {
storage.loadDocuments()
updateTable(filter: "") {}
}

func loadMoveMenu() {
let storageItemList = CoreDataManager.instance.fetchStorageList()

Expand Down

0 comments on commit afe9f63

Please sign in to comment.