Пример #1
0
 void flattener_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
 {
     // Deselect nodes that are being hidden, if any remain in the tree
     if (e.Action == NotifyCollectionChangedAction.Remove && Items.Count > 0)
     {
         List <SharpTreeNode> selectedOldItems = null;
         foreach (SharpTreeNode node in e.OldItems)
         {
             if (node.IsSelected)
             {
                 if (selectedOldItems == null)
                 {
                     selectedOldItems = new List <SharpTreeNode>();
                 }
                 selectedOldItems.Add(node);
             }
         }
         if (selectedOldItems != null)
         {
             var list = SelectedItems.Cast <SharpTreeNode>().Except(selectedOldItems).ToList();
             SetSelectedItems(list);
             if (SelectedItem == null)
             {
                 // if we removed all selected nodes, then move the focus to the node
                 // preceding the first of the old selected nodes
                 SelectedIndex = Math.Max(0, e.OldStartingIndex - 1);
                 FocusNode((SharpTreeNode)SelectedItem);
             }
         }
     }
 }
Пример #2
0
        private async void OnPlaySelectedCommand()
        {
            _appLoaderService.Show();

            await Task.Run(async() =>
            {
                var tracks = SelectedItems.Cast <T>().ToList();
                PrepareTracksBeforePlay(tracks);

                _playerService.IsShuffleMode = false;
                if (_maxPlayingTracks != -1 && tracks.Count > _maxPlayingTracks)
                {
                    int newIndex  = 0;
                    var newTracks = tracks.GetFromCentre(0, _maxPlayingTracks, out newIndex);

                    PrepareTracksBeforePlay(newTracks);
                    await _playerService.PlayNewTracks(newTracks.Select(t => ConvertToPlayerTrack(t)), newIndex);
                }
                else
                {
                    PrepareTracksBeforePlay(tracks);
                    await _playerService.PlayNewTracks(tracks.Select(t => ConvertToPlayerTrack(t)), 0);
                }
            });

            _navigationService.Navigate("PlayerView", null);
            _appLoaderService.Hide();
        }
Пример #3
0
        private async Task OnArchiveFavorite()
        {
            if (SelectedItems?.Count == 0)
            {
                return;
            }

            bool canNavigate = await NavigationManager.CanPopUpNavigateAsync <ChoiceModalViewModel>();

            if (canNavigate)
            {
                var action = new Action(async() =>
                {
                    var items = SelectedItems.Cast <FavoritedAnime>().ToList();
                    SelectedItems.Clear();
                    var favoriteCollection = App.liteDB.GetCollection <FavoritedAnime>();

                    foreach (var item in items)
                    {
                        item.IsArchived = !item.IsArchived;
                        item.CanGenerateNotifications = false;
                        favoriteCollection.Update(item.Anime.MalId, item);
                    }

                    var collection      = await ConstructGroupedCollectionAsync();
                    _originalCollection = collection;

                    GroupedFavoriteByWeekList.ReplaceRange(_originalCollection);
                });

                await NavigationManager.NavigatePopUpAsync <ChoiceModalViewModel>(Lang.Lang.Shelving, Lang.Lang.ShelvingMessage, action);
            }
        }
Пример #4
0
 void flattener_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
 {
     // Deselect nodes that are being hidden
     if (e.Action == NotifyCollectionChangedAction.Remove)
     {
         List <SharpTreeNode> selectedOldItems = null;
         foreach (SharpTreeNode node in e.OldItems)
         {
             if (node.IsSelected)
             {
                 if (selectedOldItems == null)
                 {
                     selectedOldItems = new List <SharpTreeNode>();
                 }
                 selectedOldItems.Add(node);
             }
         }
         if (selectedOldItems != null)
         {
             var list = SelectedItems.Cast <SharpTreeNode>().Except(selectedOldItems).ToList();
             SetSelectedItems(list);
         }
         // reset the focus to the previous node
         SelectedIndex = Math.Max(0, e.OldStartingIndex - 1);
         if (SelectedItem != null)
         {
             FocusNode((SharpTreeNode)SelectedItem);
         }
     }
 }
Пример #5
0
        private void ScrollViewerScrollChanged(object sender, ScrollChangedEventArgs e)
        {
            if (Math.Abs(e.VerticalChange) < 1e-3 && Math.Abs(e.HorizontalChange) < 1e-3)
            {
                return;
            }

            if (!ReferenceEquals(e.OriginalSource, scrollViewer))
            {
                return;
            }

            var selectedItem = SelectedItems
                               .Cast <object>()
                               .LastOrDefault();

            if (selectedItem == null)
            {
                return;
            }

            var selectedContainer = (EditableContentListBoxItem)ItemContainerGenerator.ContainerFromItem(selectedItem);

            if (selectedContainer == null)
            {
                return;
            }

            selectedContainer.IsEditing = false;
        }
Пример #6
0
        private void ColorSelect_Impl(int selectedColor)
        {
            if (SelectedItem is not null)
            {
                bool anyChanged       = false;
                bool fileWasDirty     = FileDirty;
                var  editedShowlights = SelectedItems.Cast <ShowLightViewModel>().ToArray();
                var  oldShowlights    = new List <(ShowLightViewModel, int)>();

                foreach (var sl in editedShowlights)
                {
                    if (sl.Note == selectedColor)
                    {
                        continue;
                    }

                    anyChanged = true;

                    oldShowlights.Add((sl, sl.Note));

                    sl.Note = (byte)selectedColor;
                }

                if (!anyChanged)
                {
                    return;
                }

                var undo = new UndoEdit(oldShowlights, selectedColor);

                scrollIntoView.OnNext(editedShowlights[0]);

                UndoManager.AddUndo(undo, fileWasDirty);
            }
        }
Пример #7
0
        /// <summary>
        /// Manually select the items...
        /// </summary>
        /// <param name="e">SelectionChangedEventArgs</param>
        protected override void OnSelectionChanged(SelectionChangedEventArgs e)
        {
            base.OnSelectionChanged(e);

            bool isVirtualizing = VirtualizingPanel.GetIsVirtualizing(this);
            bool isMultiSelect  = (SelectionMode != SelectionMode.Single);

            if (isVirtualizing && isMultiSelect)
            {
                var newSelectedItems = SelectedItems.Cast <IScrobbableObjectViewModel>();

                foreach (var deselectedItem in selectedItems.Except(newSelectedItems))
                {
                    deselectedItem.UpdateIsSelectedSilent(false);
                }

                selectedItems.Clear();
                selectedItems.AddRange(newSelectedItems);

                foreach (var newlySelectedItem in selectedItems)
                {
                    newlySelectedItem.UpdateIsSelectedSilent(true);
                }

                // todo: kinda hacky way to update the view...
                var lastItem = selectedItems.LastOrDefault();
                if (lastItem != null)
                {
                    lastItem.IsSelected = true;
                }
            }
        }
Пример #8
0
        // Fast implementation to remove the currently selected articles from the list, making use of List.Except method
        // As list is implicitly deduplicated, only use for main listbox if remove duplicates option is on
        private void RemoveSelectedNew()
        {
            List <Article> articles  = Items.Cast <Article>().ToList();
            List <Article> Sarticles = SelectedItems.Cast <Article>().ToList();

            Items.Clear();
            Items.AddRange(articles.Except(Sarticles).ToArray());
        }
Пример #9
0
 private void HandleMouseMove(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Left)
     {
         List <string> characterIds = SelectedItems.Cast <string>().ToList();
         DoDragDrop(characterIds, DragDropEffects.Move);
     }
 }
Пример #10
0
        /// <summary>
        /// Raises the <see cref="E:System.Windows.Forms.Control.DragOver"/> event.
        /// </summary>
        /// <param name="e">A <see cref="T:System.Windows.Forms.DragEventArgs"/> that contains the event data. </param>
        protected override void OnDragOver(DragEventArgs e)
        {
            base.OnDragOver(e);

            Skill dragSkill = GetDraggingSkill(e);

            if (dragSkill != null)
            {
                return;
            }

            if (!AllowRowReorder)
            {
                e.Effect = DragDropEffects.None;
                ClearDropMarker();
                return;
            }
            if (!e.Data.GetDataPresent(DataFormats.Text))
            {
                e.Effect = DragDropEffects.None;
                ClearDropMarker();
                return;
            }
            Point        cp        = PointToClient(new Point(e.X, e.Y));
            ListViewItem hoverItem = GetItemAt(cp.X, cp.Y);

            if (hoverItem == null)
            {
                e.Effect = DragDropEffects.None;
                ClearDropMarker();
                return;
            }

            if (SelectedItems.Cast <ListViewItem>().Any(moveItem => moveItem.Index == hoverItem.Index))
            {
                e.Effect = DragDropEffects.None;
                hoverItem.EnsureVisible();
                ClearDropMarker();
                return;
            }

            base.OnDragOver(e);
            String text = (String)e.Data.GetData(Reorder.GetType());

            if (String.Compare(text, Reorder, StringComparison.CurrentCulture) == 0)
            {
                e.Effect = DragDropEffects.Move;
                hoverItem.EnsureVisible();

                Rectangle hoverBounds = hoverItem.GetBounds(ItemBoundsPortion.ItemOnly);
                DrawDropMarker(hoverItem.Index, cp.Y > hoverBounds.Top + hoverBounds.Height / 2);
            }
            else
            {
                e.Effect = DragDropEffects.None;
                ClearDropMarker();
            }
        }
Пример #11
0
        private void RemoveSelectedItems()
        {
            var values = SelectedItems.Cast <SongEntity>().ToList().ConvertAll(x => PlayingList.IndexOf(x)).OrderByDescending(x => x).ToList();

            foreach (int mi in values)
            {
                PlayingList.RemoveAt(mi);
            }
        }
        private void UpdateText()
        {
            string newValue = String.Join(Delimiter, SelectedItems.Cast <object>().Select(x => GetItemDisplayValue(x).ToString()).ToArray());

            if (String.IsNullOrEmpty(Text) || !Text.Equals(newValue))
            {
                Text = newValue;
            }
        }
Пример #13
0
 /// <summary>
 /// Opens the containing folder for all the selected files.
 /// </summary>
 private void OpenFolderImpl()
 {
     if (SelectedItems is not null)
     {
         foreach (string path in SelectedItems.Cast <XMLProcessor>().Select(x => x.XMLFileFullPath).Distinct())
         {
             Path.GetDirectoryName(path)?.StartAsProcess();
         }
     }
 }
Пример #14
0
        private string GetFilterQuickLink(string filter)
        {
            if (string.IsNullOrEmpty(filter))
            {
                return(string.Empty);
            }
            var newFilter = filter;
            var pattern   = new Regex(@"\[(?<val>.*?)\]", RegexOptions.Compiled | RegexOptions.Singleline);

            foreach (Match m in pattern.Matches(newFilter))
            {
                var str      = m.Groups["val"].Value;
                var pattern2 = new Regex(@"\$(?<val>.*?)(\s|'|$)", RegexOptions.Compiled | RegexOptions.Singleline);
                var strNew   = string.Empty;
                foreach (var m2 in pattern2.Matches(str).Cast <Match>())
                {
                    var propName = m2.Groups["val"].Value;
                    if (string.IsNullOrEmpty(propName))
                    {
                        continue;
                    }

                    var isQuote = str.Contains(string.Format("'${0}'", propName));

                    var values = new List <string>();
                    var sb     = str.Contains('=') ? new StringBuilder(str.Substring(0, str.IndexOf('=')) + " IN (") : new StringBuilder("(");


                    foreach (var strValue in SelectedItems.Cast <WMSBusinessObject>().Select(item => item.GetProperty(propName)).
                             Select(i => CheckValue(i, isQuote)).Where(strValue => values.FirstOrDefault(strValue.Equals) == null))
                    {
                        var typeParam = TypeDescriptor.GetProperties(SelectedItems.FirstOrDefault()).Find(propName, true).PropertyType;
                        //TODO: сделать правильную обработку null полей
                        if (strValue.Contains("NULL") && values.Contains("'NULL'"))
                        {
                            continue;
                        }
                        var strParam = strValue == "NULL" && typeParam.IsAssignableFrom(typeof(string)) ? "'NULL'" : strValue;
                        values.Add(strParam);
                        if (values.Count == 1)
                        {
                            sb.Append(strParam);
                        }
                        else
                        {
                            sb.Append(",").Append(strParam);
                        }
                    }

                    strNew = strNew + sb.Append(")");
                }
                newFilter = newFilter.Replace(string.Format("[{0}]", str), strNew);
            }
            return(newFilter);
        }
Пример #15
0
        protected override void OnPreviewKeyDown(KeyEventArgs e)
        {
            base.OnKeyUp(e);

            // Only if at least one item is selected, shift is held, and up or down is pressed, we want to execute a move
            if (SelectedItem != null && Keyboard.Modifiers == ModifierKeys.Shift && (e.Key == Key.Up || e.Key == Key.Down))
            {
                TrackList <AudioTrack> itemsSource = (TrackList <AudioTrack>)ItemsSource;

                // Get the selected tracks ordered by their position
                var selectedTracks = new List <AudioTrack>(SelectedItems.Cast <AudioTrack>().OrderBy(t => itemsSource.IndexOf(t)));

                int delta = 0; // The delta to the new index after moving (no moving if zero)

                if (e.Key == Key.Up)
                {
                    // Check the index of the first key and see if it can be moved upwards
                    int oldIndex = itemsSource.IndexOf(selectedTracks.First());
                    delta = Math.Max(0, oldIndex - 1) - oldIndex;
                }
                else if (e.Key == Key.Down)
                {
                    // Check the index of the last key and see if it can be moved downwards
                    int oldIndex = itemsSource.IndexOf(selectedTracks.Last());
                    delta = Math.Min(itemsSource.Count - 1, oldIndex + 1) - oldIndex;
                }

                if (delta != 0)
                {
                    if (delta > 0)
                    {
                        // When moving down, the sequence of the moves must be in the opposite direction
                        // beginning with the last one, else it somehow locks up and movement does not work.
                        selectedTracks.Reverse();
                    }

                    // Move items
                    selectedTracks.ForEach(t => {
                        int oldIndex = itemsSource.IndexOf(t);
                        itemsSource.Move(oldIndex, oldIndex + delta);
                    });

                    // Refocus on the moved selected item because it loses focus during the move
                    // http://stackoverflow.com/a/10463162
                    ListBoxItem listBoxItem = (ListBoxItem)multiTrackListBox.ItemContainerGenerator
                                              .ContainerFromItem(multiTrackListBox.SelectedItem);
                    listBoxItem.Focus();

                    RefreshAdornerLayer();
                }

                e.Handled = true;
            }
        }
Пример #16
0
        internal void HandleCollapsing(SharpTreeNode Node)
        {
            var selectedChilds = Node.Descendants().Where(n => SharpTreeNode.SelectedNodes.Contains(n));

            if (selectedChilds.Any())
            {
                var list = SelectedItems.Cast <SharpTreeNode>().Except(selectedChilds).ToList();
                list.AddOnce(Node);
                SetSelectedItems(list);
            }
        }
Пример #17
0
        public void OnDelete()
        {
            if (!ConnectionManager.Instance.AllowRequest())
            {
                return;
            }

            if (!CanDelete())
            {
                return;
            }

            try
            {
                if (GetViewService().ShowDialog(StringResources.Confirmation
                                                , StringResources.ConfirmationDeleteObject
                                                , MessageBoxButton.YesNo
                                                , MessageBoxImage.Question
                                                , MessageBoxResult.Yes) != MessageBoxResult.Yes)
                {
                    return;
                }

                var items = SelectedItems.Cast <EditableBusinessObject>().ToList();

                foreach (var item in items)
                {
                    ChildSource.Remove(item);

                    var key = ((WMSBusinessObject)item).GetKey().ToString();
                    if (!string.IsNullOrEmpty(key))
                    {
                        var exit = false;
                        while (!exit)
                        {
                            var e2gc = Source.FirstOrDefault(x => string.Equals(key, x.ENTITY2GCKEY));
                            if (e2gc != null)
                            {
                                Source.Remove(e2gc);
                            }
                            else
                            {
                                exit = true;
                            }
                        }
                    }
                }
                Revalidate();
            }
            catch (Exception ex)
            {
                throw new OperationException(ExceptionResources.ItemCantDelete, ex);
            }
        }
Пример #18
0
 private void SelectNodes()
 {
     if (SelectedItems == null)
     {
         return;
     }
     foreach (var node in _nodeList)
     {
         node.IsSelected = SelectedItems.Cast <object>().Any(x => x.GetType().GetProperties().FirstOrDefault(y => y.Name == SelectedValuePath).GetValue(x)?.ToString() == node.Key);
     }
 }
Пример #19
0
        private async void OnPlaySelectedCommand()
        {
            _appLoaderService.Show();

            var toPlay = SelectedItems.Cast <Audio>().ToPlayerTracks();
            await _playerService.PlayNewTracks(toPlay, 0);

            _navigationService.Navigate("PlayerView", null);

            _appLoaderService.Hide();
        }
Пример #20
0
        internal void HandleCollapsing(SharpTreeNode node)
        {
            var selectedChilds = node.VisibleDescendants().Where(n => n.IsSelected);

            if (selectedChilds.Any())
            {
                var list = SelectedItems.Cast <SharpTreeNode>().Except(selectedChilds).ToList();
                list.AddOnce(node);
                SetSelectedItems(list);
            }
        }
Пример #21
0
        /// <summary>
        ///     Updates the SelectedValue property based on what is present in the SelectedItems property.
        /// </summary>
        private void UpdateSelectedValue()
        {
            string newValue = String.Join(Delimiter, SelectedItems.Cast <object>().Select(GetItemValue));

            if (String.IsNullOrEmpty(SelectedValue) || !SelectedValue.Equals(newValue))
            {
                _ignoreSelectedValueChanged = true;
                SelectedValue = newValue;
                _ignoreSelectedValueChanged = false;
            }
        }
Пример #22
0
        private async void OnDeleteSelectedCommand()
        {
            _appLoaderService.Show(_locService["AppLoader_Preparing"]);
            _cancelOperations = false;

            var items   = SelectedItems.Cast <Audio>().ToList();
            var errors  = new List <Audio>();
            var success = new List <Audio>();

            foreach (var track in items)
            {
                if (_cancelOperations)
                {
                    errors.Add(track);
                    continue;
                }

                _appLoaderService.Show(String.Format(_locService["AppLoader_DeletingItem"], track.ToString()));

                bool isSuccess = false;
                try
                {
                    isSuccess = await DeleteAudio(track);
                }
                catch (Exception)
                {
                    errors.Add(track);
                    _cancelOperations = true;
                    _appLoaderService.Show(_locService["AppLoader_PleaseWait"]);
                    continue;
                }

                if (isSuccess)
                {
                    success.Add(track);
                }
                else
                {
                    errors.Add(track);
                }

                await Task.Delay(300);
            }

            RemoveDeletedItems(success);
            if (errors.Any())
            {
                ShowDeletingError(errors);
            }

            _appLoaderService.Hide();
            SetDefaultMode();
        }
Пример #23
0
 protected override void OnContextMenuOpening(ContextMenuEventArgs e)
 {
     if (SelectedItems?.Cast <object>().Count() > 1)
     {
         ContextMenu = MultiSelectionContextMenu;
     }
     else
     {
         ContextMenu = SingleSelectionContextMenu;
     }
     base.OnContextMenuOpening(e);
 }
Пример #24
0
        private void OnDelete()
        {
            if (!ConnectionManager.Instance.AllowRequest())
            {
                return;
            }

            if (!CanDelete())
            {
                return;
            }

            try
            {
                if (GetViewService().ShowDialog(StringResources.Confirmation
                                                , StringResources.ConfirmationDeleteObject
                                                , MessageBoxButton.YesNo
                                                , MessageBoxImage.Question
                                                , MessageBoxResult.Yes) != MessageBoxResult.Yes)
                {
                    return;
                }

                var items = SelectedItems.Cast <EditableBusinessObject>().ToList();

                if (ShouldUpdateSeparately)
                {
                    using (var mng = GetManager(_itemType))
                        foreach (var item in items)
                        {
                            mng.Delete(item);
                            if (ParentViewModel == null)
                            {
                                Source.Remove(item);
                            }
                        }
                    ParentRefresh();
                }
                else
                {
                    foreach (var item in items)
                    {
                        Source.Remove(item);
                    }
                    Revalidate();
                }
            }
            catch (Exception ex)
            {
                throw new OperationException(ExceptionResources.ItemCantDelete, ex);
            }
        }
Пример #25
0
 /// <summary>
 /// Raises the <see cref="ListView.ItemDrag"/> event of the list view.
 /// </summary>
 /// <remarks>
 /// This starts the drag/drop reorder operation if at least one item is selected.
 /// </remarks>
 /// <param name="e">An <see cref="ItemDragEventArgs"/> describing the event arguments.</param>
 protected override void OnItemDrag(ItemDragEventArgs e)
 {
     base.OnItemDrag(e);
     if (SelectedItems.Count == 0)
     {
         return;
     }
     DoDragDrop(new List <ListViewItem>(SelectedItems.Cast <ListViewItem>()), DragDropEffects.Move);
     while (m_queDragDropExceptions.Count > 0)
     {
         throw new Exception("Exception thrown during drag-drop operation. See inner exception for the exception that was thrown.", m_queDragDropExceptions.Dequeue());
     }
 }
Пример #26
0
        public void OpenSelectedGamesUsers()
        {
            if (SelectedItems == null || SelectedItems.Count == 0)
            {
                return;
            }
            var users = new ObservableCollection <UserModel>(User.Parse(SelectedItems
                                                                        .Cast <PlayerGameModel>()
                                                                        .Select(x => x.Game.Game))
                                                             .Select(x => new UserModel(x)));

            OpenViewModel?.Invoke(this, new OpenModelViewerEventArgs(new UserListModel(users)));
        }
Пример #27
0
 private void CalculateAffectedNotes(FrameworkElement view)
 {
     if (((NoteVelocityView)view).IsSelected)
     {
         _affectedNotes = SelectedItems.Cast <NoteViewModel>();
         (_min, _max)   = _affectedNotes.MinMaxBy(note => note.Velocity);
     }
     else
     {
         _affectedNotes = new[] { (NoteViewModel)view.DataContext };
         _min           = _max = (NoteViewModel)view.DataContext;
     }
 }
Пример #28
0
 private void CalculateAffectedItems(FrameworkElement view)
 {
     if (((PatternPlacementView)view).IsSelected)
     {
         _affectedItems         = SelectedItems.Cast <PatternPlacementViewModel>();
         _minTick               = _affectedItems.MinBy(pp => pp.Start);
         (_minTrack, _maxTrack) = _affectedItems.MinMaxBy(pp => pp.TrackIndex);
     }
     else
     {
         _affectedItems = new[] { (PatternPlacementViewModel)view.DataContext };
         _minTick       = _minTrack = _maxTrack = (PatternPlacementViewModel)view.DataContext;
     }
 }
Пример #29
0
        /// <summary>
        /// Updates the SelectedValue property based on what is present in the SelectedItems property.
        /// </summary>
        private void UpdateSelectedValue()
        {
#if VS2008
            string newValue = String.Join(Delimiter, SelectedItems.Cast <object>().Select(x => GetItemValue(x).ToString()).ToArray());
#else
            string newValue = String.Join(Delimiter, SelectedItems.Cast <object>().Select(x => GetItemValue(x)));
#endif
            if (String.IsNullOrEmpty(SelectedValue) || !SelectedValue.Equals(newValue))
            {
                _ignoreSelectedValueChanged = true;
                SelectedValue = newValue;
                _ignoreSelectedValueChanged = false;
            }
        }
Пример #30
0
 private void PreviewKeyDownEventHandler(object sender, System.Windows.Input.KeyEventArgs e)
 {
     if (!AllowDragDrop)
     {
         return;
     }
     if (e.Key == System.Windows.Input.Key.Delete)
     {
         foreach (var file in SelectedItems.Cast <string>().ToArray())
         {
             FileList.Remove(file);
         }
     }
 }