Skip to content

Commit

Permalink
sort address book name dropdown (rustdesk#8127)
Browse files Browse the repository at this point in the history
Signed-off-by: 21pages <[email protected]>
  • Loading branch information
21pages authored May 23, 2024
1 parent b8d9c4c commit 7da09f6
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 21 deletions.
56 changes: 36 additions & 20 deletions flutter/lib/common/widgets/address_book.dart
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,40 @@ class _AddressBookState extends State<AddressBook> {
if (!names.contains(gFFI.abModel.currentName.value)) {
return Offstage();
}
// order: personal, divider, character order
// https://pub.dev/packages/dropdown_button2#3-dropdownbutton2-with-items-of-different-heights-like-dividers
final personalAddressBookName = gFFI.abModel.personalAddressBookName();
bool contains = names.remove(personalAddressBookName);
names.sort((a, b) => a.toLowerCase().compareTo(b.toLowerCase()));
if (contains) {
names.insert(0, personalAddressBookName);
}
final items = names
.map((e) => DropdownMenuItem(
value: e,
child: Row(
children: [
Expanded(
child: Tooltip(
waitDuration: Duration(milliseconds: 500),
message: gFFI.abModel.translatedName(e),
child: Text(
gFFI.abModel.translatedName(e),
style: TextStyle(fontSize: 14.0),
maxLines: 1,
overflow: TextOverflow.ellipsis,
)),
),
],
)))
.toList();
var menuItemStyleData = MenuItemStyleData(height: 36);
if (contains && items.length > 1) {
items.insert(1, DropdownMenuItem(enabled: false, child: Divider()));
List<double> customHeights = List.filled(items.length, 36);
customHeights[1] = 4;
menuItemStyleData = MenuItemStyleData(customHeights: customHeights);
}
final TextEditingController textEditingController = TextEditingController();

final isOptFixed = isOptionFixed(kOptionCurrentAbName);
Expand All @@ -208,26 +242,8 @@ class _AddressBookState extends State<AddressBook> {
color: Theme.of(context).dividerColor.withOpacity(0.1),
),
buttonStyleData: ButtonStyleData(height: 48),
menuItemStyleData: MenuItemStyleData(height: 36),
items: names
.map((e) => DropdownMenuItem(
value: e,
child: Row(
children: [
Expanded(
child: Tooltip(
waitDuration: Duration(milliseconds: 500),
message: gFFI.abModel.translatedName(e),
child: Text(
gFFI.abModel.translatedName(e),
style: TextStyle(fontSize: 14.0),
maxLines: 1,
overflow: TextOverflow.ellipsis,
)),
),
],
)))
.toList(),
menuItemStyleData: menuItemStyleData,
items: items,
isExpanded: true,
dropdownSearchData: DropdownSearchData(
searchController: textEditingController,
Expand Down
7 changes: 6 additions & 1 deletion flutter/lib/models/ab_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,8 @@ class AbModel {
}

void setShouldAsync(bool v) async {
await bind.mainSetLocalOption(key: syncAbOption, value: v ? 'Y' : defaultOptionNo);
await bind.mainSetLocalOption(
key: syncAbOption, value: v ? 'Y' : defaultOptionNo);
_syncAllFromRecent = true;
_timerCounter = 0;
}
Expand Down Expand Up @@ -648,6 +649,10 @@ class AbModel {
return addressbooks.keys.toList();
}

String personalAddressBookName() {
return _personalAddressBookName;
}

Future<void> setCurrentName(String name) async {
final oldName = _currentName.value;
if (addressbooks.containsKey(name)) {
Expand Down

0 comments on commit 7da09f6

Please sign in to comment.