private async void RefreshEntries(int activeEntryId = 0)
        {
            if (!_activeGroupSet)
                return;
            
//            panelEntriesContainer.Controls.Clear();
//            panelEntriesContainer.Controls.Add(new Label
//            {
//                Dock = DockStyle.Fill,
//                ImageAlign = ContentAlignment.MiddleCenter,
//                Image = Properties.Resources.loading_spinner
//            });
            
            var groupEntries = Model.DatabasesEntries.Find(new DatabaseEntry
            {
                DatabaseId = _databaseId,
                DatabaseGroupId = _activeGroupId,
                ToBeDeleted = false
            });

            Control selectedControl = null;
            var controlsList = new List<DatabaseViewEntry>();
            foreach (var entry in groupEntries)
            {
                var entryData = Model.DatabasesEntriesData.Get(entry.DatabaseEntryDataId);

                var control = new DatabaseViewEntry(entry.Id)
                {
                    Dock = DockStyle.Top,
                    lblEntryName = { Text = entryData.Name },
                    Selected = activeEntryId == entry.Id
                };
                
                control.Click += DatabaseEntry_Click;
                controlsList.Add(control);

                if (control.Selected)
                    selectedControl = control;
            }

            // OrderByDescending because each control added to the panel puts it at the top.
            controlsList = controlsList.OrderByDescending(control => control.lblEntryName.Text).ToList();

            panelEntriesContainer.AutoScroll = false;
            var origScrollPositition = AutoScrollPosition;
            
            panelEntriesContainer.SuspendLayout();
            panelEntriesContainer.Controls.Clear();
            panelEntriesContainer.Controls.AddRange(controlsList.ToArray());
            //foreach (var control in controlsList)
            //    panelEntriesContainer.Controls.Add(control);
            panelEntriesContainer.ResumeLayout(false);
            
            panelEntriesContainer.AutoScroll = true;
            panelEntriesContainer.AutoScrollPosition = origScrollPositition;

            if (selectedControl != null)
                panelEntriesContainer.ScrollControlIntoView(selectedControl);

            if (Program.IsRunningOnMono())
            {
                // Mono doesn't seem to wan't to automatically show scroll bars, so we'll have to force it
                panelEntriesContainer.VerticalScroll.Visible = true;
            }

            panelEntriesContainer.Focus();
        }
Exemple #2
0
        private async void RefreshEntries(int activeEntryId = 0)
        {
            if (!_activeGroupSet)
            {
                return;
            }

//            panelEntriesContainer.Controls.Clear();
//            panelEntriesContainer.Controls.Add(new Label
//            {
//                Dock = DockStyle.Fill,
//                ImageAlign = ContentAlignment.MiddleCenter,
//                Image = Properties.Resources.loading_spinner
//            });

            var groupEntries = Model.DatabasesEntries.Find(new DatabaseEntry
            {
                DatabaseId      = _databaseId,
                DatabaseGroupId = _activeGroupId,
                ToBeDeleted     = false
            });

            Control selectedControl = null;
            var     controlsList    = new List <DatabaseViewEntry>();

            foreach (var entry in groupEntries)
            {
                var entryData = Model.DatabasesEntriesData.Get(entry.DatabaseEntryDataId);

                var control = new DatabaseViewEntry(entry.Id)
                {
                    Dock         = DockStyle.Top,
                    lblEntryName = { Text = entryData.Name },
                    Selected     = activeEntryId == entry.Id
                };

                control.Click += DatabaseEntry_Click;
                controlsList.Add(control);

                if (control.Selected)
                {
                    selectedControl = control;
                }
            }

            // OrderByDescending because each control added to the panel puts it at the top.
            controlsList = controlsList.OrderByDescending(control => control.lblEntryName.Text).ToList();

            panelEntriesContainer.AutoScroll = false;
            var origScrollPositition = AutoScrollPosition;

            panelEntriesContainer.SuspendLayout();
            panelEntriesContainer.Controls.Clear();
            panelEntriesContainer.Controls.AddRange(controlsList.ToArray());
            //foreach (var control in controlsList)
            //    panelEntriesContainer.Controls.Add(control);
            panelEntriesContainer.ResumeLayout(false);

            panelEntriesContainer.AutoScroll         = true;
            panelEntriesContainer.AutoScrollPosition = origScrollPositition;

            if (selectedControl != null)
            {
                panelEntriesContainer.ScrollControlIntoView(selectedControl);
            }

            if (Program.IsRunningOnMono())
            {
                // Mono doesn't seem to wan't to automatically show scroll bars, so we'll have to force it
                panelEntriesContainer.VerticalScroll.Visible = true;
            }

            panelEntriesContainer.Focus();
        }