internal FormTouch(TouchElementViewModel touch) { disposable = new CompositeDisposable(); CompositeDisposable listItemDisposable = new CompositeDisposable().AddTo(disposable); CompositeDisposable entryDisposable = new CompositeDisposable().AddTo(disposable); this.touch = touch; InitializeComponent(); touch.TreeItem .BindTo( this, x => x.TreeViewTouchTopNode, BindingMode.OneWay, FormEditor.TreeViewItemViewModelToTreeNode ) .AddTo(disposable); touch.SelectedTreeItem .BindTo( treeViewTouch, x => x.SelectedNode, BindingMode.TwoWay, x => treeViewTouch.Nodes.OfType <TreeNode>().Select(y => FormEditor.SearchTreeNode(x, y)).FirstOrDefault(y => y != null), x => (TreeViewItemViewModel)x.Tag, Observable.FromEvent <TreeViewEventHandler, TreeViewEventArgs>( h => (s, e) => h(e), h => treeViewTouch.AfterSelect += h, h => treeViewTouch.AfterSelect -= h ) .ToUnit() ) .AddTo(disposable); touch.SelectedTreeItem .BindTo( listViewTouch, x => x.Enabled, BindingMode.OneWay, x => touch.TreeItem.Value.Children.Contains(x) ) .AddTo(disposable); touch.ListColumns .ObserveAddChanged() .Subscribe(x => { listViewTouch.Columns.Add(FormEditor.ListViewColumnHeaderViewModelToColumnHeader(x)); listViewTouch.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); }) .AddTo(disposable); touch.ListColumns .ObserveRemoveChanged() .Subscribe(y => { foreach (ColumnHeader column in listViewTouch.Columns.OfType <ColumnHeader>().Where(z => z.Tag == y).ToArray()) { listViewTouch.Columns.Remove(column); } listViewTouch.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); }) .AddTo(disposable); touch.ListColumns .ObserveResetChanged() .Subscribe(_ => { listViewTouch.Columns.Clear(); listViewTouch.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); }) .AddTo(disposable); touch.ListItems .ObserveAddChanged() .Subscribe(x => { listViewTouch.Items.Add(FormEditor.ListViewItemViewModelToListViewItem(x)); listViewTouch.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); }) .AddTo(disposable); touch.ListItems .ObserveRemoveChanged() .Subscribe(x => { foreach (ListViewItem item in listViewTouch.Items.OfType <ListViewItem>().Where(y => y.Tag == x).ToArray()) { listViewTouch.Items.Remove(item); } listViewTouch.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); }) .AddTo(disposable); touch.ListItems .ObserveResetChanged() .Subscribe(_ => { listViewTouch.Items.Clear(); listViewTouch.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); }) .AddTo(disposable); touch.SelectedListItem .BindTo( this, x => x.ListViewTouchSelectedItem, BindingMode.TwoWay, x => listViewTouch.Items.OfType <ListViewItem>().FirstOrDefault(y => y.Tag == x), x => (ListViewItemViewModel)x?.Tag, Observable.FromEvent <EventHandler, EventArgs>( h => (s, e) => h(e), h => listViewTouch.SelectedIndexChanged += h, h => listViewTouch.SelectedIndexChanged -= h ) .ToUnit() ) .AddTo(disposable); touch.SelectedListItem .Where(x => x != null) .Subscribe(x => { listItemDisposable.Dispose(); listItemDisposable = new CompositeDisposable().AddTo(disposable); x.Texts .ObserveReplaceChanged() .Subscribe(_ => { FormEditor.UpdateListViewItem(ListViewTouchSelectedItem, touch.SelectedListItem.Value); listViewTouch.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); }) .AddTo(listItemDisposable); }) .AddTo(disposable); touch.SelectedSoundEntry .BindTo( groupBoxTouchSound, x => x.Enabled, x => x != null ) .AddTo(disposable); touch.SelectedSoundEntry .Where(x => x != null) .Subscribe(x => { entryDisposable.Dispose(); entryDisposable = new CompositeDisposable().AddTo(disposable); BindToSoundEntry(x).AddTo(entryDisposable); }) .AddTo(disposable); touch.SelectedCommandEntry .BindTo( groupBoxTouchCommand, x => x.Enabled, x => x != null ) .AddTo(disposable); touch.SelectedCommandEntry .Where(x => x != null) .Subscribe(x => { entryDisposable.Dispose(); entryDisposable = new CompositeDisposable().AddTo(disposable); BindToCommandEntry(x).AddTo(entryDisposable); }) .AddTo(disposable); comboBoxTouchCommandName.Items .AddRange( Enum.GetValues(typeof(Translations.Command)) .OfType <Translations.Command>() .Select(c => Translations.CommandInfos.TryGetInfo(c).Name) .OfType <object>() .ToArray() ); new[] { touch.AddSoundEntry, touch.AddCommandEntry } .BindToButton(buttonTouchAdd) .AddTo(disposable); new[] { touch.CopySoundEntry, touch.CopyCommandEntry } .BindToButton(buttonTouchCopy) .AddTo(disposable); new[] { touch.RemoveSoundEntry, touch.RemoveCommandEntry } .BindToButton(buttonTouchRemove) .AddTo(disposable); }
private IDisposable BindToTouch(TouchElementViewModel y) { CompositeDisposable touchDisposable = new CompositeDisposable(); y.LocationX .BindTo( textBoxTouchLocationX, z => z.Text, BindingMode.TwoWay, null, null, Observable.FromEvent <EventHandler, EventArgs>( h => (s, e) => h(e), h => textBoxTouchLocationX.TextChanged += h, h => textBoxTouchLocationX.TextChanged -= h ) .ToUnit() ) .AddTo(touchDisposable); y.LocationX .BindToErrorProvider(errorProvider, textBoxTouchLocationX) .AddTo(touchDisposable); y.LocationY .BindTo( textBoxTouchLocationY, z => z.Text, BindingMode.TwoWay, null, null, Observable.FromEvent <EventHandler, EventArgs>( h => (s, e) => h(e), h => textBoxTouchLocationY.TextChanged += h, h => textBoxTouchLocationY.TextChanged -= h ) .ToUnit() ) .AddTo(touchDisposable); y.LocationY .BindToErrorProvider(errorProvider, textBoxTouchLocationY) .AddTo(touchDisposable); y.Layer .BindTo( numericUpDownTouchLayer, z => z.Value, BindingMode.TwoWay, null, z => (int)z, Observable.FromEvent <EventHandler, EventArgs>( h => (s, e) => h(e), h => numericUpDownTouchLayer.ValueChanged += h, h => numericUpDownTouchLayer.ValueChanged -= h ) .ToUnit() ) .AddTo(touchDisposable); y.SizeX .BindTo( textBoxTouchSizeX, z => z.Text, BindingMode.TwoWay, null, null, Observable.FromEvent <EventHandler, EventArgs>( h => (s, e) => h(e), h => textBoxTouchSizeX.TextChanged += h, h => textBoxTouchSizeX.TextChanged -= h ) .ToUnit() ) .AddTo(touchDisposable); y.SizeX .BindToErrorProvider(errorProvider, textBoxTouchSizeX) .AddTo(touchDisposable); y.SizeY .BindTo( textBoxTouchSizeY, z => z.Text, BindingMode.TwoWay, null, null, Observable.FromEvent <EventHandler, EventArgs>( h => (s, e) => h(e), h => textBoxTouchSizeY.TextChanged += h, h => textBoxTouchSizeY.TextChanged -= h ) .ToUnit() ) .AddTo(touchDisposable); y.SizeY .BindToErrorProvider(errorProvider, textBoxTouchSizeY) .AddTo(touchDisposable); y.JumpScreen .BindTo( numericUpDownTouchJumpScreen, z => z.Value, BindingMode.TwoWay, null, z => (int)z, Observable.FromEvent <EventHandler, EventArgs>( h => (s, e) => h(e), h => numericUpDownTouchJumpScreen.ValueChanged += h, h => numericUpDownTouchJumpScreen.ValueChanged -= h ) .ToUnit() ) .AddTo(touchDisposable); return(touchDisposable); }
private IDisposable BindToTouch(TouchElementViewModel y) { CompositeDisposable touchDisposable = new CompositeDisposable(); y.LocationX .BindTo( textBoxTouchLocationX, z => z.Text, BindingMode.TwoWay, null, null, Observable.FromEvent <EventHandler, EventArgs>( h => (s, e) => h(e), h => textBoxTouchLocationX.TextChanged += h, h => textBoxTouchLocationX.TextChanged -= h ) .ToUnit() ) .AddTo(touchDisposable); y.LocationX .BindToErrorProvider(errorProvider, textBoxTouchLocationX) .AddTo(touchDisposable); y.LocationY .BindTo( textBoxTouchLocationY, z => z.Text, BindingMode.TwoWay, null, null, Observable.FromEvent <EventHandler, EventArgs>( h => (s, e) => h(e), h => textBoxTouchLocationY.TextChanged += h, h => textBoxTouchLocationY.TextChanged -= h ) .ToUnit() ) .AddTo(touchDisposable); y.LocationY .BindToErrorProvider(errorProvider, textBoxTouchLocationY) .AddTo(touchDisposable); y.SizeX .BindTo( textBoxTouchSizeX, z => z.Text, BindingMode.TwoWay, null, null, Observable.FromEvent <EventHandler, EventArgs>( h => (s, e) => h(e), h => textBoxTouchSizeX.TextChanged += h, h => textBoxTouchSizeX.TextChanged -= h ) .ToUnit() ) .AddTo(touchDisposable); y.SizeX .BindToErrorProvider(errorProvider, textBoxTouchSizeX) .AddTo(touchDisposable); y.SizeY .BindTo( textBoxTouchSizeY, z => z.Text, BindingMode.TwoWay, null, null, Observable.FromEvent <EventHandler, EventArgs>( h => (s, e) => h(e), h => textBoxTouchSizeY.TextChanged += h, h => textBoxTouchSizeY.TextChanged -= h ) .ToUnit() ) .AddTo(touchDisposable); y.SizeY .BindToErrorProvider(errorProvider, textBoxTouchSizeY) .AddTo(touchDisposable); y.JumpScreen .BindTo( numericUpDownTouchJumpScreen, z => z.Value, BindingMode.TwoWay, null, z => (int)z, Observable.FromEvent <EventHandler, EventArgs>( h => (s, e) => h(e), h => numericUpDownTouchJumpScreen.ValueChanged += h, h => numericUpDownTouchJumpScreen.ValueChanged -= h ) .ToUnit() ) .AddTo(touchDisposable); y.SoundIndex .BindTo( numericUpDownTouchSoundIndex, z => z.Value, BindingMode.TwoWay, null, z => (int)z, Observable.FromEvent <EventHandler, EventArgs>( h => (s, e) => h(e), h => numericUpDownTouchSoundIndex.ValueChanged += h, h => numericUpDownTouchSoundIndex.ValueChanged -= h ) .ToUnit() ) .AddTo(touchDisposable); y.CommandInfo .BindTo( comboBoxTouchCommand, z => z.SelectedIndex, BindingMode.TwoWay, z => (int)z.Command, z => Translations.CommandInfos.TryGetInfo((Translations.Command)z), Observable.FromEvent <EventHandler, EventArgs>( h => (s, e) => h(e), h => comboBoxTouchCommand.SelectedIndexChanged += h, h => comboBoxTouchCommand.SelectedIndexChanged -= h ) .ToUnit() ) .AddTo(touchDisposable); y.CommandOption .BindTo( numericUpDownTouchCommandOption, z => z.Value, BindingMode.TwoWay, null, z => (int)z, Observable.FromEvent <EventHandler, EventArgs>( h => (s, e) => h(e), h => numericUpDownTouchCommandOption.ValueChanged += h, h => numericUpDownTouchCommandOption.ValueChanged -= h ) .ToUnit() ) .AddTo(touchDisposable); return(touchDisposable); }