@ -105,30 +105,72 @@ const WeatherPrefsWidget = new GObject.Class({
this . editWidget = this . Window . get _object ( "edit-widget" ) ;
this . editName = this . Window . get _object ( "edit-name" ) ;
this . editCoord = this . Window . get _object ( "edit-coord" ) ;
this . searchWidget = this . Window . get _object ( "search-widget" ) ;
this . searchMenu = this . Window . get _object ( "search-menu" ) ;
this . searchName = this . Window . get _object ( "search-name" ) ;
this . searchName . connect ( "icon-release" , Lang . bind ( this , this . clearEntry ) ) ;
this . editName . connect ( "icon-release" , Lang . bind ( this , this . clearEntry ) ) ;
this . editCoord . connect ( "icon-release" , Lang . bind ( this , this . clearEntry ) ) ;
this . Window . get _object ( "tree-toolbutton-add" ) . connect ( "clicked" , Lang . bind ( this , function ( ) {
this . addCity ( ) ;
log ( new Error ( ) . fileName + ':' + new Error ( ) . lineNumber + ' => this.searchWidget.get_parent() = ' + this . searchWidget . get _parent ( ) ) ;
this . searchWidget . show _all ( ) ;
} ) ) ;
this . Window . get _object ( "tree-toolbutton-remove" ) . connect ( "clicked" , Lang . bind ( this , function ( ) {
this . removeCity ( ) ;
} ) ) ;
this . Window . get _object ( "tree-toolbutton-remove" ) . connect ( "clicked" , Lang . bind ( this , this . removeCity ) ) ;
this . Window . get _object ( "tree-toolbutton-edit" ) . connect ( "clicked" , Lang . bind ( this , function ( ) {
this . editCity ( ) ;
} ) ) ;
this . Window . get _object ( "tree-toolbutton-edit" ) . connect ( "clicked" , Lang . bind ( this , this . editCity ) ) ;
this . Window . get _object ( "treeview-selection" ) . connect ( "changed" , Lang . bind ( this , function ( selection ) {
this . selectionChanged ( selection ) ;
} ) ) ;
this . Window . get _object ( "button-edit-cancel" ) . connect ( "clicked" , Lang . bind ( this , function ( ) {
this . editCancel ( ) ;
this . Window . get _object ( "button-edit-cancel" ) . connect ( "clicked" , Lang . bind ( this , this . editCancel ) ) ;
this . Window . get _object ( "button-edit-save" ) . connect ( "clicked" , Lang . bind ( this , this . editSave ) ) ;
this . Window . get _object ( "button-search-cancel" ) . connect ( "clicked" , Lang . bind ( this , function ( ) {
this . searchWidget . hide ( ) ;
} ) ) ;
this . Window . get _object ( "button-edit-save" ) . connect ( "clicked" , Lang . bind ( this , function ( ) {
this . editSave ( ) ;
this . Window . get _object ( "button-search-save" ) . connect ( "clicked" , Lang . bind ( this , this . searchSave ) ) ;
this . Window . get _object ( "button-search-find" ) . connect ( "clicked" , Lang . bind ( this , function ( ) {
let location = this . searchName . get _text ( ) . trim ( ) ;
if ( location === "" )
return 0 ;
let params = {
format : 'json' ,
addressdetails : '1' ,
q : location
} ;
this . loadJsonAsync ( WEATHER _URL _FIND , params , Lang . bind ( this , function ( ) {
if ( ! arguments [ 0 ] )
return 0 ;
let newCity = arguments [ 0 ] ;
if ( Number ( newCity . length ) < 1 )
return 0 ;
this . clearSearchMenu ( ) ;
var m = { } ;
for ( var i in newCity ) {
let cityText = newCity [ i ] . display _name ;
let cityCoord = "[" + newCity [ i ] . lat + "," + newCity [ i ] . lon + "]" ;
let item = new Gtk . MenuItem ( {
label : cityText + " " + cityCoord
} ) ;
item . connect ( "activate" , Lang . bind ( this , this . onActivateItem ) ) ;
this . searchMenu . append ( item ) ;
}
this . searchMenu . show _all ( ) ;
this . searchMenu . popup ( null , null , Lang . bind ( this , this . placeSearchMenu ) , 0 , this . searchName ) ;
} ) ) ;
} ) ) ;
let column = new Gtk . TreeViewColumn ( ) ;
@ -157,6 +199,28 @@ const WeatherPrefsWidget = new GObject.Class({
}
} ,
clearEntry : function ( ) {
arguments [ 0 ] . set _text ( "" ) ;
} ,
onActivateItem : function ( ) {
this . searchName . set _text ( arguments [ 0 ] . get _label ( ) ) ;
} ,
placeSearchMenu : function ( ) {
let [ gx , gy , gw , gh ] = this . searchName . get _window ( ) . get _geometry ( ) ;
let [ px , py ] = this . searchName . get _window ( ) . get _position ( ) ;
return [ gx + px , gy + py + this . searchName . get _allocated _height ( ) ] ;
} ,
clearSearchMenu : function ( ) {
let children = this . searchMenu . get _children ( ) ;
for ( let i in children ) {
log ( new Error ( ) . fileName + ':' + new Error ( ) . lineNumber + ' => children[' + i + '] = ' + children [ i ] ) ;
this . searchMenu . remove ( children [ i ] ) ;
}
} ,
initEntry : function ( theEntry ) {
let name = theEntry . get _name ( ) ;
theEntry . text = this [ name ] ;
@ -332,6 +396,22 @@ const WeatherPrefsWidget = new GObject.Class({
completionModel . set _value ( current , 0 , cityText + " " + cityCoord ) ;
}
log ( new Error ( ) . fileName + ':' + new Error ( ) . lineNumber ) ;
let ev = Gdk . EventKey ( ) ;
log ( new Error ( ) . fileName + ':' + new Error ( ) . lineNumber + ' => Gdk.EventKey = ' + Gdk . EventKey ) ;
// log(new Error().fileName+':'+new Error().lineNumber+' => ev = '+ev);
// new_event.key.type = GDK_KEY_PRESS;
// new_event.key.window = gtk_widget_get_parent_window(entry);
// new_event.key.send_event = TRUE;
// new_event.key.time = GDK_CURRENT_TIME;
// new_event.key.keyval = 0x053; // capital S
// new_event.key.state = GDK_KEY_PRESS_MASK;
// new_event.key.length = 0;
// new_event.key.string = 0;
// new_event.key.hardware_keycode = 0;
// new_event.key.group = 0;
//
// gdk_event_put((gpointer)&new_event);
completion . complete ( ) ;
return 0 ;
} , "getInfo" ) ;
@ -438,6 +518,19 @@ const WeatherPrefsWidget = new GObject.Class({
return 0 ;
} ,
searchSave : function ( ) {
let cityText = this . searchName . get _text ( ) . split ( /\[/ ) [ 0 ] ;
let coord = this . searchName . get _text ( ) . split ( /\[/ ) [ 1 ] . split ( /\]/ ) [ 0 ] ;
if ( this . city )
this . city = this . city + " && " + coord + ">" + cityText ;
else
this . city = coord + ">" + cityText ;
this . searchWidget . hide ( ) ;
return 0 ;
} ,
editSave : function ( ) {
let theCity = this . city . split ( " && " ) ;