|
@@ -1,12 +1,12 @@
|
|
import 'package:appflowy/workspace/application/app/app_service.dart';
|
|
import 'package:appflowy/workspace/application/app/app_service.dart';
|
|
-import 'package:appflowy_backend/protobuf/flowy-folder/app.pb.dart';
|
|
|
|
-import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
|
|
|
|
|
|
+import 'package:appflowy_backend/protobuf/flowy-folder2/view.pb.dart';
|
|
import 'package:appflowy_editor/appflowy_editor.dart';
|
|
import 'package:appflowy_editor/appflowy_editor.dart';
|
|
import 'package:dartz/dartz.dart' as dartz;
|
|
import 'package:dartz/dartz.dart' as dartz;
|
|
import 'package:flowy_infra/image.dart';
|
|
import 'package:flowy_infra/image.dart';
|
|
import 'package:flowy_infra_ui/style_widget/button.dart';
|
|
import 'package:flowy_infra_ui/style_widget/button.dart';
|
|
import 'package:flowy_infra_ui/style_widget/text.dart';
|
|
import 'package:flowy_infra_ui/style_widget/text.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
+import 'package:flutter/services.dart';
|
|
import 'insert_page_command.dart';
|
|
import 'insert_page_command.dart';
|
|
import 'package:appflowy/generated/locale_keys.g.dart';
|
|
import 'package:appflowy/generated/locale_keys.g.dart';
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
@@ -18,7 +18,7 @@ void showLinkToPageMenu(
|
|
EditorState editorState,
|
|
EditorState editorState,
|
|
SelectionMenuService menuService,
|
|
SelectionMenuService menuService,
|
|
BuildContext context,
|
|
BuildContext context,
|
|
- ViewLayoutTypePB pageType,
|
|
|
|
|
|
+ ViewLayoutPB pageType,
|
|
) {
|
|
) {
|
|
final alignment = menuService.alignment;
|
|
final alignment = menuService.alignment;
|
|
final offset = menuService.offset;
|
|
final offset = menuService.offset;
|
|
@@ -28,10 +28,10 @@ void showLinkToPageMenu(
|
|
|
|
|
|
String hintText = '';
|
|
String hintText = '';
|
|
switch (pageType) {
|
|
switch (pageType) {
|
|
- case ViewLayoutTypePB.Grid:
|
|
|
|
|
|
+ case ViewLayoutPB.Grid:
|
|
hintText = LocaleKeys.document_slashMenu_grid_selectAGridToLinkTo.tr();
|
|
hintText = LocaleKeys.document_slashMenu_grid_selectAGridToLinkTo.tr();
|
|
break;
|
|
break;
|
|
- case ViewLayoutTypePB.Board:
|
|
|
|
|
|
+ case ViewLayoutPB.Board:
|
|
hintText = LocaleKeys.document_slashMenu_board_selectABoardToLinkTo.tr();
|
|
hintText = LocaleKeys.document_slashMenu_board_selectABoardToLinkTo.tr();
|
|
break;
|
|
break;
|
|
default:
|
|
default:
|
|
@@ -50,15 +50,15 @@ void showLinkToPageMenu(
|
|
editorState: editorState,
|
|
editorState: editorState,
|
|
layoutType: pageType,
|
|
layoutType: pageType,
|
|
hintText: hintText,
|
|
hintText: hintText,
|
|
- onSelected: (appPB, viewPB) {
|
|
|
|
- editorState.insertPage(appPB, viewPB);
|
|
|
|
|
|
+ onSelected: (viewPB, childViewPB) {
|
|
|
|
+ editorState.insertPage(viewPB, childViewPB);
|
|
},
|
|
},
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
);
|
|
});
|
|
});
|
|
|
|
|
|
- Overlay.of(context)?.insert(_linkToPageMenu!);
|
|
|
|
|
|
+ Overlay.of(context).insert(_linkToPageMenu!);
|
|
|
|
|
|
editorState.service.selectionService.currentSelection
|
|
editorState.service.selectionService.currentSelection
|
|
.addListener(dismissLinkToPageMenu);
|
|
.addListener(dismissLinkToPageMenu);
|
|
@@ -83,23 +83,59 @@ class LinkToPageMenu extends StatefulWidget {
|
|
});
|
|
});
|
|
|
|
|
|
final EditorState editorState;
|
|
final EditorState editorState;
|
|
- final ViewLayoutTypePB layoutType;
|
|
|
|
|
|
+ final ViewLayoutPB layoutType;
|
|
final String hintText;
|
|
final String hintText;
|
|
- final void Function(AppPB appPB, ViewPB viewPB) onSelected;
|
|
|
|
|
|
+ final void Function(ViewPB view, ViewPB childView) onSelected;
|
|
|
|
|
|
@override
|
|
@override
|
|
State<LinkToPageMenu> createState() => _LinkToPageMenuState();
|
|
State<LinkToPageMenu> createState() => _LinkToPageMenuState();
|
|
}
|
|
}
|
|
|
|
|
|
class _LinkToPageMenuState extends State<LinkToPageMenu> {
|
|
class _LinkToPageMenuState extends State<LinkToPageMenu> {
|
|
|
|
+ final _focusNode = FocusNode(debugLabel: 'reference_list_widget');
|
|
EditorStyle get style => widget.editorState.editorStyle;
|
|
EditorStyle get style => widget.editorState.editorStyle;
|
|
|
|
+ int _selectedIndex = 0;
|
|
|
|
+ int _totalItems = 0;
|
|
|
|
+ Future<List<dartz.Tuple2<ViewPB, List<ViewPB>>>>? _availableLayout;
|
|
|
|
+ final Map<int, dartz.Tuple2<ViewPB, ViewPB>> _items = {};
|
|
|
|
+
|
|
|
|
+ Future<List<dartz.Tuple2<ViewPB, List<ViewPB>>>> fetchItems() async {
|
|
|
|
+ final items = await AppBackendService().fetchViews(widget.layoutType);
|
|
|
|
+
|
|
|
|
+ int index = 0;
|
|
|
|
+ for (final app in items) {
|
|
|
|
+ for (final view in app.value2) {
|
|
|
|
+ _items.putIfAbsent(index, () => dartz.Tuple2(app.value1, view));
|
|
|
|
+ index += 1;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ _totalItems = _items.length;
|
|
|
|
+ return items;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @override
|
|
|
|
+ void initState() {
|
|
|
|
+ _availableLayout = fetchItems();
|
|
|
|
+ WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
|
|
+ _focusNode.requestFocus();
|
|
|
|
+ });
|
|
|
|
+ super.initState();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @override
|
|
|
|
+ void dispose() {
|
|
|
|
+ _focusNode.dispose();
|
|
|
|
+ super.dispose();
|
|
|
|
+ }
|
|
|
|
|
|
@override
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
Widget build(BuildContext context) {
|
|
- return Container(
|
|
|
|
- color: Colors.transparent,
|
|
|
|
- width: 300,
|
|
|
|
|
|
+ return Focus(
|
|
|
|
+ focusNode: _focusNode,
|
|
|
|
+ onKey: _onKey,
|
|
child: Container(
|
|
child: Container(
|
|
|
|
+ width: 300,
|
|
padding: const EdgeInsets.fromLTRB(10, 6, 10, 6),
|
|
padding: const EdgeInsets.fromLTRB(10, 6, 10, 6),
|
|
decoration: BoxDecoration(
|
|
decoration: BoxDecoration(
|
|
color: style.selectionMenuBackgroundColor,
|
|
color: style.selectionMenuBackgroundColor,
|
|
@@ -112,17 +148,62 @@ class _LinkToPageMenuState extends State<LinkToPageMenu> {
|
|
],
|
|
],
|
|
borderRadius: BorderRadius.circular(6.0),
|
|
borderRadius: BorderRadius.circular(6.0),
|
|
),
|
|
),
|
|
- child: _buildListWidget(context),
|
|
|
|
|
|
+ child: _buildListWidget(context, _selectedIndex, _availableLayout),
|
|
),
|
|
),
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
- Widget _buildListWidget(BuildContext context) {
|
|
|
|
- return FutureBuilder<List<dartz.Tuple2<AppPB, List<ViewPB>>>>(
|
|
|
|
|
|
+ KeyEventResult _onKey(FocusNode node, RawKeyEvent event) {
|
|
|
|
+ if (event is! RawKeyDownEvent ||
|
|
|
|
+ _availableLayout == null ||
|
|
|
|
+ _items.isEmpty) {
|
|
|
|
+ return KeyEventResult.ignored;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ final acceptedKeys = [
|
|
|
|
+ LogicalKeyboardKey.arrowUp,
|
|
|
|
+ LogicalKeyboardKey.arrowDown,
|
|
|
|
+ LogicalKeyboardKey.tab,
|
|
|
|
+ LogicalKeyboardKey.enter
|
|
|
|
+ ];
|
|
|
|
+
|
|
|
|
+ if (!acceptedKeys.contains(event.logicalKey)) {
|
|
|
|
+ return KeyEventResult.handled;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var newSelectedIndex = _selectedIndex;
|
|
|
|
+ if (event.logicalKey == LogicalKeyboardKey.arrowDown &&
|
|
|
|
+ newSelectedIndex != _totalItems - 1) {
|
|
|
|
+ newSelectedIndex += 1;
|
|
|
|
+ } else if (event.logicalKey == LogicalKeyboardKey.arrowUp &&
|
|
|
|
+ newSelectedIndex != 0) {
|
|
|
|
+ newSelectedIndex -= 1;
|
|
|
|
+ } else if (event.logicalKey == LogicalKeyboardKey.tab) {
|
|
|
|
+ newSelectedIndex += 1;
|
|
|
|
+ newSelectedIndex %= _totalItems;
|
|
|
|
+ } else if (event.logicalKey == LogicalKeyboardKey.enter) {
|
|
|
|
+ widget.onSelected(
|
|
|
|
+ _items[_selectedIndex]!.value1, _items[_selectedIndex]!.value2);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ setState(() {
|
|
|
|
+ _selectedIndex = newSelectedIndex;
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ return KeyEventResult.handled;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Widget _buildListWidget(
|
|
|
|
+ BuildContext context,
|
|
|
|
+ int selectedIndex,
|
|
|
|
+ Future<List<dartz.Tuple2<ViewPB, List<ViewPB>>>>? items,
|
|
|
|
+ ) {
|
|
|
|
+ int index = 0;
|
|
|
|
+ return FutureBuilder<List<dartz.Tuple2<ViewPB, List<ViewPB>>>>(
|
|
builder: (context, snapshot) {
|
|
builder: (context, snapshot) {
|
|
if (snapshot.hasData &&
|
|
if (snapshot.hasData &&
|
|
snapshot.connectionState == ConnectionState.done) {
|
|
snapshot.connectionState == ConnectionState.done) {
|
|
- final apps = snapshot.data;
|
|
|
|
|
|
+ final views = snapshot.data;
|
|
final children = <Widget>[
|
|
final children = <Widget>[
|
|
Padding(
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 4),
|
|
padding: const EdgeInsets.symmetric(vertical: 4),
|
|
@@ -133,28 +214,31 @@ class _LinkToPageMenuState extends State<LinkToPageMenu> {
|
|
),
|
|
),
|
|
),
|
|
),
|
|
];
|
|
];
|
|
- if (apps != null && apps.isNotEmpty) {
|
|
|
|
- for (final app in apps) {
|
|
|
|
- if (app.value2.isNotEmpty) {
|
|
|
|
|
|
+ if (views != null && views.isNotEmpty) {
|
|
|
|
+ for (final view in views) {
|
|
|
|
+ if (view.value2.isNotEmpty) {
|
|
children.add(
|
|
children.add(
|
|
Padding(
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 4),
|
|
padding: const EdgeInsets.symmetric(vertical: 4),
|
|
child: FlowyText.regular(
|
|
child: FlowyText.regular(
|
|
- app.value1.name,
|
|
|
|
|
|
+ view.value1.name,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
);
|
|
- for (final value in app.value2) {
|
|
|
|
|
|
+ for (final value in view.value2) {
|
|
children.add(
|
|
children.add(
|
|
FlowyButton(
|
|
FlowyButton(
|
|
|
|
+ isSelected: index == _selectedIndex,
|
|
leftIcon: svgWidget(
|
|
leftIcon: svgWidget(
|
|
_iconName(value),
|
|
_iconName(value),
|
|
color: Theme.of(context).iconTheme.color,
|
|
color: Theme.of(context).iconTheme.color,
|
|
),
|
|
),
|
|
text: FlowyText.regular(value.name),
|
|
text: FlowyText.regular(value.name),
|
|
- onTap: () => widget.onSelected(app.value1, value),
|
|
|
|
|
|
+ onTap: () => widget.onSelected(view.value1, value),
|
|
),
|
|
),
|
|
);
|
|
);
|
|
|
|
+
|
|
|
|
+ index += 1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -169,15 +253,15 @@ class _LinkToPageMenuState extends State<LinkToPageMenu> {
|
|
);
|
|
);
|
|
}
|
|
}
|
|
},
|
|
},
|
|
- future: AppBackendService().fetchViews(widget.layoutType),
|
|
|
|
|
|
+ future: items,
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
String _iconName(ViewPB viewPB) {
|
|
String _iconName(ViewPB viewPB) {
|
|
switch (viewPB.layout) {
|
|
switch (viewPB.layout) {
|
|
- case ViewLayoutTypePB.Grid:
|
|
|
|
|
|
+ case ViewLayoutPB.Grid:
|
|
return 'editor/grid';
|
|
return 'editor/grid';
|
|
- case ViewLayoutTypePB.Board:
|
|
|
|
|
|
+ case ViewLayoutPB.Board:
|
|
return 'editor/board';
|
|
return 'editor/board';
|
|
default:
|
|
default:
|
|
throw Exception('Unknown layout type');
|
|
throw Exception('Unknown layout type');
|