Преглед изворни кода

More fields, options in config, fix tooltips

Scott Lahteine пре 10 година
родитељ
комит
ec53c6309a

+ 4
- 2
Marlin/configurator/config/Configuration.h Прегледај датотеку

48
 // SERIAL_PORT selects which serial port should be used for communication with the host.
48
 // SERIAL_PORT selects which serial port should be used for communication with the host.
49
 // This allows the connection of wireless adapters (for instance) to non-default port pins.
49
 // This allows the connection of wireless adapters (for instance) to non-default port pins.
50
 // Serial port 0 is still used by the Arduino bootloader regardless of this setting.
50
 // Serial port 0 is still used by the Arduino bootloader regardless of this setting.
51
+// :[0,1,2,3,4,5,6,7]
51
 #define SERIAL_PORT 0
52
 #define SERIAL_PORT 0
52
 
53
 
53
 // This determines the communication speed of the printer
54
 // This determines the communication speed of the printer
71
 // #define MACHINE_UUID "00000000-0000-0000-0000-000000000000"
72
 // #define MACHINE_UUID "00000000-0000-0000-0000-000000000000"
72
 
73
 
73
 // This defines the number of extruders
74
 // This defines the number of extruders
75
+// :[1,2,3,4]
74
 #define EXTRUDERS 1
76
 #define EXTRUDERS 1
75
 
77
 
76
 //// The following define selects which power supply you have. Please choose the one that matches your setup
78
 //// The following define selects which power supply you have. Please choose the one that matches your setup
77
 // 1 = ATX
79
 // 1 = ATX
78
 // 2 = X-Box 360 203Watts (the blue wire connected to PS_ON and the red wire to VCC)
80
 // 2 = X-Box 360 203Watts (the blue wire connected to PS_ON and the red wire to VCC)
79
-
81
+// :{1:'ATX',2:'X-Box 360'}
80
 #define POWER_SUPPLY 1
82
 #define POWER_SUPPLY 1
81
 
83
 
82
 // Define this to have the electronics keep the power supply off on startup. If you don't know what this is leave it.
84
 // Define this to have the electronics keep the power supply off on startup. If you don't know what this is leave it.
119
 // 1010 is Pt1000 with 1k pullup (non standard)
121
 // 1010 is Pt1000 with 1k pullup (non standard)
120
 // 147 is Pt100 with 4k7 pullup
122
 // 147 is Pt100 with 4k7 pullup
121
 // 110 is Pt100 with 1k pullup (non standard)
123
 // 110 is Pt100 with 1k pullup (non standard)
122
-
124
+// :{ 0: "Not used", 4: "10k !! do not use for a hotend. Bad resolution at high temp. !!", 1: "100k / 4.7k - EPCOS", 51: "100k / 1k - EPCOS", 6: "100k / 4.7k EPCOS - Not as accurate as Table 1", 5: "100K / 4.7k - ATC Semitec 104GT-2 (Used in ParCan & J-Head)", 7: "100k / 4.7k Honeywell 135-104LAG-J01", 71: "100k / 4.7k Honeywell 135-104LAF-J01", 8: "100k / 4.7k 0603 SMD Vishay NTCS0603E3104FXT", 9: "100k / 4.7k GE Sensing AL03006-58.2K-97-G1", 10: "100k / 4.7k RS 198-961", 11: "100k / 4.7k beta 3950 1%", 12: "100k / 4.7k 0603 SMD Vishay NTCS0603E3104FXT (calibrated for Makibox hot bed)", 13: "100k Hisens 3950  1% up to 300°C for hotend 'Simple ONE ' & hotend 'All In ONE'", 60: "100k Maker's Tool Works Kapton Bed Thermistor beta=3950", 55: "100k / 1k - ATC Semitec 104GT-2 (Used in ParCan & J-Head)", 2: "200k / 4.7k - ATC Semitec 204GT-2", 52: "200k / 1k - ATC Semitec 204GT-2", '-2': "Thermocouple + MAX6675 (only for sensor 0)", '-1': "Thermocouple + AD595", 3: "Mendel-parts / 4.7k", 1047: "Pt1000 / 4.7k", 1010: "Pt1000 / 1k (non standard)", 20: "PT100 (Ultimainboard V2.x)", 147: "Pt100 / 4.7k", 110: "Pt100 / 1k (non-standard)" }
123
 #define TEMP_SENSOR_0 -1
125
 #define TEMP_SENSOR_0 -1
124
 #define TEMP_SENSOR_1 -1
126
 #define TEMP_SENSOR_1 -1
125
 #define TEMP_SENSOR_2 0
127
 #define TEMP_SENSOR_2 0

+ 15
- 3
Marlin/configurator/css/configurator.css Прегледај датотеку

41
 
41
 
42
 #message { text-align: center; }
42
 #message { text-align: center; }
43
 #message { width: 80%; margin: 0 auto 0.25em; color: #FF0; }
43
 #message { width: 80%; margin: 0 auto 0.25em; color: #FF0; }
44
-#message p { padding: 2px 0; }
45
-#message p.error, #message p.message { color: #F00; background: #FF4; font-weight: bold; border-radius: 0.8em; }
44
+#message p { padding: 2px 0; font-weight: bold; border-radius: 0.8em; }
46
 #message p.message { color: #080; background: #CFC; }
45
 #message p.message { color: #080; background: #CFC; }
46
+#message p.error { color: #F00; background: #FF4; }
47
+#message p.warning { color: #FF0; background: #BA4; }
47
 #message p.message span {
48
 #message p.message span {
48
 	color: #A00;
49
 	color: #A00;
49
 	background: rgba(255, 255, 255, 1);
50
 	background: rgba(255, 255, 255, 1);
92
 
93
 
93
 input:disabled { color: #BBB; }
94
 input:disabled { color: #BBB; }
94
 
95
 
96
+#more input[type="text"] { width: 20em; }
97
+
98
+#more label {
99
+	width: 240px; /* label area */
100
+	height: 1em;
101
+	padding: 10px 360px 10px 1em;
102
+	margin-right: -350px;
103
+	text-align: right;
104
+	}
105
+
106
+
95
 ul.tabs { padding: 0; list-style: none; }
107
 ul.tabs { padding: 0; list-style: none; }
96
 ul.tabs li { display: inline; }
108
 ul.tabs li { display: inline; }
97
 ul.tabs li a,
109
 ul.tabs li a,
136
 	}
148
 	}
137
 
149
 
138
 #serial_stepper { padding-top: 0.75em; display: block; float: left; }
150
 #serial_stepper { padding-top: 0.75em; display: block; float: left; }
139
-#SERIAL_PORT { display: none; }
151
+/*#SERIAL_PORT { display: none; }*/
140
 
152
 
141
 /* Tooltips */
153
 /* Tooltips */
142
 
154
 

+ 144
- 80
Marlin/configurator/js/configurator.js Прегледај датотеку

165
       this.makeTabsForFieldsets();
165
       this.makeTabsForFieldsets();
166
 
166
 
167
       // No selection on errors
167
       // No selection on errors
168
-      $msgbox.noSelect();
168
+      // $msgbox.noSelect();
169
 
169
 
170
       // Make a droppable file uploader, if possible
170
       // Make a droppable file uploader, if possible
171
       var $uploader = $('#file-upload');
171
       var $uploader = $('#file-upload');
231
           },
231
           },
232
           complete: function() {
232
           complete: function() {
233
             ajax_count++;
233
             ajax_count++;
234
-            if (ajax_count >= 3) {
235
-              $.each(config_files, function(){ if (loaded_items[this]) loaded_items[this](); });
234
+            if (ajax_count >= config_files.length) {
235
+              // If not all files loaded set an error
236
               if (success_count < ajax_count)
236
               if (success_count < ajax_count)
237
                 self.setMessage('Unable to load configurations. Try the upload field.', 'error');
237
                 self.setMessage('Unable to load configurations. Try the upload field.', 'error');
238
+
239
+              // Is the request near the rate limit? Set an error.
238
               var r;
240
               var r;
239
               if (r = rateLimit) {
241
               if (r = rateLimit) {
240
                 if (r.quota < 20) {
242
                 if (r.quota < 20) {
241
                   self.setMessage(
243
                   self.setMessage(
242
                     'Approaching request limit (' +
244
                     'Approaching request limit (' +
243
                     r.quota + ' remaining.' +
245
                     r.quota + ' remaining.' +
244
-                    ' Reset in ' + Math.floor(r.timeLeft/60) + ':' + (r.timeLeft%60+'').zeroPad(2) + ')'
246
+                    ' Reset in ' + Math.floor(r.timeLeft/60) + ':' + (r.timeLeft%60+'').zeroPad(2) + ')',
247
+                    'warning'
245
                   );
248
                   );
246
                 }
249
                 }
247
               }
250
               }
251
+              // Post-process all the loaded files
252
+              $.each(config_files, function(){ if (loaded_items[this]) loaded_items[this](); });
248
             }
253
             }
249
           }
254
           }
250
         });
255
         });
251
       });
256
       });
252
     },
257
     },
253
 
258
 
254
-    createDownloadLink: function(adv) {
259
+    /**
260
+     * Make a download link visible and active
261
+     */
262
+    activateDownloadLink: function(adv) {
255
       var $c = adv ? $config_adv : $config, txt = $c.text();
263
       var $c = adv ? $config_adv : $config, txt = $c.text();
256
       var filename = (adv ? config_adv_file : config_file);
264
       var filename = (adv ? config_adv_file : config_file);
257
       $c.prevAll('.download:first')
265
       $c.prevAll('.download:first')
266
+        .unbind('mouseover click')
258
         .mouseover(function() {
267
         .mouseover(function() {
259
           var d = new Date(), fn = d.fileStamp(filename);
268
           var d = new Date(), fn = d.fileStamp(filename);
260
           $(this).attr({ download:fn, href:'download:'+fn, title:'download:'+fn });
269
           $(this).attr({ download:fn, href:'download:'+fn, title:'download:'+fn });
300
      * Get all the unique define names
309
      * Get all the unique define names
301
      */
310
      */
302
     getDefinesFromText: function(txt) {
311
     getDefinesFromText: function(txt) {
312
+      var leave_out_defines = ['CONFIGURATION_H', 'CONFIGURATION_ADV_H', 'STRING_VERSION', 'STRING_URL', 'STRING_VERSION_CONFIG_H', 'STRING_CONFIG_H_AUTHOR', 'STRING_SPLASH_LINE1', 'STRING_SPLASH_LINE2'];
303
       // Get all the unique #define's and save them in an array
313
       // Get all the unique #define's and save them in an array
304
       var r, define_obj = {}, findDef = new RegExp('#define[ \\t]+(\\w+)', 'gm');
314
       var r, define_obj = {}, findDef = new RegExp('#define[ \\t]+(\\w+)', 'gm');
305
-      var cnt = 0;
306
       while((r = findDef.exec(txt)) !== null) {
315
       while((r = findDef.exec(txt)) !== null) {
307
-        if (cnt++ && !(r[1] in define_obj)) define_obj[r[1]] = null;
316
+        if ($.inArray(r[1], leave_out_defines) < 0 && !(r[1] in define_obj))
317
+          define_obj[r[1]] = null;
308
       }
318
       }
309
       this.log(Object.keys(define_obj), 2);
319
       this.log(Object.keys(define_obj), 2);
310
       return Object.keys(define_obj);
320
       return Object.keys(define_obj);
311
     },
321
     },
312
 
322
 
313
     /**
323
     /**
314
-     * Create placeholder fields for defines, as needed
324
+     * Create fields for any defines that have none
315
      */
325
      */
316
     createFieldsForDefines: function(adv) {
326
     createFieldsForDefines: function(adv) {
317
       var e = adv ? 1 : 0, n = 0;
327
       var e = adv ? 1 : 0, n = 0;
318
       var fail_list = [];
328
       var fail_list = [];
319
       $.each(define_list[e], function(i,name) {
329
       $.each(define_list[e], function(i,name) {
320
         if (!$('#'+name).length) {
330
         if (!$('#'+name).length) {
321
-          var $ff = $('#more');
322
-          var inf = self.getDefineInfo(name, adv);
331
+          var $ff = $('#more'),
332
+              inf = self.getDefineInfo(name, adv);
323
           if (inf) {
333
           if (inf) {
324
             var $newlabel = $('<label>',{for:name}).text(name.toLabel());
334
             var $newlabel = $('<label>',{for:name}).text(name.toLabel());
325
             // if (!(++n % 3))
335
             // if (!(++n % 3))
326
               $newlabel.addClass('newline');
336
               $newlabel.addClass('newline');
327
-            var $newfield = inf.type == 'switch' ? $('<input>',{type:'checkbox'}) : $('<input>',{type:'text',size:10,maxlength:40});
337
+
338
+            var $newfield;
339
+            if (inf.options !== undefined) {
340
+              $newfield = $('<select>'); //.addOptions(inf.options);
341
+            }
342
+            else {
343
+              $newfield = inf.type == 'switch' ? $('<input>',{type:'checkbox'}) : $('<input>',{type:'text',size:10,maxlength:40});
344
+            }
328
             $newfield.attr({id:name,name:name}).prop({defineInfo:inf});
345
             $newfield.attr({id:name,name:name}).prop({defineInfo:inf});
346
+            // Add the new field to the form
329
             $ff.append($newlabel, $newfield);
347
             $ff.append($newlabel, $newfield);
330
           }
348
           }
331
           else
349
           else
358
      */
376
      */
359
     fileLoaded: function(filename, txt) {
377
     fileLoaded: function(filename, txt) {
360
       this.log("fileLoaded:"+filename,4);
378
       this.log("fileLoaded:"+filename,4);
361
-      var err;
379
+      var err, init_index;
362
       switch(filename) {
380
       switch(filename) {
363
         case boards_file:
381
         case boards_file:
364
           this.initBoardsFromText(txt);
382
           this.initBoardsFromText(txt);
369
           if (has_boards) {
387
           if (has_boards) {
370
             $config.text(txt);
388
             $config.text(txt);
371
             total_config_lines = txt.lineCount();
389
             total_config_lines = txt.lineCount();
372
-            this.initThermistorsFromText(txt);
373
-            this.purgeDefineInfo(false);
374
-            define_list[0] = this.getDefinesFromText(txt);
375
-            this.log(define_list[0], 2);
376
-            this.createFieldsForDefines(0);
377
-            this.refreshConfigForm();
378
-            this.createDownloadLink(false);
390
+            // this.initThermistorsFromText(txt);
391
+            init_index = 0;
379
             has_config = true;
392
             has_config = true;
380
           }
393
           }
381
           else {
394
           else {
386
           if (has_config) {
399
           if (has_config) {
387
             $config_adv.text(txt);
400
             $config_adv.text(txt);
388
             total_config_adv_lines = txt.lineCount();
401
             total_config_adv_lines = txt.lineCount();
389
-            this.purgeDefineInfo(true);
390
-            define_list[1] = this.getDefinesFromText(txt);
391
-            this.log(define_list[1], 2);
392
-            this.refreshConfigForm();
393
-            this.createDownloadLink(true);
402
+            init_index = 1;
394
             has_config_adv = true;
403
             has_config_adv = true;
395
           }
404
           }
396
           else {
405
           else {
398
           }
407
           }
399
           break;
408
           break;
400
       }
409
       }
410
+      // When a config file loads defines might change
411
+      if (init_index != null) {
412
+        var adv = init_index == 1;
413
+        define_list[init_index] = this.getDefinesFromText(txt);
414
+        this.log(define_list[init_index], 2);
415
+        this.purgeDefineInfo(adv);
416
+        this.createFieldsForDefines(init_index);
417
+        this.refreshConfigForm(init_index);
418
+        this.activateDownloadLink(adv);
419
+      }
401
       this.setMessage(err
420
       this.setMessage(err
402
         ? 'Please upload a "' + boards_file + '" file first!'
421
         ? 'Please upload a "' + boards_file + '" file first!'
403
         : '"' + filename + '" loaded successfully.', err ? 'error' : 'message'
422
         : '"' + filename + '" loaded successfully.', err ? 'error' : 'message'
405
     },
424
     },
406
 
425
 
407
     /**
426
     /**
408
-     * Add enhancements to the form
427
+     * Add initial enhancements to the existing form
409
      */
428
      */
410
     initConfigForm: function() {
429
     initConfigForm: function() {
411
       // Modify form fields and make the form responsive.
430
       // Modify form fields and make the form responsive.
436
       });
455
       });
437
 
456
 
438
       // Add options to the popup menus
457
       // Add options to the popup menus
439
-      $('#SERIAL_PORT').addOptions([0,1,2,3,4,5,6,7]);
440
-      $('#BAUDRATE').addOptions([2400,9600,19200,38400,57600,115200,250000]);
441
-      $('#EXTRUDERS').addOptions([1,2,3,4]);
442
-      $('#POWER_SUPPLY').addOptions({'1':'ATX','2':'Xbox 360'});
458
+      // $('#SERIAL_PORT').addOptions([0,1,2,3,4,5,6,7]);
459
+      // $('#BAUDRATE').addOptions([2400,9600,19200,38400,57600,115200,250000]);
460
+      // $('#EXTRUDERS').addOptions([1,2,3,4]);
461
+      // $('#POWER_SUPPLY').addOptions({'1':'ATX','2':'Xbox 360'});
443
 
462
 
444
       // Replace the Serial popup menu with a stepper control
463
       // Replace the Serial popup menu with a stepper control
464
+      /*
445
       $('#serial_stepper').jstepper({
465
       $('#serial_stepper').jstepper({
446
         min: 0,
466
         min: 0,
447
         max: 3,
467
         max: 3,
455
         textStyle: {width:'1.5em',fontSize:'120%',textAlign:'center'},
475
         textStyle: {width:'1.5em',fontSize:'120%',textAlign:'center'},
456
         onChange: function(v) { $('#SERIAL_PORT').val(v).trigger('change'); }
476
         onChange: function(v) { $('#SERIAL_PORT').val(v).trigger('change'); }
457
       });
477
       });
478
+      */
458
     },
479
     },
459
 
480
 
460
     /**
481
     /**
462
      */
483
      */
463
     makeTabsForFieldsets: function() {
484
     makeTabsForFieldsets: function() {
464
       // Make tabs for the fieldsets
485
       // Make tabs for the fieldsets
465
-      var $fset = $form.find('fieldset');
466
-      var $tabs = $('<ul>',{class:'tabs'}), ind = 1;
486
+      var $fset = $form.find('fieldset'),
487
+          $tabs = $('<ul>',{class:'tabs'}),
488
+          ind = 1;
467
       $fset.each(function(){
489
       $fset.each(function(){
468
         var tabID = 'TAB'+ind;
490
         var tabID = 'TAB'+ind;
469
         $(this).addClass(tabID);
491
         $(this).addClass(tabID);
489
     /**
511
     /**
490
      * Update all fields on the form after loading a configuration
512
      * Update all fields on the form after loading a configuration
491
      */
513
      */
492
-    refreshConfigForm: function() {
514
+    refreshConfigForm: function(init_index) {
493
 
515
 
494
       /**
516
       /**
495
        * Any manually-created form elements will remain
517
        * Any manually-created form elements will remain
499
        * Specific exceptions can be managed by applying
521
        * Specific exceptions can be managed by applying
500
        * classes to the associated form fields.
522
        * classes to the associated form fields.
501
        * Sorting and arrangement can come from an included
523
        * Sorting and arrangement can come from an included
502
-       * js file that describes the configuration in JSON.
524
+       * Javascript file that describes the configuration
525
+       * in JSON, or using information added to the config
526
+       * files.
503
        *
527
        *
504
-       * For now I'm trying to derive information
505
-       * about options directly from the config file.
506
        */
528
        */
507
 
529
 
530
+      // Refresh the motherboard menu with new options
508
       $('#MOTHERBOARD').html('').addOptions(boards_list);
531
       $('#MOTHERBOARD').html('').addOptions(boards_list);
509
 
532
 
510
-      $('#TEMP_SENSOR_0, #TEMP_SENSOR_1, #TEMP_SENSOR_2, #TEMP_SENSOR_BED').html('').addOptions(therms_list);
511
-
512
-      $.each(define_list, function() { $.each(this, function() { if ($('#'+this).length) self.initField(this); }); });
533
+      // Init all existing fields, getting define info for any that need it
534
+      // refreshing the options and updating their current values
535
+      $.each(define_list[init_index], function() {
536
+        if ($('#'+this).length)
537
+          self.initField(this,init_index==1);
538
+        else
539
+          self.log(this + " is not on the page yet.", 2);
540
+      });
513
     },
541
     },
514
 
542
 
515
     /**
543
     /**
516
-     * Make a field responsive and initialize its defineInfo
544
+     * Get the defineInfo for a field on the form
545
+     * Make it responsive, add a tooltip
517
      */
546
      */
518
     initField: function(name, adv) {
547
     initField: function(name, adv) {
519
       this.log("initField:"+name,4);
548
       this.log("initField:"+name,4);
520
-      var $elm = $('#'+name), elm = $elm[0];
521
-      if (elm.defineInfo == null) {
522
-        var inf = elm.defineInfo = this.getDefineInfo(name, adv);
523
-        $elm.on($elm.attr('type') == 'text' ? 'input' : 'change', this.handleChange);
524
-
525
-        if (inf.tooltip) {
526
-          var $tipme = $elm.prev('label');
527
-          if ($tipme.length) {
528
-            $tipme.hover(
529
-              function() {
530
-                if ($('#tipson input').prop('checked')) {
531
-                  var pos = $tipme.position();
532
-                  $tooltip.html(inf.tooltip)
533
-                    .append('<span>')
534
-                    .css({bottom:($tooltip.parent().outerHeight()-pos.top)+'px',left:(pos.left+70)+'px'})
535
-                    .show();
536
-                  if (hover_timer) {
537
-                    clearTimeout(hover_timer);
538
-                    hover_timer = null;
539
-                  }
540
-                }
541
-              },
542
-              function() {
543
-                hover_timer = setTimeout(function(){
549
+      var $elm = $('#'+name), elm = $elm[0], inf = elm.defineInfo;
550
+      if (inf == null)
551
+        inf = elm.defineInfo = this.getDefineInfo(name, adv);
552
+
553
+      // Set options on the field if there are any
554
+      if (inf.options !== undefined)
555
+        $elm.html('').addOptions(inf.options);
556
+
557
+      // Create a tooltip if there is one
558
+      if (inf.tooltip) {
559
+        var $tipme = $elm.prev('label');
560
+        if ($tipme.length) {
561
+          $tipme.unbind('mouseenter mouseleave');
562
+          $tipme.hover(
563
+            function() {
564
+              if ($('#tipson input').prop('checked')) {
565
+                var pos = $tipme.position();
566
+                $tooltip.html(inf.tooltip)
567
+                  .append('<span>')
568
+                  .css({bottom:($tooltip.parent().outerHeight()-pos.top)+'px',left:(pos.left+70)+'px'})
569
+                  .show();
570
+                if (hover_timer) {
571
+                  clearTimeout(hover_timer);
544
                   hover_timer = null;
572
                   hover_timer = null;
545
-                  $tooltip.fadeOut(400);
546
-                }, 400);
573
+                }
547
               }
574
               }
548
-            );
549
-          }
575
+            },
576
+            function() {
577
+              hover_timer = setTimeout(function(){
578
+                hover_timer = null;
579
+                $tooltip.fadeOut(400);
580
+              }, 400);
581
+            }
582
+          );
550
         }
583
         }
551
       }
584
       }
585
+
586
+      $elm.unbind('input change');
587
+      $elm.on($elm.attr('type') == 'text' ? 'input' : 'change', this.handleChange);
588
+
589
+      // Set the field's initial value from the define
552
       this.setFieldFromDefine(name);
590
       this.setFieldFromDefine(name);
553
     },
591
     },
554
 
592
 
733
      *   - Store the existing #define line as a fast key to finding it later.
771
      *   - Store the existing #define line as a fast key to finding it later.
734
      *   - Determine the line number of the #define so it can be scrolled to.
772
      *   - Determine the line number of the #define so it can be scrolled to.
735
      *   - Gather nearby comments to be used as tooltips.
773
      *   - Gather nearby comments to be used as tooltips.
774
+     *   - Look for JSON in nearby comments to use as select options.
736
      */
775
      */
737
     getDefineInfo: function(name, adv) {
776
     getDefineInfo: function(name, adv) {
738
       if (adv === undefined) adv = false;
777
       if (adv === undefined) adv = false;
757
         info.repl =  new RegExp('([ \\t]*)(\/\/)?([ \\t]*' + info.define.regEsc() + info.post.regEsc() + ')', 'm');
796
         info.repl =  new RegExp('([ \\t]*)(\/\/)?([ \\t]*' + info.define.regEsc() + info.post.regEsc() + ')', 'm');
758
       }
797
       }
759
       else {
798
       else {
760
-        // a define with quotes
761
-        findDef = new RegExp('^(.*//)?(.*#define[ \\t]+' + name + '[ \\t]+)("[^"]*")([ \\t]*/[*/].*)?$', 'm');
799
+        // a define with curly braces
800
+        findDef = new RegExp('^(.*//)?(.*#define[ \\t]+' + name + '[ \\t]+)(\{[^\}]*\})([ \\t]*/[*/].*)?$', 'm');
762
         result = findDef.exec(txt);
801
         result = findDef.exec(txt);
763
         if (result !== null) {
802
         if (result !== null) {
764
           $.extend(info, {
803
           $.extend(info, {
765
-            type:   'quoted',
804
+            type:   'list',
766
             line:   result[0],
805
             line:   result[0],
767
             pre:    result[1] === undefined ? '' : result[1].replace('//',''),
806
             pre:    result[1] === undefined ? '' : result[1].replace('//',''),
768
             define: result[2],
807
             define: result[2],
769
             post:   result[4] === undefined ? '' : result[4]
808
             post:   result[4] === undefined ? '' : result[4]
770
           });
809
           });
771
-          info.regex = new RegExp('([ \\t]*//)?[ \\t]*' + info.define.regEsc() + '"([^"]*)"' + info.post.regEsc(), 'm');
772
-          info.repl  = new RegExp('(([ \\t]*//)?[ \\t]*' + info.define.regEsc() + '")[^"]*("' + info.post.regEsc() + ')', 'm');
810
+          info.regex = new RegExp('([ \\t]*//)?[ \\t]*' + info.define.regEsc() + '\{([^\}]*)\}' + info.post.regEsc(), 'm');
811
+          info.repl  = new RegExp('(([ \\t]*//)?[ \\t]*' + info.define.regEsc() + '\{)[^\}]*(\}' + info.post.regEsc() + ')', 'm');
773
         }
812
         }
774
         else {
813
         else {
775
-          // a define with no quotes
776
-          findDef = new RegExp('^([ \\t]*//)?([ \\t]*#define[ \\t]+' + name + '[ \\t]+)(\\S*)([ \\t]*/[*/].*)?$', 'm');
814
+          // a define with quotes
815
+          findDef = new RegExp('^(.*//)?(.*#define[ \\t]+' + name + '[ \\t]+)("[^"]*")([ \\t]*/[*/].*)?$', 'm');
777
           result = findDef.exec(txt);
816
           result = findDef.exec(txt);
778
           if (result !== null) {
817
           if (result !== null) {
779
             $.extend(info, {
818
             $.extend(info, {
780
-              type:   'plain',
819
+              type:   'quoted',
781
               line:   result[0],
820
               line:   result[0],
782
               pre:    result[1] === undefined ? '' : result[1].replace('//',''),
821
               pre:    result[1] === undefined ? '' : result[1].replace('//',''),
783
               define: result[2],
822
               define: result[2],
784
               post:   result[4] === undefined ? '' : result[4]
823
               post:   result[4] === undefined ? '' : result[4]
785
             });
824
             });
786
-            info.regex = new RegExp('([ \\t]*//)?[ \\t]*' + info.define.regEsc() + '(\\S*)' + info.post.regEsc(), 'm');
787
-            info.repl  = new RegExp('(([ \\t]*//)?[ \\t]*' + info.define.regEsc() + ')\\S*(' + info.post.regEsc() + ')', 'm');
825
+            info.regex = new RegExp('([ \\t]*//)?[ \\t]*' + info.define.regEsc() + '"([^"]*)"' + info.post.regEsc(), 'm');
826
+            info.repl  = new RegExp('(([ \\t]*//)?[ \\t]*' + info.define.regEsc() + '")[^"]*("' + info.post.regEsc() + ')', 'm');
827
+          }
828
+          else {
829
+            // a define with no quotes
830
+            findDef = new RegExp('^([ \\t]*//)?([ \\t]*#define[ \\t]+' + name + '[ \\t]+)(\\S*)([ \\t]*/[*/].*)?$', 'm');
831
+            result = findDef.exec(txt);
832
+            if (result !== null) {
833
+              $.extend(info, {
834
+                type:   'plain',
835
+                line:   result[0],
836
+                pre:    result[1] === undefined ? '' : result[1].replace('//',''),
837
+                define: result[2],
838
+                post:   result[4] === undefined ? '' : result[4]
839
+              });
840
+              info.regex = new RegExp('([ \\t]*//)?[ \\t]*' + info.define.regEsc() + '(\\S*)' + info.post.regEsc(), 'm');
841
+              info.repl  = new RegExp('(([ \\t]*//)?[ \\t]*' + info.define.regEsc() + ')\\S*(' + info.post.regEsc() + ')', 'm');
842
+            }
788
           }
843
           }
789
         }
844
         }
790
       }
845
       }
807
               tooltip = '';
862
               tooltip = '';
808
               break;
863
               break;
809
             }
864
             }
810
-            tooltip += ' ' + s[1] + '\n';
865
+            // JSON data? Save as select options
866
+            if (s[1].match(/:[\[{]/) != null) {
867
+              // TODO
868
+              // :[1-6] = value limits
869
+              eval('info.options = ' + s[1].substr(1));
870
+            }
871
+            else {
872
+              // Other lines added to the tooltip
873
+              tooltip += ' ' + s[1] + '\n';
874
+            }
811
           }
875
           }
812
         }
876
         }
813
 
877
 
814
-        findDef = new RegExp('^[ \\t]*'+name); // To strip the name from the start
878
+        findDef = new RegExp('^'+name); // To strip the name from the start
815
         $.extend(info, {
879
         $.extend(info, {
816
-          tooltip: '<strong>'+name+'</strong> '+tooltip.replace(findDef,'').trim().toHTML(),
880
+          tooltip: '<strong>'+name+'</strong> '+tooltip.trim().replace(findDef,'').toHTML(),
817
           lineNum: this.getLineNumberOfText(info.line, txt)
881
           lineNum: this.getLineNumberOfText(info.line, txt)
818
         });
882
         });
819
       }
883
       }

Loading…
Откажи
Сачувај