예제 #1
0
 public void Add(CategoryItemViewModel dragSource, CategoryItemViewModel dropTarget)
 {
     DoDrop(dragSource, dropTarget, () =>
     {
         if (dropTarget != null)
         {
             dropTarget.CategoryItem.Items.Add(dragSource.CategoryItem);
             dropTarget.Items.Add(dragSource);
         }
         else
         {
             ViewModelLocator.Locator.Main.Items.Add(dragSource);
         }
     });
 }
예제 #2
0
        private void Insert(CategoryItemViewModel dragSource, CategoryItemViewModel dropTarget, int indexModifier)
        {
            DoDrop(dragSource, dropTarget, () =>
            {
                if (dropTarget != null)
                {
                    if (dropTarget.Parent != null)
                    {
                        var parent = dropTarget.Parent;
                        var index  = parent.CategoryItem.Items.IndexOf(dropTarget.CategoryItem) + indexModifier;
                        if (index < 0)
                        {
                            index = 0;
                        }
                        else if (index > parent.CategoryItem.Items.Count)
                        {
                            index = parent.CategoryItem.Items.Count;
                        }

                        parent.CategoryItem.Items.Insert(index, dragSource.CategoryItem);
                        parent.Items.Insert(index, dragSource);

                        dragSource.Parent = parent;
                    }
                    else
                    {
                        var items = ViewModelLocator.Locator.Main.Items;
                        var index = items.IndexOf(dropTarget) + indexModifier;
                        if (index < 0)
                        {
                            index = 0;
                        }
                        else if (index > items.Count)
                        {
                            index = items.Count;
                        }

                        items.Insert(index, dragSource);
                    }
                }
                else
                {
                    ViewModelLocator.Locator.Main.Items.Add(dragSource);
                }
            });
        }
예제 #3
0
        public void ExecuteCreateCategoryCommand()
        {
            var civm = new CategoryItemViewModel(new CategoryItem
            {
                DisplayName = Resources.New + " " + Resources.Category
            }, null);

            Items.Add(civm);

            SelectedItem = civm;

            _telemetryService.TrackEvent(
                "Create",
                new Dictionary <string, string>
            {
                { "Type", "Category" }
            });
        }
예제 #4
0
        public void Drop(CategoryItemViewModel dragSource, CategoryItemViewModel dropTarget)
        {
            ViewModelLocator.Locator.Main.SuspendSave = true;

            // Prevent dropping a parent on its child.
            if (dropTarget != null)
            {
                if (dragSource.Items.GetFlatList(x => x.Items, x => x == dropTarget).Any())
                {
                    return;
                }
            }

            if (dragSource.Parent != null)
            {
                dragSource.Parent.CategoryItem.Items.Remove(dragSource.CategoryItem);
                dragSource.Parent.Items.Remove(dragSource);
                dragSource.Parent = null;
            }
            else
            {
                ViewModelLocator.Locator.Main.Items.Remove(dragSource);
            }

            if (dropTarget != null)
            {
                dropTarget.CategoryItem.Items.Add(dragSource.CategoryItem);
                dropTarget.Items.Add(dragSource);
                dragSource.Parent = dropTarget;
            }
            else
            {
                ViewModelLocator.Locator.Main.Items.Add(dragSource);
            }

            ViewModelLocator.Locator.Main.SuspendSave = false;
            ViewModelLocator.Locator.Main.SaveConnections();

            ViewModelLocator.Locator.Main.SelectedItem = dragSource;
        }
예제 #5
0
        private void DoDrop(
            CategoryItemViewModel dragSource,
            CategoryItemViewModel dropTarget,
            Action doDrop)
        {
            if (dragSource == null)
            {
                return;
            }

            // Prevent dropping a parent on its child.
            if (dropTarget != null)
            {
                if (dragSource.Items.GetFlatList(x => x.Items, x => x == dropTarget).Any())
                {
                    return;
                }
            }

            ViewModelLocator.Locator.Main.SuspendSave = true;

            // Remove the drag source from it's parent.
            if (dragSource.Parent != null)
            {
                dragSource.Parent.CategoryItem.Items.Remove(dragSource.CategoryItem);
                dragSource.Parent.Items.Remove(dragSource);
                dragSource.Parent = null;
            }
            else
            {
                ViewModelLocator.Locator.Main.Items.Remove(dragSource);
            }

            doDrop();

            ViewModelLocator.Locator.Main.SuspendSave = false;
            ViewModelLocator.Locator.Main.SaveConnections();

            ViewModelLocator.Locator.Main.SelectedItem = dragSource;
        }
예제 #6
0
        public CategoryItemViewModel(CategoryItem categoryItem, CategoryItemViewModel parent)
        {
            CategoryItem = categoryItem;
            Parent       = parent;

            if (CategoryItem.ConnectionSettings != null)
            {
                ConnectionSettings = new ConnectionSettingsViewModel(this);
                Properties         = ConnectionSettings;
            }
            else if (CategoryItem.Credentials != null)
            {
                Credentials = new CredentialsViewModel(this);
                Properties  = Credentials;
            }
            else
            {
                Properties = new GenericPropertiesViewModel(this);
            }

            Items = new ObservableCollection <CategoryItemViewModel>();
        }
예제 #7
0
        private CategoryItemViewModel[] LoadSettingsRecursive(IList <CategoryItem> items, CategoryItemViewModel parent)
        {
            if (items == null || items.Count == 0)
            {
                return(new CategoryItemViewModel[] { });
            }

            var civms = items.Select(x => new CategoryItemViewModel(x, parent)).ToArray();

            foreach (var civm in civms)
            {
                civm.Items.CollectionChanged += CollectionChanged;
                var children = LoadSettingsRecursive(civm.CategoryItem.Items, civm);
                children.ForEach(x => civm.Items.Add(x));
            }

            return(civms);
        }
예제 #8
0
 public void InsertAfter(CategoryItemViewModel dragSource, CategoryItemViewModel dropTarget)
 {
     Insert(dragSource, dropTarget, +1);
 }
예제 #9
0
 public void InsertBefore(CategoryItemViewModel dragSource, CategoryItemViewModel dropTarget)
 {
     Insert(dragSource, dropTarget, 0);
 }