Skip to content

Commit 4032108

Browse files
committed
Refresh recent projects icon after module loaded
1 parent 0da27c7 commit 4032108

File tree

3 files changed

+51
-25
lines changed

3 files changed

+51
-25
lines changed

lib/editor.dart

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,14 @@ class _EditorPageState extends State<EditorPage> {
168168
debugPrint(content);
169169
content = content.replaceAll("\t", " ");
170170
setState(() {
171-
tabs.add(createFileTab(filename, content, 'json'));
171+
var language = 'javascript';
172+
if(filename.endsWith(".json")){
173+
language = 'json';
174+
}
175+
if(filename.endsWith(".lua")){
176+
language = 'lua';
177+
}
178+
tabs.add(createFileTab(filename, content, language));
172179
});
173180
}
174181

@@ -179,10 +186,6 @@ class _EditorPageState extends State<EditorPage> {
179186
// Populate the file browser tree once
180187
initializeTreeView();
181188
}
182-
final codeBox = InnerField(
183-
language: 'json',
184-
theme: ThemeManager.getHighlighting(),
185-
source: project.name);
186189
final page = Column(//direction: Axis.vertical,
187190
children: [
188191
Expanded(

lib/homepage.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,11 @@ class _HomePageState extends State<HomePage> {
227227
void initState() {
228228
super.initState();
229229
mm = ModulesManager(context);
230-
refreshRecentProjects();
230+
231+
mm.initialize(context);
232+
mm.onFinishedLoading = (){
233+
refreshRecentProjects();
234+
};
231235
}
232236

233237
@override

lib/util/modules_manager.dart

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,41 @@ import 'dart:typed_data';
44
import 'package:corecoder_develop/modules/module_minecraft.dart';
55
import 'package:corecoder_develop/util/plugins_manager.dart';
66
import 'package:flutter/material.dart';
7-
class ModulesManager{
7+
8+
class ModulesManager {
89
static List<Module> internalModules = List.empty(growable: true);
910
static List<Module> externalModules = List.empty(growable: true);
10-
static List<Module> get modules{
11+
Function? onFinishedLoading;
12+
13+
static List<Module> get modules {
1114
return List.from(internalModules)..addAll(externalModules);
1215
}
16+
1317
static const JsonDecoder decoder = JsonDecoder();
1418
static const JsonEncoder encoder = JsonEncoder.withIndent('\t');
15-
void initialize(BuildContext context) async {
16-
await PluginsManager.reloadPlugins(this,context);
19+
20+
Future<void> initialize(BuildContext context) async {
21+
await PluginsManager.reloadPlugins(this, context);
1722
}
1823

19-
void onInitialized(BuildContext context){ /// called by PluginsManager so the timing is right
24+
void onInitialized(BuildContext context) {
25+
/// called by PluginsManager so the timing is right
2026
debugPrint("Initializing modules (${modules.length})");
2127
for (Module m in modules) {
2228
m.onInitialized(this, context);
2329
}
30+
if (onFinishedLoading != null) {
31+
onFinishedLoading!();
32+
}
2433
}
2534

2635
ModulesManager(BuildContext context) {
2736
internalModules.add(MinecraftModule());
28-
initialize(context);
2937
}
3038

31-
static Module? getModuleByIdentifier(String id){
32-
for(var m in modules){
33-
if(m.identifier == id){
39+
static Module? getModuleByIdentifier(String id) {
40+
for (var m in modules) {
41+
if (m.identifier == id) {
3442
return m;
3543
}
3644
}
@@ -48,7 +56,8 @@ class ModulesManager{
4856
return null;
4957
}
5058
}
51-
class Template{
59+
60+
class Template {
5261
String title = "Template.Title",
5362
desc = "Template.Desc",
5463
version = "Template.Version",
@@ -61,22 +70,32 @@ class Template{
6170
this.icon, this.identifier);
6271
}
6372

64-
abstract class Module{
73+
abstract class Module {
6574
List<Template> templates = List.empty(growable: true);
66-
String name="Module.name", desc="Module.desc", author="Module.author", version="Module.version";
75+
String name = "Module.name",
76+
desc = "Module.desc",
77+
author = "Module.author",
78+
version = "Module.version";
6779
Uint8List? imageRaw;
68-
Widget get icon{
69-
if(imageRaw != null) {
80+
81+
Widget get icon {
82+
if (imageRaw != null) {
7083
return Image(
71-
image: ResizeImage.resizeIfNeeded(48, 48, Image.memory(imageRaw!).image));
84+
image: ResizeImage.resizeIfNeeded(
85+
48, 48, Image.memory(imageRaw!).image));
7286
}
7387
return const Icon(Icons.insert_drive_file);
7488
}
89+
7590
String identifier;
76-
Module(this.name, this.desc, this.author, this.version, this.imageRaw, this.identifier);
91+
92+
Module(this.name, this.desc, this.author, this.version, this.imageRaw,
93+
this.identifier);
94+
7795
void onInitialized(ModulesManager modulesManager, BuildContext buildContext);
78-
void addTemplate(Template template){
96+
97+
void addTemplate(Template template) {
7998
templates.add(template);
8099
}
81-
//TODO: void onGetAutoComplete(...)
82-
}
100+
//TODO: void onGetAutoComplete(...)
101+
}

0 commit comments

Comments
 (0)