port from perforce
This commit is contained in:
84
intromat/Intromat/Views/MainWindow.xaml.cs
Normal file
84
intromat/Intromat/Views/MainWindow.xaml.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Windows;
|
||||
using Intromat.Graphics;
|
||||
using Intromat.ViewModels;
|
||||
using Microsoft.Win32;
|
||||
using ReactiveUI;
|
||||
using Splat;
|
||||
|
||||
namespace Intromat.Views
|
||||
{
|
||||
public partial class MainWindow : IViewFor<MainViewModel>
|
||||
{
|
||||
public static readonly DependencyProperty ViewModelProperty = DependencyProperty.Register(nameof(ViewModel),
|
||||
typeof(MainViewModel), typeof(MainWindow), new PropertyMetadata(null));
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
var dxHost = Locator.Current.GetService<DxHost>()!;
|
||||
this.WhenActivated(d =>
|
||||
{
|
||||
dxHost.Load(this);
|
||||
this.Events().Unloaded.Subscribe(_ => dxHost.Unload());
|
||||
|
||||
this.OneWayBind(ViewModel, vm => vm.PropertiesContext, v => v._propertiesView.ViewModel).DisposeWith(d);
|
||||
this.OneWayBind(ViewModel, vm => vm.Preview2dContext, v => v._preview2dView.ViewModel).DisposeWith(d);
|
||||
this.OneWayBind(ViewModel, vm => vm.Preview3dContext, v => v._preview3dView.ViewModel).DisposeWith(d);
|
||||
//this.OneWayBind(ViewModel, vm => vm.CodePreview, v => v._codePreviewView.ViewModel).DisposeWith(d);
|
||||
|
||||
Debug.Assert(ViewModel != null, nameof(ViewModel) + " != null");
|
||||
ViewModel.OpenProjectFile.RegisterHandler(interaction =>
|
||||
{
|
||||
FileDialog dialog;
|
||||
if (interaction.Input)
|
||||
dialog = new OpenFileDialog();
|
||||
else
|
||||
dialog = new SaveFileDialog();
|
||||
|
||||
dialog.FileName = "network.xml";
|
||||
dialog.AddExtension = true;
|
||||
dialog.DereferenceLinks = true;
|
||||
dialog.DefaultExt = "json";
|
||||
|
||||
interaction.SetOutput(dialog.ShowDialog() ?? false ? dialog.FileName : null);
|
||||
});
|
||||
|
||||
ViewModel.SelectName.RegisterHandler(interaction =>
|
||||
{
|
||||
interaction.SetOutput(UserInputWindow.Show(this, interaction.Input));
|
||||
});
|
||||
|
||||
ViewModel.SelectTypeAndFileName.RegisterHandler(interaction =>
|
||||
{
|
||||
interaction.SetOutput(NewFileWindow.Show(this, ViewModel));
|
||||
});
|
||||
|
||||
_dockingManager.DocumentsSource = ViewModel.Files;
|
||||
this.OneWayBind(ViewModel, vm => vm.Explorer, v => v._explorerView.ViewModel).DisposeWith(d);
|
||||
this.Bind(ViewModel, vm => vm.ActiveFile, v => v._dockingManager.ActiveContent).DisposeWith(d);
|
||||
this.OneWayBind(ViewModel, vm => vm.NodeList, v => v._nodeList.ViewModel).DisposeWith(d);
|
||||
this.OneWayBind(ViewModel, vm => vm.UndoRedo, v => v._undoRedoView.ViewModel).DisposeWith(d);
|
||||
this.OneWayBind(ViewModel, vm => vm.LoadProject, v => v._openButton.Command).DisposeWith(d);
|
||||
this.OneWayBind(ViewModel, vm => vm.SaveProject, v => v._saveButton.Command).DisposeWith(d);
|
||||
});
|
||||
|
||||
ViewModel = new MainViewModel();
|
||||
}
|
||||
|
||||
public MainViewModel? ViewModel
|
||||
{
|
||||
get => (MainViewModel?)GetValue(ViewModelProperty);
|
||||
set => SetValue(ViewModelProperty, value);
|
||||
}
|
||||
|
||||
object? IViewFor.ViewModel
|
||||
{
|
||||
get => ViewModel;
|
||||
set => ViewModel = (MainViewModel?)value;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user