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) { string 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(); }
private string GetItemText(Graphics graphics, GitItemStatus gitItemStatus) { var pathFormatter = new PathFormatter(graphics, FileStatusListBox.Font); return pathFormatter.FormatTextForDrawing(FileStatusListBox.ClientSize.Width - ImageSize, gitItemStatus.Name, gitItemStatus.OldName); }
internal static string FormatOldName(string oldName) => PathFormatter.FormatOldName(oldName);