Skip to content

Commit

Permalink
Merge pull request #808 from frg2089/feat/nav
Browse files Browse the repository at this point in the history
Windows 支持更新
  • Loading branch information
Notsfsssf authored Oct 11, 2024
2 parents 33d68c6 + 12e7b01 commit b2e8313
Show file tree
Hide file tree
Showing 17 changed files with 741 additions and 660 deletions.
36 changes: 19 additions & 17 deletions lib/er/fluent_leader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:bot_toast/bot_toast.dart';
import 'package:dio/dio.dart';
import 'package:fluent_ui/fluent_ui.dart';
import 'package:pixez/er/lprinter.dart';
import 'package:pixez/fluent/navigation/pixez_page_history_manager.dart';
import 'package:pixez/fluent/page/hello/fluent_hello_page.dart';
import 'package:pixez/fluent/page/hello/setting/save_eval_page.dart';
import 'package:pixez/fluent/page/picture/illust_lighting_page.dart';
Expand Down Expand Up @@ -144,9 +145,12 @@ class FluentLeader {
} else if (link.host.contains("novel")) {
try {
int id = int.parse(link.pathSegments.last);
Navigator.of(context).push(PixEzPageRoute(builder: (context) {
return NovelViewerPage(id: id);
}));
FluentLeader.push(
context,
NovelViewerPage(id: id),
title: Text(I18n.of(context).novel + ': ${id}'),
icon: Icon(FluentIcons.book_answers),
);
return;
} catch (e) {
LPrinter.d(e);
Expand Down Expand Up @@ -210,12 +214,15 @@ class FluentLeader {
icon: Icon(FluentIcons.account_browser),
);
else
Navigator.of(context).push(PixEzPageRoute(builder: (context) {
return NovelViewerPage(
FluentLeader.push(
context,
NovelViewerPage(
id: int.parse(id!),
novelStore: null,
);
}));
),
title: Text(I18n.of(context).novel + ': ${id}'),
icon: Icon(FluentIcons.book_answers),
);
return;
} catch (e) {}
}
Expand Down Expand Up @@ -284,21 +291,16 @@ class FluentLeader {
padding: EdgeInsets.all(0.0),
);

var state = context.findAncestorStateOfType<FluentHelloPageState>();
if (state == null) state = FluentHelloPageState.state;
assert(state != null);
if (icon == null || title == null) {
debugPrint('icon: $icon');
debugPrint('title: $title');
debugPrintStack();
}
return state!.push(
context,
PixEzPageRoute(
builder: (_) => _final,
icon: icon ?? const Icon(FluentIcons.unknown),
title: title ?? Text(I18n.of(context).undefined),
),

return PixEzPageHistoryManager.pushRoute(
page: _final,
icon: icon ?? const Icon(FluentIcons.unknown),
title: title ?? Text(I18n.of(context).undefined),
);
}
}
37 changes: 37 additions & 0 deletions lib/fluent/component/pixez_global_shortkey_listener.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import 'package:fluent_ui/fluent_ui.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/services.dart';

class PixEzGlobalShortkeyListener extends StatelessWidget {
final Widget child;
final Function() goBack;

const PixEzGlobalShortkeyListener({
super.key,
required this.child,
required this.goBack,
});

@override
Widget build(BuildContext context) {
return KeyboardListener(
focusNode: FocusNode(),
autofocus: true,
child: Listener(
child: child,
onPointerDown: (event) {
// 鼠标的后退按钮
if (event.buttons == kBackMouseButton &&
event.kind == PointerDeviceKind.mouse) goBack();
},
),
onKeyEvent: (value) {
if (value is KeyUpEvent) {
// 键盘的 Alt + 左箭头
if (HardwareKeyboard.instance.isAltPressed &&
value.logicalKey == LogicalKeyboardKey.arrowLeft) goBack();
}
},
);
}
}
213 changes: 213 additions & 0 deletions lib/fluent/component/search_box/item.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
part of 'pixez_search_box.dart';

enum _PixEzSearchBoxItemType {
normal,
history,
tag,
illustId,
painterId,
pixivisionId,
cleanHistory,
}

class _PixEzSearchBoxItem {
final _PixEzSearchBoxItemType type;
final String? word;
final String? translated;
final int? id;

const _PixEzSearchBoxItem({
this.type = _PixEzSearchBoxItemType.normal,
this.word = null,
this.translated = null,
this.id = null,
});
}

class _PixEzSearchItem {
static Widget _buildTagImage(BuildContext context, TrendTags tags) {
return PixEzButton(
noPadding: true,
child: PixivImage(
tags.illust.imageUrls.squareMedium,
fit: BoxFit.cover,
height: 26,
),
onPressed: () {
Leader.push(
context,
IllustLightingPage(id: tags.illust.id),
icon: Icon(FluentIcons.picture),
title: Text(
I18n.of(context).illust_id + ': ${tags.illust.id}',
),
);
},
);
}

static AutoSuggestBoxItem<_PixEzSearchBoxItem> _buildItem({
required BuildContext context,
required String title,
required _PixEzSearchBoxItem value,
String? subtitle = null,
Widget? leading = null,
Widget? trailing = null,
void Function()? onSelected,
bool reverse = false,
}) {
var text = [
TextSpan(
text: title,
style: FluentTheme.of(context).typography.body?.copyWith(
color: FluentTheme.of(context).accentColor,
),
),
TextSpan(
text: ' ',
style: null,
),
TextSpan(
text: subtitle,
style: null,
)
];

if (reverse && subtitle != null) text = text.reversed.toList();

return AutoSuggestBoxItem<_PixEzSearchBoxItem>(
child: Row(
children: [
if (leading != null)
Padding(
padding: EdgeInsets.only(right: 4.0),
child: leading,
),
Expanded(
child: Tooltip(
richMessage: TextSpan(
children: text,
),
child: Text.rich(
TextSpan(
children: text,
),
overflow: TextOverflow.ellipsis,
),
),
),
if (trailing != null)
Padding(
padding: EdgeInsets.only(left: 4.0),
child: trailing,
),
],
),
label: "$title $subtitle",
value: value,
onSelected: onSelected,
);
}

/// 清空历史记录
static AutoSuggestBoxItem<_PixEzSearchBoxItem> cleanHistoryItem(
BuildContext context) {
return _buildItem(
context: context,
leading: Icon(FluentIcons.delete),
title: I18n.of(context).clear_search_tag_history,
value: _PixEzSearchBoxItem(type: _PixEzSearchBoxItemType.cleanHistory),
);
}

static AutoSuggestBoxItem<_PixEzSearchBoxItem> tagsPersist(
BuildContext context, TagsPersist tags, void Function() refresh) {
final item = _buildItem(
context: context,
title: tags.name,
subtitle: tags.translatedName,
value: _PixEzSearchBoxItem(
type: _PixEzSearchBoxItemType.history,
word: tags.name,
translated: tags.translatedName,
),
trailing: PixEzButton(
child: Icon(FluentIcons.chrome_close),
onPressed: () {
if (tags.id != null) tagHistoryStore.delete(tags.id!);
refresh();
},
),
);
return item;
}

static AutoSuggestBoxItem<_PixEzSearchBoxItem> trendTags(
BuildContext context, TrendTags tags) {
return _buildItem(
context: context,
title: "#${tags.tag}",
subtitle: tags.translatedName != null ? "#${tags.translatedName}" : null,
leading: _buildTagImage(context, tags),
value: _PixEzSearchBoxItem(
word: tags.tag,
translated: tags.translatedName,
),
);
}

static AutoSuggestBoxItem<_PixEzSearchBoxItem> tags(
BuildContext context, Tags tags) {
return _buildItem(
context: context,
title: tags.name,
subtitle: tags.translated_name,
value: _PixEzSearchBoxItem(
word: tags.name,
translated: tags.translated_name,
),
);
}

static AutoSuggestBoxItem<_PixEzSearchBoxItem> illustId(
BuildContext context, int id) {
return _buildItem(
context: context,
reverse: true,
title: id.toString(),
subtitle: I18n.of(context).illust_id,
value: _PixEzSearchBoxItem(
type: _PixEzSearchBoxItemType.illustId,
id: id,
),
);
}

static AutoSuggestBoxItem<_PixEzSearchBoxItem> painterId(
BuildContext context, int id) {
return _buildItem(
context: context,
reverse: true,
title: id.toString(),
subtitle: I18n.of(context).painter_id,
value: _PixEzSearchBoxItem(
type: _PixEzSearchBoxItemType.painterId,
id: id,
),
);
}

static AutoSuggestBoxItem<_PixEzSearchBoxItem> pixivisionId(
BuildContext context, int id) {
return _buildItem(
context: context,
reverse: true,
title: id.toString(),
subtitle: 'Pixivision Id',
value: _PixEzSearchBoxItem(
type: _PixEzSearchBoxItemType.pixivisionId,
id: id,
),
);
}
}
Loading

0 comments on commit b2e8313

Please sign in to comment.