Skip to content

Commit 968c7cd

Browse files
author
Sébastien Geiser
committed
Export in progress
1 parent c3241b3 commit 968c7cd

File tree

7 files changed

+60
-31
lines changed

7 files changed

+60
-31
lines changed

RegexDialog/RegExToolDialog.xaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@
7878
<Image Source="{StaticResource VS}" />
7979
</MenuItem.Icon>
8080
</MenuItem>
81-
<MenuItem Header="Export C# Code In A New Tab" >
82-
</MenuItem>
8381
<Separator />
8482
<MenuItem Header="_Exit" Click="Exit_MenuItem_Click" >
8583
<MenuItem.Icon>

RegexDialog/RegExToolDialog.xaml.cs

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using System.Diagnostics;
1111
using System.IO;
1212
using System.Linq;
13+
using System.Reflection;
1314
using System.Text;
1415
using System.Text.RegularExpressions;
1516
using System.Windows;
@@ -2128,8 +2129,10 @@ private void ExportToVisualStudio_Click(object sender, RoutedEventArgs e)
21282129
string projectFile = Path.Combine(projectDirectory, $"{projectName}.csproj");
21292130
string entryFile = Path.Combine(projectDirectory, "Program.cs");
21302131
string replaceFile = Path.Combine(projectDirectory, "CSharpReplaceContainer.cs");
2131-
string textSourceFile = Path.Combine(projectDirectory, "TextSourceContainer.cs");
2132+
string csharpTextSourceFile = Path.Combine(projectDirectory, "TextSourceContainer.cs");
2133+
string textSourceFile = Path.Combine(projectDirectory, "TextSource.txt");
21322134
string projectGuid = Guid.NewGuid().ToString();
2135+
string resourcesForCsProj = string.Empty;
21332136
string options = regExOptionViewModelsList.Count(option => option.Selected) == 0
21342137
? "RegexOptions.None"
21352138
: string.Join(" | ",
@@ -2145,6 +2148,33 @@ private void ExportToVisualStudio_Click(object sender, RoutedEventArgs e)
21452148

21462149
Directory.CreateDirectory(projectDirectory);
21472150

2151+
if (Config.Instance.CSharpReplaceMode)
2152+
{
2153+
File.WriteAllText(replaceFile, ReplaceScriptForMatch);
2154+
}
2155+
2156+
// Write text source as specific cs file if in CSharpScript
2157+
if (Config.Instance.TextSourceOn == RegexTextSource.CSharpScript)
2158+
{
2159+
File.WriteAllText(csharpTextSourceFile, CSharpTextSourceScript);
2160+
}
2161+
// Write text source as text file in resources
2162+
else
2163+
{
2164+
File.WriteAllText(textSourceFile, GetCurrentText());
2165+
resourcesForCsProj += Res.TextSourceAsResourceInCsProj;
2166+
}
2167+
2168+
// Write Entry file
2169+
if (!File.Exists(entryFile)
2170+
|| MessageBox.Show($"The entry file \"{entryFile}\" already exists.\r\nDo you want to override it ?",
2171+
"Entry file override",
2172+
MessageBoxButton.YesNo,
2173+
MessageBoxImage.Question) == MessageBoxResult.Yes)
2174+
{
2175+
File.WriteAllText(entryFile, programCode);
2176+
}
2177+
21482178
// Write solution file
21492179
if (!File.Exists(projectFile)
21502180
|| MessageBox.Show($"The solution file \"{solutionFile}\" already exists.\r\nDo you want to override it ?",
@@ -2167,27 +2197,8 @@ private void ExportToVisualStudio_Click(object sender, RoutedEventArgs e)
21672197
MessageBoxButton.YesNo,
21682198
MessageBoxImage.Question) == MessageBoxResult.Yes)
21692199
{
2170-
File.WriteAllText(projectFile, Res.VSProject);
2171-
}
2172-
2173-
if (Config.Instance.CSharpReplaceMode)
2174-
{
2175-
File.WriteAllText(replaceFile, ReplaceScriptForMatch);
2176-
}
2177-
2178-
if (Config.Instance.TextSourceOn == RegexTextSource.CSharpScript)
2179-
{
2180-
File.WriteAllText(textSourceFile, CSharpTextSourceScript);
2181-
}
2182-
2183-
// Write Entry file
2184-
if (!File.Exists(entryFile)
2185-
|| MessageBox.Show($"The entry file \"{entryFile}\" already exists.\r\nDo you want to override it ?",
2186-
"Entry file override",
2187-
MessageBoxButton.YesNo,
2188-
MessageBoxImage.Question) == MessageBoxResult.Yes)
2189-
{
2190-
File.WriteAllText(entryFile, programCode);
2200+
File.WriteAllText(projectFile, Res.VSProject
2201+
.Replace("<!-- Resources -->", resourcesForCsProj));
21912202
}
21922203

21932204
Process.Start($"\"{solutionFile}\"");

RegexDialog/RegexDialog.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,9 @@
412412
<ItemGroup>
413413
<Resource Include="Resources\VSProject.csproj" />
414414
</ItemGroup>
415+
<ItemGroup>
416+
<None Include="Resources\TextSourceAsResourceInCsProj.txt" />
417+
</ItemGroup>
415418
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
416419
<PropertyGroup>
417420
<PostBuildEvent>

RegexDialog/Res.Designer.cs

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

RegexDialog/Res.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@
133133
<data name="Replace_syntax_color" type="System.Resources.ResXFileRef, System.Windows.Forms">
134134
<value>resources\replace_syntax_color.xshd;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;iso-8859-1</value>
135135
</data>
136+
<data name="TextSourceAsResourceInCsProj" type="System.Resources.ResXFileRef, System.Windows.Forms">
137+
<value>resources\textsourceasresourceincsproj.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
138+
</data>
136139
<data name="TextSourceContainer" type="System.Resources.ResXFileRef, System.Windows.Forms">
137140
<value>resources\textsourcecontainer.cs;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
138141
</data>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<ItemGroup>
2+
<Resource Include="TextSource.txt" />
3+
</ItemGroup>

RegexDialog/Resources/VSProject.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
<TargetFramework>netcoreapp3.0</TargetFramework>
66
</PropertyGroup>
77

8+
<!-- Resources -->
89
</Project>

0 commit comments

Comments
 (0)