2022-10-17 21:26:18 +08:00
|
|
|
import 'dart:async';
|
2022-06-17 22:57:41 +08:00
|
|
|
import 'dart:io';
|
2022-07-09 19:14:40 +08:00
|
|
|
import 'dart:math';
|
2022-06-17 22:57:41 +08:00
|
|
|
|
2022-08-16 13:28:48 +08:00
|
|
|
import 'package:desktop_drop/desktop_drop.dart';
|
2022-10-20 10:20:41 +08:00
|
|
|
import 'package:flutter/gestures.dart';
|
2022-06-17 22:57:41 +08:00
|
|
|
import 'package:flutter/material.dart';
|
2022-10-17 21:26:18 +08:00
|
|
|
import 'package:flutter/services.dart';
|
2022-08-16 11:46:51 +08:00
|
|
|
import 'package:flutter_breadcrumb/flutter_breadcrumb.dart';
|
2022-12-13 12:55:41 +08:00
|
|
|
import 'package:flutter_hbb/desktop/widgets/list_search_action_listener.dart';
|
2022-10-18 22:56:36 +08:00
|
|
|
import 'package:flutter_hbb/desktop/widgets/tabbar_widget.dart';
|
2022-06-17 22:57:41 +08:00
|
|
|
import 'package:flutter_hbb/models/file_model.dart';
|
|
|
|
import 'package:get/get.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'package:wakelock/wakelock.dart';
|
2022-10-13 19:22:11 +08:00
|
|
|
import '../../consts.dart';
|
|
|
|
import '../../desktop/widgets/material_mod_popup_menu.dart' as mod_menu;
|
2022-06-17 22:57:41 +08:00
|
|
|
|
|
|
|
import '../../common.dart';
|
|
|
|
import '../../models/model.dart';
|
2022-08-03 22:03:31 +08:00
|
|
|
import '../../models/platform_model.dart';
|
2022-10-13 19:22:11 +08:00
|
|
|
import '../widgets/popup_menu.dart';
|
2022-06-17 22:57:41 +08:00
|
|
|
|
2022-10-13 09:17:20 +08:00
|
|
|
/// status of location bar
|
|
|
|
enum LocationStatus {
|
|
|
|
/// normal bread crumb bar
|
|
|
|
bread,
|
|
|
|
|
|
|
|
/// show path text field
|
|
|
|
pathLocation,
|
|
|
|
|
|
|
|
/// show file search bar text field
|
|
|
|
fileSearchBar
|
|
|
|
}
|
2022-08-16 11:46:51 +08:00
|
|
|
|
2022-12-13 12:55:41 +08:00
|
|
|
/// The status of currently focused scope of the mouse
|
|
|
|
enum MouseFocusScope {
|
|
|
|
/// Mouse is in local field.
|
|
|
|
local,
|
|
|
|
|
|
|
|
/// Mouse is in remote field.
|
|
|
|
remote,
|
|
|
|
|
|
|
|
/// Mouse is not in local field, remote neither.
|
|
|
|
none
|
|
|
|
}
|
|
|
|
|
2022-06-17 22:57:41 +08:00
|
|
|
class FileManagerPage extends StatefulWidget {
|
2022-09-06 17:08:59 +08:00
|
|
|
const FileManagerPage({Key? key, required this.id}) : super(key: key);
|
2022-06-17 22:57:41 +08:00
|
|
|
final String id;
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() => _FileManagerPageState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _FileManagerPageState extends State<FileManagerPage>
|
|
|
|
with AutomaticKeepAliveClientMixin {
|
2022-07-09 19:14:40 +08:00
|
|
|
final _localSelectedItems = SelectedItems();
|
|
|
|
final _remoteSelectedItems = SelectedItems();
|
2022-06-17 22:57:41 +08:00
|
|
|
|
2022-08-16 11:46:51 +08:00
|
|
|
final _locationStatusLocal = LocationStatus.bread.obs;
|
|
|
|
final _locationStatusRemote = LocationStatus.bread.obs;
|
2022-10-17 21:26:18 +08:00
|
|
|
final _locationNodeLocal = FocusNode(debugLabel: "locationNodeLocal");
|
|
|
|
final _locationNodeRemote = FocusNode(debugLabel: "locationNodeRemote");
|
2022-10-19 09:52:29 +08:00
|
|
|
final _locationBarKeyLocal = GlobalKey(debugLabel: "locationBarKeyLocal");
|
|
|
|
final _locationBarKeyRemote = GlobalKey(debugLabel: "locationBarKeyRemote");
|
2022-08-16 12:28:12 +08:00
|
|
|
final _searchTextLocal = "".obs;
|
|
|
|
final _searchTextRemote = "".obs;
|
|
|
|
final _breadCrumbScrollerLocal = ScrollController();
|
|
|
|
final _breadCrumbScrollerRemote = ScrollController();
|
2022-12-13 12:55:41 +08:00
|
|
|
final _mouseFocusScope = Rx<MouseFocusScope>(MouseFocusScope.none);
|
|
|
|
final _keyboardNodeLocal = FocusNode(debugLabel: "keyboardNodeLocal");
|
|
|
|
final _keyboardNodeRemote = FocusNode(debugLabel: "keyboardNodeRemote");
|
|
|
|
final _listSearchBufferLocal = TimeoutStringBuffer();
|
|
|
|
final _listSearchBufferRemote = TimeoutStringBuffer();
|
2022-08-16 12:28:12 +08:00
|
|
|
|
2022-10-17 21:26:18 +08:00
|
|
|
/// [_lastClickTime], [_lastClickEntry] help to handle double click
|
2022-11-02 11:32:30 +08:00
|
|
|
int _lastClickTime =
|
|
|
|
DateTime.now().millisecondsSinceEpoch - bind.getDoubleClickTime() - 1000;
|
2022-10-17 21:26:18 +08:00
|
|
|
Entry? _lastClickEntry;
|
|
|
|
|
2022-10-13 09:17:20 +08:00
|
|
|
final _dropMaskVisible = false.obs; // TODO impl drop mask
|
2022-08-16 13:28:48 +08:00
|
|
|
|
2022-08-16 12:28:12 +08:00
|
|
|
ScrollController getBreadCrumbScrollController(bool isLocal) {
|
|
|
|
return isLocal ? _breadCrumbScrollerLocal : _breadCrumbScrollerRemote;
|
|
|
|
}
|
2022-08-16 11:46:51 +08:00
|
|
|
|
2022-10-19 09:52:29 +08:00
|
|
|
GlobalKey getLocationBarKey(bool isLocal) {
|
|
|
|
return isLocal ? _locationBarKeyLocal : _locationBarKeyRemote;
|
|
|
|
}
|
|
|
|
|
2022-08-12 18:42:02 +08:00
|
|
|
late FFI _ffi;
|
2022-06-17 22:57:41 +08:00
|
|
|
|
|
|
|
FileModel get model => _ffi.fileModel;
|
|
|
|
|
2022-10-19 09:52:29 +08:00
|
|
|
SelectedItems getSelectedItems(bool isLocal) {
|
2022-07-09 19:14:40 +08:00
|
|
|
return isLocal ? _localSelectedItems : _remoteSelectedItems;
|
|
|
|
}
|
|
|
|
|
2022-06-17 22:57:41 +08:00
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
2022-08-12 18:42:02 +08:00
|
|
|
_ffi = FFI();
|
2022-09-27 20:35:02 +08:00
|
|
|
_ffi.start(widget.id, isFileTransfer: true);
|
2022-09-06 19:08:45 +08:00
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
|
|
_ffi.dialogManager
|
|
|
|
.showLoading(translate('Connecting...'), onCancel: closeConnection);
|
|
|
|
});
|
2022-08-12 18:42:02 +08:00
|
|
|
Get.put(_ffi, tag: 'ft_${widget.id}');
|
2022-06-17 22:57:41 +08:00
|
|
|
if (!Platform.isLinux) {
|
|
|
|
Wakelock.enable();
|
|
|
|
}
|
2022-09-13 21:36:38 +08:00
|
|
|
debugPrint("File manager page init success with id ${widget.id}");
|
2022-12-04 21:41:44 +08:00
|
|
|
model.onDirChanged = breadCrumbScrollToEnd;
|
2022-08-16 11:46:51 +08:00
|
|
|
// register location listener
|
|
|
|
_locationNodeLocal.addListener(onLocalLocationFocusChanged);
|
|
|
|
_locationNodeRemote.addListener(onRemoteLocationFocusChanged);
|
2022-06-17 22:57:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
2022-12-04 21:41:44 +08:00
|
|
|
model.onClose().whenComplete(() {
|
|
|
|
_ffi.close();
|
|
|
|
_ffi.dialogManager.dismissAll();
|
|
|
|
if (!Platform.isLinux) {
|
|
|
|
Wakelock.disable();
|
|
|
|
}
|
|
|
|
Get.delete<FFI>(tag: 'ft_${widget.id}');
|
|
|
|
_locationNodeLocal.removeListener(onLocalLocationFocusChanged);
|
|
|
|
_locationNodeRemote.removeListener(onRemoteLocationFocusChanged);
|
|
|
|
_locationNodeLocal.dispose();
|
|
|
|
_locationNodeRemote.dispose();
|
|
|
|
});
|
2022-06-17 22:57:41 +08:00
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
super.build(context);
|
2022-08-19 12:44:35 +08:00
|
|
|
return Overlay(initialEntries: [
|
|
|
|
OverlayEntry(builder: (context) {
|
|
|
|
_ffi.dialogManager.setOverlayState(Overlay.of(context));
|
|
|
|
return ChangeNotifierProvider.value(
|
|
|
|
value: _ffi.fileModel,
|
2022-10-11 08:59:27 +08:00
|
|
|
child: Consumer<FileModel>(builder: (context, model, child) {
|
2022-10-13 09:17:20 +08:00
|
|
|
return Scaffold(
|
|
|
|
backgroundColor: Theme.of(context).backgroundColor,
|
|
|
|
body: Row(
|
|
|
|
children: [
|
|
|
|
Flexible(flex: 3, child: body(isLocal: true)),
|
|
|
|
Flexible(flex: 3, child: body(isLocal: false)),
|
|
|
|
Flexible(flex: 2, child: statusList())
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
2022-08-19 12:44:35 +08:00
|
|
|
}));
|
|
|
|
})
|
|
|
|
]);
|
2022-06-17 22:57:41 +08:00
|
|
|
}
|
|
|
|
|
2022-06-27 16:44:34 +08:00
|
|
|
Widget menu({bool isLocal = false}) {
|
2022-10-13 19:22:11 +08:00
|
|
|
var menuPos = RelativeRect.fill;
|
|
|
|
|
2022-10-19 09:52:29 +08:00
|
|
|
final List<MenuEntryBase<String>> items = [
|
2022-10-13 19:22:11 +08:00
|
|
|
MenuEntrySwitch<String>(
|
|
|
|
switchType: SwitchType.scheckbox,
|
|
|
|
text: translate("Show Hidden Files"),
|
|
|
|
getter: () async {
|
|
|
|
return model.getCurrentShowHidden(isLocal);
|
|
|
|
},
|
|
|
|
setter: (bool v) async {
|
|
|
|
model.toggleShowHidden(local: isLocal);
|
2022-06-27 16:44:34 +08:00
|
|
|
},
|
2022-10-13 19:22:11 +08:00
|
|
|
padding: kDesktopMenuPadding,
|
|
|
|
dismissOnClicked: true,
|
|
|
|
),
|
2022-10-19 09:52:29 +08:00
|
|
|
MenuEntryButton(
|
|
|
|
childBuilder: (style) => Text(translate("Select All"), style: style),
|
|
|
|
proc: () => setState(() => getSelectedItems(isLocal)
|
|
|
|
.selectAll(model.getCurrentDir(isLocal).entries)),
|
|
|
|
padding: kDesktopMenuPadding,
|
|
|
|
dismissOnClicked: true),
|
|
|
|
MenuEntryButton(
|
|
|
|
childBuilder: (style) =>
|
|
|
|
Text(translate("Unselect All"), style: style),
|
|
|
|
proc: () => setState(() => getSelectedItems(isLocal).clear()),
|
|
|
|
padding: kDesktopMenuPadding,
|
|
|
|
dismissOnClicked: true)
|
2022-10-13 19:22:11 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
return Listener(
|
|
|
|
onPointerDown: (e) {
|
|
|
|
final x = e.position.dx;
|
|
|
|
final y = e.position.dy;
|
|
|
|
menuPos = RelativeRect.fromLTRB(x, y, x, y);
|
|
|
|
},
|
|
|
|
child: IconButton(
|
|
|
|
icon: const Icon(Icons.more_vert),
|
2022-10-26 20:13:32 +08:00
|
|
|
splashRadius: kDesktopIconButtonSplashRadius,
|
2022-10-13 19:22:11 +08:00
|
|
|
onPressed: () => mod_menu.showMenu(
|
|
|
|
context: context,
|
|
|
|
position: menuPos,
|
|
|
|
items: items
|
|
|
|
.map((e) => e.build(
|
|
|
|
context,
|
|
|
|
MenuConfig(
|
|
|
|
commonColor: CustomPopupMenuTheme.commonColor,
|
|
|
|
height: CustomPopupMenuTheme.height,
|
|
|
|
dividerHeight: CustomPopupMenuTheme.dividerHeight)))
|
|
|
|
.expand((i) => i)
|
|
|
|
.toList(),
|
|
|
|
elevation: 8,
|
|
|
|
),
|
|
|
|
));
|
2022-06-27 16:44:34 +08:00
|
|
|
}
|
|
|
|
|
2022-06-21 18:14:44 +08:00
|
|
|
Widget body({bool isLocal = false}) {
|
2022-12-13 12:55:41 +08:00
|
|
|
final scrollController = ScrollController();
|
2022-07-01 17:17:25 +08:00
|
|
|
return Container(
|
2022-08-16 11:46:51 +08:00
|
|
|
decoration: BoxDecoration(border: Border.all(color: Colors.black26)),
|
2022-07-01 17:17:25 +08:00
|
|
|
margin: const EdgeInsets.all(16.0),
|
|
|
|
padding: const EdgeInsets.all(8.0),
|
2022-08-16 13:28:48 +08:00
|
|
|
child: DropTarget(
|
|
|
|
onDragDone: (detail) => handleDragDone(detail, isLocal),
|
|
|
|
onDragEntered: (enter) {
|
|
|
|
_dropMaskVisible.value = true;
|
|
|
|
},
|
|
|
|
onDragExited: (exit) {
|
|
|
|
_dropMaskVisible.value = false;
|
|
|
|
},
|
2022-12-14 11:56:36 +08:00
|
|
|
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
2022-08-16 13:28:48 +08:00
|
|
|
headTools(isLocal),
|
|
|
|
Expanded(
|
|
|
|
child: Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: SingleChildScrollView(
|
2022-12-13 12:55:41 +08:00
|
|
|
controller: scrollController,
|
|
|
|
child: _buildDataTable(context, isLocal, scrollController),
|
2022-07-01 17:17:25 +08:00
|
|
|
),
|
2022-08-16 13:28:48 +08:00
|
|
|
)
|
|
|
|
],
|
|
|
|
)),
|
|
|
|
]),
|
|
|
|
),
|
2022-07-01 17:17:25 +08:00
|
|
|
);
|
2022-06-17 22:57:41 +08:00
|
|
|
}
|
|
|
|
|
2022-12-13 12:55:41 +08:00
|
|
|
Widget _buildDataTable(
|
|
|
|
BuildContext context, bool isLocal, ScrollController scrollController) {
|
|
|
|
const rowHeight = 25.0;
|
2022-10-17 21:26:18 +08:00
|
|
|
final fd = model.getCurrentDir(isLocal);
|
|
|
|
final entries = fd.entries;
|
|
|
|
final sortIndex = (SortBy style) {
|
|
|
|
switch (style) {
|
2022-10-19 22:29:45 +08:00
|
|
|
case SortBy.name:
|
2022-10-17 21:26:18 +08:00
|
|
|
return 0;
|
2022-10-19 22:29:45 +08:00
|
|
|
case SortBy.type:
|
2022-10-17 21:26:18 +08:00
|
|
|
return 0;
|
2022-10-19 22:29:45 +08:00
|
|
|
case SortBy.modified:
|
2022-10-17 21:26:18 +08:00
|
|
|
return 1;
|
2022-10-19 22:29:45 +08:00
|
|
|
case SortBy.size:
|
2022-10-17 21:26:18 +08:00
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
}(model.getSortStyle(isLocal));
|
|
|
|
final sortAscending =
|
|
|
|
isLocal ? model.localSortAscending : model.remoteSortAscending;
|
|
|
|
|
2022-12-13 12:55:41 +08:00
|
|
|
return MouseRegion(
|
|
|
|
onEnter: (evt) {
|
|
|
|
_mouseFocusScope.value =
|
|
|
|
isLocal ? MouseFocusScope.local : MouseFocusScope.remote;
|
|
|
|
if (isLocal) {
|
|
|
|
_keyboardNodeLocal.requestFocus();
|
|
|
|
} else {
|
|
|
|
_keyboardNodeRemote.requestFocus();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onExit: (evt) {
|
|
|
|
_mouseFocusScope.value = MouseFocusScope.none;
|
|
|
|
},
|
|
|
|
child: ListSearchActionListener(
|
|
|
|
node: isLocal ? _keyboardNodeLocal : _keyboardNodeRemote,
|
|
|
|
buffer: isLocal ? _listSearchBufferLocal : _listSearchBufferRemote,
|
|
|
|
onNext: (buffer) {
|
|
|
|
debugPrint("searching next for $buffer");
|
|
|
|
assert(buffer.length == 1);
|
|
|
|
final selectedEntries = getSelectedItems(isLocal);
|
|
|
|
assert(selectedEntries.length <= 1);
|
|
|
|
var skipCount = 0;
|
|
|
|
if (selectedEntries.items.isNotEmpty) {
|
|
|
|
final index = entries.indexOf(selectedEntries.items.first);
|
|
|
|
if (index < 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
skipCount = index + 1;
|
|
|
|
}
|
|
|
|
var searchResult = entries
|
|
|
|
.skip(skipCount)
|
|
|
|
.where((element) => element.name.startsWith(buffer));
|
|
|
|
if (searchResult.isEmpty) {
|
2022-12-14 11:56:36 +08:00
|
|
|
// cannot find next, lets restart search from head
|
2022-12-13 12:55:41 +08:00
|
|
|
searchResult =
|
|
|
|
entries.where((element) => element.name.startsWith(buffer));
|
|
|
|
}
|
|
|
|
if (searchResult.isEmpty) {
|
2022-12-14 11:56:36 +08:00
|
|
|
setState(() {
|
|
|
|
getSelectedItems(isLocal).clear();
|
|
|
|
});
|
2022-12-13 12:55:41 +08:00
|
|
|
return;
|
|
|
|
}
|
2022-12-14 11:56:36 +08:00
|
|
|
_jumpToEntry(
|
|
|
|
isLocal, searchResult.first, scrollController, rowHeight, buffer);
|
2022-12-13 12:55:41 +08:00
|
|
|
},
|
|
|
|
onSearch: (buffer) {
|
|
|
|
debugPrint("searching for $buffer");
|
|
|
|
final selectedEntries = getSelectedItems(isLocal);
|
|
|
|
final searchResult =
|
|
|
|
entries.where((element) => element.name.startsWith(buffer));
|
|
|
|
selectedEntries.clear();
|
|
|
|
if (searchResult.isEmpty) {
|
2022-12-14 11:56:36 +08:00
|
|
|
setState(() {
|
|
|
|
getSelectedItems(isLocal).clear();
|
|
|
|
});
|
2022-12-13 12:55:41 +08:00
|
|
|
return;
|
|
|
|
}
|
2022-12-14 11:56:36 +08:00
|
|
|
_jumpToEntry(
|
|
|
|
isLocal, searchResult.first, scrollController, rowHeight, buffer);
|
2022-12-13 12:55:41 +08:00
|
|
|
},
|
|
|
|
child: ObxValue<RxString>(
|
|
|
|
(searchText) {
|
|
|
|
final filteredEntries = searchText.isNotEmpty
|
|
|
|
? entries.where((element) {
|
|
|
|
return element.name.contains(searchText.value);
|
|
|
|
}).toList(growable: false)
|
|
|
|
: entries;
|
|
|
|
return DataTable(
|
|
|
|
key: ValueKey(isLocal ? 0 : 1),
|
|
|
|
showCheckboxColumn: false,
|
|
|
|
dataRowHeight: rowHeight,
|
|
|
|
headingRowHeight: 30,
|
|
|
|
horizontalMargin: 8,
|
|
|
|
columnSpacing: 8,
|
|
|
|
showBottomBorder: true,
|
|
|
|
sortColumnIndex: sortIndex,
|
|
|
|
sortAscending: sortAscending,
|
|
|
|
columns: [
|
|
|
|
DataColumn(
|
|
|
|
label: Text(
|
|
|
|
translate("Name"),
|
|
|
|
).marginSymmetric(horizontal: 4),
|
|
|
|
onSort: (columnIndex, ascending) {
|
|
|
|
model.changeSortStyle(SortBy.name,
|
|
|
|
isLocal: isLocal, ascending: ascending);
|
|
|
|
}),
|
|
|
|
DataColumn(
|
|
|
|
label: Text(
|
|
|
|
translate("Modified"),
|
|
|
|
),
|
|
|
|
onSort: (columnIndex, ascending) {
|
|
|
|
model.changeSortStyle(SortBy.modified,
|
|
|
|
isLocal: isLocal, ascending: ascending);
|
|
|
|
}),
|
|
|
|
DataColumn(
|
|
|
|
label: Text(translate("Size")),
|
|
|
|
onSort: (columnIndex, ascending) {
|
|
|
|
model.changeSortStyle(SortBy.size,
|
|
|
|
isLocal: isLocal, ascending: ascending);
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
rows: filteredEntries.map((entry) {
|
|
|
|
final sizeStr =
|
|
|
|
entry.isFile ? readableFileSize(entry.size.toDouble()) : "";
|
|
|
|
final lastModifiedStr = entry.isDrive
|
|
|
|
? " "
|
|
|
|
: "${entry.lastModified().toString().replaceAll(".000", "")} ";
|
|
|
|
return DataRow(
|
|
|
|
key: ValueKey(entry.name),
|
|
|
|
onSelectChanged: (s) {
|
|
|
|
_onSelectedChanged(getSelectedItems(isLocal),
|
|
|
|
filteredEntries, entry, isLocal);
|
|
|
|
},
|
|
|
|
selected: getSelectedItems(isLocal).contains(entry),
|
|
|
|
cells: [
|
|
|
|
DataCell(
|
|
|
|
Container(
|
|
|
|
width: 200,
|
|
|
|
child: Tooltip(
|
|
|
|
waitDuration: Duration(milliseconds: 500),
|
|
|
|
message: entry.name,
|
|
|
|
child: Row(children: [
|
|
|
|
entry.isDrive
|
|
|
|
? Image(
|
|
|
|
image: iconHardDrive,
|
|
|
|
fit: BoxFit.scaleDown,
|
|
|
|
color: Theme.of(context)
|
|
|
|
.iconTheme
|
|
|
|
.color
|
|
|
|
?.withOpacity(0.7))
|
|
|
|
.paddingAll(4)
|
|
|
|
: Icon(
|
|
|
|
entry.isFile
|
|
|
|
? Icons.feed_outlined
|
|
|
|
: Icons.folder,
|
|
|
|
size: 20,
|
2022-10-20 09:31:31 +08:00
|
|
|
color: Theme.of(context)
|
|
|
|
.iconTheme
|
|
|
|
.color
|
2022-12-13 12:55:41 +08:00
|
|
|
?.withOpacity(0.7),
|
|
|
|
).marginSymmetric(horizontal: 2),
|
|
|
|
Expanded(
|
|
|
|
child: Text(entry.name,
|
|
|
|
overflow: TextOverflow.ellipsis))
|
|
|
|
]),
|
|
|
|
)),
|
|
|
|
onTap: () {
|
|
|
|
final items = getSelectedItems(isLocal);
|
2022-12-14 11:56:36 +08:00
|
|
|
|
2022-12-13 12:55:41 +08:00
|
|
|
// handle double click
|
|
|
|
if (_checkDoubleClick(entry)) {
|
|
|
|
openDirectory(entry.path, isLocal: isLocal);
|
|
|
|
items.clear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_onSelectedChanged(
|
|
|
|
items, filteredEntries, entry, isLocal);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
DataCell(FittedBox(
|
|
|
|
child: Tooltip(
|
|
|
|
waitDuration: Duration(milliseconds: 500),
|
|
|
|
message: lastModifiedStr,
|
|
|
|
child: Text(
|
|
|
|
lastModifiedStr,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 12, color: MyTheme.darkGray),
|
|
|
|
)))),
|
|
|
|
DataCell(Tooltip(
|
2022-10-17 21:26:18 +08:00
|
|
|
waitDuration: Duration(milliseconds: 500),
|
2022-12-13 12:55:41 +08:00
|
|
|
message: sizeStr,
|
2022-10-17 21:26:18 +08:00
|
|
|
child: Text(
|
2022-12-13 12:55:41 +08:00
|
|
|
sizeStr,
|
|
|
|
overflow: TextOverflow.ellipsis,
|
2022-12-14 11:56:36 +08:00
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 10, color: MyTheme.darkGray),
|
2022-12-13 12:55:41 +08:00
|
|
|
))),
|
|
|
|
]);
|
|
|
|
}).toList(growable: false),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
isLocal ? _searchTextLocal : _searchTextRemote,
|
|
|
|
),
|
|
|
|
),
|
2022-10-17 21:26:18 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-12-14 11:56:36 +08:00
|
|
|
void _jumpToEntry(bool isLocal, Entry entry,
|
|
|
|
ScrollController scrollController, double rowHeight, String buffer) {
|
|
|
|
final entries = model.getCurrentDir(isLocal).entries;
|
|
|
|
final index = entries.indexOf(entry);
|
|
|
|
if (index == -1) {
|
|
|
|
debugPrint("entry is not valid: ${entry.path}");
|
|
|
|
}
|
|
|
|
final selectedEntries = getSelectedItems(isLocal);
|
|
|
|
final searchResult =
|
|
|
|
entries.where((element) => element.name.startsWith(buffer));
|
|
|
|
selectedEntries.clear();
|
|
|
|
if (searchResult.isEmpty) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
final offset = min(
|
|
|
|
max(scrollController.position.minScrollExtent,
|
|
|
|
entries.indexOf(searchResult.first) * rowHeight),
|
|
|
|
scrollController.position.maxScrollExtent);
|
|
|
|
scrollController.jumpTo(offset);
|
|
|
|
setState(() {
|
|
|
|
selectedEntries.add(isLocal, searchResult.first);
|
|
|
|
debugPrint("focused on ${searchResult.first.name}");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-10-17 22:07:40 +08:00
|
|
|
void _onSelectedChanged(SelectedItems selectedItems, List<Entry> entries,
|
|
|
|
Entry entry, bool isLocal) {
|
|
|
|
final isCtrlDown = RawKeyboard.instance.keysPressed
|
|
|
|
.contains(LogicalKeyboardKey.controlLeft);
|
|
|
|
final isShiftDown =
|
|
|
|
RawKeyboard.instance.keysPressed.contains(LogicalKeyboardKey.shiftLeft);
|
|
|
|
if (isCtrlDown) {
|
|
|
|
if (selectedItems.contains(entry)) {
|
|
|
|
selectedItems.remove(entry);
|
|
|
|
} else {
|
|
|
|
selectedItems.add(isLocal, entry);
|
|
|
|
}
|
|
|
|
} else if (isShiftDown) {
|
|
|
|
final List<int> indexGroup = [];
|
|
|
|
for (var selected in selectedItems.items) {
|
|
|
|
indexGroup.add(entries.indexOf(selected));
|
|
|
|
}
|
|
|
|
indexGroup.add(entries.indexOf(entry));
|
|
|
|
indexGroup.removeWhere((e) => e == -1);
|
|
|
|
final maxIndex = indexGroup.reduce(max);
|
|
|
|
final minIndex = indexGroup.reduce(min);
|
|
|
|
selectedItems.clear();
|
|
|
|
entries
|
|
|
|
.getRange(minIndex, maxIndex + 1)
|
|
|
|
.forEach((e) => selectedItems.add(isLocal, e));
|
|
|
|
} else {
|
|
|
|
selectedItems.clear();
|
|
|
|
selectedItems.add(isLocal, entry);
|
|
|
|
}
|
|
|
|
setState(() {});
|
|
|
|
}
|
|
|
|
|
2022-10-17 21:26:18 +08:00
|
|
|
bool _checkDoubleClick(Entry entry) {
|
|
|
|
final current = DateTime.now().millisecondsSinceEpoch;
|
|
|
|
final elapsed = current - _lastClickTime;
|
|
|
|
_lastClickTime = current;
|
|
|
|
if (_lastClickEntry == entry) {
|
2022-11-02 11:32:30 +08:00
|
|
|
if (elapsed < bind.getDoubleClickTime()) {
|
2022-10-17 21:26:18 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_lastClickEntry = entry;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-07-01 12:08:52 +08:00
|
|
|
/// transfer status list
|
|
|
|
/// watch transfer status
|
|
|
|
Widget statusList() {
|
2022-07-01 17:17:25 +08:00
|
|
|
return PreferredSize(
|
2022-09-06 19:08:45 +08:00
|
|
|
preferredSize: const Size(200, double.infinity),
|
2022-07-01 17:17:25 +08:00
|
|
|
child: Container(
|
2022-07-11 16:07:49 +08:00
|
|
|
margin: const EdgeInsets.only(top: 16.0, bottom: 16.0, right: 16.0),
|
2022-07-01 17:17:25 +08:00
|
|
|
padding: const EdgeInsets.all(8.0),
|
2022-08-16 11:46:51 +08:00
|
|
|
decoration: BoxDecoration(border: Border.all(color: Colors.grey)),
|
2022-07-09 19:14:40 +08:00
|
|
|
child: Obx(
|
|
|
|
() => ListView.builder(
|
2022-09-12 11:23:45 +08:00
|
|
|
controller: ScrollController(),
|
2022-07-11 10:30:45 +08:00
|
|
|
itemBuilder: (BuildContext context, int index) {
|
|
|
|
final item = model.jobTable[index];
|
|
|
|
return Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
2022-07-09 19:14:40 +08:00
|
|
|
children: [
|
2022-07-11 10:30:45 +08:00
|
|
|
Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Transform.rotate(
|
|
|
|
angle: item.isRemote ? pi : 0,
|
2022-09-06 19:08:45 +08:00
|
|
|
child: const Icon(Icons.send)),
|
|
|
|
const SizedBox(
|
2022-07-11 16:07:49 +08:00
|
|
|
width: 16.0,
|
|
|
|
),
|
2022-07-11 10:30:45 +08:00
|
|
|
Expanded(
|
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Tooltip(
|
2022-10-17 21:26:18 +08:00
|
|
|
waitDuration: Duration(milliseconds: 500),
|
2022-07-11 10:30:45 +08:00
|
|
|
message: item.jobName,
|
2022-07-11 16:07:49 +08:00
|
|
|
child: Text(
|
2022-09-06 19:08:45 +08:00
|
|
|
item.jobName,
|
2022-07-11 10:30:45 +08:00
|
|
|
maxLines: 1,
|
2022-07-11 16:07:49 +08:00
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
)),
|
2022-07-11 10:30:45 +08:00
|
|
|
Wrap(
|
|
|
|
children: [
|
2022-07-11 16:07:49 +08:00
|
|
|
Text(
|
2022-12-05 20:09:48 +08:00
|
|
|
'${item.display()} ${max(0, item.fileNum)}/${item.fileCount} '),
|
2022-07-11 16:07:49 +08:00
|
|
|
Text(
|
|
|
|
'${translate("files")} ${readableFileSize(item.totalSize.toDouble())} '),
|
|
|
|
Offstage(
|
|
|
|
offstage:
|
|
|
|
item.state != JobState.inProgress,
|
|
|
|
child: Text(
|
2022-09-06 19:08:45 +08:00
|
|
|
'${"${readableFileSize(item.speed)}/s"} ')),
|
2022-07-11 16:07:49 +08:00
|
|
|
Offstage(
|
|
|
|
offstage: item.totalSize <= 0,
|
|
|
|
child: Text(
|
|
|
|
'${(item.finishedSize.toDouble() * 100 / item.totalSize.toDouble()).toStringAsFixed(2)}%'),
|
|
|
|
),
|
2022-07-11 10:30:45 +08:00
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
|
|
children: [
|
2022-07-11 18:23:58 +08:00
|
|
|
Offstage(
|
|
|
|
offstage: item.state != JobState.paused,
|
|
|
|
child: IconButton(
|
|
|
|
onPressed: () {
|
|
|
|
model.resumeJob(item.id);
|
|
|
|
},
|
2022-10-26 20:13:32 +08:00
|
|
|
splashRadius: kDesktopIconButtonSplashRadius,
|
2022-09-06 19:08:45 +08:00
|
|
|
icon: const Icon(Icons.restart_alt_rounded)),
|
2022-07-11 18:23:58 +08:00
|
|
|
),
|
2022-07-11 16:07:49 +08:00
|
|
|
IconButton(
|
2022-12-05 20:57:08 +08:00
|
|
|
icon: const Icon(Icons.close),
|
|
|
|
splashRadius: 1,
|
2022-07-11 16:07:49 +08:00
|
|
|
onPressed: () {
|
|
|
|
model.jobTable.removeAt(index);
|
|
|
|
model.cancelJob(item.id);
|
|
|
|
},
|
|
|
|
),
|
2022-07-11 10:30:45 +08:00
|
|
|
],
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
2022-07-11 16:07:49 +08:00
|
|
|
SizedBox(
|
|
|
|
height: 8.0,
|
|
|
|
),
|
|
|
|
Divider(
|
|
|
|
height: 2.0,
|
|
|
|
)
|
2022-07-09 19:14:40 +08:00
|
|
|
],
|
|
|
|
);
|
2022-07-11 16:07:49 +08:00
|
|
|
},
|
2022-07-09 19:14:40 +08:00
|
|
|
itemCount: model.jobTable.length,
|
|
|
|
),
|
|
|
|
),
|
2022-09-06 19:08:45 +08:00
|
|
|
));
|
2022-07-01 12:08:52 +08:00
|
|
|
}
|
|
|
|
|
2022-08-16 11:46:51 +08:00
|
|
|
Widget headTools(bool isLocal) {
|
2022-10-11 08:59:27 +08:00
|
|
|
final locationStatus =
|
2022-08-16 11:46:51 +08:00
|
|
|
isLocal ? _locationStatusLocal : _locationStatusRemote;
|
2022-10-11 08:59:27 +08:00
|
|
|
final locationFocus = isLocal ? _locationNodeLocal : _locationNodeRemote;
|
2022-10-19 09:52:29 +08:00
|
|
|
final selectedItems = getSelectedItems(isLocal);
|
2022-08-16 11:46:51 +08:00
|
|
|
return Container(
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
// symbols
|
|
|
|
PreferredSize(
|
|
|
|
child: Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Container(
|
|
|
|
width: 50,
|
|
|
|
height: 50,
|
|
|
|
decoration: BoxDecoration(color: Colors.blue),
|
|
|
|
padding: EdgeInsets.all(8.0),
|
|
|
|
child: FutureBuilder<String>(
|
|
|
|
future: bind.sessionGetPlatform(
|
|
|
|
id: _ffi.id, isRemote: !isLocal),
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (snapshot.hasData && snapshot.data!.isNotEmpty) {
|
|
|
|
return getPlatformImage('${snapshot.data}');
|
|
|
|
} else {
|
|
|
|
return CircularProgressIndicator(
|
|
|
|
color: Colors.white,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
})),
|
|
|
|
Text(isLocal
|
|
|
|
? translate("Local Computer")
|
|
|
|
: translate("Remote Computer"))
|
|
|
|
.marginOnly(left: 8.0)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
preferredSize: Size(double.infinity, 70)),
|
|
|
|
// buttons
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
Row(
|
|
|
|
children: [
|
2022-10-11 16:25:34 +08:00
|
|
|
IconButton(
|
|
|
|
icon: const Icon(Icons.arrow_back),
|
2022-10-26 20:13:32 +08:00
|
|
|
splashRadius: kDesktopIconButtonSplashRadius,
|
2022-10-11 16:25:34 +08:00
|
|
|
onPressed: () {
|
2022-10-19 09:52:29 +08:00
|
|
|
selectedItems.clear();
|
2022-10-11 16:25:34 +08:00
|
|
|
model.goBack(isLocal: isLocal);
|
|
|
|
},
|
|
|
|
),
|
2022-08-16 11:46:51 +08:00
|
|
|
IconButton(
|
2022-09-06 19:08:45 +08:00
|
|
|
icon: const Icon(Icons.arrow_upward),
|
2022-10-26 20:13:32 +08:00
|
|
|
splashRadius: kDesktopIconButtonSplashRadius,
|
2022-08-16 11:46:51 +08:00
|
|
|
onPressed: () {
|
2022-10-19 09:52:29 +08:00
|
|
|
selectedItems.clear();
|
2022-10-11 16:25:34 +08:00
|
|
|
model.goToParentDirectory(isLocal: isLocal);
|
2022-08-16 11:46:51 +08:00
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: GestureDetector(
|
|
|
|
onTap: () {
|
2022-10-11 08:59:27 +08:00
|
|
|
locationStatus.value =
|
|
|
|
locationStatus.value == LocationStatus.bread
|
2022-10-13 09:17:20 +08:00
|
|
|
? LocationStatus.pathLocation
|
2022-08-16 11:46:51 +08:00
|
|
|
: LocationStatus.bread;
|
|
|
|
Future.delayed(Duration.zero, () {
|
2022-10-13 09:17:20 +08:00
|
|
|
if (locationStatus.value == LocationStatus.pathLocation) {
|
2022-10-11 08:59:27 +08:00
|
|
|
locationFocus.requestFocus();
|
2022-08-16 11:46:51 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2022-10-13 09:17:20 +08:00
|
|
|
child: Obx(() => Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
border: Border.all(
|
|
|
|
color: locationStatus.value == LocationStatus.bread
|
|
|
|
? Colors.black12
|
|
|
|
: Theme.of(context)
|
|
|
|
.colorScheme
|
|
|
|
.primary
|
|
|
|
.withOpacity(0.5))),
|
2022-08-16 11:46:51 +08:00
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
2022-10-13 09:17:20 +08:00
|
|
|
child: locationStatus.value == LocationStatus.bread
|
|
|
|
? buildBread(isLocal)
|
|
|
|
: buildPathLocation(isLocal)),
|
2022-08-16 11:46:51 +08:00
|
|
|
],
|
2022-10-13 09:17:20 +08:00
|
|
|
))),
|
2022-08-16 11:46:51 +08:00
|
|
|
)),
|
2022-10-13 09:17:20 +08:00
|
|
|
Obx(() {
|
|
|
|
switch (locationStatus.value) {
|
|
|
|
case LocationStatus.bread:
|
|
|
|
return IconButton(
|
|
|
|
onPressed: () {
|
|
|
|
locationStatus.value = LocationStatus.fileSearchBar;
|
|
|
|
final focusNode =
|
|
|
|
isLocal ? _locationNodeLocal : _locationNodeRemote;
|
|
|
|
Future.delayed(
|
|
|
|
Duration.zero, () => focusNode.requestFocus());
|
|
|
|
},
|
2022-10-26 20:13:32 +08:00
|
|
|
splashRadius: kDesktopIconButtonSplashRadius,
|
2022-10-13 09:17:20 +08:00
|
|
|
icon: Icon(Icons.search));
|
|
|
|
case LocationStatus.pathLocation:
|
|
|
|
return IconButton(
|
|
|
|
color: Theme.of(context).disabledColor,
|
|
|
|
onPressed: null,
|
2022-10-26 20:13:32 +08:00
|
|
|
splashRadius: kDesktopIconButtonSplashRadius,
|
2022-10-13 09:17:20 +08:00
|
|
|
icon: Icon(Icons.close));
|
|
|
|
case LocationStatus.fileSearchBar:
|
|
|
|
return IconButton(
|
|
|
|
color: Theme.of(context).disabledColor,
|
|
|
|
onPressed: () {
|
|
|
|
onSearchText("", isLocal);
|
|
|
|
locationStatus.value = LocationStatus.bread;
|
|
|
|
},
|
|
|
|
splashRadius: 1,
|
|
|
|
icon: Icon(Icons.close));
|
|
|
|
}
|
|
|
|
}),
|
2022-08-16 11:46:51 +08:00
|
|
|
IconButton(
|
|
|
|
onPressed: () {
|
|
|
|
model.refresh(isLocal: isLocal);
|
|
|
|
},
|
2022-10-26 20:13:32 +08:00
|
|
|
splashRadius: kDesktopIconButtonSplashRadius,
|
2022-09-06 19:08:45 +08:00
|
|
|
icon: const Icon(Icons.refresh)),
|
2022-08-16 11:46:51 +08:00
|
|
|
],
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
textDirection: isLocal ? TextDirection.ltr : TextDirection.rtl,
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment:
|
|
|
|
isLocal ? MainAxisAlignment.start : MainAxisAlignment.end,
|
2022-07-11 16:07:49 +08:00
|
|
|
children: [
|
2022-10-19 22:59:02 +08:00
|
|
|
IconButton(
|
|
|
|
onPressed: () {
|
|
|
|
model.goHome(isLocal: isLocal);
|
|
|
|
},
|
|
|
|
icon: const Icon(Icons.home_outlined),
|
2022-10-26 20:13:32 +08:00
|
|
|
splashRadius: kDesktopIconButtonSplashRadius,
|
2022-10-19 22:59:02 +08:00
|
|
|
),
|
2022-07-11 16:07:49 +08:00
|
|
|
IconButton(
|
|
|
|
onPressed: () {
|
2022-08-16 11:46:51 +08:00
|
|
|
final name = TextEditingController();
|
2022-09-03 18:19:50 +08:00
|
|
|
_ffi.dialogManager.show((setState, close) {
|
|
|
|
submit() {
|
|
|
|
if (name.value.text.isNotEmpty) {
|
|
|
|
model.createDir(
|
|
|
|
PathUtil.join(
|
|
|
|
model.getCurrentDir(isLocal).path,
|
|
|
|
name.value.text,
|
|
|
|
model.getCurrentIsWindows(isLocal)),
|
|
|
|
isLocal: isLocal);
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cancel() => close(false);
|
|
|
|
return CustomAlertDialog(
|
|
|
|
title: Text(translate("Create Folder")),
|
|
|
|
content: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
TextFormField(
|
|
|
|
decoration: InputDecoration(
|
|
|
|
labelText: translate(
|
|
|
|
"Please enter the folder name"),
|
|
|
|
),
|
|
|
|
controller: name,
|
|
|
|
focusNode: FocusNode()..requestFocus(),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
actions: [
|
2023-01-15 19:46:16 +08:00
|
|
|
dialogButton("Cancel",
|
|
|
|
onPressed: cancel, isOutline: true),
|
|
|
|
dialogButton("OK", onPressed: submit)
|
2022-09-03 18:19:50 +08:00
|
|
|
],
|
|
|
|
onSubmit: submit,
|
|
|
|
onCancel: cancel,
|
|
|
|
);
|
|
|
|
});
|
2022-07-11 16:07:49 +08:00
|
|
|
},
|
2022-10-26 20:13:32 +08:00
|
|
|
splashRadius: kDesktopIconButtonSplashRadius,
|
2022-09-03 18:19:50 +08:00
|
|
|
icon: const Icon(Icons.create_new_folder_outlined)),
|
2022-07-11 16:07:49 +08:00
|
|
|
IconButton(
|
2022-10-19 09:52:29 +08:00
|
|
|
onPressed: validItems(selectedItems)
|
|
|
|
? () async {
|
|
|
|
await (model.removeAction(selectedItems,
|
|
|
|
isLocal: isLocal));
|
|
|
|
selectedItems.clear();
|
|
|
|
}
|
|
|
|
: null,
|
2022-10-26 20:13:32 +08:00
|
|
|
splashRadius: kDesktopIconButtonSplashRadius,
|
2022-09-06 19:08:45 +08:00
|
|
|
icon: const Icon(Icons.delete_forever_outlined)),
|
2022-10-11 16:25:34 +08:00
|
|
|
menu(isLocal: isLocal),
|
2022-07-11 16:07:49 +08:00
|
|
|
],
|
2022-06-17 22:57:41 +08:00
|
|
|
),
|
2022-08-16 11:46:51 +08:00
|
|
|
),
|
|
|
|
TextButton.icon(
|
2022-10-19 09:52:29 +08:00
|
|
|
onPressed: validItems(selectedItems)
|
|
|
|
? () {
|
|
|
|
model.sendFiles(selectedItems, isRemote: !isLocal);
|
|
|
|
selectedItems.clear();
|
|
|
|
}
|
|
|
|
: null,
|
2022-08-16 11:46:51 +08:00
|
|
|
icon: Transform.rotate(
|
|
|
|
angle: isLocal ? 0 : pi,
|
2022-09-06 19:08:45 +08:00
|
|
|
child: const Icon(
|
2022-08-16 11:46:51 +08:00
|
|
|
Icons.send,
|
2022-07-11 16:07:49 +08:00
|
|
|
),
|
2022-08-16 11:46:51 +08:00
|
|
|
),
|
|
|
|
label: Text(
|
|
|
|
isLocal ? translate('Send') : translate('Receive'),
|
|
|
|
)),
|
|
|
|
],
|
|
|
|
).marginOnly(top: 8.0)
|
|
|
|
],
|
|
|
|
));
|
|
|
|
}
|
2022-06-17 22:57:41 +08:00
|
|
|
|
2022-10-19 09:52:29 +08:00
|
|
|
bool validItems(SelectedItems items) {
|
|
|
|
if (items.length > 0) {
|
|
|
|
// exclude DirDrive type
|
|
|
|
return items.items.any((item) => !item.isDrive);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-06-17 22:57:41 +08:00
|
|
|
@override
|
|
|
|
bool get wantKeepAlive => true;
|
2022-07-11 16:07:49 +08:00
|
|
|
|
2022-08-16 11:46:51 +08:00
|
|
|
void onLocalLocationFocusChanged() {
|
|
|
|
debugPrint("focus changed on local");
|
|
|
|
if (_locationNodeLocal.hasFocus) {
|
|
|
|
// ignore
|
|
|
|
} else {
|
|
|
|
// lost focus, change to bread
|
2022-10-13 09:17:20 +08:00
|
|
|
if (_locationStatusLocal.value != LocationStatus.fileSearchBar) {
|
|
|
|
_locationStatusLocal.value = LocationStatus.bread;
|
|
|
|
}
|
2022-08-16 11:46:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void onRemoteLocationFocusChanged() {
|
|
|
|
debugPrint("focus changed on remote");
|
|
|
|
if (_locationNodeRemote.hasFocus) {
|
|
|
|
// ignore
|
|
|
|
} else {
|
|
|
|
// lost focus, change to bread
|
2022-10-13 09:17:20 +08:00
|
|
|
if (_locationStatusRemote.value != LocationStatus.fileSearchBar) {
|
|
|
|
_locationStatusRemote.value = LocationStatus.bread;
|
|
|
|
}
|
2022-08-16 11:46:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget buildBread(bool isLocal) {
|
2022-08-16 12:50:08 +08:00
|
|
|
final items = getPathBreadCrumbItems(isLocal, (list) {
|
|
|
|
var path = "";
|
|
|
|
for (var item in list) {
|
|
|
|
path = PathUtil.join(path, item, model.getCurrentIsWindows(isLocal));
|
|
|
|
}
|
|
|
|
openDirectory(path, isLocal: isLocal);
|
|
|
|
});
|
2022-10-19 09:52:29 +08:00
|
|
|
final locationBarKey = getLocationBarKey(isLocal);
|
2022-10-18 22:56:36 +08:00
|
|
|
|
2022-08-16 12:50:08 +08:00
|
|
|
return items.isEmpty
|
|
|
|
? Offstage()
|
2022-10-18 22:56:36 +08:00
|
|
|
: Row(
|
|
|
|
key: locationBarKey,
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
|
|
|
Expanded(
|
2022-10-20 10:20:41 +08:00
|
|
|
child: Listener(
|
|
|
|
// handle mouse wheel
|
|
|
|
onPointerSignal: (e) {
|
|
|
|
if (e is PointerScrollEvent) {
|
|
|
|
final sc = getBreadCrumbScrollController(isLocal);
|
2022-12-04 22:51:48 +08:00
|
|
|
final scale = Platform.isWindows ? 2 : 4;
|
|
|
|
sc.jumpTo(sc.offset + e.scrollDelta.dy / scale);
|
2022-10-20 10:20:41 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
child: BreadCrumb(
|
|
|
|
items: items,
|
2022-11-02 21:30:41 +08:00
|
|
|
divider: Icon(Icons.chevron_right),
|
2022-10-20 10:20:41 +08:00
|
|
|
overflow: ScrollableOverflow(
|
|
|
|
controller:
|
|
|
|
getBreadCrumbScrollController(isLocal)),
|
|
|
|
))),
|
2022-10-18 22:56:36 +08:00
|
|
|
ActionIcon(
|
|
|
|
message: "",
|
|
|
|
icon: Icons.arrow_drop_down,
|
|
|
|
onTap: () async {
|
|
|
|
final renderBox = locationBarKey.currentContext
|
|
|
|
?.findRenderObject() as RenderBox;
|
|
|
|
locationBarKey.currentContext?.size;
|
|
|
|
|
|
|
|
final size = renderBox.size;
|
|
|
|
final offset = renderBox.localToGlobal(Offset.zero);
|
|
|
|
|
|
|
|
final x = offset.dx;
|
|
|
|
final y = offset.dy + size.height + 1;
|
|
|
|
|
2022-12-04 22:44:03 +08:00
|
|
|
final isPeerWindows = model.getCurrentIsWindows(isLocal);
|
2022-10-19 10:24:44 +08:00
|
|
|
final List<MenuEntryBase> menuItems = [
|
|
|
|
MenuEntryButton(
|
2022-11-02 22:48:02 +08:00
|
|
|
childBuilder: (TextStyle? style) => isPeerWindows
|
|
|
|
? buildWindowsThisPC(style)
|
|
|
|
: Text(
|
|
|
|
'/',
|
|
|
|
style: style,
|
|
|
|
),
|
2022-10-19 10:24:44 +08:00
|
|
|
proc: () {
|
|
|
|
openDirectory('/', isLocal: isLocal);
|
|
|
|
},
|
|
|
|
dismissOnClicked: true),
|
|
|
|
MenuEntryDivider()
|
|
|
|
];
|
2022-11-02 22:48:02 +08:00
|
|
|
if (isPeerWindows) {
|
2022-10-19 09:52:29 +08:00
|
|
|
var loadingTag = "";
|
|
|
|
if (!isLocal) {
|
|
|
|
loadingTag = _ffi.dialogManager.showLoading("Waiting");
|
|
|
|
}
|
2022-10-18 22:56:36 +08:00
|
|
|
try {
|
|
|
|
final fd =
|
2022-10-19 09:52:29 +08:00
|
|
|
await model.fetchDirectory("/", isLocal, isLocal);
|
2022-10-18 22:56:36 +08:00
|
|
|
for (var entry in fd.entries) {
|
|
|
|
menuItems.add(MenuEntryButton(
|
2022-10-19 22:59:02 +08:00
|
|
|
childBuilder: (TextStyle? style) =>
|
|
|
|
Row(children: [
|
2022-10-20 09:31:31 +08:00
|
|
|
Image(
|
|
|
|
image: iconHardDrive,
|
|
|
|
fit: BoxFit.scaleDown,
|
|
|
|
color: Theme.of(context)
|
|
|
|
.iconTheme
|
|
|
|
.color
|
|
|
|
?.withOpacity(0.7)),
|
2022-10-19 22:59:02 +08:00
|
|
|
SizedBox(width: 10),
|
|
|
|
Text(
|
|
|
|
entry.name,
|
|
|
|
style: style,
|
|
|
|
)
|
|
|
|
]),
|
2022-10-18 22:56:36 +08:00
|
|
|
proc: () {
|
2022-11-02 22:48:02 +08:00
|
|
|
openDirectory('${entry.name}\\',
|
|
|
|
isLocal: isLocal);
|
2022-10-19 09:52:29 +08:00
|
|
|
},
|
|
|
|
dismissOnClicked: true));
|
2022-10-18 22:56:36 +08:00
|
|
|
}
|
2022-12-20 22:55:54 +08:00
|
|
|
} catch (e) {
|
|
|
|
debugPrint("buildBread fetchDirectory err=$e");
|
2022-10-18 22:56:36 +08:00
|
|
|
} finally {
|
2022-10-19 09:52:29 +08:00
|
|
|
if (!isLocal) {
|
|
|
|
_ffi.dialogManager.dismissByTag(loadingTag);
|
|
|
|
}
|
2022-10-18 22:56:36 +08:00
|
|
|
}
|
|
|
|
}
|
2022-10-19 22:59:02 +08:00
|
|
|
menuItems.add(MenuEntryDivider());
|
2022-10-18 22:56:36 +08:00
|
|
|
mod_menu.showMenu(
|
|
|
|
context: context,
|
|
|
|
position: RelativeRect.fromLTRB(x, y, x, y),
|
|
|
|
elevation: 4,
|
|
|
|
items: menuItems
|
|
|
|
.map((e) => e.build(
|
|
|
|
context,
|
|
|
|
MenuConfig(
|
|
|
|
commonColor:
|
|
|
|
CustomPopupMenuTheme.commonColor,
|
|
|
|
height: CustomPopupMenuTheme.height,
|
|
|
|
dividerHeight:
|
|
|
|
CustomPopupMenuTheme.dividerHeight,
|
|
|
|
boxWidth: size.width)))
|
|
|
|
.expand((i) => i)
|
|
|
|
.toList());
|
|
|
|
},
|
|
|
|
iconSize: 20,
|
|
|
|
)
|
|
|
|
]);
|
2022-08-16 11:46:51 +08:00
|
|
|
}
|
|
|
|
|
2022-11-02 22:48:02 +08:00
|
|
|
Widget buildWindowsThisPC([TextStyle? textStyle]) {
|
|
|
|
final color = Theme.of(context).iconTheme.color?.withOpacity(0.7);
|
|
|
|
return Row(children: [
|
|
|
|
Icon(Icons.computer, size: 20, color: color),
|
|
|
|
SizedBox(width: 10),
|
|
|
|
Text(translate('This PC'), style: textStyle)
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2022-08-16 11:46:51 +08:00
|
|
|
List<BreadCrumbItem> getPathBreadCrumbItems(
|
|
|
|
bool isLocal, void Function(List<String>) onPressed) {
|
|
|
|
final path = model.getCurrentDir(isLocal).path;
|
|
|
|
final breadCrumbList = List<BreadCrumbItem>.empty(growable: true);
|
2022-12-04 22:44:03 +08:00
|
|
|
final isWindows = model.getCurrentIsWindows(isLocal);
|
|
|
|
if (isWindows && path == '/') {
|
2022-11-02 22:48:02 +08:00
|
|
|
breadCrumbList.add(BreadCrumbItem(
|
|
|
|
content: TextButton(
|
|
|
|
child: buildWindowsThisPC(),
|
|
|
|
style: ButtonStyle(
|
|
|
|
minimumSize: MaterialStateProperty.all(Size(0, 0))),
|
|
|
|
onPressed: () => onPressed(['/']))
|
|
|
|
.marginSymmetric(horizontal: 4)));
|
|
|
|
} else {
|
2022-12-04 22:44:03 +08:00
|
|
|
final list = PathUtil.split(path, isWindows);
|
2022-11-02 22:48:02 +08:00
|
|
|
breadCrumbList.addAll(list.asMap().entries.map((e) => BreadCrumbItem(
|
|
|
|
content: TextButton(
|
|
|
|
child: Text(e.value),
|
|
|
|
style: ButtonStyle(
|
|
|
|
minimumSize: MaterialStateProperty.all(Size(0, 0))),
|
|
|
|
onPressed: () => onPressed(list.sublist(0, e.key + 1)))
|
|
|
|
.marginSymmetric(horizontal: 4))));
|
|
|
|
}
|
2022-08-16 11:46:51 +08:00
|
|
|
return breadCrumbList;
|
|
|
|
}
|
|
|
|
|
2022-08-16 12:28:12 +08:00
|
|
|
breadCrumbScrollToEnd(bool isLocal) {
|
|
|
|
Future.delayed(Duration(milliseconds: 200), () {
|
2022-10-11 08:59:27 +08:00
|
|
|
final breadCrumbScroller = getBreadCrumbScrollController(isLocal);
|
2022-10-13 19:22:11 +08:00
|
|
|
if (breadCrumbScroller.hasClients) {
|
|
|
|
breadCrumbScroller.animateTo(
|
|
|
|
breadCrumbScroller.position.maxScrollExtent,
|
|
|
|
duration: Duration(milliseconds: 200),
|
|
|
|
curve: Curves.fastLinearToSlowEaseIn);
|
|
|
|
}
|
2022-08-16 12:28:12 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-08-16 11:46:51 +08:00
|
|
|
Widget buildPathLocation(bool isLocal) {
|
2022-10-13 09:17:20 +08:00
|
|
|
final searchTextObs = isLocal ? _searchTextLocal : _searchTextRemote;
|
|
|
|
final locationStatus =
|
|
|
|
isLocal ? _locationStatusLocal : _locationStatusRemote;
|
|
|
|
final focusNode = isLocal ? _locationNodeLocal : _locationNodeRemote;
|
2022-10-13 18:57:59 +08:00
|
|
|
final text = locationStatus.value == LocationStatus.pathLocation
|
|
|
|
? model.getCurrentDir(isLocal).path
|
|
|
|
: searchTextObs.value;
|
|
|
|
final textController = TextEditingController(text: text)
|
|
|
|
..selection = TextSelection.collapsed(offset: text.length);
|
2022-10-13 09:17:20 +08:00
|
|
|
return Row(children: [
|
|
|
|
Icon(
|
|
|
|
locationStatus.value == LocationStatus.pathLocation
|
|
|
|
? Icons.folder
|
|
|
|
: Icons.search,
|
|
|
|
color: Theme.of(context).hintColor,
|
|
|
|
).paddingSymmetric(horizontal: 2),
|
|
|
|
Expanded(
|
|
|
|
child: TextField(
|
|
|
|
focusNode: focusNode,
|
|
|
|
decoration: InputDecoration(
|
|
|
|
border: InputBorder.none,
|
|
|
|
isDense: true,
|
|
|
|
prefix: Padding(padding: EdgeInsets.only(left: 4.0))),
|
2022-10-13 18:57:59 +08:00
|
|
|
controller: textController,
|
2022-10-13 09:17:20 +08:00
|
|
|
onSubmitted: (path) {
|
|
|
|
openDirectory(path, isLocal: isLocal);
|
|
|
|
},
|
|
|
|
onChanged: locationStatus.value == LocationStatus.fileSearchBar
|
|
|
|
? (searchText) => onSearchText(searchText, isLocal)
|
|
|
|
: null,
|
|
|
|
))
|
|
|
|
]);
|
2022-08-16 11:46:51 +08:00
|
|
|
}
|
2022-08-16 12:06:54 +08:00
|
|
|
|
|
|
|
onSearchText(String searchText, bool isLocal) {
|
|
|
|
if (isLocal) {
|
2022-10-17 22:09:38 +08:00
|
|
|
_localSelectedItems.clear();
|
2022-08-16 12:28:12 +08:00
|
|
|
_searchTextLocal.value = searchText;
|
2022-08-16 12:06:54 +08:00
|
|
|
} else {
|
2022-10-17 22:09:38 +08:00
|
|
|
_remoteSelectedItems.clear();
|
2022-08-16 12:28:12 +08:00
|
|
|
_searchTextRemote.value = searchText;
|
2022-08-16 12:06:54 +08:00
|
|
|
}
|
|
|
|
}
|
2022-08-16 12:28:12 +08:00
|
|
|
|
|
|
|
openDirectory(String path, {bool isLocal = false}) {
|
2022-12-04 21:41:44 +08:00
|
|
|
model.openDirectory(path, isLocal: isLocal);
|
2022-08-16 12:28:12 +08:00
|
|
|
}
|
2022-08-16 13:28:48 +08:00
|
|
|
|
|
|
|
void handleDragDone(DropDoneDetails details, bool isLocal) {
|
|
|
|
if (isLocal) {
|
|
|
|
// ignore local
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var items = SelectedItems();
|
2022-10-11 08:59:27 +08:00
|
|
|
for (var file in details.files) {
|
2022-08-16 13:28:48 +08:00
|
|
|
final f = File(file.path);
|
|
|
|
items.add(
|
|
|
|
true,
|
|
|
|
Entry()
|
|
|
|
..path = file.path
|
|
|
|
..name = file.name
|
|
|
|
..size =
|
|
|
|
FileSystemEntity.isDirectorySync(f.path) ? 0 : f.lengthSync());
|
2022-10-11 08:59:27 +08:00
|
|
|
}
|
2022-08-16 13:28:48 +08:00
|
|
|
model.sendFiles(items, isRemote: false);
|
|
|
|
}
|
2022-12-13 12:55:41 +08:00
|
|
|
|
|
|
|
void refocusKeyboardListener(bool isLocal) {
|
|
|
|
Future.delayed(Duration.zero, () {
|
|
|
|
if (isLocal) {
|
|
|
|
_keyboardNodeLocal.requestFocus();
|
|
|
|
} else {
|
|
|
|
_keyboardNodeRemote.requestFocus();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2022-06-17 22:57:41 +08:00
|
|
|
}
|