Skip to content

Commit

Permalink
new: pick dialog support tags
Browse files Browse the repository at this point in the history
  • Loading branch information
lollipopkit committed Feb 20, 2024
1 parent 1a64dc5 commit ba564a8
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 40 deletions.
36 changes: 18 additions & 18 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CURRENT_PROJECT_VERSION = 770;
CURRENT_PROJECT_VERSION = 771;
DEVELOPMENT_TEAM = BA88US33G6;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = "Runner/Info-$(CONFIGURATION).plist";
Expand All @@ -596,7 +596,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0.770;
MARKETING_VERSION = 1.0.771;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
Expand Down Expand Up @@ -720,7 +720,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CURRENT_PROJECT_VERSION = 770;
CURRENT_PROJECT_VERSION = 771;
DEVELOPMENT_TEAM = BA88US33G6;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = "Runner/Info-$(CONFIGURATION).plist";
Expand All @@ -730,7 +730,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0.770;
MARKETING_VERSION = 1.0.771;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
Expand All @@ -748,7 +748,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CURRENT_PROJECT_VERSION = 770;
CURRENT_PROJECT_VERSION = 771;
DEVELOPMENT_TEAM = BA88US33G6;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = "Runner/Info-$(CONFIGURATION).plist";
Expand All @@ -758,7 +758,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0.770;
MARKETING_VERSION = 1.0.771;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
Expand All @@ -779,7 +779,7 @@
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 770;
CURRENT_PROJECT_VERSION = 771;
DEVELOPMENT_TEAM = BA88US33G6;
GCC_C_LANGUAGE_STANDARD = gnu11;
GENERATE_INFOPLIST_FILE = YES;
Expand All @@ -792,7 +792,7 @@
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
MARKETING_VERSION = 1.0.770;
MARKETING_VERSION = 1.0.771;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox.StatusWidget;
Expand All @@ -818,7 +818,7 @@
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 770;
CURRENT_PROJECT_VERSION = 771;
DEVELOPMENT_TEAM = BA88US33G6;
GCC_C_LANGUAGE_STANDARD = gnu11;
GENERATE_INFOPLIST_FILE = YES;
Expand All @@ -831,7 +831,7 @@
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
MARKETING_VERSION = 1.0.770;
MARKETING_VERSION = 1.0.771;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox.StatusWidget;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -854,7 +854,7 @@
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 770;
CURRENT_PROJECT_VERSION = 771;
DEVELOPMENT_TEAM = BA88US33G6;
GCC_C_LANGUAGE_STANDARD = gnu11;
GENERATE_INFOPLIST_FILE = YES;
Expand All @@ -867,7 +867,7 @@
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
MARKETING_VERSION = 1.0.770;
MARKETING_VERSION = 1.0.771;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox.StatusWidget;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -890,7 +890,7 @@
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 770;
CURRENT_PROJECT_VERSION = 771;
DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = BA88US33G6;
ENABLE_PREVIEWS = YES;
Expand All @@ -902,7 +902,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0.770;
MARKETING_VERSION = 1.0.771;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox.WatchEnd;
Expand Down Expand Up @@ -931,7 +931,7 @@
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 770;
CURRENT_PROJECT_VERSION = 771;
DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = BA88US33G6;
ENABLE_PREVIEWS = YES;
Expand All @@ -943,7 +943,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0.770;
MARKETING_VERSION = 1.0.771;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox.WatchEnd;
PRODUCT_NAME = ServerBox;
Expand All @@ -969,7 +969,7 @@
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 770;
CURRENT_PROJECT_VERSION = 771;
DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = BA88US33G6;
ENABLE_PREVIEWS = YES;
Expand All @@ -981,7 +981,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0.770;
MARKETING_VERSION = 1.0.771;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox.WatchEnd;
PRODUCT_NAME = ServerBox;
Expand Down
74 changes: 74 additions & 0 deletions lib/core/extension/context/dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'package:toolbox/core/extension/context/common.dart';
import 'package:toolbox/core/extension/context/locale.dart';
import 'package:toolbox/view/widget/choice_chip.dart';
import 'package:toolbox/view/widget/tag.dart';

import '../../../data/res/ui.dart';
import '../../../view/widget/input_field.dart';
Expand Down Expand Up @@ -119,4 +120,77 @@ extension DialogX on BuildContext {
}
return null;
}

Future<List<T>?> showPickWithTagDialog<T>({
required List<T?> Function(String? tag) itemsBuilder,
required ValueNotifier<List<String>> tags,
String Function(T)? name,
List<T>? initial,
bool clearable = false,
bool multi = false,
List<Widget>? actions,
}) async {
var vals = initial ?? <T>[];
final tag = ValueNotifier<String?>(null);
final sure = await showRoundDialog<bool>(
title: Text(l10n.choose),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ListenableBuilder(
listenable: tag,
builder: (_, __) => TagSwitcher(
tags: tags,
width: 300,
initTag: tag.value,
onTagChanged: (e) => tag.value = e,
),
),
const Divider(),
SingleChildScrollView(
child: ValueListenableBuilder(
valueListenable: tag,
builder: (_, val, __) {
final items = itemsBuilder(val);
return Choice<T>(
onChanged: (value) => vals = value,
multiple: multi,
clearable: clearable,
value: vals,
builder: (state, _) {
return Wrap(
children: List<Widget>.generate(
items.length,
(index) {
final item = items[index];
if (item == null) return UIs.placeholder;
return ChoiceChipX<T>(
label: name?.call(item) ?? item.toString(),
state: state,
value: item,
);
},
),
);
},
);
},
),
)
],
),
actions: [
if (actions != null) ...actions,
TextButton(
onPressed: () => pop(true),
child: Text(l10n.ok),
),
],
);
if (sure == true && vals.isNotEmpty) {
return vals;
}
return null;
}
}
6 changes: 3 additions & 3 deletions lib/data/res/build_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

class BuildData {
static const String name = "ServerBox";
static const int build = 770;
static const int build = 771;
static const String engine = "3.19.0";
static const String buildAt = "2024-02-20 15:34:30";
static const int modifications = 10;
static const String buildAt = "2024-02-20 16:12:21";
static const int modifications = 8;
static const int script = 38;
}
1 change: 0 additions & 1 deletion lib/view/page/server/tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ class _ServerPageState extends State<ServerPage>
_tag = p0;
}),
initTag: _tag,
all: l10n.all,
);
}

Expand Down
1 change: 0 additions & 1 deletion lib/view/page/snippet/list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ class _SnippetListPageState extends State<SnippetListPage> {
tags: provider.tags,
onTagChanged: (tag) => setState(() => _tag = tag),
initTag: _tag,
all: l10n.all,
width: _media.size.width,
),
footer: UIs.height77,
Expand Down
18 changes: 13 additions & 5 deletions lib/view/page/ssh/page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,20 @@ class _SSHPageState extends State<SSHPage> with AutomaticKeepAliveClientMixin {
}
break;
case VirtualKeyFunc.snippet:
final s = await context.showPickSingleDialog<Snippet>(
items: Pros.snippet.snippets,
name: (p0) => p0.name,
final snippets = await context.showPickWithTagDialog<Snippet>(
tags: Pros.snippet.tags,
itemsBuilder: (e) {
if (e == null) return Pros.snippet.snippets;
return Pros.snippet.snippets
.where((element) => element.tags?.contains(e) ?? false)
.toList();
},
name: (e) => e.name,
);
if (s == null) return;
_terminal.textInput(s.script);
if (snippets == null || snippets.isEmpty) return;

final snippet = snippets.first;
_terminal.textInput(snippet.script);
_terminal.keyInput(TerminalKey.enter);
break;
case VirtualKeyFunc.file:
Expand Down
13 changes: 10 additions & 3 deletions lib/view/widget/server_func_btns.dart
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,18 @@ void _onTapMoreBtns(
);
break;
case ServerFuncBtn.snippet:
final snippet = await context.showPickSingleDialog<Snippet>(
items: Pros.snippet.snippets,
final snippets = await context.showPickWithTagDialog<Snippet>(
tags: Pros.snippet.tags,
itemsBuilder: (e) {
if (e == null) return Pros.snippet.snippets;
return Pros.snippet.snippets
.where((element) => element.tags?.contains(e) ?? false)
.toList();
},
name: (e) => e.name,
);
if (snippet == null) return;
if (snippets == null || snippets.isEmpty) return;
final snippet = snippets.first;

AppRoute.ssh(spi: spi, initCmd: snippet.fmtWith(spi)).checkGo(
context: context,
Expand Down
4 changes: 1 addition & 3 deletions lib/view/widget/tag.dart
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,12 @@ class TagSwitcher extends StatelessWidget implements PreferredSizeWidget {
final double width;
final void Function(String?) onTagChanged;
final String? initTag;
final String all;

const TagSwitcher({
super.key,
required this.tags,
required this.width,
required this.onTagChanged,
required this.all,
this.initTag,
});

Expand All @@ -213,7 +211,7 @@ class TagSwitcher extends StatelessWidget implements PreferredSizeWidget {
itemBuilder: (context, index) {
final item = items[index];
return TagBtn(
content: item == null ? all : '#$item',
content: item == null ? l10n.all : '#$item',
isEnable: initTag == item,
onTap: () => onTagChanged(item),
);
Expand Down
Loading

0 comments on commit ba564a8

Please sign in to comment.