Skip to content

Commit 4826316

Browse files
committed
Window fixes
1 parent 2668cd3 commit 4826316

File tree

8 files changed

+65
-180
lines changed

8 files changed

+65
-180
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using RazorLight;
2+
3+
namespace GCodeRazor.EngineBuilder
4+
{
5+
public static class Builder
6+
{
7+
public static RazorLightEngine GetBuilder()
8+
{
9+
var engine = new RazorLightEngineBuilder()
10+
// required to have a default RazorLightProject type,
11+
// but not required to create a template from string.
12+
.UseEmbeddedResourcesProject(typeof(EmptyModel))
13+
.SetOperatingAssembly(typeof(EmptyModel).Assembly)
14+
.UseMemoryCachingProvider()
15+
.Build();
16+
17+
return engine;
18+
}
19+
}
20+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace GCodeRazor.EngineBuilder
2+
{
3+
class EmptyModel
4+
{
5+
}
6+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="RazorLight" Version="2.0.0-rc.3" />
9+
</ItemGroup>
10+
11+
</Project>

src/GCodeRazor.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HL", "HL\HL.csproj", "{724C
99
EndProject
1010
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TextEditLib", "TextEditLib\TextEditLib.csproj", "{220F6F00-DCF0-4DC0-921D-691F6843D45C}"
1111
EndProject
12+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GCodeRazor.EngineBuilder", "GCodeRazor.Compiler\GCodeRazor.EngineBuilder.csproj", "{ABE5E18E-63EA-40CE-9A0A-65B80F052FDA}"
13+
EndProject
1214
Global
1315
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1416
Debug|Any CPU = Debug|Any CPU
@@ -27,6 +29,10 @@ Global
2729
{220F6F00-DCF0-4DC0-921D-691F6843D45C}.Debug|Any CPU.Build.0 = Debug|Any CPU
2830
{220F6F00-DCF0-4DC0-921D-691F6843D45C}.Release|Any CPU.ActiveCfg = Release|Any CPU
2931
{220F6F00-DCF0-4DC0-921D-691F6843D45C}.Release|Any CPU.Build.0 = Release|Any CPU
32+
{ABE5E18E-63EA-40CE-9A0A-65B80F052FDA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33+
{ABE5E18E-63EA-40CE-9A0A-65B80F052FDA}.Debug|Any CPU.Build.0 = Debug|Any CPU
34+
{ABE5E18E-63EA-40CE-9A0A-65B80F052FDA}.Release|Any CPU.ActiveCfg = Release|Any CPU
35+
{ABE5E18E-63EA-40CE-9A0A-65B80F052FDA}.Release|Any CPU.Build.0 = Release|Any CPU
3036
EndGlobalSection
3137
GlobalSection(SolutionProperties) = preSolution
3238
HideSolutionNode = FALSE

src/GCodeRazor/App.xaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:local="clr-namespace:CustomWindow"
55
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
6+
xmlns:ui="http://schemas.modernwpf.com/2019"
67
StartupUri="MainWindow.xaml">
78
<Application.Resources>
89
<ResourceDictionary>
910
<ResourceDictionary.MergedDictionaries>
11+
<ui:ThemeResources />
12+
<ui:XamlControlsResources />
1013
<materialDesign:BundledTheme BaseTheme="Dark" PrimaryColor="DeepPurple" SecondaryColor="Lime" />
1114
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
1215
</ResourceDictionary.MergedDictionaries>

src/GCodeRazor/GCodeRazor.csproj

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,21 @@
152152
<PackageReference Include="MaterialDesignThemes">
153153
<Version>3.1.3</Version>
154154
</PackageReference>
155+
<PackageReference Include="ModernWpfUI">
156+
<Version>0.9.4</Version>
157+
</PackageReference>
155158
<PackageReference Include="Newtonsoft.Json">
156159
<Version>12.0.3</Version>
157160
</PackageReference>
158161
<PackageReference Include="RazorLight">
159-
<Version>2.0.0-beta9</Version>
162+
<Version>2.0.0-rc.3</Version>
160163
</PackageReference>
161164
</ItemGroup>
162165
<ItemGroup>
166+
<ProjectReference Include="..\GCodeRazor.Compiler\GCodeRazor.EngineBuilder.csproj">
167+
<Project>{abe5e18e-63ea-40ce-9a0a-65b80f052fda}</Project>
168+
<Name>GCodeRazor.EngineBuilder</Name>
169+
</ProjectReference>
163170
<ProjectReference Include="..\HL\HL.csproj">
164171
<Project>{724c5c4d-0cb9-44bb-969c-632f6beb83de}</Project>
165172
<Name>HL</Name>

src/GCodeRazor/MainWindow.xaml

Lines changed: 10 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,29 @@
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:ui="http://schemas.modernwpf.com/2019"
6+
ui:WindowHelper.UseModernWindowStyle="True"
7+
ui:TitleBar.ExtendViewIntoTitleBar="True"
8+
ui:TitleBar.IsBackButtonVisible="False"
59
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
610
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
711
xmlns:avEditEx="clr-namespace:TextEditLib;assembly=TextEditLib"
812
mc:Ignorable="d"
9-
WindowStyle="None"
10-
Title="G-Code Razor" Height="550" Width="850"
11-
StateChanged="Window_StateChanged" LocationChanged="Window_LocationChanged"
13+
Title="G-Code Razor" Height="550" Width="850"
1214
UseLayoutRounding="True"
1315
TextElement.Foreground="{DynamicResource MaterialDesignBody}"
1416
TextOptions.TextFormattingMode="Ideal"
1517
TextOptions.TextRenderingMode="Auto"
1618
Background="{DynamicResource MaterialDesignPaper}"
1719
FontFamily="{DynamicResource MaterialDesignFont}"
1820
>
19-
<WindowChrome.WindowChrome>
20-
<WindowChrome CaptionHeight="0" ResizeBorderThickness="5"/>
21-
</WindowChrome.WindowChrome>
2221
<Border Name="main" BorderThickness="0" BorderBrush="Black" Margin="0">
2322
<DockPanel>
2423
<!-- Title Bar Area -->
2524
<Border Name="border" DockPanel.Dock="Top" Height="32">
2625

2726
<Grid>
28-
<Grid Background="Black" HorizontalAlignment="Stretch" Margin="0,0,296,0" PreviewMouseDown="System_MouseDown" PreviewMouseMove="System_MouseMove">
27+
<Grid Background="Black" HorizontalAlignment="Stretch" Margin="0,0,296,0">
2928
<Image VerticalAlignment="Center" Margin="7 4 7 4" HorizontalAlignment="Left" DockPanel.Dock="Left" Source="logo.png" Width="30" ></Image>
3029
<TextBlock VerticalAlignment="Center" Margin="40 0 0 0" Foreground="White" FontSize="19" Text="{Binding Title, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}}"/>
3130
</Grid>
@@ -59,54 +58,12 @@
5958
</StackPanel.Resources>
6059

6160
<Grid Width="160" Background="#FF252525">
62-
<Button x:Name="SeeExampleButton" Width="160" Style="{StaticResource systemButton}" Click="SeeExamplesButtonPressed">
63-
<Label FontSize="20" x:Name="SeeExamplesLabel">See Examples</Label>
64-
</Button>
61+
<ui:TitleBarButton x:Name="SeeExampleButton" Width="160" Style="{StaticResource systemButton}" Click="SeeExamplesButtonPressed">
62+
<Label FontSize="20" x:Name="SeeExamplesLabel" FontFamily="{DynamicResource MaterialDesignFont}">See Examples</Label>
63+
</ui:TitleBarButton>
6564
</Grid>
6665

67-
<Button Click="Mimimize_Click" Style="{StaticResource systemButton}">
68-
<Rectangle Width="11"
69-
Stroke="white"
70-
StrokeThickness="1"/>
71-
</Button>
72-
73-
<Button Click="Maximize_Click" Style="{StaticResource systemButton}">
74-
<Grid>
75-
<Rectangle Name="rectMax" Width="10" Height="10"
76-
Stroke="white"
77-
StrokeThickness="1"/>
78-
<Canvas Name="rectMin" Visibility="Hidden" RenderOptions.EdgeMode="Aliased">
79-
<Polyline Points="2.375,2 2.375,0.375 10.625,0.375 10.625,8.625 9,8.625"
80-
StrokeThickness="0.75" Stroke="white" RenderOptions.EdgeMode="Aliased" RenderOptions.BitmapScalingMode="HighQuality"/>
81-
<Rectangle Width="9" Height="9"
82-
Stroke="white"
83-
StrokeThickness="1" Margin="0,2,2,0" SnapsToDevicePixels="True" RenderOptions.EdgeMode="Aliased" RenderOptions.BitmapScalingMode="HighQuality" />
84-
</Canvas>
85-
</Grid>
86-
</Button>
87-
88-
<Button Click="Close_Click">
89-
<Button.Style>
90-
<Style TargetType="Button" BasedOn="{StaticResource systemButton}">
91-
<Style.Triggers>
92-
<Trigger Property="Button.IsMouseOver" Value="True">
93-
<Setter Property="Button.Background" Value="#E81123" />
94-
</Trigger>
95-
</Style.Triggers>
96-
<Setter Property="Button.Background" Value="black" />
97-
</Style>
98-
</Button.Style>
99-
<Canvas Height="25" Width="35">
100-
<Line
101-
X1="12" Y1="8"
102-
X2="22" Y2="18"
103-
Stroke="white" StrokeThickness="1"/>
104-
<Line
105-
X1="12" Y1="18"
106-
X2="22" Y2="8"
107-
Stroke="white" StrokeThickness="1"/>
108-
</Canvas>
109-
</Button>
66+
<Grid Width="140"></Grid>
11067

11168
</StackPanel>
11269
</Grid>

src/GCodeRazor/MainWindow.xaml.cs

Lines changed: 1 addition & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@ public partial class MainWindow : Window
3333
private bool hasChanged = true;
3434
private bool isLoading = false;
3535
private string oldText = null;
36-
3736
private bool isShowingExamples;
38-
private Point startPos;
39-
System.Windows.Forms.Screen[] screens = System.Windows.Forms.Screen.AllScreens;
4037

4138
public MainWindow()
4239
{
@@ -78,121 +75,6 @@ public MainWindow()
7875
BuildExample(Serializer.GetExamples());
7976
}
8077

81-
private void InputArea_Loaded(object sender, RoutedEventArgs e)
82-
{
83-
throw new NotImplementedException();
84-
}
85-
86-
private void Window_LocationChanged(object sender, EventArgs e)
87-
{
88-
int sum = 0;
89-
foreach (var item in screens)
90-
{
91-
sum += item.WorkingArea.Width;
92-
if (sum >= this.Left + this.Width / 2)
93-
{
94-
this.MaxHeight = item.WorkingArea.Height + 7;
95-
break;
96-
}
97-
}
98-
}
99-
100-
private void System_MouseDown(object sender, MouseButtonEventArgs e)
101-
{
102-
if (e.ChangedButton == MouseButton.Left)
103-
{
104-
if (e.ClickCount >= 2)
105-
{
106-
this.WindowState = (this.WindowState == WindowState.Normal) ? WindowState.Maximized : WindowState.Normal;
107-
}
108-
else
109-
{
110-
startPos = e.GetPosition(null);
111-
}
112-
}
113-
else if (e.ChangedButton == MouseButton.Right)
114-
{
115-
var pos = PointToScreen(e.GetPosition(this));
116-
IntPtr hWnd = new System.Windows.Interop.WindowInteropHelper(this).Handle;
117-
IntPtr hMenu = GetSystemMenu(hWnd, false);
118-
int cmd = TrackPopupMenu(hMenu, 0x100, (int)pos.X, (int)pos.Y, 0, hWnd, IntPtr.Zero);
119-
if (cmd > 0) SendMessage(hWnd, 0x112, (IntPtr)cmd, IntPtr.Zero);
120-
}
121-
}
122-
123-
[DllImport("user32.dll")]
124-
static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp);
125-
[DllImport("user32.dll")]
126-
static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
127-
[DllImport("user32.dll")]
128-
static extern int TrackPopupMenu(IntPtr hMenu, uint uFlags, int x, int y, int nReserved, IntPtr hWnd, IntPtr prcRect);
129-
130-
private void System_MouseMove(object sender, MouseEventArgs e)
131-
{
132-
if (e.LeftButton == MouseButtonState.Pressed)
133-
{
134-
if (this.WindowState == WindowState.Maximized && Math.Abs(startPos.Y - e.GetPosition(null).Y) > 2)
135-
{
136-
var point = PointToScreen(e.GetPosition(null));
137-
138-
this.WindowState = WindowState.Normal;
139-
140-
this.Left = point.X - this.ActualWidth / 2;
141-
this.Top = point.Y - border.ActualHeight / 2;
142-
}
143-
DragMove();
144-
}
145-
}
146-
147-
private void Maximize_Click(object sender, RoutedEventArgs e)
148-
{
149-
this.WindowState = (this.WindowState == WindowState.Normal) ? WindowState.Maximized : WindowState.Normal;
150-
}
151-
152-
private void Close_Click(object sender, RoutedEventArgs e)
153-
{
154-
if (!settings.AskBeforeClosing)
155-
{
156-
this.Close();
157-
return;
158-
}
159-
160-
if (string.IsNullOrEmpty(InputArea.Text) || InputArea.Text.Trim() == "Enter your code here ...")
161-
{
162-
this.Close();
163-
return;
164-
}
165-
166-
MessageBoxResult result = MessageBox.Show("Do you want to close this window? Any text you entered will be lost.", "Are you sure?", MessageBoxButton.YesNo);
167-
if (result == MessageBoxResult.Yes)
168-
{
169-
this.Close();
170-
}
171-
}
172-
173-
private void Mimimize_Click(object sender, RoutedEventArgs e)
174-
{
175-
this.WindowState = WindowState.Minimized;
176-
}
177-
178-
private void Window_StateChanged(object sender, EventArgs e)
179-
{
180-
if (this.WindowState == WindowState.Maximized)
181-
{
182-
main.BorderThickness = new Thickness(0);
183-
main.Margin = new Thickness(7, 7, 7, 0);
184-
rectMax.Visibility = Visibility.Hidden;
185-
rectMin.Visibility = Visibility.Visible;
186-
}
187-
else
188-
{
189-
main.BorderThickness = new Thickness(1);
190-
main.Margin = new Thickness(0);
191-
rectMax.Visibility = Visibility.Visible;
192-
rectMin.Visibility = Visibility.Hidden;
193-
}
194-
}
195-
19678
private void SeeExamplesButtonPressed(object sender, EventArgs e)
19779
{
19880
isShowingExamples = !isShowingExamples;
@@ -296,14 +178,7 @@ private string GetFullPath(string path)
296178

297179
private async Task Compile(string templateContent)
298180
{
299-
300-
var engine = new RazorLightEngineBuilder()
301-
// required to have a default RazorLightProject type,
302-
// but not required to create a template from string.
303-
.UseEmbeddedResourcesProject(typeof(Window))
304-
.UseMemoryCachingProvider()
305-
.Build();
306-
181+
var engine = GCodeRazor.EngineBuilder.Builder.GetBuilder();
307182

308183
bool isError = false;
309184
string result = string.Empty;

0 commit comments

Comments
 (0)