Skip to content

Commit 3129edc

Browse files
authored
Merge pull request #6265 from Kristupasc/next
Export function now allows to choose a file name
2 parents 1d92568 + 89e0e17 commit 3129edc

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

Rubberduck.Core/UI/CodeExplorer/Commands/ExportCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public bool PromptFileNameAndExport(QualifiedModuleName qualifiedModule)
101101
var component = ProjectsProvider.Component(qualifiedModule);
102102
try
103103
{
104-
var path = Path.GetDirectoryName(dialog.FileName);
104+
var path = dialog.FileName; // This makes it that the file is named not as the module name, but as the file name the user provided in the explorer.
105105
component.ExportAsSourceFile(path, false, true); // skipped optional parameters interfere with mock setup
106106
}
107107
catch (Exception ex)

Rubberduck.VBEditor.VBA/SafeComWrappers/VB/VBComponent.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,27 @@ public bool HasDesigner
107107
/// <param name="folder">Destination folder for the resulting source file.</param>
108108
/// <param name="isTempFile">True if a unique temp file name should be generated. WARNING: filenames generated with this flag are not persisted.</param>
109109
/// <param name="specialCaseDocumentModules">If reimport of a document file is required later, it has to receive special treatment.</param>
110-
public string ExportAsSourceFile(string folder, bool isTempFile = false, bool specialCaseDocumentModules = true)
110+
public string ExportAsSourceFile(string folderOrPath, bool isTempFile = false, bool specialCaseDocumentModules = true)
111111
{
112112
//TODO: this entire thign needs to be reworked. IO is not the class' concern.
113113
//We probably need to leverage IPersistancePathProvider? ITempSourceFileHandler?
114114
//Just not here.
115-
var fullPath = isTempFile
116-
? _fileSystem.Path.Combine(folder, _fileSystem.Path.GetRandomFileName())
117-
: _fileSystem.Path.Combine(folder, SafeName + Type.FileExtension());
115+
string fullPath;
116+
if (_fileSystem.Path.HasExtension(folderOrPath))
117+
{
118+
fullPath = folderOrPath;
119+
}
120+
else
121+
{
122+
fullPath = isTempFile
123+
? _fileSystem.Path.Combine(folderOrPath, _fileSystem.Path.GetRandomFileName())
124+
: _fileSystem.Path.Combine(folderOrPath, SafeName + Type.FileExtension());
125+
}
118126

119-
if (!_fileSystem.Directory.Exists(folder))
127+
var dir = _fileSystem.Path.GetDirectoryName(fullPath);
128+
if (!_fileSystem.Directory.Exists(dir))
120129
{
121-
_fileSystem.Directory.CreateDirectory(folder);
130+
_fileSystem.Directory.CreateDirectory(dir);
122131
}
123132

124133
switch (Type)

RubberduckTests/CodeExplorer/CodeExplorerViewModelTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1858,7 +1858,8 @@ public void ExportModule_ExpectExecution()
18581858
{
18591859
explorer.VbComponent.Setup(c => c.ExportAsSourceFile(folder, It.IsAny<bool>(), It.IsAny<bool>()));
18601860
explorer.ExecuteExportCommand();
1861-
explorer.VbComponent.Verify(c => c.ExportAsSourceFile(folder, false, true), Times.Once);
1861+
// Expected: ExportAsSourceFile will now be called with the full path, because the default filename was appended.
1862+
explorer.VbComponent.Verify(c => c.ExportAsSourceFile(path, false, true), Times.Once);
18621863
}
18631864
}
18641865

0 commit comments

Comments
 (0)