Files
Prod/lib/models/editor.dart
Phani Pavan K 85bc4450f9
All checks were successful
Build CI / Build (linux-arm64) (push) Successful in 1m48s
Build CI / Build (linux-amd64) (push) Successful in 7m3s
beautified editor list
2026-02-13 19:54:45 +05:30

66 lines
1.5 KiB
Dart

import "package:flutter/material.dart";
import "package:process_run/which.dart";
import "package:prod/models/rand.dart";
class Editor {
final String id;
final String sname;
final String name;
final String command;
final String commandTemplate;
// final Icon icon;
const Editor(
this.sname,
this.name,
this.command,
this.commandTemplate,
this.id,
);
factory Editor.create(String name, String command, String commandTemplate) {
return Editor(
"${name.substring(0, 1).toUpperCase()}${name.substring(1, 2).toLowerCase()}",
name,
command,
commandTemplate,
getRandomString(5),
);
}
bool validateCommand() {
final String? fullPath = whichSync(command);
if (fullPath == null) {
return false;
} else {
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["sname"] as String,
data["name"] as String,
data["command"] as String,
data["commandTemplate"] as String,
data["id"] as String,
);
}
}