RadioDld.Main.InitDownloadList C# (CSharp) Method

InitDownloadList() private method

private InitDownloadList ( ) : void
return void
        private void InitDownloadList()
        {
            if (this.ListDownloads.SelectedItems.Count > 0)
            {
                this.SetViewDefaults(); // Revert back to default sidebar and toolbar
            }

            this.downloadColSizes.Clear();
            this.downloadColOrder.Clear();
            Application.DoEvents(); // Give any queued Invoke calls a chance to be processed
            this.ListDownloads.Clear();
            this.ListDownloads.HideAllProgress();

            const string DefaultColSizes = "0,2.49|1,0.81|2,1.28|3,1.04|4,0.6";

            if (string.IsNullOrEmpty(Settings.DownloadColSizes))
            {
                Settings.DownloadColSizes = DefaultColSizes;
            }
            else
            {
                string newItems = string.Empty;

                // Find any columns without widths defined in the current setting
                foreach (string sizePair in DefaultColSizes.Split('|'))
                {
                    if (!("|" + Settings.DownloadColSizes).Contains("|" + sizePair.Split(',')[0] + ","))
                    {
                        newItems += "|" + sizePair;
                    }
                }

                // Append the new column sizes to the end of the setting
                if (!string.IsNullOrEmpty(newItems))
                {
                    Settings.DownloadColSizes += newItems;
                }
            }

            // Fetch the column sizes into downloadColSizes for ease of access
            foreach (string sizePair in Settings.DownloadColSizes.Split('|'))
            {
                string[] splitPair = sizePair.Split(',');
                int pixelSize = (int)(float.Parse(splitPair[1], CultureInfo.InvariantCulture) * this.CurrentAutoScaleDimensions.Width);

                this.downloadColSizes.Add(int.Parse(splitPair[0], CultureInfo.InvariantCulture), pixelSize);
            }

            // Set up the columns specified in the DownloadCols setting
            if (!string.IsNullOrEmpty(Settings.DownloadCols))
            {
                string[] columns = Settings.DownloadCols.Split(',');

                foreach (string column in columns)
                {
                    int colVal = int.Parse(column, CultureInfo.InvariantCulture);
                    this.downloadColOrder.Add((Model.Download.DownloadCols)colVal);
                    this.ListDownloads.Columns.Add(this.downloadColNames[colVal], this.downloadColSizes[colVal]);
                }
            }

            // Apply the sort from the current settings
            Model.Download.SortByColumn = Settings.DownloadColSortBy;
            Model.Download.SortAscending = Settings.DownloadColSortAsc;
            this.ListDownloads.ShowSortOnHeader(this.downloadColOrder.IndexOf(Model.Download.SortByColumn), Model.Download.SortAscending ? SortOrder.Ascending : SortOrder.Descending);

            // Convert the list of Download items to an array of ListItems
            List<Model.Download> initData = Model.Download.FetchVisible(this.dataSearch);
            ListViewItem[] initItems = new ListViewItem[initData.Count];

            for (int convItems = 0; convItems < initData.Count; convItems++)
            {
                initItems[convItems] = this.DownloadListItem(initData[convItems], null);
            }

            // Add the whole array of ListItems at once
            this.ListDownloads.Items.AddRange(initItems);
        }
Main