@ -231,8 +231,13 @@ const OpenweatherMenuButton = new Lang.Class({
reactive : false
} ) ;
_itemCurrent . actor . add _actor ( this . _currentWeather ) ;
_itemFuture . actor . add _actor ( this . _futureWeather ) ;
if ( ExtensionUtils . versionCheck ( [ '3.8' ] , Config . PACKAGE _VERSION ) ) {
_itemCurrent . addActor ( this . _currentWeather ) ;
_itemFuture . addActor ( this . _futureWeather ) ;
} else {
_itemCurrent . actor . add _actor ( this . _currentWeather ) ;
_itemFuture . actor . add _actor ( this . _futureWeather ) ;
}
this . menu . addMenuItem ( _itemCurrent ) ;
@ -294,6 +299,13 @@ const OpenweatherMenuButton = new Lang.Class({
this . _checkConnectionState ( ) ;
this . menu . connect ( 'open-state-changed' , Lang . bind ( this , this . recalcLayout ) ) ;
if ( ExtensionUtils . versionCheck ( [ '3.8' ] , Config . PACKAGE _VERSION ) ) {
this . _needsColorUpdate = true ;
let context = St . ThemeContext . get _for _stage ( global . stage ) ;
this . _globalThemeChangedId = context . connect ( 'changed' , Lang . bind ( this , function ( ) {
this . _needsColorUpdate = true ;
} ) ) ;
}
} ,
_onStatusChanged : function ( status ) {
@ -593,6 +605,63 @@ const OpenweatherMenuButton = new Lang.Class({
return this . _settings . set _string ( OPENWEATHER _CITY _KEY , v ) ;
} ,
_onButtonHoverChanged : function ( actor , event ) {
if ( actor . hover ) {
actor . add _style _pseudo _class ( 'hover' ) ;
actor . set _style ( this . _button _background _style ) ;
} else {
actor . remove _style _pseudo _class ( 'hover' ) ;
actor . set _style ( 'background-color:;' ) ;
if ( actor != this . _urlButton )
actor . set _style ( this . _button _border _style ) ;
}
} ,
_updateButtonColors : function ( ) {
if ( ! this . _needsColorUpdate )
return ;
this . _needsColorUpdate = false ;
let color = this . _separatorItem . _separator . actor . get _theme _node ( ) . get _color ( '-gradient-end' ) ;
let alpha = ( Math . round ( color . alpha / 2.55 ) / 100 ) ;
if ( color . red > 0 && color . green > 0 && color . blue > 0 )
this . _button _border _style = 'border:1px solid rgb(' + Math . round ( alpha * color . red ) + ',' + Math . round ( alpha * color . green ) + ',' + Math . round ( alpha * color . blue ) + ');' ;
else
this . _button _border _style = 'border:1px solid rgba(' + color . red + ',' + color . green + ',' + color . blue + ',' + alpha + ');' ;
this . _locationButton . set _style ( this . _button _border _style ) ;
this . _reloadButton . set _style ( this . _button _border _style ) ;
this . _prefsButton . set _style ( this . _button _border _style ) ;
this . _buttonMenu . actor . add _style _pseudo _class ( 'active' ) ;
color = this . _buttonMenu . actor . get _theme _node ( ) . get _background _color ( ) ;
this . _button _background _style = 'background-color:rgba(' + color . red + ',' + color . green + ',' + color . blue + ',' + ( Math . round ( color . alpha / 2.55 ) / 100 ) + ');' ;
this . _buttonMenu . actor . remove _style _pseudo _class ( 'active' ) ;
} ,
createButton : function ( iconName , accessibleName ) {
let button ;
if ( ExtensionUtils . versionCheck ( [ '3.8' ] , Config . PACKAGE _VERSION ) ) {
button = new St . Button ( {
reactive : true ,
can _focus : true ,
track _hover : true ,
accessible _name : accessibleName ,
style _class : 'popup-menu-item openweather-button'
} ) ;
button . child = new St . Icon ( {
icon _name : iconName
} ) ;
button . connect ( 'notify::hover' , Lang . bind ( this , this . _onButtonHoverChanged ) ) ;
} else
button = Main . panel . statusArea . aggregateMenu . _system . _createActionButton ( iconName , accessibleName ) ;
return button ;
} ,
get _actual _city ( ) {
if ( ! this . _settings )
this . loadConfig ( ) ;
@ -773,19 +842,22 @@ const OpenweatherMenuButton = new Lang.Class({
this . _buttonBox2 = undefined ;
}
this . _locationButton = Main . panel . statusArea . aggregateMenu . _system . _createAction Button( 'find-location-symbolic' , _ ( "Locations" ) ) ;
this . _locationButton = this . create Button( 'find-location-symbolic' , _ ( "Locations" ) ) ;
if ( this . _use _text _on _buttons )
this . _locationButton . set _label ( this . _locationButton . get _accessible _name ( ) ) ;
this . _locationButton . connect ( 'clicked' , Lang . bind ( this , function ( ) {
this . _selectCity . _setOpenState ( ! this . _selectCity . _getOpenState ( ) ) ;
if ( ExtensionUtils . versionCheck ( [ '3.8' ] , Config . PACKAGE _VERSION ) )
this . _selectCity . menu . toggle ( ) ;
else
this . _selectCity . _setOpenState ( ! this . _selectCity . _getOpenState ( ) ) ;
} ) ) ;
this . _buttonBox1 = new St . BoxLayout ( {
style _class : 'openweather-button-box'
} ) ;
this . _buttonBox1 . add _actor ( this . _locationButton ) ;
this . _reloadButton = Main . panel . statusArea . aggregateMenu . _system . _createAction Button( 'view-refresh-symbolic' , _ ( "Reload Weather Information" ) ) ;
this . _reloadButton = this . create Button( 'view-refresh-symbolic' , _ ( "Reload Weather Information" ) ) ;
if ( this . _use _text _on _buttons )
this . _reloadButton . set _label ( this . _reloadButton . get _accessible _name ( ) ) ;
this . _reloadButton . connect ( 'clicked' , Lang . bind ( this , function ( ) {
@ -800,8 +872,13 @@ const OpenweatherMenuButton = new Lang.Class({
style _class : 'openweather-button-box'
} ) ;
this . _urlButton = Main . panel . statusArea . aggregateMenu . _system . _createAction Button( '' , _ ( "Weather data provided by:" ) + ( this . _use _text _on _buttons ? "\n" : " " ) + this . weatherProvider ) ;
this . _urlButton = this . create Button( '' , _ ( "Weather data provided by:" ) + ( this . _use _text _on _buttons ? "\n" : " " ) + this . weatherProvider ) ;
this . _urlButton . set _label ( this . _urlButton . get _accessible _name ( ) ) ;
if ( ExtensionUtils . versionCheck ( [ '3.8' ] , Config . PACKAGE _VERSION ) ) {
this . _urlButton . connect ( 'notify::hover' , Lang . bind ( this , this . _onButtonHoverChanged ) ) ;
this . _urlButton . style _class = 'popup-menu-item' ;
}
this . _urlButton . style _class += ' openweather-provider' ;
this . _urlButton . connect ( 'clicked' , Lang . bind ( this , function ( ) {
@ -818,15 +895,25 @@ const OpenweatherMenuButton = new Lang.Class({
this . _buttonBox2 . add _actor ( this . _urlButton ) ;
this . _prefsButton = Main . panel . statusArea . aggregateMenu . _system . _createAction Button( 'preferences-system-symbolic' , _ ( "Weather Settings" ) ) ;
this . _prefsButton = this . create Button( 'preferences-system-symbolic' , _ ( "Weather Settings" ) ) ;
if ( this . _use _text _on _buttons )
this . _prefsButton . set _label ( this . _prefsButton . get _accessible _name ( ) ) ;
this . _prefsButton . connect ( 'clicked' , Lang . bind ( this , this . _onPreferencesActivate ) ) ;
this . _buttonBox2 . add _actor ( this . _prefsButton ) ;
this . _buttonMenu . actor . add _actor ( this . _buttonBox1 ) ;
this . _buttonMenu . actor . add _actor ( this . _buttonBox2 ) ;
if ( ExtensionUtils . versionCheck ( [ '3.8' ] , Config . PACKAGE _VERSION ) ) {
this . _buttonBox = new St . BoxLayout ( ) ;
this . _buttonBox1 . add _style _class _name ( 'openweather-button-box-38' ) ;
this . _buttonBox2 . add _style _class _name ( 'openweather-button-box-38' ) ;
this . _buttonBox . add _actor ( this . _buttonBox1 ) ;
this . _buttonBox . add _actor ( this . _buttonBox2 ) ;
this . _buttonMenu . addActor ( this . _buttonBox ) ;
this . _needsColorUpdate = true ;
} else {
this . _buttonMenu . actor . add _actor ( this . _buttonBox1 ) ;
this . _buttonMenu . actor . add _actor ( this . _buttonBox2 ) ;
}
this . _buttonBox1MinWidth = undefined ;
} ,
@ -845,7 +932,10 @@ const OpenweatherMenuButton = new Lang.Class({
item = new PopupMenu . PopupMenuItem ( this . extractLocation ( cities [ i ] ) ) ;
item . location = i ;
if ( i == this . _actual _city ) {
item . setOrnament ( PopupMenu . Ornament . DOT ) ;
if ( ExtensionUtils . versionCheck ( [ '3.8' ] , Config . PACKAGE _VERSION ) )
item . setShowDot ( true ) ;
else
item . setOrnament ( PopupMenu . Ornament . DOT ) ;
}
this . _selectCity . menu . addMenuItem ( item ) ;
@ -906,6 +996,9 @@ const OpenweatherMenuButton = new Lang.Class({
recalcLayout : function ( ) {
if ( ! this . menu . isOpen )
return ;
if ( ExtensionUtils . versionCheck ( [ '3.8' ] , Config . PACKAGE _VERSION ) ) {
this . _updateButtonColors ( ) ;
}
if ( this . _buttonBox1MinWidth === undefined )
this . _buttonBox1MinWidth = this . _buttonBox1 . get _width ( ) ;
this . _buttonBox1 . set _width ( Math . max ( this . _buttonBox1MinWidth , this . _currentWeather . get _width ( ) - this . _buttonBox2 . get _width ( ) ) ) ;