diff options
-rw-r--r-- | QtVsTools.Core/FakeFilter.cs | 10 | ||||
-rw-r--r-- | QtVsTools.Core/VcFilterExtensions.cs | 28 | ||||
-rw-r--r-- | QtVsTools.Wizards/ItemWizard/QtClass/QtClassWizard.cs | 25 | ||||
-rw-r--r-- | QtVsTools.Wizards/ItemWizard/Translation/TranslationWizard.cs | 12 | ||||
-rw-r--r-- | QtVsTools.Wizards/ItemWizard/WidgetsClass/WidgetsClassWizard.cs | 28 | ||||
-rw-r--r-- | Templates/qtclass/qtclass.vstemplate_TT | 5 | ||||
-rw-r--r-- | Templates/widgetsclass/widgetsclass.vstemplate_TT | 8 |
7 files changed, 106 insertions, 10 deletions
diff --git a/QtVsTools.Core/FakeFilter.cs b/QtVsTools.Core/FakeFilter.cs index 974107a6..c4e403bf 100644 --- a/QtVsTools.Core/FakeFilter.cs +++ b/QtVsTools.Core/FakeFilter.cs @@ -62,5 +62,15 @@ namespace QtVsTools.Core Filter = "moc;h;cpp" }; } + + public static FakeFilter TranslationFiles() + { + return new FakeFilter + { + UniqueIdentifier = "{639EADAA-A684-42e4-A9AD-28FC9BCB8F7C}", + Name = "Translation Files", + Filter = "ts;qm" + }; + } } } diff --git a/QtVsTools.Core/VcFilterExtensions.cs b/QtVsTools.Core/VcFilterExtensions.cs index 2c184d8b..73bb97c2 100644 --- a/QtVsTools.Core/VcFilterExtensions.cs +++ b/QtVsTools.Core/VcFilterExtensions.cs @@ -64,6 +64,34 @@ namespace QtVsTools.Core } } + public static void MoveToFilter(this VCFile vcFile, FakeFilter fakeFilter) + { + if (vcFile is not { project: VCProject vcProject }) + return; + if (vcFile.IsInFilter(fakeFilter)) + return; + + if (vcProject.Filters is not IVCCollection filters) + return; + + foreach (VCFilter filter in filters) { + if (!vcFile.IsInFilter(filter)) + continue; + + // We need to get the path early, since removing a VCFile from an + // filter disposes the object and we will get an disposed exception. + var fullPath = vcFile.FullPath; + + // Only try to move the file if we can find the right filter. + if (vcProject.FilterFromGuid(fakeFilter) is {} newFilter) { + filter.RemoveFile(vcFile); + if (newFilter.CanAddFile(fullPath)) + newFilter.AddFile(fullPath); + } + break; + } + } + public static VCFilter FilterFromName(this VCProject vcProject, FakeFilter fakeFilter) { try { diff --git a/QtVsTools.Wizards/ItemWizard/QtClass/QtClassWizard.cs b/QtVsTools.Wizards/ItemWizard/QtClass/QtClassWizard.cs index 10a47d21..af4139de 100644 --- a/QtVsTools.Wizards/ItemWizard/QtClass/QtClassWizard.cs +++ b/QtVsTools.Wizards/ItemWizard/QtClass/QtClassWizard.cs @@ -11,6 +11,7 @@ using System.Text.RegularExpressions; using System.Windows.Controls; using EnvDTE; using Microsoft.VisualStudio.Shell; +using Microsoft.VisualStudio.VCProjectEngine; namespace QtVsTools.Wizards.ItemWizard { @@ -19,6 +20,7 @@ namespace QtVsTools.Wizards.ItemWizard using ProjectWizard; using QtVsTools.Common; using Util; + using VisualStudio; using static QtVsTools.Common.EnumExt; @@ -32,7 +34,8 @@ namespace QtVsTools.Wizards.ItemWizard { [String("safeitemname")] SafeItemName, [String("sourcefilename")] SourceFileName, - [String("headerfilename")] HeaderFileName + [String("headerfilename")] HeaderFileName, + [String("rootname")] Rootname } enum NewQtItem @@ -160,7 +163,25 @@ namespace QtVsTools.Wizards.ItemWizard public override void ProjectItemFinishedGenerating(ProjectItem projectItem) { ThreadHelper.ThrowIfNotOnUIThread(); - TextAndWhitespace.Adjust(Dte, projectItem.Properties.Item("FullPath").Value.ToString()); + + if (projectItem.Object is not VCFile vcFile) + return; + + var fullPath = vcFile.FullPath; + TextAndWhitespace.Adjust(Dte, fullPath); + + if (HelperFunctions.IsHeaderFile(fullPath)) + vcFile.MoveToFilter(FakeFilter.HeaderFiles()); + + if (HelperFunctions.IsSourceFile(fullPath)) + vcFile.MoveToFilter(FakeFilter.SourceFiles()); + } + + public override void RunFinished() + { + var rootName = Parameter[NewClass.Rootname]; + if (!string.IsNullOrEmpty(rootName)) + VsEditor.Open(rootName + ".cpp"); } } } diff --git a/QtVsTools.Wizards/ItemWizard/Translation/TranslationWizard.cs b/QtVsTools.Wizards/ItemWizard/Translation/TranslationWizard.cs index 31338de2..b4f1b1f6 100644 --- a/QtVsTools.Wizards/ItemWizard/Translation/TranslationWizard.cs +++ b/QtVsTools.Wizards/ItemWizard/Translation/TranslationWizard.cs @@ -13,8 +13,10 @@ using Microsoft.VisualStudio.Shell; namespace QtVsTools.Wizards.ItemWizard { using Common; + using Microsoft.VisualStudio.VCProjectEngine; using ProjectWizard; using QtVsTools.Common; + using QtVsTools.Core; using Util; using static QtVsTools.Common.EnumExt; @@ -91,7 +93,15 @@ namespace QtVsTools.Wizards.ItemWizard public override void ProjectItemFinishedGenerating(ProjectItem projectItem) { ThreadHelper.ThrowIfNotOnUIThread(); - TextAndWhitespace.Adjust(Dte, projectItem.Properties.Item("FullPath").Value.ToString()); + + if (projectItem.Object is not VCFile vcFile) + return; + + var fullPath = vcFile.FullPath; + TextAndWhitespace.Adjust(Dte, fullPath); + + if (HelperFunctions.IsTranslationFile(fullPath)) + vcFile.MoveToFilter(FakeFilter.TranslationFiles()); } } } diff --git a/QtVsTools.Wizards/ItemWizard/WidgetsClass/WidgetsClassWizard.cs b/QtVsTools.Wizards/ItemWizard/WidgetsClass/WidgetsClassWizard.cs index d8a1a2b3..cceb672c 100644 --- a/QtVsTools.Wizards/ItemWizard/WidgetsClass/WidgetsClassWizard.cs +++ b/QtVsTools.Wizards/ItemWizard/WidgetsClass/WidgetsClassWizard.cs @@ -12,6 +12,7 @@ using System.Text.RegularExpressions; using System.Windows.Controls; using EnvDTE; using Microsoft.VisualStudio.Shell; +using Microsoft.VisualStudio.VCProjectEngine; namespace QtVsTools.Wizards.ItemWizard { @@ -20,6 +21,7 @@ namespace QtVsTools.Wizards.ItemWizard using ProjectWizard; using QtVsTools.Common; using Util; + using VisualStudio; using static QtVsTools.Common.EnumExt; @@ -34,7 +36,8 @@ namespace QtVsTools.Wizards.ItemWizard [String("safeitemname")] SafeItemName, [String("sourcefilename")] SourceFileName, [String("headerfilename")] HeaderFileName, - [String("uifilename")] UiFileName + [String("uifilename")] UiFileName, + [String("rootname")] Rootname } enum NewWidgetsItem @@ -206,7 +209,28 @@ namespace QtVsTools.Wizards.ItemWizard public override void ProjectItemFinishedGenerating(ProjectItem projectItem) { ThreadHelper.ThrowIfNotOnUIThread(); - TextAndWhitespace.Adjust(Dte, projectItem.Properties.Item("FullPath").Value.ToString()); + + if (projectItem.Object is not VCFile vcFile) + return; + + var fullPath = vcFile.FullPath; + TextAndWhitespace.Adjust(Dte, fullPath); + + if (HelperFunctions.IsUicFile(fullPath)) + vcFile.MoveToFilter(FakeFilter.FormFiles()); + + if (HelperFunctions.IsHeaderFile(fullPath)) + vcFile.MoveToFilter(FakeFilter.HeaderFiles()); + + if (HelperFunctions.IsSourceFile(fullPath)) + vcFile.MoveToFilter(FakeFilter.SourceFiles()); + } + + public override void RunFinished() + { + var rootName = Parameter[NewClass.Rootname]; + if (!string.IsNullOrEmpty(rootName)) + VsEditor.Open(rootName + ".cpp"); } } } diff --git a/Templates/qtclass/qtclass.vstemplate_TT b/Templates/qtclass/qtclass.vstemplate_TT index e57d899e..cbdc2512 100644 --- a/Templates/qtclass/qtclass.vstemplate_TT +++ b/Templates/qtclass/qtclass.vstemplate_TT @@ -32,10 +32,11 @@ <ProjectTypeTag>Console</ProjectTypeTag> </TemplateData> <TemplateContent> - <ProjectItem OpenInEditor="true" + <ProjectItem OpenInEditor="false" ReplaceParameters="true" TargetFileName="$sourcefilename$">source.cpp</ProjectItem> - <ProjectItem ReplaceParameters="true" + <ProjectItem OpenInEditor="false" + ReplaceParameters="true" TargetFileName="$headerfilename$">header.h</ProjectItem> </TemplateContent> <WizardExtension> diff --git a/Templates/widgetsclass/widgetsclass.vstemplate_TT b/Templates/widgetsclass/widgetsclass.vstemplate_TT index 390cc49e..e3a34238 100644 --- a/Templates/widgetsclass/widgetsclass.vstemplate_TT +++ b/Templates/widgetsclass/widgetsclass.vstemplate_TT @@ -29,12 +29,14 @@ <ProjectTypeTag>Desktop</ProjectTypeTag> </TemplateData> <TemplateContent> - <ProjectItem OpenInEditor="true" + <ProjectItem OpenInEditor="false" ReplaceParameters="true" TargetFileName="$sourcefilename$">widget.cpp</ProjectItem> - <ProjectItem ReplaceParameters="true" + <ProjectItem OpenInEditor="false" + ReplaceParameters="true" TargetFileName="$headerfilename$">widget.h</ProjectItem> - <ProjectItem ReplaceParameters="true" + <ProjectItem OpenInEditor="false" + ReplaceParameters="true" TargetFileName="$uifilename$">widget.ui</ProjectItem> </TemplateContent> <WizardExtension> |