aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAli Can Demiralp <ali.demiralp@qt.io>2024-02-26 17:18:44 +0100
committerAli Can Demiralp <ali.demiralp@qt.io>2024-03-05 16:49:34 +0000
commit5aa212ced155e5f9cd31295274e0896e24f2d8a2 (patch)
treede103295234d540208d9da968960d213fd2c7584
parent24dd1df6a62eb49d55c528bbccfa4e21542d2da1 (diff)
Enable file wizards to accept relative paths
The QtClassWizard, TranslationWizard and WidgetsClassWizard once again accept relative paths. Fixes: QTVSADDINBUG-528 Change-Id: I04a379840dc59c9be1a50de851001f621b31da9c Reviewed-by: Miguel Costa <miguel.costa@qt.io>
-rw-r--r--QtVsTools.Core/HelperFunctions.cs15
-rw-r--r--QtVsTools.Wizards/ItemWizard/QtClass/QtClassWizard.cs11
-rw-r--r--QtVsTools.Wizards/ItemWizard/Translation/TranslationWizard.cs8
-rw-r--r--QtVsTools.Wizards/ItemWizard/WidgetsClass/WidgetsClassWizard.cs15
-rw-r--r--QtVsTools.Wizards/Util/FileNameValidationRule.cs3
5 files changed, 46 insertions, 6 deletions
diff --git a/QtVsTools.Core/HelperFunctions.cs b/QtVsTools.Core/HelperFunctions.cs
index a75ff801..f2854711 100644
--- a/QtVsTools.Core/HelperFunctions.cs
+++ b/QtVsTools.Core/HelperFunctions.cs
@@ -169,6 +169,21 @@ namespace QtVsTools.Core
StringComparison.Ordinal, true);
}
+ public static bool MoveToRelativePath(this VCFile file, string relativePath)
+ {
+ var prevPath = file.FullPath;
+ var prevRelativePath = file.RelativePath;
+ try {
+ file.RelativePath = relativePath;
+ Directory.CreateDirectory(Path.GetDirectoryName(file.FullPath));
+ File.Move(prevPath, file.FullPath);
+ return true;
+ } catch {
+ file.RelativePath = prevRelativePath;
+ return false;
+ }
+ }
+
/// <summary>
/// Converts all directory separators of the path to the alternate character
/// directory separator. For instance, FromNativeSeparators("c:\\winnt\\system32")
diff --git a/QtVsTools.Wizards/ItemWizard/QtClass/QtClassWizard.cs b/QtVsTools.Wizards/ItemWizard/QtClass/QtClassWizard.cs
index 13130bc9..0e36ae09 100644
--- a/QtVsTools.Wizards/ItemWizard/QtClass/QtClassWizard.cs
+++ b/QtVsTools.Wizards/ItemWizard/QtClass/QtClassWizard.cs
@@ -5,6 +5,7 @@
using System;
using System.Collections.Generic;
+using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
@@ -170,11 +171,17 @@ namespace QtVsTools.Wizards.ItemWizard
var fullPath = vcFile.FullPath;
TextAndWhitespace.Adjust(Dte, fullPath);
- if (HelperFunctions.IsHeaderFile(fullPath))
+ if (HelperFunctions.IsHeaderFile(fullPath)) {
+ if (!string.IsNullOrEmpty(Path.GetDirectoryName(WizardData.ClassHeaderFile)))
+ vcFile.MoveToRelativePath(WizardData.ClassHeaderFile);
vcFile.MoveToFilter(FakeFilter.HeaderFiles());
+ }
- if (HelperFunctions.IsSourceFile(fullPath))
+ if (HelperFunctions.IsSourceFile(fullPath)) {
+ if (!string.IsNullOrEmpty(Path.GetDirectoryName(WizardData.ClassSourceFile)))
+ vcFile.MoveToRelativePath(WizardData.ClassSourceFile);
vcFile.MoveToFilter(FakeFilter.SourceFiles());
+ }
}
public override void RunFinished()
diff --git a/QtVsTools.Wizards/ItemWizard/Translation/TranslationWizard.cs b/QtVsTools.Wizards/ItemWizard/Translation/TranslationWizard.cs
index 60cb58df..63312a07 100644
--- a/QtVsTools.Wizards/ItemWizard/Translation/TranslationWizard.cs
+++ b/QtVsTools.Wizards/ItemWizard/Translation/TranslationWizard.cs
@@ -6,6 +6,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
+using System.IO;
using System.Linq;
using EnvDTE;
using Microsoft.VisualStudio.Shell;
@@ -100,8 +101,13 @@ namespace QtVsTools.Wizards.ItemWizard
var fullPath = vcFile.FullPath;
TextAndWhitespace.Adjust(Dte, fullPath);
- if (HelperFunctions.IsTranslationFile(fullPath))
+ if (HelperFunctions.IsTranslationFile(fullPath)) {
+ if (WizardData is TsWizardData ts &&
+ !string.IsNullOrEmpty(Path.GetDirectoryName(ts.TsFile))) {
+ vcFile.MoveToRelativePath(ts.TsFile);
+ }
vcFile.MoveToFilter(FakeFilter.TranslationFiles());
+ }
}
}
}
diff --git a/QtVsTools.Wizards/ItemWizard/WidgetsClass/WidgetsClassWizard.cs b/QtVsTools.Wizards/ItemWizard/WidgetsClass/WidgetsClassWizard.cs
index 4bd164e6..ba993f83 100644
--- a/QtVsTools.Wizards/ItemWizard/WidgetsClass/WidgetsClassWizard.cs
+++ b/QtVsTools.Wizards/ItemWizard/WidgetsClass/WidgetsClassWizard.cs
@@ -216,14 +216,23 @@ namespace QtVsTools.Wizards.ItemWizard
var fullPath = vcFile.FullPath;
TextAndWhitespace.Adjust(Dte, fullPath);
- if (HelperFunctions.IsUicFile(fullPath))
+ if (HelperFunctions.IsUicFile(fullPath)) {
+ if (!string.IsNullOrEmpty(Path.GetDirectoryName(WizardData.UiFile)))
+ vcFile.MoveToRelativePath(WizardData.UiFile);
vcFile.MoveToFilter(FakeFilter.FormFiles());
+ }
- if (HelperFunctions.IsHeaderFile(fullPath))
+ if (HelperFunctions.IsHeaderFile(fullPath)) {
+ if (!string.IsNullOrEmpty(Path.GetDirectoryName(WizardData.ClassHeaderFile)))
+ vcFile.MoveToRelativePath(WizardData.ClassHeaderFile);
vcFile.MoveToFilter(FakeFilter.HeaderFiles());
+ }
- if (HelperFunctions.IsSourceFile(fullPath))
+ if (HelperFunctions.IsSourceFile(fullPath)) {
+ if (!string.IsNullOrEmpty(Path.GetDirectoryName(WizardData.ClassSourceFile)))
+ vcFile.MoveToRelativePath(WizardData.ClassSourceFile);
vcFile.MoveToFilter(FakeFilter.SourceFiles());
+ }
}
public override void RunFinished()
diff --git a/QtVsTools.Wizards/Util/FileNameValidationRule.cs b/QtVsTools.Wizards/Util/FileNameValidationRule.cs
index c4d096ab..2edbc5fb 100644
--- a/QtVsTools.Wizards/Util/FileNameValidationRule.cs
+++ b/QtVsTools.Wizards/Util/FileNameValidationRule.cs
@@ -15,6 +15,9 @@ namespace QtVsTools.Wizards.Util
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
if (value is string filename) {
+ if (!string.IsNullOrEmpty(Path.GetDirectoryName(filename)))
+ filename = Path.GetFileName(filename);
+
if (FileExt is @".ui" or @".qrc") {
filename = filename.ToLower().Replace(@".h", @".x");
filename = filename.Replace(FileExt, @".h");