Skip to content

Commit

Permalink
refactor: adapt to merge changes
Browse files Browse the repository at this point in the history
  • Loading branch information
squidrye committed Mar 3, 2024
1 parent 9b5f834 commit 31a6dca
Show file tree
Hide file tree
Showing 22 changed files with 115 additions and 114 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/workspace/presentation/home/panes/flowy_pane.dart';
import 'package:appflowy_backend/protobuf/flowy-folder2/protobuf.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/protobuf.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
Expand Down Expand Up @@ -57,7 +57,7 @@ void main() {
findsNWidgets(2),
);

await tester.createNewPageWithName(name: _documentName);
await tester.createNewPageWithNameUnderParent(name: _documentName);
await tester.tap(find.byType(FlowyPane).first);
await tester.openPage(_documentName);

Expand Down Expand Up @@ -97,7 +97,7 @@ void main() {
);

await tester.tap(find.byType(FlowyPane).first);
await tester.createNewPageWithName(name: _documentName);
await tester.createNewPageWithNameUnderParent(name: _documentName);

expect(
find.textContaining(LocaleKeys.readOnlyViewText.tr()),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:appflowy/workspace/presentation/home/panes/flowy_pane.dart';
import 'package:appflowy_backend/protobuf/flowy-folder2/protobuf.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/protobuf.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
Expand All @@ -19,12 +19,12 @@ void main() {

expect(find.byType(FlowyPane), findsOneWidget);

await tester.createNewPageWithName(
await tester.createNewPageWithNameUnderParent(
name: _documentName,
layout: ViewLayoutPB.Document,
);

await tester.createNewPageWithName(
await tester.createNewPageWithNameUnderParent(
name: _documentTwoName,
layout: ViewLayoutPB.Document,
);
Expand Down
15 changes: 6 additions & 9 deletions frontend/appflowy_flutter/lib/plugins/document/document.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
library document_plugin;

import 'package:flutter/material.dart';

import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/document/application/document_appearance_cubit.dart';
Expand All @@ -19,6 +17,7 @@ import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

class DocumentPluginBuilder extends PluginBuilder {
Expand Down Expand Up @@ -54,7 +53,7 @@ class DocumentPlugin extends Plugin<int> {
}

late PluginType _pluginType;
late final ViewInfoBloc _viewInfoBloc;
ViewInfoBloc? _viewInfoBloc;

@override
final ViewPluginNotifier notifier;
Expand All @@ -63,7 +62,7 @@ class DocumentPlugin extends Plugin<int> {

@override
PluginWidgetBuilder get widgetBuilder => DocumentPluginWidgetBuilder(
bloc: _viewInfoBloc,
bloc: _viewInfoBloc!,
notifier: notifier,
initialSelection: initialSelection,
);
Expand All @@ -76,19 +75,17 @@ class DocumentPlugin extends Plugin<int> {

@override
void init() {
_viewInfoBloc = ViewInfoBloc(view: notifier.view)
..add(const ViewInfoEvent.started());
_viewInfoBloc = ViewInfoBloc(view: notifier.view)..add(const ViewInfoEvent.started());
}

@override
void dispose() {
_viewInfoBloc.close();
_viewInfoBloc?.close();
notifier.dispose();
}
}

class DocumentPluginWidgetBuilder extends PluginWidgetBuilder
with NavigationItem {
class DocumentPluginWidgetBuilder extends PluginWidgetBuilder with NavigationItem {
DocumentPluginWidgetBuilder({
required this.bloc,
required this.notifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ class _DocumentPageState extends State<DocumentPage> {
Widget _buildEditorPage(BuildContext context, DocumentState state) {
final appflowyEditorPage = AppFlowyEditorPage(
autoFocus: !widget.readOnlyStatus,
editorState: editorState!,
editorState: state.editorState!,
styleCustomizer: EditorStyleCustomizer(
context: context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.da
import 'package:appflowy/startup/plugin/plugin.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/workspace/application/panes/panes_bloc/panes_bloc.dart';
import 'package:appflowy/workspace/application/tabs/tabs_bloc.dart';
import 'package:appflowy/workspace/application/view/view_ext.dart';
import 'package:appflowy/workspace/application/view/view_service.dart';
import 'package:appflowy/workspace/presentation/widgets/pop_up_action.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import 'package:appflowy/startup/plugin/plugin.dart';
import 'package:appflowy/workspace/application/panes/panes.dart';
import 'package:appflowy/workspace/application/panes/panes_service.dart';
import 'package:appflowy/workspace/presentation/home/panes/draggable_pane_target.dart';
import 'package:bloc/bloc.dart';
import 'package:flutter/material.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

import 'package:appflowy/workspace/application/panes/panes.dart';

part 'panes_bloc.freezed.dart';
part 'panes_state.dart';
part 'panes_event.dart';
part 'panes_state.dart';

enum SplitDirection { left, right, up, down, none }

Expand All @@ -29,13 +28,17 @@ class PanesBloc extends Bloc<PanesEvent, PanesState> {
return;
}

final direction = [SplitDirection.right, SplitDirection.down]
.contains(e.splitDirection)
final direction = [
SplitDirection.right,
SplitDirection.down,
].contains(e.splitDirection)
? Direction.front
: Direction.back;

final axis = [SplitDirection.down, SplitDirection.up]
.contains(e.splitDirection)
final axis = [
SplitDirection.down,
SplitDirection.up,
].contains(e.splitDirection)
? Axis.horizontal
: Axis.vertical;

Expand Down Expand Up @@ -82,10 +85,8 @@ class PanesBloc extends Bloc<PanesEvent, PanesState> {
),
);
},
openTabInActivePane: (e) =>
state.activePane.tabsController.openView(e.plugin),
opnePluginInActivePane: (e) =>
state.activePane.tabsController.openPlugin(plugin: e.plugin),
openTabInActivePane: (e) => state.activePane.tabsController.openView(e.plugin),
opnePluginInActivePane: (e) => state.activePane.tabsController.openPlugin(plugin: e.plugin),
selectTab: (e) {
if (e.pane != null) {
emit(state.copyWith(activePane: e.pane!));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,14 @@ class PanesService {

final ret = newHolderNode.copyWith(
children: direction == Direction.front
? [oldChildNode, newChildNode]
: [newChildNode, oldChildNode],
? [
oldChildNode,
newChildNode,
]
: [
newChildNode,
oldChildNode,
],
);

return ret.copyWith(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import 'package:appflowy/startup/plugin/plugin.dart';
import 'package:appflowy/workspace/application/tabs/tabs_service.dart';
import 'package:appflowy/workspace/presentation/home/home_stack.dart';
import 'package:appflowy/workspace/presentation/home/tabs/draggable_tab_item.dart';

import 'package:appflowy_backend/protobuf/flowy-folder2/view.pb.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
import 'package:flutter/material.dart';
import 'package:nanoid/nanoid.dart';

Expand Down Expand Up @@ -42,10 +41,17 @@ class TabsController extends ChangeNotifier {
pageManagers = pageManagersCopy;
}

void openView(Plugin plugin, {int? index}) {
void openView(
Plugin plugin, {
int? index,
}) {
final selectExistingPlugin = _selectPluginIfOpen(plugin.id);
if (!selectExistingPlugin) {
tabService.openViewHandler(this, plugin, index: index);
tabService.openViewHandler(
this,
plugin,
index: index,
);
currentIndex = index ?? pageManagers.length - 1;
}

Expand All @@ -69,9 +75,7 @@ class TabsController extends ChangeNotifier {
/// And the current selected tab isn't the first (index 0)
/// as currentIndex cannot be -1
/// Then decrease currentIndex by 1
currentIndex = currentIndex > pageManagers.length - 1 && currentIndex > 0
? currentIndex - 1
: currentIndex;
currentIndex = currentIndex > pageManagers.length - 1 && currentIndex > 0 ? currentIndex - 1 : currentIndex;

if (!closePaneSubRoutine) {
setLatestOpenView();
Expand Down Expand Up @@ -130,12 +134,18 @@ class TabsController extends ChangeNotifier {
break;
case TabDraggableHoverPosition.left:
final index = pageManagers.indexOf(to);
openView(from.plugin, index: index);
openView(
from.plugin,
index: index,
);
currentIndex = index;
break;
case TabDraggableHoverPosition.right:
final index = pageManagers.indexOf(to);
openView(from.plugin, index: index + 1);
openView(
from.plugin,
index: index + 1,
);
currentIndex = index + 1;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ class TabService {
return null;
}

void openViewHandler(TabsController controller, Plugin plugin, {int? index}) {
void openViewHandler(
TabsController controller,
Plugin plugin, {
int? index,
}) {
final openPlugins = menuSharedState.openPlugins;

/// Determine placement of new pagemanager in list of pagemanagers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@ import 'package:appflowy/user/application/auth/auth_service.dart';
import 'package:appflowy/user/application/reminder/reminder_bloc.dart';
import 'package:appflowy/workspace/application/favorite/favorite_bloc.dart';
import 'package:appflowy/workspace/application/home/home_bloc.dart';
import 'package:appflowy/workspace/application/home/home_bloc.dart';
import 'package:appflowy/workspace/application/home/home_service.dart';
import 'package:appflowy/workspace/application/home/home_service.dart';
import 'package:appflowy/workspace/application/home/home_setting_bloc.dart';
import 'package:appflowy/workspace/application/home/home_setting_bloc.dart';
import 'package:appflowy/workspace/application/panes/panes_bloc/panes_bloc.dart';
import 'package:appflowy/workspace/application/settings/appearance/appearance_cubit.dart';
import 'package:appflowy/workspace/application/settings/appearance/appearance_cubit.dart';
import 'package:appflowy/workspace/application/tabs/tabs_bloc.dart';
import 'package:appflowy/workspace/application/view/view_ext.dart';
import 'package:appflowy/workspace/presentation/home/errors/workspace_failed_screen.dart';
import 'package:appflowy/workspace/presentation/home/hotkeys.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:appflowy/workspace/application/panes/panes.dart';
import 'package:appflowy/workspace/application/tabs/tabs_controller.dart';
import 'package:appflowy/workspace/presentation/home/home_stack.dart';
import 'package:appflowy_backend/protobuf/flowy-folder2/view.pb.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';

enum CrossDraggableType { view, tab, pane, none }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@ import 'package:appflowy/workspace/presentation/home/panes/panes_layout.dart';
import 'package:appflowy/workspace/presentation/home/toast.dart';
import 'package:appflowy_backend/dispatch/dispatch.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
import 'package:appflowy_backend/protobuf/flowy-folder2/view.pb.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:equatable/equatable.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flowy_infra_ui/style_widget/extension.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:provider/provider.dart';
import 'package:time/time.dart';
Expand Down Expand Up @@ -181,17 +178,17 @@ abstract mixin class NavigationItem {
}

class PageNotifier extends ChangeNotifier {
PageNotifier({Plugin? plugin, bool? readOnly})
: _plugin = plugin ?? makePlugin(pluginType: PluginType.blank),
_readOnly = readOnly ?? false;

Plugin _plugin;
bool _readOnly;

Widget get titleWidget => _plugin.widgetBuilder.leftBarItem;

Widget tabBarWidget(String pluginId) => _plugin.widgetBuilder.tabBarItem(pluginId);

PageNotifier({Plugin? plugin, bool? readOnly})
: _plugin = plugin ?? makePlugin(pluginType: PluginType.blank),
_readOnly = readOnly ?? false;

/// This is the only place where the plugin is set.
/// No need compare the old plugin with the new plugin. Just set it.
set plugin(Plugin newPlugin) {
Expand All @@ -216,7 +213,7 @@ class PageNotifier extends ChangeNotifier {
}

// PageManager manages the view for one Tab
class PageManager {
class PageManager extends Equatable {
PageManager();

final PageNotifier _notifier = PageNotifier();
Expand Down Expand Up @@ -284,6 +281,9 @@ class PageManager {
void dispose() {
_notifier.dispose();
}

@override
List<Object?> get props => [notifier.plugin.id];
}

class HomeTopBar extends StatelessWidget {
Expand Down Expand Up @@ -340,7 +340,7 @@ class HomeTopBar extends StatelessWidget {
),
],
),
).bottomBorder(color: Theme.of(context).dividerColor),
),
),
if (notifier.readOnly) _buildReadOnlyBanner(context),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ import 'dart:io';

import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/workspace/application/home/home_setting_bloc.dart';
import 'package:appflowy/workspace/application/home/home_setting_bloc.dart';
import 'package:appflowy/workspace/application/panes/panes_bloc/panes_bloc.dart';
import 'package:appflowy/workspace/application/settings/appearance/appearance_cubit.dart';
import 'package:appflowy/workspace/application/settings/appearance/appearance_cubit.dart';
import 'package:appflowy/workspace/application/sidebar/rename_view/rename_view_bloc.dart';
import 'package:appflowy/workspace/application/tabs/tabs_bloc.dart';
import 'package:appflowy/workspace/presentation/home/menu/sidebar/sidebar_user.dart';
import 'package:flutter/material.dart';
import 'package:hotkey_manager/hotkey_manager.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ class MenuSharedState {
_latestOpenView.value = view;
}

final ValueNotifier<ViewPB?> _latestOpenView = ValueNotifier<ViewPB?>(null);

ViewPB? get latestOpenView => _latestOpenView.value;
ValueNotifier<ViewPB?> get notifier => _latestOpenView;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class FavoriteFolder extends StatelessWidget {
view: view,
level: 0,
onSelected: (view) {
if (RawKeyboard.instance.isControlPressed) {
if (HardwareKeyboard.instance.isControlPressed) {
context.read<PanesBloc>().add(OpenTabInActivePane(plugin: view.plugin()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class PersonalFolder extends StatelessWidget {
leftPadding: 16,
isFeedback: false,
onSelected: (view) {
if (RawKeyboard.instance.isControlPressed) {
if (HardwareKeyboard.instance.isControlPressed) {
context.read<PanesBloc>().add(OpenTabInActivePane(plugin: view.plugin()));
}

Expand Down
Loading

0 comments on commit 31a6dca

Please sign in to comment.