Browse Source

More grouping, cleanup, start on overrides

Scott Lahteine 9 years ago
parent
commit
1149c24b86

+ 1
- 1
Marlin/configurator/config/Configuration.h View File

@@ -347,7 +347,7 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of
347 347
 // @section machine
348 348
 
349 349
 // For Inverting Stepper Enable Pins (Active Low) use 0, Non Inverting (Active High) use 1
350
-// :{0:'Active Low',1:'Active High'}
350
+// :{0:'Low',1:'High'}
351 351
 #define X_ENABLE_ON 0
352 352
 #define Y_ENABLE_ON 0
353 353
 #define Z_ENABLE_ON 0

+ 0
- 3
Marlin/configurator/index.html View File

@@ -65,9 +65,6 @@
65 65
           <label class="newline">Temp Sensor 2:</label><select name="TEMP_SENSOR_2"></select>
66 66
           <label class="newline">Bed Temp Sensor:</label><select name="TEMP_SENSOR_BED"></select>
67 67
 
68
-          <label class="newline">Redundant Sensor:</label>
69
-            <input name="TEMP_SENSOR_1_AS_REDUNDANT" type="checkbox" value="1" checked />
70
-
71 68
           <label>Max Diff:</label>
72 69
             <input name="MAX_REDUNDANT_TEMP_SENSOR_DIFF" type="text" size="3" maxlength="2" />
73 70
 

+ 164
- 119
Marlin/configurator/js/configurator.js View File

@@ -85,7 +85,9 @@ String.prototype.prePad = function(len, chr) { return len ? this.lpad(len, chr)
85 85
 String.prototype.zeroPad = function(len)     { return this.prePad(len, '0'); };
86 86
 String.prototype.toHTML = function()         { return jQuery('<div>').text(this).html(); };
87 87
 String.prototype.regEsc = function()         { return this.replace(/[.?*+^$[\]\\(){}|-]/g, "\\$&"); }
88
-String.prototype.lineCount = function()      { var len = this.split(/\r?\n|\r/).length; return len > 0 ? len - 1 : 0; };
88
+String.prototype.lineCount = function(ind)   { var len = (ind === undefined ? this : this.substr(0,ind*1)).split(/\r?\n|\r/).length; return len > 0 ? len - 1 : 0; };
89
+String.prototype.line = function(num)        { var arr = this.split(/\r?\n|\r/); return num < arr.length ? arr[1*num] : ''; };
90
+String.prototype.replaceLine = function(num,txt) { var arr = this.split(/\r?\n|\r/); if (num < arr.length) { arr[num] = txt; return arr.join('\n'); } else return this; }
89 91
 String.prototype.toLabel = function()        { return this.replace(/[\[\]]/g, '').replace(/_/g, ' ').toTitleCase(); }
90 92
 String.prototype.toTitleCase = function()    { return this.replace(/([A-Z])(\w+)/gi, function(m,p1,p2) { return p1.toUpperCase() + p2.toLowerCase(); }); }
91 93
 Number.prototype.limit = function(m1, m2)  {
@@ -148,11 +150,12 @@ window.configuratorApp = (function(){
148 150
       $config = $cfg.find('pre'), $config_adv = $adv.find('pre'),
149 151
       config_file_list = [ boards_file, config_file, config_adv_file ],
150 152
       config_list = [ $config, $config_adv ],
151
-      define_info = {},
152
-      define_list = [[],[]],
153
-      define_groups = [{},{}],
154
-      define_section = {},
155
-      dependentGroups = {},
153
+      define_info = {},         // info for all defines, by name
154
+      define_list = [[],[]],    // arrays with all define names
155
+      define_occur = [{},{}],   // lines where defines occur in each file
156
+      define_groups = [{},{}],  // similarly-named defines that group in the form
157
+      define_section = {},      // the section of each define
158
+      dependent_groups = {},
156 159
       boards_list = {},
157 160
       therms_list = {},
158 161
       total_config_lines,
@@ -339,32 +342,62 @@ window.configuratorApp = (function(){
339 342
     },
340 343
 
341 344
     /**
342
-     * Get all the unique define names
345
+     * Get all the unique define names, building lists that will be used
346
+     * when gathering info about each define.
347
+     *
348
+     * define_list[c][j]        : Define names in each config (in order of occurrence)
349
+     * define_section[name]     : Section where define should appear in the form
350
+     * define_occur[c][name][i] : Lines in each config where the same define occurs
351
+     *   .cindex   Config file index
352
+     *   .lineNum  Line number of the occurrence
353
+     *   .line     The occurrence line
343 354
      */
344 355
     initDefineList: function(cindex) {
345 356
       var section = 'hidden',
346 357
           leave_out_defines = ['CONFIGURATION_H', 'CONFIGURATION_ADV_H'],
347 358
           define_sect = {},
359
+          occ_list = {},
348 360
           txt = config_list[cindex].text(),
349
-          r, findDef = new RegExp('(@section|#define)[ \\t]+(\\w+)', 'gm');
361
+          r, findDef = new RegExp('^.*(@section|#define)[ \\t]+(\\w+).*$', 'gm');
350 362
       while((r = findDef.exec(txt)) !== null) {
351 363
         var name = r[2];
352
-        if (r[1] == '@section')
364
+        if (r[1] == '@section') {
353 365
           section = name;
354
-        else if ($.inArray(name, leave_out_defines) < 0 && !(name in define_section) && !(name in define_sect))
355
-          define_sect[name] = section;
366
+        }
367
+        else if ($.inArray(name, leave_out_defines) < 0) {
368
+          var lineNum = txt.lineCount(r.index),
369
+              inst = { cindex:cindex, lineNum:lineNum, line:r[0] },
370
+              in_sect = (name in define_sect);
371
+          if (!in_sect) {
372
+            occ_list[name] = [ inst ];
373
+          }
374
+          if (!(name in define_section) && !in_sect) {
375
+            define_sect[name] = section; // new first-time define
376
+          }
377
+          else {
378
+            occ_list[name].push(inst);
379
+          }
380
+        }
356 381
       }
357 382
       define_list[cindex] = Object.keys(define_sect);
383
+      define_occur[cindex] = occ_list;
358 384
       $.extend(define_section, define_sect);
359 385
       this.log(define_list[cindex], 2);
386
+      this.log(occ_list, 2);
387
+      this.log(define_sect, 2);
360 388
     },
361 389
 
362 390
     /**
363 391
      * Find the defines in one of the configs that are just variants.
364 392
      * Group them together for form-building and other uses.
393
+     *
394
+     * define_groups[c][name]
395
+     *   .pattern regexp matching items in the group
396
+     *   .title   title substitution
397
+     *   .count   number of items in the group
365 398
      */
366 399
     refreshDefineGroups: function(cindex) {
367
-      var findDef = /^(|.*_)(([XYZE](MAX|MIN))|(E[0-3]|[XYZE01234])|MAX|MIN|(bed)?K[pid])(_.*|)$/;
400
+      var findDef = /^(|.*_)(([XYZE](MAX|MIN))|(E[0-3]|[XYZE01234])|MAX|MIN|(bed)?K[pid]|HOTEND|HPB|JAPAN|WESTERN|LEFT|RIGHT|BACK|FRONT|[XYZ]_POINT)(_.*|)$/i;
368 401
       var match_prev, patt, title, nameList, groups = {}, match_section;
369 402
       $.each(define_list[cindex], function(i, name) {
370 403
         if (match_prev) {
@@ -387,7 +420,8 @@ window.configuratorApp = (function(){
387 420
         if (!match_prev) {
388 421
           var r = findDef.exec(name);
389 422
           if (r != null) {
390
-            switch(r[2]) {
423
+            title = '';
424
+            switch(r[2].toUpperCase()) {
391 425
               case '0':
392 426
                 patt = '([0123])';
393 427
                 title = 'N';
@@ -400,18 +434,31 @@ window.configuratorApp = (function(){
400 434
                 patt = 'E([0-3])';
401 435
                 title = 'E';
402 436
                 break;
403
-              case 'bedKp':
437
+              case 'BEDKP':
404 438
                 patt = 'bed(K[pid])';
405 439
                 title = 'BED_PID';
406 440
                 break;
407
-              case 'Kp':
441
+              case 'KP':
408 442
                 patt = '(K[pid])';
409 443
                 title = 'PID';
410 444
                 break;
445
+              case 'LEFT':
446
+              case 'RIGHT':
447
+              case 'BACK':
448
+              case 'FRONT':
449
+                patt = '([LRBF])(EFT|IGHT|ACK|RONT)';
450
+                break;
411 451
               case 'MAX':
412 452
               case 'MIN':
413 453
                 patt = '(MAX|MIN)';
414
-                title = '';
454
+                break;
455
+              case 'HOTEND':
456
+              case 'HPB':
457
+                patt = '(HOTEND|HPB)';
458
+                break;
459
+              case 'JAPAN':
460
+              case 'WESTERN':
461
+                patt = '(JAPAN|WESTERN)';
415 462
                 break;
416 463
               case 'XMIN':
417 464
               case 'XMAX':
@@ -425,7 +472,7 @@ window.configuratorApp = (function(){
425 472
             if (patt) {
426 473
               patt = '^' + r[1] + patt + r[7] + '$';
427 474
               title = r[1] + title + r[7];
428
-              match_prev = new RegExp(patt);
475
+              match_prev = new RegExp(patt, 'i');
429 476
               match_section = define_section[name];
430 477
               nameList = [ name ];
431 478
             }
@@ -433,21 +480,29 @@ window.configuratorApp = (function(){
433 480
         }
434 481
       });
435 482
       define_groups[cindex] = groups;
483
+      this.log(define_groups[cindex], 2);
436 484
     },
437 485
 
438 486
     /**
439
-     * Get all condition blocks and their line ranges.
440
-     * Conditions may control multiple line-ranges
441
-     * across both config files.
487
+     * Get all conditional blocks and their line ranges
488
+     * and store them in the dependent_groups list.
489
+     *
490
+     * dependent_groups[condition][i]
491
+     *
492
+     *   .cindex config file index
493
+     *   .start  starting line
494
+     *   .end    ending line
495
+     *
442 496
      */
443 497
     initDependentGroups: function() {
444 498
       var findBlock = /^[ \t]*#(ifn?def|if|else|endif)[ \t]*(.*)([ \t]*\/\/[^\n]+)?$/gm,
445 499
           leave_out_defines = ['CONFIGURATION_H', 'CONFIGURATION_ADV_H'];
500
+      dependent_groups = {};
446 501
       $.each(config_list, function(i, $v) {
447 502
         var ifStack = [];
448 503
         var r, txt = $v.text();
449 504
         while((r = findBlock.exec(txt)) !== null) {
450
-          var lineNum = txt.substr(0, r.index).lineCount();
505
+          var lineNum = txt.lineCount(r.index);
451 506
           var code = r[2].replace(/[ \t]*\/\/.*$/, '');
452 507
           switch(r[1]) {
453 508
             case 'if':
@@ -481,8 +536,8 @@ window.configuratorApp = (function(){
481 536
               if (c) {
482 537
                 var cond = c[0], line = c[1];
483 538
                 self.log("pop " + c[0], 4);
484
-                if (dependentGroups[cond] === undefined) dependentGroups[cond] = [];
485
-                dependentGroups[cond].push({cindex:i,start:line,end:lineNum});
539
+                if (dependent_groups[cond] === undefined) dependent_groups[cond] = [];
540
+                dependent_groups[cond].push({cindex:i,start:line,end:lineNum});
486 541
                 if (r[1] == 'else') {
487 542
                   // Reverse the condition
488 543
                   cond = (cond.indexOf('!') === 0) ? cond.substr(1) : ('!'+cond);
@@ -544,11 +599,11 @@ window.configuratorApp = (function(){
544 599
               grouping = true;
545 600
               g_subitem = false;
546 601
               var grp = group[name];
547
-              g_pattern = grp.pattern;
602
+              g_section = section;
548 603
               g_class = 'one_of_' + grp.count;
604
+              g_pattern = grp.pattern;
605
+              g_regex = new RegExp(g_pattern, 'i');
549 606
               label_text = grp.title;
550
-              g_regex = new RegExp(g_pattern);
551
-              g_section = section;
552 607
               sublabel = g_regex.exec(name)[1];
553 608
             }
554 609
 
@@ -596,8 +651,9 @@ window.configuratorApp = (function(){
596 651
               $newfield.attr({id:name,name:name,class:'added',disabled:!avail}).unblock(avail);
597 652
               if (grouping) {
598 653
                 $newfield.addClass(g_class);
599
-                if (sublabel)
654
+                if (sublabel) {
600 655
                   $ff.append($('<label>',{class:'added sublabel',for:name}).text(sublabel.toTitleCase()).unblock(avail));
656
+                }
601 657
               }
602 658
               // Add the new field to the form
603 659
               $ff.append($newfield);
@@ -823,33 +879,18 @@ window.configuratorApp = (function(){
823 879
     },
824 880
 
825 881
     /**
826
-     * Enable / disable fields based on condition tests
882
+     * Enable / disable fields in dependent groups
883
+     * based on their dependencies.
827 884
      */
828 885
     refreshDependentFields: function() {
829
-      // Simplest way is to go through all define_info
830
-      // and run a test on all fields that have one.
831
-      //
832
-      // Each define_info caches its enable test as code.
833
-      //
834
-      // The fields that act as switches for these dependencies
835
-      // are not currently modified, but they will soon be.
836
-      //
837
-      // Once all conditions have been gathered into define_info
838
-      // the conditions can be scraped for define names.
839
-      //
840
-      // Those named fields will be given a .change action to
841
-      // check and update enabled state for the field.
842
-      //
843 886
       $.each(define_list, function(e,def_list){
844 887
         $.each(def_list, function(i, name) {
845 888
           var inf = define_info[name];
846 889
           if (inf && inf.enabled != 'true') {
847 890
             var $elm = $('#'+name), ena = eval(inf.enabled);
848 891
             var isEnabled = (inf.type == 'switch') || self.defineIsEnabled(name);
849
-            // Make any switch toggle also
850 892
             $('#'+name+'-switch').attr('disabled', !ena);
851 893
             $elm.attr('disabled', !(ena && isEnabled)).unblock(ena);
852
-            //self.log("Setting " + name + " to " + (ena && isEnabled ? 'enabled' : 'disabled'));
853 894
             $('label[for="'+name+'"]').unblock(ena);
854 895
           }
855 896
         });
@@ -873,10 +914,10 @@ window.configuratorApp = (function(){
873 914
           $tipme.hover(
874 915
             function() {
875 916
               if ($('#tipson input').prop('checked')) {
876
-                var pos = $tipme.position();
917
+                var pos = $tipme.position(), px = $tipme.width()/2;
877 918
                 $tooltip.html(inf.tooltip)
878 919
                   .append('<span>')
879
-                  .css({bottom:($tooltip.parent().outerHeight()-pos.top)+'px',left:(pos.left+70)+'px'})
920
+                  .css({bottom:($tooltip.parent().outerHeight()-pos.top+10)+'px',left:(pos.left+px)+'px'})
880 921
                   .show();
881 922
                 if (hover_timer) {
882 923
                   clearTimeout(hover_timer);
@@ -957,33 +998,31 @@ window.configuratorApp = (function(){
957 998
     },
958 999
 
959 1000
     /**
960
-     * Get the current value of a #define (from the config text)
1001
+     * Get the current value of a #define
961 1002
      */
962 1003
     defineValue: function(name) {
963 1004
       this.log('defineValue:'+name,4);
964 1005
       var inf = define_info[name];
965 1006
       if (inf == null) return 'n/a';
966
-      // var result = inf.regex.exec($(inf.field).text());
967
-      var result = inf.regex.exec(inf.line);
1007
+      var r = inf.regex.exec(inf.line), val = r[inf.val_i];
968 1008
 
969
-      this.log(result,2);
1009
+      this.log(r,2);
970 1010
 
971
-      return (inf.type == 'switch') ? (result[inf.val_i] === undefined || result[inf.val_i].trim() != '//') : result[inf.val_i];
1011
+      return (inf.type == 'switch') ? (val === undefined || val.trim() != '//') : val;
972 1012
     },
973 1013
 
974 1014
     /**
975
-     * Get the current enabled state of a #define (from the config text)
1015
+     * Get the current enabled state of a #define
976 1016
      */
977 1017
     defineIsEnabled: function(name) {
978 1018
       this.log('defineIsEnabled:'+name,4);
979 1019
       var inf = define_info[name];
980 1020
       if (inf == null) return false;
981
-      // var result = inf.regex.exec($(inf.field).text());
982
-      var result = inf.regex.exec(inf.line);
1021
+      var r = inf.regex.exec(inf.line);
983 1022
 
984
-      this.log(result,2);
1023
+      this.log(r,2);
985 1024
 
986
-      var on = result[1] != null ? result[1].trim() != '//' : true;
1025
+      var on = r[1] != null ? r[1].trim() != '//' : true;
987 1026
       this.log(name + ' = ' + on, 2);
988 1027
 
989 1028
       return on;
@@ -1054,7 +1093,7 @@ window.configuratorApp = (function(){
1054 1093
 
1055 1094
       var hilite_token = '[HIGHLIGHTER-TOKEN]';
1056 1095
 
1057
-      txt = txt.replace(inf.line, hilite_token + newline);
1096
+      txt = txt.replaceLine(inf.lineNum, hilite_token + newline); // for override line and lineNum would be changed
1058 1097
       inf.line = newline;
1059 1098
 
1060 1099
       // Convert txt into HTML before storing
@@ -1131,82 +1170,84 @@ window.configuratorApp = (function(){
1131 1170
      * Get information about a #define from configuration file text:
1132 1171
      *
1133 1172
      *   - Pre-examine the #define for its prefix, value position, suffix, etc.
1134
-     *   - Construct RegExp's for the #define to quickly find (and replace) values.
1173
+     *   - Construct RegExp's for the #define to find and replace values.
1135 1174
      *   - Store the existing #define line as a fast key to finding it later.
1136
-     *   - Determine the line number of the #define so it can be scrolled to.
1175
+     *   - Determine the line number of the #define
1137 1176
      *   - Gather nearby comments to be used as tooltips.
1138
-     *   - Look for JSON in nearby comments to use as select options.
1177
+     *   - Look for JSON in nearby comments for use as select options.
1178
+     *
1179
+     *  define_info[name]
1180
+     *    .type    type of define: switch, list, quoted, plain, or toggle
1181
+     *    .size    the number of items in a "list" type
1182
+     *    .options select options, if any
1183
+     *    .cindex  config index
1184
+     *    .field   pre containing the config text (config_list[cindex][0])
1185
+     *    .line    the full line from the config text
1186
+     *    .pre     any text preceding #define
1187
+     *    .define  the "#define NAME" text (may have leading spaces)
1188
+     *    .post    the text following the "#define NAME val" part
1189
+     *    .regex   regexp to get the value from the line
1190
+     *    .repl    regexp to replace the value in the line
1191
+     *    .val_i   the value's index in the .regex result
1139 1192
      */
1140 1193
     getDefineInfo: function(name, cindex) {
1141 1194
       if (cindex === undefined) cindex = 0;
1142 1195
       this.log('getDefineInfo:'+name,4);
1143
-      var $c = config_list[cindex], txt = $c.text();
1196
+      var $c = config_list[cindex], txt = $c.text(),
1197
+          info = { type:0, cindex:cindex, field:$c[0], val_i:2 }, post;
1144 1198
 
1145 1199
       // a switch line with no value
1146
-      var findDef = new RegExp('^([ \\t]*//)?([ \\t]*#define[ \\t]+' + name + ')([ \\t]*/[*/].*)?$', 'm'),
1147
-          result = findDef.exec(txt),
1148
-          info = { type:0, cindex:cindex, field:$c[0], val_i: 2 };
1149
-      if (result !== null) {
1200
+      var find = new RegExp('^([ \\t]*//)?([ \\t]*#define[ \\t]+' + name + ')([ \\t]*(/[*/].*)?)$', 'm'),
1201
+          r = find.exec(txt);
1202
+      if (r !== null) {
1203
+        post = r[3] == null ? '' : r[3];
1150 1204
         $.extend(info, {
1151
-          val_i:  1,
1152
-          type:   'switch',
1153
-          line:   result[0], // whole line
1154
-          pre:    result[1] == null ? '' : result[1].replace('//',''),
1155
-          define: result[2],
1156
-          post:   result[3] == null ? '' : result[3]
1205
+          type: 'switch',
1206
+          val_i: 1,
1207
+          regex: new RegExp('([ \\t]*//)?([ \\t]*' + r[2].regEsc() + post.regEsc() + ')', 'm'),
1208
+          repl:  new RegExp('([ \\t]*)(\/\/)?([ \\t]*' + r[2].regEsc() + post.regEsc() + ')', 'm')
1157 1209
         });
1158
-        info.regex = new RegExp('([ \\t]*//)?([ \\t]*' + info.define.regEsc() + info.post.regEsc() + ')', 'm');
1159
-        info.repl =  new RegExp('([ \\t]*)(\/\/)?([ \\t]*' + info.define.regEsc() + info.post.regEsc() + ')', 'm');
1160 1210
       }
1161 1211
       else {
1162 1212
         // a define with curly braces
1163
-        findDef = new RegExp('^(.*//)?(.*#define[ \\t]+' + name + '[ \\t]+)(\{[^\}]*\})([ \\t]*/[*/].*)?$', 'm');
1164
-        result = findDef.exec(txt);
1165
-        if (result !== null) {
1213
+        find = new RegExp('^(.*//)?(.*#define[ \\t]+' + name + '[ \\t]+)(\{[^\}]*\})([ \\t]*(/[*/].*)?)$', 'm');
1214
+        r = find.exec(txt);
1215
+        if (r !== null) {
1216
+          post = r[4] == null ? '' : r[4];
1166 1217
           $.extend(info, {
1167
-            type:   'list',
1168
-            line:   result[0],
1169
-            pre:    result[1] == null ? '' : result[1].replace('//',''),
1170
-            define: result[2],
1171
-            size:   result[3].split(',').length,
1172
-            post:   result[4] == null ? '' : result[4]
1218
+            type:  'list',
1219
+            size:  r[3].split(',').length,
1220
+            regex: new RegExp('([ \\t]*//)?[ \\t]*' + r[2].regEsc() + '\{([^\}]*)\}' + post.regEsc(), 'm'),
1221
+            repl:  new RegExp('(([ \\t]*//)?[ \\t]*' + r[2].regEsc() + '\{)[^\}]*(\}' + post.regEsc() + ')', 'm')
1173 1222
           });
1174
-          info.regex = new RegExp('([ \\t]*//)?[ \\t]*' + info.define.regEsc() + '\{([^\}]*)\}' + info.post.regEsc(), 'm');
1175
-          info.repl  = new RegExp('(([ \\t]*//)?[ \\t]*' + info.define.regEsc() + '\{)[^\}]*(\}' + info.post.regEsc() + ')', 'm');
1176 1223
         }
1177 1224
         else {
1178 1225
           // a define with quotes
1179
-          findDef = new RegExp('^(.*//)?(.*#define[ \\t]+' + name + '[ \\t]+)("[^"]*")([ \\t]*/[*/].*)?$', 'm');
1180
-          result = findDef.exec(txt);
1181
-          if (result !== null) {
1226
+          find = new RegExp('^(.*//)?(.*#define[ \\t]+' + name + '[ \\t]+)("[^"]*")([ \\t]*(/[*/].*)?)$', 'm');
1227
+          r = find.exec(txt);
1228
+          if (r !== null) {
1229
+            post = r[4] == null ? '' : r[4];
1182 1230
             $.extend(info, {
1183
-              type:   'quoted',
1184
-              line:   result[0],
1185
-              pre:    result[1] == null ? '' : result[1].replace('//',''),
1186
-              define: result[2],
1187
-              post:   result[4] == null ? '' : result[4]
1231
+              type:  'quoted',
1232
+              regex: new RegExp('([ \\t]*//)?[ \\t]*' + r[2].regEsc() + '"([^"]*)"' + post.regEsc(), 'm'),
1233
+              repl:  new RegExp('(([ \\t]*//)?[ \\t]*' + r[2].regEsc() + '")[^"]*("' + post.regEsc() + ')', 'm')
1188 1234
             });
1189
-            info.regex = new RegExp('([ \\t]*//)?[ \\t]*' + info.define.regEsc() + '"([^"]*)"' + info.post.regEsc(), 'm');
1190
-            info.repl  = new RegExp('(([ \\t]*//)?[ \\t]*' + info.define.regEsc() + '")[^"]*("' + info.post.regEsc() + ')', 'm');
1191 1235
           }
1192 1236
           else {
1193 1237
             // a define with no quotes
1194
-            findDef = new RegExp('^([ \\t]*//)?([ \\t]*#define[ \\t]+' + name + '[ \\t]+)(\\S*)([ \\t]*/[*/].*)?$', 'm');
1195
-            result = findDef.exec(txt);
1196
-            if (result !== null) {
1238
+            find = new RegExp('^([ \\t]*//)?([ \\t]*#define[ \\t]+' + name + '[ \\t]+)(\\S*)([ \\t]*(/[*/].*)?)$', 'm');
1239
+            r = find.exec(txt);
1240
+            if (r !== null) {
1241
+              post = r[4] == null ? '' : r[4];
1197 1242
               $.extend(info, {
1198
-                type:   'plain',
1199
-                line:   result[0],
1200
-                pre:    result[1] == null ? '' : result[1].replace('//',''),
1201
-                define: result[2],
1202
-                post:   result[4] == null ? '' : result[4]
1243
+                type:  'plain',
1244
+                regex: new RegExp('([ \\t]*//)?[ \\t]*' + r[2].regEsc() + '(\\S*)' + post.regEsc(), 'm'),
1245
+                repl:  new RegExp('(([ \\t]*//)?[ \\t]*' + r[2].regEsc() + ')\\S*(' + post.regEsc() + ')', 'm')
1203 1246
               });
1204
-              if (result[3].match(/false|true/)) {
1247
+              if (r[3].match(/false|true/)) {
1205 1248
                 info.type = 'toggle';
1206 1249
                 info.options = ['false','true'];
1207 1250
               }
1208
-              info.regex = new RegExp('([ \\t]*//)?[ \\t]*' + info.define.regEsc() + '(\\S*)' + info.post.regEsc(), 'm');
1209
-              info.repl  = new RegExp('(([ \\t]*//)?[ \\t]*' + info.define.regEsc() + ')\\S*(' + info.post.regEsc() + ')', 'm');
1210 1251
             }
1211 1252
           }
1212 1253
         }
@@ -1214,19 +1255,25 @@ window.configuratorApp = (function(){
1214 1255
 
1215 1256
       // Success?
1216 1257
       if (info.type) {
1258
+        $.extend(info, {
1259
+          line:   r[0],
1260
+          pre:    r[1] == null ? '' : r[1].replace('//',''),
1261
+          define: r[2],
1262
+          post:   post
1263
+        });
1217 1264
         // Get the end-of-line comment, if there is one
1218 1265
         var tooltip = '', eoltip = '';
1219
-        findDef = new RegExp('.*#define[ \\t].*/[/*]+[ \\t]*(.*)');
1220
-        if (info.line.search(findDef) >= 0)
1221
-          eoltip = tooltip = info.line.replace(findDef, '$1');
1266
+        find = new RegExp('.*#define[ \\t].*/[/*]+[ \\t]*(.*)');
1267
+        if (info.line.search(find) >= 0)
1268
+          eoltip = tooltip = info.line.replace(find, '$1');
1222 1269
 
1223 1270
         // Get all the comments immediately before the item
1224
-        var r, s;
1225
-        findDef = new RegExp('(([ \\t]*(//|#)[^\n]+\n){1,4})' + info.line.regEsc(), 'g');
1226
-        if (r = findDef.exec(txt)) {
1271
+        var s;
1272
+        find = new RegExp('(([ \\t]*(//|#)[^\n]+\n){1,4})' + info.line.regEsc(), 'g');
1273
+        if (r = find.exec(txt)) {
1227 1274
           // Get the text of the found comments
1228
-          findDef = new RegExp('^[ \\t]*//+[ \\t]*(.*)[ \\t]*$', 'gm');
1229
-          while((s = findDef.exec(r[1])) !== null) {
1275
+          find = new RegExp('^[ \\t]*//+[ \\t]*(.*)[ \\t]*$', 'gm');
1276
+          while((s = find.exec(r[1])) !== null) {
1230 1277
             var tip = s[1].replace(/[ \\t]*(={5,}|(#define[ \\t]+.*|@section[ \\t]+\w+))[ \\t]*/g, '');
1231 1278
             if (tip.length) {
1232 1279
               if (tip.match(/^#define[ \\t]/) != null) tooltip = eoltip;
@@ -1248,16 +1295,14 @@ window.configuratorApp = (function(){
1248 1295
         }
1249 1296
 
1250 1297
         // Add .tooltip and .lineNum properties to the info
1251
-        findDef = new RegExp('^'+name); // Strip the name from the tooltip
1298
+        find = new RegExp('^'+name); // Strip the name from the tooltip
1252 1299
         var lineNum = this.getLineNumberOfText(info.line, txt);
1253 1300
 
1254 1301
         // See if this define is enabled conditionally
1255 1302
         var enable_cond = '';
1256
-        $.each(dependentGroups, function(cond,dat){
1303
+        $.each(dependent_groups, function(cond,dat){
1257 1304
           $.each(dat, function(i,o){
1258 1305
             if (o.cindex == cindex && lineNum > o.start && lineNum < o.end) {
1259
-              // self.log(name + " is in range " + o.start + "-" + o.end, 2);
1260
-              // if this setting is in a range, conditions are added
1261 1306
               if (enable_cond != '') enable_cond += ' && ';
1262 1307
               enable_cond += '(' + cond + ')';
1263 1308
             }
@@ -1265,7 +1310,7 @@ window.configuratorApp = (function(){
1265 1310
         });
1266 1311
 
1267 1312
         $.extend(info, {
1268
-          tooltip: '<strong>'+name+'</strong> '+tooltip.trim().replace(findDef,'').toHTML(),
1313
+          tooltip: '<strong>'+name+'</strong> '+tooltip.trim().replace(find,'').toHTML(),
1269 1314
           lineNum: lineNum,
1270 1315
           switchable: (info.type != 'switch' && info.line.match(/^[ \t]*\/\//)) || false, // Disabled? Mark as "switchable"
1271 1316
           enabled: enable_cond ? enable_cond : 'true'
@@ -1285,7 +1330,7 @@ window.configuratorApp = (function(){
1285 1330
      */
1286 1331
     getLineNumberOfText: function(line, txt) {
1287 1332
       var pos = txt.indexOf(line);
1288
-      return (pos < 0) ? pos : txt.substr(0, pos).lineCount();
1333
+      return (pos < 0) ? pos : txt.lineCount(pos);
1289 1334
     },
1290 1335
 
1291 1336
     /**

Loading…
Cancel
Save