mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2025-11-01 10:33:29 +00:00
chore: remove rename dialog logic (#6906)
This commit is contained in:
parent
e7491e5182
commit
d9bc97e012
@ -49,6 +49,7 @@ class KVKeys {
|
||||
/// {'SidebarFolderCategoryType.value': true}
|
||||
static const String expandedFolders = 'expandedFolders';
|
||||
|
||||
/// @deprecated in version 0.7.6
|
||||
/// The key for saving if showing the rename dialog when creating a new file
|
||||
///
|
||||
/// The value is a boolean string.
|
||||
|
||||
@ -1,14 +1,11 @@
|
||||
import 'package:appflowy/generated/locale_keys.g.dart';
|
||||
import 'package:appflowy/workspace/application/menu/sidebar_sections_bloc.dart';
|
||||
import 'package:appflowy/workspace/application/sidebar/folder/folder_bloc.dart';
|
||||
import 'package:appflowy/workspace/application/tabs/tabs_bloc.dart';
|
||||
import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
|
||||
import 'package:appflowy/workspace/presentation/home/home_sizes.dart';
|
||||
import 'package:appflowy/workspace/presentation/home/menu/sidebar/folder/_folder_header.dart';
|
||||
import 'package:appflowy/workspace/presentation/home/menu/sidebar/shared/rename_view_dialog.dart';
|
||||
import 'package:appflowy/workspace/presentation/home/menu/view/view_item.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.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/services.dart';
|
||||
@ -78,23 +75,17 @@ class _SectionFolderState extends State<SectionFolder> {
|
||||
onPressed: () =>
|
||||
context.read<FolderBloc>().add(const FolderEvent.expandOrUnExpand()),
|
||||
onAdded: () {
|
||||
createViewAndShowRenameDialogIfNeeded(
|
||||
context,
|
||||
LocaleKeys.newPageText.tr(),
|
||||
(_, __) {
|
||||
context.read<SidebarSectionsBloc>().add(
|
||||
SidebarSectionsEvent.createRootViewInSection(
|
||||
name: '',
|
||||
index: 0,
|
||||
viewSection: widget.spaceType.toViewSectionPB,
|
||||
),
|
||||
);
|
||||
context.read<SidebarSectionsBloc>().add(
|
||||
SidebarSectionsEvent.createRootViewInSection(
|
||||
name: '',
|
||||
index: 0,
|
||||
viewSection: widget.spaceType.toViewSectionPB,
|
||||
),
|
||||
);
|
||||
|
||||
context
|
||||
.read<FolderBloc>()
|
||||
.add(const FolderEvent.expandOrUnExpand(isExpanded: true));
|
||||
},
|
||||
);
|
||||
context
|
||||
.read<FolderBloc>()
|
||||
.add(const FolderEvent.expandOrUnExpand(isExpanded: true));
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@ -1,36 +0,0 @@
|
||||
import 'package:appflowy/core/config/kv.dart';
|
||||
import 'package:appflowy/core/config/kv_keys.dart';
|
||||
import 'package:appflowy/generated/locale_keys.g.dart';
|
||||
import 'package:appflowy/startup/startup.dart';
|
||||
import 'package:appflowy/workspace/presentation/widgets/dialogs.dart';
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Creates a new view and shows the rename dialog if needed.
|
||||
///
|
||||
/// If the user has enabled the setting to show the rename dialog when creating a new view,
|
||||
/// this function will show the rename dialog.
|
||||
///
|
||||
/// Otherwise, it will just create the view with default name.
|
||||
Future<void> createViewAndShowRenameDialogIfNeeded(
|
||||
BuildContext context,
|
||||
String dialogTitle,
|
||||
void Function(String viewName, BuildContext context) createView,
|
||||
) async {
|
||||
final value = await getIt<KeyValueStorage>().getWithFormat(
|
||||
KVKeys.showRenameDialogWhenCreatingNewFile,
|
||||
(value) => bool.parse(value),
|
||||
);
|
||||
final showRenameDialog = value ?? false;
|
||||
final defaultName = LocaleKeys.menuAppHeader_defaultNewPageName.tr();
|
||||
if (context.mounted && showRenameDialog) {
|
||||
await NavigatorTextFieldDialog(
|
||||
title: dialogTitle,
|
||||
value: defaultName,
|
||||
autoSelectAllText: true,
|
||||
onConfirm: createView,
|
||||
).show(context);
|
||||
} else if (context.mounted) {
|
||||
createView(defaultName, context);
|
||||
}
|
||||
}
|
||||
@ -5,7 +5,6 @@ import 'package:appflowy/workspace/application/sidebar/space/space_bloc.dart';
|
||||
import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
|
||||
import 'package:appflowy/workspace/presentation/home/home_sizes.dart';
|
||||
import 'package:appflowy/workspace/presentation/home/hotkeys.dart';
|
||||
import 'package:appflowy/workspace/presentation/home/menu/sidebar/shared/rename_view_dialog.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
|
||||
@ -57,35 +56,28 @@ class _SidebarNewPageButtonState extends State<SidebarNewPageButton> {
|
||||
}
|
||||
|
||||
Future<void> _createNewPage() async {
|
||||
return createViewAndShowRenameDialogIfNeeded(
|
||||
context,
|
||||
LocaleKeys.newPageText.tr(),
|
||||
(_, __) {
|
||||
// if the workspace is collaborative, create the view in the private section by default.
|
||||
final section =
|
||||
context.read<UserWorkspaceBloc>().state.isCollabWorkspaceOn
|
||||
? ViewSectionPB.Private
|
||||
: ViewSectionPB.Public;
|
||||
final spaceState = context.read<SpaceBloc>().state;
|
||||
if (spaceState.spaces.isNotEmpty) {
|
||||
context.read<SpaceBloc>().add(
|
||||
const SpaceEvent.createPage(
|
||||
name: '',
|
||||
index: 0,
|
||||
layout: ViewLayoutPB.Document,
|
||||
openAfterCreate: true,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
context.read<SidebarSectionsBloc>().add(
|
||||
SidebarSectionsEvent.createRootViewInSection(
|
||||
name: '',
|
||||
viewSection: section,
|
||||
index: 0,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
// if the workspace is collaborative, create the view in the private section by default.
|
||||
final section = context.read<UserWorkspaceBloc>().state.isCollabWorkspaceOn
|
||||
? ViewSectionPB.Private
|
||||
: ViewSectionPB.Public;
|
||||
final spaceState = context.read<SpaceBloc>().state;
|
||||
if (spaceState.spaces.isNotEmpty) {
|
||||
context.read<SpaceBloc>().add(
|
||||
const SpaceEvent.createPage(
|
||||
name: '',
|
||||
index: 0,
|
||||
layout: ViewLayoutPB.Document,
|
||||
openAfterCreate: true,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
context.read<SidebarSectionsBloc>().add(
|
||||
SidebarSectionsEvent.createRootViewInSection(
|
||||
name: '',
|
||||
viewSection: section,
|
||||
index: 0,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,7 +14,6 @@ import 'package:appflowy/workspace/application/view/prelude.dart';
|
||||
import 'package:appflowy/workspace/application/view/view_ext.dart';
|
||||
import 'package:appflowy/workspace/presentation/home/home_sizes.dart';
|
||||
import 'package:appflowy/workspace/presentation/home/menu/menu_shared_state.dart';
|
||||
import 'package:appflowy/workspace/presentation/home/menu/sidebar/shared/rename_view_dialog.dart';
|
||||
import 'package:appflowy/workspace/presentation/home/menu/view/draggable_view_item.dart';
|
||||
import 'package:appflowy/workspace/presentation/home/menu/view/view_action_type.dart';
|
||||
import 'package:appflowy/workspace/presentation/home/menu/view/view_add_button.dart';
|
||||
@ -692,26 +691,18 @@ class _SingleInnerViewItemState extends State<SingleInnerViewItem> {
|
||||
) {
|
||||
final viewBloc = context.read<ViewBloc>();
|
||||
|
||||
if (createNewView) {
|
||||
createViewAndShowRenameDialogIfNeeded(
|
||||
context,
|
||||
_convertLayoutToHintText(pluginBuilder.layoutType!),
|
||||
(viewName, _) {
|
||||
// the name of new document should be empty
|
||||
if (pluginBuilder.layoutType == ViewLayoutPB.Document) {
|
||||
viewName = '';
|
||||
}
|
||||
viewBloc.add(
|
||||
ViewEvent.createView(
|
||||
viewName,
|
||||
pluginBuilder.layoutType!,
|
||||
openAfterCreated: openAfterCreated,
|
||||
section: widget.spaceType.toViewSectionPB,
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
// the name of new document should be empty
|
||||
final viewName = pluginBuilder.layoutType != ViewLayoutPB.Document
|
||||
? LocaleKeys.menuAppHeader_defaultNewPageName.tr()
|
||||
: '';
|
||||
viewBloc.add(
|
||||
ViewEvent.createView(
|
||||
viewName,
|
||||
pluginBuilder.layoutType!,
|
||||
openAfterCreated: openAfterCreated,
|
||||
section: widget.spaceType.toViewSectionPB,
|
||||
),
|
||||
);
|
||||
|
||||
viewBloc.add(const ViewEvent.setIsExpanded(true));
|
||||
}
|
||||
@ -815,22 +806,6 @@ class _SingleInnerViewItemState extends State<SingleInnerViewItem> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String _convertLayoutToHintText(ViewLayoutPB layout) {
|
||||
switch (layout) {
|
||||
case ViewLayoutPB.Document:
|
||||
return LocaleKeys.newDocumentText.tr();
|
||||
case ViewLayoutPB.Grid:
|
||||
return LocaleKeys.newGridText.tr();
|
||||
case ViewLayoutPB.Board:
|
||||
return LocaleKeys.newBoardText.tr();
|
||||
case ViewLayoutPB.Calendar:
|
||||
return LocaleKeys.newCalendarText.tr();
|
||||
case ViewLayoutPB.Chat:
|
||||
return LocaleKeys.chat_newChat.tr();
|
||||
}
|
||||
return LocaleKeys.newPageText.tr();
|
||||
}
|
||||
}
|
||||
|
||||
class _DotIconWidget extends StatelessWidget {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user