Skip to content

Commit 4166d0a

Browse files
committed
files: Cleanup main.dart
Moved some a n c i e n t stuff (we talking about Flux ancient)
1 parent 710b158 commit 4166d0a

File tree

7 files changed

+57
-79
lines changed

7 files changed

+57
-79
lines changed

lib/backend/entity_info.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
//credits: @HrX03 for API https://github.com/HrX03/Flux
18-
1917
import 'dart:io';
2018

2119
import 'package:files/backend/database/model.dart';

lib/backend/folder_provider.dart

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,20 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
//credits: @HrX03 for API https://github.com/HrX03/Flux
18-
1917
import 'dart:io';
2018

2119
import 'package:collection/collection.dart';
20+
import 'package:files/backend/utils.dart';
2221
import 'package:flutter/material.dart';
2322
import 'package:windows_path_provider/windows_path_provider.dart';
2423
import 'package:xdg_directories/xdg_directories.dart';
2524

2625
class FolderProvider {
2726
final List<BuiltinFolder> _folders;
27+
final List<SideDestination> _destinations;
2828

2929
List<BuiltinFolder> get folders => List.from(_folders);
30+
List<SideDestination> get destinations => List.from(_destinations);
3031

3132
static Future<FolderProvider> init() async {
3233
final List<BuiltinFolder> folders = [];
@@ -71,10 +72,19 @@ class FolderProvider {
7172
throw Exception("Platform not supported");
7273
}
7374

74-
return FolderProvider._(folders);
75+
final List<SideDestination> destinations = [
76+
for (final BuiltinFolder element in folders)
77+
SideDestination(
78+
_icons[element.type]!,
79+
Utils.getEntityName(element.directory.path),
80+
element.directory.path,
81+
),
82+
];
83+
84+
return FolderProvider._(folders, destinations);
7585
}
7686

77-
const FolderProvider._(this._folders);
87+
const FolderProvider._(this._folders, this._destinations);
7888

7989
IconData getIconForType(FolderType type) {
8090
return _icons[type]!;
@@ -110,6 +120,14 @@ class BuiltinFolder {
110120
const BuiltinFolder(this.type, this.directory);
111121
}
112122

123+
class SideDestination {
124+
final IconData icon;
125+
final String label;
126+
final String path;
127+
128+
const SideDestination(this.icon, this.label, this.path);
129+
}
130+
113131
const Map<FolderType, IconData> _icons = {
114132
FolderType.home: Icons.home_filled,
115133
FolderType.desktop: Icons.desktop_windows,

lib/main.dart

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
import 'package:files/backend/folder_provider.dart';
1817
import 'package:files/backend/providers.dart';
19-
import 'package:files/backend/utils.dart';
2018
import 'package:files/backend/workspace.dart';
2119
import 'package:files/widgets/side_pane.dart';
2220
import 'package:files/widgets/tab_strip.dart';
@@ -86,35 +84,19 @@ class FilesHome extends StatefulWidget {
8684
}
8785

8886
class _FilesHomeState extends State<FilesHome> {
89-
final List<SideDestination> sideDestinations = [];
90-
final List<WorkspaceController> workspaces = [];
91-
final PageStorageBucket bucket = PageStorageBucket();
87+
late final List<WorkspaceController> workspaces = [
88+
WorkspaceController(initialDir: folderProvider.destinations.first.path),
89+
];
9290
int currentWorkspace = 0;
9391

9492
String get currentDir => workspaces[currentWorkspace].currentDir;
9593

96-
@override
97-
void initState() {
98-
super.initState();
99-
for (final BuiltinFolder element in folderProvider.folders) {
100-
sideDestinations.add(
101-
SideDestination(
102-
folderProvider.getIconForType(element.type),
103-
Utils.getEntityName(element.directory.path),
104-
element.directory.path,
105-
),
106-
);
107-
}
108-
workspaces
109-
.add(WorkspaceController(initialDir: sideDestinations.first.path));
110-
}
111-
11294
@override
11395
Widget build(BuildContext context) {
11496
return Row(
11597
children: [
11698
SidePane(
117-
destinations: sideDestinations,
99+
destinations: folderProvider.destinations,
118100
workspace: workspaces[currentWorkspace],
119101
onNewTab: (String tabPath) {
120102
workspaces.add(WorkspaceController(initialDir: tabPath));

lib/widgets/side_pane.dart

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:files/backend/folder_provider.dart';
12
import 'package:files/backend/workspace.dart';
23
import 'package:files/widgets/context_menu.dart';
34
import 'package:flutter/material.dart';
@@ -91,11 +92,3 @@ class _SidePaneState extends State<SidePane> {
9192
);
9293
}
9394
}
94-
95-
class SideDestination {
96-
final IconData icon;
97-
final String label;
98-
final String path;
99-
100-
const SideDestination(this.icon, this.label, this.path);
101-
}

lib/widgets/table.dart

Lines changed: 21 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import 'package:filesize/filesize.dart';
1111
import 'package:flutter/material.dart';
1212
import 'package:intl/intl.dart';
1313
import 'package:path/path.dart' as p;
14+
import 'package:recase/recase.dart';
1415

1516
typedef HeaderTapCallback = void Function(
1617
bool newAscending,
@@ -161,47 +162,6 @@ class FilesTable extends StatelessWidget {
161162
}
162163

163164
Widget _buildHeaderCell(FilesColumn column, int index) {
164-
late Widget child;
165-
166-
switch (column.type) {
167-
case FilesColumnType.name:
168-
child = const Text(
169-
"Name",
170-
overflow: TextOverflow.ellipsis,
171-
);
172-
break;
173-
case FilesColumnType.date:
174-
child = const Text(
175-
"Date",
176-
overflow: TextOverflow.ellipsis,
177-
);
178-
break;
179-
case FilesColumnType.type:
180-
child = const Text(
181-
"Type",
182-
overflow: TextOverflow.ellipsis,
183-
);
184-
break;
185-
case FilesColumnType.size:
186-
child = const Text(
187-
"Size",
188-
overflow: TextOverflow.ellipsis,
189-
);
190-
break;
191-
}
192-
child = SizedBox.expand(
193-
child: Row(
194-
children: [
195-
Expanded(child: child),
196-
if (columnIndex == index)
197-
Icon(
198-
ascending ? Icons.arrow_downward : Icons.arrow_upward,
199-
size: 16,
200-
),
201-
],
202-
),
203-
);
204-
205165
final double startPadding = index == 0 ? rowHorizontalPadding : 0;
206166

207167
return InkWell(
@@ -231,7 +191,23 @@ class FilesTable extends StatelessWidget {
231191
start: index == 0 ? rowHorizontalPadding : 8,
232192
end: 8,
233193
),
234-
child: child,
194+
child: SizedBox.expand(
195+
child: Row(
196+
children: [
197+
Expanded(
198+
child: Text(
199+
column.type.formattedName,
200+
overflow: TextOverflow.ellipsis,
201+
),
202+
),
203+
if (columnIndex == index)
204+
Icon(
205+
ascending ? Icons.arrow_downward : Icons.arrow_upward,
206+
size: 16,
207+
),
208+
],
209+
),
210+
),
235211
),
236212
),
237213
PositionedDirectional(
@@ -276,7 +252,9 @@ enum FilesColumnType {
276252
name,
277253
date,
278254
type,
279-
size,
255+
size;
256+
257+
String get formattedName => this.name.sentenceCase;
280258
}
281259

282260
class FilesRow {

pubspec.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,14 @@ packages:
499499
url: "https://pub.dev"
500500
source: hosted
501501
version: "1.2.2"
502+
recase:
503+
dependency: "direct main"
504+
description:
505+
name: recase
506+
sha256: e4eb4ec2dcdee52dcf99cb4ceabaffc631d7424ee55e56f280bc039737f89213
507+
url: "https://pub.dev"
508+
source: hosted
509+
version: "4.1.0"
502510
shelf:
503511
dependency: transitive
504512
description:

pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ dependencies:
2626
path_provider: ^2.0.2
2727
provider: ^6.0.0
2828

29+
recase: ^4.1.0
2930
ubuntu_service: ^0.2.0
3031
url_launcher: any
3132
windows_path_provider:

0 commit comments

Comments
 (0)