From 25c587c124dcfb5b7f7d09a9fc8718581248ae9f Mon Sep 17 00:00:00 2001 From: Derek Rhodes Date: Sun, 7 May 2017 19:39:53 -0400 Subject: [PATCH] adds a button to select module dependencies of selected modules. --- jade.js | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-) diff --git a/jade.js b/jade.js index 9989d273..c84e39e5 100644 --- a/jade.js +++ b/jade.js @@ -652,11 +652,43 @@ jade_defs.top_level = function(jade) { dialog('Select modules to load',contents,upload,offset); }; + // given a single module name M, generate a set of all the module + // names that M depends on. + function module_deps(mname) { + var depNames = []; + + var allMods = jade.model.json_modules().json; + var allModNames = Object.keys(allMods); + + var findSubMods = function(modName) { + curMod = allMods[modName]; + if (curMod === undefined) throw "module name not found: " + modName; + + schems = curMod.schematic; + if (schems === undefined) return; // atomic unit of jade universe? + + schems.forEach(function(el) { + subName = el[0]; + // is this schematic element a sub module? + if (allModNames.indexOf(subName) == -1) return; // nope. + // has it been processed already? + if (depNames.indexOf(subName) != -1) return; // yep. + // don't export built-ins? + if (subName.startsWith("/gate")) return; + + depNames.push(subName); + findSubMods(subName); + }); + }; + findSubMods(mname); + return depNames; + } + // let user select which modules to export to their Downloads directory function export_modules(j) { var all_modules = jade.model.json_modules().json; var mnames = Object.keys(all_modules).sort(); - + var win; var contents = module_table(mnames); @@ -675,9 +707,37 @@ jade_defs.top_level = function(jade) { // close dialog box window_close(win[0]); }); + + // add a button to checkoff all module dependencies + var depsButton = $(''); + depsButton.on('click',function (e) { + var selected = {}; + var deps = []; + $('input',contents).each(function (index,input) { + input = $(input); + var mname = input.attr('name'); + if (input[0].checked) { + deps = deps.concat(module_deps(mname)); + } + }); + $('input',contents).each(function (index,input) { + input = $(input); + var mname = input.attr('name'); + if (deps.indexOf(mname) != -1) { + input[0].checked = true; + } + }); + + }); + + var doDeps = $('').attr('colspan',$('#select-all',contents).attr('colspan')).append(depsButton); + contents.append($('').append(doDeps)); + var doit = $('').attr('colspan',$('#select-all',contents).attr('colspan')).append(a); contents.append($('').append(doit)); - + + + var offset = $('.jade-tabs-div',j.top_level).offset(); win = jade_window('Export modules', contents, offset); };