public FieldSlot AddField(Box parent, Widget label, Widget field, string syncTooltip, FieldLabelClosure labelClosure,
                                  FieldValueClosure readClosure, FieldValueClosure writeClosure, FieldValueClosure syncClosure, FieldOptions options)
        {
            var editor_field = field as IEditorField;

            if (editor_field != null && dialog.Mode == EditorMode.View)
            {
                editor_field.SetAsReadOnly();
            }

            FieldSlot slot = new FieldSlot();

            slot.Parent       = parent;
            slot.Label        = label;
            slot.Field        = field;
            slot.LabelClosure = labelClosure;
            slot.ReadClosure  = readClosure;
            slot.WriteClosure = writeClosure;
            slot.SyncClosure  = syncClosure;

            if (MultipleTracks && (options & FieldOptions.NoSync) == 0)
            {
                slot.Sync = delegate {
                    dialog.ForeachNonCurrentTrack(delegate(EditorTrackInfo track) {
                        (slot.SyncClosure ?? slot.WriteClosure)(track, slot.Field);
                    });
                };
            }

            if (MultipleTracks && (options & FieldOptions.NoSync) == 0 && (options & FieldOptions.NoShowSync) == 0)
            {
                slot.SyncButton = new SyncButton();
                if (syncTooltip != null)
                {
                    TooltipSetter.Set(tooltip_host, slot.SyncButton, syncTooltip);
                }

                slot.SyncButton.Clicked += delegate { slot.Sync(); };
            }

            Table table = new Table(1, 1, false);

            table.ColumnSpacing = 1;

            table.Attach(field, 0, 1, 1, 2,
                         AttachOptions.Expand | AttachOptions.Fill,
                         AttachOptions.Fill, 0, 0);

            if (editor_field != null)
            {
                editor_field.Changed += delegate {
                    if (CurrentTrack != null)
                    {
                        slot.WriteClosure(CurrentTrack, slot.Field);
                    }
                };
            }

            if (slot.SyncButton != null)
            {
                table.Attach(slot.SyncButton, 1, 2, 1, 2,
                             AttachOptions.Fill,
                             AttachOptions.Fill, 0, 0);
            }

            if (label != null)
            {
                if (label is Label)
                {
                    ((Label)label).MnemonicWidget = field;
                }
                table.Attach(label, 0, table.NColumns, 0, 1,
                             AttachOptions.Fill | AttachOptions.Expand,
                             AttachOptions.Fill, 0, 0);
            }

            table.ShowAll();

            if ((options & FieldOptions.Shrink) == 0)
            {
                slot.Container = table;
                parent.PackStart(table, false, false, 0);
            }
            else
            {
                HBox shrink = new HBox();
                shrink.Show();
                slot.Container = shrink;
                shrink.PackStart(table, false, false, 0);
                parent.PackStart(shrink, false, false, 0);
            }

            field_slots.Add(slot);
            return(slot);
        }
Esempio n. 2
0
        public FieldSlot AddField (Box parent, Widget label, Widget field, string syncTooltip, FieldLabelClosure labelClosure,
            FieldValueClosure readClosure, FieldValueClosure writeClosure, FieldValueClosure syncClosure, FieldOptions options)
        {
            var editor_field = field as IEditorField;

            if (editor_field != null && dialog.Mode == EditorMode.View) {
                editor_field.SetAsReadOnly ();
            }

            FieldSlot slot = new FieldSlot ();

            slot.Parent = parent;
            slot.Label = label;
            slot.Field = field;
            slot.LabelClosure = labelClosure;
            slot.ReadClosure = readClosure;
            slot.WriteClosure = writeClosure;
            slot.SyncClosure = syncClosure;

            if (MultipleTracks && (options & FieldOptions.NoSync) == 0) {
                slot.Sync = delegate {
                    dialog.ForeachNonCurrentTrack (delegate (EditorTrackInfo track) {
                        (slot.SyncClosure ?? slot.WriteClosure) (track, slot.Field);
                    });
                };
            }

            if (MultipleTracks && (options & FieldOptions.NoSync) == 0 && (options & FieldOptions.NoShowSync) == 0) {
                slot.SyncButton = new SyncButton ();
                if (syncTooltip != null) {
                    TooltipSetter.Set (tooltip_host, slot.SyncButton, syncTooltip);
                }

                slot.SyncButton.Clicked += delegate { slot.Sync (); };
            }

            Table table = new Table (1, 1, false);
            table.ColumnSpacing = 1;

            table.Attach (field, 0, 1, 1, 2,
                AttachOptions.Expand | AttachOptions.Fill,
                AttachOptions.Fill, 0, 0);

            if (editor_field != null) {
                editor_field.Changed += delegate {
                    if (CurrentTrack != null) {
                        slot.WriteClosure (CurrentTrack, slot.Field);
                    }
                };
            }

            if (slot.SyncButton != null) {
                table.Attach (slot.SyncButton, 1, 2, 1, 2,
                    AttachOptions.Fill,
                    AttachOptions.Fill, 0, 0);
            }

            if (label != null) {
                if (label is Label) {
                    ((Label)label).MnemonicWidget = field;
                }
                table.Attach (label, 0, table.NColumns, 0, 1,
                    AttachOptions.Fill | AttachOptions.Expand,
                    AttachOptions.Fill, 0, 0);
            }

            table.ShowAll ();

            if ((options & FieldOptions.Shrink) == 0) {
                slot.Container = table;
                parent.PackStart (table, false, false, 0);
            } else {
                HBox shrink = new HBox ();
                shrink.Show ();
                slot.Container = shrink;
                shrink.PackStart (table, false, false, 0);
                parent.PackStart (shrink, false, false, 0);
            }

            field_slots.Add (slot);
            return slot;
        }