private async Task openFile(string path) { var mdiChild = _mdiContainer.MdiChildren.Values.FirstOrDefault(c => c.ViewModel.Path == path); if (mdiChild == null) { TsiFileViewModel vm = await TsiFileViewModel.LoadAsync(path); if (vm != null) { _tsiFileViewModels.Add(vm); openTab(vm); _mru.Add(path); } else { MessageBoxHelper.ShowError( String.Format( "Cannot open file: {0}.\n" + "\n" + "Please confirm the file opens correctly in Traktor, and then upload the TSI to https://github.com/pestrela/cmdr/issues", path )); } } else { _mdiContainer.SelectMdiChild(mdiChild.Id); } }
void onMdiChildSelected(string id) { var mdiChild = _mdiContainer.MdiChildren[id]; SelectedTsiFileModel = mdiChild.ViewModel; refreshAppTitle(); }
private void @new() { var vm = TsiFileViewModel.Create(); _tsiFileViewModels.Add(vm); openTab(vm); }
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 async Task <bool> save(TsiFileViewModel vm) { if (vm.Path == null) { return(await saveAs(vm)); } else { return(await vm.SaveAsync(vm.Path)); } }
private void openTab(TsiFileViewModel vm) { var mdiChild = new MdiChild <TsiFileView, TsiFileViewModel>(new TsiFileView(), vm, vm.Title + (vm.IsChanged ? "*" : "")); // bind viewmodel's title to MDI child title vm.PropertyChanged += (s, e) => { if (e.PropertyName == "Title" || e.PropertyName == "IsChanged") { mdiChild.Title = vm.Title + (vm.IsChanged ? "*" : ""); } refreshAppTitle(); }; _mdiContainer.AddMdiChild(mdiChild); }
void onMdiChildClosed(string id) { var mdiChild = _mdiContainer.MdiChildren[id]; var vm = mdiChild.ViewModel; _tsiFileViewModels.Remove(vm); if (!_tsiFileViewModels.Any()) { SelectedTsiFileModel = null; } }
public static async Task <TsiFileViewModel> LoadAsync(string filePath) { TsiFileViewModel result = null; App.SetStatus("Opening " + filePath + " ..."); TsiFile.EffectIdentificationRequest += onEffectIdentificationRequest; var tsiFile = await loadTsiAsync(filePath); if (tsiFile != null) { result = new TsiFileViewModel(tsiFile); } TsiFile.EffectIdentificationRequest -= onEffectIdentificationRequest; App.ResetStatus(); return(result); }
private async Task <bool> saveAs(TsiFileViewModel vm) { string initialDirectory = null; if (!String.IsNullOrEmpty(CmdrSettings.Instance.DefaultWorkspace)) { initialDirectory = CmdrSettings.Instance.DefaultWorkspace; } string path = BrowseDialogHelper.BrowseTsiFile(App.Current.MainWindow, true, initialDirectory, vm.Title); if (!String.IsNullOrEmpty(path)) { return(await vm.SaveAsync(path)); } return(false); }
private bool savePendingChanges(TsiFileViewModel vm, out bool cancel) { cancel = false; if (vm.IsChanged && vm.Devices.Any()) { _mdiContainer.SelectMdiChild(_mdiContainer.MdiChildren.Single(m => m.Value.ViewModel.Equals(vm)).Key); string msg = "'" + vm.Title + "' was changed. Do you want to save it before exit?"; var result = MessageBox.Show(msg, "Warning", MessageBoxButton.YesNoCancel); if (result == MessageBoxResult.Yes) { return(true); } else if (result == MessageBoxResult.Cancel) { cancel = true; } } return(false); }
private async Task openFile(string path) { var mdiChild = _mdiContainer.MdiChildren.Values.FirstOrDefault(c => c.ViewModel.Path == path); if (mdiChild == null) { TsiFileViewModel vm = await TsiFileViewModel.LoadAsync(path); if (vm != null) { _tsiFileViewModels.Add(vm); openTab(vm); _mru.Add(path); } else { MessageBoxHelper.ShowError("Cannot open file.\nPlease upload the TSI in https://github.com/pestrela/cmdr/issues"); } } else { _mdiContainer.SelectMdiChild(mdiChild.Id); } }
// Constructor public DeviceViewModel(Device device, TsiFileViewModel parent) { // link to parent, used for the filtering operations this.ParentSelector = parent; _device = device; _traktorVersion = _device.TraktorVersion; updatePorts(device); generateAddMappingContextMenus(); loadDefaultMidiDefinitionsAsync(); foreach (var mapping in _device.Mappings) { var mvm = new MappingViewModel(_device, mapping); Mappings.Add(new RowItemViewModel(mvm)); mvm.DirtyStateChanged += (s, e) => updateMapsChanged(); } loadMetadata(); AcceptChanges(); Mappings.CollectionChanged += Mappings_CollectionChanged; // set selection if possible if (Mappings.Any()) { SelectedMappings.Add(Mappings.First()); updateAddMappingContextMenus(); this.ParentSelector.ClearFiltering(); } }
private bool savePendingChanges(TsiFileViewModel vm, out bool cancel, in bool ignore_changes = false)
private void close(TsiFileViewModel vm) { _mdiContainer.RemoveMdiChild(_mdiContainer.MdiChildren.Single(m => m.Value.ViewModel.Equals(vm)).Key, true); }