@@ -27,6 +27,18 @@ void touchFile(File file, CCSolution solution) {
27
27
void loadSolution (CCSolution solution, BuildContext context) {
28
28
Navigator .pushNamed (context, EditorPage .routeName, arguments: solution);
29
29
}
30
+ enum HistoryItemType {
31
+ solution,
32
+ singleFile
33
+ }
34
+ class HistoryItem {
35
+ HistoryItemType type;
36
+ CCSolution ? solution;
37
+ String ? filePath;
38
+ DateTime dateModified;
39
+ String name;
40
+ HistoryItem (this .type, {this .solution, this .filePath, required this .dateModified, required this .name});
41
+ }
30
42
31
43
class RecentProjectsManager {
32
44
static RecentProjectsManager ? _instance;
@@ -36,13 +48,16 @@ class RecentProjectsManager {
36
48
return _instance! ;
37
49
}
38
50
39
- List <CCSolution > projects = List .empty (growable: true );
51
+ List <HistoryItem > projects = List .empty (growable: true );
40
52
41
53
/// Commit the recent projects to the pref
42
54
Future <void > commit (Future <SharedPreferences > _pref) async {
43
55
List <String > list = List .empty (growable: true );
44
- for (CCSolution p in projects) {
45
- list.add (p.slnPath);
56
+ for (HistoryItem p in projects) {
57
+ if (p.type == HistoryItemType .solution) {
58
+ list.add (p.solution! .slnPath);
59
+ }
60
+ //TODO: support single file
46
61
}
47
62
(await _pref).setStringList ("recentProjectsSln" , list).then ((bool success) {
48
63
debugPrint ("Success: $success " );
@@ -57,12 +72,14 @@ class RecentProjectsManager {
57
72
Future <CCSolution ?> addSolution (String slnPath) async {
58
73
// Prevent project with same solution to be loaded
59
74
for (var p in projects) {
60
- if (p.slnPath == slnPath) return null ;
75
+ if (p.solution ? . slnPath == slnPath) return null ;
61
76
}
62
77
63
78
var sln = await CCSolution .loadFromFile (slnPath);
79
+
64
80
if (sln != null ) {
65
- projects.add (sln);
81
+ var item = HistoryItem (HistoryItemType .solution, solution: sln, dateModified: sln.dateModified, name: sln.name);
82
+ projects.add (item);
66
83
}
67
84
return sln;
68
85
}
@@ -283,7 +300,7 @@ class _HomePageState extends State<HomePage> {
283
300
await loadPrefs ();
284
301
setState (() {
285
302
projectsWidgets.clear ();
286
- RecentProjectsManager .instance.projects.sort ((CCSolution a, CCSolution b) {
303
+ RecentProjectsManager .instance.projects.sort ((HistoryItem a, HistoryItem b) {
287
304
return b.dateModified.compareTo (a.dateModified);
288
305
});
289
306
if (RecentProjectsManager .instance.projects.isEmpty) {
@@ -294,75 +311,88 @@ class _HomePageState extends State<HomePage> {
294
311
);
295
312
}
296
313
else {
297
- for (CCSolution p in RecentProjectsManager .instance.projects) {
298
- if (p.name == "" ) {
299
- continue ;
300
- } // TODO: add better way to check if project is corrupt
314
+ for (HistoryItem p in RecentProjectsManager .instance.projects) {
315
+ // if (p.name == "") {
316
+ // continue;
317
+ // } // TODO: add better way to check if project is corrupt
301
318
//debugPrint(p.name);
302
319
projectsWidgets.add (Card ( //TODO: refactor this as a widget elsewhere, then reference that widget from here
303
320
child: ListTile (
304
321
onTap: () {
305
- touchFile (File (p.slnPath), p);
306
- refreshRecentProjects ();
307
- loadSolution (p, context);
322
+ if (p.type == HistoryItemType .solution) {
323
+ touchFile (File (p.solution! .slnPath), p.solution! );
324
+ refreshRecentProjects ();
325
+ loadSolution (p.solution! , context);
326
+ }
327
+ //TODO: Handle single file
308
328
},
309
- leading: p.image ??
329
+ leading: p.type == HistoryItemType .solution ? p.solution ! . image ??
310
330
const Icon (
311
331
Icons .insert_drive_file,
312
332
size: 48 ,
313
- ),
333
+ ):
334
+ const Icon (
335
+ Icons .insert_drive_file,
336
+ size: 48 ,
337
+ ),
314
338
title: Text (p.name),
315
339
subtitle: Text (
316
- p.desc + " Last Modified: " + p.dateModified.toString ()),
340
+ (p.type == HistoryItemType .solution? p.solution! .desc : "" )
341
+ + " Last Modified: " + p.dateModified.toString ()),
317
342
trailing: PopupMenuButton <String >(
318
343
onSelected: (String result) {
319
344
switch (result) {
320
345
case "delete" :
321
- showDialog (
322
- context: context,
323
- builder: (BuildContext context) {
324
- return AlertDialog (
325
- title: Text ("Delete ${p .name }?" ),
326
- content: Text (
327
- "This action cannot be undone!\n folders will be deleted: ${() {
328
- String result = "" ;
329
- for (var folder in p .folders .keys ) {
330
- result +=
331
- (p .folders [folder ] as String ) + ", \n " ;
332
- }
333
- return result ;
334
- }()}" ),
335
- actions: [
336
- TextButton (
337
- onPressed: () {
338
- Navigator .pop (context);
339
- },
340
- child: const Text ("No" )),
341
- TextButton (
342
- onPressed: () {
343
- var folders = < String > [];
344
- for (var folder in p.folders.keys) {
345
- folders.add (p.slnFolderPath +
346
- Platform .pathSeparator +
347
- p.folders[folder]! );
346
+ if (p.type == HistoryItemType .solution) {
347
+ showDialog (
348
+ context: context,
349
+ builder: (BuildContext context) {
350
+ return AlertDialog (
351
+ title: Text ("Delete ${p .name }?" ),
352
+ content: Text (
353
+ "This action cannot be undone!\n folders will be deleted: ${() {
354
+ String result = "" ;
355
+ for (var folder in p .solution !.folders .keys ) {
356
+ result +=
357
+ (p .solution !.folders [folder ] as String ) +
358
+ ", \n " ;
348
359
}
349
- deleteFolderWithIndicator (
350
- context, folders);
351
- // Delete the solution file too
352
- File (p.slnPath).deleteSync ();
353
-
354
- // Quit and refresh
355
- Navigator .pop (context);
356
- refreshRecentProjects ();
357
- },
358
- child: const Text (
359
- "Delete" ,
360
- style:
361
- TextStyle (color: Colors .redAccent),
362
- )),
363
- ],
364
- );
365
- });
360
+ return result ;
361
+ }()}" ),
362
+ actions: [
363
+ TextButton (
364
+ onPressed: () {
365
+ Navigator .pop (context);
366
+ },
367
+ child: const Text ("No" )),
368
+ TextButton (
369
+ onPressed: () {
370
+ var folders = < String > [];
371
+ for (var folder in p.solution! .folders.keys) {
372
+ folders.add (p.solution! .slnFolderPath +
373
+ Platform .pathSeparator +
374
+ p.solution! .folders[folder]! );
375
+ }
376
+ deleteFolderWithIndicator (
377
+ context, folders);
378
+ // Delete the solution file too
379
+ File (p.solution! .slnPath).deleteSync ();
380
+
381
+ // Quit and refresh
382
+ Navigator .pop (context);
383
+ refreshRecentProjects ();
384
+ },
385
+ child: const Text (
386
+ "Delete" ,
387
+ style:
388
+ TextStyle (color: Colors .redAccent),
389
+ )),
390
+ ],
391
+ );
392
+ });
393
+ }else {
394
+ //TODO: Handle single file delete
395
+ }
366
396
break ;
367
397
}
368
398
},
0 commit comments