Config sections, multi-field values, toggles, etc

- Auto-detect “switchable” items where possible
- Handle switchable multi-value fields
- Add standard sections to config form
- Add section markers to configurations
- Add value options to configurations
- Remove and re-add fields for loaded configs
- Preserve sections across configs
- Preserve non-added fields
- Style added fields wider & newline by default
master
Scott Lahteine 10 years ago
parent ec53c6309a
commit 83cb702e72

@ -35,6 +35,8 @@ Here are some standard links for getting your machine calibrated:
// example_configurations/SCARA directory.
//
// @section info
// User-specified version info of this build to display in [Pronterface, etc] terminal window during
// startup. Implementation of an idea by Prof Braino to inform user that any changes made to this
// build by the user have been successfully uploaded into firmware.
@ -45,6 +47,8 @@ Here are some standard links for getting your machine calibrated:
#define STRING_SPLASH_LINE1 "v" STRING_VERSION // will be shown during bootup in line 1
//#define STRING_SPLASH_LINE2 STRING_VERSION_CONFIG_H // will be shown during bootup in line2
// @section machine
// SERIAL_PORT selects which serial port should be used for communication with the host.
// This allows the connection of wireless adapters (for instance) to non-default port pins.
// Serial port 0 is still used by the Arduino bootloader regardless of this setting.
@ -84,6 +88,8 @@ Here are some standard links for getting your machine calibrated:
// Define this to have the electronics keep the power supply off on startup. If you don't know what this is leave it.
// #define PS_DEFAULT_OFF
// @section temperature
//===========================================================================
//============================= Thermal Settings ============================
//===========================================================================
@ -237,6 +243,7 @@ Here are some standard links for getting your machine calibrated:
// FIND YOUR OWN: "M303 E-1 C8 S90" to run autotune on the bed at 90 degreesC for 8 cycles.
#endif // PIDTEMPBED
// @section extruder
//this prevents dangerous Extruder moves, i.e. if the temperature is under the limit
//can be software-disabled for whatever purposes by
@ -291,9 +298,13 @@ your extruder heater takes 2 minutes to hit the target on heating.
//============================= Mechanical Settings =========================
//===========================================================================
// @section machine
// Uncomment the following line to enable CoreXY kinematics
// #define COREXY
// @section homing
// coarse Endstop Settings
#define ENDSTOPPULLUPS // Comment this out (using // at the start of the line) to disable the endstop pullup resistors
@ -326,33 +337,51 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of
//#define DISABLE_MAX_ENDSTOPS
//#define DISABLE_MIN_ENDSTOPS
// @section hidden
// Disable max endstops for compatibility with endstop checking routine
#if defined(COREXY) && !defined(DISABLE_MAX_ENDSTOPS)
#define DISABLE_MAX_ENDSTOPS
#endif
// @section homing
// For Inverting Stepper Enable Pins (Active Low) use 0, Non Inverting (Active High) use 1
// :[0,1]
#define X_ENABLE_ON 0
#define Y_ENABLE_ON 0
#define Z_ENABLE_ON 0
#define E_ENABLE_ON 0 // For all extruders
// @section machine
// Disables axis when it's not being used.
#define DISABLE_X false
#define DISABLE_Y false
#define DISABLE_Z false
// @section extruder
#define DISABLE_E false // For all extruders
#define DISABLE_INACTIVE_EXTRUDER true //disable only inactive extruders and keep active extruder enabled
// @section machine
#define INVERT_X_DIR true // for Mendel set to false, for Orca set to true
#define INVERT_Y_DIR false // for Mendel set to true, for Orca set to false
#define INVERT_Z_DIR true // for Mendel set to false, for Orca set to true
// @section extruder
#define INVERT_E0_DIR false // for direct drive extruder v9 set to true, for geared extruder set to false
#define INVERT_E1_DIR false // for direct drive extruder v9 set to true, for geared extruder set to false
#define INVERT_E2_DIR false // for direct drive extruder v9 set to true, for geared extruder set to false
// @section homing
// ENDSTOP SETTINGS:
// Sets direction of endstops when homing; 1=MAX, -1=MIN
// :[-1,1]
#define X_HOME_DIR -1
#define Y_HOME_DIR -1
#define Z_HOME_DIR -1
@ -360,6 +389,8 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of
#define min_software_endstops true // If true, axis won't move to coordinates less than HOME_POS.
#define max_software_endstops true // If true, axis won't move to coordinates greater than the defined lengths below.
// @section machine
// Travel limits after homing (units are in mm)
#define X_MAX_POS 205
#define X_MIN_POS 0
@ -368,6 +399,8 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of
#define Z_MAX_POS 200
#define Z_MIN_POS 0
// @section hidden
#define X_MAX_LENGTH (X_MAX_POS - X_MIN_POS)
#define Y_MAX_LENGTH (Y_MAX_POS - Y_MIN_POS)
#define Z_MAX_LENGTH (Z_MAX_POS - Z_MIN_POS)
@ -377,6 +410,8 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of
//============================= Bed Auto Leveling ===========================
//===========================================================================
// @section bedlevel
//#define ENABLE_AUTO_BED_LEVELING // Delete the comment to enable (remove // at the start of the line)
#define Z_PROBE_REPEATABILITY_TEST // If not commented out, Z-Probe Repeatability test will be included if Auto Bed Leveling is Enabled.
@ -493,6 +528,8 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of
#endif // ENABLE_AUTO_BED_LEVELING
// @section homing
// The position of the homing switches
//#define MANUAL_HOME_POSITIONS // If defined, MANUAL_*_HOME_POS below will be used
//#define BED_CENTER_AT_0_0 // If defined, the center of the bed is at (X=0, Y=0)
@ -504,6 +541,8 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of
#define MANUAL_Z_HOME_POS 0
//#define MANUAL_Z_HOME_POS 402 // For delta: Distance between nozzle and print surface after homing.
// @section movement
//// MOVEMENT SETTINGS
#define NUM_AXIS 4 // The axis order in all axis related arrays is X, Y, Z, E
#define HOMING_FEEDRATE {50*60, 50*60, 4*60, 0} // set the homing speeds (mm/min)
@ -533,6 +572,8 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of
//============================= Additional Features ===========================
//=============================================================================
// @section more
// Custom M code points
#define CUSTOM_M_CODES
#ifdef CUSTOM_M_CODES
@ -541,6 +582,7 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of
#define Z_PROBE_OFFSET_RANGE_MAX -5
#endif
// @section extras
// EEPROM
// The microcontroller can store settings in the EEPROM, e.g. max velocity...
@ -553,6 +595,8 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of
// please keep turned on if you can.
//#define EEPROM_CHITCHAT
// @section temperature
// Preheat Constants
#define PLA_PREHEAT_HOTEND_TEMP 180
#define PLA_PREHEAT_HPB_TEMP 70
@ -562,6 +606,8 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of
#define ABS_PREHEAT_HPB_TEMP 100
#define ABS_PREHEAT_FAN_SPEED 255 // Insert Value between 0 and 255
// @section lcd
//LCD and SD support
// Character based displays can have different extended charsets.
@ -738,6 +784,8 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of
# endif
#endif
// @section extras
// Increase the FAN pwm frequency. Removes the PWM noise but increases heating in the FET/Arduino
//#define FAST_PWM_FAN

@ -1,6 +1,8 @@
#ifndef CONFIGURATION_ADV_H
#define CONFIGURATION_ADV_H
// @section temperature
//===========================================================================
//=============================Thermal Settings ============================
//===========================================================================
@ -44,6 +46,8 @@
//The M105 command return, besides traditional information, the ADC value read from temperature sensors.
//#define SHOW_TEMP_ADC_VALUES
// @section extruder
// extruder run-out prevention.
//if the machine is idle, and the temperature over MINTEMP, every couple of SECONDS some filament is extruded
//#define EXTRUDER_RUNOUT_PREVENT
@ -53,6 +57,8 @@
#define EXTRUDER_RUNOUT_SPEED 1500. //extrusion speed
#define EXTRUDER_RUNOUT_EXTRUDE 100
// @section temperature
//These defines help to calibrate the AD595 sensor in case you get wrong temperature measurements.
//The measured temperature is defined as "actualTemp = (measuredTemp * TEMP_SENSOR_AD595_GAIN) + TEMP_SENSOR_AD595_OFFSET"
#define TEMP_SENSOR_AD595_OFFSET 0.0
@ -70,6 +76,8 @@
// before setting a PWM value. (Does not work with software PWM for fan on Sanguinololu)
//#define FAN_KICKSTART_TIME 100
// @section extruder
// Extruder cooling fans
// Configure fan pin outputs to automatically turn on/off when the associated
// extruder temperature is above/below EXTRUDER_AUTO_FAN_TEMPERATURE.
@ -87,6 +95,8 @@
//=============================Mechanical Settings===========================
//===========================================================================
// @section machine
#define ENDSTOPS_ONLY_FOR_HOMING // If defined the endstops will only be used for homing
@ -210,12 +220,16 @@
#endif //DUAL_X_CARRIAGE
// @section homing
//homing hits the endstop, then retracts by this distance, before it tries to slowly bump again:
#define X_HOME_RETRACT_MM 5
#define Y_HOME_RETRACT_MM 5
#define Z_HOME_RETRACT_MM 2
//#define QUICK_HOME //if this is defined, if both x and y are to be homed, a diagonal move will be performed initially.
// @section machine
#define AXIS_RELATIVE_MODES {false, false, false, false}
#ifdef CONFIG_STEPPERS_TOSHIBA
#define MAX_STEP_FREQUENCY 10000 // Max step frequency for Toshiba Stepper Controllers
@ -228,12 +242,14 @@
#define INVERT_Z_STEP_PIN false
#define INVERT_E_STEP_PIN false
//default stepper release if idle
//default stepper release if idle. Set to 0 to deactivate.
#define DEFAULT_STEPPER_DEACTIVE_TIME 60
#define DEFAULT_MINIMUMFEEDRATE 0.0 // minimum feedrate
#define DEFAULT_MINTRAVELFEEDRATE 0.0
// @section lcd
// Feedrates for manual moves along X, Y, Z, E from panel
#ifdef ULTIPANEL
#define MANUAL_FEEDRATE {50*60, 50*60, 4*60, 60} // set the speeds for manual moves (mm/min)
@ -244,6 +260,8 @@
#define ULTIPANEL_FEEDMULTIPLY
#endif
// @section extras
// minimum time in microseconds that a movement needs to take if the buffer is emptied.
#define DEFAULT_MINSEGMENTTIME 20000
@ -287,6 +305,8 @@
//#define CHDK 4 //Pin for triggering CHDK to take a picture see how to use it here http://captain-slow.dk/2014/03/09/3d-printing-timelapses/
#define CHDK_DELAY 50 //How long in ms the pin should stay HIGH before going LOW again
// @section lcd
#define SD_FINISHED_STEPPERRELEASE true //if sd support and the file is finished: disable steppers?
#define SD_FINISHED_RELEASECOMMAND "M84 X Y Z E" // You might want to keep the z enabled so your bed stays in place.
@ -315,6 +335,8 @@
#endif
#endif
// @section more
// The hardware watchdog should reset the microcontroller disabling all outputs, in case the firmware gets stuck and doesn't do temperature regulation.
//#define USE_WATCHDOG
@ -373,12 +395,16 @@
const unsigned int dropsegments=5; //everything with less than this number of steps will be ignored as move and joined with the next movement
// @section lcd
// If you are using a RAMPS board or cheap E-bay purchased boards that do not detect when an SD card is inserted
// You can get round this by connecting a push button or single throw switch to the pin defined as SDCARDCARDDETECT
// in the pins.h file. When using a push button pulling the pin to ground this will need inverted. This setting should
// be commented out otherwise
#define SDCARDDETECTINVERTED
// @section hidden
#ifdef ULTIPANEL
#undef SDCARDDETECTINVERTED
#endif
@ -399,6 +425,8 @@ const unsigned int dropsegments=5; //everything with less than this number of st
#define PS_ON_ASLEEP LOW
#endif
// @section temperature
// Control heater 0 and heater 1 in parallel.
//#define HEATERS_PARALLEL
@ -406,6 +434,8 @@ const unsigned int dropsegments=5; //everything with less than this number of st
//=============================Buffers ============================
//===========================================================================
// @section hidden
// The number of linear motions that can be in the plan at any give time.
// THE BLOCK_BUFFER_SIZE NEEDS TO BE A POWER OF 2, i.g. 8,16,32 because shifts and ors are used to do the ring-buffering.
#if defined SDSUPPORT
@ -414,11 +444,13 @@ const unsigned int dropsegments=5; //everything with less than this number of st
#define BLOCK_BUFFER_SIZE 16 // maximize block buffer
#endif
// @section more
//The ASCII buffer for receiving from the serial:
#define MAX_CMD_SIZE 96
#define BUFSIZE 4
// @section extras
// Firmware based and LCD controlled retract
// M207 and M208 can be used to define parameters for the retraction.
@ -460,6 +492,8 @@ const unsigned int dropsegments=5; //everything with less than this number of st
//============================= Define Defines ============================
//===========================================================================
// @section hidden
#if defined (ENABLE_AUTO_BED_LEVELING) && defined (DELTA)
#error "Bed Auto Leveling is still not compatible with Delta Kinematics."
#endif

@ -45,7 +45,9 @@ p.info span { color: #800; }
#message p.message { color: #080; background: #CFC; }
#message p.error { color: #F00; background: #FF4; }
#message p.warning { color: #FF0; background: #BA4; }
#message p.message span {
#message p.message span,
#message p.error span,
#message p.warning span {
color: #A00;
background: rgba(255, 255, 255, 1);
border: 1px solid rgba(0,0,0,0.5);
@ -89,21 +91,22 @@ label {
}
input[type="text"], select { margin: 0.75em 0 0; }
input[type="checkbox"], input[type="radio"], input[type="file"] { margin: 1em 0 0; }
input[type="checkbox"], input[type="radio"].enabler { margin-left: 1em; }
input[type="checkbox"].enabler, input[type="radio"].enabler { margin-left: 1em; }
input:disabled { color: #BBB; }
#more input[type="text"] { width: 20em; }
#config_form input[type="text"].subitem { width: 4em; }
#config_form input[type="text"].subitem+.subitem { margin-left: 4px; }
#more label {
width: 240px; /* label area */
input[type="text"].added { width: 20em; }
label.added {
width: 275px; /* label area */
height: 1em;
padding: 10px 360px 10px 1em;
margin-right: -350px;
text-align: right;
}
ul.tabs { padding: 0; list-style: none; }
ul.tabs li { display: inline; }
ul.tabs li a,
@ -192,8 +195,19 @@ fieldset legend { display: none; }
/* Tooltips Checkbox */
#tipson { float: right; font-weight: bold; font-size: 100%; font-family: helvetica; }
#tipson input { float: none; display: inline; }
#tipson {
width: auto;
height: auto;
padding: 0;
margin-right: 0;
float: right;
font-weight: bold;
font-size: 100%;
font-family: helvetica;
text-align: left;
cursor: pointer;
}
#tipson input { float: none; display: inline; cursor: pointer; }
/* Config Text */
@ -206,7 +220,7 @@ pre.config {
clear: both;
background-color: #FFF;
color: #000;
font-family: "Fira Mono";
font-family: "Fira Mono", monospace;
font-size: small;
}

@ -25,7 +25,7 @@
<div id="tooltip"></div>
<label>Drop Files Here:</label><input type="file" id="file-upload" />
<div id="tipson"><input type="checkbox" checked /> ?</div>
<label id="tipson"><input type="checkbox" checked /> ?</label>
<br class="clear" />
<fieldset id="machine">
@ -40,9 +40,9 @@
<label class="newline">Motherboard:</label><select name="MOTHERBOARD"></select>
<label class="newline">Custom Name:</label><input name="CUSTOM_MENDEL_NAME" class="switchable" type="text" size="14" maxlength="12" value="" />
<label class="newline">Custom Name:</label><input name="CUSTOM_MENDEL_NAME" type="text" size="14" maxlength="12" value="" />
<label class="newline">Machine UUID:</label><input name="MACHINE_UUID" class="switchable" type="text" size="38" maxlength="36" value="" />
<label class="newline">Machine UUID:</label><input name="MACHINE_UUID" type="text" size="38" maxlength="36" value="" />
<label class="newline">Extruders:</label><select name="EXTRUDERS"></select>
@ -52,6 +52,10 @@
<input name="PS_DEFAULT_OFF" type="checkbox" value="1" checked />
</fieldset>
<fieldset id="homing">
<legend>Homing</legend>
</fieldset>
<fieldset id="temperature">
<legend>Temperature</legend>
<label class="newline">Temp Sensor 0:</label><select name="TEMP_SENSOR_0"></select>
@ -69,12 +73,20 @@
<input name="TEMP_RESIDENCY_TIME" type="text" size="3" maxlength="2" />
</fieldset>
<fieldset id="hotends">
<legend>Hot Ends</legend>
<fieldset id="extruder">
<legend>Extruder</legend>
</fieldset>
<fieldset id="lcd">
<legend>LCD / SD</legend>
</fieldset>
<fieldset id="bedlevel">
<legend>Bed Leveling</legend>
</fieldset>
<fieldset id="heatbed">
<legend>Heated Bed</legend>
<fieldset id="extras">
<legend>Extras</legend>
</fieldset>
<fieldset id="more">

@ -143,6 +143,7 @@ var configuratorApp = (function(){
$config = $('#config_text pre'),
$config_adv = $('#config_adv_text pre'),
define_list = [[],[]],
define_section = {},
boards_list = {},
therms_list = {},
total_config_lines,
@ -308,16 +309,21 @@ var configuratorApp = (function(){
/**
* Get all the unique define names
*/
getDefinesFromText: function(txt) {
var leave_out_defines = ['CONFIGURATION_H', 'CONFIGURATION_ADV_H', 'STRING_VERSION', 'STRING_URL', 'STRING_VERSION_CONFIG_H', 'STRING_CONFIG_H_AUTHOR', 'STRING_SPLASH_LINE1', 'STRING_SPLASH_LINE2'];
// Get all the unique #define's and save them in an array
var r, define_obj = {}, findDef = new RegExp('#define[ \\t]+(\\w+)', 'gm');
updateDefinesFromText: function(index, txt) {
var section = 'machine',
leave_out_defines = ['CONFIGURATION_H', 'CONFIGURATION_ADV_H', 'STRING_VERSION', 'STRING_URL', 'STRING_VERSION_CONFIG_H', 'STRING_CONFIG_H_AUTHOR', 'STRING_SPLASH_LINE1', 'STRING_SPLASH_LINE2'],
define_sect = {},
r, findDef = new RegExp('(@section|#define)[ \\t]+(\\w+)', 'gm');
while((r = findDef.exec(txt)) !== null) {
if ($.inArray(r[1], leave_out_defines) < 0 && !(r[1] in define_obj))
define_obj[r[1]] = null;
var name = r[2];
if (r[1] == '@section')
section = name;
else if ($.inArray(name, leave_out_defines) < 0 && !(name in define_sect))
define_sect[name] = section;
}
this.log(Object.keys(define_obj), 2);
return Object.keys(define_obj);
define_list[index] = Object.keys(define_sect);
$.extend(define_section, define_sect);
this.log(define_list[index], 2);
},
/**
@ -327,24 +333,48 @@ var configuratorApp = (function(){
var e = adv ? 1 : 0, n = 0;
var fail_list = [];
$.each(define_list[e], function(i,name) {
if (!$('#'+name).length) {
var $ff = $('#more'),
inf = self.getDefineInfo(name, adv);
var section = define_section[name];
if (section != 'hidden' && !$('#'+name).length) {
var inf = self.getDefineInfo(name, adv);
if (inf) {
var $newlabel = $('<label>',{for:name}).text(name.toLabel());
var $ff = $('#'+section), $newfield,
$newlabel = $('<label>',{for:name,class:'added'}).text(name.toLabel());
// if (!(++n % 3))
$newlabel.addClass('newline');
var $newfield;
if (inf.options !== undefined) {
$newfield = $('<select>'); //.addOptions(inf.options);
$ff.append($newlabel);
// Multiple fields?
if (inf.type == 'list') {
for (var i=0; i<inf.size; i++) {
var fieldname = i > 0 ? name+'-'+i : name;
$newfield = $('<input>',{type:'text',size:6,maxlength:10,id:fieldname,name:fieldname,class:'subitem added'}).prop({defineInfo:inf});
$ff.append($newfield);
}
}
else {
$newfield = inf.type == 'switch' ? $('<input>',{type:'checkbox'}) : $('<input>',{type:'text',size:10,maxlength:40});
// Items with options, either toggle or select
// TODO: Radio buttons for other values
if (inf.options !== undefined) {
if (inf.type == 'toggle') {
$newfield = $('<input>',{type:'checkbox'});
}
else {
// Otherwise selectable
$newfield = $('<select>');
}
// ...Options added when field initialized
}
else {
$newfield = inf.type == 'switch' ? $('<input>',{type:'checkbox'}) : $('<input>',{type:'text',size:10,maxlength:40});
}
$newfield.attr({id:name,name:name,class:'added'}).prop({defineInfo:inf});
// Add the new field to the form
$ff.append($newfield);
}
$newfield.attr({id:name,name:name}).prop({defineInfo:inf});
// Add the new field to the form
$ff.append($newlabel, $newfield);
}
else
fail_list.push(name);
@ -410,10 +440,9 @@ var configuratorApp = (function(){
// When a config file loads defines might change
if (init_index != null) {
var adv = init_index == 1;
define_list[init_index] = this.getDefinesFromText(txt);
this.log(define_list[init_index], 2);
this.purgeDefineInfo(adv);
this.createFieldsForDefines(init_index);
this.purgeAddedFields(init_index);
this.updateDefinesFromText(init_index, txt);
this.createFieldsForDefines(adv);
this.refreshConfigForm(init_index);
this.activateDownloadLink(adv);
}
@ -446,13 +475,14 @@ var configuratorApp = (function(){
});
// Get all 'switchable' class items and add a checkbox
$form.find('.switchable').each(function(){
$(this).after(
$('<input>',{type:'checkbox',value:'1',class:'enabler'}).prop('checked',true)
.attr('id',this.id + '-switch')
.change(self.handleSwitch)
);
});
// $form.find('.switchable').each(function(){
// $(this).after(
// $('<input>',{type:'checkbox',value:'1',class:'enabler added'})
// .prop('checked',true)
// .attr('id',this.id + '-switch')
// .change(self.handleSwitch)
// );
// });
// Add options to the popup menus
// $('#SERIAL_PORT').addOptions([0,1,2,3,4,5,6,7]);
@ -516,7 +546,7 @@ var configuratorApp = (function(){
/**
* Any manually-created form elements will remain
* where they are. Unknown defines (currently most)
* are added to the "More..." tab for now.
* are added to tabs based on section
*
* Specific exceptions can be managed by applying
* classes to the associated form fields.
@ -550,11 +580,7 @@ var configuratorApp = (function(){
if (inf == null)
inf = elm.defineInfo = this.getDefineInfo(name, adv);
// Set options on the field if there are any
if (inf.options !== undefined)
$elm.html('').addOptions(inf.options);
// Create a tooltip if there is one
// Create a tooltip on the label if there is one
if (inf.tooltip) {
var $tipme = $elm.prev('label');
if ($tipme.length) {
@ -583,8 +609,34 @@ var configuratorApp = (function(){
}
}
$elm.unbind('input change');
$elm.on($elm.attr('type') == 'text' ? 'input' : 'change', this.handleChange);
// Make the element(s) respond to events
if (inf.type == 'list') {
// Multiple fields need to respond
for (var i=0; i<inf.size; i++) {
if (i > 0) $elm = $('#'+name+'-'+i);
$elm.unbind('input');
$elm.on('input', this.handleChange);
}
}
else {
var elmtype = $elm.attr('type');
// Set options on single fields if there are any
if (inf.options !== undefined && elmtype === undefined)
$elm.html('').addOptions(inf.options);
$elm.unbind('input change');
$elm.on(elmtype == 'text' ? 'input' : 'change', this.handleChange);
}
// Add an enabler checkbox if it needs one
if (inf.switchable && $('#'+name+'-switch').length == 0) {
// $elm = the last element added
$elm.after(
$('<input>',{type:'checkbox',value:'1',class:'enabler added'})
.prop('checked',self.defineIsEnabled(name))
.attr({id: name+'-switch'})
.change(self.handleSwitch)
);
}
// Set the field's initial value from the define
this.setFieldFromDefine(name);
@ -592,17 +644,31 @@ var configuratorApp = (function(){
/**
* Handle any value field being changed
* this = the field
*/
handleChange: function() { self.updateDefineFromField(this.id); },
/**
* Handle a switch checkbox being changed
* this = the switch checkbox
*/
handleSwitch: function() {
var $elm = $(this), $prev = $elm.prev();
var on = $elm.prop('checked') || false;
$prev.attr('disabled', !on);
self.setDefineEnabled($prev[0].id, on);
var $elm = $(this),
name = $elm[0].id.replace(/-.+/,''),
inf = $('#'+name)[0].defineInfo,
on = $elm.prop('checked') || false;
self.setDefineEnabled(name, on);
if (inf.type == 'list') {
// Multiple fields?
for (var i=0; i<inf.size; i++) {
$('#'+name+(i?'-'+i:'')).attr('disabled', !on);
}
}
else {
$elm.prev().attr('disabled', !on);
}
},
/**
@ -656,11 +722,15 @@ var configuratorApp = (function(){
*/
updateDefineFromField: function(name) {
this.log('updateDefineFromField:'+name,4);
// Drop the suffix on sub-fields
name = name.replace(/-\d+$/, '');
var $elm = $('#'+name), inf = $elm[0].defineInfo;
if (inf == null) return;
var isCheck = $elm.attr('type') == 'checkbox',
val = isCheck ? $elm.prop('checked') : $elm.val();
val = isCheck ? $elm.prop('checked') : $elm.val().trim();
var newline;
switch(inf.type) {
@ -668,12 +738,19 @@ var configuratorApp = (function(){
var slash = val ? '' : '//';
newline = inf.line.replace(inf.repl, '$1'+slash+'$3');
break;
case 'list':
case 'quoted':
case 'plain':
if (isCheck)
this.setMessage(name + ' should not be a checkbox!', 'error');
else
newline = inf.line.replace(inf.repl, '$1'+val.replace('$','\\$')+'$3');
if (isCheck) this.setMessage(name + ' should not be a checkbox!', 'error');
case 'toggle':
if (isCheck) {
val = val ? inf.options[1] : inf.options[0];
}
else {
if (inf.type == 'list')
for (var i=1; i<inf.size; i++) val += ', ' + $('#'+name+'-'+i).val().trim();
}
newline = inf.line.replace(inf.repl, '$1'+(''+val).replace('$','\\$')+'$3');
break;
}
this.setDefineLine(name, newline);
@ -725,31 +802,40 @@ var configuratorApp = (function(){
* Set a form field to the current #define value in the config text
*/
setFieldFromDefine: function(name) {
var $elm = $('#'+name), val = this.defineValue(name);
var $elm = $('#'+name), inf = $elm[0].defineInfo,
val = this.defineValue(name);
this.log('setFieldFromDefine:' + name + ' to ' + val, 2);
// Set the field value
$elm.attr('type') == 'checkbox' ? $elm.prop('checked', val) : $elm.val(''+val);
// If the item has a checkbox then set enabled state too
var $cb = $('#'+name+'-switch');
var $cb = $('#'+name+'-switch'), on = true;
if ($cb.length) {
var on = self.defineIsEnabled(name);
on = self.defineIsEnabled(name);
$cb.prop('checked', on);
}
if (inf.type == 'list') {
$.each(val.split(','),function(i,v){
var $e = i > 0 ? $('#'+name+'-'+i) : $elm;
$e.val(v.trim());
$e.attr('disabled', !on);
});
}
else {
if (inf.type == 'toggle') val = val == inf.options[1];
$elm.attr('type') == 'checkbox' ? $elm.prop('checked', val) : $elm.val(''+val);
$elm.attr('disabled', !on); // enable/disable the form field (could also dim it)
$cb.prop('checked', on); // check/uncheck the checkbox
}
},
/**
* Purge #define information for one of the config files
* Purge added fields and all their define info
*/
purgeDefineInfo: function(adv) {
if (adv === undefined) adv = false;
$('[name]').each(function() {
var inf = this.defineInfo;
if (inf && adv === inf.adv) $(this).removeProp('defineInfo');
purgeAddedFields: function(index) {
$.each(define_list[index], function(){
$('#'+this + ",[id^='"+this+"-'],label[for='"+this+"']").filter('.added').remove();
});
define_list[index] = [];
},
/**
@ -805,6 +891,7 @@ var configuratorApp = (function(){
line: result[0],
pre: result[1] === undefined ? '' : result[1].replace('//',''),
define: result[2],
size: result[3].split(',').length,
post: result[4] === undefined ? '' : result[4]
});
info.regex = new RegExp('([ \\t]*//)?[ \\t]*' + info.define.regEsc() + '\{([^\}]*)\}' + info.post.regEsc(), 'm');
@ -837,6 +924,10 @@ var configuratorApp = (function(){
define: result[2],
post: result[4] === undefined ? '' : result[4]
});
if (result[3].match(/false|true/)) {
info.type = 'toggle';
info.options = ['false','true'];
}
info.regex = new RegExp('([ \\t]*//)?[ \\t]*' + info.define.regEsc() + '(\\S*)' + info.post.regEsc(), 'm');
info.repl = new RegExp('(([ \\t]*//)?[ \\t]*' + info.define.regEsc() + ')\\S*(' + info.post.regEsc() + ')', 'm');
}
@ -854,31 +945,41 @@ var configuratorApp = (function(){
// Get all the comments immediately before the item
var r, s;
findDef = new RegExp('(([ \\t]*(//|#)[^\n]+\n){1,4})([ \\t]*\n){0,1}' + info.line.regEsc(), 'g');
findDef = new RegExp('(([ \\t]*(//|#)[^\n]+\n){1,4})([ \\t]*\n)?' + info.line.regEsc(), 'g');
if (r = findDef.exec(txt)) {
// Get the text of the found comments
findDef = new RegExp('^[ \\t]*//+[ \\t]*(.*)[ \\t]*$', 'gm');
while((s = findDef.exec(r[1])) !== null) {
if (s[1].match(/^#define[ \\t]/) != null) {
tooltip = '';
break;
}
// JSON data? Save as select options
if (s[1].match(/:[\[{]/) != null) {
// TODO
// :[1-6] = value limits
eval('info.options = ' + s[1].substr(1));
}
else {
// Other lines added to the tooltip
tooltip += ' ' + s[1] + '\n';
var tip = s[1].replace(/[ \\t]*(={5,}|@section[ \\t]+\w+)[ \\t]*/g, '');
if (tip.length) {
if (tip.match(/^#define[ \\t]/) != null) {
tooltip = '';
break;
}
// JSON data? Save as select options
if (!info.options && tip.match(/:[\[{]/) != null) {
// TODO
// :[1-6] = value limits
var o; eval('o=' + tip.substr(1));
info.options = o;
if (Object.prototype.toString.call(o) == "[object Array]" && o.length == 2 && !eval(''+o[0]))
info.type = 'toggle';
}
else {
// Other lines added to the tooltip
tooltip += ' ' + tip + '\n';
}
}
}
}
findDef = new RegExp('^'+name); // To strip the name from the start
// Add .tooltip and .lineNum properties to the info
findDef = new RegExp('^'+name); // Strip the name from the tooltip
$.extend(info, {
tooltip: '<strong>'+name+'</strong> '+tooltip.trim().replace(findDef,'').toHTML(),
lineNum: this.getLineNumberOfText(info.line, txt)
lineNum: this.getLineNumberOfText(info.line, txt),
switchable: (info.type != 'switch' && info.line.match(/^[ \t]*\/\//)) || false // Disabled? Mark as "switchable"
});
}
else

Loading…
Cancel
Save