Пример #1
0
 public ThemeDictionariesTreeItemViewModel(ITreeViewModel treeViewModel, TreeItemViewModel parent, IDictionary <object, object> themeDictionaries) : base(treeViewModel, parent)
 {
     foreach (var themeDictionary in themeDictionaries)
     {
         this.Children.Add(new ResourceDictionaryTreeItemViewModel(treeViewModel, this, (ResourceDictionary)themeDictionary.Value, themeDictionary.Key));
     }
 }
Пример #2
0
        private async Task <TagBuilder> CreateTreeViewTagAsync(ITreeViewModel model)
        {
            TagBuilder tagBuilder = new TagBuilder("li");

            tagBuilder.AddCssClass("treeview-item");
            tagBuilder.AddCssClass(LiClass);

            IHtmlContent innerContentWithModel = await htmlHelper.PartialAsync(ViewChild, model);

            tagBuilder.InnerHtml.AppendHtml(innerContentWithModel);

            if (model.Childs.Count > 0)
            {
                tagBuilder.AddCssClass("has-children");

                TagBuilder ul = new TagBuilder("ul");
                ul.AddCssClass(UlClass);
                ul.Attributes.Add("id", "treeview-childs-" + model.Key);
                foreach (ITreeViewModel child in model.Childs)
                {
                    TagBuilder childLi = await CreateTreeViewTagAsync(child);

                    ul.InnerHtml.AppendHtml(childLi);
                }
                tagBuilder.InnerHtml.AppendHtml(ul);
            }
            return(tagBuilder);
        }
Пример #3
0
        static IControl CreatePopScopeButton(ITreeViewModel treeViewModel)
        {
            var popScopeButton =
                treeViewModel.PopScopeCommand.IsEnabled.Select(
                    enabled => enabled
                                                ? Button.Create(
                        treeViewModel.PopScopeCommand,
                        state => Layout.StackFromTop(
                            Spacer.Medium,
                            Layout.StackFromLeft(
                                Arrow.WithShaft(RectangleEdge.Left, brush: Theme.Purple)
                                .WithSize(new Size <Points>(15, 7.5))
                                .CenterVertically(),
                                Spacer.Small,
                                Label.Create(
                                    text: treeViewModel.PopScopeLabel.AsText(),
                                    font: Theme.DefaultFont,
                                    color: Theme.DefaultText)
                                .CenterVertically())
                            .CenterHorizontally(),
                            Spacer.Medium))
                                                : Spacer.Medim).Switch();

            return(popScopeButton);
        }
Пример #4
0
 public TreeItemViewModel(
     ITreeViewModel treeViewViewModel,
     TreeItemViewModel parent)
 {
     this.TreeViewModel = treeViewViewModel;
     this.Parent        = parent;
 }
        public void Initialize(ITreeViewModel viewModel)
        {
            if (IsInitialized)
            {
                throw new Exception("Error : Attempting to initialize an already initialized list selection binding.");
            }

            Owner = viewModel;
            Timer = new Timer()
            {
                AutoReset = false,
                Interval  = 100,
            };
            Timer.Elapsed        += OnTimerElapsed;
            SelectionChangedScope = new Scope();
            SelectionSubscription = new Subscription()
            {
                Event = Selection,
                Token = Selection.Subscribe(o => OnSelectionChanged(), ThreadOption.PublisherThread)
            };

            foreach (var item in Owner.Items)
            {
                item.IsSelected = Selection.Value.Contains((T)item.Value);
            }

            IsInitialized = true;
        }
Пример #6
0
        /******************************************************************************************************
        ****************************************** Item Management *******************************************
        ******************************************************************************************************/


        /// <summary>
        /// Initializes this tree view model item instance in the context of the specified owner and parent.
        /// </summary>
        /// <param name="owner">The owner of this tree view model item.</param>
        /// <param name="parent">The tree view model item parent of this instance, or null if this tree view model item is a direct child of it's owner.</param>
        public void Initialize(ITreeViewModel owner, ITreeViewModelItem parent)
        {
            owner.AssertParameterNotNull(nameof(owner));

            if (IsInitialized)
            {
                throw new Exception("Error : Attempting to initialize a tree view model item instance that has already been initialized.");
            }

            Owner  = owner;
            Parent = parent;

            if (FallbackIcon == null)
            {
                FallbackIcon = Owner.IconManager.GetIconForType <T>();
            }

            if (Owner.ExpansionRetainingStrategy != TreeExpansionRetainingStrategy.None)
            {
                if (Owner.ExpansionRetainer == null)
                {
                    throw new Exception("Error : The owner of this tree view model item doesn't have an expansion retainer set while having a defined expansion retaining strategy.");
                }

                Owner.ExpansionRetainer.LoadExpansionState(this);
            }

            Owner.NotifyItemCreated(this);

            IsInitialized = true;
        }
 public ThemeDictionariesTreeItemViewModel(ITreeViewModel treeViewModel, TreeItemViewModel parent, IDictionary<object, object> themeDictionaries) : base(treeViewModel, parent)
 {
     foreach (var themeDictionary in themeDictionaries)
     {
         this.Children.Add(new ResourceDictionaryTreeItemViewModel(treeViewModel, this, (ResourceDictionary)themeDictionary.Value, themeDictionary.Key));
     }
 }
Пример #8
0
        /// <summary>
        /// Assign parent items on scroll.
        /// </summary>
        /// <param name="sender">Sender of event.</param>
        /// <param name="e">Event arguments.</param>
        private void ScrollChanged(object sender, ScrollChangedEventArgs e)
        {
            if (sender is ListBox listBox)
            {
                if (listBox.ItemContainerGenerator.Items == null || listBox.ItemContainerGenerator.Items.Count == 0)
                {
                    return;
                }

                int firstItem = (int)e.VerticalOffset;

                ITreeViewModel item = (ITreeViewModel)listBox.ItemContainerGenerator.Items[firstItem];

                var parentCollection = new List <object>();

                while (item.Parent is not null)
                {
                    item = item.Parent;
                    parentCollection.Insert(0, item);
                }

                if (listBox.Template.FindName("ParentsView", listBox) is ItemsControl parents)
                {
                    parents.ItemsSource = parentCollection;
                }
            }
        }
Пример #9
0
        public static T ToTreeView <T>(this List <T> collections, object rootNodeKey) where T : class, ITreeViewModel
        {
            if (collections == null || collections.Count == 0)
            {
                return(null);
            }
            T rootNode = ShallowCopy(collections.First());

            rootNode.Key = rootNodeKey;
            Dictionary <object, ITreeViewModel> treeViewModelTable = new Dictionary <object, ITreeViewModel>();

            foreach (T item in collections)
            {
                item.Childs = new List <ITreeViewModel>();
                treeViewModelTable[item.Key] = item;
            }

            foreach (T item in collections)
            {
                if (treeViewModelTable.Keys.Contains(item.ParentKey))
                {
                    ITreeViewModel parent = treeViewModelTable[item.ParentKey];
                    item.Parent = parent;
                    parent.Childs.Add(item);
                }
            }

            rootNode.Childs = collections.Where(x => x.Parent == null).Select(x => (ITreeViewModel)x).ToList();
            foreach (ITreeViewModel child in rootNode.Childs)
            {
                child.Parent = rootNode;
            }

            return(rootNode);
        }
Пример #10
0
        public StrategyViewModel(ITreeViewModel parent, StrategyModel model, MarketsModel markets, SettingModel settings)
        {
            _parent   = parent;
            Model     = model ?? throw new ArgumentNullException(nameof(model));
            _markets  = markets;
            _settings = settings;

            StartCommand                = new RelayCommand(() => DoStartCommand(), () => !IsBusy && !Active);
            StopCommand                 = new RelayCommand(() => DoStopCommand(), () => !IsBusy && Active);
            CloneCommand                = new RelayCommand(() => DoCloneStrategy(), () => !IsBusy);
            CloneAlgorithmCommand       = new RelayCommand(() => DoCloneAlgorithm(), () => !IsBusy && !string.IsNullOrEmpty(Model.AlgorithmLocation));
            ExportCommand               = new RelayCommand(() => DoExportStrategy(), () => !IsBusy);
            DeleteCommand               = new RelayCommand(() => DoDeleteStrategy(), () => !IsBusy);
            DeleteAllTracksCommand      = new RelayCommand(() => DoDeleteTracks(null), () => !IsBusy);
            DeleteSelectedTracksCommand = new RelayCommand <IList>(m => DoDeleteTracks(m), m => !IsBusy);
            UseParametersCommand        = new RelayCommand <IList>(m => DoUseParameters(m), m => !IsBusy);
            AddSymbolCommand            = new RelayCommand(() => DoAddSymbol(), () => !IsBusy);
            DeleteSymbolsCommand        = new RelayCommand <IList>(m => DoDeleteSymbols(m), m => !IsBusy && SelectedSymbol != null);
            ImportSymbolsCommand        = new RelayCommand(() => DoImportSymbols(), () => !IsBusy);
            ExportSymbolsCommand        = new RelayCommand <IList>(m => DoExportSymbols(m), trm => !IsBusy && SelectedSymbol != null);
            TrackDoubleClickCommand     = new RelayCommand <TrackViewModel>(m => DoSelectItem(m), m => !IsBusy);
            MoveUpSymbolsCommand        = new RelayCommand <IList>(m => OnMoveUpSymbols(m), m => !IsBusy && SelectedSymbol != null);
            MoveDownSymbolsCommand      = new RelayCommand <IList>(m => OnMoveDownSymbols(m), m => !IsBusy && SelectedSymbol != null);
            SortSymbolsCommand          = new RelayCommand(() => Symbols.Sort(), () => !IsBusy);
            MoveStrategyCommand         = new RelayCommand <ITreeViewModel>(m => OnMoveStrategy(m), m => !IsBusy);
            DropDownOpenedCommand       = new RelayCommand(() => DoDropDownOpenedCommand(), () => !IsBusy);

            Model.NameChanged          += StrategyNameChanged;
            Model.AlgorithmNameChanged += AlgorithmNameChanged;
            DataFromModel();

            Model.EndDate = DateTime.Now;
            Debug.Assert(IsUiThread(), "Not UI thread!");
        }
 public MergedDictionariesTreeItemViewModel(ITreeViewModel treeViewModel, TreeItemViewModel parent, IList<ResourceDictionary> mergedDictionaries)
     : base(treeViewModel, parent)
 {
     foreach (var mergedDictionary in mergedDictionaries)
     {
         this.Children.Add(new ResourceDictionaryTreeItemViewModel(treeViewModel, this, mergedDictionary));
     }
 }
Пример #12
0
 public MergedDictionariesTreeItemViewModel(ITreeViewModel treeViewModel, TreeItemViewModel parent, IList <ResourceDictionary> mergedDictionaries)
     : base(treeViewModel, parent)
 {
     foreach (var mergedDictionary in mergedDictionaries)
     {
         this.Children.Add(new ResourceDictionaryTreeItemViewModel(treeViewModel, this, mergedDictionary));
     }
 }
Пример #13
0
        public SymbolViewModel(ITreeViewModel parent, SymbolModel model)
        {
            _parent = parent;
            Model   = model;

            DeleteCommand = new RelayCommand(() => { }, () => false);
            StartCommand  = new RelayCommand(() => { }, () => false);
            StopCommand   = new RelayCommand(() => { }, () => false);
            UpdateCommand = new RelayCommand(() => DoLoadData(_parent as MarketViewModel), () => !IsBusy && _parent is MarketViewModel);
        }
Пример #14
0
 private ITreeViewModel GetParentWithRank(ITreeViewModel i, int rank)
 {
     if (i.Rank == rank)
     {
         return(i);
     }
     else
     {
         return(this.GetParentWithRank(i.Parent ?? throw new ArgumentNullException(), rank));
     }
 }
        public ResourceDictionaryTreeItemViewModel(
            ITreeViewModel treeViewModel,
            TreeItemViewModel parent,
            ResourceDictionary resourceDictionary,
            object key = null)
            : base(treeViewModel, parent)
        {
            this.QualifierString = String.Empty;

            if (key != null)
            {
                this.QualifierString += $" [{key}]";
            }

            if (resourceDictionary.Source != null)
            {
                this.QualifierString += $" Source: {resourceDictionary.Source}";
            }

            if (resourceDictionary.MergedDictionaries != null &&
                resourceDictionary.MergedDictionaries.Count > 0)
            {
                this.Children.Add(new MergedDictionariesTreeItemViewModel(treeViewModel, this, resourceDictionary.MergedDictionaries));
            }

            if (resourceDictionary.ThemeDictionaries != null &&
                resourceDictionary.ThemeDictionaries.Count > 0)
            {
                this.Children.Add(new ThemeDictionariesTreeItemViewModel(treeViewModel, null, resourceDictionary.ThemeDictionaries));
            }

            foreach (var kvp in resourceDictionary.ToList())
            {
                this.Properties.Add(new ResourceViewModel(kvp.Key, kvp.Value, resourceDictionary));
            }
        }
        public ResourceDictionaryTreeItemViewModel(
            ITreeViewModel treeViewModel,
            TreeItemViewModel parent,
            ResourceDictionary resourceDictionary,
            object key = null)
            : base(treeViewModel, parent)
        {
            this.QualifierString = String.Empty;

            if (key != null)
            {
                this.QualifierString += $" [{key}]";
            }

            if (resourceDictionary.Source != null)
            {
                this.QualifierString += $" Source: {resourceDictionary.Source}";
            }

            if (resourceDictionary.MergedDictionaries != null &&
                resourceDictionary.MergedDictionaries.Count > 0)
            {
                this.Children.Add(new MergedDictionariesTreeItemViewModel(treeViewModel, this, resourceDictionary.MergedDictionaries));
            }

            if (resourceDictionary.ThemeDictionaries != null &&
                resourceDictionary.ThemeDictionaries.Count > 0)
            {
                this.Children.Add(new ThemeDictionariesTreeItemViewModel(treeViewModel, null, resourceDictionary.ThemeDictionaries));
            }

            foreach (var kvp in resourceDictionary.ToList())
            {
                this.Properties.Add(new ResourceViewModel(kvp.Key, kvp.Value, resourceDictionary));
            }
        }
Пример #17
0
        public static IControl Create(ITreeViewModel model)
        {
            var rowHeight      = TreeRowView.Height;
            var hoverIndicator = model.PendingDrop.SelectPerElement(
                x => Point.Create(
                    Observable.Return(TreeRowView.GetIndentation(x.Depth + (x.DropPosition == DropPosition.Inside ? 1 : 0))),
                    Observable.Return <Points>((x.RowOffset + (x.DropPosition != DropPosition.Before ? 1 : 0)) * rowHeight)));

            var rowCount = model.TotalRowCount.Replay(1).RefCount();

            var visibleHeight = new BehaviorSubject <Points>(0);
            var contentHeight = visibleHeight.CombineLatest(rowCount, (vheight, rcount) => (Points)Math.Max(vheight, rcount * rowHeight)).Replay(1).RefCount();

            var flipy = ShouldFlip ? ((Func <IObservable <Points>, IObservable <Points> >)(logicalY => logicalY.CombineLatest(contentHeight, (ly, ch) => ch - ly))) : (y => y);

            var rowOffsetToTop = (Func <IObservable <int>, IObservable <Points> >)
                                     (rowOffset => flipy(
                                         rowOffset.Select(offset => new Points(rowHeight.Value * offset))));

            var top = RectangleEdge.Top.FlipVerticallyOnMac();
            //var down = ShouldFlip ? -1.0 : 1.0;
            //var scrollTargetRect =
            //	rowOffsetToTop(model.ScrollTarget)
            //	.Select(rowTop =>
            //		Rectangle.FromPositionSize<Points>(0, 0, 50, 0)
            //		.WithEdge(top, rowTop)
            //		.WithEdge(top.Opposite(), rowTop + rowHeight * down));

            var rowViews = model.VisibleRows
                           .CachePerElement(rowModel => CreateRow(rowModel, rowOffsetToTop))
                           .Replay(1)
                           .RefCount();

            var background =
                rowViews.SelectPerElement(x => x.Background).Layer();
            var foreground =
                rowViews.SelectPerElement(x => x.Foreground).Layer();
            var overlay =
                rowViews.SelectPerElement(x => x.Overlay).Layer();

            var width =
                rowViews.Select(
                    rows => rows.Select(row => row.Foreground.DesiredSize.Width)
                    .CombineLatest()
                    .Select(widths => widths.ConcatOne(0).Max()))
                .Switch()
                .DistinctUntilChanged();

            var treeView =
                Layout.Layer(background, foreground, overlay)
                .WithBackground(Theme.PanelBackground)
                .WithOverlay(InsertionRod.Create(hoverIndicator))
                .WithHeight(contentHeight)
                .WithWidth(width)
                .MakeScrollable(
                    darkTheme: Theme.IsDark,
                    // scrollToRectangle: scrollTargetRect,
                    onBoundsChanged: bounds =>
            {
                var rowTop             = bounds.Visible.GetEdge(top);
                rowTop                 = ShouldFlip ? bounds.Content.Height - rowTop : rowTop;
                var rowOffset          = (int)Math.Floor(rowTop / rowHeight);
                model.VisibleRowOffset = rowOffset;
                var maxVisibleRowCount = (int)Math.Ceiling(bounds.Visible.VerticalInterval.Length / rowHeight.Value) + 1;
                model.VisibleRowCount  = maxVisibleRowCount;
                visibleHeight.OnNext(bounds.Visible.Height);
            });

            // TODO: CAN'T GET LOCAL KEYS TO WORK PROPERLY
            //.OnKeyPressed(ModifierKeys.None, Key.Up, model.NavigateUpCommand, isGlobal: true)
            //.OnKeyPressed(ModifierKeys.None, Key.Down, model.NavigateDownCommand, isGlobal: true);

            return(CreatePopScopeButton(model).DockTop(fill: treeView));
        }
Пример #18
0
 public void AttachTreeView(ITreeViewModel treeViewModel)
 {
     _treeView = treeViewModel;
 }
Пример #19
0
 public ItemCollectionSource(ITreeViewModel treeViewModel)
 {
     this.TreeViewModel = treeViewModel ?? throw new ArgumentNullException(nameof(treeViewModel));
     this.TreeViewModel.CollectionChanged += (s, a) => this.InvokeCollectionChanged();
 }
Пример #20
0
 public void SetDataModel(ITreeViewModel m)
 {
     m.FillData(this);
 }
Пример #21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ChildPropertyChangedEventArgs"/> class.
 /// </summary>
 /// <param name="child">The model that contains the property that was changed.</param>
 /// <param name="propertyName">The name of the property that was changed.</param>
 public ChildPropertyChangedEventArgs(ITreeViewModel child, string?propertyName)
     : base(propertyName)
 {
     this.Child = child;
 }
Пример #22
0
 public ItemPathExpansionRetainer(ITreeViewModel owner)
 {
     Owner = owner;
 }
 public TreeItemViewModel(
     ITreeViewModel treeViewViewModel,
     TreeItemViewModel parent)
 {
     this.TreeViewModel = treeViewViewModel;
     this.Parent = parent;
 }
 public ReferencePathExpansionRetainer(ITreeViewModel owner)
 {
     Owner = owner;
 }
		public TypesTreeWindow(ITreeViewModel viewModel)
		{
			DataContext = viewModel;
			InitializeComponent();
		}