refactor DesktopTab impl for file_manager_tab_page.dart
This commit is contained in:
parent
cc3c725f38
commit
4f4ac67228
@ -35,7 +35,6 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
|
|||||||
label: params['id'],
|
label: params['id'],
|
||||||
selectedIcon: selectedIcon,
|
selectedIcon: selectedIcon,
|
||||||
unselectedIcon: unselectedIcon,
|
unselectedIcon: unselectedIcon,
|
||||||
closable: false,
|
|
||||||
page: RemotePage(
|
page: RemotePage(
|
||||||
id: params['id'],
|
id: params['id'],
|
||||||
tabBarHeight:
|
tabBarHeight:
|
||||||
@ -118,23 +117,3 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
|
|||||||
return widget.params["windowId"];
|
return widget.params["windowId"];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class AddButton extends StatelessWidget {
|
|
||||||
late final TarBarTheme theme;
|
|
||||||
|
|
||||||
AddButton({
|
|
||||||
Key? key,
|
|
||||||
required this.theme,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return ActionIcon(
|
|
||||||
message: 'New Connection',
|
|
||||||
icon: IconFont.add,
|
|
||||||
theme: theme,
|
|
||||||
onTap: () =>
|
|
||||||
rustDeskWinManager.call(WindowType.Main, "main_window_on_top", ""),
|
|
||||||
is_close: false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -20,25 +20,26 @@ class FileManagerTabPage extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _FileManagerTabPageState extends State<FileManagerTabPage> {
|
class _FileManagerTabPageState extends State<FileManagerTabPage> {
|
||||||
// refactor List<int> when using multi-tab
|
final tabController = Get.put(DesktopTabController());
|
||||||
// this singleton is only for test
|
|
||||||
RxList<TabInfo> tabs = List<TabInfo>.empty(growable: true).obs;
|
static final IconData selectedIcon = Icons.file_copy_sharp;
|
||||||
final IconData selectedIcon = Icons.file_copy_sharp;
|
static final IconData unselectedIcon = Icons.file_copy_outlined;
|
||||||
final IconData unselectedIcon = Icons.file_copy_outlined;
|
|
||||||
|
|
||||||
_FileManagerTabPageState(Map<String, dynamic> params) {
|
_FileManagerTabPageState(Map<String, dynamic> params) {
|
||||||
if (params['id'] != null) {
|
tabController.state.value.tabs.add(TabInfo(
|
||||||
tabs.add(TabInfo(
|
key: params['id'],
|
||||||
key: params['id'],
|
label: params['id'],
|
||||||
label: params['id'],
|
selectedIcon: selectedIcon,
|
||||||
selectedIcon: selectedIcon,
|
unselectedIcon: unselectedIcon,
|
||||||
unselectedIcon: unselectedIcon));
|
page: FileManagerPage(id: params['id'])));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
|
||||||
|
tabController.onRemove = (_, id) => onRemoveId(id);
|
||||||
|
|
||||||
rustDeskWinManager.setMethodHandler((call, fromWindowId) async {
|
rustDeskWinManager.setMethodHandler((call, fromWindowId) async {
|
||||||
print(
|
print(
|
||||||
"call ${call.method} with args ${call.arguments} from window ${fromWindowId}");
|
"call ${call.method} with args ${call.arguments} from window ${fromWindowId}");
|
||||||
@ -47,18 +48,16 @@ class _FileManagerTabPageState extends State<FileManagerTabPage> {
|
|||||||
final args = jsonDecode(call.arguments);
|
final args = jsonDecode(call.arguments);
|
||||||
final id = args['id'];
|
final id = args['id'];
|
||||||
window_on_top(windowId());
|
window_on_top(windowId());
|
||||||
DesktopTabBar.onAdd(
|
tabController.add(TabInfo(
|
||||||
tabs,
|
key: id,
|
||||||
TabInfo(
|
label: id,
|
||||||
key: id,
|
selectedIcon: selectedIcon,
|
||||||
label: id,
|
unselectedIcon: unselectedIcon,
|
||||||
selectedIcon: selectedIcon,
|
page: FileManagerPage(id: id)));
|
||||||
unselectedIcon: unselectedIcon));
|
|
||||||
} else if (call.method == "onDestroy") {
|
} else if (call.method == "onDestroy") {
|
||||||
print(
|
tabController.state.value.tabs.forEach((tab) {
|
||||||
"executing onDestroy hook, closing ${tabs.map((tab) => tab.label).toList()}");
|
print("executing onDestroy hook, closing ${tab.label}}");
|
||||||
tabs.forEach((tab) {
|
final tag = tab.label;
|
||||||
final tag = 'ft_${tab.label}';
|
|
||||||
ffi(tag).close().then((_) {
|
ffi(tag).close().then((_) {
|
||||||
Get.delete<FFI>(tag: tag);
|
Get.delete<FFI>(tag: tag);
|
||||||
});
|
});
|
||||||
@ -70,43 +69,29 @@ class _FileManagerTabPageState extends State<FileManagerTabPage> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final theme = isDarkTheme() ? TarBarTheme.dark() : TarBarTheme.light();
|
||||||
return SubWindowDragToResizeArea(
|
return SubWindowDragToResizeArea(
|
||||||
windowId: windowId(),
|
windowId: windowId(),
|
||||||
child: Container(
|
child: Container(
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
border: Border.all(color: MyTheme.color(context).border!)),
|
border: Border.all(color: MyTheme.color(context).border!)),
|
||||||
child: Scaffold(
|
child: Scaffold(
|
||||||
backgroundColor: MyTheme.color(context).bg,
|
backgroundColor: MyTheme.color(context).bg,
|
||||||
body: Column(
|
body: DesktopTab(
|
||||||
children: [
|
controller: tabController,
|
||||||
DesktopTabBar(
|
theme: theme,
|
||||||
tabs: tabs,
|
isMainWindow: false,
|
||||||
onTabClose: onRemoveId,
|
tail: AddButton(
|
||||||
dark: isDarkTheme(),
|
theme: theme,
|
||||||
mainTab: false,
|
).paddingOnly(left: 10),
|
||||||
),
|
)),
|
||||||
Expanded(
|
|
||||||
child: Obx(
|
|
||||||
() => PageView(
|
|
||||||
controller: DesktopTabBar.controller.value,
|
|
||||||
children: tabs
|
|
||||||
.map((tab) => FileManagerPage(
|
|
||||||
key: ValueKey(tab.label),
|
|
||||||
id: tab
|
|
||||||
.label)) //RemotePage(key: ValueKey(e), id: e))
|
|
||||||
.toList()),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void onRemoveId(String id) {
|
void onRemoveId(String id) {
|
||||||
ffi("ft_$id").close();
|
ffi("ft_$id").close();
|
||||||
if (tabs.length == 0) {
|
if (tabController.state.value.tabs.length == 0) {
|
||||||
WindowController.fromWindowId(windowId()).close();
|
WindowController.fromWindowId(windowId()).close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,8 @@ import 'package:get/get.dart';
|
|||||||
import 'package:window_manager/window_manager.dart';
|
import 'package:window_manager/window_manager.dart';
|
||||||
import 'package:scroll_pos/scroll_pos.dart';
|
import 'package:scroll_pos/scroll_pos.dart';
|
||||||
|
|
||||||
|
import '../../utils/multi_window_manager.dart';
|
||||||
|
|
||||||
const double _kTabBarHeight = kDesktopRemoteTabBarHeight;
|
const double _kTabBarHeight = kDesktopRemoteTabBarHeight;
|
||||||
const double _kIconSize = 18;
|
const double _kIconSize = 18;
|
||||||
const double _kDividerIndent = 10;
|
const double _kDividerIndent = 10;
|
||||||
@ -40,11 +42,6 @@ class DesktopTabState {
|
|||||||
|
|
||||||
DesktopTabState() {
|
DesktopTabState() {
|
||||||
scrollController.itemCount = tabs.length;
|
scrollController.itemCount = tabs.length;
|
||||||
// TODO test
|
|
||||||
// WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
||||||
// scrollController.scrollToItem(selected,
|
|
||||||
// center: true, animate: true);
|
|
||||||
// });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -533,6 +530,26 @@ class ActionIcon extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class AddButton extends StatelessWidget {
|
||||||
|
late final TarBarTheme theme;
|
||||||
|
|
||||||
|
AddButton({
|
||||||
|
Key? key,
|
||||||
|
required this.theme,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return ActionIcon(
|
||||||
|
message: 'New Connection',
|
||||||
|
icon: IconFont.add,
|
||||||
|
theme: theme,
|
||||||
|
onTap: () =>
|
||||||
|
rustDeskWinManager.call(WindowType.Main, "main_window_on_top", ""),
|
||||||
|
is_close: false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class TarBarTheme {
|
class TarBarTheme {
|
||||||
final Color unSelectedtabIconColor;
|
final Color unSelectedtabIconColor;
|
||||||
final Color selectedtabIconColor;
|
final Color selectedtabIconColor;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user