89 lines
3.4 KiB
C#
89 lines
3.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Reactive.Disposables;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Forms.VisualStyles;
|
|
using Intromat.Interfaces;
|
|
using Intromat.Nodes.Code;
|
|
using Intromat.ViewModels;
|
|
using NodeNetwork.ViewModels;
|
|
using ReactiveUI;
|
|
|
|
namespace Intromat.Views.Editors
|
|
{
|
|
[TemplatePart(Name = nameof(_header), Type = typeof(EditorHeader))]
|
|
[TemplatePart(Name = nameof(_content), Type = typeof(Panel))]
|
|
public abstract class EditorViewBase<T> : ContentControl, IViewFor<T> where T : NodeEndpointEditorViewModel
|
|
{
|
|
protected EditorHeader _header = null!;
|
|
protected Panel _content = null!;
|
|
|
|
public static readonly DependencyProperty ViewModelProperty = DependencyProperty.Register(nameof(ViewModel),
|
|
typeof(T), typeof(EditorViewBase<T>), new PropertyMetadata(null));
|
|
|
|
protected EditorViewBase()
|
|
{
|
|
this.WhenActivated(d =>
|
|
{
|
|
this.Bind(ViewModel, vm => vm.Parent.Name, v => v._header._textBlockName.Text)
|
|
.DisposeWith(d);
|
|
|
|
if (ViewModel is IExpressionEditor expressionEditor)
|
|
{
|
|
if (expressionEditor.HasParentSource)
|
|
_header._comboBoxRelativeSource.Items.Add(ERelativeSource.Parent);
|
|
if (expressionEditor.HasInputSource)
|
|
_header._comboBoxRelativeSource.Items.Add(ERelativeSource.Input);
|
|
|
|
if (_header._comboBoxRelativeSource.Items.Count > 0)
|
|
_header._comboBoxRelativeSource.Items.Add(ERelativeSource.Custom);
|
|
else
|
|
_header._comboBoxRelativeSource.Visibility = Visibility.Collapsed;
|
|
|
|
this.Bind(expressionEditor, vm => vm.RelativeSource, v => v._header._comboBoxRelativeSource.SelectedItem)
|
|
.DisposeWith(d);
|
|
|
|
if (expressionEditor.CodeGenPort.PortType == EPortType.None)
|
|
{
|
|
_header._checkBoxPortVisible.Visibility = Visibility.Collapsed;
|
|
}
|
|
else
|
|
{
|
|
this.Bind(expressionEditor, vm => vm.CodeGenPort.IsPortVisible, v => v._header._checkBoxPortVisible.IsChecked)
|
|
.DisposeWith(d);
|
|
this.OneWayBind(expressionEditor, vm => vm.CodeGenPort.IsPortVisible, v => v._content.Visibility, portVisible => portVisible ? Visibility.Collapsed : Visibility.Visible)
|
|
.DisposeWith(d);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
_header._comboBoxRelativeSource.Visibility = Visibility.Collapsed;
|
|
}
|
|
});
|
|
}
|
|
|
|
public override void OnApplyTemplate()
|
|
{
|
|
base.OnApplyTemplate();
|
|
_header = (EditorHeader)GetTemplateChild(nameof(_header))!;
|
|
_content = (Panel)GetTemplateChild(nameof(_content))!;
|
|
}
|
|
|
|
public T? ViewModel
|
|
{
|
|
get => (T?)GetValue(ViewModelProperty);
|
|
set => SetValue(ViewModelProperty, value);
|
|
}
|
|
|
|
object? IViewFor.ViewModel
|
|
{
|
|
get => ViewModel;
|
|
set => ViewModel = (T?)value;
|
|
}
|
|
}
|
|
}
|