public int GetNextIndex(bool searchBackward, bool loop) { int curIdx = SelectedIndex; if (curIdx >= 0) { ListViewItem currentItem = FileStatusListView.Items[curIdx]; var currentGroup = currentItem.Group; int maxIdx = GitItemStatuses.Count() - 1; if (searchBackward) { var nextItem = FindPrevItemInGroups(curIdx, currentGroup); if (nextItem == null) { return(loop ? GetLastIndex() : curIdx); } return(nextItem.Index); } else { var nextItem = FindNextItemInGroups(curIdx, currentGroup); if (nextItem == null) { return(loop ? 0 : curIdx); } return(nextItem.Index); } } else { return(-1); } }
private void UpdateFileStatusListView(bool updateCausedByFilter = false) { if (!GitItemStatuses.Any()) { HandleVisibility_NoFilesLabel_FilterComboBox(filesPresent: false); } else { EnsureSelectedIndexChangeSubscription(); HandleVisibility_NoFilesLabel_FilterComboBox(filesPresent: true); } FileStatusListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); var previouslySelectedItems = new List <GitItemStatus>(); if (updateCausedByFilter) { foreach (ListViewItem Item in FileStatusListView.SelectedItems) { previouslySelectedItems.Add(Item.Tag as GitItemStatus); } DataSourceChanged?.Invoke(this, new EventArgs()); } FileStatusListView.BeginUpdate(); FileStatusListView.ShowGroups = GitItemStatusesWithParents.Count > 1; FileStatusListView.Groups.Clear(); FileStatusListView.Items.Clear(); var clientSizeWidth = AppSettings.TruncatePathMethod == "compact" || AppSettings.TruncatePathMethod == "trimstart"; var fileNameOnlyMode = AppSettings.TruncatePathMethod == "fileNameOnly"; var list = new List <ListViewItem>(); foreach (var pair in GitItemStatusesWithParents) { ListViewGroup group = null; if (pair.Key != null) { var groupName = ""; if (pair.Key.Guid == CombinedDiff.Text) { groupName = CombinedDiff.Text; } else { groupName = _DiffWithParent.Text + " " + GetDescriptionForRevision(pair.Key.Guid); } group = new ListViewGroup(groupName); group.Tag = pair.Key; FileStatusListView.Groups.Add(group); } foreach (var item in pair.Value) { if (_filter.IsMatch(item.Name)) { var text = item.Name; if (clientSizeWidth) { // list-item has client width, so we don't need horizontal scrollbar (which is determined by this text width) text = string.Empty; } else if (fileNameOnlyMode) { // we need to put filename in list-item text -> then horizontal scrollbar // will have proper width (by the longest filename, and not all path) text = PathFormatter.FormatTextForFileNameOnly(item.Name, item.OldName); text = AppendItemSubmoduleStatus(text, item); } var listItem = new ListViewItem(text, group); listItem.ImageIndex = GetItemImageIndex(item); if (item.SubmoduleStatus != null && !item.SubmoduleStatus.IsCompleted) { var capturedItem = item; item.SubmoduleStatus.ContinueWith((task) => listItem.ImageIndex = GetItemImageIndex(capturedItem), CancellationToken.None, TaskContinuationOptions.OnlyOnRanToCompletion, TaskScheduler.FromCurrentSynchronizationContext()); } if (previouslySelectedItems.Contains(item)) { listItem.Selected = true; } listItem.Tag = item; list.Add(listItem); } } } FileStatusListView.Items.AddRange(list.ToArray()); if (updateCausedByFilter == false) { FileStatusListView_SelectedIndexChanged(); DataSourceChanged?.Invoke(this, new EventArgs()); if (SelectFirstItemOnSetItems) { SelectFirstVisibleItem(); } } FileStatusListView_SizeChanged(null, null); FileStatusListView.SetGroupState(ListViewGroupState.Collapsible); FileStatusListView.EndUpdate(); }