private void SaveCustomizationSettings()
        {
            var settingsRepository = _historyToolWindowRepositoryFactory.Create();

            var columnsInfo = new List <ColumnInfo>();

            foreach (var item in _columnHeaders)
            {
                var column = _listViewContect.Columns.SingleOrDefault(x => x.GetGridViewHeaderText() == item.Value);
                columnsInfo.Add(new ColumnInfo()
                {
                    Id       = item.Key,
                    Position = column != null ? _listViewContect.Columns.IndexOf(column) : -1,
                    Visible  = column != null,
                    Width    = column?.Width ?? 0
                });
            }

            var settings = new HistoryControlData()
            {
                SearchHistory = _search.HistoryList.Take(10),
                ColumnsInfo   = columnsInfo
            };

            settingsRepository?.SaveSettings(settings);
        }
        private void AddContextMenu(HistoryControlData historyControlData)
        {
            var contextMenu = new ContextMenu();

            var removeSortingMenu = new MenuItem()
            {
                Uid         = "_removeSortingMenu",
                Header      = "Remove sorting",
                IsCheckable = false,
            };

            removeSortingMenu.Click += _listViewRemoveSort_Click;

            var hideShowColumnMenu = new MenuItem()
            {
                Uid         = "_showHideColumnsMenu",
                Header      = "Show/Hide columns",
                IsCheckable = false,
            };

            hideShowColumnMenu.Click += _listViewShowColumns_Click;

            int index = 0;

            foreach (var item in _listViewContect.Columns)
            {
                var setting = historyControlData?.ColumnsInfo?.SingleOrDefault(x => x.Id == index);

                var menu = new MenuItem()
                {
                    Uid         = index++.ToString(),
                    Header      = item.GetGridViewHeaderText(),
                    IsCheckable = true,
                    IsChecked   = setting?.Visible ?? true
                };
                hideShowColumnMenu.Items.Add(menu);
            }

            var resetShowColumnMenu = new MenuItem()
            {
                Uid         = "_resetShowColumnMenu",
                Header      = "Reset column customization",
                IsCheckable = false,
            };

            resetShowColumnMenu.Click += _resetShowColumnMenu_Click;

            contextMenu.Items.Add(removeSortingMenu);
            contextMenu.Items.Add(hideShowColumnMenu);
            contextMenu.Items.Add(resetShowColumnMenu);

            _listView.ContextMenu = contextMenu;
        }
        private void HandleColumnsStatus(HistoryControlData historyControlData)
        {
            if (historyControlData?.ColumnsInfo?.Any() ?? false)
            {
                var hiddenColumns = historyControlData.ColumnsInfo.Where(x => !x.Visible);
                foreach (var item in hiddenColumns)
                {
                    if (_columnHeaders.ContainsKey(item.Id))
                    {
                        HideColumn(_columnHeaders[item.Id]);
                    }
                }

                var visibleColumns = historyControlData.ColumnsInfo.Except(hiddenColumns).OrderBy(o => o.Position);
                foreach (var item in visibleColumns)
                {
                    if (_columnHeaders.ContainsKey(item.Id))
                    {
                        SetColumnData(_columnHeaders[item.Id], item.Position, item.Width);
                    }
                }
            }
        }