9ebadf535789ebbf5f4a7706b69824c1e33f13e6
[roobuilder] / src / Builder4 / PopoverAddObject.vala
1 static Xcls_PopoverAddObject  _PopoverAddObject;
2
3 public class Xcls_PopoverAddObject : Object
4 {
5     public Gtk.Popover el;
6     private Xcls_PopoverAddObject  _this;
7
8     public static Xcls_PopoverAddObject singleton()
9     {
10         if (_PopoverAddObject == null) {
11             _PopoverAddObject= new Xcls_PopoverAddObject();
12         }
13         return _PopoverAddObject;
14     }
15     public Xcls_model model;
16     public Xcls_txtrender txtrender;
17
18         // my vars (def)
19     public bool active;
20     public signal void before_node_change (JsRender.Node? node);
21     public signal void drag_end ();
22     public Xcls_MainWindow mainwindow;
23     public signal void after_node_change (JsRender.Node? node);
24
25     // ctor
26     public Xcls_PopoverAddObject()
27     {
28         _this = this;
29         this.el = new Gtk.Popover( null );
30
31         // my vars (dec)
32         this.active = false;
33
34         // set gobject values
35         this.el.width_request = 900;
36         this.el.height_request = 800;
37         this.el.hexpand = false;
38         this.el.modal = true;
39         this.el.position = Gtk.PositionType.RIGHT;
40         var child_0 = new Xcls_ScrolledWindow2( _this );
41         child_0.ref();
42         this.el.add (  child_0.el  );
43     }
44
45     // user defined functions
46     public void show (Palete.Palete pal, string cls,  Gtk.Widget onbtn) {
47     
48         
49        
50      
51     
52         var tr = pal.getChildList(cls);
53         this.model.el.clear();
54     
55     
56         Gtk.TreeIter citer;
57     
58         for(var i =0 ; i < tr.length; i++) {
59              this.model.el.append(out citer);   
60              var dname = tr[i];
61              if (dname.contains(":")) {
62                         var ar = dname.split(":");
63                         dname = "<b>" + ar[1] +"</b> - <i>"+ar[0]+"</i>";
64                 }
65              
66             this.model.el.set_value(citer, 0,   tr[i] ); // used data. 
67             this.model.el.set_value(citer, 1,   dname ); // displayed value.
68             
69         }
70         this.model.el.set_sort_column_id(1,Gtk.SortType.ASCENDING);
71         
72         
73         
74         
75         
76         // set size up...
77         
78         this.model.el.set_sort_column_id(0,Gtk.SortType.ASCENDING);
79         int w,h;
80         this.mainwindow.el.get_size(out w, out h);
81         
82         // left tree = 250, editor area = 500?
83         
84         // min 450?
85         // max hieght ...
86         this.el.set_size_request( 350, h); // full height?
87     
88         
89     
90         if (this.el.relative_to == null) {
91             this.el.set_relative_to(onbtn);
92         }
93         this.el.show_all();
94        
95         while(Gtk.events_pending()) { 
96                 Gtk.main_iteration();
97         }       
98      //   this.hpane.el.set_position( 0);
99     }
100     public void hide () {
101      
102         this.el.hide();
103     }
104     public void clear () {
105      this.model.el.clear();
106     }
107     public class Xcls_ScrolledWindow2 : Object
108     {
109         public Gtk.ScrolledWindow el;
110         private Xcls_PopoverAddObject  _this;
111
112
113             // my vars (def)
114
115         // ctor
116         public Xcls_ScrolledWindow2(Xcls_PopoverAddObject _owner )
117         {
118             _this = _owner;
119             this.el = new Gtk.ScrolledWindow( null, null );
120
121             // my vars (dec)
122
123             // set gobject values
124             this.el.shadow_type = Gtk.ShadowType.IN;
125             var child_0 = new Xcls_TreeView3( _this );
126             child_0.ref();
127             this.el.add (  child_0.el  );
128
129             // init method
130
131             this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
132                this.el.set_size_request(-1,200);
133         }
134
135         // user defined functions
136     }
137     public class Xcls_TreeView3 : Object
138     {
139         public Gtk.TreeView el;
140         private Xcls_PopoverAddObject  _this;
141
142
143             // my vars (def)
144         public string dragData;
145
146         // ctor
147         public Xcls_TreeView3(Xcls_PopoverAddObject _owner )
148         {
149             _this = _owner;
150             this.el = new Gtk.TreeView();
151
152             // my vars (dec)
153
154             // set gobject values
155             this.el.enable_tree_lines = true;
156             this.el.headers_visible = true;
157             var child_0 = new Xcls_model( _this );
158             child_0.ref();
159             this.el.set_model (  child_0.el  );
160             var child_1 = new Xcls_TreeViewColumn5( _this );
161             child_1.ref();
162             this.el.append_column (  child_1.el  );
163
164             // init method
165
166             {
167                 this.el.set_size_request(150,-1);
168                                       //  set_reorderable: [1]
169                                               
170                 var description = new Pango.FontDescription();
171                 description.set_size(10000);
172                 this.el.override_font(description);
173                 
174                 var selection = this.el.get_selection();
175                 selection.set_mode( Gtk.SelectionMode.SINGLE);
176                // this.selection.signal['changed'].connect(function() {
177                 //    _view.listeners['cursor-changed'].apply(_view, [ _view, '']);
178                 //});
179                 // see: http://live.gnome.org/GnomeLove/DragNDropTutorial
180                  
181                 Gtk.drag_source_set (
182                         this.el,            /* widget will be drag-able */
183                         Gdk.ModifierType.BUTTON1_MASK,       /* modifier that will start a drag */
184                         BuilderApplication.targetList,            /* lists of target to support */
185                         Gdk.DragAction.COPY         /* what to do with data after dropped */
186                 );
187                 //Gtk.drag_source_set_target_list(this.el, LeftTree.targetList);
188                
189                // Gtk.drag_source_set_target_list(this.el, Application.targetList);
190                // Gtk.drag_source_add_text_targets(this.el); 
191              
192             }
193
194             //listeners
195             this.el.button_press_event.connect( ( event) => {
196             
197              // if (!this.get('/Editor').save()) {
198              //     // popup!! - click handled.. 
199             //      return true;
200             //        }
201                 return false;
202             });
203             this.el.drag_begin.connect( ( ctx) => {
204                 // we could fill this in now...
205             //        Seed.print('SOURCE: drag-begin');
206                     
207                     
208                     
209                     Gtk.TreeIter iter;
210                     var s = this.el.get_selection();
211                     
212                     Gtk.TreeModel mod;
213                     s.get_selected(out mod, out iter);
214                     var path = mod.get_path(iter);
215                     
216                     /// pix is a surface..
217                     var pix = this.el.create_row_drag_icon ( path);
218                         
219                             
220                     Gtk.drag_set_icon_surface (ctx, pix);
221                     GLib.Value value;
222                     
223             
224                     _this.model.el.get_value(iter, 0, out value);
225                     
226                     this.dragData = (string) value;
227                      
228                     
229                     return;
230             });
231             this.el.drag_data_get.connect( (drag_context, selection_data, info, time) => {
232                 //Seed.print('Palete: drag-data-get: ' + target_type);
233                 if (this.dragData.length < 1 ) {
234                     return; 
235                 }
236                 
237                 GLib.debug("setting drag data to %s\n", this.dragData);
238                // selection_data.set_text(this.dragData ,this.dragData.length);
239                selection_data.set (selection_data.get_target (), 8, (uchar[]) this.dragData.to_utf8 ());
240             
241                     //this.el.dragData = "TEST from source widget";
242                     
243                     
244             });
245             this.el.drag_end.connect( ( drag_context)  => {
246                  GLib.debug("SOURCE: drag-end (call listener on this)\n");
247                 
248                 this.dragData = "";
249                 //this.dropList = null;
250                 _this.drag_end(); // call signal..
251                 //this.get('/LeftTree.view').highlight(false);
252                  
253             });
254         }
255
256         // user defined functions
257     }
258     public class Xcls_model : Object
259     {
260         public Gtk.ListStore el;
261         private Xcls_PopoverAddObject  _this;
262
263
264             // my vars (def)
265
266         // ctor
267         public Xcls_model(Xcls_PopoverAddObject _owner )
268         {
269             _this = _owner;
270             _this.model = this;
271             this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
272
273             // my vars (dec)
274
275             // set gobject values
276         }
277
278         // user defined functions
279         public string getValue (Gtk.TreeIter iter, int col)  {
280                 GLib.Value gval;
281                 this.el.get_value(iter, col , out gval);
282                 return  (string)gval;
283              
284         }
285     }
286
287     public class Xcls_TreeViewColumn5 : Object
288     {
289         public Gtk.TreeViewColumn el;
290         private Xcls_PopoverAddObject  _this;
291
292
293             // my vars (def)
294
295         // ctor
296         public Xcls_TreeViewColumn5(Xcls_PopoverAddObject _owner )
297         {
298             _this = _owner;
299             this.el = new Gtk.TreeViewColumn();
300
301             // my vars (dec)
302
303             // set gobject values
304             this.el.title = "Drag to add Object";
305             var child_0 = new Xcls_txtrender( _this );
306             child_0.ref();
307             this.el.pack_start (  child_0.el , true );
308
309             // init method
310
311             this.el.add_attribute(_this.txtrender.el , "markup",  1 );
312         }
313
314         // user defined functions
315     }
316     public class Xcls_txtrender : Object
317     {
318         public Gtk.CellRendererText el;
319         private Xcls_PopoverAddObject  _this;
320
321
322             // my vars (def)
323
324         // ctor
325         public Xcls_txtrender(Xcls_PopoverAddObject _owner )
326         {
327             _this = _owner;
328             _this.txtrender = this;
329             this.el = new Gtk.CellRendererText();
330
331             // my vars (dec)
332
333             // set gobject values
334         }
335
336         // user defined functions
337     }
338
339
340
341
342 }