Beispiel #1
0
 public MimeMapListViewItem(MimeMapItem item, MimeMapPage page)
     : base(item.FileExtension)
 {
     this.Item = item;
     _page     = page;
     this.SubItems.Add(new ListViewSubItem(this, item.MimeType));
     this.SubItems.Add(new ListViewSubItem(this, item.Flag));
 }
        public NewMapItemDialog(IServiceProvider serviceProvider, MimeMapItem existing, MimeMapFeature feature)
            : base(serviceProvider)
        {
            InitializeComponent();
            Text = string.Format("{0} MIME Type", existing == null ? "Add" : "Edit");
            Item = existing ?? new MimeMapItem(null);
            if (existing != null)
            {
                txtExtension.Text = Item.FileExtension;
                txtType.Text      = Item.MimeType;
            }

            var container = new CompositeDisposable();

            FormClosed += (sender, args) => container.Dispose();

            container.Add(
                Observable.FromEventPattern <EventArgs>(btnOK, "Click")
                .ObserveOn(System.Threading.SynchronizationContext.Current)
                .Subscribe(evt =>
            {
                Item.FileExtension = txtExtension.Text;
                Item.MimeType      = txtType.Text;
                if (feature.Items.Any(item => item.Match(Item)))
                {
                    ShowMessage(
                        "This MIME map already exists.",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error,
                        MessageBoxDefaultButton.Button1);
                    return;
                }

                DialogResult = DialogResult.OK;
            }));

            container.Add(
                Observable.FromEventPattern <EventArgs>(txtExtension, "TextChanged")
                .Merge(Observable.FromEventPattern <EventArgs>(txtType, "TextChanged"))
                .Sample(TimeSpan.FromSeconds(1))
                .ObserveOn(System.Threading.SynchronizationContext.Current)
                .Subscribe(evt =>
            {
                btnOK.Enabled = !string.IsNullOrWhiteSpace(txtExtension.Text) &&
                                !string.IsNullOrWhiteSpace(txtType.Text);
            }));

            container.Add(
                Observable.FromEventPattern <CancelEventArgs>(this, "HelpButtonClicked")
                .ObserveOn(System.Threading.SynchronizationContext.Current)
                .Subscribe(EnvironmentVariableTarget =>
            {
                feature.ShowHelp();
            }));
        }