Skip to content

Commit 51e04af

Browse files
committed
Load last opened project on startup
1 parent 794fc48 commit 51e04af

File tree

3 files changed

+54
-30
lines changed

3 files changed

+54
-30
lines changed

android/.idea/gradle.xml

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/homepage.dart

Lines changed: 51 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ void touchFile(File file, CCSolution solution) {
2626

2727
void loadSolution(CCSolution solution, BuildContext context) {
2828
Navigator.pushNamed(context, EditorPage.routeName, arguments: solution);
29+
// Save the last solution opened to preferences
30+
SharedPreferences.getInstance()
31+
.then((value) => value.setString("lastOpenedPath", solution.slnPath));
2932
}
3033

3134
enum HistoryItemType { solution, singleFile }
@@ -382,6 +385,25 @@ class _HomePageState extends State<HomePage> {
382385
mm.onFinishedLoading = () {
383386
refreshRecentProjects();
384387
};
388+
389+
/// Check the last opened projects
390+
SharedPreferences.getInstance().then((inst) async {
391+
var isAutoOpen = inst.getBool("openLastProjectOnStartup");
392+
if (isAutoOpen != null && isAutoOpen) {
393+
var val = inst.getString("lastOpenedPath");
394+
debugPrint("Loading last opened $val");
395+
if (val != null) {
396+
if (val.endsWith(".ccsln.json")) {
397+
var sln = await CCSolution.loadFromFile(val);
398+
if (sln != null) {
399+
loadSolution(sln, context);
400+
}
401+
} else {
402+
//TODO: handle loading single file
403+
}
404+
}
405+
}
406+
});
385407
}
386408

387409
@override
@@ -510,35 +532,35 @@ class _HomePageState extends State<HomePage> {
510532
/// ==================
511533
/// The android layout
512534
/// ==================
513-
Padding(
514-
padding: const EdgeInsets.all(16.0),
515-
child: Column(
516-
crossAxisAlignment: CrossAxisAlignment.stretch,
517-
children: [
518-
Row(children: [
519-
const Text(
520-
"Recent Projects",
521-
style: TextStyle(
522-
fontWeight: FontWeight.bold,
523-
fontSize: 24.0,
524-
),
525-
),
526-
const Spacer(flex: 1),
527-
OutlinedButton(
528-
onPressed: () {
529-
refreshRecentProjects();
530-
},
531-
child: const Text("Refresh"),
532-
),
533-
OutlinedButton(
534-
onPressed: () {},
535-
child: const Text("Add"),
536-
),
537-
]),
538-
Column(
539-
children: projectsWidgetList,
540-
)
541-
])),
535+
Padding(
536+
padding: const EdgeInsets.all(16.0),
537+
child: Column(
538+
crossAxisAlignment: CrossAxisAlignment.stretch,
539+
children: [
540+
Row(children: [
541+
const Text(
542+
"Recent Projects",
543+
style: TextStyle(
544+
fontWeight: FontWeight.bold,
545+
fontSize: 24.0,
546+
),
547+
),
548+
const Spacer(flex: 1),
549+
OutlinedButton(
550+
onPressed: () {
551+
refreshRecentProjects();
552+
},
553+
child: const Text("Refresh"),
554+
),
555+
OutlinedButton(
556+
onPressed: () {},
557+
child: const Text("Add"),
558+
),
559+
]),
560+
Column(
561+
children: projectsWidgetList,
562+
)
563+
])),
542564
));
543565
return Scaffold(
544566
appBar: CoreCoderApp.isLandscape(context)

lib/main.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'dart:io';
22

33
import 'package:corecoder_develop/editor.dart';
44
import 'package:corecoder_develop/plugins_browser.dart';
5+
import 'package:corecoder_develop/util/cc_project_structure.dart';
56
import 'package:corecoder_develop/util/theme_manager.dart';
67
import 'package:flutter/material.dart';
78
import 'package:flutter/services.dart';
@@ -69,6 +70,8 @@ class CoreCoderAppState extends State<CoreCoderApp> {
6970
debugPrint(result as String);
7071
});
7172
}
73+
74+
7275
}
7376
static final Future<SharedPreferences> _pref =
7477
SharedPreferences.getInstance();

0 commit comments

Comments
 (0)