Skip to content

Commit

Permalink
Add inline dialog in Avalonia
Browse files Browse the repository at this point in the history
  • Loading branch information
aelij committed Aug 2, 2023
1 parent bad133b commit d90b623
Show file tree
Hide file tree
Showing 17 changed files with 351 additions and 260 deletions.
3 changes: 2 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<PackageVersion Include="Avalonia.ThemeManager" Version="$(AvaloniaVersion)" />
<PackageVersion Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageVersion Include="AvalonLibrary" Version="3.0.0" />
<PackageVersion Include="DialogHost.Avalonia" Version="0.7.5" />
<PackageVersion Include="Dirkster.AvalonDock" Version="4.70.3" />
<PackageVersion Include="Dock.Avalonia" Version="11.0.0" />
<PackageVersion Include="Dock.Model.Avalonia" Version="11.0.0" />
Expand Down Expand Up @@ -49,4 +50,4 @@
<PackageVersion Include="Xunit.StaFact" Version="1.1.11" />
<PackageVersion Include="xunit" Version="2.5.0" />
</ItemGroup>
</Project>
</Project>
47 changes: 47 additions & 0 deletions src/RoslynPad.Avalonia/App.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
xmlns:codeAnalysis="clr-namespace:Microsoft.CodeAnalysis;assembly=Microsoft.CodeAnalysis"
xmlns:codeActions="clr-namespace:Microsoft.CodeAnalysis.CodeActions;assembly=Microsoft.CodeAnalysis.Workspaces"
xmlns:codeFixes="clr-namespace:RoslynPad.Roslyn.CodeFixes;assembly=RoslynPad.Roslyn"
xmlns:dialogHostAvalonia="clr-namespace:DialogHostAvalonia;assembly=DialogHost.Avalonia"
RequestedThemeVariant="Light">
<Application.Styles>
<FluentTheme />
<DockFluentTheme />
<dialogHostAvalonia:DialogHostStyles />
<StyleInclude Source="avares://AvaloniaEdit/Themes/Fluent/AvaloniaEdit.xaml" />

<Style Selector="cc|CompletionList">
Expand All @@ -32,6 +34,51 @@
</ControlTemplate>
</Setter>
</Style>

<Style Selector="TextBlock.Title">
<Setter Property="FontSize" Value="16" />
</Style>

<Style Selector="DataValidationErrors">
<Setter Property="Template">
<ControlTemplate>
<DockPanel LastChildFill="True">
<ContentControl DockPanel.Dock="Right"
ContentTemplate="{TemplateBinding ErrorTemplate}"
DataContext="{TemplateBinding Owner}"
Content="{Binding (DataValidationErrors.Errors)}"
IsVisible="{Binding (DataValidationErrors.HasErrors)}"/>
<ContentPresenter Name="PART_ContentPresenter"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding CornerRadius}"
ContentTemplate="{TemplateBinding ContentTemplate}"
Content="{TemplateBinding Content}"
Padding="{TemplateBinding Padding}"/>
</DockPanel>
</ControlTemplate>
</Setter>
<Setter Property="ErrorTemplate">
<DataTemplate>
<Canvas Width="14" Height="14" Margin="4 0 1 0"
Background="Transparent">
<Canvas.Styles>
<Style Selector="ToolTip">
<Setter Property="BorderBrush" Value="Red"/>
</Style>
</Canvas.Styles>
<ToolTip.Tip>
<ItemsControl ItemsSource="{Binding}"/>
</ToolTip.Tip>
<Path Data="M14,7 A7,7 0 0,0 0,7 M0,7 A7,7 0 1,0 14,7 M7,3l0,5 M7,9l0,2"
Stroke="Red"
StrokeThickness="2"/>
</Canvas>
</DataTemplate>
</Setter>
</Style>

</Application.Styles>
<Application.DataTemplates>

Expand Down
1 change: 0 additions & 1 deletion src/RoslynPad.Avalonia/DocumentTreeView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
xmlns:roslynPad="using:RoslynPad"
xmlns:roslyn="clr-namespace:Microsoft.CodeAnalysis;assembly=Microsoft.CodeAnalysis"
xmlns:ui="using:RoslynPad.UI"
Design.Height="300"
x:Class="RoslynPad.DocumentTreeView">
<UserControl.Styles>

Expand Down
82 changes: 42 additions & 40 deletions src/RoslynPad.Avalonia/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
x:Class="RoslynPad.MainWindow"
xmlns:AvalonEdit="clr-namespace:AvaloniaEdit;assembly=AvaloniaEdit"
xmlns:local="clr-namespace:RoslynPad;assembly=RoslynPad"
xmlns:converters="clr-namespace:RoslynPad.ValueConverters;assembly=RoslynPad"
xmlns:roslyn="clr-namespace:Microsoft.CodeAnalysis;assembly=Microsoft.CodeAnalysis"
xmlns:ui="clr-namespace:RoslynPad.UI;assembly=RoslynPad.Common.UI"
xmlns:dialogHost="clr-namespace:DialogHostAvalonia;assembly=DialogHost.Avalonia"
MinWidth="500"
MinHeight="300"
Title="{Binding WindowTitle, Mode=OneTime}"
Expand All @@ -25,56 +25,58 @@
<KeyBinding Gesture="Ctrl+Shift+O"
Command="{Binding ToggleOptimizationCommand, Mode=OneTime}" />
</Window.KeyBindings>
<DockPanel>
<dialogHost:DialogHost x:Name="DiaglogHost" Identifier="Main" CloseOnClickAway="True" DisableOpeningAnimation="True">
<DockPanel>

<Border Padding="3"
Margin="1"
Background="#eebbbb"
DockPanel.Dock="Bottom"
IsVisible="{Binding HasError}">
<DockPanel LastChildFill="False">
<TextBlock VerticalAlignment="Center"
Text="{Binding LastError.Message}" />
</DockPanel>
</Border>
<Border Padding="3"
Margin="1"
Background="#eebbbb"
DockPanel.Dock="Bottom"
IsVisible="{Binding HasError}">
<DockPanel LastChildFill="False">
<TextBlock VerticalAlignment="Center"
Text="{Binding LastError.Message}" />
</DockPanel>
</Border>

<DockControl x:Name="Dock" InitializeLayout="True" InitializeFactory="True">
<DockControl.Factory>
<Factory />
</DockControl.Factory>
<DockControl x:Name="Dock" InitializeLayout="True" InitializeFactory="True">
<DockControl.Factory>
<Factory />
</DockControl.Factory>

<RootDock x:Name="Root" Id="Root" IsCollapsable="False" DefaultDockable="{Binding #MainLayout}">
<RootDock x:Name="Root" Id="Root" IsCollapsable="False" DefaultDockable="{Binding #MainLayout}">

<ProportionalDock x:Name="MainLayout" Id="MainLayout" Orientation="Horizontal">
<ProportionalDock x:Name="MainLayout" Id="MainLayout" Orientation="Horizontal">

<ToolDock x:Name="LeftPane" Id="LeftPane" Proportion="0.25" Alignment="Left">
<Tool x:Name="Documents" Id="Documents" Title="Documents" x:DataType="Tool" CanFloat="False" CanPin="True" CanClose="False">
<local:DocumentTreeView x:Name="DocumentTreeView" DataContext="{Binding #This.DataContext}" />
</Tool>
</ToolDock>
<ToolDock x:Name="LeftPane" Id="LeftPane" Proportion="0.25" Alignment="Left">
<Tool x:Name="Documents" Id="Documents" Title="Documents" x:DataType="Tool" CanFloat="False" CanPin="True" CanClose="False">
<local:DocumentTreeView x:Name="DocumentTreeView" DataContext="{Binding #This.DataContext}" />
</Tool>
</ToolDock>

<ProportionalDockSplitter x:Name="LeftSplitter" Id="LeftSplitter" />
<ProportionalDockSplitter x:Name="LeftSplitter" Id="LeftSplitter" />

<ProportionalDock x:Name="MainPane" Id="MainPane" Orientation="Vertical">
<ProportionalDock x:Name="MainPane" Id="MainPane" Orientation="Vertical">

<DocumentDock x:Name="DocumentsPane" Id="DocumentsPane">
<DocumentDock.DocumentTemplate>
<DocumentTemplate>
<local:DocumentView DataContext="{Binding DataContext}" />
</DocumentTemplate>
</DocumentDock.DocumentTemplate>
<Document x:Name="NewDoc" Id="NewDoc" Title="Home" x:DataType="Document" CanClose="False" CanFloat="False">
<local:NewDocumentView DataContext="{Binding #This.DataContext}" />
</Document>
</DocumentDock>
<DocumentDock x:Name="DocumentsPane" Id="DocumentsPane">
<DocumentDock.DocumentTemplate>
<DocumentTemplate>
<local:DocumentView DataContext="{Binding DataContext}" />
</DocumentTemplate>
</DocumentDock.DocumentTemplate>
<Document x:Name="NewDoc" Id="NewDoc" Title="Home" x:DataType="Document" CanClose="False" CanFloat="False">
<local:NewDocumentView DataContext="{Binding #This.DataContext}" />
</Document>
</DocumentDock>

</ProportionalDock>
</ProportionalDock>

</ProportionalDock>
</RootDock>
</ProportionalDock>
</RootDock>

</DockControl>
</DockControl>

</DockPanel>
</DockPanel>
</dialogHost:DialogHost>

</Window>
6 changes: 1 addition & 5 deletions src/RoslynPad.Avalonia/RoslynPad.Avalonia.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<ItemGroup>
<PackageReference Include="Avalonia.Desktop" />
<PackageReference Include="Avalonia.ThemeManager" />
<PackageReference Include="DialogHost.Avalonia" />
<PackageReference Include="Dock.Avalonia" />
<PackageReference Include="Dock.Model.Avalonia" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" />
Expand All @@ -22,9 +23,4 @@
<ProjectReference Include="..\RoslynPad.Common.UI\RoslynPad.Common.UI.csproj" />
<ProjectReference Include="..\RoslynPad.Editor.Avalonia\RoslynPad.Editor.Avalonia.csproj" />
</ItemGroup>
<ItemGroup>
<Compile Update="NewDocumentView.axaml.cs">
<DependentUpon>NewDocumentView.axaml</DependentUpon>
</Compile>
</ItemGroup>
</Project>
39 changes: 39 additions & 0 deletions src/RoslynPad.Avalonia/SaveDocumentDialog.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:RoslynPad;assembly=RoslynPad"
x:Class="RoslynPad.SaveDocumentDialog"
MinWidth="300"
BorderThickness="1"
BorderBrush="Gray"
Background="White">
<StackPanel Margin="10">
<TextBlock Text="Save Document"
Classes="Title" />
<TextBox Name="DocumentTextBox"
KeyDown="DocumentText_KeyDown"
Text="{Binding DocumentName}"
IsEnabled="{Binding AllowNameEdit}"
MaxLength="200"
Margin="0,10,0,0" />
<StackPanel HorizontalAlignment="Right"
Orientation="Horizontal"
Margin="50,30,0,0">
<Button Name="OverwriteButton"
BorderBrush="Red"
IsVisible="false"
Content="_Overwrite"
Click="Overwrite_Click"/>
<Button IsDefault="True"
Name="SaveButton"
Content="_Save"
Click="Save_Click" />
<Button Content="_Don't Save"
IsVisible="{Binding ShowDontSave}"
Name="DontSaveButton"
Click="DoNotSave_Click" />
<Button Content="_Cancel"
IsCancel="True"
Click="Cancel_Click" />
</StackPanel>
</StackPanel>
</UserControl>
Loading

0 comments on commit d90b623

Please sign in to comment.