Skip to content

Commit a1e7a14

Browse files
Merge pull request #7 from Enache-Ionut/master
fixed the deploy and added multiple errors support
2 parents ad97d74 + 64fbed6 commit a1e7a14

6 files changed

+65
-48
lines changed

src/RcStrings.VSIX/RcStrings.VSIX.csproj

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
<CopyOutputSymbolsToOutputDirectory>false</CopyOutputSymbolsToOutputDirectory>
3131
</PropertyGroup>
3232
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
33+
<VsSDKVersion>14.0</VsSDKVersion>
3334
<DebugSymbols>true</DebugSymbols>
3435
<DebugType>full</DebugType>
3536
<Optimize>false</Optimize>
@@ -38,6 +39,7 @@
3839
<ErrorReport>prompt</ErrorReport>
3940
<WarningLevel>4</WarningLevel>
4041
<DeployExtension>True</DeployExtension>
42+
<CreateVsixContainer>True</CreateVsixContainer>
4143
</PropertyGroup>
4244
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
4345
<DebugType>pdbonly</DebugType>

src/RcStrings.VsPackage/EditStringResourceDialog.xaml.cs

+27-18
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public int ResourceId
103103
set => mResourceId = value;
104104
}
105105

106-
private Dictionary<string, string> Errors { get; } = new Dictionary<string, string>();
106+
private Dictionary<string, List<string>> Errors { get; } = new Dictionary<string, List<string>>();
107107

108108
private bool HasError => Errors.Any();
109109

@@ -114,8 +114,6 @@ public int ResourceId
114114
public EditStringResourceDialog(IServiceProvider aServiceProvider, List<RcFile> aRcFiles, RcFile aSelectedRcFile,
115115
string aSelectedText, bool aReplaceCode, string aReplaceWithCodeFormated, StringLine aStringResource = null)
116116
{
117-
if (aRcFiles.Count == 0)
118-
throw new Exception("No RC files detected");
119117
InitializeComponent();
120118
DataContext = this;
121119
mRcFilesContexts = new Dictionary<RcFile, StringResourceContext>();
@@ -165,7 +163,7 @@ private void btnAdd_Click(object sender, RoutedEventArgs e)
165163
}
166164
if (HasError)
167165
{
168-
VsShellUtilities.ShowMessageBox(mServiceProvider, Errors.First().Value, "Invalid input",
166+
VsShellUtilities.ShowMessageBox(mServiceProvider, Errors.First().Value.First(), "Invalid input",
169167
OLEMSGICON.OLEMSGICON_CRITICAL, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
170168
return;
171169
}
@@ -215,7 +213,8 @@ public string this[string PropertyName]
215213
get
216214
{
217215
CollectErrors();
218-
return Errors.ContainsKey(PropertyName) ? Errors[PropertyName] : string.Empty;
216+
return Errors.ContainsKey(PropertyName) ?
217+
String.Join("\n", Errors[PropertyName]) : string.Empty;
219218
}
220219
}
221220

@@ -224,33 +223,43 @@ private void CollectErrors()
224223
Errors.Clear();
225224

226225
if (string.IsNullOrEmpty(ResourceName) ||
227-
ResourceName.Length > ParseConstants.kMaximumResourceNameLength ||
228-
!ResourceName.StartsWith(TagConstants.kStringPreffix))
226+
ResourceName.Length > ParseConstants.kMaximumResourceNameLength ||
227+
!ResourceName.StartsWith(TagConstants.kStringPreffix))
229228
{
230-
Errors.Add(nameof(ResourceName),
231-
string.Format("Name with the IDS_ prefix and maximum length of {0} is required!",
232-
ParseConstants.kMaximumResourceNameLength));
229+
if (!Errors.ContainsKey(nameof(ResourceName)))
230+
Errors[nameof(ResourceName)] = new List<string>();
231+
232+
Errors[nameof(ResourceName)].Add(string.Format(
233+
$"Name with the IDS_ prefix and maximum length of {ParseConstants.kMaximumResourceNameLength} is required!"));
233234
}
234235

235236
if(AddMode && (string.IsNullOrEmpty(ResourceName) ||
236237
ResourceContext.ResourceNameExists(ResourceName)))
237238
{
238-
Errors.Add(nameof(ResourceName), string.Format("Name \"{0}\" already exists!", ResourceName));
239+
if (!Errors.ContainsKey(nameof(ResourceName)))
240+
Errors[nameof(ResourceName)] = new List<string>();
241+
242+
Errors[nameof(ResourceName)].Add(string.Format($"Name \"{ResourceName}\" already exists!"));
239243
}
240244

241245
if (string.IsNullOrEmpty(ResourceIdTemp) ||
242-
!ParseUtility.TransformToDecimal(ResourceIdTemp, out mResourceId) ||
243-
mResourceId < 0 || mResourceId > IdGenerator.kMaximumId)
246+
!ParseUtility.TransformToDecimal(ResourceIdTemp, out mResourceId) ||
247+
mResourceId < 0 || mResourceId > IdGenerator.kMaximumId)
244248
{
245-
Errors.Add(nameof(ResourceIdTemp),
246-
string.Format("Positive id less then {0} is required!", IdGenerator.kMaximumId));
249+
if (!Errors.ContainsKey(nameof(ResourceIdTemp)))
250+
Errors[nameof(ResourceIdTemp)] = new List<string>();
251+
252+
Errors[nameof(ResourceIdTemp)].Add(string.Format($"Positive id less then {IdGenerator.kMaximumId} is required!"));
247253
}
254+
248255
if (string.IsNullOrEmpty(ResourceValue) ||
249256
ResourceValue.Length > ParseConstants.kMaximumResourceValueLength)
250257
{
251-
Errors.Add(nameof(ResourceValue),
252-
string.Format("Value with maximum length of {0} characters is required!",
253-
ParseConstants.kMaximumResourceValueLength));
258+
if (!Errors.ContainsKey(nameof(ResourceValue)))
259+
Errors[nameof(ResourceValue)] = new List<string>();
260+
261+
Errors[nameof(ResourceValue)].Add(
262+
string.Format($"Value with maximum length of {ParseConstants.kMaximumResourceValueLength} characters is required!"));
254263
}
255264
}
256265
#endregion

src/RcStrings.VsPackage/Properties/Settings.Designer.cs

+4-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/RcStrings.VsPackage/RcStrings.VsPackage.csproj

+3-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
<UpgradeBackupLocation>
1212
</UpgradeBackupLocation>
1313
<OldToolsVersion>14.0</OldToolsVersion>
14-
<VsSDKVersion>14.0</VsSDKVersion>
1514
<PublishUrl>publish\</PublishUrl>
1615
<Install>true</Install>
1716
<InstallFrom>Disk</InstallFrom>
@@ -54,6 +53,7 @@
5453
<CopyOutputSymbolsToOutputDirectory>false</CopyOutputSymbolsToOutputDirectory>
5554
</PropertyGroup>
5655
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
56+
<VsSDKVersion>14.0</VsSDKVersion>
5757
<DebugSymbols>true</DebugSymbols>
5858
<DebugType>full</DebugType>
5959
<Optimize>false</Optimize>
@@ -125,6 +125,7 @@
125125
<EmbedInteropTypes>False</EmbedInteropTypes>
126126
<HintPath>C:\Program Files (x86)\Common Files\Microsoft Shared\MSEnv\PublicAssemblies\envdte90.dll</HintPath>
127127
</Reference>
128+
<Reference Include="Microsoft.Build, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
128129
<Reference Include="Microsoft.Build.Framework" />
129130
<Reference Include="Microsoft.CSharp" />
130131
<Reference Include="Microsoft.VisualStudio.CommandBars, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
@@ -186,15 +187,13 @@
186187
<Reference Include="Microsoft.VisualStudio.Validation, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
187188
<HintPath>..\packages\Microsoft.VisualStudio.Validation.14.1.111\lib\net45\Microsoft.VisualStudio.Validation.dll</HintPath>
188189
</Reference>
189-
<Reference Include="Microsoft.VisualStudio.VCProjectEngine, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
190-
<EmbedInteropTypes>True</EmbedInteropTypes>
191-
</Reference>
192190
<Reference Include="PresentationCore" />
193191
<Reference Include="PresentationFramework" />
194192
<Reference Include="PresentationFramework.Aero2" />
195193
<Reference Include="System" />
196194
<Reference Include="System.Design" />
197195
<Reference Include="System.Xaml" />
196+
<Reference Include="System.Xml" />
198197
<Reference Include="WindowsBase" />
199198
</ItemGroup>
200199
<ItemGroup>

src/RcStrings.VsPackage/RcStringsPackage.cs

+25-19
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
using EnvDTE;
1010
using Microsoft.VisualStudio.Shell;
1111
using Microsoft.VisualStudio.Shell.Interop;
12-
using Microsoft.VisualStudio.VCProjectEngine;
1312
using System;
1413
using System.Collections.Generic;
1514
using System.ComponentModel.Design;
@@ -18,6 +17,7 @@
1817
using System.Linq;
1918
using System.Runtime.InteropServices;
2019
using System.Windows.Interop;
20+
using Microsoft.Build.Evaluation;
2121

2222
namespace Caphyon.RcStrings.VsPackage
2323
{
@@ -224,6 +224,9 @@ private void SetResourceCommandClick(object sender, EventArgs e)
224224
}
225225
}
226226

227+
if (rcFiles.Count == 0)
228+
throw new Exception("No RC files detected");
229+
227230
EditStringResourceDialog dialog = new EditStringResourceDialog((IServiceProvider)this, rcFiles,
228231
mSelectedRcFile, mSelectedWord, mReplaceString, mReplaceWithCodeFormated)
229232
{
@@ -353,27 +356,30 @@ private List<RcFile> GetRCFilesFromSolution()
353356
return rcFiles;
354357
}
355358

356-
private List<RcFile> GetRcFilesFromProject(Project aProject)
359+
private List<RcFile> GetRcFilesFromProject(EnvDTE.Project aProject)
357360
{
358-
if (!(aProject.Object is VCProject))
361+
if (aProject.Kind != kCppProjectKind)
359362
return new List<RcFile>();
360363

361364
var rcFiles = GetRcFiles(aProject.ProjectItems, string.Empty);
362-
// Set Aditional Include Directories collection
363-
VCProject vcProject = aProject.Object as VCProject;
365+
if (rcFiles.Count == 0)
366+
return rcFiles;
364367

365-
List<string> aditionalDirectories = new List<string>();
366-
foreach (var toolObject in vcProject.ActiveConfiguration.Tools)
368+
ProjectCollection projectCollection = new ProjectCollection();
369+
var project = projectCollection.LoadProject(aProject.FullName);
370+
HashSet<string> aditionalDirectories = new HashSet<string>();
371+
372+
// Set Aditional Include Directories collection
373+
foreach (var item in project.Items)
367374
{
368-
string aditionalDirsValue;
369-
if (toolObject is VCResourceCompilerTool)
370-
aditionalDirsValue = (toolObject as VCResourceCompilerTool).AdditionalIncludeDirectories;
371-
else if (toolObject is VCCLCompilerTool)
372-
aditionalDirsValue = (toolObject as VCCLCompilerTool).AdditionalIncludeDirectories;
373-
else
375+
if (item.ItemType != "ResourceComplile" && item.ItemType != "ClCompile")
374376
continue;
375377

376-
string[] aditionalDirs = aditionalDirsValue.Split(';');
378+
var aditionalDirsProp = item.GetMetadata("AdditionalIncludeDirectories");
379+
if (aditionalDirsProp == null)
380+
continue;
381+
382+
string[] aditionalDirs = aditionalDirsProp.EvaluatedValue.Split(';');
377383
foreach (string dirRelativePath in aditionalDirs)
378384
{
379385
try
@@ -384,13 +390,13 @@ private List<RcFile> GetRcFilesFromProject(Project aProject)
384390
if (Directory.Exists(dirAbsolutePath))
385391
aditionalDirectories.Add(dirAbsolutePath);
386392
}
387-
catch{ }
393+
catch { }
388394
}
389-
390-
VCppProject project = new VCppProject(aProject);
391-
project.AditionalIncludeDirectories.AddRange(aditionalDirectories);
392-
rcFiles.ForEach(rcf => rcf.Project = project);
393395
}
396+
VCppProject cppProject = new VCppProject(aProject);
397+
cppProject.AditionalIncludeDirectories.AddRange(aditionalDirectories);
398+
rcFiles.ForEach(rcf => rcf.Project = cppProject);
399+
394400
return rcFiles;
395401
}
396402

src/RcStrings.VsPackage/source.extension.vsixmanifest

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
<Description>Empty VSIX Project.</Description>
77
</Metadata>
88
<Installation>
9-
<InstallationTarget Id="Microsoft.VisualStudio.Community" Version="[15.0]" />
9+
<InstallationTarget Version="[14.0,16.0)" Id="Microsoft.VisualStudio.Pro" />
10+
<InstallationTarget Version="[14.0,16.0)" Id="Microsoft.VisualStudio.Community" />
11+
<InstallationTarget Version="[14.0,16.0)" Id="Microsoft.VisualStudio.Enterprise" />
1012
</Installation>
1113
<Dependencies>
1214
<Dependency Id="Microsoft.Framework.NDP" DisplayName="Microsoft .NET Framework" d:Source="Manual" Version="[4.5,)" />
@@ -16,6 +18,6 @@
1618
<Asset Type="Microsoft.VisualStudio.VsPackage" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%;PkgdefProjectOutputGroup|" />
1719
</Assets>
1820
<Prerequisites>
19-
<Prerequisite Id="Microsoft.VisualStudio.Component.CoreEditor" Version="[15.0.26208.0,16.0)" DisplayName="Visual Studio core editor" />
21+
<Prerequisite Id="Microsoft.VisualStudio.Component.CoreEditor" Version="[15.0,16.0)" DisplayName="Visual Studio core editor" />
2022
</Prerequisites>
2123
</PackageManifest>

0 commit comments

Comments
 (0)