Ejemplo n.º 1
0
 public void selectNone()
 {
     if (_selectedMappings.Count > 0)
     {
         SelectedMappings.Clear();
     }
 }
Ejemplo n.º 2
0
        public DeviceViewModel(Device device)
        {
            _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();
            }
        }
Ejemplo n.º 3
0
        private void paste()
        {
            var sorted = _selectedMappings.OrderBy(s => _mappings.IndexOf(s));

            int index = _mappings.Count;

            if (_selectedMappings.Count > 0)
            {
                index = _mappings.IndexOf(sorted.Last()) + 1;
                if (can_change_selection_automatically())
                {
                    SelectedMappings.Clear();
                }
            }

            foreach (var mapping in _mappingClipboard)
            {
                var new_map = mapping.Copy(true);
                insertMapping(index++, new_map);
            }

            if (can_change_selection_automatically())
            {
                _selectedMappings.Last().BringIntoView();
            }

            var all_mappings          = _mappings.Count;
            var all_selected_mappings = _selectedMappings.Count;

            OnModification();
        }
Ejemplo n.º 4
0
 private void selectExclusive(RowItemViewModel row)
 {
     if (can_change_selection_automatically())
     {
         SelectedMappings.Clear();
         SelectedMappings.Add(row);
     }
 }
Ejemplo n.º 5
0
        public void selectAll()
        {
            selectNone();

            foreach (var m in Mappings)
            {
                SelectedMappings.Add(m);
            }
        }
Ejemplo n.º 6
0
        private void insertMapping(int index, Mapping rawMapping)
        {
            _device.InsertMapping(index, rawMapping);
            var mvm = new MappingViewModel(_device, rawMapping);
            var row = new RowItemViewModel(mvm);

            _mappings.Insert(index, row);

            SelectedMappings.Add(row);
        }
Ejemplo n.º 7
0
        private void insertMapping(int index, Mapping rawMapping)
        {
            _device.InsertMapping(index, rawMapping);
            var mvm = new MappingViewModel(_device, rawMapping);
            var row = new RowItemViewModel(mvm);

            _mappings.Insert(index, row);

            if (can_change_selection_automatically())
            {
                SelectedMappings.Add(row);
            }

            OnModification();
        }
Ejemplo n.º 8
0
        private void paste()
        {
            var sorted = _selectedMappings.OrderBy(s => _mappings.IndexOf(s));

            int index = _mappings.Count;

            if (_selectedMappings.Count > 0)
            {
                index = _mappings.IndexOf(sorted.Last()) + 1;
                SelectedMappings.Clear();
            }

            foreach (var mapping in _mappingClipboard)
            {
                insertMapping(index++, mapping.Copy(true));
            }

            _selectedMappings.Last().BringIntoView();
        }
Ejemplo n.º 9
0
        private void paste()
        {
            var sorted = _selectedMappings.OrderBy(s => _mappings.IndexOf(s));

            int index = _mappings.Count;

            if (_selectedMappings.Count > 0)
            {
                index = _mappings.IndexOf(sorted.Last()) + 1;
                SelectedMappings.Clear();
            }

            foreach (var mapping in _mappingClipboard)
            {
                insertMapping(index++, mapping.Copy(true));
            }

            _selectedMappings.Last().BringIntoView();

            Mappings.First().ClearFiltering();   // HACK: investigate why there is a duplication on the very first paste or "add-in". Clearing grid filters avoids this bug
        }
Ejemplo n.º 10
0
 private void selectExclusive(RowItemViewModel row)
 {
     SelectedMappings.Clear();
     SelectedMappings.Add(row);
 }
Ejemplo n.º 11
0
        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();
            }
        }