private void addDevice(Device rawDevice) { _tsiFile.AddDevice(rawDevice); var dvm = new DeviceViewModel(rawDevice, this); Devices.Add(dvm); }
private void insertDevice(int index, Device rawDevice) { _tsiFile.InsertDevice(index, rawDevice); var dvm = new DeviceViewModel(rawDevice, this); Devices.Insert(index, dvm); }
private TsiFileViewModel(TsiFile tsiFile) { _tsiFile = tsiFile; // Is new file? if (tsiFile.Path == null) { IsChanged = true; } else { foreach (var device in _tsiFile.Devices) { var dvm = new DeviceViewModel(device, this); Devices.Add(dvm); dvm.DirtyStateChanged += (s, a) => onDeviceChanged(); } // Set selection if possible SelectedDevice = Devices.FirstOrDefault(); AcceptChanges(); } Devices.CollectionChanged += Devices_CollectionChanged; }
private void removeDevice(DeviceViewModel device) { int id = device.Id; Devices.Remove(device); _tsiFile.RemoveDevice(id); }
private void drop(IDataObject dataObject) { if (dataObject == null) { return; } var data = dataObject.GetData(typeof(DraggableRowsBehavior.Data)) as DraggableRowsBehavior.Data; if (data == null) { return; } if (data.TargetIndex < 0 && Devices.Any()) // // don't allow invalid targets, but allow drop on an empty grid { return; } TsiFileViewModel srcFile = data.SenderDataContext as TsiFileViewModel; if (srcFile == null) { return; } DeviceViewModel selected = data.SelectedItems[0] as DeviceViewModel; int newIndex = Math.Max(0, data.TargetIndex); if (srcFile != this || !data.IsMove) { if (data.IsMove) { srcFile.removeDevice(selected); } var rawDevice = selected.Copy(true); insertDevice(newIndex++, rawDevice); } else { var movingAction = new Action <int, int>((oi, ni) => { _tsiFile.MoveDevice(oi, ni); _devices.Move(oi, ni); }); MovingLogicHelper.Move <DeviceViewModel>(_devices, new List <DeviceViewModel> { selected }, newIndex, movingAction); } SelectedDevice = selected; }
private void removeDevice(DeviceViewModel device, bool is_optimizing_tsi = false) { int id = device.Id; if (!is_optimizing_tsi && CmdrSettings.Instance.ConfirmDeleteDevices) { MessageBoxResult messageBoxResult = MessageBox.Show("Are you sure to delete this device?", "Delete Confirmation", MessageBoxButton.YesNo); if (messageBoxResult == MessageBoxResult.No) { return; } } ; Devices.Remove(device); _tsiFile.RemoveDevice(id); }
public MappingEditorViewModel(DeviceViewModel device, IEnumerable <MappingViewModel> mappings) { _device = device; _mappings = mappings ?? new List <MappingViewModel>(); _commentEditor = new CommentEditorViewModel(_mappings); _conditionsEditor = new ConditionsEditorViewModel(_mappings); _conditionsEditor.PropertyChanged += onConditionsChanged; _commandEditor = CommandEditorViewModel.BuildEditor(_mappings); _isCommandEnabled = _commandEditor != null; if (_isCommandEnabled) { _commandEditor.PropertyChanged += onCommandChanged; } _midiBindingEditor = MidiBindingEditorViewModel.BuildEditor(_device, _mappings); _isBindingEnabled = _midiBindingEditor != null; buildAdvancedOptionsMenu(); }
private void drop(IDataObject dataObject) { if (dataObject == null) { return; } var data = dataObject.GetData(typeof(DraggableRowsBehavior.Data)) as DraggableRowsBehavior.Data; if (data == null) { return; } if (data.TargetIndex < 0 && Mappings.Any()) // // don't allow invalid targets, but allow drop on an empty grid { return; } DeviceViewModel srcDevice = data.SenderDataContext as DeviceViewModel; if (srcDevice == null) { return; } // copy and sort selected items List <RowItemViewModel> selected = new List <RowItemViewModel>( data.SelectedItems .Cast <RowItemViewModel>() .OrderBy(s => srcDevice._mappings.IndexOf(s)) ); int newIndex = Math.Max(0, data.TargetIndex); if (srcDevice != this || !data.IsMove) { if (data.IsMove) { srcDevice.removeMappings(selected); } SelectedMappings.Clear(); foreach (var row in selected) { var rawMapping = (row.Item as MappingViewModel).Copy(true); insertMapping(newIndex++, rawMapping); } } else { var movingAction = new Action <int, int>((oi, ni) => { _device.MoveMapping(oi, ni); _mappings.Move(oi, ni); }); MovingLogicHelper.Move <RowItemViewModel>(_mappings, selected, newIndex, movingAction); } if (selected.Any()) { selected.Last().BringIntoView(); } }
public SearchViewModel(DeviceViewModel dvm) { _dvm = dvm; }
public FilterCmdViewModel(DeviceViewModel dvm) { _dvm = dvm; }