示例#1
0
    protected void OnPayloadChanged(object o, EventArgs e)
    {
        ComboBox combo = (ComboBox)o;
        TreeIter iter;

        Dictionary <string, object> opts = null;

        if (combo.GetActiveIter(out iter))
        {
            opts = _manager.GetModuleOptions("payload", ((ComboBox)o).Model.GetValue(iter, 0).ToString());
        }

        VBox payloadDetails = RedrawOptions(opts, false);

        HBox   addBox     = new HBox();
        Button addPayload = new Button("Add payload");

        addPayload.Clicked += (object sender, EventArgs es) => {
            TreeIter i;
            ((ComboBox)o).GetActiveIter(out i);

            if (_newPayloads.ContainsKey(((ComboBox)o).Model.GetValue(i, 0).ToString()))
            {
                MessageDialog md = new MessageDialog(this,
                                                     DialogFlags.DestroyWithParent,
                                                     MessageType.Warning,
                                                     ButtonsType.Close, "Currently support only one of each type of payload.\n\nMultiple payloads of the same type will be supported in the future.");

                md.Run();
                md.Destroy();
                return;
            }

            int n = _treeViews [_parentNotebook.CurrentPage].Model.IterNChildren();
            Dictionary <string, object> newopts = new Dictionary <string, object> ();
            foreach (Widget child in _dynamicOptions[_parentNotebook.CurrentPage].Children)
            {
                if (child is CheckButton)
                {
                    newopts.Add((child as CheckButton).Label, (child as CheckButton).Active.ToString());
                }
                else if (child is HBox)
                {
                    foreach (Widget c in (child as HBox).Children)
                    {
                        if (c is Entry)
                        {
                            newopts.Add((c as Entry).TooltipText, (c as Entry).Text);
                        }
                    }
                }
            }

            _newPayloads.Add(((ComboBox)o).Model.GetValue(i, 0).ToString(), newopts);

            ((ListStore)_treeViews [_parentNotebook.CurrentPage].Model).AppendValues((n + 1).ToString(), ((ComboBox)o).Model.GetValue(i, 0).ToString());

            CellRendererText tx = new CellRendererText();
            _treeViews [_parentNotebook.CurrentPage].Columns [1].PackStart(tx, true);
            _treeViews [_parentNotebook.CurrentPage].ShowAll();
        };

        addBox.PackStart(addPayload, false, false, 0);
        payloadDetails.PackStart(addBox, false, false, 0);
        payloadDetails.ShowAll();
    }