Skip to content

Commit ea99720

Browse files
committed
Updated the project creation dialog
1 parent 3924742 commit ea99720

File tree

6 files changed

+232
-68
lines changed

6 files changed

+232
-68
lines changed

android/.idea/.name

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

lib/modules/jsapi.dart

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,18 @@ Map<String, String> jsObjectToDartMap(Pointer _ctxPtr, Pointer jsValueRef) {
9090
return {};
9191
}
9292

93+
List<String> jsArrayToDartStringList(JSObject arr){
94+
var result = <String>[];
95+
var val = arr.toValue();
96+
assert(val.isArray);
97+
JSValuePointer err;
98+
/*var jsval = arr.getPropertyAtIndex(propertyIndex,exception: err);
99+
while(err.pointer != nullptr && err.count == 0) {
100+
var jsval = arr.getPropertyAtIndex(propertyIndex,exception: err);
101+
}*/
102+
return result;
103+
}
104+
93105
class CoreCoder {
94106
static late JsModule module; // set by the parent object
95107
static late JSContext context; // set by the parent object
@@ -259,6 +271,46 @@ class CoreCoder {
259271
260272
}
261273

274+
275+
/// CoreCoder implementation of the OS module
276+
/// Can't name OS because it's already used
277+
class CCOS {
278+
static late JsModule module; // set by the parent object
279+
static late JSContext context; // set by the parent object
280+
static CCOS? _instance;
281+
282+
static CCOS get instance {
283+
_instance ??= CCOS();
284+
return _instance!;
285+
}
286+
287+
void process(
288+
Pointer ctx,
289+
String executable,
290+
List<String> arguments) async {
291+
debugPrint("[JS Process] Running `$executable`");
292+
Process.start(executable, arguments);
293+
}
294+
295+
static Pointer jsProcess(
296+
Pointer ctx,
297+
Pointer function,
298+
Pointer thisObject,
299+
int argumentCount,
300+
Pointer<Pointer> arguments,
301+
Pointer<Pointer> exception) {
302+
String executable = JSString(arguments[0]).string ?? "unknown";
303+
/*var argObj = JSObject(context, arguments[1]);
304+
if(argObj.)
305+
List<String> args = ;
306+
307+
instance.process(ctx, executable,args);*/
308+
return nullptr;
309+
}
310+
311+
}
312+
313+
262314
class FileIO {
263315
static late JsModule module; // set by the parent object
264316
static late JSContext context; // set by the parent object

lib/modules/module_core.dart

Lines changed: 85 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,57 +4,103 @@ import 'package:corecoder_develop/util/modules_manager.dart';
44
import 'package:flutter/material.dart';
55

66
import '../main.dart';
7-
class CoreModule extends Module {
87

8+
class CoreModule extends Module {
99
@override
1010
CoreModule()
11-
: super(
12-
"Built-in",
13-
"Provides core functionality",
14-
"skybird23333",
15-
"Corecoder 0.0.1",
16-
null,
17-
"com.corecoder.coremodule");
11+
: super("Built-in", "Provides core functionality", "skybird23333",
12+
"Corecoder 0.0.1", null, "com.corecoder.coremodule");
1813

1914
@override
20-
void onInitialized(ModulesManager modulesManager, BuildContext buildContext) async {
15+
void onInitialized(
16+
ModulesManager modulesManager, BuildContext buildContext) async {
2117
super.onInitialized(modulesManager, buildContext);
2218
var template = Template(
23-
"Empty", //title
24-
"Empty project with no workspace plugins or files", //desc
19+
"Empty",
20+
//title
21+
"Empty project with no workspace plugins or files",
22+
//desc
2523
"",
2624
{
27-
"Project Name" : "String",
28-
"Author" : "String",
29-
},
30-
(Map<String, dynamic> args) async {
25+
"Project Name": "String",
26+
"Author": "String",
27+
}, (Map<String, dynamic> args) async {
3128
//do absolutely nothing because this is empty
32-
/// ---------------------------
33-
/// Create .ccsln.json file
34-
/// ---------------------------
35-
var obj = {
36-
"cc_version": CoreCoderApp.version,
37-
"name": args["Project Name"],
38-
"author": args["Author"],
39-
"description": "",
40-
"identifier": identifier,
41-
// must be unique to every module
42-
"folders": {
43-
},
44-
"run_config": []
45-
};
46-
obj["folders"]["Workspace"] = ".";
29+
/// ---------------------------
30+
/// Create .ccsln.json file
31+
/// ---------------------------
32+
var obj = {
33+
"cc_version": CoreCoderApp.version,
34+
"name": args["Project Name"],
35+
"author": args["Author"],
36+
"description": "",
37+
"identifier": identifier,
38+
// must be unique to every module
39+
"folders": {},
40+
"run_config": []
41+
};
42+
obj["folders"]["Workspace"] = ".";
4743

44+
// Write the file asynchronously
45+
var slnFilePath =
46+
CoreCoder.getProjectFolder("core", args["Project Name"]) +
47+
"solution.ccsln.json";
48+
var slnFile = File(slnFilePath);
49+
await slnFile.create(recursive: true);
50+
await slnFile.writeAsString(ModulesManager.encoder.convert(obj));
51+
// Return the filepath so it loads the project automatically
52+
return slnFilePath;
53+
}, icon, "com.corecoder.empty");
4854

49-
// Write the file asynchronously
50-
var slnFilePath = CoreCoder.getProjectFolder("core", args["Project Name"]) + "solution.ccsln.json";
51-
var slnFile = File(slnFilePath);
52-
await slnFile.create(recursive: true);
53-
await slnFile.writeAsString(ModulesManager.encoder.convert(obj));
54-
// Return the filepath so it loads the project automatically
55-
return slnFilePath;
56-
},
57-
icon, "com.corecoder.empty");
55+
templates.add(template);
56+
57+
template = Template(
58+
"CoreCoder plugins",
59+
//title
60+
"Extends the capability of CoreCoder using Javascript & HTML",
61+
//desc
62+
CoreCoderApp.version,
63+
{
64+
"Plugins Name": "String|The name of the plugins",
65+
"Plugins Identifier": "String|com.example.something",
66+
"Plugins Version": "String|0.0.1",
67+
"Description": "String",
68+
"Author": "String",
69+
}, (Map<String, dynamic> args) async {
70+
//do absolutely nothing because this is empty
71+
/// ---------------------------
72+
/// Create .ccsln.json file
73+
/// ---------------------------
74+
var obj = {
75+
"cc_version": CoreCoderApp.version,
76+
"name": args["Plugins Name"],
77+
"author": args["Author"],
78+
"description": "",
79+
"identifier": identifier,
80+
// must be unique to every module
81+
"folders": {},
82+
"run_config": []
83+
};
84+
obj["folders"]["Workspace"] = ".";
85+
86+
var manifest = {
87+
"title": args["Plugins Name"],
88+
"version": args["Plugins Version"],
89+
"description": args["Description"],
90+
"author": args["Author"],
91+
"identifier": args["Plugins Identifier"]
92+
};
93+
94+
// Write the file asynchronously
95+
var slnFilePath =
96+
CoreCoder.getProjectFolder("core", args["Plugins Name"]) +
97+
"solution.ccsln.json";
98+
var slnFile = File(slnFilePath);
99+
await slnFile.create(recursive: true);
100+
await slnFile.writeAsString(ModulesManager.encoder.convert(obj));
101+
// Return the filepath so it loads the project automatically
102+
return slnFilePath;
103+
}, icon, "com.corecoder.plugins");
58104

59105
templates.add(template);
60106
}
@@ -63,5 +109,4 @@ class CoreModule extends Module {
63109
List<String> onAutoComplete(String language, String lastToken) {
64110
return [];
65111
}
66-
67112
}

lib/modules/module_jsplugins.dart

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,58 @@ class JsModule extends Module {
9191
malloc.free(ccClassName);
9292
}
9393

94+
void initializeOSJS() {
95+
//TODO: this doesn't use JSCore, which is easier to read, see `initializeCC3JSFileIO`
96+
Pointer<Utf8> ccClassName = 'OS'.toNativeUtf8();
97+
98+
var staticFunctions = JSStaticFunctionPointer.allocateArray([
99+
JSStaticFunctionStruct(
100+
name: 'print'.toNativeUtf8(),
101+
callAsFunction: Pointer.fromFunction(CoreCoder.jsPrint),
102+
attributes: JSPropertyAttributes.kJSPropertyAttributeNone,
103+
),
104+
JSStaticFunctionStruct(
105+
name: 'addTemplate'.toNativeUtf8(),
106+
callAsFunction: Pointer.fromFunction(CoreCoder.jsAddTemplate),
107+
attributes: JSPropertyAttributes.kJSPropertyAttributeNone,
108+
),
109+
JSStaticFunctionStruct(
110+
name: 'getProjectFolder'.toNativeUtf8(),
111+
callAsFunction: Pointer.fromFunction(CoreCoder.jsGetProjectFolder),
112+
attributes: JSPropertyAttributes.kJSPropertyAttributeNone,
113+
),
114+
]);
115+
var definition = JSClassDefinitionPointer.allocate(
116+
version: 0,
117+
attributes: JSClassAttributes.kJSClassAttributeNone,
118+
className: ccClassName,
119+
parentClass: null,
120+
staticValues: null,
121+
staticFunctions: staticFunctions,
122+
initialize: null,
123+
finalize: null,
124+
hasProperty: null,
125+
getProperty: null,
126+
setProperty: null,
127+
deleteProperty: null,
128+
getPropertyNames: null,
129+
callAsFunction: null,
130+
callAsConstructor: null,
131+
hasInstance: null,
132+
convertToType: null,
133+
);
134+
var flutterJSClass = jSClassCreate(definition);
135+
var flutterJSObject = jSObjectMake(_ctxPtr, flutterJSClass, nullptr);
136+
jSObjectSetProperty(
137+
_ctxPtr,
138+
_globalObjPtr,
139+
jSStringCreateWithUTF8CString(ccClassName),
140+
flutterJSObject,
141+
JSPropertyAttributes.kJSPropertyAttributeDontDelete,
142+
nullptr);
143+
malloc.free(ccClassName);
144+
}
145+
94146
void initializeCC3JSFileIO() {
95147
var staticFunctions = <jscore.JSStaticFunction>[
96148
jscore.JSStaticFunction(

lib/screens/homepage/homepage_project_create.dart

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'dart:io';
22
import 'package:corecoder_develop/util/cc_project_structure.dart';
33
import 'package:corecoder_develop/util/modules_manager.dart';
44
import 'package:corecoder_develop/util/theme_manager.dart';
5+
import 'package:flutter/cupertino.dart';
56
import 'package:flutter/material.dart';
67
import 'package:permission_handler/permission_handler.dart';
78
import 'package:shared_preferences/shared_preferences.dart';
@@ -50,31 +51,41 @@ class HomePageProjectCreate extends StatelessWidget {
5051

5152
/// Add Options
5253
for (var argName in t.options.keys) {
53-
controls.add(Text(
54-
argName,
55-
textAlign: TextAlign.end,
56-
));
57-
if (t.options[argName] == "String") {
58-
controls.add(TextField(
59-
maxLines: 1,
60-
autofocus: true,
61-
onChanged: (change) {
62-
values[argName] = change;
63-
}));
54+
controls.add(Row(children: [
55+
const Icon(Icons.subdirectory_arrow_right_outlined),
56+
Text(
57+
argName,
58+
textAlign: TextAlign.start,
59+
)
60+
]));
61+
var optionVal = (t.options[argName] ?? "");
62+
if (optionVal.startsWith("String")) {
63+
var splt = optionVal.split("|");
64+
var hint = splt.length > 1? splt[1] : argName;
65+
controls.add(Padding(
66+
padding: const EdgeInsets.only(bottom: 16.0),
67+
child: TextField(
68+
decoration: InputDecoration(hintText: hint),
69+
maxLines: 1,
70+
autofocus: true,
71+
onChanged: (change) {
72+
values[argName] = change;
73+
})));
6474
values[argName] = "";
6575
}
6676
}
6777

6878
/// Add Buttons
6979
var row = Row(
80+
mainAxisAlignment: MainAxisAlignment.end,
7081
children: [
7182
TextButton(
7283
child: const Text("Cancel"),
7384
onPressed: () {
7485
Navigator.pop(context, 1);
7586
},
7687
),
77-
TextButton(
88+
ElevatedButton(
7889
child: const Text("Create"),
7990
onPressed: () async {
8091
/// Go Ahead and create project asynchronously
@@ -102,8 +113,11 @@ class HomePageProjectCreate extends StatelessWidget {
102113
title: Text('Create ${t.title}'),
103114
children: <Widget>[
104115
Padding(
105-
padding: const EdgeInsets.symmetric(horizontal: 8.0),
106-
child: Column(children: controls))
116+
padding: const EdgeInsets.symmetric(horizontal: 16.0),
117+
child: Column(
118+
children: controls,
119+
crossAxisAlignment: CrossAxisAlignment.stretch,
120+
))
107121
],
108122
);
109123
},

0 commit comments

Comments
 (0)