Auto enable associated plugin on file import
This commit is contained in:
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
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user