Exemplo n.º 1
0
 public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, System.Type destinationType)
 {
     if (destinationType == typeof(InstanceDescriptor))
     {
         Type[] signature          = { typeof(ThreadedListViewItem.ListViewSubItem[]), typeof(int), typeof(int) };
         ThreadedListViewItem itm  = ((ThreadedListViewItem)value);
         object[]             args = { itm.SubItemsArray, itm.ImageIndex, itm.GroupIndex };
         return(new InstanceDescriptor(typeof(ThreadedListViewItem).GetConstructor(signature), args, false));
     }
     return(base.ConvertTo(context, culture, value, destinationType));
 }
Exemplo n.º 2
0
 private void RaiseCollapseEvent(ThreadedListViewItem tlv)
 {
     if (CollapseThread != null)
     {
         var tea = new ThreadEventArgs(tlv);
         //TODO: add the thread child elements to eventArgs
         try
         {
             CollapseThread(this, tea);
         }
         catch (Exception ex)
         {
             _log.Error("Event CollapseThread() failed", ex);
         }
     }
 }
Exemplo n.º 3
0
 private void RaiseAfterExpandEvent(ThreadedListViewItem parent, ThreadedListViewItem[] newItems)
 {
     if (AfterExpandThread != null)
     {
         var tea = new ThreadEventArgs(parent)
         {
             ChildItems = newItems
         };
         try
         {
             AfterExpandThread(this, tea);
         }
         catch (Exception ex)
         {
             _log.Error("Event AfterExpandThread() failed", ex);
         }
     }
 }
Exemplo n.º 4
0
        private bool RaiseBeforeCollapseEventCancel(ThreadedListViewItem tlv)
        {
            bool cancel = false;

            if (BeforeCollapseThread != null)
            {
                var e = new ThreadCancelEventArgs(tlv, false);
                try
                {
                    BeforeCollapseThread(this, e);
                    cancel = e.Cancel;
                }
                catch (Exception ex)
                {
                    _log.Error("Event BeforeCollapseThread() failed", ex);
                }
            }
            return(cancel);
        }
Exemplo n.º 5
0
 private ThreadedListViewItem[] RaiseExpandEvent(ThreadedListViewItem tlv)
 {
     if (ExpandThread != null)
     {
         var tea = new ThreadEventArgs(tlv);
         try
         {
             ExpandThread(this, tea);
         }
         catch (Exception ex)
         {
             _log.Error("Event ExpandThread() failed", ex);
         }
         if (tea.ChildItems != null)
         {
             return(tea.ChildItems);
         }
     }
     return(new ThreadedListViewItem[] {});
 }
Exemplo n.º 6
0
        /// <summary>
        /// The workhorse to expand a threaded listview item
        /// </summary>
        /// <param name="lvItem"></param>
        /// <param name="activate">true, if lvItem should be activated</param>
        internal void ExpandListViewItem(ThreadedListViewItem lvItem, bool activate)
        {
            int selIdxsCount = SelectedIndices.Count;
            var selIdxs      = new int[selIdxsCount];

            SelectedIndices.CopyTo(selIdxs, 0);

            ThreadedListViewItem[] newItems;

            if (lvItem != null && lvItem.Collapsed)
            {
                if (RaiseBeforeExpandEventCancel(lvItem))
                {
                    lvItem.StateImageIndex = 0; // switch to non-state image (no +/-)
                    return;
                }

                int paramItemIndex = lvItem.Index;
                int currentIndent  = lvItem.IndentLevel;

//				if (base.SelectedItems.Count > 0 && activate)
//					selectedItemIndex = paramItemIndex;

                newItems = RaiseExpandEvent(lvItem);

                if (newItems == null)
                {
                    ThreadedListViewItem item = _noChildsPlaceHolder;
                    if (item == null)
                    {
                        item = new ThreadedListViewItemPlaceHolder(SR.FeedListNoChildsMessage)
                        {
                            Font = new Font(Font.FontFamily, Font.Size, FontStyle.Regular)
                        };
                    }
                    newItems = new[] { item };
                }

                if (newItems.Length > 1 && ListViewItemSorter != null)
                {
                    // sort new child entries according to listview sortorder
                    Array.Sort(newItems, ListViewItemSorter);
                }

                if (_showInGroups)
                {
                    APIEnableGrouping(false);
                }

                BeginUpdate();
                try
                {
                    lvItem.SetThreadState(true);

                    lock (Items)
                    {
                        foreach (var newListItem in newItems)
                        {
                            // check, if we have  all subitems for correct grouping
                            while (newListItem.SubItems.Count < Columns.Count)
                            {
                                newListItem.SubItems.Add(String.Empty);
                            }

                            newListItem.Parent = lvItem;
                            Items.Insert(paramItemIndex + 1, newListItem);
                            newListItem.IndentLevel = currentIndent + 1;

                            paramItemIndex++;
                        }
                    }
                }
                finally
                {
                    EndUpdate();
                }

                RedrawItems();

                if (_showInGroups)
                {
                    APIEnableGrouping(true);
                }

                // Make the last inserted subfolder visible, then the parent folder visible,
                // per default treeview behavior.
                try
                {
                    EnsureVisible(paramItemIndex - 1);
                    EnsureVisible(lvItem.Index);
                }
                catch (Exception ex)
                {
                    _log.Error("EnsureVisible() failed", ex);
                }

                if (activate)
                {
                    SelectedItems.Clear();
                    lvItem.Selected = true;
                    lvItem.Focused  = true;
                }
                else if (selIdxsCount > 0)
                {
//					foreach (int i in selIdxs) {
//						this.Items[i].Selected = true;
//					}
                }

                RaiseAfterExpandEvent(lvItem, newItems);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// The workhorse to collapse a threaded listview item
        /// </summary>
        /// <param name="lvItem"></param>
        internal void CollapseListViewItem(ThreadedListViewItem lvItem)
        {
            if (lvItem != null && lvItem.Expanded)
            {
                if (RaiseBeforeCollapseEventCancel(lvItem))
                {
                    lvItem.StateImageIndex = 0;
                    return;
                }

                int focusedItemIndex;
                if (FocusedItem == null)
                {
                    focusedItemIndex = lvItem.Index;
                }
                else
                {
                    focusedItemIndex = FocusedItem.Index;
                }

                BeginUpdate();
                try
                {
                    lvItem.SetThreadState(false);
                    int paramItemIndex = lvItem.Index;
                    int currentIndent  = lvItem.IndentLevel;
                    int nextIndex      = paramItemIndex + 1;

                    lock (Items)
                    {
                        while (nextIndex < base.Items.Count &&
                               ((ThreadedListViewItem)base.Items[nextIndex]).IndentLevel > currentIndent)
                        {
                            Items[nextIndex].Parent = null;
                            Items.RemoveAt(nextIndex);
                            if (nextIndex < focusedItemIndex)
                            {
                                focusedItemIndex = focusedItemIndex - 1;
                            }
                            else if (nextIndex == focusedItemIndex)
                            {
                                focusedItemIndex = paramItemIndex;
                            }
                        }
                    }

                    RaiseCollapseEvent(lvItem);
                }
                finally
                {
                    EndUpdate();
                }

                if (focusedItemIndex >= 0)
                {
                    ListViewItem lvi = base.Items[focusedItemIndex];
                    lvi.Focused  = true;
                    lvi.Selected = true;
                }
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Insert items as a replacement for a placeholder item inserted before.
        /// The placeholder item will be identified by the placeHolderTicket to be provided.
        /// </summary>
        /// <param name="placeHolderTicket">The unique placeholder item's ticket. (string)</param>
        /// <param name="newChildItems">ThreadedListViewItem array</param>
        /// <param name="sortOnInsert">True uses the current sort column and order to insert childs.
        /// Set to false, if you want to sort by your own.</param>
        /// <exception cref="ArgumentNullException">If placeHolderTicket is null or empty</exception>
        public void InsertItemsForPlaceHolder(string placeHolderTicket, ThreadedListViewItem[] newChildItems,
                                              bool sortOnInsert)
        {
            if (string.IsNullOrEmpty(placeHolderTicket))
            {
                throw new ArgumentNullException("placeHolderTicket");
            }

            ThreadedListViewItemPlaceHolder placeHolder = null;

            lock (Items)
            {
                for (int i = 0; i < Items.Count; i++)
                {
                    var p = Items[i] as ThreadedListViewItemPlaceHolder;
                    if (p != null)
                    {
                        // found one; check ticket
                        if (p.InsertionPointTicket.Equals(placeHolderTicket))
                        {
                            placeHolder = p;
                            break;
                        }
                    }
                }

                // the ThreadedListViewItemPlaceHolder to work on is not anymore displayed;
                // because of a refresh or user has collapsed the parent meanwhile
                if (placeHolder == null)
                {
                    return;
                }

                int parentItemIndex   = placeHolder.Index;
                int parentIndentLevel = placeHolder.IndentLevel;

                try
                {
                    BeginUpdate();

                    // remove the placeholder
                    Items.RemoveAt(parentItemIndex);

                    if (newChildItems == null || newChildItems.Length == 0)
                    {
                        ThreadedListViewItem item = _noChildsPlaceHolder;
                        if (item == null)
                        {
                            item = new ThreadedListViewItemPlaceHolder(SR.FeedListNoChildsMessage)
                            {
                                Font = new Font(Font.FontFamily, Font.Size, FontStyle.Regular)
                            };
                        }
                        newChildItems = new[] { item };
                    }

                    if (newChildItems.Length > 1 && _sorter.SortOrder != SortOrder.None && sortOnInsert)
                    {
                        // sort new child entries according to listview sortorder
                        Array.Sort(newChildItems, _sorter.GetComparer());
                    }

                    // now insert the new items
                    for (int i = 0; i < newChildItems.Length; i++)
                    {
                        ThreadedListViewItem newListItem = newChildItems[i];
                        newListItem.Parent = placeHolder.Parent;

                        // check, if we have  all subitems for correct grouping
                        while (newListItem.SubItems.Count < Columns.Count)
                        {
                            newListItem.SubItems.Add(String.Empty);
                        }

                        if (parentItemIndex < Items.Count)
                        {
                            //_log.Info("InsertItemsForPlaceHolder() insert at " + String.Format("{0}", parentItemIndex + 1));
                            Items.Insert(parentItemIndex, newListItem);
                        }
                        else
                        {
                            //_log.Info("InsertItemsForPlaceHolder() append.");
                            Items.Add(newListItem);
                        }

                        newListItem.IndentLevel = parentIndentLevel;
                        // only valid after the item is part of the listview items collection!
                        parentItemIndex++;
                    } //iterator.MoveNext
                }
                finally
                {
                    EndUpdate();
                }
            } //lock

            UpdateItems();
        }
Exemplo n.º 9
0
 public ThreadEventArgs(ThreadedListViewItem tlv) : base()
 {
     this._tlv = tlv;
 }
Exemplo n.º 10
0
 public ThreadCancelEventArgs(ThreadedListViewItem tlv, bool cancel) : base(cancel)
 {
     this._tlv = tlv;
 }
 public ListViewItemEventArgs(ThreadedListViewItem item)
 {
     mItem = item;
 }