Skip to content

Commit 6c604ff

Browse files
kingceanmmanela
authored andcommitted
Add context menu for WPF controls.
1 parent 9f2ee6b commit 6c604ff

27 files changed

Lines changed: 1604 additions & 53 deletions

DiffPlex.WindowsForms/DiffPlex.WindowsForms.csproj renamed to DiffPlex.WindowsForms/DiffPlex.WinForms.Demo.csproj

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
77
<ProjectGuid>{D969E0F0-D913-472B-96AF-A46AD49FC765}</ProjectGuid>
88
<OutputType>WinExe</OutputType>
9-
<RootNamespace>DiffPlex.WindowsForms</RootNamespace>
10-
<AssemblyName>DiffPlex.WindowsForms</AssemblyName>
9+
<RootNamespace>DiffPlex.WinForms.Demo</RootNamespace>
10+
<AssemblyName>DiffPlex.WinForms.Demo</AssemblyName>
1111
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
1212
<FileAlignment>512</FileAlignment>
1313
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
@@ -34,9 +34,15 @@
3434
<ErrorReport>prompt</ErrorReport>
3535
<WarningLevel>4</WarningLevel>
3636
</PropertyGroup>
37+
<PropertyGroup>
38+
<StartupObject>DiffPlex.WinForms.Demo.Program</StartupObject>
39+
</PropertyGroup>
3740
<ItemGroup>
41+
<Reference Include="PresentationCore" />
42+
<Reference Include="PresentationFramework" />
3843
<Reference Include="System" />
3944
<Reference Include="System.Core" />
45+
<Reference Include="System.Xaml" />
4046
<Reference Include="System.Xml.Linq" />
4147
<Reference Include="System.Data.DataSetExtensions" />
4248
<Reference Include="Microsoft.CSharp" />
@@ -46,20 +52,35 @@
4652
<Reference Include="System.Net.Http" />
4753
<Reference Include="System.Windows.Forms" />
4854
<Reference Include="System.Xml" />
55+
<Reference Include="UIAutomationProvider" />
56+
<Reference Include="WindowsBase" />
57+
<Reference Include="WindowsFormsIntegration" />
4958
</ItemGroup>
5059
<ItemGroup>
60+
<Compile Include="..\DiffPlex.Wpf.Demo\TestData.cs">
61+
<Link>TestData.cs</Link>
62+
</Compile>
5163
<Compile Include="Extensions\RichTextBoxExtensions.cs" />
5264
<Compile Include="Form1.cs">
5365
<SubType>Form</SubType>
5466
</Compile>
5567
<Compile Include="Form1.Designer.cs">
5668
<DependentUpon>Form1.cs</DependentUpon>
5769
</Compile>
70+
<Compile Include="Form2.cs">
71+
<SubType>Form</SubType>
72+
</Compile>
73+
<Compile Include="Form2.Designer.cs">
74+
<DependentUpon>Form2.cs</DependentUpon>
75+
</Compile>
5876
<Compile Include="Program.cs" />
5977
<Compile Include="Properties\AssemblyInfo.cs" />
6078
<EmbeddedResource Include="Form1.resx">
6179
<DependentUpon>Form1.cs</DependentUpon>
6280
</EmbeddedResource>
81+
<EmbeddedResource Include="Form2.resx">
82+
<DependentUpon>Form2.cs</DependentUpon>
83+
</EmbeddedResource>
6384
<EmbeddedResource Include="Properties\Resources.resx">
6485
<Generator>ResXFileCodeGenerator</Generator>
6586
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
@@ -87,6 +108,10 @@
87108
<Project>{54247212-ba10-4593-8e4d-d3b5ac06d2f2}</Project>
88109
<Name>DiffPlex</Name>
89110
</ProjectReference>
111+
<ProjectReference Include="..\DiffPlex.Wpf\DiffPlex.Wpf.csproj">
112+
<Project>{cb18d73d-7e84-4b28-b44d-93cb34794a6a}</Project>
113+
<Name>DiffPlex.Wpf</Name>
114+
</ProjectReference>
90115
</ItemGroup>
91116
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
92117
</Project>

DiffPlex.WindowsForms/Extensions/RichTextBoxExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System.Drawing;
22
using System.Windows.Forms;
33

4-
namespace DiffPlex.WindowsForms.Extensions
4+
namespace DiffPlex.WinForms.Demo
55
{
66
/// <summary>
77
/// Extension methods for the RichTextBox control.

DiffPlex.WindowsForms/Form1.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

DiffPlex.WindowsForms/Form1.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
using DiffPlex.DiffBuilder;
2-
using DiffPlex.DiffBuilder.Model;
3-
using DiffPlex.WindowsForms.Extensions;
4-
using System;
1+
using System;
52
using System.Drawing;
63
using System.Linq;
74
using System.Windows.Forms;
85

9-
namespace DiffPlex.WindowsForms
6+
using DiffPlex.DiffBuilder;
7+
using DiffPlex.DiffBuilder.Model;
8+
9+
namespace DiffPlex.WinForms.Demo
1010
{
1111
public partial class Form1 : Form
1212
{

DiffPlex.WindowsForms/Form2.Designer.cs

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

DiffPlex.WindowsForms/Form2.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel;
4+
using System.Data;
5+
using System.Drawing;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
using System.Windows.Forms;
10+
11+
namespace DiffPlex.WinForms.Demo
12+
{
13+
public partial class Form2 : Form
14+
{
15+
/// <summary>
16+
/// Initializes a new instance of the Form2 class.
17+
/// </summary>
18+
public Form2()
19+
{
20+
InitializeComponent();
21+
22+
DiffView = new Wpf.Controls.DiffViewer();
23+
diffViewHost.Child = DiffView;
24+
var isDark = Wpf.Demo.TestData.FillDiffViewer(DiffView, 20);
25+
BackColor = isDark ? Color.FromArgb(255, 32, 32, 32) : Color.FromArgb(255, 251, 251, 251);
26+
}
27+
28+
/// <summary>
29+
/// Gets the diff viewer control.
30+
/// </summary>
31+
public Wpf.Controls.DiffViewer DiffView { get; }
32+
}
33+
}

DiffPlex.WindowsForms/Form2.resx

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<root>
3+
<!--
4+
Microsoft ResX Schema
5+
6+
Version 2.0
7+
8+
The primary goals of this format is to allow a simple XML format
9+
that is mostly human readable. The generation and parsing of the
10+
various data types are done through the TypeConverter classes
11+
associated with the data types.
12+
13+
Example:
14+
15+
... ado.net/XML headers & schema ...
16+
<resheader name="resmimetype">text/microsoft-resx</resheader>
17+
<resheader name="version">2.0</resheader>
18+
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
19+
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
20+
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
21+
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
22+
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
23+
<value>[base64 mime encoded serialized .NET Framework object]</value>
24+
</data>
25+
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
26+
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
27+
<comment>This is a comment</comment>
28+
</data>
29+
30+
There are any number of "resheader" rows that contain simple
31+
name/value pairs.
32+
33+
Each data row contains a name, and value. The row also contains a
34+
type or mimetype. Type corresponds to a .NET class that support
35+
text/value conversion through the TypeConverter architecture.
36+
Classes that don't support this are serialized and stored with the
37+
mimetype set.
38+
39+
The mimetype is used for serialized objects, and tells the
40+
ResXResourceReader how to depersist the object. This is currently not
41+
extensible. For a given mimetype the value must be set accordingly:
42+
43+
Note - application/x-microsoft.net.object.binary.base64 is the format
44+
that the ResXResourceWriter will generate, however the reader can
45+
read any of the formats listed below.
46+
47+
mimetype: application/x-microsoft.net.object.binary.base64
48+
value : The object must be serialized with
49+
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
50+
: and then encoded with base64 encoding.
51+
52+
mimetype: application/x-microsoft.net.object.soap.base64
53+
value : The object must be serialized with
54+
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
55+
: and then encoded with base64 encoding.
56+
57+
mimetype: application/x-microsoft.net.object.bytearray.base64
58+
value : The object must be serialized into a byte array
59+
: using a System.ComponentModel.TypeConverter
60+
: and then encoded with base64 encoding.
61+
-->
62+
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
63+
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
64+
<xsd:element name="root" msdata:IsDataSet="true">
65+
<xsd:complexType>
66+
<xsd:choice maxOccurs="unbounded">
67+
<xsd:element name="metadata">
68+
<xsd:complexType>
69+
<xsd:sequence>
70+
<xsd:element name="value" type="xsd:string" minOccurs="0" />
71+
</xsd:sequence>
72+
<xsd:attribute name="name" use="required" type="xsd:string" />
73+
<xsd:attribute name="type" type="xsd:string" />
74+
<xsd:attribute name="mimetype" type="xsd:string" />
75+
<xsd:attribute ref="xml:space" />
76+
</xsd:complexType>
77+
</xsd:element>
78+
<xsd:element name="assembly">
79+
<xsd:complexType>
80+
<xsd:attribute name="alias" type="xsd:string" />
81+
<xsd:attribute name="name" type="xsd:string" />
82+
</xsd:complexType>
83+
</xsd:element>
84+
<xsd:element name="data">
85+
<xsd:complexType>
86+
<xsd:sequence>
87+
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
88+
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
89+
</xsd:sequence>
90+
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
91+
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
92+
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
93+
<xsd:attribute ref="xml:space" />
94+
</xsd:complexType>
95+
</xsd:element>
96+
<xsd:element name="resheader">
97+
<xsd:complexType>
98+
<xsd:sequence>
99+
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
100+
</xsd:sequence>
101+
<xsd:attribute name="name" type="xsd:string" use="required" />
102+
</xsd:complexType>
103+
</xsd:element>
104+
</xsd:choice>
105+
</xsd:complexType>
106+
</xsd:element>
107+
</xsd:schema>
108+
<resheader name="resmimetype">
109+
<value>text/microsoft-resx</value>
110+
</resheader>
111+
<resheader name="version">
112+
<value>2.0</value>
113+
</resheader>
114+
<resheader name="reader">
115+
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
116+
</resheader>
117+
<resheader name="writer">
118+
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119+
</resheader>
120+
</root>

DiffPlex.WindowsForms/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System.Threading.Tasks;
55
using System.Windows.Forms;
66

7-
namespace DiffPlex.WindowsForms
7+
namespace DiffPlex.WinForms.Demo
88
{
99
static class Program
1010
{
@@ -16,7 +16,7 @@ static void Main()
1616
{
1717
Application.EnableVisualStyles();
1818
Application.SetCompatibleTextRenderingDefault(false);
19-
Application.Run(new Form1());
19+
Application.Run(new Form2()); // Replace Form2 to Form1 to test classic version.
2020
}
2121
}
2222
}

DiffPlex.WindowsForms/README.md

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,34 @@
1-
# DiffPlex Windows Forms Demo
2-
This is an example Windows Forms application developed in .NET 4.8 (C#).
1+
# DiffPlex WinForms Demo
2+
3+
This is an example of WinForms application that targets .NET Framework 4.8 (developed by C#).
4+
5+
## WPF element in WinForms
6+
7+
By using `ElementHost` [control](https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.integration.elementhost)
8+
(in `System.Windows.Forms.Integration` namespace and can be found in Toolbox of Visual Studio)
9+
and setting its `Child` property as one of `DiffViewer`, `SideBySideDiffViewer` and `InlineDiffViewer`
10+
(in `DiffPlex.Wpf.Controls` namespace of `DiffPlex.Wpf.dll` assembly) instance,
11+
you can add the visual element into the control or window of your WinForms project.
12+
13+
See `Form2.cs` to get details.
14+
15+
## Classic
316

417
This shows how to use both `InlineDiffBuilder` and `SideBySideDiffBuilder` with a standard `System.Windows.Forms.RichTextBox`.
518

619
![Screenshot of the application showing an inline and side-by-side example.](screenshot.png)
20+
21+
See `Form1.cs` to get details.
22+
23+
To run this sample, please update file `Program.cs` as following.
24+
25+
```csharp
26+
[STAThread]
27+
static void Main()
28+
{
29+
Application.EnableVisualStyles();
30+
Application.SetCompatibleTextRenderingDefault(false);
31+
+ Application.Run(new Form1());
32+
- Application.Run(new Form2());
33+
}
34+
```

DiffPlex.Wpf.Demo/DiffPlex.Wpf.Demo.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>WinExe</OutputType>
5-
<TargetFrameworks>net5.0-windows;net46</TargetFrameworks>
5+
<TargetFrameworks>netcoreapp3.1;net46</TargetFrameworks>
66
<UseWPF>true</UseWPF>
77
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
88
<Authors>Kingcean Tuan</Authors>
@@ -16,7 +16,7 @@
1616
<PackageIcon>diffplex_icon.png</PackageIcon>
1717
<StartupObject>DiffPlex.Wpf.Demo.App</StartupObject>
1818
</PropertyGroup>
19-
19+
2020
<ItemGroup>
2121
<ProjectReference Include="..\DiffPlex.Wpf\DiffPlex.Wpf.csproj" />
2222
</ItemGroup>

0 commit comments

Comments
 (0)