Test.GtkWriter.vala.c
[app.Builder.js] / Builder4 / WindowRightPalete.js
1 Gtk = imports.gi.Gtk;
2 Gdk = imports.gi.Gdk;
3 Pango = imports.gi.Pango;
4 GLib = imports.gi.GLib;
5 Gio = imports.gi.Gio;
6 GObject = imports.gi.GObject;
7 GtkSource = imports.gi.GtkSource;
8 WebKit = imports.gi.WebKit;
9 Vte = imports.gi.Vte;
10 console = imports.console;
11 XObject = imports.XObject.XObject;
12 WindowRightPalete=new XObject({
13     xtype: Gtk.VBox,
14     id : "RightPalete",
15     pack : "pack_start,false,false",
16     'void:hide' : () {
17         
18           _this.buttonbar.el.show();
19           _this.viewbox.el.hide();
20       //    print("TRIED TO HIDE");
21     },
22     'void:show' : function() {
23         _this.buttonbar.el.hide();
24         _this.viewbox.el.show();
25        // this.get('model').expanded();
26                 
27     },
28     items : [
29         {
30             xtype: Gtk.VBox,
31             pack : "add",
32             id : "buttonbar",
33             items : [
34                 {
35                     xtype: Gtk.Button,
36                     listeners : {
37                         clicked : (self) => {
38                                 _this..show();
39                         }
40                     },
41                     pack : "pack_start,false,true",
42                     items : [
43                         {
44                             xtype: Gtk.Image,
45                             pack : "add",
46                             stock : Gtk.STOCK_GOTO_FIRST,
47                             icon_size : Gtk.IconSize.MENU
48                         }
49                     ]
50                 },
51                 {
52                     xtype: Gtk.Label,
53                     listeners : {
54                         enter_notify_event : (self, event) => {
55                             RightPalete.show();
56                             return false;
57                         }
58                     },
59                     angle : 270,
60                     label : "Palete",
61                     pack : "add",
62                     init : this.el.add_events ( Gdk.EventMask.BUTTON_MOTION_MASK );
63                 }
64             ]
65         },
66         {
67             xtype: Gtk.VBox,
68             pack : "add",
69             id : "viewbox",
70             items : [
71                 {
72                     xtype: Gtk.HBox,
73                     pack : "pack_start,false,true",
74                     items : [
75                         {
76                             xtype: Gtk.Label,
77                             pack : "add",
78                             label : "Palete"
79                         },
80                         {
81                             xtype: Gtk.Button,
82                             listeners : {
83                                 clicked : function (self) {
84                                         _this.RightPalete.hide();
85                                 }
86                             },
87                             pack : "pack_start,false,true",
88                             items : [
89                                 {
90                                     xtype: Gtk.Image,
91                                     pack : "add",
92                                     stock : Gtk.STOCK_GOTO_LAST,
93                                     icon_size : Gtk.IconSize.MENU
94                                 }
95                             ]
96                         }
97                     ]
98                 },
99                 {
100                     xtype: Gtk.ScrolledWindow,
101                     pack : "add",
102                     init : this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
103                        this.el.set_size_request(-1,200);,
104                     shadow_type : Gtk.ShadowType.IN,
105                     items : [
106                         {
107                             xtype: Gtk.TreeView,
108                             listeners : {
109                                 drag_begin : ( ctx) => {
110                                     // we could fill this in now...
111                                 //        Seed.print('SOURCE: drag-begin');
112                                         
113                                         
114                                         
115                                         Gtk.TreeIter iter;
116                                         var s = _this.selection;
117                                         
118                                         s.get_selected(_this.model.el, out iter);
119                                         var path = _this.model.el.get_path(iter);
120                                         
121                                         /// pix is a surface..
122                                         var pix = this.el.create_row_drag_icon ( path);
123                                             
124                                                 
125                                         Gtk.drag_set_icon_surface (ctx, pix);
126                                         Glib.Value val;
127                                         
128                                 
129                                         _this.model.el.get_value(iter, 0, out value);
130                                         if (_this.provider == null) {
131                                             return false;
132                                         }
133                                         //if (!this.get('/RightPalete').provider) {
134                                         //    return false;
135                                         //}
136                                         this.dropList = _this.provider.getDropList((string)value);
137                                         this.dragData = (string) value;
138                                          
139                                         
140                                         return true;
141                                 },
142                                 drag_data_get : (drag_context, selection_data, info, time) => {
143                                         //Seed.print('Palete: drag-data-get: ' + target_type);
144                                         if (this.el.dragData.length > 0 ) {
145                                             selection_data.set_text(this.dragData ,this.dragData.length);
146                                         }
147                                         
148                                         
149                                         //this.el.dragData = "TEST from source widget";
150                                         
151                                         
152                                 },
153                                 drag_end : ( drag_context)  => {
154                                         //Seed.print('SOURCE: drag-end');
155                                         
156                                         this.dragData = "";
157                                         this.dropList = null;
158                                         _this.drag_end(); // call signal..
159                                         //this.get('/LeftTree.view').highlight(false);
160                                         return true;
161                                 },
162                                 button_press_event : ( event) => {
163                                 
164                                  //     if (!this.get('/Editor').save()) {
165                                  //         // popup!! - click handled.. 
166                                 //          return true;
167                                 //        }
168                                     return false;
169                                 }
170                             },
171                             pack : "add",
172                             enable_tree_lines : true,
173                             headers_visible : false,
174                             init : {
175                                 this.el.set_size_request(150,-1);
176                                                       //  set_reorderable: [1]
177                                                               
178                                 var description = new Pango.FontDescription();
179                                 description.set_size(8000);
180                                 this.el.modify_font(description);
181                                 
182                                 var selection = this.el.get_selection();
183                                 selection.set_mode( Gtk.SelectionMode.SINGLE);
184                                // this.selection.signal['changed'].connect(function() {
185                                 //    _view.listeners['cursor-changed'].apply(_view, [ _view, '']);
186                                 //});
187                                 // see: http://live.gnome.org/GnomeLove/DragNDropTutorial
188                                  
189                                 Gtk.drag_source_set (
190                                         this.el,            /* widget will be drag-able */
191                                         Gdk.ModifierType.BUTTON1_MASK,       /* modifier that will start a drag */
192                                         null,            /* lists of target to support */
193                                         0,              /* size of list */
194                                         Gdk.DragAction.COPY         /* what to do with data after dropped */
195                                 );
196                                 //Gtk.drag_source_set_target_list(this.el, LeftTree.targetList);
197                                
198                                 Gtk.drag_source_set_target_list(this.el, Application.targetList);
199                                 Gtk.drag_source_add_text_targets(this.el); 
200                              
201                             },
202                             items : [
203                                 {
204                                     xtype: Gtk.ListStore,
205                                     columns : "typeof(string),typeof(string)",
206                                     id : "model",
207                                     n_columns : 2,
208                                     pack : "set_model",
209                                     'void:load' : (GLib.List<string> tr, Gtk.TreeIter? iter)
210                                     {
211                                         if (iter == null) {
212                                             this.el.clear();
213                                         }
214                                         //console.log('Project tree load: ' + tr.length);
215                                     
216                                         Gtk.TreeIter citer;
217                                         //this.insert(citer,iter,0);
218                                         for(var i =0 ; i < tr.length(); i++) {
219                                             if (iter == null) {
220                                                 
221                                                 this.el.append(out citer);   
222                                             } else {
223                                                 this.el.insert(out citer,iter,-1);
224                                             }
225                                             
226                                             var r = tr.nth_data(i);
227                                             //Seed.print(r);
228                                             this.el.set_value(citer, 0,   r ); // title 
229                                             
230                                             //this.el.set_value(citer, 1,  new GObject.Value( r)); //id
231                                             //if (r.cn && r.cn.length) {
232                                             //    this.load(r.cn, citer);
233                                             //}
234                                         }
235                                         
236                                         
237                                     },
238                                     'string:getValue' : (Gtk.TreeIter iter, int col)  {
239                                         GLib.Value gval;
240                                          this.el.get_value(iter, col , out gval);
241                                         return  (string)gval;
242                                         
243                                         
244                                     }
245                                 },
246                                 {
247                                     xtype: Gtk.TreeViewColumn,
248                                     pack : "append_column",
249                                     init : this.el.add_attribute(_this.txtrender , "markup", 0 );,
250                                     items : [
251                                         {
252                                             xtype: Gtk.CellRendererText,
253                                             id : "txtrender",
254                                             pack : "pack_start"
255                                         }
256                                     ]
257                                 }
258                             ]
259                         }
260                     ]
261                 }
262             ]
263         }
264     ]
265 });
266 WindowRightPalete.init();
267 XObject.cache['/WindowRightPalete'] = WindowRightPalete;