Can create, display, and delete tabs

This commit is contained in:
Timothy Baldridge 2022-01-29 15:32:46 -07:00
parent ebc3172f74
commit c26d8e4d98
14 changed files with 198 additions and 2 deletions

View File

@ -0,0 +1,23 @@
<TabItem x:Class="Wabbajack.App.Blazor.Browser.BrowserTabView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Wabbajack.App.Blazor.Browser"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<TabItem.Style>
<Style TargetType="TabItem" BasedOn="{StaticResource {x:Type TabItem}}"></Style>
</TabItem.Style>
<TabItem.Header>
<StackPanel Orientation="Horizontal">
<TextBlock FontSize="16" x:Name="HeaderText">_</TextBlock>
<Button Click="ButtonBase_OnClick">X</Button>
</StackPanel>
</TabItem.Header>
<Grid>
<local:BrowserView x:Name="Browser">
</local:BrowserView>
</Grid>
</TabItem>

View File

@ -0,0 +1,37 @@
using System;
using System.Reactive.Disposables;
using System.Windows;
using System.Windows.Controls;
using ReactiveUI;
namespace Wabbajack.App.Blazor.Browser;
public partial class BrowserTabView : IDisposable
{
private readonly CompositeDisposable _compositeDisposable;
public BrowserTabView(BrowserTabViewModel vm)
{
_compositeDisposable = new CompositeDisposable();
InitializeComponent();
Browser.Browser.Source = new Uri("http://www.google.com");
DataContext = vm;
vm.WhenAnyValue(vm => vm.HeaderText)
.BindTo(this, view => view.HeaderText.Text)
.DisposeWith(_compositeDisposable);
}
public void Dispose()
{
_compositeDisposable.Dispose();
}
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
var tc = (TabControl) this.Parent;
tc.Items.Remove(this);
this.Dispose();
}
}

View File

@ -0,0 +1,10 @@
using ReactiveUI.Fody.Helpers;
namespace Wabbajack.App.Blazor.Browser;
public class BrowserTabViewModel : ViewModel
{
[Reactive]
public string HeaderText { get; set; }
}

View File

@ -0,0 +1,16 @@
<reactiveUi:ReactiveUserControl x:TypeArguments="local:BrowserTabViewModel"
x:Class="Wabbajack.App.Blazor.Browser.BrowserView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Wabbajack.App.Blazor.Browser"
xmlns:wpf="clr-namespace:Microsoft.Web.WebView2.Wpf;assembly=Microsoft.Web.WebView2.Wpf"
xmlns:reactiveUi="http://reactiveui.net"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<wpf:WebView2 x:Name="Browser"></wpf:WebView2>
</Grid>
</reactiveUi:ReactiveUserControl>

View File

@ -0,0 +1,13 @@
using System.Windows.Controls;
using ReactiveUI;
namespace Wabbajack.App.Blazor.Browser;
public partial class BrowserView
{
public BrowserView()
{
InitializeComponent();
}
}

View File

@ -0,0 +1,8 @@
using ReactiveUI;
namespace Wabbajack.App.Blazor.Browser;
public class ViewModel : ReactiveObject, IActivatableViewModel
{
public ViewModelActivator Activator { get; } = new();
}

View File

@ -0,0 +1,11 @@
using Wabbajack.DTOs.Logins;
namespace Wabbajack.App.Blazor.Browser.ViewModels;
public class NexusLogin : BrowserTabViewModel
{
public NexusLogin()
{
HeaderText = "Nexus Login";
}
}

View File

@ -0,0 +1,3 @@
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<ReactiveUI />
</Weavers>

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. -->
<xs:element name="Weavers">
<xs:complexType>
<xs:all>
<xs:element name="ReactiveUI" minOccurs="0" maxOccurs="1" type="xs:anyType" />
</xs:all>
<xs:attribute name="VerifyAssembly" type="xs:boolean">
<xs:annotation>
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="VerifyIgnoreCodes" type="xs:string">
<xs:annotation>
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="GenerateXsd" type="xs:boolean">
<xs:annotation>
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>

View File

@ -10,7 +10,7 @@
ShowTitleBar="False"
Title="WABBAJACK" Height="750" Width="1200" MinHeight="750" MinWidth="1200">
<Grid Background="#121212" MouseDown="UIElement_OnMouseDown">
<TabControl>
<TabControl x:Name="Tabs">
<TabItem>
<TabItem.Header>
<TextBlock FontSize="16" Margin="0, 0, 8, 0">WABBAJACK 3.0.0</TextBlock>

View File

@ -1,16 +1,24 @@
using System;
using System.Reactive.Disposables;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using ReactiveUI;
using Wabbajack.App.Blazor.Browser;
using Wabbajack.App.Blazor.Messages;
using Wabbajack.App.Blazor.State;
namespace Wabbajack.App.Blazor;
public partial class MainWindow
public partial class MainWindow : IDisposable
{
private Point _lastPosition;
private readonly CompositeDisposable _compositeDisposable;
public MainWindow(IServiceProvider serviceProvider, IStateContainer stateContainer)
{
_compositeDisposable = new CompositeDisposable();
stateContainer.TaskBarStateObservable.Subscribe(state =>
{
Dispatcher.InvokeAsync(() =>
@ -21,6 +29,10 @@ public partial class MainWindow
});
});
MessageBus.Current.Listen<OpenBrowserTab>()
.Subscribe(OnOpenBrowserTab)
.DisposeWith(_compositeDisposable);
InitializeComponent();
BlazorWebView.Services = serviceProvider;
}
@ -29,6 +41,18 @@ public partial class MainWindow
{
this.DragMove();
}
private void OnOpenBrowserTab(OpenBrowserTab msg)
{
var tab = new BrowserTabView(msg.ViewModel);
Tabs.Items.Add(tab);
Tabs.SelectedItem = tab;
}
public void Dispose()
{
_compositeDisposable.Dispose();
}
}
// Required so compiler doesn't complain about not finding the type. [MC3050]

View File

@ -0,0 +1,13 @@
using Wabbajack.App.Blazor.Browser;
namespace Wabbajack.App.Blazor.Messages;
public class OpenBrowserTab
{
public BrowserTabViewModel ViewModel { get; set; }
public OpenBrowserTab(BrowserTabViewModel viewModel)
{
ViewModel = viewModel;
}
}

View File

@ -1,12 +1,21 @@
@page "/settings"
@using ReactiveUI
@using Wabbajack.App.Blazor.Browser.ViewModels
@using Wabbajack.App.Blazor.Messages
@namespace Wabbajack.App.Blazor.Pages
<div id="content">
<div class="resources">
<button onclick="@LoginToNexus">Login To Nexus</button>
</div>
</div>
@code {
public const string Route = "/settings";
public void LoginToNexus()
{
MessageBus.Current.SendMessage(new OpenBrowserTab(new NexusLogin()));
}
}

View File

@ -26,6 +26,9 @@
<PackageReference Include="NLog" Version="4.7.13" />
<PackageReference Include="NLog.Extensions.Logging" Version="1.7.4" />
<PackageReference Include="PInvoke.User32" Version="0.7.104" />
<PackageReference Include="ReactiveUI" Version="17.1.17" />
<PackageReference Include="ReactiveUI.Fody" Version="17.1.17" />
<PackageReference Include="ReactiveUI.WPF" Version="17.1.17" />
<PackageReference Include="Silk.NET.DXGI" Version="2.12.0" />
<PackageReference Include="System.Reactive" Version="5.0.0" />
</ItemGroup>