new: note of Snippet

This commit is contained in:
lollipopkit
2023-09-07 19:17:49 +08:00
parent 4bdf3694c3
commit 6e4cc8eb28
15 changed files with 80 additions and 19 deletions

View File

@@ -890,6 +890,12 @@ abstract class S {
/// **'Not selected'** /// **'Not selected'**
String get notSelected; String get notSelected;
/// No description provided for @note.
///
/// In en, this message translates to:
/// **'Note'**
String get note;
/// No description provided for @nullToken. /// No description provided for @nullToken.
/// ///
/// In en, this message translates to: /// In en, this message translates to:

View File

@@ -420,6 +420,9 @@ class SDe extends S {
@override @override
String get notSelected => 'Nicht ausgewählt'; String get notSelected => 'Nicht ausgewählt';
@override
String get note => 'Hinweis';
@override @override
String get nullToken => 'Null token'; String get nullToken => 'Null token';

View File

@@ -420,6 +420,9 @@ class SEn extends S {
@override @override
String get notSelected => 'Not selected'; String get notSelected => 'Not selected';
@override
String get note => 'Note';
@override @override
String get nullToken => 'Null token'; String get nullToken => 'Null token';

View File

@@ -420,6 +420,9 @@ class SId extends S {
@override @override
String get notSelected => 'Tidak terpilih'; String get notSelected => 'Tidak terpilih';
@override
String get note => 'Catatan';
@override @override
String get nullToken => 'Token NULL'; String get nullToken => 'Token NULL';

View File

@@ -420,6 +420,9 @@ class SZh extends S {
@override @override
String get notSelected => '未选择'; String get notSelected => '未选择';
@override
String get note => '备注';
@override @override
String get nullToken => '无Token'; String get nullToken => '无Token';
@@ -1149,6 +1152,9 @@ class SZhTw extends SZh {
@override @override
String get notSelected => '未選擇'; String get notSelected => '未選擇';
@override
String get note => '備註';
@override @override
String get nullToken => '無Token'; String get nullToken => '無Token';

View File

@@ -12,18 +12,28 @@ class Snippet implements TagPickable {
final String script; final String script;
@HiveField(2) @HiveField(2)
final List<String>? tags; final List<String>? tags;
const Snippet(this.name, this.script, this.tags); @HiveField(3)
final String? note;
const Snippet({
required this.name,
required this.script,
this.tags,
this.note,
});
Snippet.fromJson(Map<String, dynamic> json) Snippet.fromJson(Map<String, dynamic> json)
: name = json['name'].toString(), : name = json['name'].toString(),
script = json['script'].toString(), script = json['script'].toString(),
tags = json['tags']?.cast<String>(); tags = json['tags']?.cast<String>(),
note = json['note']?.toString();
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final data = <String, dynamic>{}; final data = <String, dynamic>{};
data['name'] = name; data['name'] = name;
data['script'] = script; data['script'] = script;
data['tags'] = tags; data['tags'] = tags;
data['note'] = note;
return data; return data;
} }
@@ -38,7 +48,9 @@ class Snippet implements TagPickable {
/// Snippet for installing ServerBoxMonitor /// Snippet for installing ServerBoxMonitor
const installSBM = Snippet( const installSBM = Snippet(
'Install ServerBoxMonitor', name: 'Install ServerBoxMonitor',
'curl -fsSL https://raw.githubusercontent.com/lollipopkit/server_box_monitor/main/install.sh | sh -s -- install', script:
null, 'curl -fsSL https://raw.githubusercontent.com/lollipopkit/server_box_monitor/main/install.sh | sh -s -- install',
tags: ['ServerBoxMonitor'],
note: 'One click script to install ServerBoxMonitor',
); );

View File

@@ -17,22 +17,25 @@ class SnippetAdapter extends TypeAdapter<Snippet> {
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
}; };
return Snippet( return Snippet(
fields[0] as String, name: fields[0] as String,
fields[1] as String, script: fields[1] as String,
(fields[2] as List?)?.cast<String>(), tags: (fields[2] as List?)?.cast<String>(),
note: fields[3] as String?,
); );
} }
@override @override
void write(BinaryWriter writer, Snippet obj) { void write(BinaryWriter writer, Snippet obj) {
writer writer
..writeByte(3) ..writeByte(4)
..writeByte(0) ..writeByte(0)
..write(obj.name) ..write(obj.name)
..writeByte(1) ..writeByte(1)
..write(obj.script) ..write(obj.script)
..writeByte(2) ..writeByte(2)
..write(obj.tags); ..write(obj.tags)
..writeByte(3)
..write(obj.note);
} }
@override @override

View File

@@ -27,6 +27,7 @@ class SettingStore extends PersistentStore {
'timeOut', 'timeOut',
5, 5,
); );
/// Duration of [timeout] /// Duration of [timeout]
Duration get timeoutD => Duration(seconds: timeout.fetch()); Duration get timeoutD => Duration(seconds: timeout.fetch());

View File

@@ -132,6 +132,7 @@
"noTask": "Nicht fragen", "noTask": "Nicht fragen",
"noUpdateAvailable": "Kein Update verfügbar", "noUpdateAvailable": "Kein Update verfügbar",
"notSelected": "Nicht ausgewählt", "notSelected": "Nicht ausgewählt",
"note": "Hinweis",
"nullToken": "Null token", "nullToken": "Null token",
"ok": "OK", "ok": "OK",
"onServerDetailPage": "in Detailansicht des Servers", "onServerDetailPage": "in Detailansicht des Servers",

View File

@@ -132,6 +132,7 @@
"noTask": "No task", "noTask": "No task",
"noUpdateAvailable": "No update available", "noUpdateAvailable": "No update available",
"notSelected": "Not selected", "notSelected": "Not selected",
"note": "Note",
"nullToken": "Null token", "nullToken": "Null token",
"ok": "OK", "ok": "OK",
"onServerDetailPage": "On server detail page", "onServerDetailPage": "On server detail page",

View File

@@ -132,6 +132,7 @@
"noTask": "Tidak bertanya", "noTask": "Tidak bertanya",
"noUpdateAvailable": "Tidak ada pembaruan yang tersedia", "noUpdateAvailable": "Tidak ada pembaruan yang tersedia",
"notSelected": "Tidak terpilih", "notSelected": "Tidak terpilih",
"note": "Catatan",
"nullToken": "Token NULL", "nullToken": "Token NULL",
"ok": "OKE", "ok": "OKE",
"onServerDetailPage": "Di halaman detail server", "onServerDetailPage": "Di halaman detail server",

View File

@@ -132,6 +132,7 @@
"noTask": "没有任务", "noTask": "没有任务",
"noUpdateAvailable": "没有可用更新", "noUpdateAvailable": "没有可用更新",
"notSelected": "未选择", "notSelected": "未选择",
"note": "备注",
"nullToken": "无Token", "nullToken": "无Token",
"ok": "好", "ok": "好",
"onServerDetailPage": "在服务器详情页", "onServerDetailPage": "在服务器详情页",

View File

@@ -132,6 +132,7 @@
"noTask": "沒有任務", "noTask": "沒有任務",
"noUpdateAvailable": "沒有可用更新", "noUpdateAvailable": "沒有可用更新",
"notSelected": "未選擇", "notSelected": "未選擇",
"note": "備註",
"nullToken": "無Token", "nullToken": "無Token",
"ok": "好", "ok": "好",
"onServerDetailPage": "在服務器詳情頁", "onServerDetailPage": "在服務器詳情頁",

View File

@@ -25,6 +25,7 @@ class _SnippetEditPageState extends State<SnippetEditPage>
with AfterLayoutMixin { with AfterLayoutMixin {
final _nameController = TextEditingController(); final _nameController = TextEditingController();
final _scriptController = TextEditingController(); final _scriptController = TextEditingController();
final _noteController = TextEditingController();
final _scriptNode = FocusNode(); final _scriptNode = FocusNode();
late SnippetProvider _provider; late SnippetProvider _provider;
@@ -91,7 +92,13 @@ class _SnippetEditPageState extends State<SnippetEditPage>
showSnackBar(context, Text(_s.fieldMustNotEmpty)); showSnackBar(context, Text(_s.fieldMustNotEmpty));
return; return;
} }
final snippet = Snippet(name, script, _tags); final note = _noteController.text;
final snippet = Snippet(
name: name,
script: script,
tags: _tags.isEmpty ? null : _tags,
note: note.isEmpty ? null : note,
);
if (widget.snippet != null) { if (widget.snippet != null) {
_provider.update(widget.snippet!, snippet); _provider.update(widget.snippet!, snippet);
} else { } else {
@@ -115,13 +122,12 @@ class _SnippetEditPageState extends State<SnippetEditPage>
icon: Icons.info, icon: Icons.info,
), ),
Input( Input(
controller: _scriptController, controller: _noteController,
node: _scriptNode,
minLines: 3, minLines: 3,
maxLines: 10, maxLines: 3,
type: TextInputType.multiline, type: TextInputType.multiline,
label: _s.snippet, label: _s.note,
icon: Icons.code, icon: Icons.note,
), ),
TagEditor( TagEditor(
tags: _tags, tags: _tags,
@@ -133,7 +139,16 @@ class _SnippetEditPageState extends State<SnippetEditPage>
onRenameTag: (old, n) => setState(() { onRenameTag: (old, n) => setState(() {
_provider.renameTag(old, n); _provider.renameTag(old, n);
}), }),
) ),
Input(
controller: _scriptController,
node: _scriptNode,
minLines: 3,
maxLines: 10,
type: TextInputType.multiline,
label: _s.snippet,
icon: Icons.code,
),
], ],
); );
} }
@@ -143,6 +158,10 @@ class _SnippetEditPageState extends State<SnippetEditPage>
if (widget.snippet != null) { if (widget.snippet != null) {
_nameController.text = widget.snippet!.name; _nameController.text = widget.snippet!.name;
_scriptController.text = widget.snippet!.script; _scriptController.text = widget.snippet!.script;
if (widget.snippet!.note != null) {
_noteController.text = widget.snippet!.note!;
}
if (widget.snippet!.tags != null) { if (widget.snippet!.tags != null) {
_tags = widget.snippet!.tags!; _tags = widget.snippet!.tags!;
setState(() {}); setState(() {});

View File

@@ -108,9 +108,9 @@ class _SnippetListPageState extends State<SnippetListPage> {
maxLines: 1, maxLines: 1,
), ),
subtitle: Text( subtitle: Text(
snippet.script, snippet.note ?? snippet.script,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
maxLines: 1, maxLines: 3,
style: grey, style: grey,
), ),
trailing: Row( trailing: Row(