Fix #7214 - move edit code into popover
[roobuilder] / src / Builder4 / PopoverAddProp.bjs
1 {
2  "build_module" : "",
3  "items" : [
4   {
5    "$ xns" : "Gtk",
6    "@ void select" : "(string key, string type, string skel, string prop_or_listener)",
7    "Gtk.PositionType position" : "Gtk.PositionType.RIGHT",
8    "Xcls_MainWindow mainwindow" : "",
9    "bool active" : false,
10    "bool hexpand" : false,
11    "bool modal" : true,
12    "id" : "PopoverAddProp",
13    "int height_request" : 800,
14    "int width_request" : 900,
15    "items" : [
16     {
17      "$ shadow_type" : "Gtk.ShadowType.IN",
18      "$ xns" : "Gtk",
19      "* init" : [
20       "    this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);",
21       " "
22      ],
23      "* pack" : "add",
24      "items" : [
25       {
26        "$ enable_tree_lines" : true,
27        "$ headers_visible" : true,
28        "$ xns" : "Gtk",
29        "* init" : [
30         "{  ",
31         "       var description = new Pango.FontDescription();",
32         "     description.set_size(10000);",
33         "    this.el.override_font(description);     ",
34         "                    ",
35         "    this.el.get_selection().set_mode( Gtk.SelectionMode.SINGLE);",
36         " ",
37         "",
38         "    ",
39         "  ",
40         "    ",
41         "}",
42         ""
43        ],
44        "* pack" : "add",
45        "items" : [
46         {
47          "$ columns" : [
48           "typeof(string),  // 0 real key",
49           "typeof(string), // 1 real type",
50           "typeof(string), // 2 docs ?",
51           "typeof(string), // 3 visable desc",
52           "typeof(string), // 4 function desc",
53           "typeof(string) // 5 element type (event|prop)",
54           "        "
55          ],
56          "$ xns" : "Gtk",
57          "* pack" : "set_model",
58          "id" : "model",
59          "n_columns" : 6,
60          "xtype" : "ListStore",
61          "| string getValue" : [
62           "(Gtk.TreeIter iter, int col)",
63           "{",
64           "",
65           "    GLib.Value value;",
66           "    this.el.get_value(iter, col, out value);",
67           " ",
68           "    return (string)value;",
69           "    ",
70           "}"
71          ]
72         },
73         {
74          "$ xns" : "Gtk",
75          "* init" : [
76           "  this.el.add_attribute(_this.namerender.el , \"markup\", 4  );",
77           " ",
78           ""
79          ],
80          "* pack" : "append_column",
81          "id" : "namecol",
82          "items" : [
83           {
84            "$ xns" : "Gtk",
85            "* pack" : "pack_start,true",
86            "id" : "namerender",
87            "xtype" : "CellRendererText"
88           }
89          ],
90          "utf8 title" : "Double click to add",
91          "xtype" : "TreeViewColumn"
92         }
93        ],
94        "listeners" : {
95         "row_activated" : [
96          "(path, column)  => {",
97          "",
98          "\tGtk.TreeIter iter;",
99          "",
100          "",
101          "\tvar m = _this.model;",
102          "",
103          "\tm.el.get_iter(out iter,path);",
104          "",
105          "",
106          "\t// var val = \"\";",
107          "",
108          "",
109          "\tvar key = m.getValue(iter, 0);",
110          "",
111          "\tvar type = m.getValue(iter, 1);",
112          "\tvar skel = m.getValue(iter, 3);",
113          "\tvar etype = m.getValue(iter, 5);",
114          "",
115          "\t// hide the popover",
116          "\t_this.el.hide();",
117          "\t_this.prop_or_listener = \"\";",
118          "\t",
119          "\t",
120          "\t_this.select(key,etype == \"signals\" ? \"\" : type,skel, etype);",
121          " ",
122          "}",
123          " "
124         ]
125        },
126        "tooltip_column" : 2,
127        "xtype" : "TreeView"
128       }
129      ],
130      "xtype" : "ScrolledWindow"
131     }
132    ],
133    "string prop_or_listener" : "\"\"",
134    "xtype" : "Popover",
135    "| void clear" : [
136     "() {",
137     " this.model.el.clear();",
138     "}",
139     ""
140    ],
141    "| void hide" : [
142     "() {",
143     "\tthis.prop_or_listener = \"\";",
144     "\tthis.el.hide();",
145     "}",
146     ""
147    ],
148    "| void show" : [
149     "(Palete.Palete pal, string prop_or_listener, string xtype,  Gtk.Widget onbtn) {",
150     "",
151     "    ",
152     "    if (this.prop_or_listener  != \"\" && this.prop_or_listener == prop_or_listener) {",
153     "    \tthis.prop_or_listener = \"\";",
154     "    \tthis.el.hide();",
155     "    \treturn;",
156     "\t}",
157     "    this.prop_or_listener = prop_or_listener;",
158     "    ",
159     "    this.model.el.clear();",
160     "",
161     "    Gtk.TreeIter iter;",
162     "    var elementList = pal.getPropertiesFor( xtype,prop_or_listener);",
163     "     ",
164     "    //print (\"GOT \" + elementList.length + \" items for \" + fullpath + \"|\" + type);",
165     "           // console.dump(elementList);",
166     "           ",
167     "    var miter = elementList.map_iterator();",
168     "    while (miter.next()) {",
169     "       var p = miter.get_value();",
170     "        ",
171     "        this.model.el.append(out iter);",
172     "",
173     "\t\tvar dname = p.name;",
174     "\t\tvar dtype = p.type;",
175     "\t\t ",
176     "",
177     "        this.model.el.set(iter,",
178     "                0,  p.name, ",
179     "                1, p.type,",
180     "                2, \"<b>\" + p.name +\"</b> <i>\"+p.type+\"</i>\\n\" + ",
181     "                        GLib.Markup.escape_text(p.doctxt),",
182     "                3, p.sig,",
183     "                4, \"<b>\" + dname +\"</b> <span size=\\\"small\\\"><i>\"+dtype+\"</i></span>\",",
184     "                5, prop_or_listener,",
185     "                -1",
186     "        );",
187     "    }",
188     "    this.model.el.set_sort_column_id(0,Gtk.SortType.ASCENDING);    ",
189     "    ",
190     "    // set size up...",
191     "    ",
192     "",
193     "    int w,h;",
194     "    this.mainwindow.el.get_size(out w, out h);",
195     "    ",
196     "    // left tree = 250, editor area = 500?",
197     "    ",
198     "    // min 450?",
199     "\t// max hieght ...",
200     "    this.el.set_size_request( 250, h);",
201     "",
202     "    ",
203     "",
204     "    if (this.el.relative_to == null) {",
205     "        this.el.set_relative_to(onbtn);",
206     "    }",
207     "    this.el.show_all();",
208     "   ",
209     "    while(Gtk.events_pending()) { ",
210     "            Gtk.main_iteration();   // why?",
211     "    }       ",
212     " //   this.hpane.el.set_position( 0);",
213     "}",
214     ""
215    ]
216   }
217  ],
218  "modOrder" : "",
219  "name" : "PopoverAddProp",
220  "parent" : "",
221  "path" : "/home/alan/gitlive/roobuilder/src/Builder4/PopoverAddProp.bjs",
222  "permname" : "",
223  "title" : ""
224 }