Skip to content

Commit 98b5fa2

Browse files
committed
Implemented adding external projects
1 parent c97257f commit 98b5fa2

File tree

5 files changed

+97
-35
lines changed

5 files changed

+97
-35
lines changed

android/.idea/gradle.xml

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

lib/screens/homepage/homepage.dart

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,13 @@ class _HomePageState extends State<HomePage> {
200200
//TODO: Handle single file delete
201201
}
202202
break;
203+
case "remove":
204+
setState(() {
205+
/// Remove item from the list without deleting the actual file
206+
RecentProjectsManager.instance.projects.remove(p);
207+
RecentProjectsManager.staticCommit();
208+
});
209+
break;
203210
}
204211
},
205212
itemBuilder: (BuildContext context) => <PopupMenuEntry<String>>[
@@ -217,6 +224,10 @@ class _HomePageState extends State<HomePage> {
217224
value: "export",
218225
child: Text('Export Project'),
219226
),
227+
const PopupMenuItem<String>(
228+
//TODO: Implement this menu
229+
value: "remove",
230+
child: Text('Remove from list')),
220231
],
221232
))));
222233
// IconButton(
@@ -471,8 +482,18 @@ class _HomePageState extends State<HomePage> {
471482
});
472483
}
473484

474-
//TODO: Implement add project
475-
void onAddProject() {}
485+
/// Add project from a specific folder path
486+
/// Called from ProjectList
487+
void onAddProject(String path) async {
488+
CCSolution? sln = await CCSolution.loadFromFile(path);
489+
if(sln != null){
490+
await RecentProjectsManager.instance.addSolution(path);
491+
setState(() {
492+
RecentProjectsManager.staticCommit();
493+
});
494+
loadSolution(sln, context);
495+
}
496+
}
476497

477498
@override
478499
Widget build(BuildContext context) {
Lines changed: 57 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,66 @@
11
import 'package:flutter/material.dart';
2+
import 'package:file_picker/file_picker.dart';
23

3-
class ProjectList extends StatelessWidget{
4+
class ProjectList extends StatelessWidget {
45
final Function onRefresh;
5-
final Function onAddProject;
6+
final Function(String) onAddProject;
67
final List<Widget> children;
7-
const ProjectList({Key? key,required this.onRefresh, required this.onAddProject, required this.children}) : super(key: key);
8+
9+
const ProjectList(
10+
{Key? key,
11+
required this.onRefresh,
12+
required this.onAddProject,
13+
required this.children})
14+
: super(key: key);
15+
816
@override
917
Widget build(BuildContext context) {
1018
return Padding(
1119
padding: const EdgeInsets.all(16.0),
12-
child: Column(
13-
crossAxisAlignment: CrossAxisAlignment.stretch,
14-
children: [
15-
Row(children: [
16-
const Text(
17-
"Recent Projects",
18-
style: TextStyle(
19-
fontWeight: FontWeight.bold,
20-
fontSize: 24.0,
21-
),
22-
),
23-
const Spacer(flex: 1),
24-
OutlinedButton(
25-
onPressed: () {
26-
onRefresh();
27-
},
28-
child: const Text("Refresh"),
29-
),
30-
const SizedBox(width: 4,),
31-
OutlinedButton(
32-
onPressed: () {},
33-
child: const Text("Open"),
34-
),
35-
]),
36-
Column(
37-
children: children,
38-
)
39-
]));
40-
}
20+
child:
21+
Column(crossAxisAlignment: CrossAxisAlignment.stretch, children: [
22+
Row(children: [
23+
const Text(
24+
"Recent Projects",
25+
style: TextStyle(
26+
fontWeight: FontWeight.bold,
27+
fontSize: 24.0,
28+
),
29+
),
30+
const Spacer(flex: 1),
31+
OutlinedButton(
32+
onPressed: () {
33+
onRefresh();
34+
},
35+
child: const Text("Refresh"),
36+
),
37+
const SizedBox(
38+
width: 4,
39+
),
40+
OutlinedButton(
41+
onPressed: () async {
42+
FilePickerResult? result =
43+
await FilePicker.platform.pickFiles(
44+
allowMultiple: false
45+
);
4146

42-
}
47+
if (result != null) {
48+
var path = result.files.single.path;
49+
if(path != null) {
50+
onAddProject(path);
51+
}else{
52+
debugPrint("[Open Project] error: the resulting path is null");
53+
}
54+
} else {
55+
// User canceled the picker
56+
}
57+
},
58+
child: const Text("Open"),
59+
),
60+
]),
61+
Column(
62+
children: children,
63+
)
64+
]));
65+
}
66+
}

pubspec.lock

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,13 @@ packages:
141141
url: "https://pub.dartlang.org"
142142
source: hosted
143143
version: "1.0.0"
144+
file_picker:
145+
dependency: "direct main"
146+
description:
147+
name: file_picker
148+
url: "https://pub.dartlang.org"
149+
source: hosted
150+
version: "4.3.0"
144151
flutter:
145152
dependency: "direct main"
146153
description: flutter
@@ -167,6 +174,13 @@ packages:
167174
url: "https://pub.dartlang.org"
168175
source: hosted
169176
version: "1.0.4"
177+
flutter_plugin_android_lifecycle:
178+
dependency: transitive
179+
description:
180+
name: flutter_plugin_android_lifecycle
181+
url: "https://pub.dartlang.org"
182+
source: hosted
183+
version: "2.0.5"
170184
flutter_test:
171185
dependency: "direct dev"
172186
description: flutter

pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ dependencies:
6161
archive: ^3.1.6
6262
android_intent_plus: ^3.0.2
6363
bitsdojo_window: ^0.1.1+1
64+
file_picker: ^4.3.0
6465

6566
dev_dependencies:
6667
flutter_test:

0 commit comments

Comments
 (0)