|
1 |
| -using System.Runtime.InteropServices; |
| 1 | +using System.IO; |
| 2 | +using System.Runtime.InteropServices; |
2 | 3 | using Rubberduck.Navigation.CodeExplorer;
|
3 | 4 | using Rubberduck.Parsing.Symbols;
|
| 5 | +using Rubberduck.Resources; |
4 | 6 | using Rubberduck.VBEditor.SafeComWrappers;
|
5 | 7 | using Rubberduck.VBEditor.SafeComWrappers.Abstract;
|
6 | 8 |
|
@@ -51,30 +53,51 @@ public void AddComponent(CodeExplorerItemViewModel node, ComponentType type)
|
51 | 53 | }
|
52 | 54 | }
|
53 | 55 |
|
54 |
| - public void AddComponent(CodeExplorerItemViewModel node, string fileName) |
| 56 | + public void AddComponent(CodeExplorerItemViewModel node, string moduleText) |
55 | 57 | {
|
56 | 58 | var nodeProject = GetDeclaration(node)?.Project;
|
57 | 59 | if (node != null && nodeProject == null)
|
58 | 60 | {
|
59 | 61 | return; //The project is not available.
|
60 | 62 | }
|
61 | 63 |
|
| 64 | + string optionCompare = string.Empty; |
| 65 | + using (IHostApplication hostApp = _vbe.HostApplication()) |
| 66 | + { |
| 67 | + optionCompare = hostApp.ApplicationName == "Microsoft Access" ? "Option Compare Database" : |
| 68 | + string.Empty; |
| 69 | + } |
| 70 | + |
62 | 71 | using (var components = node != null
|
63 | 72 | ? nodeProject.VBComponents
|
64 | 73 | : ComponentsCollectionFromActiveProject())
|
65 | 74 | {
|
66 | 75 | var folderAnnotation = $"'@Folder(\"{GetFolder(node)}\")";
|
| 76 | + string fileName = createTempTextFile(moduleText); |
67 | 77 |
|
68 | 78 | using (var newComponent = components.Import(fileName))
|
69 | 79 | {
|
70 | 80 | using (var codeModule = newComponent.CodeModule)
|
71 | 81 | {
|
72 |
| - codeModule.InsertLines(1, folderAnnotation); |
| 82 | + var delarationLines = string.Concat(folderAnnotation, optionCompare); |
| 83 | + codeModule.InsertLines(1, delarationLines); |
73 | 84 | }
|
74 | 85 | }
|
75 | 86 | }
|
76 | 87 | }
|
77 | 88 |
|
| 89 | + private string createTempTextFile(string moduleText) |
| 90 | + { |
| 91 | + string tempFolder = ApplicationConstants.RUBBERDUCK_TEMP_PATH; |
| 92 | + if (!Directory.Exists(tempFolder)) |
| 93 | + { |
| 94 | + Directory.CreateDirectory(tempFolder); |
| 95 | + } |
| 96 | + string filePath = Path.Combine(tempFolder, Path.GetRandomFileName()); |
| 97 | + File.WriteAllText(filePath, moduleText); |
| 98 | + return filePath; |
| 99 | + } |
| 100 | + |
78 | 101 | private IVBComponents ComponentsCollectionFromActiveProject()
|
79 | 102 | {
|
80 | 103 | using (var activeProject = _vbe.ActiveVBProject)
|
|
0 commit comments