Skip to content

Commit 26addb4

Browse files
authored
im config: no floating; color of -; no async; fix rename group (#243)
1 parent f7e4cc7 commit 26addb4

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

src/config/inputmethod.swift

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ class InputMethodConfigController: ConfigWindowController {
1414
window.center()
1515
self.init(window: window)
1616
window.contentView = NSHostingView(rootView: view)
17-
window.level = .floating
1817
window.titlebarAppearsTransparent = true
1918
attachToolbar(window)
2019
}
@@ -73,7 +72,7 @@ struct InputMethodConfigView: View {
7372

7473
Button {
7574
renameGroupDialog.show { input in
76-
viewModel.renameGroup(&group, input)
75+
viewModel.renameGroup(group, input)
7776
}
7877
} label: {
7978
Image(systemName: "pencil")
@@ -82,6 +81,7 @@ struct InputMethodConfigView: View {
8281
.foregroundColor(.secondary)
8382
.help(NSLocalizedString("Rename", comment: "") + " '\(group.name)'")
8483
}
84+
// Make right-click available in the whole line.
8585
.frame(maxWidth: .infinity, alignment: .leading)
8686
.contentShape(Rectangle())
8787
.contextMenu {
@@ -98,6 +98,8 @@ struct InputMethodConfigView: View {
9898
viewModel.removeItem(group.name, inputMethod.id)
9999
} label: {
100100
Image(systemName: "minus")
101+
// When system is dark and im is not selected, hover color is black by default which is hardly visible.
102+
.foregroundColor(.primary)
101103
.frame(maxHeight: .infinity)
102104
.contentShape(Rectangle())
103105
}
@@ -330,39 +332,40 @@ struct InputMethodConfigView: View {
330332
self.save()
331333
}
332334

333-
func renameGroup(_ group: inout Group, _ name: String) {
334-
if name == "" {
335+
func renameGroup(_ group: Group, _ name: String) {
336+
if name == "" || groups.contains(where: { $0.name == name }) {
335337
return
336338
}
337-
group.name = name
339+
for i in 0..<self.groups.count {
340+
if self.groups[i].name == group.name {
341+
self.groups[i].name = name
342+
break
343+
}
344+
}
338345
save()
339346
}
340347

341348
func removeItem(_ groupName: String, _ uuid: UUID) {
342-
DispatchQueue.main.async {
343-
for i in 0..<self.groups.count {
344-
if self.groups[i].name == groupName {
345-
self.groups[i].inputMethods.removeAll(where: { $0.id == uuid })
346-
break
347-
}
349+
for i in 0..<self.groups.count {
350+
if self.groups[i].name == groupName {
351+
self.groups[i].inputMethods.removeAll(where: { $0.id == uuid })
352+
break
348353
}
349-
self.save()
350354
}
355+
self.save()
351356
}
352357

353358
func addItems(_ groupName: String, _ ims: Set<InputMethod>) {
354-
DispatchQueue.main.async {
355-
for i in 0..<self.groups.count {
356-
if self.groups[i].name == groupName {
357-
for im in ims {
358-
let item = GroupItem(name: im.uniqueName, displayName: im.displayName)
359-
self.groups[i].inputMethods.append(item)
360-
self.uuidToIM[item.id] = item.name
361-
}
359+
for i in 0..<self.groups.count {
360+
if self.groups[i].name == groupName {
361+
for im in ims {
362+
let item = GroupItem(name: im.uniqueName, displayName: im.displayName)
363+
self.groups[i].inputMethods.append(item)
364+
self.uuidToIM[item.id] = item.name
362365
}
363366
}
364-
self.save()
365367
}
368+
self.save()
366369
}
367370
}
368371
}

0 commit comments

Comments
 (0)