Browse Source

Parse and use dependent groups

- Parse #if, #ifdef, etc. for rules to enable fields
Scott Lahteine 10 years ago
parent
commit
f994729999

+ 4
- 0
Marlin/configurator/css/configurator.css View File

91
 	margin-right: -450px;
91
 	margin-right: -450px;
92
 	text-align: right;
92
 	text-align: right;
93
 	}
93
 	}
94
+label.blocked { color: #AAA; }
95
+
94
 input[type="text"], select { margin: 0.75em 0 0; }
96
 input[type="text"], select { margin: 0.75em 0 0; }
95
 input[type="checkbox"], input[type="radio"], input[type="file"] { margin: 1em 0 0; }
97
 input[type="checkbox"], input[type="radio"], input[type="file"] { margin: 1em 0 0; }
96
 input[type="checkbox"].enabler, input[type="radio"].enabler { margin-left: 1em; }
98
 input[type="checkbox"].enabler, input[type="radio"].enabler { margin-left: 1em; }
308
 	.disclose { display: none; }
310
 	.disclose { display: none; }
309
 
311
 
310
 }
312
 }
313
+
314
+/*.blocked { display: none; }*/

+ 1
- 1
Marlin/configurator/index.html View File

26
 
26
 
27
         <div id="tooltip"></div>
27
         <div id="tooltip"></div>
28
 
28
 
29
-        <label>Drop Files Here:</label><input type="file" id="file-upload" />
29
+        <label>Drop Files:</label><input type="file" id="file-upload" />
30
         <label id="tipson"><input type="checkbox" checked /> ?</label>
30
         <label id="tipson"><input type="checkbox" checked /> ?</label>
31
         <a href="" class="download-all">Download Zip</a>
31
         <a href="" class="download-all">Download Zip</a>
32
 
32
 

+ 209
- 67
Marlin/configurator/js/configurator.js View File

142
       $tooltip = $('#tooltip'),
142
       $tooltip = $('#tooltip'),
143
       $cfg = $('#config_text'), $adv = $('#config_adv_text'),
143
       $cfg = $('#config_text'), $adv = $('#config_adv_text'),
144
       $config = $cfg.find('pre'), $config_adv = $adv.find('pre'),
144
       $config = $cfg.find('pre'), $config_adv = $adv.find('pre'),
145
+      define_info = {},
145
       define_list = [[],[]],
146
       define_list = [[],[]],
146
       define_section = {},
147
       define_section = {},
148
+      dependentGroups = {},
147
       boards_list = {},
149
       boards_list = {},
148
       therms_list = {},
150
       therms_list = {},
149
       total_config_lines,
151
       total_config_lines,
321
     /**
323
     /**
322
      * Init the thermistors array from the Configuration.h file
324
      * Init the thermistors array from the Configuration.h file
323
      */
325
      */
324
-    initThermistorsFromText: function(txt) {
326
+    initThermistorList: function(txt) {
325
       // Get all the thermistors and save them into an object
327
       // Get all the thermistors and save them into an object
326
       var r, s, findDef = new RegExp('(//.*\n)+\\s+(#define[ \\t]+TEMP_SENSOR_0)', 'g');
328
       var r, s, findDef = new RegExp('(//.*\n)+\\s+(#define[ \\t]+TEMP_SENSOR_0)', 'g');
327
       r = findDef.exec(txt);
329
       r = findDef.exec(txt);
334
     /**
336
     /**
335
      * Get all the unique define names
337
      * Get all the unique define names
336
      */
338
      */
337
-    updateDefinesFromText: function(index, txt) {
339
+    initDefineList: function(index, txt) {
338
       var section = 'hidden',
340
       var section = 'hidden',
339
           leave_out_defines = ['CONFIGURATION_H', 'CONFIGURATION_ADV_H'],
341
           leave_out_defines = ['CONFIGURATION_H', 'CONFIGURATION_ADV_H'],
340
           define_sect = {},
342
           define_sect = {},
343
         var name = r[2];
345
         var name = r[2];
344
         if (r[1] == '@section')
346
         if (r[1] == '@section')
345
           section = name;
347
           section = name;
346
-        else if ($.inArray(name, leave_out_defines) < 0 && !(name in define_sect))
348
+        else if ($.inArray(name, leave_out_defines) < 0 && !(name in define_section) && !(name in define_sect))
347
           define_sect[name] = section;
349
           define_sect[name] = section;
348
       }
350
       }
349
       define_list[index] = Object.keys(define_sect);
351
       define_list[index] = Object.keys(define_sect);
352
     },
354
     },
353
 
355
 
354
     /**
356
     /**
357
+     * Get all condition blocks and their line ranges.
358
+     * Conditions may control multiple line-ranges
359
+     * across both config files.
360
+     */
361
+    initDependentGroups: function() {
362
+      var findDef = /^[ \t]*#(ifn?def|if|else|endif)[ \t]*(.*)([ \t]*\/\/[^\n]+)?$/gm,
363
+          leave_out_defines = ['CONFIGURATION_H', 'CONFIGURATION_ADV_H'];
364
+      $.each([$config, $config_adv], function(i, $v) {
365
+        var ifStack = [];
366
+        var r, txt = $v.text();
367
+        while((r = findDef.exec(txt)) !== null) {
368
+          var lineNum = txt.substr(0, r.index).lineCount();
369
+          var code = r[2].replace(/[ \t]*\/\/.*$/, '');
370
+          switch(r[1]) {
371
+            case 'if':
372
+              var code = code
373
+                .replace(/([A-Z][A-Z0-9_]+)/g, 'self.defineValue("$1")')
374
+                .replace(/defined[ \t]*\(?[ \t]*self.defineValue\(("[A-Z][A-Z0-9_]+")\)[ \t]*\)?/g, 'self.defineIsEnabled($1)');
375
+              ifStack.push(['('+code+')', lineNum]);  // #if starts on next line
376
+              self.log("push     if " + code, 4);
377
+              break;
378
+            case 'ifdef':
379
+              if ($.inArray(code, leave_out_defines) < 0) {
380
+                ifStack.push(['self.defineIsEnabled("' + code + '")', lineNum]);
381
+                self.log("push  ifdef " + code, 4);
382
+              }
383
+              else {
384
+                ifStack.push(0);
385
+              }
386
+              break;
387
+            case 'ifndef':
388
+              if ($.inArray(code, leave_out_defines) < 0) {
389
+                ifStack.push(['!self.defineIsEnabled("' + code + '")', lineNum]);
390
+                self.log("push ifndef " + code, 4);
391
+              }
392
+              else {
393
+                ifStack.push(0);
394
+              }
395
+              break;
396
+            case 'else':
397
+            case 'endif':
398
+              var c = ifStack.pop();
399
+              if (c) {
400
+                var cond = c[0], line = c[1];
401
+                self.log("pop " + c[0], 4);
402
+                if (dependentGroups[cond] === undefined) dependentGroups[cond] = [];
403
+                dependentGroups[cond].push({adv:i,start:line,end:lineNum});
404
+                if (r[1] == 'else') {
405
+                  // Reverse the condition
406
+                  cond = (cond.indexOf('!') === 0) ? cond.substr(1) : ('!'+cond);
407
+                  ifStack.push([cond, lineNum]);
408
+                  self.log("push " + cond, 4);
409
+                }
410
+              }
411
+              else {
412
+                if (r[1] == 'else') ifStack.push(0);
413
+              }
414
+              break;
415
+          }
416
+        }
417
+      }); // text blobs loop
418
+    },
419
+
420
+    /**
421
+     * Init all the defineInfo structures after reload
422
+     * The "enabled" field may need an update for newly-loaded dependencies
423
+     */
424
+    initDefineInfo: function() {
425
+      $.each(define_list, function(e,def_list){
426
+        var adv = e == 1;
427
+        $.each(def_list, function(i,name) {
428
+          define_info[name] = self.getDefineInfo(name, adv);
429
+        });
430
+      });
431
+    },
432
+
433
+    /**
355
      * Create fields for any defines that have none
434
      * Create fields for any defines that have none
356
      */
435
      */
357
-    createFieldsForDefines: function(adv) {
358
-      var e = adv ? 1 : 0, n = 0;
359
-      var fail_list = [];
436
+    createFieldsForDefines: function(e) {
437
+      var n = 0, fail_list = [];
360
       $.each(define_list[e], function(i,name) {
438
       $.each(define_list[e], function(i,name) {
361
         var section = define_section[name];
439
         var section = define_section[name];
362
         if (section != 'hidden' && !$('#'+name).length) {
440
         if (section != 'hidden' && !$('#'+name).length) {
363
-          var inf = self.getDefineInfo(name, adv);
441
+          var inf = define_info[name];
364
 
442
 
365
           if (inf) {
443
           if (inf) {
366
 
444
 
367
             var $ff = $('#'+section), $newfield,
445
             var $ff = $('#'+section), $newfield,
446
+                avail = eval(inf.enabled),
368
                 $newlabel = $('<label>',{for:name,class:'added'}).text(name.toLabel());
447
                 $newlabel = $('<label>',{for:name,class:'added'}).text(name.toLabel());
369
 
448
 
449
+            if (!avail) $newlabel.addClass('blocked');
450
+
370
             // if (!(++n % 3))
451
             // if (!(++n % 3))
371
               $newlabel.addClass('newline');
452
               $newlabel.addClass('newline');
372
 
453
 
376
             if (inf.type == 'list') {
457
             if (inf.type == 'list') {
377
               for (var i=0; i<inf.size; i++) {
458
               for (var i=0; i<inf.size; i++) {
378
                 var fieldname = i > 0 ? name+'-'+i : name;
459
                 var fieldname = i > 0 ? name+'-'+i : name;
379
-                $newfield = $('<input>',{type:'text',size:6,maxlength:10,id:fieldname,name:fieldname,class:'subitem added'}).prop({defineInfo:inf});
460
+                $newfield = $('<input>',{type:'text',size:6,maxlength:10,id:fieldname,name:fieldname,class:'subitem added',disabled:!avail});
461
+                if (!avail) $newfield.addClass('blocked');
380
                 $ff.append($newfield);
462
                 $ff.append($newfield);
381
               }
463
               }
382
             }
464
             }
396
               else {
478
               else {
397
                 $newfield = inf.type == 'switch' ? $('<input>',{type:'checkbox'}) : $('<input>',{type:'text',size:10,maxlength:40});
479
                 $newfield = inf.type == 'switch' ? $('<input>',{type:'checkbox'}) : $('<input>',{type:'text',size:10,maxlength:40});
398
               }
480
               }
399
-              $newfield.attr({id:name,name:name,class:'added'}).prop({defineInfo:inf});
481
+              $newfield.attr({id:name,name:name,class:'added',disabled:!avail});
482
+              if (!avail) $newfield.addClass('blocked');
400
               // Add the new field to the form
483
               // Add the new field to the form
401
               $ff.append($newfield);
484
               $ff.append($newfield);
402
             }
485
             }
442
           if (has_boards) {
525
           if (has_boards) {
443
             $config.text(txt);
526
             $config.text(txt);
444
             total_config_lines = txt.lineCount();
527
             total_config_lines = txt.lineCount();
445
-            // this.initThermistorsFromText(txt);
528
+            // this.initThermistorList(txt);
446
             init_index = 0;
529
             init_index = 0;
447
             has_config = true;
530
             has_config = true;
448
             if (has_config_adv)
531
             if (has_config_adv)
466
           }
549
           }
467
           break;
550
           break;
468
       }
551
       }
469
-      // When a config file loads defines might change
552
+      // When a config file loads defines need update
470
       if (init_index != null) {
553
       if (init_index != null) {
471
         var adv = init_index == 1;
554
         var adv = init_index == 1;
555
+        // Purge old fields from the form, clear the define list
472
         this.purgeAddedFields(init_index);
556
         this.purgeAddedFields(init_index);
473
-        this.updateDefinesFromText(init_index, txt);
557
+        // Build the define_list
558
+        this.initDefineList(init_index, txt);
474
         // TODO: Find sequential names and group them
559
         // TODO: Find sequential names and group them
475
         //       Allows related settings to occupy one line in the form
560
         //       Allows related settings to occupy one line in the form
476
           // this.refreshSequentialDefines();
561
           // this.refreshSequentialDefines();
477
-        // TODO: Get dependent groups (#ifdef's) from text
478
-        //       Allows parent to hide/show or disable/enable dependent fields!
479
-          // this.refreshDependentGroups(); // (from all config text)
480
-        this.createFieldsForDefines(adv);
481
-        this.refreshConfigForm(init_index); // TODO: <-- hide dependent fields
562
+        // Build the dependent defines list
563
+        this.initDependentGroups(); // all config text
564
+        // Get define_info for all known defines
565
+        this.initDefineInfo();      // all config text
566
+        // Create new fields
567
+        this.createFieldsForDefines(init_index); // create new fields
568
+        // Init the fields, set values, etc
569
+        this.refreshConfigForm(init_index);
482
         this.activateDownloadLink(adv);
570
         this.activateDownloadLink(adv);
483
       }
571
       }
484
       this.setMessage(err
572
       this.setMessage(err
595
       // Refresh the motherboard menu with new options
683
       // Refresh the motherboard menu with new options
596
       $('#MOTHERBOARD').html('').addOptions(boards_list);
684
       $('#MOTHERBOARD').html('').addOptions(boards_list);
597
 
685
 
598
-      // Init all existing fields, getting define info for any that need it
686
+      // Init all existing fields, getting define info for those that need it
599
       // refreshing the options and updating their current values
687
       // refreshing the options and updating their current values
600
       $.each(define_list[init_index], function() {
688
       $.each(define_list[init_index], function() {
601
-        if ($('#'+this).length)
602
-          self.initField(this,init_index==1);
689
+        if ($('#'+this).length) {
690
+          self.initField(this);
691
+          self.initFieldValue(this);
692
+        }
603
         else
693
         else
604
           self.log(this + " is not on the page yet.", 2);
694
           self.log(this + " is not on the page yet.", 2);
605
       });
695
       });
696
+
697
+      // Set enabled state based on dependencies
698
+      // this.enableForDependentConditions();
699
+    },
700
+
701
+    /**
702
+     * Enable / disable fields based on condition tests
703
+     */
704
+    refreshDependentFields: function() {
705
+      // Simplest way is to go through all define_info
706
+      // and run a test on all fields that have one.
707
+      //
708
+      // Each define_info caches its enable test as code.
709
+      //
710
+      // The fields that act as switches for these dependencies
711
+      // are not currently modified, but they will soon be.
712
+      //
713
+      // Once all conditions have been gathered into define_info
714
+      // the conditions can be scraped for define names.
715
+      //
716
+      // Those named fields will be given a .change action to
717
+      // check and update enabled state for the field.
718
+      //
719
+      $.each(define_list, function(e,def_list){
720
+        $.each(def_list, function() {
721
+          var inf = define_info[this];
722
+          if (inf && inf.enabled != 'true') {
723
+            var $elm = $('#'+this), ena = eval(inf.enabled);
724
+            // Make any switch toggle also
725
+            $('#'+this+'-switch').attr('disabled', !ena);
726
+            var alreadyEnabled = inf.type == 'switch' || self.defineIsEnabled(this);
727
+            $elm.attr('disabled', !(ena && alreadyEnabled));
728
+            ena ? $elm.removeClass('blocked') : $elm.addClass('blocked');
729
+            // Dim label for unavailable element
730
+            var $lbl = $elm.prev('label');
731
+            if ($lbl.length)
732
+              ena ? $lbl.removeClass('blocked') : $lbl.addClass('blocked');
733
+          }
734
+        });
735
+      });
606
     },
736
     },
607
 
737
 
608
     /**
738
     /**
609
-     * Get the defineInfo for a field on the form
610
-     * Make it responsive, add a tooltip
739
+     * Make the field responsive, add optional tooltip, enabler box
611
      */
740
      */
612
-    initField: function(name, adv) {
741
+    initField: function(name) {
613
       this.log("initField:"+name,4);
742
       this.log("initField:"+name,4);
614
-      var $elm = $('#'+name), elm = $elm[0], inf = elm.defineInfo;
615
-      if (inf == null)
616
-        inf = elm.defineInfo = this.getDefineInfo(name, adv);
743
+      var $elm = $('#'+name), inf = define_info[name];
744
+      $elm[0].defineInfo = inf;
617
 
745
 
618
       // Create a tooltip on the label if there is one
746
       // Create a tooltip on the label if there is one
619
       if (inf.tooltip) {
747
       if (inf.tooltip) {
672
             .change(self.handleSwitch)
800
             .change(self.handleSwitch)
673
         );
801
         );
674
       }
802
       }
675
-
676
-      // Set the field's initial value from the define
677
-      this.setFieldFromDefine(name);
678
     },
803
     },
679
 
804
 
680
     /**
805
     /**
681
      * Handle any value field being changed
806
      * Handle any value field being changed
682
      * this = the field
807
      * this = the field
683
      */
808
      */
684
-    handleChange: function() { self.updateDefineFromField(this.id); },
809
+    handleChange: function() {
810
+      self.updateDefineFromField(this.id);
811
+      self.refreshDependentFields();
812
+    },
685
 
813
 
686
     /**
814
     /**
687
      * Handle a switch checkbox being changed
815
      * Handle a switch checkbox being changed
690
     handleSwitch: function() {
818
     handleSwitch: function() {
691
       var $elm = $(this),
819
       var $elm = $(this),
692
           name = $elm[0].id.replace(/-.+/,''),
820
           name = $elm[0].id.replace(/-.+/,''),
693
-          inf = $('#'+name)[0].defineInfo,
821
+          inf = define_info[name],
694
           on = $elm.prop('checked') || false;
822
           on = $elm.prop('checked') || false;
695
 
823
 
696
       self.setDefineEnabled(name, on);
824
       self.setDefineEnabled(name, on);
711
      */
839
      */
712
     defineValue: function(name) {
840
     defineValue: function(name) {
713
       this.log('defineValue:'+name,4);
841
       this.log('defineValue:'+name,4);
714
-      var inf = $('#'+name)[0].defineInfo;
842
+      var inf = define_info[name];
715
       if (inf == null) return 'n/a';
843
       if (inf == null) return 'n/a';
716
-      var result = inf.regex.exec($(inf.field).text());
844
+      // var result = inf.regex.exec($(inf.field).text());
845
+      var result = inf.regex.exec(inf.line);
717
 
846
 
718
       this.log(result,2);
847
       this.log(result,2);
719
 
848
 
725
      */
854
      */
726
     defineIsEnabled: function(name) {
855
     defineIsEnabled: function(name) {
727
       this.log('defineIsEnabled:'+name,4);
856
       this.log('defineIsEnabled:'+name,4);
728
-      var inf = $('#'+name)[0].defineInfo;
857
+      var inf = define_info[name];
729
       if (inf == null) return false;
858
       if (inf == null) return false;
730
-      var result = inf.regex.exec($(inf.field).text());
859
+      // var result = inf.regex.exec($(inf.field).text());
860
+      var result = inf.regex.exec(inf.line);
731
 
861
 
732
       this.log(result,2);
862
       this.log(result,2);
733
 
863
 
734
-      var on = result !== null ? result[1].trim() != '//' : true;
864
+      var on = result[1] != null ? result[1].trim() != '//' : true;
735
       this.log(name + ' = ' + on, 2);
865
       this.log(name + ' = ' + on, 2);
736
 
866
 
737
       return on;
867
       return on;
742
      */
872
      */
743
     setDefineEnabled: function(name, val) {
873
     setDefineEnabled: function(name, val) {
744
       this.log('setDefineEnabled:'+name,4);
874
       this.log('setDefineEnabled:'+name,4);
745
-      var inf = $('#'+name)[0].defineInfo;
875
+      var inf = define_info[name];
746
       if (inf) {
876
       if (inf) {
747
         var slash = val ? '' : '//';
877
         var slash = val ? '' : '//';
748
         var newline = inf.line
878
         var newline = inf.line
761
       // Drop the suffix on sub-fields
891
       // Drop the suffix on sub-fields
762
       name = name.replace(/-\d+$/, '');
892
       name = name.replace(/-\d+$/, '');
763
 
893
 
764
-      var $elm = $('#'+name), inf = $elm[0].defineInfo;
894
+      var $elm = $('#'+name), inf = define_info[name];
765
       if (inf == null) return;
895
       if (inf == null) return;
766
 
896
 
767
       var isCheck = $elm.attr('type') == 'checkbox',
897
       var isCheck = $elm.attr('type') == 'checkbox',
797
      */
927
      */
798
     setDefineLine: function(name, newline) {
928
     setDefineLine: function(name, newline) {
799
       this.log('setDefineLine:'+name+'\n'+newline,4);
929
       this.log('setDefineLine:'+name+'\n'+newline,4);
800
-      var inf = $('#'+name)[0].defineInfo;
930
+      var inf = define_info[name];
801
       var $c = $(inf.field), txt = $c.text();
931
       var $c = $(inf.field), txt = $c.text();
802
 
932
 
803
       var hilite_token = '[HIGHLIGHTER-TOKEN]';
933
       var hilite_token = '[HIGHLIGHTER-TOKEN]';
820
      */
950
      */
821
     scrollToDefine: function(name, always) {
951
     scrollToDefine: function(name, always) {
822
       this.log('scrollToDefine:'+name,4);
952
       this.log('scrollToDefine:'+name,4);
823
-      var inf = $('#'+name)[0].defineInfo, $c = $(inf.field);
953
+      var inf = define_info[name], $c = $(inf.field);
824
 
954
 
825
       // Scroll to the altered text if it isn't visible
955
       // Scroll to the altered text if it isn't visible
826
       var halfHeight = $c.height()/2, scrollHeight = $c.prop('scrollHeight'),
956
       var halfHeight = $c.height()/2, scrollHeight = $c.prop('scrollHeight'),
836
     /**
966
     /**
837
      * Set a form field to the current #define value in the config text
967
      * Set a form field to the current #define value in the config text
838
      */
968
      */
839
-    setFieldFromDefine: function(name) {
840
-      var $elm = $('#'+name), inf = $elm[0].defineInfo,
969
+    initFieldValue: function(name) {
970
+      var $elm = $('#'+name), inf = define_info[name],
841
           val = this.defineValue(name);
971
           val = this.defineValue(name);
842
 
972
 
843
-      this.log('setFieldFromDefine:' + name + ' to ' + val, 2);
973
+      this.log('initFieldValue:' + name + ' to ' + val, 2);
844
 
974
 
845
       // If the item has a checkbox then set enabled state too
975
       // If the item has a checkbox then set enabled state too
846
-      var $cb = $('#'+name+'-switch'), on = true;
976
+      var $cb = $('#'+name+'-switch'), avail = eval(inf.enabled), on = true;
847
       if ($cb.length) {
977
       if ($cb.length) {
848
         on = self.defineIsEnabled(name);
978
         on = self.defineIsEnabled(name);
849
         $cb.prop('checked', on);
979
         $cb.prop('checked', on);
854
           var $e = i > 0 ? $('#'+name+'-'+i) : $elm;
984
           var $e = i > 0 ? $('#'+name+'-'+i) : $elm;
855
           $e.val(v.trim());
985
           $e.val(v.trim());
856
           $e.attr('disabled', !on);
986
           $e.attr('disabled', !on);
987
+          avail ? $e.removeClass('blocked') : $e.addClass('blocked');
857
         });
988
         });
858
       }
989
       }
859
       else {
990
       else {
860
         if (inf.type == 'toggle') val = val == inf.options[1];
991
         if (inf.type == 'toggle') val = val == inf.options[1];
861
         $elm.attr('type') == 'checkbox' ? $elm.prop('checked', val) : $elm.val(''+val);
992
         $elm.attr('type') == 'checkbox' ? $elm.prop('checked', val) : $elm.val(''+val);
862
         $elm.attr('disabled', !on); // enable/disable the form field (could also dim it)
993
         $elm.attr('disabled', !on); // enable/disable the form field (could also dim it)
994
+        avail ? $elm.removeClass('blocked') : $elm.addClass('blocked');
863
       }
995
       }
996
+
997
+      // set label color
998
+      var $lbl = $elm.prev('label');
999
+      avail ? $lbl.removeClass('blocked') : $lbl.addClass('blocked');
864
     },
1000
     },
865
 
1001
 
866
     /**
1002
     /**
874
     },
1010
     },
875
 
1011
 
876
     /**
1012
     /**
877
-     * Update #define information for one of the config files
878
-     */
879
-    refreshDefineInfo: function(adv) {
880
-      if (adv === undefined) adv = false;
881
-      $('[name]').each(function() {
882
-        var inf = this.defineInfo;
883
-        if (inf && adv == inf.adv) this.defineInfo = self.getDefineInfo(this.id, adv);
884
-      });
885
-    },
886
-
887
-    /**
888
      * Get information about a #define from configuration file text:
1013
      * Get information about a #define from configuration file text:
889
      *
1014
      *
890
      *   - Pre-examine the #define for its prefix, value position, suffix, etc.
1015
      *   - Pre-examine the #define for its prefix, value position, suffix, etc.
909
           val_i:  1,
1034
           val_i:  1,
910
           type:   'switch',
1035
           type:   'switch',
911
           line:   result[0], // whole line
1036
           line:   result[0], // whole line
912
-          pre:    result[1] === undefined ? '' : result[1].replace('//',''),
1037
+          pre:    result[1] == null ? '' : result[1].replace('//',''),
913
           define: result[2],
1038
           define: result[2],
914
-          post:   result[3] === undefined ? '' : result[3]
1039
+          post:   result[3] == null ? '' : result[3]
915
         });
1040
         });
916
         info.regex = new RegExp('([ \\t]*//)?([ \\t]*' + info.define.regEsc() + info.post.regEsc() + ')', 'm');
1041
         info.regex = new RegExp('([ \\t]*//)?([ \\t]*' + info.define.regEsc() + info.post.regEsc() + ')', 'm');
917
         info.repl =  new RegExp('([ \\t]*)(\/\/)?([ \\t]*' + info.define.regEsc() + info.post.regEsc() + ')', 'm');
1042
         info.repl =  new RegExp('([ \\t]*)(\/\/)?([ \\t]*' + info.define.regEsc() + info.post.regEsc() + ')', 'm');
924
           $.extend(info, {
1049
           $.extend(info, {
925
             type:   'list',
1050
             type:   'list',
926
             line:   result[0],
1051
             line:   result[0],
927
-            pre:    result[1] === undefined ? '' : result[1].replace('//',''),
1052
+            pre:    result[1] == null ? '' : result[1].replace('//',''),
928
             define: result[2],
1053
             define: result[2],
929
             size:   result[3].split(',').length,
1054
             size:   result[3].split(',').length,
930
-            post:   result[4] === undefined ? '' : result[4]
1055
+            post:   result[4] == null ? '' : result[4]
931
           });
1056
           });
932
           info.regex = new RegExp('([ \\t]*//)?[ \\t]*' + info.define.regEsc() + '\{([^\}]*)\}' + info.post.regEsc(), 'm');
1057
           info.regex = new RegExp('([ \\t]*//)?[ \\t]*' + info.define.regEsc() + '\{([^\}]*)\}' + info.post.regEsc(), 'm');
933
           info.repl  = new RegExp('(([ \\t]*//)?[ \\t]*' + info.define.regEsc() + '\{)[^\}]*(\}' + info.post.regEsc() + ')', 'm');
1058
           info.repl  = new RegExp('(([ \\t]*//)?[ \\t]*' + info.define.regEsc() + '\{)[^\}]*(\}' + info.post.regEsc() + ')', 'm');
940
             $.extend(info, {
1065
             $.extend(info, {
941
               type:   'quoted',
1066
               type:   'quoted',
942
               line:   result[0],
1067
               line:   result[0],
943
-              pre:    result[1] === undefined ? '' : result[1].replace('//',''),
1068
+              pre:    result[1] == null ? '' : result[1].replace('//',''),
944
               define: result[2],
1069
               define: result[2],
945
-              post:   result[4] === undefined ? '' : result[4]
1070
+              post:   result[4] == null ? '' : result[4]
946
             });
1071
             });
947
             info.regex = new RegExp('([ \\t]*//)?[ \\t]*' + info.define.regEsc() + '"([^"]*)"' + info.post.regEsc(), 'm');
1072
             info.regex = new RegExp('([ \\t]*//)?[ \\t]*' + info.define.regEsc() + '"([^"]*)"' + info.post.regEsc(), 'm');
948
             info.repl  = new RegExp('(([ \\t]*//)?[ \\t]*' + info.define.regEsc() + '")[^"]*("' + info.post.regEsc() + ')', 'm');
1073
             info.repl  = new RegExp('(([ \\t]*//)?[ \\t]*' + info.define.regEsc() + '")[^"]*("' + info.post.regEsc() + ')', 'm');
955
               $.extend(info, {
1080
               $.extend(info, {
956
                 type:   'plain',
1081
                 type:   'plain',
957
                 line:   result[0],
1082
                 line:   result[0],
958
-                pre:    result[1] === undefined ? '' : result[1].replace('//',''),
1083
+                pre:    result[1] == null ? '' : result[1].replace('//',''),
959
                 define: result[2],
1084
                 define: result[2],
960
-                post:   result[4] === undefined ? '' : result[4]
1085
+                post:   result[4] == null ? '' : result[4]
961
               });
1086
               });
962
               if (result[3].match(/false|true/)) {
1087
               if (result[3].match(/false|true/)) {
963
                 info.type = 'toggle';
1088
                 info.type = 'toggle';
1005
           }
1130
           }
1006
         }
1131
         }
1007
 
1132
 
1008
-
1009
         // Add .tooltip and .lineNum properties to the info
1133
         // Add .tooltip and .lineNum properties to the info
1010
         findDef = new RegExp('^'+name); // Strip the name from the tooltip
1134
         findDef = new RegExp('^'+name); // Strip the name from the tooltip
1135
+        var lineNum = this.getLineNumberOfText(info.line, txt);
1136
+
1137
+        // See if this define is enabled conditionally
1138
+        var enable_cond = '';
1139
+        var adv_index = adv ? 1 : 0;
1140
+        $.each(dependentGroups, function(cond,dat){
1141
+          $.each(dat, function(i,o){
1142
+            if (o.adv == adv_index && lineNum > o.start && lineNum < o.end) {
1143
+              // self.log(name + " is in range " + o.start + "-" + o.end, 2);
1144
+              // if this setting is in a range, conditions are added
1145
+              if (enable_cond != '') enable_cond += ' && ';
1146
+              enable_cond += '(' + cond + ')';
1147
+            }
1148
+          });
1149
+        });
1150
+
1011
         $.extend(info, {
1151
         $.extend(info, {
1012
           tooltip: '<strong>'+name+'</strong> '+tooltip.trim().replace(findDef,'').toHTML(),
1152
           tooltip: '<strong>'+name+'</strong> '+tooltip.trim().replace(findDef,'').toHTML(),
1013
-          lineNum: this.getLineNumberOfText(info.line, txt),
1014
-          switchable: (info.type != 'switch' && info.line.match(/^[ \t]*\/\//)) || false // Disabled? Mark as "switchable"
1153
+          lineNum: lineNum,
1154
+          switchable: (info.type != 'switch' && info.line.match(/^[ \t]*\/\//)) || false, // Disabled? Mark as "switchable"
1155
+          enabled: enable_cond ? enable_cond : 'true'
1015
         });
1156
         });
1157
+
1016
       }
1158
       }
1017
       else
1159
       else
1018
         info = null;
1160
         info = null;
1019
 
1161
 
1020
-      this.log(info,2);
1162
+      this.log(info, 2);
1021
 
1163
 
1022
       return info;
1164
       return info;
1023
     },
1165
     },

Loading…
Cancel
Save