6cbbfc9e84670ab34a3b1d8da73f7092b93e21be
[roobuilder] / src / Builder4 / PopoverAddObject.bjs
1 {
2  "build_module" : "",
3  "items" : [
4   {
5    "$ xns" : "Gtk",
6    "@ void after_node_change" : "(JsRender.Node? node)",
7    "@ void before_node_change" : "(JsRender.Node? node)",
8    "@ void drag_end" : "()",
9    "Gtk.PositionType position" : "Gtk.PositionType.RIGHT",
10    "Xcls_MainWindow mainwindow" : "",
11    "bool active" : false,
12    "bool hexpand" : false,
13    "bool modal" : true,
14    "id" : "PopoverAddObject",
15    "int height_request" : 800,
16    "int width_request" : 900,
17    "items" : [
18     {
19      "$ shadow_type" : "Gtk.ShadowType.IN",
20      "$ xns" : "Gtk",
21      "* init" : [
22       "  this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);",
23       "   this.el.set_size_request(-1,200);",
24       " ",
25       ""
26      ],
27      "* pack" : "add",
28      "items" : [
29       {
30        "# string dragData" : "",
31        "$ enable_tree_lines" : true,
32        "$ headers_visible" : true,
33        "$ xns" : "Gtk",
34        "* init" : [
35         " {",
36         "    this.el.set_size_request(150,-1);",
37         "                          //  set_reorderable: [1]",
38         "                                  ",
39         "    var description = new Pango.FontDescription();",
40         "    description.set_size(10000);",
41         "    this.el.override_font(description);",
42         "    ",
43         "    var selection = this.el.get_selection();",
44         "    selection.set_mode( Gtk.SelectionMode.SINGLE);",
45         "   // this.selection.signal['changed'].connect(function() {",
46         "    //    _view.listeners['cursor-changed'].apply(_view, [ _view, '']);",
47         "    //});",
48         "    // see: http://live.gnome.org/GnomeLove/DragNDropTutorial",
49         "     ",
50         "    Gtk.drag_source_set (",
51         "            this.el,            /* widget will be drag-able */",
52         "            Gdk.ModifierType.BUTTON1_MASK,       /* modifier that will start a drag */",
53         "            BuilderApplication.targetList,            /* lists of target to support */",
54         "            Gdk.DragAction.COPY         /* what to do with data after dropped */",
55         "    );",
56         "    //Gtk.drag_source_set_target_list(this.el, LeftTree.targetList);",
57         "   ",
58         "   // Gtk.drag_source_set_target_list(this.el, Application.targetList);",
59         "   // Gtk.drag_source_add_text_targets(this.el); ",
60         " ",
61         "}",
62         ""
63        ],
64        "* pack" : "add",
65        "items" : [
66         {
67          "$ columns" : "typeof(string),typeof(string),typeof(Gdk.Pixbuf)",
68          "$ xns" : "Gtk",
69          "* pack" : "set_model",
70          "id" : "model",
71          "n_columns" : 3,
72          "xtype" : "ListStore",
73          "| string getValue" : [
74           " (Gtk.TreeIter iter, int col)  {",
75           "\tGLib.Value gval;",
76           "\tthis.el.get_value(iter, col , out gval);",
77           "\treturn  (string)gval;",
78           "     ",
79           "}"
80          ]
81         },
82         {
83          "$ xns" : "Gtk",
84          "* init" : [
85           "this.el.add_attribute(_this.txtrender.el , \"markup\",  1 );",
86           "this.el.add_attribute(_this.iconrender.el , \"pixbuf\",  2 );",
87           ""
88          ],
89          "* pack" : "append_column",
90          "items" : [
91           {
92            "$ xns" : "Gtk",
93            "* pack" : "pack_start,true",
94            "id" : "iconrender",
95            "xtype" : "CellRendererPixbuf"
96           },
97           {
98            "$ xns" : "Gtk",
99            "* pack" : "pack_start,true",
100            "id" : "txtrender",
101            "xtype" : "CellRendererText"
102           }
103          ],
104          "utf8 title" : "Drag to add Object",
105          "xtype" : "TreeViewColumn"
106         }
107        ],
108        "listeners" : {
109         "button_press_event" : [
110          " ( event) => {",
111          "",
112          " //\tif (!this.get('/Editor').save()) {",
113          " //\t    // popup!! - click handled.. ",
114          "// \t    return true;",
115          "//        }",
116          "    return false;",
117          "}"
118         ],
119         "drag_begin" : [
120          "  ( ctx) => {",
121          "    // we could fill this in now...",
122          "//        Seed.print('SOURCE: drag-begin');",
123          "        ",
124          "        ",
125          "        ",
126          "        Gtk.TreeIter iter;",
127          "        var s = this.el.get_selection();",
128          "        ",
129          "        Gtk.TreeModel mod;",
130          "        s.get_selected(out mod, out iter);",
131          "        var path = mod.get_path(iter);",
132          "        ",
133          "        /// pix is a surface..",
134          "        var pix = this.el.create_row_drag_icon ( path);",
135          "            ",
136          "                ",
137          "        Gtk.drag_set_icon_surface (ctx, pix);",
138          "        GLib.Value value;",
139          "        ",
140          "",
141          "        _this.model.el.get_value(iter, 0, out value);",
142          "        ",
143          "        this.dragData = (string) value;",
144          "         ",
145          "        ",
146          "        return;",
147          "}"
148         ],
149         "drag_data_get" : [
150          "(drag_context, selection_data, info, time) => {",
151          " \t//Seed.print('Palete: drag-data-get: ' + target_type);",
152          "    if (this.dragData.length < 1 ) {",
153          "        return; ",
154          "    }",
155          "    ",
156          "    GLib.debug(\"setting drag data to %s\\n\", this.dragData);",
157          "   // selection_data.set_text(this.dragData ,this.dragData.length);",
158          "   selection_data.set (selection_data.get_target (), 8, (uchar[]) this.dragData.to_utf8 ());",
159          "",
160          "        //this.el.dragData = \"TEST from source widget\";",
161          "        ",
162          "        ",
163          "}"
164         ],
165         "drag_end" : [
166          "( drag_context)  => {",
167          " \t GLib.debug(\"SOURCE: drag-end (call listener on this)\\n\");",
168          "\t",
169          "\tthis.dragData = \"\";",
170          "\t//this.dropList = null;",
171          "\t_this.drag_end(); // call signal..",
172          "\t//this.get('/LeftTree.view').highlight(false);",
173          "\t ",
174          "}"
175         ]
176        },
177        "xtype" : "TreeView"
178       }
179      ],
180      "xtype" : "ScrolledWindow"
181     }
182    ],
183    "xtype" : "Popover",
184    "| void clear" : [
185     "() {",
186     " this.model.el.clear();",
187     "}",
188     ""
189    ],
190    "| void hide" : [
191     "() {",
192     " ",
193     "\tthis.el.hide();",
194     "}",
195     ""
196    ],
197    "| void show" : [
198     "(Palete.Palete pal, string cls,  Gtk.Widget onbtn) {",
199     "",
200     "    ",
201     "   ",
202     "",
203     "    var tr = pal.getChildList(cls);",
204     "    this.model.el.clear();",
205     "",
206     "",
207     "    Gtk.TreeIter citer;",
208     "    var ic = Gtk.IconTheme.get_default();",
209     "    Gdk.Pixbuf pixdef = null;",
210     "    try {",
211     "\t\tpixdef = ic.load_icon(\"emblem-new\", 16,0);",
212     "\t} catch (Error e) {",
213     "\t}",
214     "",
215     "    for(var i =0 ; i < tr.length; i++) {",
216     "         this.model.el.append(out citer);   ",
217     "         var dname = tr[i];",
218     "         var clsname = dname;",
219     "         if (dname.contains(\":\")) {",
220     "\t\t\tvar ar = dname.split(\":\");",
221     "\t\t\tdname = \"<b>\" + ar[1] +\"</b> - <i>\"+ar[0]+\"</i>\";",
222     "\t\t\tclsname = ar[0]; /// possibly?",
223     "\t\t}",
224     "         ",
225     "        this.model.el.set_value(citer, 0,   tr[i] ); // used data. ",
226     "        this.model.el.set_value(citer, 1,   dname ); // displayed value.",
227     "        ",
228     "        var clsb = clsname.split(\".\");",
229     "        var sub = clsb.length > 1 ? clsb[1].down()  : \"\";",
230     "        ",
231     "        var pix = pixdef;",
232     "        var fn = \"/usr/share/glade/pixmaps/hicolor/16x16/actions/widget-gtk-\" + sub + \".png\";",
233     "        if (FileUtils.test (fn, FileTest.IS_REGULAR)) {",
234     "        \ttry {",
235     "\t        \tpix = new Gdk.Pixbuf.from_file (fn);",
236     "        \t} catch (Error e) {}",
237     "        \t",
238     "        }",
239     "        ",
240     "        ",
241     "        this.model.el.set_value(citer, 2,   pix );",
242     "        ",
243     "        ",
244     "    }",
245     "    this.model.el.set_sort_column_id(1,Gtk.SortType.ASCENDING);",
246     "    ",
247     "    ",
248     "    ",
249     "    // set size up...",
250     "    ",
251     "    this.model.el.set_sort_column_id(0,Gtk.SortType.ASCENDING);",
252     "    int w,h;",
253     "    this.mainwindow.el.get_size(out w, out h);",
254     "    ",
255     "    // left tree = 250, editor area = 500?",
256     "    ",
257     "    // min 450?",
258     "\t// max hieght ...",
259     "    this.el.set_size_request( 350, h); // full height?",
260     "",
261     "    ",
262     "",
263     "    if (this.el.relative_to == null) {",
264     "        this.el.set_relative_to(onbtn);",
265     "    }",
266     "    this.el.show_all();",
267     "   ",
268     "    while(Gtk.events_pending()) { ",
269     "            Gtk.main_iteration();",
270     "    }       ",
271     " //   this.hpane.el.set_position( 0);",
272     "}",
273     ""
274    ]
275   }
276  ],
277  "modOrder" : "",
278  "name" : "PopoverAddObject",
279  "parent" : "",
280  "path" : "/home/alan/gitlive/roobuilder/src/Builder4/PopoverAddObject.bjs",
281  "permname" : "",
282  "title" : ""
283 }