浏览代码

More grouping, cleanup, start on overrides

Scott Lahteine 10 年前
父节点
当前提交
1149c24b86
共有 3 个文件被更改,包括 165 次插入123 次删除
  1. 1
    1
      Marlin/configurator/config/Configuration.h
  2. 0
    3
      Marlin/configurator/index.html
  3. 164
    119
      Marlin/configurator/js/configurator.js

+ 1
- 1
Marlin/configurator/config/Configuration.h 查看文件

347
 // @section machine
347
 // @section machine
348
 
348
 
349
 // For Inverting Stepper Enable Pins (Active Low) use 0, Non Inverting (Active High) use 1
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
 #define X_ENABLE_ON 0
351
 #define X_ENABLE_ON 0
352
 #define Y_ENABLE_ON 0
352
 #define Y_ENABLE_ON 0
353
 #define Z_ENABLE_ON 0
353
 #define Z_ENABLE_ON 0

+ 0
- 3
Marlin/configurator/index.html 查看文件

65
           <label class="newline">Temp Sensor 2:</label><select name="TEMP_SENSOR_2"></select>
65
           <label class="newline">Temp Sensor 2:</label><select name="TEMP_SENSOR_2"></select>
66
           <label class="newline">Bed Temp Sensor:</label><select name="TEMP_SENSOR_BED"></select>
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
           <label>Max Diff:</label>
68
           <label>Max Diff:</label>
72
             <input name="MAX_REDUNDANT_TEMP_SENSOR_DIFF" type="text" size="3" maxlength="2" />
69
             <input name="MAX_REDUNDANT_TEMP_SENSOR_DIFF" type="text" size="3" maxlength="2" />
73
 
70
 

+ 164
- 119
Marlin/configurator/js/configurator.js 查看文件

85
 String.prototype.zeroPad = function(len)     { return this.prePad(len, '0'); };
85
 String.prototype.zeroPad = function(len)     { return this.prePad(len, '0'); };
86
 String.prototype.toHTML = function()         { return jQuery('<div>').text(this).html(); };
86
 String.prototype.toHTML = function()         { return jQuery('<div>').text(this).html(); };
87
 String.prototype.regEsc = function()         { return this.replace(/[.?*+^$[\]\\(){}|-]/g, "\\$&"); }
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
 String.prototype.toLabel = function()        { return this.replace(/[\[\]]/g, '').replace(/_/g, ' ').toTitleCase(); }
91
 String.prototype.toLabel = function()        { return this.replace(/[\[\]]/g, '').replace(/_/g, ' ').toTitleCase(); }
90
 String.prototype.toTitleCase = function()    { return this.replace(/([A-Z])(\w+)/gi, function(m,p1,p2) { return p1.toUpperCase() + p2.toLowerCase(); }); }
92
 String.prototype.toTitleCase = function()    { return this.replace(/([A-Z])(\w+)/gi, function(m,p1,p2) { return p1.toUpperCase() + p2.toLowerCase(); }); }
91
 Number.prototype.limit = function(m1, m2)  {
93
 Number.prototype.limit = function(m1, m2)  {
148
       $config = $cfg.find('pre'), $config_adv = $adv.find('pre'),
150
       $config = $cfg.find('pre'), $config_adv = $adv.find('pre'),
149
       config_file_list = [ boards_file, config_file, config_adv_file ],
151
       config_file_list = [ boards_file, config_file, config_adv_file ],
150
       config_list = [ $config, $config_adv ],
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
       boards_list = {},
159
       boards_list = {},
157
       therms_list = {},
160
       therms_list = {},
158
       total_config_lines,
161
       total_config_lines,
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
     initDefineList: function(cindex) {
355
     initDefineList: function(cindex) {
345
       var section = 'hidden',
356
       var section = 'hidden',
346
           leave_out_defines = ['CONFIGURATION_H', 'CONFIGURATION_ADV_H'],
357
           leave_out_defines = ['CONFIGURATION_H', 'CONFIGURATION_ADV_H'],
347
           define_sect = {},
358
           define_sect = {},
359
+          occ_list = {},
348
           txt = config_list[cindex].text(),
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
       while((r = findDef.exec(txt)) !== null) {
362
       while((r = findDef.exec(txt)) !== null) {
351
         var name = r[2];
363
         var name = r[2];
352
-        if (r[1] == '@section')
364
+        if (r[1] == '@section') {
353
           section = name;
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
       define_list[cindex] = Object.keys(define_sect);
382
       define_list[cindex] = Object.keys(define_sect);
383
+      define_occur[cindex] = occ_list;
358
       $.extend(define_section, define_sect);
384
       $.extend(define_section, define_sect);
359
       this.log(define_list[cindex], 2);
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
      * Find the defines in one of the configs that are just variants.
391
      * Find the defines in one of the configs that are just variants.
364
      * Group them together for form-building and other uses.
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
     refreshDefineGroups: function(cindex) {
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
       var match_prev, patt, title, nameList, groups = {}, match_section;
401
       var match_prev, patt, title, nameList, groups = {}, match_section;
369
       $.each(define_list[cindex], function(i, name) {
402
       $.each(define_list[cindex], function(i, name) {
370
         if (match_prev) {
403
         if (match_prev) {
387
         if (!match_prev) {
420
         if (!match_prev) {
388
           var r = findDef.exec(name);
421
           var r = findDef.exec(name);
389
           if (r != null) {
422
           if (r != null) {
390
-            switch(r[2]) {
423
+            title = '';
424
+            switch(r[2].toUpperCase()) {
391
               case '0':
425
               case '0':
392
                 patt = '([0123])';
426
                 patt = '([0123])';
393
                 title = 'N';
427
                 title = 'N';
400
                 patt = 'E([0-3])';
434
                 patt = 'E([0-3])';
401
                 title = 'E';
435
                 title = 'E';
402
                 break;
436
                 break;
403
-              case 'bedKp':
437
+              case 'BEDKP':
404
                 patt = 'bed(K[pid])';
438
                 patt = 'bed(K[pid])';
405
                 title = 'BED_PID';
439
                 title = 'BED_PID';
406
                 break;
440
                 break;
407
-              case 'Kp':
441
+              case 'KP':
408
                 patt = '(K[pid])';
442
                 patt = '(K[pid])';
409
                 title = 'PID';
443
                 title = 'PID';
410
                 break;
444
                 break;
445
+              case 'LEFT':
446
+              case 'RIGHT':
447
+              case 'BACK':
448
+              case 'FRONT':
449
+                patt = '([LRBF])(EFT|IGHT|ACK|RONT)';
450
+                break;
411
               case 'MAX':
451
               case 'MAX':
412
               case 'MIN':
452
               case 'MIN':
413
                 patt = '(MAX|MIN)';
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
                 break;
462
                 break;
416
               case 'XMIN':
463
               case 'XMIN':
417
               case 'XMAX':
464
               case 'XMAX':
425
             if (patt) {
472
             if (patt) {
426
               patt = '^' + r[1] + patt + r[7] + '$';
473
               patt = '^' + r[1] + patt + r[7] + '$';
427
               title = r[1] + title + r[7];
474
               title = r[1] + title + r[7];
428
-              match_prev = new RegExp(patt);
475
+              match_prev = new RegExp(patt, 'i');
429
               match_section = define_section[name];
476
               match_section = define_section[name];
430
               nameList = [ name ];
477
               nameList = [ name ];
431
             }
478
             }
433
         }
480
         }
434
       });
481
       });
435
       define_groups[cindex] = groups;
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
     initDependentGroups: function() {
497
     initDependentGroups: function() {
444
       var findBlock = /^[ \t]*#(ifn?def|if|else|endif)[ \t]*(.*)([ \t]*\/\/[^\n]+)?$/gm,
498
       var findBlock = /^[ \t]*#(ifn?def|if|else|endif)[ \t]*(.*)([ \t]*\/\/[^\n]+)?$/gm,
445
           leave_out_defines = ['CONFIGURATION_H', 'CONFIGURATION_ADV_H'];
499
           leave_out_defines = ['CONFIGURATION_H', 'CONFIGURATION_ADV_H'];
500
+      dependent_groups = {};
446
       $.each(config_list, function(i, $v) {
501
       $.each(config_list, function(i, $v) {
447
         var ifStack = [];
502
         var ifStack = [];
448
         var r, txt = $v.text();
503
         var r, txt = $v.text();
449
         while((r = findBlock.exec(txt)) !== null) {
504
         while((r = findBlock.exec(txt)) !== null) {
450
-          var lineNum = txt.substr(0, r.index).lineCount();
505
+          var lineNum = txt.lineCount(r.index);
451
           var code = r[2].replace(/[ \t]*\/\/.*$/, '');
506
           var code = r[2].replace(/[ \t]*\/\/.*$/, '');
452
           switch(r[1]) {
507
           switch(r[1]) {
453
             case 'if':
508
             case 'if':
481
               if (c) {
536
               if (c) {
482
                 var cond = c[0], line = c[1];
537
                 var cond = c[0], line = c[1];
483
                 self.log("pop " + c[0], 4);
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
                 if (r[1] == 'else') {
541
                 if (r[1] == 'else') {
487
                   // Reverse the condition
542
                   // Reverse the condition
488
                   cond = (cond.indexOf('!') === 0) ? cond.substr(1) : ('!'+cond);
543
                   cond = (cond.indexOf('!') === 0) ? cond.substr(1) : ('!'+cond);
544
               grouping = true;
599
               grouping = true;
545
               g_subitem = false;
600
               g_subitem = false;
546
               var grp = group[name];
601
               var grp = group[name];
547
-              g_pattern = grp.pattern;
602
+              g_section = section;
548
               g_class = 'one_of_' + grp.count;
603
               g_class = 'one_of_' + grp.count;
604
+              g_pattern = grp.pattern;
605
+              g_regex = new RegExp(g_pattern, 'i');
549
               label_text = grp.title;
606
               label_text = grp.title;
550
-              g_regex = new RegExp(g_pattern);
551
-              g_section = section;
552
               sublabel = g_regex.exec(name)[1];
607
               sublabel = g_regex.exec(name)[1];
553
             }
608
             }
554
 
609
 
596
               $newfield.attr({id:name,name:name,class:'added',disabled:!avail}).unblock(avail);
651
               $newfield.attr({id:name,name:name,class:'added',disabled:!avail}).unblock(avail);
597
               if (grouping) {
652
               if (grouping) {
598
                 $newfield.addClass(g_class);
653
                 $newfield.addClass(g_class);
599
-                if (sublabel)
654
+                if (sublabel) {
600
                   $ff.append($('<label>',{class:'added sublabel',for:name}).text(sublabel.toTitleCase()).unblock(avail));
655
                   $ff.append($('<label>',{class:'added sublabel',for:name}).text(sublabel.toTitleCase()).unblock(avail));
656
+                }
601
               }
657
               }
602
               // Add the new field to the form
658
               // Add the new field to the form
603
               $ff.append($newfield);
659
               $ff.append($newfield);
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
     refreshDependentFields: function() {
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
       $.each(define_list, function(e,def_list){
886
       $.each(define_list, function(e,def_list){
844
         $.each(def_list, function(i, name) {
887
         $.each(def_list, function(i, name) {
845
           var inf = define_info[name];
888
           var inf = define_info[name];
846
           if (inf && inf.enabled != 'true') {
889
           if (inf && inf.enabled != 'true') {
847
             var $elm = $('#'+name), ena = eval(inf.enabled);
890
             var $elm = $('#'+name), ena = eval(inf.enabled);
848
             var isEnabled = (inf.type == 'switch') || self.defineIsEnabled(name);
891
             var isEnabled = (inf.type == 'switch') || self.defineIsEnabled(name);
849
-            // Make any switch toggle also
850
             $('#'+name+'-switch').attr('disabled', !ena);
892
             $('#'+name+'-switch').attr('disabled', !ena);
851
             $elm.attr('disabled', !(ena && isEnabled)).unblock(ena);
893
             $elm.attr('disabled', !(ena && isEnabled)).unblock(ena);
852
-            //self.log("Setting " + name + " to " + (ena && isEnabled ? 'enabled' : 'disabled'));
853
             $('label[for="'+name+'"]').unblock(ena);
894
             $('label[for="'+name+'"]').unblock(ena);
854
           }
895
           }
855
         });
896
         });
873
           $tipme.hover(
914
           $tipme.hover(
874
             function() {
915
             function() {
875
               if ($('#tipson input').prop('checked')) {
916
               if ($('#tipson input').prop('checked')) {
876
-                var pos = $tipme.position();
917
+                var pos = $tipme.position(), px = $tipme.width()/2;
877
                 $tooltip.html(inf.tooltip)
918
                 $tooltip.html(inf.tooltip)
878
                   .append('<span>')
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
                   .show();
921
                   .show();
881
                 if (hover_timer) {
922
                 if (hover_timer) {
882
                   clearTimeout(hover_timer);
923
                   clearTimeout(hover_timer);
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
     defineValue: function(name) {
1003
     defineValue: function(name) {
963
       this.log('defineValue:'+name,4);
1004
       this.log('defineValue:'+name,4);
964
       var inf = define_info[name];
1005
       var inf = define_info[name];
965
       if (inf == null) return 'n/a';
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
     defineIsEnabled: function(name) {
1017
     defineIsEnabled: function(name) {
978
       this.log('defineIsEnabled:'+name,4);
1018
       this.log('defineIsEnabled:'+name,4);
979
       var inf = define_info[name];
1019
       var inf = define_info[name];
980
       if (inf == null) return false;
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
       this.log(name + ' = ' + on, 2);
1026
       this.log(name + ' = ' + on, 2);
988
 
1027
 
989
       return on;
1028
       return on;
1054
 
1093
 
1055
       var hilite_token = '[HIGHLIGHTER-TOKEN]';
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
       inf.line = newline;
1097
       inf.line = newline;
1059
 
1098
 
1060
       // Convert txt into HTML before storing
1099
       // Convert txt into HTML before storing
1131
      * Get information about a #define from configuration file text:
1170
      * Get information about a #define from configuration file text:
1132
      *
1171
      *
1133
      *   - Pre-examine the #define for its prefix, value position, suffix, etc.
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
      *   - Store the existing #define line as a fast key to finding it later.
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
      *   - Gather nearby comments to be used as tooltips.
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
     getDefineInfo: function(name, cindex) {
1193
     getDefineInfo: function(name, cindex) {
1141
       if (cindex === undefined) cindex = 0;
1194
       if (cindex === undefined) cindex = 0;
1142
       this.log('getDefineInfo:'+name,4);
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
       // a switch line with no value
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
         $.extend(info, {
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
       else {
1211
       else {
1162
         // a define with curly braces
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
           $.extend(info, {
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
         else {
1224
         else {
1178
           // a define with quotes
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
             $.extend(info, {
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
           else {
1236
           else {
1193
             // a define with no quotes
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
               $.extend(info, {
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
                 info.type = 'toggle';
1248
                 info.type = 'toggle';
1206
                 info.options = ['false','true'];
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
 
1255
 
1215
       // Success?
1256
       // Success?
1216
       if (info.type) {
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
         // Get the end-of-line comment, if there is one
1264
         // Get the end-of-line comment, if there is one
1218
         var tooltip = '', eoltip = '';
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
         // Get all the comments immediately before the item
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
           // Get the text of the found comments
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
             var tip = s[1].replace(/[ \\t]*(={5,}|(#define[ \\t]+.*|@section[ \\t]+\w+))[ \\t]*/g, '');
1277
             var tip = s[1].replace(/[ \\t]*(={5,}|(#define[ \\t]+.*|@section[ \\t]+\w+))[ \\t]*/g, '');
1231
             if (tip.length) {
1278
             if (tip.length) {
1232
               if (tip.match(/^#define[ \\t]/) != null) tooltip = eoltip;
1279
               if (tip.match(/^#define[ \\t]/) != null) tooltip = eoltip;
1248
         }
1295
         }
1249
 
1296
 
1250
         // Add .tooltip and .lineNum properties to the info
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
         var lineNum = this.getLineNumberOfText(info.line, txt);
1299
         var lineNum = this.getLineNumberOfText(info.line, txt);
1253
 
1300
 
1254
         // See if this define is enabled conditionally
1301
         // See if this define is enabled conditionally
1255
         var enable_cond = '';
1302
         var enable_cond = '';
1256
-        $.each(dependentGroups, function(cond,dat){
1303
+        $.each(dependent_groups, function(cond,dat){
1257
           $.each(dat, function(i,o){
1304
           $.each(dat, function(i,o){
1258
             if (o.cindex == cindex && lineNum > o.start && lineNum < o.end) {
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
               if (enable_cond != '') enable_cond += ' && ';
1306
               if (enable_cond != '') enable_cond += ' && ';
1262
               enable_cond += '(' + cond + ')';
1307
               enable_cond += '(' + cond + ')';
1263
             }
1308
             }
1265
         });
1310
         });
1266
 
1311
 
1267
         $.extend(info, {
1312
         $.extend(info, {
1268
-          tooltip: '<strong>'+name+'</strong> '+tooltip.trim().replace(findDef,'').toHTML(),
1313
+          tooltip: '<strong>'+name+'</strong> '+tooltip.trim().replace(find,'').toHTML(),
1269
           lineNum: lineNum,
1314
           lineNum: lineNum,
1270
           switchable: (info.type != 'switch' && info.line.match(/^[ \t]*\/\//)) || false, // Disabled? Mark as "switchable"
1315
           switchable: (info.type != 'switch' && info.line.match(/^[ \t]*\/\//)) || false, // Disabled? Mark as "switchable"
1271
           enabled: enable_cond ? enable_cond : 'true'
1316
           enabled: enable_cond ? enable_cond : 'true'
1285
      */
1330
      */
1286
     getLineNumberOfText: function(line, txt) {
1331
     getLineNumberOfText: function(line, txt) {
1287
       var pos = txt.indexOf(line);
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
     /**

正在加载...
取消
保存