Skip to content

Commit ecc858e

Browse files
committed
files: Add initial directory with cmd args
1 parent 01ec113 commit ecc858e

File tree

3 files changed

+29
-13
lines changed

3 files changed

+29
-13
lines changed

lib/main.dart

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,16 @@ import 'package:flutter/material.dart';
2323
import 'package:yaru/yaru.dart';
2424
import 'package:yaru_widgets/yaru_widgets.dart';
2525

26-
Future<void> main() async {
26+
Future<void> main(List<String> args) async {
2727
WidgetsFlutterBinding.ensureInitialized();
2828
await YaruWindowTitleBar.ensureInitialized();
2929
await YaruWindow.ensureInitialized();
3030
await initProviders();
3131
await driveProvider.init();
3232

33-
runApp(const Files());
33+
final String? initialDir = args.isNotEmpty ? args.first : null;
34+
35+
runApp(Files(initialDir: initialDir));
3436
}
3537

3638
ThemeData? _applyThemeValues(ThemeData? theme) {
@@ -46,7 +48,9 @@ ThemeData? _applyThemeValues(ThemeData? theme) {
4648
}
4749

4850
class Files extends StatelessWidget {
49-
const Files({super.key});
51+
final String? initialDir;
52+
53+
const Files({this.initialDir, super.key});
5054

5155
@override
5256
Widget build(BuildContext context) {
@@ -60,23 +64,27 @@ class Files extends StatelessWidget {
6064
scrollbars: false,
6165
),
6266
debugShowCheckedModeBanner: false,
63-
home: const FilesHome(),
67+
home: FilesHome(initialDir: initialDir),
6468
);
6569
},
6670
);
6771
}
6872
}
6973

7074
class FilesHome extends StatefulWidget {
71-
const FilesHome({super.key});
75+
final String? initialDir;
76+
77+
const FilesHome({this.initialDir, super.key});
7278

7379
@override
7480
_FilesHomeState createState() => _FilesHomeState();
7581
}
7682

7783
class _FilesHomeState extends State<FilesHome> {
7884
late final List<WorkspaceController> workspaces = [
79-
WorkspaceController(initialDir: folderProvider.destinations.first.path),
85+
WorkspaceController(
86+
initialDir: widget.initialDir ?? folderProvider.destinations.first.path,
87+
),
8088
];
8189
int currentWorkspace = 0;
8290

@@ -90,6 +98,7 @@ class _FilesHomeState extends State<FilesHome> {
9098
children: [
9199
GestureDetector(
92100
onPanStart: (details) => YaruWindow.drag(context),
101+
onSecondaryTap: () => YaruWindow.showMenu(context),
93102
child: SizedBox(
94103
height: 56,
95104
child: TabStrip(

lib/widgets/side_pane.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'dart:io';
2+
13
import 'package:files/backend/folder_provider.dart';
24
import 'package:files/backend/workspace.dart';
35
import 'package:files/widgets/context_menu.dart';
@@ -85,8 +87,12 @@ class _SidePaneState extends State<SidePane> {
8587
),
8688
ContextMenuItem(
8789
child: const Text("Open in new window"),
88-
onTap: () {},
89-
enabled: false,
90+
onTap: () async {
91+
await Process.start(
92+
Platform.resolvedExecutable,
93+
[widget.destinations[index].path],
94+
);
95+
},
9096
),
9197
],
9298
child: YaruMasterTile(

lib/widgets/tab_strip.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ class TabStrip extends StatelessWidget {
3030
return SizedBox.expand(
3131
child: Row(
3232
children: [
33-
const SizedBox(width: 8),
34-
YaruOptionButton(
35-
onPressed: onNewTab,
36-
child: const Icon(YaruIcons.plus),
37-
),
3833
Expanded(
3934
child: ListView.separated(
4035
itemBuilder: (context, index) => ContextMenu(
@@ -64,6 +59,12 @@ class TabStrip extends StatelessWidget {
6459
padding: const EdgeInsets.all(8),
6560
),
6661
),
62+
const SizedBox(width: 8),
63+
YaruOptionButton(
64+
onPressed: onNewTab,
65+
child: const Icon(YaruIcons.plus),
66+
),
67+
const SizedBox(width: 8),
6768
if (trailing.isNotEmpty)
6869
const VerticalDivider(
6970
indent: 12,

0 commit comments

Comments
 (0)