Skip to content

Commit

Permalink
- Fixes pins/unpins
Browse files Browse the repository at this point in the history
- Fixles i18n
  • Loading branch information
glushchenko committed May 26, 2024
1 parent 16f753a commit 1dc77b8
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 14 deletions.
2 changes: 1 addition & 1 deletion FSNotes iOS/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -7308,7 +7308,7 @@
"ru" : {
"stringUnit" : {
"state" : "translated",
"value" : "Туду"
"value" : "Задачи"
}
},
"uk" : {
Expand Down
8 changes: 4 additions & 4 deletions FSNotes.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -4556,7 +4556,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 622;
CURRENT_PROJECT_VERSION = 623;
DEVELOPMENT_TEAM = 866P6MTE92;
EMBED_ASSET_PACKS_IN_PRODUCT_BUNDLE = YES;
ENABLE_HARDENED_RUNTIME = YES;
Expand All @@ -4573,7 +4573,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.14;
MARKETING_VERSION = 6.7.2;
MARKETING_VERSION = 6.7.3;
OTHER_SWIFT_FLAGS = "$(inherited)";
PRODUCT_BUNDLE_IDENTIFIER = co.fluder.FSNotes;
PRODUCT_NAME = FSNotes;
Expand All @@ -4596,7 +4596,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 622;
CURRENT_PROJECT_VERSION = 623;
DEPLOYMENT_LOCATION = NO;
DEVELOPMENT_TEAM = 866P6MTE92;
EMBED_ASSET_PACKS_IN_PRODUCT_BUNDLE = YES;
Expand All @@ -4614,7 +4614,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.14;
MARKETING_VERSION = 6.7.2;
MARKETING_VERSION = 6.7.3;
ONLY_ACTIVE_ARCH = YES;
PRODUCT_BUNDLE_IDENTIFIER = co.fluder.FSNotes;
PRODUCT_NAME = FSNotes;
Expand Down
2 changes: 1 addition & 1 deletion FSNotes/Business/Markdown.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func renderSoulverCodeBlocks(markdown: String) -> String {
func generateAlphabeticalString(length: Int) -> String {
let alphabet = "abcdefghijklmnopqrstuvwxyz"
var result = "@"
var length = length - 2
let length = length - 2

for _ in 0..<length {
let randomIndex = Int.random(in: 0..<alphabet.count)
Expand Down
4 changes: 4 additions & 0 deletions FSNotes/Business/Note.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2189,4 +2189,8 @@ public class Note: NSObject {
public func getContentOffset() -> CGPoint {
return contentOffset
}

public func getRelatedPath() -> String {
return project.getNestedPath() + "/" + name
}
}
25 changes: 25 additions & 0 deletions FSNotes/Business/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -994,4 +994,29 @@ public class Project: Equatable {
note.load()
}
}

public func getNestedPath() -> String {
var project: Project? = self
var result = String()

while project != nil {
if project?.parent == nil {
return result
}

if let unwrappedProject = project {
if result.count > 0 {
result = unwrappedProject.label + "/" + result
} else {
result = unwrappedProject.label
}

project = unwrappedProject.parent
} else {
project = nil
}
}

return result
}
}
24 changes: 17 additions & 7 deletions FSNotes/Business/Storage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,17 @@ class Storage {
$0.title.lowercased().starts(with: startWith.lowercased())
}
}


func getByUrl(endsWith: String) -> Note? {
for note in noteList {
if note.url.path.hasSuffix(endsWith) {
return note
}
}

return nil
}

func getBy(contains: String) -> [Note]? {
return
noteList.filter{
Expand Down Expand Up @@ -833,7 +843,7 @@ class Storage {
if let pinned = getPinned() {
var names = [String]()
for note in pinned {
names.append(note.name)
names.append(note.getRelatedPath())
}

let keyStore = NSUbiquitousKeyValueStore()
Expand All @@ -856,7 +866,7 @@ class Storage {
else { return }

for note in notes {
if names.contains(note.name) {
if names.contains(note.getRelatedPath()) {
note.addPin(cloudSave: false)
success.append(note)
}
Expand All @@ -876,15 +886,15 @@ class Storage {
if let names = keyStore.array(forKey: "co.fluder.fsnotes.pins.shared") as? [String] {
if let pinned = getPinned() {
for note in pinned {
if !names.contains(note.name) {
if !names.contains(note.getRelatedPath()) {
note.removePin(cloudSave: false)
removed.append(note)
}
}
}

for name in names {
if let note = getBy(name: name), !note.isPinned {
if let note = getByUrl(endsWith: name), !note.isPinned {
note.addPin(cloudSave: false)
added.append(note)
}
Expand All @@ -905,14 +915,14 @@ class Storage {
if let names = keyStore.array(forKey: "co.fluder.fsnotes.pins.shared") as? [String] {
if let pinned = getPinned() {
for note in pinned {
if !names.contains(note.name) {
if !names.contains(note.getRelatedPath()) {
notes.append(note)
}
}
}

for name in names {
if let note = getBy(name: name), !note.isPinned {
if let note = getByUrl(endsWith: name), !note.isPinned {
notes.append(note)
}
}
Expand Down
1 change: 0 additions & 1 deletion FSNotes/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1810,7 +1810,6 @@ class ViewController: EditorViewController,
if let keys = notification.userInfo?[NSUbiquitousKeyValueStoreChangedKeysKey] as? [String] {
for key in keys {
if key == "co.fluder.fsnotes.pins.shared" {

let changedNotes = storage.getUpdatedPins()

DispatchQueue.main.async {
Expand Down

0 comments on commit 1dc77b8

Please sign in to comment.