예제 #1
0
 void AddToTree(Gtk.TreeStore treeStore, Gtk.TreeIter iter, PObject current, Dictionary <PObject, PListScheme.SchemaItem> tree)
 {
     foreach (var item in PObject.ToEnumerable(current))
     {
         var subIter = FindOrAddPObject(iter, item.Key, item.Value, tree);
         AddToTree(treeStore, subIter, item.Value, tree);
     }
 }
예제 #2
0
 public void SetPListContainer(PObjectContainer value)
 {
     nsDictionary          = value;
     nsDictionary.Changed += delegate {
         QueueDraw();
     };
     RefreshTree();
 }
예제 #3
0
        void AddNewArrayElement(PArray array)
        {
            var values = PListScheme.AvailableKeys(array, CurrentTree);

            if (values == null)
            {
                array.Add(PObject.Create(DefaultNewObjectType));
            }
            else if (values.Any())
            {
                array.Add(values.First().Create());
            }
        }
예제 #4
0
 public byte[] ToByteArray(bool binary)
 {
     using (new NSAutoreleasePool()) {
         var pobject = Convert();
         NSPropertyListFormat format = binary? NSPropertyListFormat.Binary : NSPropertyListFormat.Xml;
         var data = PObject.DataFromPropertyList(pobject, format, 0);
         if (data == null)
         {
             throw new Exception("Could not convert the NSDictionary to the specified format");
         }
         return(data.ToArray());
     }
 }
예제 #5
0
 internal static IEnumerable <KeyValuePair <string, PObject> > ToEnumerable(PObject obj)
 {
     if (obj is PDictionary)
     {
         return((PDictionary)obj);
     }
     else if (obj is PArray)
     {
         return(((PArray)obj).Select(k => new KeyValuePair <string, PObject> (k is IPValueObject ? ((IPValueObject)k).Value.ToString() : null, k)));
     }
     else
     {
         return(Enumerable.Empty <KeyValuePair <string, PObject> > ());
     }
 }
예제 #6
0
        TreeIter FindOrAddPObject(TreeIter iter, string id, PObject item, Dictionary <PObject, PListScheme.SchemaItem> tree)
        {
            TreeIter subIter;

            if (CurrentTree.ContainsKey(item))
            {
                if (iter.Equals(TreeIter.Zero) ? treeStore.IterChildren(out subIter) : treeStore.IterChildren(out subIter, iter))
                {
                    do
                    {
                        if (treeStore.GetValue(subIter, 1) == item)
                        {
                            // If we have modified the value of an existing PObject, such
                            // as changing the value of a PNumber from '1' to '2', we will
                            // need to refresh the value in the treestore.
                            treeStore.SetValue(subIter, 0, id);
                            break;
                        }
                    } while (treeStore.IterNext(ref subIter));
                }
            }
            else
            {
                subIter = treeStore.InsertNodeBefore(FindOrAddNewEntry(iter));
                treeStore.SetValues(subIter, id, item, tree [item]);
                if (CurrentTree.Count > 0)
                {
                    treeview.ExpandToPath(treeStore.GetPath(subIter));
                    this.treeview.Selection.SelectIter(subIter);
                }

                if (item is PArray || item is PDictionary)
                {
                    var newEntryIter = FindOrAddNewEntry(subIter);
                    if (CurrentTree.Count > 0)
                    {
                        treeview.ExpandToPath(treeStore.GetPath(newEntryIter));
                    }
                }
            }

            return(subIter);
        }
예제 #7
0
        void AddNewDictionaryElement(PDictionary dict)
        {
            var values = PListScheme.AvailableKeys(dict, CurrentTree);

            if (values == null)
            {
                string name = "newProperty";
                while (dict.ContainsKey(name))
                {
                    name += "_";
                }
                dict.Add(name, PObject.Create(DefaultNewObjectType));
            }
            else if (values.Any())
            {
                var value = values.FirstOrDefault();
                dict.Add(value.Identifier, value.Create());
            }
        }
예제 #8
0
        public void Replace(PObject newObject)
        {
            var p = Parent;

            if (p is PDictionary)
            {
                var dict = (PDictionary)p;
                var key  = dict.GetKey(this);
                if (key == null)
                {
                    return;
                }
                Remove();
                dict[key] = newObject;
            }
            else if (p is PArray)
            {
                var arr = (PArray)p;
                arr.Replace(this, newObject);
            }
        }
        public ClosableExpander AddListItem(string name, Widget widget, PObject obj)
        {
            if (noContentLabel != null)
            {
                contentBox.Remove(noContentLabel);
                noContentLabel.Destroy();
                noContentLabel = null;
            }

            var expander = new ClosableExpander();

            expanders++;
            expander.ContentLabel = name;
            expander.SetWidget(widget);
            expander.BorderWidth = 4;
            expander.Closed     += delegate(object sender, EventArgs e)
            {
                var expanderWidget = (ClosableExpander)sender;
                if (!RequestClose(expanderWidget))
                {
                    return;
                }
                expanders--;
                obj.Remove();
                if (expanderWidget.Parent == contentBox)
                {
                    contentBox.Remove(expanderWidget);
                }
                expanderWidget.Destroy();
                if (expanders == 0)
                {
                    Clear();
                }
            };
            contentBox.PackStart(expander, true, true, 0);
            contentBox.Show();
            expander.Expanded = false;
            return(expander);
        }
예제 #10
0
        public CustomPropertiesWidget(PListScheme scheme)
        {
            Scheme      = scheme ?? PListScheme.Empty;
            CurrentTree = new Dictionary <PObject, PListScheme.SchemaItem> ();
            treeview    = new PopupTreeView(this)
            {
                DoubleBuffered = true
            };
            treeview.HeadersClickable = true;

            RefreshKeyStore();
            PackStart(treeview, true, true, 0);
            FindOrAddNewEntry(TreeIter.Zero);
            ShowAll();

            var keyRenderer = new CellRendererCombo();

            keyRenderer.Editable        = true;
            keyRenderer.Model           = keyStore;
            keyRenderer.Mode            = CellRendererMode.Editable;
            keyRenderer.TextColumn      = 0;
            keyRenderer.EditingStarted += KeyRendererEditingStarted;
            keyRenderer.Edited         += KeyRendererEditingFinished;
            var col = new TreeViewColumn();

            col.Resizable = true;
            col.Title     = GettextCatalog.GetString("Property");
            col.PackStart(keyRenderer, true);
            col.SetCellDataFunc(keyRenderer, delegate(TreeViewColumn tree_column, CellRenderer cell, TreeModel tree_model, TreeIter iter) {
                var renderer = (CellRendererCombo)cell;
                string id    = (string)tree_model.GetValue(iter, 0) ?? "";
                var obj      = (PObject)tree_model.GetValue(iter, 1);
                if (obj == null)
                {
                    renderer.Text      = id;
                    renderer.Editable  = false;
                    renderer.Sensitive = false;
                    return;
                }

                var key            = (PListScheme.SchemaItem)tree_model.GetValue(iter, 2);
                var parentPArray   = obj.Parent is PArray;
                renderer.Editable  = !parentPArray;
                renderer.Sensitive = !parentPArray;
                if (parentPArray)
                {
                    renderer.Text = "";
                }
                else
                {
                    renderer.Text = key != null && ShowDescriptions ? key.Description : id;
                }
            });
            treeview.AppendColumn(col);

            col = new TreeViewColumn {
                MinWidth = 25, Resizable = false, Sizing = Gtk.TreeViewColumnSizing.Fixed
            };

            var removeRenderer = new CellRendererButton(ImageService.GetPixbuf("gtk-remove", IconSize.Menu));

            removeRenderer.Clicked += RemoveElement;
            col.PackEnd(removeRenderer, false);
            col.SetCellDataFunc(removeRenderer, delegate(TreeViewColumn tree_column, CellRenderer cell, TreeModel tree_model, TreeIter iter) {
                removeRenderer.Visible = treeview.Selection.IterIsSelected(iter) && !AddKeyNode.Equals(treeStore.GetValue(iter, 0));
            });

            var addRenderer = new CellRendererButton(ImageService.GetPixbuf("gtk-add", IconSize.Menu));

            addRenderer.Clicked += AddElement;
            col.PackEnd(addRenderer, false);
            col.SetCellDataFunc(addRenderer, delegate(TreeViewColumn tree_column, CellRenderer cell, TreeModel tree_model, TreeIter iter) {
                addRenderer.Visible = treeview.Selection.IterIsSelected(iter) && AddKeyNode.Equals(treeStore.GetValue(iter, 0));
            });
            treeview.AppendColumn(col);

            treeview.RowActivated += delegate(object o, RowActivatedArgs args) {
                TreeIter iter;
                if (treeStore.GetIter(out iter, args.Path) && AddKeyNode.Equals(treeStore.GetValue(iter, 0)))
                {
                    AddElement(o, EventArgs.Empty);
                }
            };

            var comboRenderer = new CellRendererCombo();

            var typeModel = new ListStore(typeof(string));

            typeModel.AppendValues(PArray.Type);
            typeModel.AppendValues(PDictionary.Type);
            typeModel.AppendValues(PBoolean.Type);
            typeModel.AppendValues(PData.Type);
            typeModel.AppendValues(PData.Type);
            typeModel.AppendValues(PNumber.Type);
            typeModel.AppendValues(PString.Type);
            comboRenderer.Model      = typeModel;
            comboRenderer.Mode       = CellRendererMode.Editable;
            comboRenderer.HasEntry   = false;
            comboRenderer.TextColumn = 0;
            comboRenderer.Edited    += delegate(object o, EditedArgs args) {
                TreeIter selIter;
                if (!treeStore.GetIterFromString(out selIter, args.Path))
                {
                    return;
                }

                PObject oldObj = (PObject)treeStore.GetValue(selIter, 1);
                if (oldObj != null && oldObj.TypeString != args.NewText)
                {
                    oldObj.Replace(PObject.Create(args.NewText));
                }
            };

            treeview.AppendColumn(GettextCatalog.GetString("Type"), comboRenderer, delegate(TreeViewColumn tree_column, CellRenderer cell, TreeModel tree_model, TreeIter iter) {
                var renderer           = (CellRendererCombo)cell;
                var value              = (string)tree_model.GetValue(iter, 0);
                var obj                = (PObject)tree_model.GetValue(iter, 1);
                var key                = (PListScheme.SchemaItem)tree_model.GetValue(iter, 2);
                renderer.Editable      = key == null && !AddKeyNode.Equals(value);
                renderer.ForegroundGdk = Style.Text(renderer.Editable ? StateType.Normal : StateType.Insensitive);
                renderer.Text          = obj == null ? "" : obj.TypeString;
            });

            var propRenderer = new CellRendererCombo();

            propRenderer.Model           = valueStore;
            propRenderer.Mode            = CellRendererMode.Editable;
            propRenderer.TextColumn      = 0;
            propRenderer.EditingStarted += PropRendererEditingStarted;
            propRenderer.Edited         += PropRendererEditingFinished;

            treeview.AppendColumn(GettextCatalog.GetString("Value"), propRenderer, delegate(TreeViewColumn tree_column, CellRenderer cell, TreeModel tree_model, TreeIter iter) {
                var renderer = (CellRendererCombo)cell;
                var obj      = (PObject)tree_model.GetValue(iter, 1);

                renderer.Sensitive = obj != null && !(obj is PDictionary || obj is PArray || obj is PData);
                renderer.Editable  = renderer.Sensitive;
                if (!renderer.Sensitive)
                {
                    renderer.Text = "";
                    return;
                }

                if (ShowDescriptions)
                {
                    var identifier = (string)tree_model.GetValue(iter, 0);
                    var values     = PListScheme.AvailableValues(obj, CurrentTree);
                    var item       = values == null ? null : values.FirstOrDefault(v => v.Identifier == identifier);
                    if (item != null)
                    {
                        renderer.Text = item.Description ?? item.Identifier;
                        return;
                    }
                }

                switch (obj.TypeString)
                {
                case PDictionary.Type:
                    renderer.Text = string.Format(GettextCatalog.GetPluralString("({0} item)", "({0} items)", ((PDictionary)obj).Count), ((PDictionary)obj).Count);
                    break;

                case PArray.Type:
                    renderer.Text = string.Format(GettextCatalog.GetPluralString("({0} item)", "({0} items)", ((PArray)obj).Count, ((PArray)obj).Count));
                    break;

                case PBoolean.Type:
                    renderer.Text = ((PBoolean)obj).Value ? GettextCatalog.GetString("Yes") : GettextCatalog.GetString("No");
                    break;

                case PData.Type:
                    renderer.Text = string.Format("byte[{0}]", ((PData)obj).Value.Length);
                    break;

                default:
                    if (obj is IPValueObject)
                    {
                        renderer.Text = (((IPValueObject)obj).Value ?? "").ToString();
                    }
                    else
                    {
                        renderer.Sensitive = false;
                        renderer.Text      = GettextCatalog.GetString("Could not render {0}.", obj.GetType().Name);
                    }
                    break;
                }
            });
            treeview.EnableGridLines = TreeViewGridLines.Horizontal;
            treeview.Model           = treeStore;
        }
예제 #11
0
 public PObjectEventArgs(PObject pObject)
 {
     this.PObject = pObject;
 }
예제 #12
0
            public PObject Create()
            {
                if (Type == PDictionary.Type)
                {
                    var dictionary = new PDictionary();
                    foreach (var v in Values)
                    {
                        if (v.Required)
                        {
                            dictionary.Add(v.Identifier, v.Create());
                        }
                    }

                    // If nothing was required, create an initial one anyway
                    if (dictionary.Count == 0)
                    {
                        var first = Values.FirstOrDefault();
                        if (first == null)
                        {
                            dictionary.Add("newNode", PObject.Create(PString.Type));
                        }
                        else
                        {
                            dictionary.Add(first.Identifier ?? "newNode", first.Create());
                        }
                    }
                    return(dictionary);
                }
                else if (Type == PArray.Type)
                {
                    var array = new PArray();
                    foreach (var v in Values)
                    {
                        if (v.Required)
                        {
                            array.Add(v.Create());
                        }
                    }

                    // If nothing was required, create an initial one anyway
                    if (array.Count == 0)
                    {
                        var first = Values.FirstOrDefault();
                        if (first == null)
                        {
                            array.Add(PObject.Create(ArrayType));
                        }
                        else
                        {
                            array.Add(first.Create());
                        }
                    }
                    return(array);
                }
                else if (Values.Any())
                {
                    return(Values.First().Create());
                }
                else
                {
                    var obj = PObject.Create(Type);
                    if (!string.IsNullOrEmpty(Identifier) && !(this is Key))
                    {
                        obj.SetValue(Identifier);
                    }
                    return(obj);
                }
            }
예제 #13
0
        public StringListWidget()
        {
            treeview = new Gtk.TreeView();
            treeview.HeadersVisible = false;
            PackStart(treeview, true, true, 0);
            ShowAll();

            var col = new TreeViewColumn {
                MinWidth = CellRendererAddRemove.MinWidth, Resizable = true, Sizing = Gtk.TreeViewColumnSizing.Autosize
            };
            var addRemoveRenderer = new CellRendererAddRemove();

            col.PackStart(addRemoveRenderer, false);
            col.SetCellDataFunc(addRemoveRenderer, delegate(TreeViewColumn tree_column, CellRenderer cell, TreeModel tree_model, TreeIter iter) {
                if (treeStore.GetValue(iter, (int)ListColumn.Object) != null)
                {
                    addRemoveRenderer.Action = CellRendererAddRemove.AddRemoveAction.Remove;
                }
                else
                {
                    addRemoveRenderer.Action = CellRendererAddRemove.AddRemoveAction.Add;
                }
            });
            addRemoveRenderer.RemoveClicked += delegate {
                TreeIter iter;
                bool     hasSelection = treeview.Selection.GetSelected(out iter);
                PObject  obj          = null;
                if (hasSelection)
                {
                    obj = (PObject)treeStore.GetValue(iter, (int)ListColumn.Object);
                    treeStore.Remove(ref iter);

                    editing = true;
                    obj.Remove();
                    editing = false;
                }
            };
            addRemoveRenderer.AddClicked += delegate {
                PObject  obj = new PString(string.Empty);
                TreeIter iter;

                bool hasSelection = treeview.Selection.GetSelected(out iter);
                if (hasSelection)
                {
                    treeStore.SetValues(iter, string.Empty, obj);
                    AppendCreateNewEntry();

                    editing = true;
                    array.Add(obj);
                    editing = false;
                }
            };
            treeview.AppendColumn(col);

            var valueRenderer = new CellRendererCombo();

            valueRenderer.Mode       = CellRendererMode.Editable;
            valueRenderer.TextColumn = (int)ListColumn.DisplayValue;

            valueRenderer.Edited += delegate(object o, EditedArgs args) {
                TreeIter iter;

                if (!treeStore.GetIterFromString(out iter, args.Path))
                {
                    return;
                }

                var pObject = (PObject)treeStore.GetValue(iter, (int)ListColumn.Object);
                if (pObject == null)
                {
                    return;
                }

                string newValue = !string.IsNullOrEmpty(ValuePrefix) ? ValuePrefix + args.NewText : args.NewText;

                pObject.SetValue(newValue);
            };

            treeview.AppendColumn(GettextCatalog.GetString("Value"), valueRenderer, delegate(TreeViewColumn tree_column, CellRenderer cell, TreeModel tree_model, TreeIter iter) {
                var text     = (string)tree_model.GetValue(iter, (int)ListColumn.DisplayValue);
                var obj      = (PObject)tree_model.GetValue(iter, (int)ListColumn.Object);
                var renderer = (CellRendererCombo)cell;

                renderer.Sensitive = obj != null;
                renderer.Editable  = obj != null;
                renderer.Text      = text;
            });

            treeview.EnableGridLines = TreeViewGridLines.Horizontal;
            treeview.Model           = treeStore;
        }
예제 #14
0
        public CustomPropertiesWidget(PListScheme scheme)
        {
            this.scheme = scheme = scheme ?? PListScheme.Empty;
            treeview    = new PopupTreeView(this);
            treeview.HeadersClickable = true;
            this.PackStart(treeview, true, true, 0);
            ShowAll();

            var keyRenderer = new CellRendererCombo();

            keyRenderer.Editable   = true;
            keyRenderer.Model      = keyStore;
            keyRenderer.Mode       = CellRendererMode.Editable;
            keyRenderer.TextColumn = 0;
            keyRenderer.Edited    += delegate(object o, EditedArgs args) {
                TreeIter selIter;
                if (!treeStore.GetIterFromString(out selIter, args.Path))
                {
                    return;
                }
                if (args.NewText == (string)treeStore.GetValue(selIter, 0))
                {
                    return;
                }

                var obj = (PObject)treeStore.GetValue(selIter, 1);

                var dict = obj.Parent as PDictionary;
                if (dict == null)
                {
                    return;
                }

                var key    = scheme.Keys.FirstOrDefault(k => k.Identifier == args.NewText || k.Description == args.NewText);
                var newKey = key != null ? key.Identifier : args.NewText;

                dict.ChangeKey(obj, newKey, key == null || obj.TypeString == key.Type ? null : CreateNewObject(key.Type));
            };
            var col = new TreeViewColumn();

            col.Resizable = true;
            col.Title     = GettextCatalog.GetString("Property");
            col.PackStart(keyRenderer, true);
            col.SetCellDataFunc(keyRenderer, delegate(TreeViewColumn tree_column, CellRenderer cell, TreeModel tree_model, TreeIter iter) {
                var renderer = (CellRendererCombo)cell;
                string id    = (string)tree_model.GetValue(iter, 0) ?? "";
                var obj      = (PObject)tree_model.GetValue(iter, 1);
                if (obj == null)
                {
                    renderer.Text      = id;
                    renderer.Editable  = false;
                    renderer.Sensitive = false;
                    return;
                }

                var key            = scheme.GetKey(id);
                renderer.Editable  = !(obj.Parent is PArray);
                renderer.Sensitive = true;
                renderer.Text      = key != null && ShowDescriptions ? GettextCatalog.GetString(key.Description) : id;
            });
            treeview.AppendColumn(col);

            var iconSize = IconSize.Menu;

            col = new TreeViewColumn {
                MinWidth = 25, Resizable = true, Sizing = Gtk.TreeViewColumnSizing.Autosize
            };

            var removeRenderer = new CellRendererButton(ImageService.GetPixbuf("gtk-remove", IconSize.Menu));

            removeRenderer.Clicked += delegate {
                TreeIter iter;
                bool     hasSelection = treeview.Selection.GetSelected(out iter);
                PObject  obj          = null;
                if (hasSelection)
                {
                    obj = (PObject)treeStore.GetValue(iter, 1);
                    obj.Remove();
                }
            };
            col.PackEnd(removeRenderer, false);
            col.SetCellDataFunc(removeRenderer, delegate(TreeViewColumn tree_column, CellRenderer cell, TreeModel tree_model, TreeIter iter) {
                removeRenderer.Visible = treeview.Selection.IterIsSelected(iter) && !AddKeyNode.Equals(treeStore.GetValue(iter, 0));
            });

            var addRenderer = new CellRendererButton(ImageService.GetPixbuf("gtk-add", IconSize.Menu));

            addRenderer.Clicked += delegate {
                Gtk.TreeIter iter = Gtk.TreeIter.Zero;
                if (!treeview.Selection.GetSelected(out iter))
                {
                    return;
                }

                PObject obj = null;
                if (treeStore.IterParent(out iter, iter))
                {
                    obj = (PObject)treeStore.GetValue(iter, 1);
                }
                obj = obj ?? nsDictionary;

                var newObj = new PString("");
                if (obj is PArray)
                {
                    var arr = (PArray)obj;
                    arr.Add(newObj);
                }
                else if (obj is PDictionary)
                {
                    string name = "newNode";
                    var    dict = (PDictionary)obj;
                    while (dict.ContainsKey(name))
                    {
                        name += "_";
                    }
                    dict.Add(name, newObj);
                }
                else
                {
                    return;
                }
            };

            col.PackEnd(addRenderer, false);
            col.SetCellDataFunc(addRenderer, delegate(TreeViewColumn tree_column, CellRenderer cell, TreeModel tree_model, TreeIter iter) {
                addRenderer.Visible = treeview.Selection.IterIsSelected(iter) && AddKeyNode.Equals(treeStore.GetValue(iter, 0));
            });
            treeview.AppendColumn(col);

            treeview.RowExpanded += delegate(object o, RowExpandedArgs args) {
                var obj = (PObject)treeStore.GetValue(args.Iter, 1);
                expandedObjects.Add(obj);
            };
            treeview.RowCollapsed += delegate(object o, RowCollapsedArgs args) {
                var obj = (PObject)treeStore.GetValue(args.Iter, 1);
                expandedObjects.Remove(obj);
            };
            var comboRenderer = new CellRendererCombo();

            var typeModel = new ListStore(typeof(string));

            typeModel.AppendValues("Array");
            typeModel.AppendValues("Dictionary");
            typeModel.AppendValues("Boolean");
            typeModel.AppendValues("Data");
            typeModel.AppendValues("Date");
            typeModel.AppendValues("Number");
            typeModel.AppendValues("String");
            comboRenderer.Model      = typeModel;
            comboRenderer.Mode       = CellRendererMode.Editable;
            comboRenderer.HasEntry   = false;
            comboRenderer.TextColumn = 0;
            comboRenderer.Edited    += delegate(object o, EditedArgs args) {
                TreeIter selIter;
                if (!treeStore.GetIterFromString(out selIter, args.Path))
                {
                    return;
                }

                PObject oldObj = (PObject)treeStore.GetValue(selIter, 1);
                if (oldObj != null && oldObj.TypeString != args.NewText)
                {
                    oldObj.Replace(CreateNewObject(args.NewText));
                }
            };

            treeview.AppendColumn(GettextCatalog.GetString("Type"), comboRenderer, delegate(TreeViewColumn tree_column, CellRenderer cell, TreeModel tree_model, TreeIter iter) {
                var renderer = (CellRendererCombo)cell;
                string id    = (string)tree_model.GetValue(iter, 0) ?? "";
                var key      = scheme.GetKey(id);
                var obj      = (PObject)tree_model.GetValue(iter, 1);
                if (obj == null)
                {
                    renderer.Editable = false;
                    renderer.Text     = "";
                    return;
                }
                renderer.Editable      = key == null;
                renderer.ForegroundGdk = Style.Text(renderer.Editable ? StateType.Normal : StateType.Insensitive);
                renderer.Text          = obj.TypeString;
            });

            var propRenderer = new CellRendererCombo();

            propRenderer.Model           = valueStore;
            propRenderer.Mode            = CellRendererMode.Editable;
            propRenderer.TextColumn      = 0;
            propRenderer.EditingStarted += delegate(object o, EditingStartedArgs args) {
                valueStore.Clear();
                if (Scheme == null)
                {
                    return;
                }
                TreeIter iter;
                if (!treeStore.GetIterFromString(out iter, args.Path))
                {
                    return;
                }
                var pObject = (PObject)treeStore.GetValue(iter, 1);
                if (pObject == null)
                {
                    return;
                }
                var key = Parent != null?Scheme.GetKey(pObject.Parent.Key) : null;

                if (key != null)
                {
                    var descr = new List <string> (key.Values.Select(v => v.Description));
                    descr.Sort();
                    foreach (var val in descr)
                    {
                        valueStore.AppendValues(val);
                    }
                }
            };

            propRenderer.Edited += delegate(object o, EditedArgs args) {
                TreeIter iter;
                if (!treeStore.GetIterFromString(out iter, args.Path))
                {
                    return;
                }
                var pObject = (PObject)treeStore.GetValue(iter, 1);
                if (pObject == null)
                {
                    return;
                }
                string newText = args.NewText;
                var    key     = Parent != null?Scheme.GetKey(pObject.Parent.Key) : null;

                if (key != null)
                {
                    foreach (var val in key.Values)
                    {
                        if (newText == val.Description)
                        {
                            newText = val.Identifier;
                            break;
                        }
                    }
                }
                pObject.SetValue(newText);
            };

            /*		propRenderer.EditingStarted += delegate(object o, EditingStartedArgs args) {
             *                      TreeIter iter;
             *                      if (!treeStore.GetIterFromString (out iter, args.Path))
             *                              return;
             *                      PObject obj = (PObject)treeStore.GetValue (iter, 1);
             *                      if (obj is PBoolean) {
             *                              ((PBoolean)obj).Value = !((PBoolean)obj).Value;
             *                              propRenderer.StopEditing (false);
             *                      }
             *              };*/


            treeview.AppendColumn(GettextCatalog.GetString("Value"), propRenderer, delegate(TreeViewColumn tree_column, CellRenderer cell, TreeModel tree_model, TreeIter iter) {
                var renderer = (CellRendererCombo)cell;
                var obj      = (PObject)tree_model.GetValue(iter, 1);
                if (obj == null)
                {
                    renderer.Editable = false;
                    renderer.Text     = "";
                    return;
                }
                renderer.Editable = !(obj is PArray || obj is PDictionary || obj is PData);
                obj.RenderValue(this, renderer);
            });
            treeview.EnableGridLines = TreeViewGridLines.Horizontal;
            treeview.Model           = treeStore;
        }
예제 #15
0
            void ShowPopup(Gdk.EventButton evnt)
            {
                Gtk.TreeIter iter;
                bool         hasSelection = Selection.GetSelected(out iter);
                PObject      obj          = null;

                if (hasSelection)
                {
                    obj = (PObject)widget.treeStore.GetValue(iter, 1);
                }
                else
                {
                    return;
                }

                var menu   = new Gtk.Menu();
                var newKey = new Gtk.MenuItem(GettextCatalog.GetString("New key"));

                menu.Append(newKey);

                newKey.Activated += delegate(object sender, EventArgs e) {
                    var newObj = new PString("");

                    PObject parent;
                    if (obj != null)
                    {
                        parent = obj.Parent;
                    }
                    else
                    {
                        Gtk.TreeIter parentIter;
                        if (widget.treeStore.IterParent(out parentIter, iter))
                        {
                            parent = (PObject)widget.treeStore.GetValue(parentIter, 1);
                        }
                        else
                        {
                            parent = widget.nsDictionary;
                        }
                    }

                    if (parent is PArray)
                    {
                        var arr = (PArray)parent;
                        arr.Add(newObj);
                        return;
                    }

                    var dict = parent as PDictionary;
                    if (dict == null)
                    {
                        return;
                    }

                    string name = "newNode";
                    while (dict.ContainsKey(name))
                    {
                        name += "_";
                    }
                    dict[name] = newObj;
                };

                if (hasSelection && obj != null)
                {
                    var removeKey = new Gtk.MenuItem(GettextCatalog.GetString("Remove key"));
                    menu.Append(removeKey);
                    removeKey.Activated += delegate(object sender, EventArgs e) {
                        //the change event handler removes it from the store
                        obj.Remove();
                    };
                }

                if (widget.scheme != null)
                {
                    menu.Append(new Gtk.SeparatorMenuItem());
                    var showDescItem = new Gtk.CheckMenuItem(GettextCatalog.GetString("Show descriptions"));
                    showDescItem.Active     = widget.ShowDescriptions;
                    showDescItem.Activated += delegate {
                        widget.ShowDescriptions = !widget.ShowDescriptions;
                    };
                    menu.Append(showDescItem);
                }
                menu.ShowAll();
                IdeApp.CommandService.ShowContextMenu(this, evnt, menu, this);
            }