(sensor, key)
| 687 | } |
| 688 | |
| 689 | _appendMenuItem(sensor, key) { |
| 690 | let split = sensor.type.split('-'); |
| 691 | let type = split[0]; |
| 692 | let icon = (split.length == 2)?'icon-' + split[1]:'icon'; |
| 693 | let gicon = Gio.icon_new_for_string(this._sensorIconPath(type, icon)); |
| 694 | |
| 695 | let item = new MenuItem.MenuItem(gicon, key, sensor.label, sensor.value, this._hotLabels[key]); |
| 696 | item.connect('toggle', (self) => { |
| 697 | let hotSensors = this._settings.get_strv('hot-sensors'); |
| 698 | |
| 699 | if (self.checked) { |
| 700 | // add selected sensor to panel |
| 701 | hotSensors.push(self.key); |
| 702 | this._createHotItem(self.key, self.value, self.gicon); |
| 703 | } else { |
| 704 | // remove selected sensor from panel |
| 705 | hotSensors.splice(hotSensors.indexOf(self.key), 1); |
| 706 | this._removeHotItem(self.key); |
| 707 | } |
| 708 | |
| 709 | if (hotSensors.length <= 0) { |
| 710 | // add generic icon to panel when no sensors are selected |
| 711 | hotSensors.push('_default_icon_'); |
| 712 | this._createHotItem('_default_icon_'); |
| 713 | } else { |
| 714 | let defIconPos = hotSensors.indexOf('_default_icon_'); |
| 715 | if (defIconPos >= 0) { |
| 716 | // remove generic icon from panel when sensors are selected |
| 717 | hotSensors.splice(defIconPos, 1); |
| 718 | this._removeHotItem('_default_icon_'); |
| 719 | } |
| 720 | } |
| 721 | |
| 722 | // this code is called asynchronously - make sure to save it for next round |
| 723 | this._saveHotSensors(hotSensors); |
| 724 | }); |
| 725 | |
| 726 | this._sensorMenuItems[key] = item; |
| 727 | let i = Object.keys(this._sensorMenuItems[key]).length; |
| 728 | |
| 729 | // alphabetize the sensors for these categories |
| 730 | if (this._settings.get_boolean('alphabetize')) { |
| 731 | let menuItems = this._groups[type].menu._getMenuItems(); |
| 732 | for (i = 0; i < menuItems.length; i++) |
| 733 | // use natural sort order for system load, etc |
| 734 | if (menuItems[i].label.localeCompare(item.label, undefined, { numeric: true, sensitivity: 'base' }) > 0) |
| 735 | break; |
| 736 | } |
| 737 | |
| 738 | this._groups[type].menu.addMenuItem(item, i); |
| 739 | } |
| 740 | |
| 741 | _defaultLabel() { |
| 742 | return new St.Label({ |
no test coverage detected