Example #1
0
        private void treeViewDrop(object sender, DragEventArgs e)
        {
            string[] files = e.Data.GetData(DataFormats.FileDrop) as string[];

            if (files == null || files.Length == 0)
            {
                return; // Nothing to add;
            }

            MenuEntry           selected = this.SelectedMenuEntry;
            MenuEntryCollection parent;

            if (selected == null)
            {
                parent = Settings.Default.Menu.Entries;
            }
            else
            {
                Submenu submenu = selected as Submenu;
                if (submenu == null)
                {
                    parent = selected.Parent;
                }
                else
                {
                    parent = submenu.MenuEntries;
                }
            }
            foreach (string file in files)
            {
                parent.Add(new Program
                {
                    Text = Path.GetFileNameWithoutExtension(file),
                    Path = file
                });
            }
        }
Example #2
0
        private void move(bool up)
        {
            MenuEntryCollection parent = this.Parent;

            if (parent == null)
            {
                return; // Unable to do anything
            }

            int index = parent.IndexOf(this);

            // The item is at the beginning of the collection
            if ((index == 0 && up) || (index == parent.Count - 1 && !up))
            {
                if (parent.Parent == null)
                {
                    return; // We can't move the element any further.
                }
                MenuEntryCollection parentParent = parent.Parent.Parent;
                if (parentParent == null)
                {
                    return; // There is nothing we can do.
                }
                int parentIndex = parentParent.IndexOf(parent.Parent);
                this.IsSelected = false;
                parent.Remove(this);
                if (up)
                {
                    parentParent.Insert(parentIndex, this);
                }
                else
                {
                    parentParent.Insert(parentIndex + 1, this);
                }
                this.IsSelected = true;
            }
            else // The element is somewhere in the parent collection and can be moved.
            {
                int delta = 1; // Increase the index by one.
                if (up)
                {
                    delta = -1; // Decrease the index by one.
                }

                Submenu moveInto = parent[index + delta] as Submenu;
                if (moveInto == null)
                {
                    parent.Move(index, index + delta);
                }
                else
                {
                    this.IsSelected = false;
                    parent.Remove(this);
                    moveInto.IsExpanded = true;
                    if (up)
                    {
                        moveInto.MenuEntries.Add(this);
                    }
                    else
                    {
                        moveInto.MenuEntries.Insert(0, this);
                    }
                    this.IsSelected = true;
                }
            }
        }