Auto enable associated plugin on file import

This commit is contained in:
luboslenco
2021-01-08 15:18:41 +01:00
parent d67881540c
commit 43562d6079
12 changed files with 153 additions and 120 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+10
View File
@@ -256,4 +256,14 @@ class Config {
UISidebar.inst.tagUIRedraw();
}
}
public static function enablePlugin(f: String) {
raw.plugins.push(f);
Plugin.start(f);
}
public static function disablePlugin(f: String) {
raw.plugins.remove(f);
Plugin.stop(f);
}
}
+17
View File
@@ -24,6 +24,7 @@ import arm.ui.UIToolbar;
import arm.ui.UINodes;
import arm.ui.UIView2D;
import arm.ui.UIHeader;
import arm.ui.BoxPreferences;
import arm.node.MakeMaterial;
import arm.Enums;
import arm.ProjectFormat;
@@ -434,4 +435,20 @@ class Context {
MakeMaterial.parseMeshMaterial();
});
}
public static function enableImportPlugin(file: String): Bool {
// Return plugin name suitable for importing the specified file
if (BoxPreferences.filesPlugin == null) {
BoxPreferences.fetchPlugins();
}
var ext = file.substr(file.lastIndexOf(".") + 1);
for (f in BoxPreferences.filesPlugin) {
if (f.indexOf(ext) >= 0) {
Config.enablePlugin(f);
Log.info(f + " " + tr("plugin enabled"));
return true;
}
}
return false;
}
}
+6 -1
View File
@@ -43,7 +43,12 @@ class ImportAsset {
ImportFolder.run(path);
}
else {
Log.error(Strings.error1());
if (Context.enableImportPlugin(path)) {
run(path, dropX, dropY, showBox);
}
else {
Log.error(Strings.error1());
}
}
}
}
+4 -2
View File
@@ -23,8 +23,10 @@ class ImportMesh {
public static function run(path: String, _clearLayers = true, _replaceExisting = true) {
if (!Path.isMesh(path)) {
Log.error(Strings.error1());
return;
if (!Context.enableImportPlugin(path)) {
Log.error(Strings.error1());
return;
}
}
clearLayers = _clearLayers;
+4 -2
View File
@@ -10,8 +10,10 @@ class ImportTexture {
public static function run(path: String) {
if (!Path.isTexture(path)) {
Log.error(Strings.error1());
return;
if (!Context.enableImportPlugin(path)) {
Log.error(Strings.error1());
return;
}
}
for (a in Project.assets) {
+6 -9
View File
@@ -486,7 +486,7 @@ plugin.drawUI = function(ui) {
ui.endSticky();
if (filesPlugin == null) {
filesPlugin = File.readDirectory(Path.data() + Path.sep + "plugins");
fetchPlugins();
}
if (Config.raw.plugins == null) Config.raw.plugins = [];
@@ -500,14 +500,7 @@ plugin.drawUI = function(ui) {
var tag = isJs ? f.split(".")[0] : f;
ui.check(h, tag);
if (h.changed && h.selected != enabled) {
if (h.selected) {
Config.raw.plugins.push(f);
Plugin.start(f);
}
else {
Config.raw.plugins.remove(f);
Plugin.stop(f);
}
h.selected ? Config.enablePlugin(f) : Config.disablePlugin(f);
App.redrawUI();
}
if (ui.isHovered && ui.inputReleasedR) {
@@ -559,6 +552,10 @@ plugin.drawUI = function(ui) {
}
}
public static function fetchPlugins() {
filesPlugin = File.readDirectory(Path.data() + Path.sep + "plugins");
}
public static function getThemeIndex(): Int {
return themes.indexOf(Config.raw.theme.substr(0, Config.raw.theme.length - 5)); // Strip .json
}