change property type dialog to use dropdown (has bug with popover autohide, but added...
[roobuilder] / src / Builder4 / PopoverProperty.bjs
index b60ab05..347c3c9 100644 (file)
 {
  "build_module" : "builder",
+ "gen_extended" : false,
  "items" : [
   {
-   "# JsRender.NodeProp? prop" : "",
+   "# Gtk.PositionType position" : "Gtk.PositionType.RIGHT",
+   "# JsRender.Node node" : "",
+   "# JsRender.NodeProp? original_prop" : "null",
+   "# JsRender.NodeProp? prop" : "null",
+   "# Xcls_MainWindow mainwindow" : "null",
+   "# string key_type" : "",
+   "# string old_keyname" : "",
    "$ xns" : "Gtk",
+   "* ctor" : "new Gtk.Popover()",
    "@ void success" : "(Project.Project pr, JsRender.JsRender file)",
-   "Gtk.PositionType position" : "Gtk.PositionType.LEFT",
-   "JsRender.Node node" : "",
-   "Xcls_MainWindow mainwindow" : "null",
+   "bool autohide" : true,
    "bool done" : false,
    "bool is_new" : false,
-   "bool modal" : true,
    "id" : "PopoverProperty",
    "items" : [
     {
-     "$ pack" : "add",
      "$ xns" : "Gtk",
+     "* pack" : "set_child",
      "Gtk.Orientation orientation" : "Gtk.Orientation.VERTICAL",
      "bool homogeneous" : false,
      "items" : [
       {
        "$ xns" : "Gtk",
-       "* pack" : "pack_start,false,true,0",
+       "Gtk.Orientation orientation" : "Gtk.Orientation.HORIZONTAL",
        "id" : "header",
-       "string title" : "Modify / Create Property",
-       "xtype" : "HeaderBar"
+       "items" : [
+        {
+         "$ xns" : "Gtk",
+         "bool always_show_image" : true,
+         "bool hexpand" : true,
+         "id" : "cancelbtn",
+         "listeners" : {
+          "clicked" : [
+           "() => {",
+           "\t_this.prop = null;",
+           "\t_this.is_new = false;",
+           "\t_this.kname.el.set_text(\"Cancel\");",
+           "\t_this.el.hide();",
+           "\t",
+           "}"
+          ]
+         },
+         "string label" : "Cancel",
+         "xtype" : "Button"
+        },
+        {
+         "$ xns" : "Gtk",
+         "bool hexpand" : true,
+         "id" : "headertitle",
+         "string label" : "Add / Edit property",
+         "xtype" : "Label"
+        },
+        {
+         "$ xns" : "Gtk",
+         "bool always_show_image" : true,
+         "bool hexpand" : true,
+         "id" : "savebtn",
+         "listeners" : {
+          "clicked" : [
+           "() => {",
+           "\tif (!_this.is_new) {",
+           "\t\t_this.el.hide();",
+           "\t}",
+           "\t",
+           "\t// check if text is not empty..",
+           "\tif ( _this.kname.el.get_text().strip().length < 1) {",
+           "\t",
+           "\t\t// error should already be showing?",
+           "\t\treturn;",
+           "\t}",
+           "\t ",
+           "\t// since we can't add listeners?!?!?",
+           "\t// only check props.",
+           "\t// check if property already exists in node.\t",
+           "",
+           "",
+           "\tvar prop = new JsRender.NodeProp(",
+           "\t\t_this.kname.el.get_text().strip(),",
+           "\t\t_this.ptype.getValue(),",
+           "\t\t_this.ktype.el.get_text().strip(),",
+           "\t\t_this.prop.val",
+           "\t);",
+           "",
+           "\tif (_this.node.props.has_key(prop.to_index_key())) {",
+           "\t\t_this.error.setError(\"Property already exists\");",
+           "\t\treturn;\t",
+           "\t}",
+           "\t",
+           "\t",
+           "\t",
+           "\t_this.node.add_prop(prop);",
+           "\t// hide self",
+           "\t_this.prop = null; // skip checks..",
+           "\t_this.is_new = false;",
+           "\t_this.el.hide();",
+           " \t_this.mainwindow.windowstate.left_props.changed();",
+           "\t_this.mainwindow.windowstate.left_props.view.editProp(prop);",
+           "",
+           "\t",
+           "\t",
+           "}"
+          ]
+         },
+         "string label" : "Add Property",
+         "xtype" : "Button"
+        }
+       ],
+       "xtype" : "Box"
       },
       {
+       "$ visible" : true,
        "$ xns" : "Gtk",
-       "* pack" : "add",
        "Gtk.Align halign" : "Gtk.Align.START",
        "Gtk.Justification justify" : "Gtk.Justification.LEFT",
        "int margin_top" : 12,
-       "label" : "Special Flags",
+       "label" : "Property Type (eg. property or method)",
        "x_options" : 4,
        "xtype" : "Label"
       },
       {
        "$ xns" : "Gtk",
-       "* init" : "this.el.add_attribute(_this.dbcellrenderer.el , \"markup\", 1 );",
-       "* pack" : "add",
-       "id" : "kflag",
+       "bool show_arrow" : true,
+       "id" : "ptype",
        "items" : [
         {
+         "$ strings" : "JsRender.NodePropType.get_pulldown_list()",
          "$ xns" : "Gtk",
-         "* pack" : "pack_start,true",
-         "id" : "dbcellrenderer",
-         "xtype" : "CellRendererText"
-        },
-        {
-         "$ columns" : "typeof(JsRender.NodePropType),typeof(string)",
-         "$ xns" : "Gtk",
-         "* pack" : "set_model",
-         "id" : "dbmodel",
-         "n_columns" : 2,
-         "xtype" : "ListStore",
-         "| void loadData" : [
-          "  (JsRender.NodeProp prop) {",
-          "    this.el.clear();                                    ",
-          "    Gtk.TreeIter iter;",
-          "    var el = this.el;",
-          "    ",
-          "    ",
-          "    // vala signal.. '@'",
-          "    // raw value '$'",
-          "    // user defined property '#'",
-          "    // user defined method '|'",
-          "    // special property '*' => prop  |args|ctor|init",
-          "    ",
-          "    ",
-          "    ",
-          "   /// el.append(out iter);",
-          "    ",
-          "     ",
-          "   // el.set_value(iter, 0, \"\");",
-          "   // el.set_value(iter, 1, \"aaa  - Just add Element - aaa\");",
-          "",
-          "    ",
-          "\tif (prop.ptype == JsRender.NodePropType.LISTENER) { ",
-          "\t\tel.append(out iter);",
-          "\t\tel.set(iter, 0, JsRender.NodePropType.LISTENER, 1,   \"Event Handler / Listener\", -1);",
-          "\t}\t ",
-          "\telse if (_this.mainwindow.windowstate.file.xtype == \"Gtk\") {",
-          "\t\t el.append(out iter);",
-          "\t    el.set(iter, 0, JsRender.NodePropType.PROP, 1,   \"Normal Property\", -1);",
-          "\t",
-          "\t\t",
-          "\t\tel.append(out iter);",
-          "\t\tel.set(iter, 0, JsRender.NodePropType.RAW, 1,   \"Raw Property (not escaped)\", -1);",
-          "\t\t ",
-          "\t\t",
-          "\t\tel.append(out iter);",
-          "\t\tel.set(iter, 0, JsRender.NodePropType.USER, 1,   \"User defined property\", -1);",
-          "\t\t ",
-          "\t\tel.append(out iter);",
-          "\t\tel.set(iter, 0, JsRender.NodePropType.METHOD, 1,   \"User defined method\", -1);",
-          "\t\t ",
-          "\t\tel.append(out iter);",
-          "\t\tel.set(iter, 0, JsRender.NodePropType.SPECIAL, 1,   \"Special property (eg. prop | args | ctor | init )\", -1);",
-          "\t\t ",
-          "\t\t",
-          "\t\tel.append(out iter);",
-          "\t    el.set(iter, 0, JsRender.NodePropType.SIGNAL, 1,   \"Vala Signal\", -1);",
-          "\t\t ",
-          "\t\t",
-          "\t} else { ",
-          "\t\t// javascript",
-          "\t    el.append(out iter);",
-          "\t    el.set(iter, 0, JsRender.NodePropType.PROP, 1,   \"Normal Property\", -1);",
-          "\t",
-          "\t\tel.append(out iter);",
-          "\t\tel.set(iter, 0, JsRender.NodePropType.RAW, 1,   \"Raw Property (not escaped)\", -1);",
-          "\t\t ",
-          "\t\tel.append(out iter);",
-          "\t\tel.set(iter, 0, JsRender.NodePropType.METHOD, 1,   \"User defined method\", -1);",
-          "\t ",
-          "\t\tel.append(out iter);",
-          "\t\tel.set(iter, 0,  JsRender.NodePropType.SPECIAL, 1,   \"(*) Special property (eg. prop )\", -1);",
-          "\t\t ",
-          "\t",
-          "\t}",
-          "\t// set selected, based on arg",
-          "\tel.foreach((tm, tp, titer) => {",
-          "\t\tGLib.Value val;",
-          "\t\tel.get_value(titer, 0, out val);",
-          "\t\t ",
-          "\t\t//print(\"check %s against %s\\n\", (string)val, _this.prop.ptype);",
-          "\t\tif (((JsRender.NodePropType)val) == prop.ptype) {",
-          "\t\t\t_this.kflag.el.set_active_iter(titer);",
-          "\t\t\treturn true;",
-          "\t\t}",
-          "\t\treturn false;",
-          "\t});",
-          "\t",
-          "",
-          "                                     ",
-          "}",
-          ""
-         ]
+         "* prop" : "model",
+         "xtype" : "StringList"
         }
        ],
-       "xtype" : "ComboBox"
+       "listeners" : {
+        "notify[\"selected\"]" : [
+         "() => {",
+         "",
+         "\t_this.el.grab_focus(); // stop prevent autohide breaking.",
+         " }"
+        ]
+       },
+       "xtype" : "DropDown",
+       "| JsRender.NodePropType getValue" : [
+        "() {",
+        "\tvar sl = this.el.model as Gtk.StringList;",
+        "\tvar str = sl.get_string(this.el.selected);",
+        "\treturn JsRender.NodePropType.nameToType(str);",
+        "}"
+       ],
+       "| void setValue" : [
+        "(JsRender.NodePropType ty) {",
+        "\tvar str = ty.to_name();",
+        "\tvar sl = this.el.model as Gtk.StringList;",
+        "\tfor(var i = 0; i < sl.get_n_items(); i++) {",
+        "\t\tif(sl.get_string(i) == str) {",
+        "\t\t\tthis.el.set_selected(i);",
+        "\t\t\tbreak;",
+        "\t\t}",
+        "\t}",
+        "\t",
+        "}"
+       ]
       },
       {
        "$ visible" : true,
        "$ xns" : "Gtk",
-       "* pack" : "add",
        "Gtk.Align halign" : "Gtk.Align.START",
        "Gtk.Justification justify" : "Gtk.Justification.LEFT",
        "int margin_top" : 12,
       {
        "$ visible" : true,
        "$ xns" : "Gtk",
-       "* pack" : "add",
        "id" : "ktype",
        "xtype" : "Entry"
       },
       {
        "$ visible" : true,
        "$ xns" : "Gtk",
-       "* pack" : "add",
        "Gtk.Align halign" : "Gtk.Align.START",
        "Gtk.Justification justify" : "Gtk.Justification.LEFT",
        "int margin_top" : 12,
       {
        "$ visible" : true,
        "$ xns" : "Gtk",
-       "* pack" : "add",
        "id" : "kname",
-       "listeners" : {
-        "focus_out_event" : [
-         "()=>{",
-         "\t_this.error.setError(\"\");",
-         "\tvar val = this.el.get_text().strip(); ",
-         "\tif (val.length < 1) {",
-         "\t\t_this.error.setError(\"Name can not be empty\");",
-         "\t}",
-         "\treturn true;",
-         "}",
-         "",
-         ""
-        ],
-        "key_release_event" : [
-         "()=>{",
-         "\t_this.error.setError(\"\");",
-         "\tvar val = this.el.get_text().strip(); ",
-         "\tif (val.length < 1) {",
-         "\t\t_this.error.setError(\"Name can not be empty\");",
-         "\t}",
-         "\treturn true;",
-         "}",
-         "",
-         ""
-        ]
-       },
+       "items" : [
+        {
+         "$ xns" : "Gtk",
+         "listeners" : {
+          "leave" : [
+           "( ) => {",
+           "",
+           "    _this.error.setError(\"\");",
+           "\tvar val = _this.kname.el.get_text().strip(); ",
+           "\tif (val.length < 1) {",
+           "\t\t_this.error.setError(\"Name can not be empty\");",
+           "\t}",
+           "",
+           "}",
+           ""
+          ]
+         },
+         "xtype" : "EventControllerFocus"
+        },
+        {
+         "$ xns" : "Gtk",
+         "listeners" : {
+          "key_released" : [
+           "(keyval, keycode, state) => {",
+           "",
+           "    _this.error.setError(\"\");",
+           "\tvar val = _this.kname.el.get_text().strip(); ",
+           "\tif (val.length < 1) {",
+           "\t\t_this.error.setError(\"Name can not be empty\");",
+           "\t}",
+           "",
+           "}",
+           ""
+          ]
+         },
+         "xtype" : "EventControllerKey"
+        }
+       ],
        "xtype" : "Entry"
       },
       {
        "$ visible" : true,
        "$ xns" : "Gtk",
-       "* pack" : "add",
        "Gtk.Align halign" : "Gtk.Align.START",
        "Gtk.Justification justify" : "Gtk.Justification.LEFT",
        "bool use_markup" : true,
        "| void setError" : [
         "(string err)   {",
         "\tif (err == \"\") {",
-        "\t\tthis.el.hide();",
+        "\t\tthis.el.label = \"\";",
         "\t} else {",
-        "\t\tthis.el.show();",
+        "",
         "\t\t",
         "\t\tthis.el.label = \"<span color=\\\"red\\\">\" + err + \"</span>\";",
         "\t}",
         "}",
         ""
        ]
-      },
-      {
-       "$ xns" : "Gtk",
-       "* pack" : "add",
-       "Gtk.Orientation orientation" : "Gtk.Orientation.HORIZONTAL",
-       "id" : "buttonbar",
-       "int margin_top" : 20,
-       "items" : [
-        {
-         "$ xns" : "Gtk",
-         "* pack" : "add",
-         "bool always_show_image" : true,
-         "bool hexpand" : true,
-         "items" : [
-          {
-           "$ xns" : "Gtk",
-           "* pack" : "composite_name",
-           "* prop" : "image",
-           "string icon_name" : "window-close",
-           "xtype" : "Image"
-          }
-         ],
-         "listeners" : {
-          "pressed" : [
-           "() => { ",
-           "",
-           "\t_this.prop = null;",
-           "\t_this.is_new = false;",
-           "\t_this.kname.el.set_text(\"Cancel\");",
-           "\t_this.el.hide();",
-           "",
-           "}"
-          ]
-         },
-         "string label" : "Cancel",
-         "xtype" : "Button"
-        },
-        {
-         "$ xns" : "Gtk",
-         "* pack" : "add",
-         "bool always_show_image" : true,
-         "bool hexpand" : true,
-         "items" : [
-          {
-           "$ xns" : "Gtk",
-           "* prop" : "image",
-           "string icon_name" : "list-add",
-           "xtype" : "Image"
-          }
-         ],
-         "listeners" : {
-          "pressed" : [
-           "() => {",
-           "\t// check if text is not empty..",
-           "\tif ( _this.kname.el.get_text().strip().length < 1) {",
-           "\t\t// error should already be showing?",
-           "\t\treturn;",
-           "\t}",
-           "\t_this.updateProp();",
-           "\t",
-           "\t// since we can't add listeners?!?!?",
-           "\t// only check props.",
-           "\t// check if property already exists in node.\t",
-           "\tvar prop = _this.prop;",
-           "\tif (_this.node.props.has_key(prop.to_index_key())) {",
-           "\t\t_this.error.setError(\"Property already exists\");",
-           "\t\treturn;\t",
-           "\t}",
-           "\t",
-           "\t",
-           "\t ",
-           "\t_this.is_new = false;\t",
-           "\t  ",
-           "\t// hide self",
-           "\t_this.prop = null; // skip checks..",
-           "\t_this.el.hide();",
-           "",
-           "// add it, ",
-           "\t// trigger editing of property.",
-           "\t// allow hide to work?",
-           "\twhile (Gtk.events_pending()) {",
-           "\t\tGtk.main_iteration();",
-           "\t}",
-           "\t",
-           "\t_this.mainwindow.windowstate.left_props.addProp(prop);\t\t",
-           "\t",
-           "",
-           "}"
-          ]
-         },
-         "string label" : "Add Property",
-         "xtype" : "Button"
-        }
-       ],
-       "xtype" : "Box"
       }
      ],
      "xtype" : "Box"
    "listeners" : {
     "closed" : [
      "() => {",
+     "",
      " \tGLib.debug(\"popover closed\");",
      "\tif (_this.is_new) {",
      "\t\t// dont allow hiding if we are creating a new one.",
      "\t\t// on.hide will reshow it.",
      "\t\treturn;",
-     "",
      "\t}",
      "\tif (_this.prop == null) {",
      "\t\t// hide and dont update.",
      "\tif (this.kname.el.get_text().strip().length < 1) {",
      "\t\treturn;",
      "\t}",
-     "\tvar oldkey = this.prop.to_index_key();\t",
-     "\t",
-     "\tthis.updateProp();",
-     "\t",
-     "\tvar newkey = this.prop.to_index_key();\t",
-     "\tif (oldkey != newkey) {",
-     "\t",
-     "\t\tif (_this.prop.ptype == JsRender.NodePropType.LISTENER) {",
-     "\t\t\tthis.node.listeners.unset(oldkey);",
-     "\t\t\tthis.node.listeners.set(newkey, _this.prop);",
-     "\t\t} else {",
-     "\t\t\tthis.node.props.unset(oldkey);",
-     "\t\t\tthis.node.props.set(newkey, _this.prop);",
-     "\t\t}",
      "\t",
-     "\t}",
-     "",
-     "\t_this.mainwindow.windowstate.left_props.reload();",
+     " ",
+     "         \t",
+     "         ",
+     "  \tthis.updateProp();",
+     "        ",
+     "\t ",
      "",
      "",
      "  ",
      "\tif (_this.is_new || this.kname.el.get_text().strip().length < 1) {",
      "\t\t// dont allow hiding if we are creating a new one.",
      "\t\tGLib.debug(\"prevent hiding as its new or text is empty\"); ",
-     "\t\tthis.el.show_all();",
+     "\t\tthis.el.show();",
      "\t\treturn;",
      "",
      "\t}",
+     "\tif (this.original_prop != null && !this.prop.equals(this.original_prop)) {",
+     "\t\t// this is convoluted..",
+     "\t\t_this.mainwindow.windowstate.left_props.changed(); ",
+     "\t}",
+     "\t",
      "\t",
      "}"
     ]
    },
-   "string key_type" : "",
-   "string old_keyname" : "",
-   "uint border_width" : 0,
    "xtype" : "Popover",
    "| void show" : [
     "(",
     "\t ) ",
     "{",
     "\t",
-    "   ",
+    "    this.original_prop = prop.dupe();",
     "\tthis.is_new = is_new; ",
     "\tvar pref = is_new ? \"Add \" : \"Modify \";",
     "\tif (prop.ptype == JsRender.NodePropType.LISTENER) {",
-    "\t\tthis.header.el.title = pref + \"Event Listener\"; // cant really happen yet?",
+    "\t\tthis.headertitle.el.label = pref + \"Event Listener\"; // cant really happen yet?",
     "\t} else {",
-    "\t\tthis.header.el.title = pref + \"Property\";",
+    "\t\tthis.headertitle.el.label = pref + \"Property\";",
     "\t}",
     "\tthis.prop = prop;",
     "\tthis.node = node;",
     "\t_this.kname.el.set_text(prop.name);",
     "\t_this.ktype.el.set_text(prop.rtype);",
     "\t",
-    "\t_this.dbmodel.loadData(prop );",
+    " \t_this.ptype.setValue(prop.ptype);",
     "\t// does node have this property...",
     "",
     "",
     "\t_this.node = node;",
     "\t//console.log('show all');",
-    "\tthis.el.set_modal(true);",
-    "\tthis.el.set_relative_to(btn);",
+    "\t",
+    "\tGLib.debug(\"set parent = %s\", btn.get_type().name());",
+    "\tvar par = btn.get_parent();",
+    "\t",
+    "\tif (par == null) {",
+    "\t\tGLib.debug(\"parent of that is null - not showing\");",
+    "\t\treturn;",
+    "\t}",
+    "\tif (this.el.parent == null) {",
+    "\t\tthis.el.set_parent(btn);",
+    "\t}",
+    "\tvar  r = Gdk.Rectangle() {",
+    "\t\t\tx = btn.get_width(), // align left...",
+    "\t\t\ty = 0,",
+    "\t\t\twidth = 1,",
+    "\t\t\theight = 1",
+    "\t\t};",
+    "\t//Gtk.Allocation rect;",
+    "\t//btn.get_allocation(out rect);",
+    "    this.el.set_pointing_to(r);",
+    "    ",
+    "",
+    "\t ",
     "\tif (y > -1) {",
-    "\t\tvar  r = Gdk.Rectangle() {",
-    "\t\t\tx = 0, // align left...",
+    "\t\t ",
+    "\t\t r = Gdk.Rectangle() {",
+    "\t\t\tx = btn.get_width(), // align left...",
     "\t\t\ty = y,",
     "\t\t\twidth = 1,",
     "\t\t\theight = 1",
     "\t//this.el.set_position(Gtk.PositionType.TOP);",
     "",
     "\t// window + header?",
-    "\t print(\"SHOWALL - POPIP\\n\");",
-    "\tthis.el.show_all();",
+    "\t GLib.debug(\"SHOWALL - POPIP\\n\");",
+    "\t",
     "\tthis.kname.el.grab_focus();",
-    "\tthis.buttonbar.el.hide();",
+    "\tthis.savebtn.el.set_label(\"Save\");",
+    "\tthis.cancelbtn.el.visible = false;",
     "\tif (this.is_new) {",
-    "\t\tthis.buttonbar.el.show();",
+    "\t\tthis.savebtn.el.set_label(\"Add Property\");",
+    "\t\tthis.cancelbtn.el.visible = true;",
     "\t}",
-    "\t this.error.setError(\"\");",
-    "",
+    "\tthis.error.setError(\"\");",
+    "\tthis.el.show();",
     "\t//this.success = c.success;",
     " ",
     "}"
    ],
    "| void updateProp" : [
     "() {",
-    "\tvar newtext = \"\";",
-    "\tGtk.TreeIter citer;",
-    "\tGLib.Value gval;",
-    "\tthis.kflag.el.get_active_iter(out citer);",
-    "\tthis.dbmodel.el.get_value(citer, 0, out  gval);",
+    " \tGLib.debug(\"updateProp called\");",
     "",
-    "",
-    "\t_this.prop.name = this.kname.el.get_text().strip(); ",
-    "\t_this.prop.rtype = this.ktype.el.get_text().strip(); ",
-    "\t_this.prop.ptype =  (JsRender.NodePropType) gval;",
-    "\t",
     "\t",
     "\t",
+    "\t_this.prop.name = this.kname.el.get_text().strip();",
+    "\t_this.prop.ptype = this.ptype.getValue();",
+    "\t_this.prop.rtype = this.ktype.el.get_text().strip();",
     "\t",
+    "\t  ",
     "}",
     ""
    ]
   }
  ],
- "modOrder" : "",
- "name" : "PopoverProperty",
- "parent" : "",
- "path" : "/home/alan/gitlive/roobuilder/src/Builder4/PopoverProperty.bjs",
- "permname" : "",
- "title" : ""
+ "name" : "PopoverProperty"
 }
\ No newline at end of file