This commit is contained in:
@@ -1,13 +1,19 @@
|
||||
import "package:flutter/material.dart";
|
||||
import "package:process_run/which.dart";
|
||||
import "package:prod/models/rand.dart";
|
||||
|
||||
class Editor {
|
||||
final String id;
|
||||
final String name;
|
||||
final String command;
|
||||
final String commandTemplate;
|
||||
// final Icon icon;
|
||||
|
||||
const Editor(this.name, this.command, this.commandTemplate);
|
||||
const Editor(this.name, this.command, this.commandTemplate, this.id);
|
||||
|
||||
factory Editor.create(String name, String command, String commandTemplate) {
|
||||
return Editor(name, command, commandTemplate, getRandomString(5));
|
||||
}
|
||||
|
||||
bool validateCommand() {
|
||||
final String? fullPath = whichSync(command);
|
||||
@@ -17,4 +23,29 @@ class Editor {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
"name": name,
|
||||
"command": command,
|
||||
"commandTemplate": commandTemplate,
|
||||
"id": id,
|
||||
};
|
||||
}
|
||||
|
||||
factory Editor.fromJson(Map<String, dynamic> data) {
|
||||
if (!data.containsKey("name") ||
|
||||
!data.containsKey("command") ||
|
||||
!data.containsKey("commandTemplate") ||
|
||||
!data.containsKey("id")) {
|
||||
print("Found invalid editor config when parsing: $data");
|
||||
return Editor("null", "null", "null", "null");
|
||||
}
|
||||
return Editor(
|
||||
data["name"] as String,
|
||||
data["command"] as String,
|
||||
data["commandTemplate"] as String,
|
||||
data["id"] as String,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user