diff --git a/source/shared/project/cppFiltersAutoShared.projitems b/source/shared/project/cppFiltersAutoShared.projitems index 8894e50..309919c 100644 --- a/source/shared/project/cppFiltersAutoShared.projitems +++ b/source/shared/project/cppFiltersAutoShared.projitems @@ -53,12 +53,15 @@ + + + diff --git a/source/shared/project/source/gui/questionFtd.Designer.cs b/source/shared/project/source/gui/questionFtd.Designer.cs index 3c2f1da..4d5d75f 100644 --- a/source/shared/project/source/gui/questionFtd.Designer.cs +++ b/source/shared/project/source/gui/questionFtd.Designer.cs @@ -49,7 +49,7 @@ private void InitializeComponent() this.labelWarning4 = new System.Windows.Forms.Label(); this.labelWarning5 = new System.Windows.Forms.Label(); this.labelWarning6 = new System.Windows.Forms.Label(); - this.label1 = new System.Windows.Forms.Label(); + this.labelWarning7 = new System.Windows.Forms.Label(); this.groupBoxQuestion.SuspendLayout(); this.SuspendLayout(); // @@ -233,9 +233,9 @@ private void InitializeComponent() this.labelWarning5.AutoSize = true; this.labelWarning5.Location = new System.Drawing.Point(82, 224); this.labelWarning5.Name = "labelWarning5"; - this.labelWarning5.Size = new System.Drawing.Size(295, 13); + this.labelWarning5.Size = new System.Drawing.Size(349, 13); this.labelWarning5.TabIndex = 11; - this.labelWarning5.Text = "2. #include directives may need to be changed"; + this.labelWarning5.Text = "2. #include directives may need to be changed afterward"; // // labelWarning6 // @@ -246,14 +246,14 @@ private void InitializeComponent() this.labelWarning6.TabIndex = 12; this.labelWarning6.Text = "3. this extension will access your fileSystem:"; // - // label1 + // labelWarning7 // - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(82, 266); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(271, 13); - this.label1.TabIndex = 13; - this.label1.Text = "move project files, delete empty directories"; + this.labelWarning7.AutoSize = true; + this.labelWarning7.Location = new System.Drawing.Point(82, 266); + this.labelWarning7.Name = "labelWarning7"; + this.labelWarning7.Size = new System.Drawing.Size(337, 13); + this.labelWarning7.TabIndex = 13; + this.labelWarning7.Text = "move project files, create and delete empty directories"; // // formQuestionFtd // @@ -261,7 +261,7 @@ private void InitializeComponent() this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(599, 293); - this.Controls.Add(this.label1); + this.Controls.Add(this.labelWarning7); this.Controls.Add(this.labelWarning6); this.Controls.Add(this.labelWarning5); this.Controls.Add(this.labelWarning4); @@ -314,6 +314,6 @@ private void InitializeComponent() public System.Windows.Forms.GroupBox groupBoxQuestion; public System.Windows.Forms.Label labelWarning5; public System.Windows.Forms.Label labelWarning6; - public System.Windows.Forms.Label label1; + public System.Windows.Forms.Label labelWarning7; } } \ No newline at end of file diff --git a/source/shared/project/source/source/extension/dirToFilter/work.cs b/source/shared/project/source/source/extension/dirToFilter/work.cs index 5ce509e..db3c63b 100644 --- a/source/shared/project/source/source/extension/dirToFilter/work.cs +++ b/source/shared/project/source/source/extension/dirToFilter/work.cs @@ -23,6 +23,7 @@ internal sealed partial class extension //callback void buttonBeforeQueryStatus(object sender, EventArgs e) { + ThreadHelper.ThrowIfNotOnUIThread(); OleMenuCommand x = (OleMenuCommand)sender; if (x == null) return; @@ -74,8 +75,8 @@ void buttonBeforeQueryStatus(object sender, EventArgs e) private void buttonClick(object sender, EventArgs e) { //projectData - dirToFilter.ProjectData p = new dirToFilter.ProjectData(); ThreadHelper.ThrowIfNotOnUIThread(); + dirToFilter.ProjectData p = new dirToFilter.ProjectData(); p.p = projectUtility.GetActive(); diff --git a/source/shared/project/source/source/extension/filterToDir/error.cs b/source/shared/project/source/source/extension/filterToDir/error.cs index 20a2c5f..76265b9 100644 --- a/source/shared/project/source/source/extension/filterToDir/error.cs +++ b/source/shared/project/source/source/extension/filterToDir/error.cs @@ -14,7 +14,7 @@ namespace filterToDir public class error { - public enum Type { move, delete, dirName, sameFile, sameFilter }; + public enum Type { move, delete, dirName, sameFile, sameFilter, existFile/*, fileSaved*/ }; @@ -66,11 +66,22 @@ public override string ToString() s2 += "\r\nfilter contains multiple filters with the same name, please rename or move them:"; s2 += "\r\n" + x2.s[0]; break; + + case Type.existFile: + s2 += "\r\nfile path, included in project, does not exist:"; + s2 += "\r\n" + x2.s[0]; + s2 += "\r\n" + x2.s[1]; + break; + /*case Type.fileSaved: + s2 += "\r\nfiles that need to be moved are opened in editor, changed, but not saved. Please save or discard (close without save)."; + foreach (string s3 in x2.s) + s2 += "\r\n" + s3; + break;*/ } - if (x2.e != null) s.Append("\r\n\r\nexception: [" + x2.e.Message + "]"); s.Append(s2); + if (x2.e != null) s.Append("\r\n\r\nexception: [" + x2.e.Message + "]"); if (i < x.Count - 1) s.Append("\r\n\r\n\r\n\r\n"); } diff --git a/source/shared/project/source/source/extension/filterToDir/filters.cs b/source/shared/project/source/source/extension/filterToDir/filters.cs index 3347601..6c8bc94 100644 --- a/source/shared/project/source/source/extension/filterToDir/filters.cs +++ b/source/shared/project/source/source/extension/filterToDir/filters.cs @@ -127,82 +127,6 @@ public void init(VCProject p) } - - - - - - /*public void fCleanEmpty(Dictionary filesIn, bool fEmptyDelete) - { - //remove from filters2 - foreach (var v in filesIn) - { - object o = v.Value.Parent; - if (!(o is VCFilter)) continue; - VCFilter f = (VCFilter)o; - fAll[f.CanonicalName].files.Remove(v.Value.FullPath); - v.Value.Move(p); - } - - //filters2 clean - bool b; - do - { - b = false; - fAll = fAll.Where(x => - { - filter2 x2 = x.Value; - if (x2.files.Count != 0) return true; - if (x2.filters2.Count != 0) return true; - if (!fEmptyDelete) if (x2.fEmpty) return true; - filter2 xp = x2.xp; - xp.filters2.Remove(x2.xn2); - x2.x.Remove(); - b = true; - return false; - } - ).ToDictionary(x => x.Key, x => x.Value); - } while (b); - - }*/ - - - - - - - - /*public filter2 fAdd(filter2 f, string x) - { - path x2 = new path(x, path.Separator.sDefault); - - - filter2 x3 = f; - for (int i = 0; i < x2.x2.Length; i++) - { - if (!x3.filters2.TryGetValue(x2.x2[i], out filter2 x4)) - { - VCFilter x5 = null; - if (x3.x == null) - x5 = (VCFilter)p.AddFilter(x2.x2[i]); - else - x5 = (VCFilter)x3.x.AddFilter(x2.x2[i]); - - x4 = new filter2() { x = x5 }; - x4.xp = x3; - x3.filters2.Add(x5.Name, x4); - fAll.Add(x5.CanonicalName, x4); - - x4.xn = x5.CanonicalName; - x4.xn2 = x5.Name; - } - x3 = x4; - } - return x3; - }*/ - - - } } } \ No newline at end of file diff --git a/source/shared/project/source/source/extension/filterToDir/projectData.cs b/source/shared/project/source/source/extension/filterToDir/projectData.cs index 69485b2..1048a59 100644 --- a/source/shared/project/source/source/extension/filterToDir/projectData.cs +++ b/source/shared/project/source/source/extension/filterToDir/projectData.cs @@ -100,10 +100,18 @@ public void filesGet(Project p) private void check2(filter x, error e) { //chars - bool b = true; - foreach (char c in checkC) - if (x.xn2.Contains(c)) { b = false; break; } - if (!b) e.add(new error.data() { t = error.Type.dirName, s = new string[] { x.xn.x } }); + if (x.xn2 != null) + { + bool b = true; + foreach (char c in checkC) + if (x.xn2.Contains(c)) { b = false; break; } + if (!b) e.add(new error.data() { t = error.Type.dirName, s = new string[] { x.xn.x } }); + } + + + //exist file + foreach (var x3 in x.o.files.Where(x2 => !File.Exists(x2.Key))) + e.add(new error.data() { t = error.Type.existFile, s = new string[] { "path: " + x3.Key, "filter: " + dir.file2.fileRelative(x3.Value).x } }); //same file foreach (var x3 in x.o.files.GroupBy(x2 => dir.file2.fileRelative(x2.Value).x.ToLower()).Where(x2 => x2.Count() > 1)) @@ -118,11 +126,8 @@ private void check2(filter x, error e) check2(x2, e); } - public void check(error e) - { - foreach (filter x in f2.f.o.filters2) - check2(x, e); - } + public void check(error e) => check2(f2.f, e); + } public Files f = new Files(); @@ -264,37 +269,48 @@ public class file2 public class Configuration { + public string itemType; + //public string contentType; //contentType can not be empty string or start with null char public eFileType fileType; + public bool deploymentContent; //public string customTool; //public bool includedInProject; public bool document = false; - public string dGuid; + public Configuration(VCFile x) { + itemType = x.ItemType; + //contentType = x.ContentType; fileType = x.FileType; + deploymentContent = x.DeploymentContent; //customTool = x.CustomTool; + //includedInProject - ProjectItem x2 = (ProjectItem)x.Object; - //if (!x2.Saved) x2.Save(); notImplemented - Document x3 = x2.Document; - if (x3 != null) + Document x2 = ((ProjectItem)x.Object).Document; + if (x2 != null) { document = true; - dGuid = x3.Kind; + x2.Close(); //if (!x2.Saved) x2.Save(); notImplemented } } public void set(VCFile x) { if (x == null) return; + + x.ItemType = itemType; + //x.ContentType = contentType; x.FileType = fileType; + x.DeploymentContent = deploymentContent; //x.CustomTool = customTool; notImplemented - - ProjectItem x2 = (ProjectItem)x.Object; - if (document) x2.Open(); + //includedInProject + + if (document) + try { ((ProjectItem)x.Object).DTE.Documents.Open(x.FullPath); } //((ProjectItem)x.Object).Open(Document.Kind {8E7B96A8-E33D-11D0-A6D5-00C04FB67F6A} ); + catch (Exception) { } } } @@ -333,16 +349,17 @@ public bool move(ProjectData p, error e) { if (File.Exists(p2.x)) return false; - object o = f.xp.x; - bool b = o != null; + VCFilter x = f.xp.x; + bool b = x != null; + path p3 = p2; Configuration c = new Configuration(f.x); { - if (b) ((VCFilter)o).RemoveFile(f.x); else p.p.p.RemoveFile(f.x); + if (b) x.RemoveFile(f.x); else p.p.p.RemoveFile(f.x); { - if (!file2.move(p1, p2, e)) p2 = p1; + if (!file2.move(p1, p2, e)) p3 = p1; } - f.x = (VCFile)(b ? ((VCFilter)o).AddFile(p2.x) : p.p.p.AddFile(p2.x)); + f.x = (VCFile)(b ? x.AddFile(p3.x) : p.p.p.AddFile(p3.x)); } c.set(f.x); return true; @@ -538,6 +555,15 @@ public void init(error e) LinkedList x1 = new LinkedList(); file2.filesGet(root, p.f.f2.f, ref x1); x = x1.ToArray(); + //error + /*{ + file2[] x4 = x.Where(x3 => !((ProjectItem)x3.f.x.Object).).ToArray(); + if (x4.Length > 0) + { + e.add(new error.data() { t = error.Type.fileSaved, s = x4.Select(x3 => x3.p1.x).ToArray() }); + return; + } + }*/ } HashSet x2 = new HashSet(); diff --git a/source/shared/project/source/source/extension/filterToDir/work.cs b/source/shared/project/source/source/extension/filterToDir/work.cs index 0c08fb0..cc0019c 100644 --- a/source/shared/project/source/source/extension/filterToDir/work.cs +++ b/source/shared/project/source/source/extension/filterToDir/work.cs @@ -22,9 +22,9 @@ internal sealed partial class extension private void button2Click(object sender, EventArgs e) { //project + ThreadHelper.ThrowIfNotOnUIThread(); filterToDir.ProjectData p = new filterToDir.ProjectData(); { - ThreadHelper.ThrowIfNotOnUIThread(); Project x = projectUtility.GetActive(); //check 1 project @@ -79,7 +79,13 @@ private void button2Click(object sender, EventArgs e) //dir - if (!p.e.full) p.dirSet(); + if (!p.e.full) + { + projectUtility.documentsRefresh(); + string dn = projectUtility.dte.ActiveDocument?.Name; + p.dirSet(); + projectUtility.documentActivate(dn); + } diff --git a/source/shared/project/source/source/other/test/dte/document.cs b/source/shared/project/source/source/other/test/dte/document.cs new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/source/shared/project/source/source/other/test/dte/document.cs @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/source/shared/project/source/source/other/test/dte/dte.cs b/source/shared/project/source/source/other/test/dte/dte.cs new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/source/shared/project/source/source/other/test/dte/dte.cs @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/source/shared/project/source/source/other/test/other.cs b/source/shared/project/source/source/other/test/other.cs index 5e940b6..bc117ab 100644 --- a/source/shared/project/source/source/other/test/other.cs +++ b/source/shared/project/source/source/other/test/other.cs @@ -36,8 +36,6 @@ public static void stringsInit(int i) - - public static void pathSeparator() { //DirectorySeparatorChar \ diff --git a/source/shared/project/source/source/other/test/vc/projectEngine.cs b/source/shared/project/source/source/other/test/vc/projectEngine.cs new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/source/shared/project/source/source/other/test/vc/projectEngine.cs @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/source/shared/project/source/source/utility/project.cs b/source/shared/project/source/source/utility/project.cs index e88d4d4..17ead60 100644 --- a/source/shared/project/source/source/utility/project.cs +++ b/source/shared/project/source/source/utility/project.cs @@ -11,16 +11,18 @@ namespace VisualStudioCppExtensions { public class projectUtility { - //active - public static Project GetActive() - { - ThreadHelper.ThrowIfNotOnUIThread(); - return GetActive((DTE)Package.GetGlobalService(typeof(SDTE))); - } + //dte + public static DTE dte => (DTE)Package.GetGlobalService(typeof(SDTE)); + + + + + //project active + public static Project GetActive() => GetActive(dte); + public static Project GetActive(DTE dte) { - ThreadHelper.ThrowIfNotOnUIThread(); object[] x = (object[])dte.ActiveSolutionProjects; if (x.xEmpty()) return null; return (Project)x[0]; @@ -32,20 +34,47 @@ public static Project GetActive(DTE dte) + //project cpp + public static bool IsCpp(Project project) + { + ThreadHelper.ThrowIfNotOnUIThread(); + return project != null + && (project.CodeModel.Language == CodeModelLanguageConstants.vsCMLanguageMC + || project.CodeModel.Language == CodeModelLanguageConstants.vsCMLanguageVC); + } - //cpp - public static bool IsCpp(Project project) + + + + + + //documents + public static void documentsRefresh() //push document tab lazy open { - ThreadHelper.ThrowIfNotOnUIThread(); - return project != null - && (project.CodeModel.Language == CodeModelLanguageConstants.vsCMLanguageMC - || project.CodeModel.Language == CodeModelLanguageConstants.vsCMLanguageVC); + foreach (Document x4 in dte.Documents) { } } + + public static void documentActivate(string x) //push document tab lazy open + { + if (x == null) return; + { + Document x2 = dte.ActiveDocument; + if (x2?.Name == x) return; + } + foreach (Document x2 in dte.Documents) + if (x2.Name == x) + { + x2.Activate(); + break; + } + } + + } }