Beispiel #1
0
 /// <summary>
 /// Updates the given entry list with the given entries.
 /// Used by other Update methods.
 /// </summary>
 /// <param name="entries">The entries to be filled in the list.</param>
 /// <param name="list">The EntryListBox list.</param>
 private void UpdateEntryList(IEnumerable<Entry> entries, EntryListBox list)
 {
     this.UpdateEntryList(entries, list, true);
 }
Beispiel #2
0
        /// <summary>
        /// Updates the given entry list with the given entries.
        /// Used by other Update methods.
        /// </summary>
        /// <param name="entries">The entries to be filled in the list.</param>
        /// <param name="list">The EntryListBox list.</param>
        /// <param name="dateSeparator">if set to <c>true</c> display the date separators.</param>
        private void UpdateEntryList(IEnumerable<Entry> entries, EntryListBox list, bool dateSeparator)
        {
            // Clear everything.
            list.Items.Clear();

            if (dateSeparator)
            {
                // Reverse sort and group by month.
                var groupedEntries = entries
                    .OrderByDescending(x => x.UTCDateTime)
                    .GroupBy(x => new DateTime(x.LocalTime.Year, x.LocalTime.Month, 1));

                // Add the list items
                foreach (var group in groupedEntries)
                {
                    // Add the month group bar
                    list.Items.Add(group.Key);
                    list.Items.AddRange(group.ToArray());
                }
            }
            else
            {
                list.Items.AddRange(entries.ToArray());
            }

            this.HighlightSelectedEntry(list);
        }
Beispiel #3
0
        /// <summary>
        /// Highlights the selected entry.
        /// </summary>
        /// <param name="list">The list.</param>
        private void HighlightSelectedEntry(EntryListBox list)
        {
            // If there is already a selected entry, select it!
            if (this.SelectedEntry != null)
            {
                int index = list.Items.IndexOf(this.SelectedEntry);
                if (list.SelectedIndex != index)
                {
                    if (index != -1)
                    {
                        bool prevSuppressEntryUpdate = this.suppressEntryUpdate;
                        this.suppressEntryUpdate = true;

                        list.SelectedIndex = index;

                        this.suppressEntryUpdate = prevSuppressEntryUpdate;

                        if (index > 0 && list.Items[index - 1] is DateTime)
                        {
                            list.TopIndex = index - 1;
                        }
                        else
                        {
                            list.TopIndex = index;
                        }
                    }
                    else
                    {
                        list.SelectedIndex = -1;
                    }
                }
            }
        }